]> git.proxmox.com Git - mirror_frr.git/commitdiff
bgpd: Add various hash optimizations
authorDonald Sharp <sharpd@cumulusnetworks.com>
Sun, 3 Sep 2017 22:57:30 +0000 (18:57 -0400)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Tue, 5 Sep 2017 18:33:06 +0000 (14:33 -0400)
1) Add hash names to all hash_create calls

2) Fix community_hash, ecommunity_hash and lcommunity_hash key
creation

3) Fix output of community and lcommunity iterators( why would
we want to see the memory location of the backet? ).

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
bgpd/bgp_advertise.c
bgpd/bgp_aspath.c
bgpd/bgp_attr.c
bgpd/bgp_community.c
bgpd/bgp_ecommunity.c
bgpd/bgp_lcommunity.c
bgpd/bgp_nexthop.c
bgpd/bgp_updgrp.c
bgpd/bgp_vty.c
bgpd/bgpd.c

index c7c9631512a0fb359892253e8cec323d9763788a..a7f72974cab4d2cf4d4e4102eea8f02a6532128d 100644 (file)
@@ -246,7 +246,9 @@ void bgp_sync_init(struct peer *peer)
                        BGP_ADV_FIFO_INIT(&sync->withdraw_low);
                        peer->sync[afi][safi] = sync;
                        peer->hash[afi][safi] =
-                               hash_create(baa_hash_key, baa_hash_cmp, NULL);
+                               hash_create(baa_hash_key,
+                                           baa_hash_cmp,
+                                           "BGP Sync Hash");
                }
 }
 
index 4e55c5f264ae7bddcda2e9c139f56cc78e74a053..2ce52d92a5acb40d4eaa25db9216cf5192bec91f 100644 (file)
@@ -2019,7 +2019,10 @@ int aspath_cmp(const void *arg1, const void *arg2)
 /* AS path hash initialize. */
 void aspath_init(void)
 {
-       ashash = hash_create_size(32768, aspath_key_make, aspath_cmp, NULL);
+       ashash = hash_create_size(32768,
+                                 aspath_key_make,
+                                 aspath_cmp,
+                                 "BGP AS Path");
 }
 
 void aspath_finish(void)
index e15a7618b8d203b96afa7961b5e3b274b29b2096..03cf3625b7546ba4e1fb13da14dc537a4c45b682 100644 (file)
@@ -200,8 +200,9 @@ void cluster_unintern(struct cluster_list *cluster)
 
 static void cluster_init(void)
 {
-       cluster_hash =
-               hash_create(cluster_hash_key_make, cluster_hash_cmp, NULL);
+       cluster_hash = hash_create(cluster_hash_key_make,
+                                  cluster_hash_cmp,
+                                  "BGP Cluster");
 }
 
 static void cluster_finish(void)
@@ -377,9 +378,13 @@ static int encap_hash_cmp(const void *p1, const void *p2)
 
 static void encap_init(void)
 {
-       encap_hash = hash_create(encap_hash_key_make, encap_hash_cmp, NULL);
+       encap_hash = hash_create(encap_hash_key_make,
+                                encap_hash_cmp,
+                                "BGP Encap Hash");
 #if ENABLE_BGP_VNC
-       vnc_hash = hash_create(encap_hash_key_make, encap_hash_cmp, NULL);
+       vnc_hash = hash_create(encap_hash_key_make,
+                              encap_hash_cmp,
+                              "BGP VNC Hash");
 #endif
 }
 
@@ -479,8 +484,9 @@ static int transit_hash_cmp(const void *p1, const void *p2)
 
 static void transit_init(void)
 {
-       transit_hash =
-               hash_create(transit_hash_key_make, transit_hash_cmp, NULL);
+       transit_hash = hash_create(transit_hash_key_make,
+                                  transit_hash_cmp,
+                                  "BGP Transit Hash");
 }
 
 static void transit_finish(void)
