diff options
author | Stephen Worley <sworley@cumulusnetworks.com> | 2019-08-06 23:30:16 +0200 |
---|---|---|
committer | Stephen Worley <sworley@cumulusnetworks.com> | 2019-10-25 17:13:42 +0200 |
commit | a15e669ceb0c9adde7ca2370aae7168a0b6548bc (patch) | |
tree | 37ec022adab2ed4f6d4c396421d184da1fd4ba44 /lib | |
parent | lib: nexthop_group_equal() assume ordered (diff) | |
download | frr-a15e669ceb0c9adde7ca2370aae7168a0b6548bc.tar.xz frr-a15e669ceb0c9adde7ca2370aae7168a0b6548bc.zip |
lib: Call nexthop g_addr hashes together
When hashing a nexthop, shove all the nexthop g_addr data together
and pass it as one call to jhash2() to optimize a bit better.
Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/nexthop.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/lib/nexthop.c b/lib/nexthop.c index e68e605a6..da7c934ef 100644 --- a/lib/nexthop.c +++ b/lib/nexthop.c @@ -374,16 +374,28 @@ unsigned int nexthop_level(struct nexthop *nexthop) return rv; } +#define GATE_SIZE 4 /* Number of uint32_t words in struct g_addr */ + uint32_t nexthop_hash(const struct nexthop *nexthop) { + uint32_t key = 0x45afe398; + uint32_t gate_src_rmap_raw[GATE_SIZE * 3] = {}; key = jhash_3words(nexthop->type, nexthop->vrf_id, nexthop->nh_label_type, key); - /* gate and blackhole are together in a union */ - key = jhash(&nexthop->gate, sizeof(nexthop->gate), key); - key = jhash(&nexthop->src, sizeof(nexthop->src), key); - key = jhash(&nexthop->rmap_src, sizeof(nexthop->rmap_src), key); + + assert(((sizeof(nexthop->gate) + sizeof(nexthop->src) + + sizeof(nexthop->rmap_src)) + / 3) + == (GATE_SIZE * sizeof(uint32_t))); + + memcpy(gate_src_rmap_raw, &nexthop->gate, GATE_SIZE); + memcpy(gate_src_rmap_raw + GATE_SIZE, &nexthop->src, GATE_SIZE); + memcpy(gate_src_rmap_raw + (2 * GATE_SIZE), &nexthop->rmap_src, + GATE_SIZE); + + key = jhash2(gate_src_rmap_raw, (GATE_SIZE * 3), key); if (nexthop->nh_label) { int labels = nexthop->nh_label->num_labels; |