Merge pull request #1099 from donaldsharp/hashing

Hashing
This commit is contained in:
David Lamparter 2017-09-07 11:35:08 +02:00 committed by GitHub
commit a7e5e20a22
20 changed files with 105 additions and 86 deletions

View 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");
}
}

View 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)

View 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");
}
/*

View 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;
u_int32_t *pnt = (u_int32_t *)com->val;
for (c = 0; c < size; c += 4) {
key += pnt[c];
key += pnt[c + 1];
key += pnt[c + 2];
key += pnt[c + 3];
}
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)

View 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)

View 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)

View 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)

View 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
@ -1550,7 +1552,9 @@ void update_bgp_group_init(struct bgp *bgp)
AF_FOREACH(afid)
bgp->update_groups[afid] =
hash_create(updgrp_hash_key_make, updgrp_hash_cmp, NULL);
hash_create(updgrp_hash_key_make,
updgrp_hash_cmp,
"BGP Update Group Hash");
}
void update_bgp_group_free(struct bgp *bgp)

View 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));
}

View 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();

View 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");
}
/**

View 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);

View 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");
}
}

View 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);

View 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 */

View file

@ -81,7 +81,9 @@ struct nhrp_cache *nhrp_cache_get(struct interface *ifp, union sockunion *remote
struct nhrp_cache key;
if (!nifp->cache_hash) {
nifp->cache_hash = hash_create(nhrp_cache_protocol_key, nhrp_cache_protocol_cmp, NULL);
nifp->cache_hash = hash_create(nhrp_cache_protocol_key,
nhrp_cache_protocol_cmp,
"NHRP Cache");
if (!nifp->cache_hash)
return NULL;
}

View file

@ -182,7 +182,9 @@ struct nhrp_peer *nhrp_peer_get(struct interface *ifp, const union sockunion *re
struct nhrp_vc *vc;
if (!nifp->peer_hash) {
nifp->peer_hash = hash_create(nhrp_peer_key, nhrp_peer_cmp, NULL);
nifp->peer_hash = hash_create(nhrp_peer_key,
nhrp_peer_cmp,
"NHRP Peer Hash");
if (!nifp->peer_hash) return NULL;
}

View file

@ -196,7 +196,9 @@ void nhrp_vc_init(void)
{
size_t i;
nhrp_vc_hash = hash_create(nhrp_vc_key, nhrp_vc_cmp, NULL);
nhrp_vc_hash = hash_create(nhrp_vc_key,
nhrp_vc_cmp,
"NHRP VC hash");
for (i = 0; i < ZEBRA_NUM_OF(childlist_head); i++)
list_init(&childlist_head[i]);
}

View file

@ -17,7 +17,9 @@ static int nhrp_reqid_cmp(const void *data, const void *key)
uint32_t nhrp_reqid_alloc(struct nhrp_reqid_pool *p, struct nhrp_reqid *r, void (*cb)(struct nhrp_reqid *, void *))
{
if (!p->reqid_hash) {
p->reqid_hash = hash_create(nhrp_reqid_key, nhrp_reqid_cmp, NULL);
p->reqid_hash = hash_create(nhrp_reqid_key,
nhrp_reqid_cmp,
"NHRP reqid Hash");
p->next_request_id = 1;
}

View file

@ -2812,8 +2812,12 @@ void zebra_mpls_init_tables(struct zebra_vrf *zvrf)
{
if (!zvrf)
return;
zvrf->slsp_table = hash_create(label_hash, label_cmp, NULL);
zvrf->lsp_table = hash_create(label_hash, label_cmp, NULL);
zvrf->slsp_table = hash_create(label_hash,
label_cmp,
"ZEBRA SLSP table");
zvrf->lsp_table = hash_create(label_hash,
label_cmp,
"ZEBRA LSP table");
zvrf->fec_table[AFI_IP] = route_table_init();
zvrf->fec_table[AFI_IP6] = route_table_init();
zvrf->mpls_flags = 0;