]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: Hash creation cleanup
authorDonald Sharp <sharpd@cumulusnetworks.com>
Sun, 3 Sep 2017 22:50:35 +0000 (18:50 -0400)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Tue, 5 Sep 2017 18:33:01 +0000 (14:33 -0400)
1) Some hash key functions where converting pointers
directly to a 32 bit value via downcasting.  Pointers
are 64 bit on a majority of our platforms.

2) Some hashes were being created with 256 entries,
downsize the hash creation size to more appropriate
values.

3) Add hash names to hash creation so we can watch
the hash via 'show debugging hashtable'

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
lib/command.c
lib/if_rmap.c
lib/qobj.c
lib/routemap.c
lib/thread.c

index a3037813705b0d1e56324244fafa7cde97f14773..d1b086737280dfdfd8809fa13af09b5af5230aaa 100644 (file)
@@ -43,6 +43,7 @@
 #include "qobj.h"
 #include "defaults.h"
 #include "libfrr.h"
+#include "jhash.h"
 
 DEFINE_MTYPE(LIB, HOST, "Host config")
 DEFINE_MTYPE(LIB, STRVEC, "String vector")
@@ -278,7 +279,9 @@ int argv_find(struct cmd_token **argv, int argc, const char *text, int *index)
 
 static unsigned int cmd_hash_key(void *p)
 {
-       return (uintptr_t)p;
+       int size = sizeof(p);
+
+       return jhash(p, size, 0);
 }
 
 static int cmd_hash_cmp(const void *a, const void *b)
@@ -298,7 +301,9 @@ void install_node(struct cmd_node *node, int (*func)(struct vty *))
                cmd_token_new(START_TKN, CMD_ATTR_NORMAL, NULL, NULL);
        graph_new_node(node->cmdgraph, token,
                       (void (*)(void *)) & cmd_token_del);
-       node->cmd_hash = hash_create(cmd_hash_key, cmd_hash_cmp, NULL);
+       node->cmd_hash = hash_create_size(16, cmd_hash_key,
+                                         cmd_hash_cmp,
+                                         "Command Hash");
 }
 
 /**
index 968c087c3c4d97e8795563a2b9feef11f60e0dd6..53c2824a99a02071de04f5174b68aa5f460a37ea 100644 (file)
@@ -294,7 +294,10 @@ void if_rmap_reset()
 
 void if_rmap_init(int node)
 {
-       ifrmaphash = hash_create(if_rmap_hash_make, if_rmap_hash_cmp, NULL);
+       ifrmaphash = hash_create_size(4,
+                                     if_rmap_hash_make,
+                                     if_rmap_hash_cmp,
+                                     "Interface Route-Map Hash");
        if (node == RIPNG_NODE) {
        } else if (node == RIP_NODE) {
                install_element(RIP_NODE, &if_rmap_cmd);
index 5f450ca0d36430890acc59483031ed683dd21620..c75002052e5f10602cffa2141e8799e643e7d9fb 100644 (file)
@@ -25,6 +25,7 @@
 #include "hash.h"
 #include "log.h"
 #include "qobj.h"
+#include "jhash.h"
 
 static pthread_rwlock_t nodes_lock;
 static struct hash *nodes = NULL;
@@ -97,7 +98,9 @@ void qobj_init(void)
 {
        if (!nodes) {
                pthread_rwlock_init(&nodes_lock, NULL);
-               nodes = hash_create(qobj_key, qobj_cmp, NULL);
+               nodes = hash_create_size(16, qobj_key,
+                                        qobj_cmp,
+                                        "QOBJ Hash");
        }
 }
 
index 409c9c378076a11d1ee511fe8517682fe5ae9585..31afc33f5818443a67ad30d798aa29363c5baef3 100644 (file)
@@ -1581,8 +1581,10 @@ static void *route_map_dep_hash_alloc(void *p)
 
        dep_entry = XCALLOC(MTYPE_ROUTE_MAP_DEP, sizeof(struct route_map_dep));
        dep_entry->dep_name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, dep_name);
-       dep_entry->dep_rmap_hash = hash_create(route_map_dep_hash_make_key,
-                                              route_map_rmap_hash_cmp, NULL);
+       dep_entry->dep_rmap_hash = hash_create_size(8,
+                                                   route_map_dep_hash_make_key,
+                                                   route_map_rmap_hash_cmp,
+                                                   "Route Map Dep Hash");
        dep_entry->this_hash = NULL;
 
        return ((void *)dep_entry);
@@ -2784,12 +2786,15 @@ void route_map_init(void)
        route_match_vec = vector_init(1);
        route_set_vec = vector_init(1);
        route_map_master_hash =
-               hash_create(route_map_hash_key_make, route_map_hash_cmp, NULL);
+               hash_create_size(8, route_map_hash_key_make,
+                                route_map_hash_cmp,
+                                "Route Map Master Hash");
 
        for (i = 1; i < ROUTE_MAP_DEP_MAX; i++)
                route_map_dep_hash[i] =
-                       hash_create(route_map_dep_hash_make_key,
-                                   route_map_dep_hash_cmp, NULL);
+                       hash_create_size(8, route_map_dep_hash_make_key,
+                                        route_map_dep_hash_cmp,
+                                        "Route Map Dep Hash");
 
        cmd_variable_handler_register(rmap_var_handlers);
 
index b39f2d55c2cead518119c218d7120b0a77e2b20b..0ce38dd3401707fc146ca496ab51a097e14a86a1 100644 (file)
@@ -31,6 +31,7 @@
 #include "command.h"
 #include "sigevent.h"
 #include "network.h"
+#include "jhash.h"
 
 DEFINE_MTYPE_STATIC(LIB, THREAD, "Thread")
 DEFINE_MTYPE_STATIC(LIB, THREAD_MASTER, "Thread master")
@@ -58,7 +59,9 @@ static struct list *masters;
 /* CLI start ---------------------------------------------------------------- */
 static unsigned int cpu_record_hash_key(struct cpu_thread_history *a)
 {
-       return (uintptr_t)a->func;
+       int size = sizeof (&a->func);
+
+       return jhash(&a->func, size, 0);
 }
 
 static int cpu_record_hash_cmp(const struct cpu_thread_history *a,
@@ -376,9 +379,11 @@ struct thread_master *thread_master_create(const char *name)
                return NULL;
        }
 
-       rv->cpu_record = hash_create(
+       rv->cpu_record = hash_create_size(
+               8,
                (unsigned int (*)(void *))cpu_record_hash_key,
-               (int (*)(const void *, const void *))cpu_record_hash_cmp, NULL);
+               (int (*)(const void *, const void *))cpu_record_hash_cmp,
+               "Thread Hash");
 
 
        /* Initialize the timer queues */