Just a ugly debug patch, use pthread spinlock for non-x86 platform Signed-off-by: Lin Ming diff --git a/time-warp-test.c b/time-warp-test.c index df51b2b..66e3d3c 100644 --- a/time-warp-test.c +++ b/time-warp-test.c @@ -31,6 +31,7 @@ #include #include #include +#include #define TEST_TSC 0 #define TEST_TOD 0 @@ -50,7 +51,7 @@ * Shared locks and variables between the test tasks: */ enum { - SHARED_LOCK = 0, + SHARED_LOCK2 = 0, SHARED_TSC = 2, SHARED_TOD = 4, SHARED_CLOCK = 6, @@ -63,7 +64,8 @@ enum { SHARED_NR_TOD_WARPS = 20, SHARED_NR_CLOCK_LOOPS = 22, SHARED_NR_CLOCK_WARPS = 24, - SHARED_END = 26, + SHARED_LOCK = 26, + SHARED_END = 34, }; #define SHARED(x) (*(shared + SHARED_##x)) @@ -138,8 +140,10 @@ static unsigned long *setup_shared_var(void) return buf; } -static inline void lock(unsigned long *flag) +static inline void lock(pthread_spinlock_t *slock) { + pthread_spin_lock(slock); +/* #if 0 __asm__ __volatile__( "1: lock; btsl $0,%0\n" @@ -156,10 +160,13 @@ static inline void lock(unsigned long *flag) "3:" : "+m"(*flag) : : "memory"); #endif +*/ } -static inline void unlock(unsigned long *flag) +static inline void unlock(pthread_spinlock_t *slock) { + pthread_spin_unlock(slock); +/* #if 0 __asm__ __volatile__( "lock; btrl $0,%0\n" @@ -168,6 +175,7 @@ static inline void unlock(unsigned long *flag) #else __asm__ __volatile__("movl $0,%0; rep; nop" : "=g"(*flag) :: "memory"); #endif +*/ } static void print_status(unsigned long *shared) @@ -278,29 +286,29 @@ static inline void test_TOD(unsigned long *shared) #endif } -static inline void test_CLOCK(unsigned long *shared) +static inline void test_CLOCK(unsigned long *shared, pthread_spinlock_t *slock) { #if TEST_CLOCK usecs_t T0, T1; long long delta; - lock(&SHARED(LOCK)); + lock(slock); rdclock(T1); T0 = SHARED_LL(CLOCK); SHARED_LL(CLOCK) = T1; SHARED_LL(NR_CLOCK_LOOPS)++; - unlock(&SHARED(LOCK)); + unlock(slock); delta = T1-T0; if (delta < 0) { - lock(&SHARED(LOCK)); + lock(slock); SHARED(NR_CLOCK_WARPS)++; if (delta < SHARED_LL(WORST_CLOCK)) { SHARED_LL(WORST_CLOCK) = delta; fprintf(stderr, "\rnew CLOCK-warp maximum: %9Ld nsecs, %016Lx -> %016Lx\n", delta, T0, T1); } - unlock(&SHARED(LOCK)); + unlock(slock); } #endif } @@ -310,6 +318,7 @@ int main(int argc, char **argv) int i, parent, me; unsigned long *shared; unsigned long cpus, tasks; + pthread_spinlock_t *slock; cpus = system("exit `grep ^processor /proc/cpuinfo | wc -l`"); cpus = WEXITSTATUS(cpus); @@ -342,6 +351,12 @@ usage: ); shared = setup_shared_var(); + slock = (pthread_spinlock_t *) (&SHARED(LOCK)); + if (pthread_spin_init(slock, PTHREAD_PROCESS_SHARED)) { + perror("pthread_spin_init"); + exit(-1); + } + parent = getpid(); for (i = 1; i < tasks; i++) { @@ -358,7 +373,7 @@ usage: for (i = 0; i < 10; i++) test_TOD(shared); for (i = 0; i < 10; i++) - test_CLOCK(shared); + test_CLOCK(shared, slock); if (me == parent) print_status(shared);