From 09dbd19c88641fe59e3a6ce5b736f241ee2de676 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Sun, 16 Jun 2024 00:52:58 +0000 Subject: [PATCH] Remove extra shift in per_pkt_ns for readability Having a shift in one place and unshift in a totally different file is confusing. --- genrules.py | 2 +- xdp.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/genrules.py b/genrules.py index a9f3d16..69fa588 100755 --- a/genrules.py +++ b/genrules.py @@ -543,7 +543,7 @@ with open("rules.h", "w") as out: value *= 2**(exp-127) first_action = "int64_t time_masked = bpf_ktime_get_ns() & RATE_TIME_MASK;\n" - first_action += f"int64_t per_pkt_ns = (1000000000LL << RATE_BUCKET_INTEGER_BITS) / {math.floor(value)};\n" + first_action += f"int64_t per_pkt_ns = 1000000000LL / {math.floor(value)};\n" if ty == "0x8006" or ty == "0x8306": first_action += "uint64_t amt = data_end - pktdata;\n" else: diff --git a/xdp.c b/xdp.c index 860fe25..d5bd0b0 100644 --- a/xdp.c +++ b/xdp.c @@ -249,7 +249,7 @@ if (rate) { \ /* time difference / (our ns/packet limit * the size of the current packet). */ \ /* We shift by RATE_BUCKET_DECIMAL_BITS first since we're calculating whole packets. */ \ int64_t pkts_allowed_since_last_update = \ - (time_diff << RATE_BUCKET_BITS) / (((uint64_t)amt_in_pkt) * ((uint64_t)limit_ns_per_pkt)); \ + (time_diff << RATE_BUCKET_DECIMAL_BITS) / (((uint64_t)amt_in_pkt) * ((uint64_t)limit_ns_per_pkt)); \ bucket_pkts -= pkts_allowed_since_last_update; \ } \ /* Accept as long as we can add one to our bucket without overflow */ \ -- 2.39.5