Having a shift in one place and unshift in a totally different file
is confusing.
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:
/* 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 */ \