diff options
author | Lukáš Ondráček <lukas.ondracek@nic.cz> | 2024-10-02 15:27:10 +0200 |
---|---|---|
committer | Lukáš Ondráček <lukas.ondracek@nic.cz> | 2024-10-02 15:27:10 +0200 |
commit | 027ce74f585b49b718357b6ddba5e98b3d3dcb5d (patch) | |
tree | a87212abbb52169942e49cb5fa0f1aeaaf5d8c21 /lib/kru.inc.c | |
parent | fixup! lib/log: add [defer ] group (diff) | |
download | knot-resolver-027ce74f585b49b718357b6ddba5e98b3d3dcb5d.tar.xz knot-resolver-027ce74f585b49b718357b6ddba5e98b3d3dcb5d.zip |
lib/kru: fix zero increment
Diffstat (limited to 'lib/kru.inc.c')
-rw-r--r-- | lib/kru.inc.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/kru.inc.c b/lib/kru.inc.c index 53a9f97b..078c8f06 100644 --- a/lib/kru.inc.c +++ b/lib/kru.inc.c @@ -229,7 +229,8 @@ struct query_ctx { struct load_cl *l[TABLE_COUNT]; uint32_t time_now; kru_price_t price; - uint16_t price16, limit16; + uint16_t price16; + uint32_t limit16; // 2^16 has to be representable uint16_t id; uint16_t final_load_value; // set by kru_limited_update if not blocked uint16_t *load; @@ -360,7 +361,7 @@ static inline bool kru_limited_fetch(struct kru *kru, struct query_ctx *ctx) const kru_price_t fract = price & ((((kru_price_t)1) << fract_bits) - 1); ctx->price16 = price >> fract_bits; - ctx->limit16 = -ctx->price16; + ctx->limit16 = (1<<16) - ctx->price16; if ((fract_bits > 0) && (fract > 0)) { ctx->price16 += (rand_bits(fract_bits) < fract); @@ -474,7 +475,7 @@ static inline bool kru_limited_update(struct kru *kru, struct query_ctx *ctx, bo static_assert(ATOMIC_CHAR16_T_LOCK_FREE == 2, "insufficient atomics"); const uint16_t price = ctx->price16; - const uint16_t limit = ctx->limit16; + const uint32_t limit = ctx->limit16; // 2^16 has to be representable uint16_t load_orig = atomic_load_explicit(load_at, memory_order_relaxed); uint16_t load_new; do { |