]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon/defer: rewrite BASE_PRICE macro to function
authorLukáš Ondráček <lukas.ondracek@nic.cz>
Thu, 23 Apr 2026 14:02:53 +0000 (16:02 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 27 Apr 2026 07:07:21 +0000 (09:07 +0200)
daemon/defer.c

index d9fbbaf4a33e44813c23168b1177ec9a8547812a..d27986afbf31bd0667e7f31a31d56dd330cd1d8a 100644 (file)
@@ -42,10 +42,15 @@ V6_CONF = {1, V6_PREFIXES_CNT, V6_PREFIXES, V6_RATE_MULT, V6_SUBPRIO};
 
 #define Q0_INSTANT_LIMIT      1000000 // ns
 #define KRU_CAPACITY          (1<<19) // same as ratelimiting default
-#define BASE_PRICE(nsec)      ((nsec) >= UINT64_MAX / ((uint64_t)KRU_LIMIT * LOADS_THRESHOLDS[0] / (1<<16)) ? UINT64_MAX : \
-                                                       (uint64_t)KRU_LIMIT * LOADS_THRESHOLDS[0] / (1<<16) * (nsec) / Q0_INSTANT_LIMIT)
+static inline uint64_t BASE_PRICE(uint64_t nsec)
+{
        // with current settings BASE_PRICE(x) is approximately x
        // with nsec > ~(2<<32) the KRU limit is reached, so rounding >~(2<<44) to ~(2<<64) is OK
+       const uint64_t q0_kru_limit = (uint64_t)KRU_LIMIT * LOADS_THRESHOLDS[0] / (1<<16);
+       if (nsec >= UINT64_MAX / q0_kru_limit)
+               return UINT64_MAX;
+       return q0_kru_limit * nsec / Q0_INSTANT_LIMIT;
+}
 #define MAX_DECAY             (BASE_PRICE(1000000) / 2)  // max value at 50% utilization of single cpu
        //   see log written by defer_str_conf for details