From 44c47feb9edc7854bf3cfa2e3d843e90fc969b3a Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Wed, 4 Jun 2008 14:31:25 +0200 Subject: [PATCH] Add write barriers And enable them in solarisaio, then it should be safe to use the signal driven IO "interrupts". Signed-off-by: Jens Axboe --- arch/arch-alpha.h | 5 +++-- arch/arch-ia64.h | 1 + arch/arch-ppc.h | 8 ++++---- arch/arch-s390.h | 1 + arch/arch-sparc.h | 1 + arch/arch-sparc64.h | 4 ++-- arch/arch-x86.h | 3 ++- arch/arch-x86_64.h | 3 ++- engines/solarisaio.c | 8 ++++---- 9 files changed, 20 insertions(+), 14 deletions(-) diff --git a/arch/arch-alpha.h b/arch/arch-alpha.h index 2b683201..811d23a1 100644 --- a/arch/arch-alpha.h +++ b/arch/arch-alpha.h @@ -12,7 +12,8 @@ #define __NR_fadvise64 413 #endif -#define nop do { } while (0) -#define read_barrier() __asm__ __volatile__("mb": : :"memory") +#define nop do { } while (0) +#define read_barrier() __asm__ __volatile__("mb": : :"memory") +#define writer_barrier() __asm__ __volatile__("wmb": : :"memory") #endif diff --git a/arch/arch-ia64.h b/arch/arch-ia64.h index 6dd8196d..2f926849 100644 --- a/arch/arch-ia64.h +++ b/arch/arch-ia64.h @@ -20,6 +20,7 @@ #define nop asm volatile ("hint @pause" ::: "memory"); #define read_barrier() asm volatile ("mf" ::: "memory") +#define writebarrier() asm volatile ("mf" ::: "memory") #define ia64_popcnt(x) \ ({ \ diff --git a/arch/arch-ppc.h b/arch/arch-ppc.h index 6256d056..06115387 100644 --- a/arch/arch-ppc.h +++ b/arch/arch-ppc.h @@ -21,13 +21,13 @@ #define nop do { } while (0) #ifdef __powerpc64__ -#define read_barrier() \ - __asm__ __volatile__ ("lwsync" : : : "memory") +#define read_barrier() __asm__ __volatile__ ("lwsync" : : : "memory") #else -#define read_barrier() \ - __asm__ __volatile__ ("sync" : : : "memory") +#define read_barrier() __asm__ __volatile__ ("sync" : : : "memory") #endif +#define write_barrier() __asm__ __volatile__ ("sync" : : : "memory") + static inline int __ilog2(unsigned long bitmask) { int lz; diff --git a/arch/arch-s390.h b/arch/arch-s390.h index c4ec1d12..dfb7899b 100644 --- a/arch/arch-s390.h +++ b/arch/arch-s390.h @@ -14,5 +14,6 @@ #define nop asm volatile ("diag 0,0,68" : : : "memory") #define read_barrier() asm volatile("bcr 15,0" : : : "memory") +#define write_barrier() asm volatile("bcr 15,0" : : : "memory") #endif diff --git a/arch/arch-sparc.h b/arch/arch-sparc.h index be3b394a..cd552ab7 100644 --- a/arch/arch-sparc.h +++ b/arch/arch-sparc.h @@ -21,5 +21,6 @@ #define nop do { } while (0) #define read_barrier() __asm__ __volatile__ ("" : : : "memory") +#define write_barrier() __asm__ __volatile__ ("" : : : "memory") #endif diff --git a/arch/arch-sparc64.h b/arch/arch-sparc64.h index b916882a..332cf917 100644 --- a/arch/arch-sparc64.h +++ b/arch/arch-sparc64.h @@ -27,7 +27,7 @@ : : : "memory"); \ } while (0) -#define read_barrier() \ - membar_safe("#LoadLoad") +#define read_barrier() membar_safe("#LoadLoad") +#define write_barrier() membar_safe("#StoreStore") #endif diff --git a/arch/arch-x86.h b/arch/arch-x86.h index a396c850..97262ffe 100644 --- a/arch/arch-x86.h +++ b/arch/arch-x86.h @@ -30,7 +30,8 @@ #define FIO_HAVE_SYSLET #define nop __asm__ __volatile__("rep;nop": : :"memory") -#define read_barrier() asm volatile ("": : :"memory") +#define read_barrier() __asm__ __volatile__("": : :"memory") +#define write_barrier() __asm__ __volatile__("": : :"memory") static inline unsigned long arch_ffz(unsigned long bitmask) { diff --git a/arch/arch-x86_64.h b/arch/arch-x86_64.h index 0d26feeb..216e74e2 100644 --- a/arch/arch-x86_64.h +++ b/arch/arch-x86_64.h @@ -30,7 +30,8 @@ #define FIO_HAVE_SYSLET #define nop __asm__ __volatile__("rep;nop": : :"memory") -#define read_barrier() asm volatile("lfence":::"memory") +#define read_barrier() __asm__ __volatile__("lfence":::"memory") +#define write_barrier() __asm__ __volatile__("sfence":::"memory") static inline unsigned int arch_ffz(unsigned int bitmask) { diff --git a/engines/solarisaio.c b/engines/solarisaio.c index b519fc54..dfaa375a 100644 --- a/engines/solarisaio.c +++ b/engines/solarisaio.c @@ -69,6 +69,7 @@ static void wait_for_event(struct timeval *tv) * the ->aio_pending store is seen after the ->aio_events store */ sd->aio_events[sd->aio_pending] = io_u; + write_barrier(); sd->aio_pending++; sd->nr--; } @@ -97,10 +98,10 @@ static int fio_solarisaio_getevents(struct thread_data *td, unsigned int min, wait_for_event(&tv); /* - * Needs locking here for SIGIO + * should be OK without locking, as int operations should be atomic */ ret = sd->aio_pending; - sd->aio_pending = 0; + sd->aio_pending -= ret; return ret; } @@ -161,8 +162,7 @@ static void fio_solarisaio_cleanup(struct thread_data *td) } /* - * Set USE_SIGNAL_COMPLETIONS to use SIGIO as completion events. Needs - * locking around ->aio_pending and ->aio_events, see comment + * Set USE_SIGNAL_COMPLETIONS to use SIGIO as completion events. */ static void fio_solarisaio_init_sigio(void) { -- 2.25.1