]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
fixup! Add highwater counters
authorAlessio Podda <alessio@isc.org>
Tue, 9 Sep 2025 13:50:07 +0000 (15:50 +0200)
committerAlessio Podda <alessio@isc.org>
Wed, 24 Sep 2025 15:01:49 +0000 (17:01 +0200)
lib/isc/include/isc/statsmulti.h
lib/isc/statsmulti.c

index e539a945445371cb1f36bdc9e7b3295b06e9cf24..0b2a50cc5eff9e6d8053e1019551d42ddd525c8c 100644 (file)
@@ -123,22 +123,22 @@ void
 isc_statsmulti_update_if_greater(isc_statsmulti_t *stats, isc_statscounter_t counter, isc_statscounter_t value);
 /*%<
  * Update a highwater counter if the provided value is greater than the current per-thread value.
- * Only works on counters in the range [n_additive, n_additive + n_max).
+ * Takes counter values from 0 to n_max-1 and internally maps to the highwater range.
  *
  * Requires:
  *\li  'stats' is a valid isc_statsmulti_t.
  *
- *\li  counter is in the highwater range for the stats specified on creation.
+ *\li  counter is less than n_max specified on creation.
  */
 
 isc_statscounter_t
 isc_statsmulti_get_highwater(isc_statsmulti_t *stats, isc_statscounter_t counter);
 /*%<
  * Returns the maximum value across all threads for a highwater counter.
- * Only works on counters in the range [n_additive, n_additive + n_max).
+ * Takes counter values from 0 to n_max-1 and internally maps to the highwater range.
  *
  * Requires:
  *\li  'stats' is a valid isc_statsmulti_t.
  *
- *\li  counter is in the highwater range for the stats specified on creation.
+ *\li  counter is less than n_max specified on creation.
  */
\ No newline at end of file
index cf29fb8c1b8a0f6013acb4fed97a175f5411cfbc..4365e4ba79258f43b04ecb9386159ae41841b2a1 100644 (file)
@@ -180,15 +180,17 @@ isc_statsmulti_clear(isc_statsmulti_t *stats) {
 void
 isc_statsmulti_update_if_greater(isc_statsmulti_t *stats, isc_statscounter_t counter, isc_statscounter_t value) {
        REQUIRE(ISC_STATSMULTI_VALID(stats));
-       REQUIRE(counter >= stats->n_additive);
-       REQUIRE(counter < stats->ncounters);
+       REQUIRE(counter < stats->n_max);
+
+       /* Map counter to internal highwater position */
+       isc_statscounter_t internal_counter = stats->n_additive + counter;
 
        isc_tid_t tid = isc_tid();
        int thread_id = ISC_MAX(tid, 0);
        if (thread_id >= stats->num_threads) {
                thread_id = 0;
        }
-       int index = thread_id * stats->per_thread_capacity + counter;
+       int index = thread_id * stats->per_thread_capacity + internal_counter;
        
        /* Atomically update if the new value is greater than current */
        isc_statscounter_t current = atomic_load_relaxed(&stats->counters[index]);
@@ -203,13 +205,15 @@ isc_statsmulti_update_if_greater(isc_statsmulti_t *stats, isc_statscounter_t cou
 isc_statscounter_t
 isc_statsmulti_get_highwater(isc_statsmulti_t *stats, isc_statscounter_t counter) {
        REQUIRE(ISC_STATSMULTI_VALID(stats));
-       REQUIRE(counter >= stats->n_additive);
-       REQUIRE(counter < stats->ncounters);
+       REQUIRE(counter < stats->n_max);
+
+       /* Map counter to internal highwater position */
+       isc_statscounter_t internal_counter = stats->n_additive + counter;
 
        isc_statscounter_t max_value = 0;
        /* Find maximum value across all threads */
        for (int thread = 0; thread < stats->num_threads; thread++) {
-               int index = thread * stats->per_thread_capacity + counter;
+               int index = thread * stats->per_thread_capacity + internal_counter;
                isc_statscounter_t value = atomic_load_acquire(&stats->counters[index]);
                if (value > max_value) {
                        max_value = value;