The path_hash function is called reasonably often. Calling
SipHash24_Update() over and over for small data is not optimal.
Inspired by /sys/sys/proc.h add a aspath_hashstart and aspath_hashend to
the struct rde_aspath and use that for the hash.
--
:wq Claudio
Index: rde.h
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/rde.h,v
retrieving revision 1.230
diff -u -p -r1.230 rde.h
--- rde.h 9 Jan 2020 13:31:52 -0000 1.230
+++ rde.h 9 Jan 2020 15:12:47 -0000
@@ -215,14 +215,16 @@ struct rde_aspath {
struct attr **others;
struct aspath *aspath;
u_int64_t hash;
+ int refcnt;
u_int32_t flags; /* internally used */
+#define aspath_hashstart med
u_int32_t med; /* multi exit disc */
u_int32_t lpref; /* local pref */
u_int32_t weight; /* low prio lpref */
- int refcnt;
u_int16_t rtlabelid; /* route label id */
u_int16_t pftableid; /* pf table id */
u_int8_t origin;
+#define aspath_hashend others_len
u_int8_t others_len;
};
Index: rde_rib.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/rde_rib.c,v
retrieving revision 1.212
diff -u -p -r1.212 rde_rib.c
--- rde_rib.c 9 Jan 2020 11:55:25 -0000 1.212
+++ rde_rib.c 9 Jan 2020 15:14:27 -0000
@@ -701,12 +701,8 @@ path_hash(struct rde_aspath *asp)
u_int64_t hash;
SipHash24_Init(&ctx, &pathtablekey);
- SipHash24_Update(&ctx, &asp->origin, sizeof(asp->origin));
- SipHash24_Update(&ctx, &asp->med, sizeof(asp->med));
- SipHash24_Update(&ctx, &asp->lpref, sizeof(asp->lpref));
- SipHash24_Update(&ctx, &asp->weight, sizeof(asp->weight));
- SipHash24_Update(&ctx, &asp->rtlabelid, sizeof(asp->rtlabelid));
- SipHash24_Update(&ctx, &asp->pftableid, sizeof(asp->pftableid));
+ SipHash24_Update(&ctx, &asp->aspath_hashstart,
+ (char *)&asp->aspath_hashend - (char *)&asp->aspath_hashstart);
if (asp->aspath)
SipHash24_Update(&ctx, asp->aspath->data, asp->aspath->len);