@@ -645,8 +651,9 @@ int attrhash_cmp(const void *p1, const void *p2)
 
 static void attrhash_init(void)
 {
-       attrhash =
-               hash_create(attrhash_key_make, attrhash_cmp, "BGP Attributes");
+       attrhash = hash_create(attrhash_key_make,
+                              attrhash_cmp,
+                              "BGP Attributes");
 }
 
 /*
index 7e8411b6a02c7fff1264209753aa53c4d88a8513..b0f00d67d66f2cb3337209b22b08adc4674ea3f9 100644 (file)
@@ -23,6 +23,7 @@
 #include "command.h"
 #include "hash.h"
 #include "memory.h"
+#include "jhash.h"
 
 #include "bgpd/bgp_memory.h"
 #include "bgpd/bgp_community.h"
@@ -409,19 +410,9 @@ char *community_str(struct community *com)
    hash package.*/
 unsigned int community_hash_make(struct community *com)
 {
-       unsigned char *pnt = (unsigned char *)com->val;
-       int size = com->size * 4;
-       unsigned int key = 0;
-       int c;
-
-       for (c = 0; c < size; c += 4) {
-               key += pnt[c];
-               key += pnt[c + 1];
-               key += pnt[c + 2];
-               key += pnt[c + 3];
-       }
+       u_int32_t *pnt = (u_int32_t *)com->val;
 
-       return key;
+       return jhash2(pnt, com->size, 0x43ea96c1);
 }
 
 int community_match(const struct community *com1, const struct community *com2)
@@ -653,7 +644,8 @@ void community_init(void)
 {
        comhash = hash_create(
                (unsigned int (*)(void *))community_hash_make,
-               (int (*)(const void *, const void *))community_cmp, NULL);
+               (int (*)(const void *, const void *))community_cmp,
+               "BGP Community Hash");
 }
 
 void community_finish(void)
index 7ac16896a2a79d9e4e3c50e1a6096b14eb0fd7da..ec52422d4cf1ae4f0db7c014914fc795561b67aa 100644 (file)
@@ -26,6 +26,7 @@
 #include "command.h"
 #include "queue.h"
 #include "filter.h"
+#include "jhash.h"
 
 #include "bgpd/bgpd.h"
 #include "bgpd/bgp_ecommunity.h"
@@ -234,22 +235,8 @@ unsigned int ecommunity_hash_make(void *arg)
 {
        const struct ecommunity *ecom = arg;
        int size = ecom->size * ECOMMUNITY_SIZE;
-       u_int8_t *pnt = ecom->val;
-       unsigned int key = 0;
-       int c;
-
-       for (c = 0; c < size; c += ECOMMUNITY_SIZE) {
-               key += pnt[c];
-               key += pnt[c + 1];
-               key += pnt[c + 2];
-               key += pnt[c + 3];
-               key += pnt[c + 4];
-               key += pnt[c + 5];
-               key += pnt[c + 6];
-               key += pnt[c + 7];
-       }
 
-       return key;
+       return jhash(ecom->val, size, 0x564321ab);
 }
 
 /* Compare two Extended Communities Attribute structure.  */
@@ -272,7 +259,9 @@ int ecommunity_cmp(const void *arg1, const void *arg2)
 /* Initialize Extended Comminities related hash. */
 void ecommunity_init(void)
 {
-       ecomhash = hash_create(ecommunity_hash_make, ecommunity_cmp, NULL);
+       ecomhash = hash_create(ecommunity_hash_make,
+                              ecommunity_cmp,
+                              "BGP ecommunity hash");
 }
 
 void ecommunity_finish(void)
index 395ae527120aa23c35b724f54f691898b7258cde..d75f33f58b827cf609ebc2991cf6b6100acf94f7 100644 (file)
@@ -25,6 +25,7 @@
 #include "prefix.h"
 #include "command.h"
 #include "filter.h"
+#include "jhash.h"
 
 #include "bgpd/bgpd.h"
 #include "bgpd/bgp_lcommunity.h"
@@ -230,26 +231,8 @@ unsigned int lcommunity_hash_make(void *arg)
 {
        const struct lcommunity *lcom = arg;
        int size = lcom_length(lcom);
-       u_int8_t *pnt = lcom->val;
-       unsigned int key = 0;
-       int c;
-
-       for (c = 0; c < size; c += LCOMMUNITY_SIZE) {
-               key += pnt[c];
-               key += pnt[c + 1];
-               key += pnt[c + 2];
-               key += pnt[c + 3];
-               key += pnt[c + 4];
-               key += pnt[c + 5];
-               key += pnt[c + 6];
-               key += pnt[c + 7];
-               key += pnt[c + 8];
-               key += pnt[c + 9];
-               key += pnt[c + 10];
-               key += pnt[c + 11];
-       }
 
-       return key;
+       return jhash(lcom->val, size, 0xab125423);
 }
 
 /* Compare two Large Communities Attribute structure.  */
