From: Mathieu Desnoyers Date: Thu, 12 Feb 2009 04:47:15 +0000 (-0500) Subject: use smp_*mb() X-Git-Tag: v0.1~295 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=b715b99eb0d52e0744bfea46c62849f260a5ec58;p=userspace-rcu.git use smp_*mb() Signed-off-by: Mathieu Desnoyers --- diff --git a/urcu.c b/urcu.c index 9542b26..162ce00 100644 --- a/urcu.c +++ b/urcu.c @@ -43,7 +43,9 @@ unsigned int __thread rand_yield; static struct reader_data *reader_data; static int num_readers, alloc_readers; +#ifndef DEBUG_FULL_MB static int sig_done; +#endif void internal_urcu_lock(void) { @@ -77,14 +79,14 @@ static void switch_next_urcu_qparity(void) #ifdef DEBUG_FULL_MB static void force_mb_all_threads(void) { - mb(); + smp_mb(); } #else static void force_mb_all_threads(void) { struct reader_data *index; /* - * Ask for each threads to execute a mb() so we can consider the + * Ask for each threads to execute a smp_mb() so we can consider the * compiler barriers around rcu read lock as real memory barriers. */ if (!reader_data) @@ -92,7 +94,7 @@ static void force_mb_all_threads(void) debug_yield_write(); sig_done = 0; debug_yield_write(); - mb(); /* write sig_done before sending the signals */ + smp_mb(); /* write sig_done before sending the signals */ debug_yield_write(); for (index = reader_data; index < reader_data + num_readers; index++) { pthread_kill(index->tid, SIGURCU); @@ -105,7 +107,7 @@ static void force_mb_all_threads(void) while (sig_done < num_readers) barrier(); debug_yield_write(); - mb(); /* read sig_done before ending the barrier */ + smp_mb(); /* read sig_done before ending the barrier */ debug_yield_write(); } #endif @@ -147,7 +149,7 @@ void synchronize_rcu(void) * waiting forever while new readers are always accessing data (no * progress). */ - mb(); + smp_mb(); /* * Wait for previous parity to be empty of readers. @@ -161,7 +163,7 @@ void synchronize_rcu(void) * the writer waiting forever while new readers are always accessing * data (no progress). */ - mb(); + smp_mb(); switch_next_urcu_qparity(); /* 1 -> 0 */ debug_yield_write(); @@ -172,7 +174,7 @@ void synchronize_rcu(void) * waiting forever while new readers are always accessing data (no * progress). */ - mb(); + smp_mb(); /* * Wait for previous parity to be empty of readers. @@ -256,7 +258,7 @@ void urcu_unregister_thread(void) #ifndef DEBUG_FULL_MB void sigurcu_handler(int signo, siginfo_t *siginfo, void *context) { - mb(); + smp_mb(); atomic_inc(&sig_done); } diff --git a/urcu.h b/urcu.h index c4a7992..92b31df 100644 --- a/urcu.h +++ b/urcu.h @@ -31,6 +31,19 @@ #define rmb() asm volatile("lfence":::"memory") #define wmb() asm volatile("sfence" ::: "memory") +/* Assume SMP machine, given we don't have this information */ +#define CONFIG_SMP 1 + +#ifdef CONFIG_SMP +#define smp_mb() mb() +#define smp_rmb() rmb() +#define smp_wmb() wmb() +#else +#define smp_mb() barrier() +#define smp_rmb() barrier() +#define smp_wmb() barrier() +#endif + static inline void atomic_inc(int *v) { asm volatile("lock; incl %0" @@ -173,7 +186,7 @@ static inline void debug_yield_init(void) #ifdef DEBUG_FULL_MB static inline void read_barrier() { - mb(); + smp_mb(); } #else static inline void read_barrier()