hash table test: don't redefine CACHE_LINE_SIZE
[urcu.git] / tests / test_urcu_hash.h
index 9abb2e0de0868aeb32ba7c981003b8fa3fdfceb9..cd064e62b76e6821c311fa9e9588330d134f503f 100644 (file)
 #include <unistd.h>
 #include <stdio.h>
 #include <assert.h>
-#include <sched.h>
 #include <errno.h>
 #include <signal.h>
 
-#ifdef __linux__
-#include <syscall.h>
-#endif
+#include <urcu/tls-compat.h>
+#include "cpuset.h"
+#include "thread-id.h"
 
 #define DEFAULT_HASH_SIZE      32
 #define DEFAULT_MIN_ALLOC_SIZE 1
@@ -53,9 +52,6 @@
  */
 #define TEST_HASH_SEED 0x42UL
 
-/* Make this big enough to include the POWER5+ L3 cacheline size of 256B */
-#define CACHE_LINE_SIZE 4096
-
 /* hardcoded number of CPUs */
 #define NR_CPUS 16384
 
 #define poison_free(ptr)       free(ptr)
 #endif
 
-
-
-#if defined(_syscall0)
-_syscall0(pid_t, gettid)
-#elif defined(__NR_gettid)
-static inline pid_t gettid(void)
-{
-       return syscall(__NR_gettid);
-}
-#else
-#warning "use pid as tid"
-static inline pid_t gettid(void)
-{
-       return getpid();
-}
-#endif
-
 #ifndef DYNAMIC_LINK_TEST
 #define _LGPL_SOURCE
 #else
@@ -102,13 +81,13 @@ struct wr_count {
        unsigned long remove;
 };
 
-extern unsigned int __thread rand_lookup;
-extern unsigned long __thread nr_add;
-extern unsigned long __thread nr_addexist;
-extern unsigned long __thread nr_del;
-extern unsigned long __thread nr_delnoent;
-extern unsigned long __thread lookup_fail;
-extern unsigned long __thread lookup_ok;
+extern DECLARE_URCU_TLS(unsigned int, rand_lookup);
+extern DECLARE_URCU_TLS(unsigned long, nr_add);
+extern DECLARE_URCU_TLS(unsigned long, nr_addexist);
+extern DECLARE_URCU_TLS(unsigned long, nr_del);
+extern DECLARE_URCU_TLS(unsigned long, nr_delnoent);
+extern DECLARE_URCU_TLS(unsigned long, lookup_fail);
+extern DECLARE_URCU_TLS(unsigned long, lookup_ok);
 
 extern struct cds_lfht *test_ht;
 
@@ -169,11 +148,13 @@ extern unsigned long init_pool_size,
        write_pool_size;
 extern int validate_lookup;
 
+extern unsigned long nr_hash_chains;
+
 extern int count_pipe[2];
 
-static inline void loop_sleep(unsigned long l)
+static inline void loop_sleep(unsigned long loops)
 {
-       while(l-- != 0)
+       while (loops-- != 0)
                caa_cpu_relax();
 }
 
@@ -191,12 +172,6 @@ extern int use_affinity;
 
 extern pthread_mutex_t affinity_mutex;
 
-#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
-
 void set_affinity(void);
 
 /*
@@ -212,8 +187,8 @@ static inline int test_duration_read(void)
        return !test_stop;
 }
 
-extern unsigned long long __thread nr_writes;
-extern unsigned long long __thread nr_reads;
+extern DECLARE_URCU_TLS(unsigned long long, nr_writes);
+extern DECLARE_URCU_TLS(unsigned long long, nr_reads);
 
 extern unsigned int nr_readers;
 extern unsigned int nr_writers;
@@ -323,7 +298,7 @@ void hashword2(
 
 #if (CAA_BITS_PER_LONG == 32)
 static inline
-unsigned long test_hash(const void *_key, size_t length, unsigned long seed)
+unsigned long test_hash_mix(const void *_key, size_t length, unsigned long seed)
 {
        unsigned int key = (unsigned int) _key;
 
@@ -332,7 +307,7 @@ unsigned long test_hash(const void *_key, size_t length, unsigned long seed)
 }
 #else
 static inline
-unsigned long test_hash(const void *_key, size_t length, unsigned long seed)
+unsigned long test_hash_mix(const void *_key, size_t length, unsigned long seed)
 {
        union {
                uint64_t v64;
@@ -351,6 +326,29 @@ unsigned long test_hash(const void *_key, size_t length, unsigned long seed)
 }
 #endif
 
+/*
+ * Hash function with nr_hash_chains != 0 for testing purpose only!
+ * Creates very long hash chains, deteriorating the hash table into a
+ * few linked lists, depending on the nr_hash_chains value. The purpose
+ * of this test is to check how the hash table behaves with hash chains
+ * containing different values, which is a rare case in a normal hash
+ * table.
+ */
+static inline
+unsigned long test_hash(const void *_key, size_t length,
+                       unsigned long seed)
+{
+       if (nr_hash_chains == 0) {
+               return test_hash_mix(_key, length, seed);
+       } else {
+               unsigned long v;
+
+               assert(length == sizeof(unsigned long));
+               v = (unsigned long) _key;
+               return v % nr_hash_chains;
+       }
+}
+
 unsigned long test_compare(const void *key1, size_t key1_len,
                            const void *key2, size_t key2_len);
 
@@ -382,4 +380,11 @@ void *test_hash_rw_thr_reader(void *_count);
 void *test_hash_rw_thr_writer(void *_count);
 int test_hash_rw_populate_hash(void);
 
+/* unique test */
+void test_hash_unique_sigusr1_handler(int signo);
+void test_hash_unique_sigusr2_handler(int signo);
+void *test_hash_unique_thr_reader(void *_count);
+void *test_hash_unique_thr_writer(void *_count);
+int test_hash_unique_populate_hash(void);
+
 #endif /* _TEST_URCU_HASH_H */
This page took 0.024806 seconds and 4 git commands to generate.