@@ -272,7 +255,9 @@ struct hash *lcommunity_hash(void)
 /* Initialize Large Comminities related hash. */
 void lcommunity_init(void)
 {
-       lcomhash = hash_create(lcommunity_hash_make, lcommunity_cmp, NULL);
+       lcomhash = hash_create(lcommunity_hash_make,
+                              lcommunity_cmp,
+                              "BGP lcommunity hash");
 }
 
 void lcommunity_finish(void)
index b7d7cd9fa308cd10de32ab2ef7009dbfba92b91b..1200d74d6a59246846d800928bda511c66770993 100644 (file)
@@ -122,8 +122,9 @@ static int bgp_tip_hash_cmp(const void *p1, const void *p2)
 
 void bgp_tip_hash_init(struct bgp *bgp)
 {
-       bgp->tip_hash =
-               hash_create(bgp_tip_hash_key_make, bgp_tip_hash_cmp, NULL);
+       bgp->tip_hash = hash_create(bgp_tip_hash_key_make,
+                                   bgp_tip_hash_cmp,
+                                   "BGP TIP hash");
 }
 
 void bgp_tip_hash_destroy(struct bgp *bgp)
@@ -204,7 +205,8 @@ static int bgp_address_hash_cmp(const void *p1, const void *p2)
 void bgp_address_init(struct bgp *bgp)
 {
        bgp->address_hash = hash_create(bgp_address_hash_key_make,
-                                       bgp_address_hash_cmp, NULL);
+                                       bgp_address_hash_cmp,
+                                       "BGP Address Hash");
 }
 
 void bgp_address_destroy(struct bgp *bgp)
index 77e6157150dbf11ae8c0700ee6333e461f16a979..9630afb717209232ccd16497a201fd3dbba62dda 100644 (file)
@@ -84,7 +84,9 @@ static void sync_init(struct update_subgroup *subgrp)
        BGP_ADV_FIFO_INIT(&subgrp->sync->update);
        BGP_ADV_FIFO_INIT(&subgrp->sync->withdraw);
        BGP_ADV_FIFO_INIT(&subgrp->sync->withdraw_low);
-       subgrp->hash = hash_create(baa_hash_key, baa_hash_cmp, NULL);
+       subgrp->hash = hash_create(baa_hash_key,
+                                  baa_hash_cmp,
+                                  "BGP SubGroup Hash");
 
        /* We use a larger buffer for subgrp->work in the event that:
         * - We RX a BGP_UPDATE where the attributes alone are just
@@ -1549,8 +1551,10 @@ void update_bgp_group_init(struct bgp *bgp)
        int afid;
 
        AF_FOREACH(afid)
-       bgp->update_groups[afid] =
-               hash_create(updgrp_hash_key_make, updgrp_hash_cmp, NULL);
+               bgp->update_groups[afid] =
+                       hash_create(updgrp_hash_key_make,
+                                   updgrp_hash_cmp,
+                                   "BGP Update Group Hash");
 }
 
 void update_bgp_group_free(struct bgp *bgp)
index a29b7f7bec5c2c23ba5865e6a88db35f77da0948..f9105bfaf7bccd3216cc005c312e10422cbd9250 100644 (file)
@@ -9934,7 +9934,7 @@ static void community_show_all_iterator(struct hash_backet *backet,
        struct community *com;
 
        com = (struct community *)backet->data;
-       vty_out(vty, "[%p] (%ld) %s\n", (void *)backet, com->refcnt,
+       vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
                community_str(com));
 }
 
@@ -9963,7 +9963,7 @@ static void lcommunity_show_all_iterator(struct hash_backet *backet,
        struct lcommunity *lcom;
 
        lcom = (struct lcommunity *)backet->data;
-       vty_out(vty, "[%p] (%ld) %s\n", (void *)backet, lcom->refcnt,
+       vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
                lcommunity_str(lcom));
 }
 
index d1470557493d0c3cc2050833c41a49c5b0fdde0c..40ca3d4886d52588f0fcae49444cc5792533340d 100644 (file)
@@ -2833,7 +2833,9 @@ static struct bgp *bgp_create(as_t *as, const char *name,
                        XSTRDUP(MTYPE_BGP_PEER_HOST, cmd_domainname_get());
        bgp->peer = list_new();
        bgp->peer->cmp = (int (*)(void *, void *))peer_cmp;
-       bgp->peerhash = hash_create(peer_hash_key_make, peer_hash_same, NULL);
+       bgp->peerhash = hash_create(peer_hash_key_make,
+                                   peer_hash_same,
+                                   "BGP Peer Hash");
        bgp->peerhash->max_size = BGP_PEER_MAX_HASH_SIZE;
 
        bgp->group = list_new();