[Cake] small cake_hash optimization?

Pete Heist peteheist at gmail.com
Wed Nov 22 05:06:18 EST 2017


I’ve been playing around with cake’s hashing and happened to notice in cake_hash that it seems like srchost_idx and dsthost_idx could rather be calculated only if need_allocate_src or need_allocate_dst are true, respectively, as the values are only used inside those code blocks.

I’ve not done any testing on what the real impact of this change would be, or even if it breaks something.

Forgive me for any waste of time if I’ve missed something here...

-----

sysadmin at apu2b:~/src/sch_cake$ git diff sch_cake.c
diff --git a/sch_cake.c b/sch_cake.c
index 97a27be..8f59917 100644
--- a/sch_cake.c
+++ b/sch_cake.c
@@ -747,8 +747,6 @@ cake_hash(struct cake_tin_data *q, const struct sk_buff *skb, int flow_mode)
        }
 
        reduced_hash = flow_hash    % CAKE_QUEUES;
-       srchost_idx  = srchost_hash % CAKE_QUEUES;
-       dsthost_idx  = dsthost_hash % CAKE_QUEUES;
 
        /* set-associative hashing */
        /* fast path if no hash collision (direct lookup succeeds) */
@@ -809,6 +807,7 @@ found:
                q->tags[reduced_hash] = flow_hash;
 
                if (need_allocate_src) {
+                       srchost_idx = srchost_hash % CAKE_QUEUES;
                        inner_hash = srchost_idx % CAKE_SET_WAYS;
                        outer_hash = srchost_idx - inner_hash;
                        for (i = 0, k = inner_hash; i < CAKE_SET_WAYS;
@@ -830,6 +829,7 @@ found_src:
                }
 
                if (need_allocate_dst) {
+                       dsthost_idx = dsthost_hash % CAKE_QUEUES;
                        inner_hash = dsthost_idx % CAKE_SET_WAYS;
                        outer_hash = dsthost_idx - inner_hash;
                        for (i = 0, k = inner_hash; i < CAKE_SET_WAYS;

-----


More information about the Cake mailing list