From: Mathieu Desnoyers Date: Sat, 13 Jun 2009 21:52:43 +0000 (-0400) Subject: Add looplen cycle test X-Git-Tag: v0.1~149 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=fd6a23f245ce6fc26b45baf1db27c8d3b359719c;p=userspace-rcu.git Add looplen cycle test Signed-off-by: Mathieu Desnoyers --- diff --git a/Makefile b/Makefile index e03d509..02d3b27 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,7 @@ all: checkarch test_urcu test_urcu_dynamic_link test_urcu_timing \ test_rwlock_timing test_rwlock test_perthreadlock_timing \ test_perthreadlock test_urcu_yield test_urcu_mb \ urcu-asm.S test_qsbr_timing test_qsbr urcu-asm.o urcutorture \ - urcutorture-yield liburcu.so test_mutex + urcutorture-yield liburcu.so test_mutex test_looplen checkarch: ifeq (${ARCHTYPE},) @@ -57,6 +57,9 @@ urcu-qsbr.h: arch.h api.h arch_atomic.h test_urcu: urcu.o test_urcu.c urcu.h $(CC) ${CFLAGS} $(LDFLAGS) -o $@ $(SRC_DEP) +test_looplen: test_looplen.c urcu.h + $(CC) ${CFLAGS} $(LDFLAGS) -o $@ $(SRC_DEP) + test_urcu_mb: urcu-mb.o test_urcu.c urcu.h $(CC) -DDEBUG_FULL_MB ${CFLAGS} $(LDFLAGS) -o $@ $(SRC_DEP) diff --git a/Makefile64 b/Makefile64 index 8d75cf3..bc07d10 100644 --- a/Makefile64 +++ b/Makefile64 @@ -28,7 +28,7 @@ all: checkarch test_urcu test_urcu_dynamic_link test_urcu_timing \ test_rwlock_timing test_rwlock test_perthreadlock_timing \ test_perthreadlock test_urcu_yield test_urcu_mb \ urcu-asm.S test_qsbr_timing test_qsbr urcu-asm.o urcutorture \ - urcutorture-yield liburcu.so test_mutex + urcutorture-yield liburcu.so test_mutex test_looplen checkarch: ifeq (${ARCHTYPE},) @@ -52,6 +52,9 @@ urcu-qsbr.h: arch.h api.h arch_atomic.h test_urcu: urcu.o test_urcu.c urcu.h $(CC) ${CFLAGS} $(LDFLAGS) -o $@ $(SRC_DEP) +test_looplen: test_looplen.c urcu.h + $(CC) ${CFLAGS} $(LDFLAGS) -o $@ $(SRC_DEP) + test_urcu_mb: urcu-mb.o test_urcu.c urcu.h $(CC) -DDEBUG_FULL_MB ${CFLAGS} $(LDFLAGS) -o $@ $(SRC_DEP) diff --git a/test_looplen.c b/test_looplen.c new file mode 100644 index 0000000..86d0386 --- /dev/null +++ b/test_looplen.c @@ -0,0 +1,87 @@ +/* + * test_looplen.c + * + * Userspace RCU library - test program + * + * Copyright February 2009 - Mathieu Desnoyers + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "arch.h" + +#if defined(_syscall0) +_syscall0(pid_t, gettid) +#elif defined(__NR_gettid) +static inline pid_t gettid(void) +{ + return syscall(__NR_gettid); +} +#else +#warning "use pid as tid" +static inline pid_t gettid(void) +{ + return getpid(); +} +#endif + +#ifndef DYNAMIC_LINK_TEST +#define _LGPL_SOURCE +#else +#define debug_yield_read() +#endif +#include "urcu.h" + +static inline void loop_sleep(unsigned long l) +{ + while(l-- != 0) + cpu_relax(); +} + +#define LOOPS 1048576 +#define TESTS 10 + +int main(int argc, char **argv) +{ + unsigned long i; + cycles_t time1, time2; + cycles_t time_tot = 0; + + for (i = 0; i < TESTS; i++) { + time1 = get_cycles(); + loop_sleep(LOOPS); + time2 = get_cycles(); + time_tot += time2 - time1; + } + time_tot /= TESTS; + time_tot /= LOOPS; + + printf("CALIBRATION : %llu cycles per loop\n", time_tot); + + return 0; +}