rculfhash: use DEFAULT_SPLIT_COUNT_MASK for !HAVE_SYSCONF
authorLai Jiangshan <laijs@cn.fujitsu.com>
Fri, 28 Oct 2011 07:31:51 +0000 (09:31 +0200)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 28 Oct 2011 07:31:51 +0000 (09:31 +0200)
Now, item accounting is always available.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
rculfhash.c

index 46513dfd40562bb7c1e0bb24f39fee3656e378a2..668f93672a17899e7fc27e9cd049e1ccf9350d74 100644 (file)
  * tables and machines lacking per-cpu data suppport.
  */
 #define COUNT_COMMIT_ORDER             10
+#define DEFAULT_SPLIT_COUNT_MASK       0xFUL
 #define CHAIN_LEN_TARGET               1
 #define CHAIN_LEN_RESIZE_THRESHOLD     3
 
@@ -497,14 +498,6 @@ int get_count_order_ulong(unsigned long x)
 static
 void cds_lfht_resize_lazy(struct cds_lfht *ht, unsigned long size, int growth);
 
-/*
- * If the sched_getcpu() and sysconf(_SC_NPROCESSORS_CONF) calls are
- * available, then we support hash table item accounting.
- * In the unfortunate event the number of CPUs reported would be
- * inaccurate, we use modulo arithmetic on the number of CPUs we got.
- */
-#if defined(HAVE_SYSCONF)
-
 static
 void cds_lfht_resize_lazy_count(struct cds_lfht *ht, unsigned long size,
                                unsigned long count);
@@ -512,6 +505,7 @@ void cds_lfht_resize_lazy_count(struct cds_lfht *ht, unsigned long size,
 static long nr_cpus_mask = -1;
 static long split_count_mask = -1;
 
+#if defined(HAVE_SYSCONF)
 static void ht_init_nr_cpus_mask(void)
 {
        long maxcpus;
@@ -528,6 +522,12 @@ static void ht_init_nr_cpus_mask(void)
        maxcpus = 1UL << get_count_order_ulong(maxcpus);
        nr_cpus_mask = maxcpus - 1;
 }
+#else /* #if defined(HAVE_SYSCONF) */
+static void ht_init_nr_cpus_mask(void)
+{
+       nr_cpus_mask = -2;
+}
+#endif /* #else #if defined(HAVE_SYSCONF) */
 
 static
 struct ht_items_count *alloc_split_items_count(void)
@@ -536,13 +536,14 @@ struct ht_items_count *alloc_split_items_count(void)
 
        if (nr_cpus_mask == -1) {
                ht_init_nr_cpus_mask();
-               split_count_mask = nr_cpus_mask;
+               if (nr_cpus_mask < 0)
+                       split_count_mask = DEFAULT_SPLIT_COUNT_MASK;
+               else
+                       split_count_mask = nr_cpus_mask;
        }
 
-       if (split_count_mask < 0)
-               return NULL;
-       else
-               return calloc(split_count_mask + 1, sizeof(*count));
+       assert(split_count_mask >= 0);
+       return calloc(split_count_mask + 1, sizeof(*count));
 }
 
 static
@@ -632,35 +633,6 @@ void ht_count_del(struct cds_lfht *ht, unsigned long size, unsigned long hash)
        }
 }
 
-#else /* #if defined(HAVE_SYSCONF) */
-
-static const long nr_cpus_mask = -2;
-static const long split_count_mask = -2;
-
-static
-struct ht_items_count *alloc_split_items_count(void)
-{
-       return NULL;
-}
-
-static
-void free_split_items_count(struct ht_items_count *count)
-{
-}
-
-static
-void ht_count_add(struct cds_lfht *ht, unsigned long size, unsigned long hash)
-{
-}
-
-static
-void ht_count_del(struct cds_lfht *ht, unsigned long size, unsigned long hash)
-{
-}
-
-#endif /* #else #if defined(HAVE_SYSCONF) */
-
-
 static
 void check_resize(struct cds_lfht *ht, unsigned long size, uint32_t chain_len)
 {
@@ -1802,8 +1774,6 @@ void cds_lfht_resize_lazy(struct cds_lfht *ht, unsigned long size, int growth)
        }
 }
 
-#if defined(HAVE_SYSCONF)
-
 static
 void cds_lfht_resize_lazy_count(struct cds_lfht *ht, unsigned long size,
                                unsigned long count)
@@ -1828,5 +1798,3 @@ void cds_lfht_resize_lazy_count(struct cds_lfht *ht, unsigned long size,
                CMM_STORE_SHARED(ht->t.resize_initiated, 1);
        }
 }
-
-#endif
This page took 0.027335 seconds and 4 git commands to generate.