diff options
author | Donald Sharp <sharpd@cumulusnetworks.com> | 2017-09-04 00:57:30 +0200 |
---|---|---|
committer | Donald Sharp <sharpd@cumulusnetworks.com> | 2017-09-05 20:33:06 +0200 |
commit | 3f65c5b1f7db20c1ee3ab723483f294975ce2f94 (patch) | |
tree | 298e5547fd5d36b177e2d3eb31a4ff88d76a158c | |
parent | zebra: Add hash name to mpls hash (diff) | |
download | frr-3f65c5b1f7db20c1ee3ab723483f294975ce2f94.tar.xz frr-3f65c5b1f7db20c1ee3ab723483f294975ce2f94.zip |
bgpd: Add various hash optimizations
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>
-rw-r--r-- | bgpd/bgp_advertise.c | 4 | ||||
-rw-r--r-- | bgpd/bgp_aspath.c | 5 | ||||
-rw-r--r-- | bgpd/bgp_attr.c | 23 | ||||
-rw-r--r-- | bgpd/bgp_community.c | 18 | ||||
-rw-r--r-- | bgpd/bgp_ecommunity.c | 21 | ||||
-rw-r--r-- | bgpd/bgp_lcommunity.c | 25 | ||||
-rw-r--r-- | bgpd/bgp_nexthop.c | 8 | ||||
-rw-r--r-- | bgpd/bgp_updgrp.c | 10 | ||||
-rw-r--r-- | bgpd/bgp_vty.c | 4 | ||||
-rw-r--r-- | bgpd/bgpd.c | 4 |
10 files changed, 54 insertions, 68 deletions
diff --git a/bgpd/bgp_advertise.c b/bgpd/bgp_advertise.c index c7c963151..a7f72974c 100644 --- a/bgpd/bgp_advertise.c +++ b/bgpd/bgp_advertise.c @@ -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"); } } diff --git a/bgpd/bgp_aspath.c b/bgpd/bgp_aspath.c index 4e55c5f26..2ce52d92a 100644 --- a/bgpd/bgp_aspath.c +++ b/bgpd/bgp_aspath.c @@ -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) diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c index e15a7618b..03cf3625b 100644 --- a/bgpd/bgp_attr.c +++ b/bgpd/bgp_attr.c @@ -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"); } /* diff --git a/bgpd/bgp_community.c b/bgpd/bgp_community.c index 7e8411b6a..b0f00d67d 100644 --- a/bgpd/bgp_community.c +++ b/bgpd/bgp_community.c @@ -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) diff --git a/bgpd/bgp_ecommunity.c b/bgpd/bgp_ecommunity.c index 7ac16896a..ec52422d4 100644 --- a/bgpd/bgp_ecommunity.c +++ b/bgpd/bgp_ecommunity.c @@ -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) diff --git a/bgpd/bgp_lcommunity.c b/bgpd/bgp_lcommunity.c index 395ae5271..d75f33f58 100644 --- a/bgpd/bgp_lcommunity.c +++ b/bgpd/bgp_lcommunity.c @@ -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) diff --git a/bgpd/bgp_nexthop.c b/bgpd/bgp_nexthop.c index b7d7cd9fa..1200d74d6 100644 --- a/bgpd/bgp_nexthop.c +++ b/bgpd/bgp_nexthop.c @@ -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) diff --git a/bgpd/bgp_updgrp.c b/bgpd/bgp_updgrp.c index 77e615715..9630afb71 100644 --- a/bgpd/bgp_updgrp.c +++ b/bgpd/bgp_updgrp.c @@ -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) diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index a29b7f7be..f9105bfaf 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -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)); } diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index d14705574..40ca3d488 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -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(); |