From: Mathieu Desnoyers Date: Sun, 13 Jun 2010 23:55:41 +0000 (-0400) Subject: Add test cycles per loop X-Git-Tag: v0.4.5~6 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=d3d3d8f0136d7c095bdf97b17ec3f1d7a1b1dfe6;p=urcu.git Add test cycles per loop Signed-off-by: Mathieu Desnoyers --- diff --git a/tests/Makefile.am b/tests/Makefile.am index e0bbf46..0ff6b3e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -12,7 +12,7 @@ noinst_PROGRAMS = test_urcu test_urcu_dynamic_link test_urcu_timing \ test_urcu_mb_gc test_qsbr_gc test_qsbr_lgc test_urcu_signal_lgc \ test_urcu_mb_lgc test_qsbr_dynamic_link test_urcu_defer \ test_uatomic test_urcu_assign test_urcu_assign_dynamic_link \ - test_urcu_bp test_urcu_bp_dynamic_link + test_urcu_bp test_urcu_bp_dynamic_link test_cycles_per_loop noinst_HEADERS = rcutorture.h if COMPAT_ARCH @@ -139,6 +139,8 @@ test_urcu_defer_SOURCES = test_urcu_defer.c $(URCU_DEFER) test_uatomic_SOURCES = test_uatomic.c $(COMPAT) +test_cycles_per_loop_SOURCES = test_cycles_per_loop.c + test_urcu_assign_SOURCES = test_urcu_assign.c $(URCU) test_urcu_assign_dynamic_link_SOURCES = test_urcu_assign.c $(URCU) diff --git a/tests/test_cycles_per_loop.c b/tests/test_cycles_per_loop.c new file mode 100644 index 0000000..64b160b --- /dev/null +++ b/tests/test_cycles_per_loop.c @@ -0,0 +1,21 @@ +#include +#include + +#define NR_LOOPS 1000000UL + +static inline void loop_sleep(unsigned long l) +{ + while(l-- != 0) + cpu_relax(); +} + +int main() +{ + cycles_t time1, time2; + + time1 = get_cycles(); + loop_sleep(NR_LOOPS); + time2 = get_cycles(); + printf("CPU clock cycles per loop: %g\n", (time2 - time1) / + (double)NR_LOOPS); +}