X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=tests%2Ftest_urcu_hash.c;h=aac1db88cbc2a09425d87f3ef12adf6e54423161;hb=8bcbd94a60f624c1faae1481fcb0888aec25b481;hp=eb6cca9381b738279affedab98ceff818c1b2bba;hpb=bc8c3c74b84e838b195faa8871344f5b672ae1cd;p=userspace-rcu.git diff --git a/tests/test_urcu_hash.c b/tests/test_urcu_hash.c index eb6cca9..aac1db8 100644 --- a/tests/test_urcu_hash.c +++ b/tests/test_urcu_hash.c @@ -21,6 +21,7 @@ */ #define _GNU_SOURCE +#include "../config.h" #include #include #include @@ -32,6 +33,7 @@ #include #include #include +#include #ifdef __linux__ #include @@ -41,6 +43,12 @@ #define DEFAULT_MIN_ALLOC_SIZE 1 #define DEFAULT_RAND_POOL 1000000 +/* + * Note: the hash seed should be a random value for hash tables + * targeting production environments to provide protection against + * denial of service attacks. We keep it a static value within this test + * program to compare identical benchmark runs. + */ #define TEST_HASH_SEED 0x42UL /* Make this big enough to include the POWER5+ L3 cacheline size of 256B */ @@ -181,6 +189,12 @@ static int use_affinity = 0; pthread_mutex_t affinity_mutex = PTHREAD_MUTEX_INITIALIZER; +#ifndef HAVE_CPU_SET_T +typedef unsigned long cpu_set_t; +# define CPU_ZERO(cpuset) do { *(cpuset) = 0; } while(0) +# define CPU_SET(cpu, cpuset) do { *(cpuset) |= (1UL << (cpu)); } while(0) +#endif + static void set_affinity(void) { cpu_set_t mask; @@ -190,6 +204,7 @@ static void set_affinity(void) if (!use_affinity) return; +#if HAVE_SCHED_SETAFFINITY ret = pthread_mutex_lock(&affinity_mutex); if (ret) { perror("Error in pthread mutex lock"); @@ -203,7 +218,12 @@ static void set_affinity(void) } CPU_ZERO(&mask); CPU_SET(cpu, &mask); - sched_setaffinity(0, sizeof(mask), &mask); +#if SCHED_SETAFFINITY_ARGS == 2 + sched_setaffinity(0, &mask); +#else + sched_setaffinity(0, sizeof(mask), &mask); +#endif +#endif /* HAVE_SCHED_SETAFFINITY */ } static enum { @@ -995,7 +1015,9 @@ int main(int argc, char **argv) count_writer = malloc(sizeof(*count_writer) * nr_writers); err = create_all_cpu_call_rcu_data(0); - assert(!err); + if (err) { + printf("Per-CPU call_rcu() worker threads unavailable. Using default global worker thread.\n"); + } if (memory_backend) { test_ht = _cds_lfht_new(init_hash_size, min_hash_alloc_size,