From 54bd224f0e98f58c3a9d0f70078c54d87969469a Mon Sep 17 00:00:00 2001 From: antirez Date: Wed, 10 May 2017 09:33:49 +0200 Subject: [PATCH] atomicvar.h: show used API in INFO. Add macro to force __sync builtin. The __sync builtin can be correctly detected by Helgrind so to force it is useful for testing. The API in the INFO output can be useful for debugging after problems are reported. --- src/atomicvar.h | 17 +++++++++++------ src/server.c | 2 ++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/atomicvar.h b/src/atomicvar.h index 9b5628ad..84a5bbc5 100644 --- a/src/atomicvar.h +++ b/src/atomicvar.h @@ -62,7 +62,13 @@ #ifndef __ATOMIC_VAR_H #define __ATOMIC_VAR_H -#if defined(__ATOMIC_RELAXED) && !defined(__sun) && (!defined(__clang__) || !defined(__APPLE__) || __apple_build_version__ > 4210057) +/* To test Redis with Helgrind (a Valgrind tool) it is useful to define + * the following macro, so that __sync macros are used: those can be detected + * by Helgrind (even if they are less efficient) so that no false positive + * is reported. */ +// #define __ATOMIC_VAR_FORCE_SYNC_MACROS + +#if !defined(__ATOMIC_VAR_FORCE_SYNC_MACROS) && defined(__ATOMIC_RELAXED) && !defined(__sun) && (!defined(__clang__) || !defined(__APPLE__) || __apple_build_version__ > 4210057) /* Implementation using __atomic macros. */ #define atomicIncr(var,count) __atomic_add_fetch(&var,(count),__ATOMIC_RELAXED) @@ -74,6 +80,7 @@ dstvar = __atomic_load_n(&var,__ATOMIC_RELAXED); \ } while(0) #define atomicSet(var,value) __atomic_store_n(&var,value,__ATOMIC_RELAXED) +#define REDIS_ATOMIC_API "atomic-builtin" #elif defined(HAVE_ATOMIC) /* Implementation using __sync macros. */ @@ -89,6 +96,7 @@ #define atomicSet(var,value) do { \ while(!__sync_bool_compare_and_swap(&var,var,value)); \ } while(0) +#define REDIS_ATOMIC_API "sync-builtin" #else /* Implementation using pthread mutex. */ @@ -98,31 +106,28 @@ var += (count); \ pthread_mutex_unlock(&var ## _mutex); \ } while(0) - #define atomicGetIncr(var,oldvalue_var,count) do { \ pthread_mutex_lock(&var ## _mutex); \ oldvalue_var = var; \ var += (count); \ pthread_mutex_unlock(&var ## _mutex); \ } while(0) - #define atomicDecr(var,count) do { \ pthread_mutex_lock(&var ## _mutex); \ var -= (count); \ pthread_mutex_unlock(&var ## _mutex); \ } while(0) - #define atomicGet(var,dstvar) do { \ pthread_mutex_lock(&var ## _mutex); \ dstvar = var; \ pthread_mutex_unlock(&var ## _mutex); \ } while(0) - #define atomicSet(var,value) do { \ pthread_mutex_lock(&var ## _mutex); \ var = value; \ pthread_mutex_unlock(&var ## _mutex); \ } while(0) -#endif +#define REDIS_ATOMIC_API "pthread-mutex" +#endif #endif /* __ATOMIC_VAR_H */ diff --git a/src/server.c b/src/server.c index 0ef3168f..75268b8a 100644 --- a/src/server.c +++ b/src/server.c @@ -2827,6 +2827,7 @@ sds genRedisInfoString(char *section) { "os:%s %s %s\r\n" "arch_bits:%d\r\n" "multiplexing_api:%s\r\n" + "atomicvar_api:%s\r\n" "gcc_version:%d.%d.%d\r\n" "process_id:%ld\r\n" "run_id:%s\r\n" @@ -2845,6 +2846,7 @@ sds genRedisInfoString(char *section) { name.sysname, name.release, name.machine, server.arch_bits, aeGetApiName(), + REDIS_ATOMIC_API, #ifdef __GNUC__ __GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__, #else