[tor-commits] [tor] 09/15: math: Replace naughty macro by an inline function

gitolite role git at cupani.torproject.org
Tue Nov 8 17:49:45 UTC 2022


This is an automated email from the git hooks/post-receive script.

dgoulet pushed a commit to branch main
in repository tor.

commit 2066e0494c5ddb51af6decbe6941ea3495603fe2
Author: David Goulet <dgoulet at torproject.org>
AuthorDate: Mon Nov 7 10:01:47 2022 -0500

    math: Replace naughty macro by an inline function
    
    Part of #40708
    
    Signed-off-by: David Goulet <dgoulet at torproject.org>
---
 src/core/or/circuitlist.c              | 12 ++++++++----
 src/core/or/congestion_control_flow.c  | 12 ++++++++----
 src/core/or/congestion_control_vegas.c |  5 +++--
 src/lib/math/stats.h                   |  7 +++++--
 4 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/src/core/or/circuitlist.c b/src/core/or/circuitlist.c
index ddcb9bebe4..d1c734bdd2 100644
--- a/src/core/or/circuitlist.c
+++ b/src/core/or/circuitlist.c
@@ -2245,13 +2245,17 @@ circuit_mark_for_close_, (circuit_t *circ, int reason, int line,
        * averaging and reporting unused and low-use circuits here */
       if (circ->ccontrol->max_rtt_usec != circ->ccontrol->min_rtt_usec) {
         stats_circ_close_ss_cwnd_ma_count++;
-        STATS_UPDATE_AVG(cc_stats_circ_close_ss_cwnd_ma,
-                   circ->ccontrol->cwnd, stats_circ_close_ss_cwnd_ma_count);
+        cc_stats_circ_close_ss_cwnd_ma =
+          stats_update_running_avg(cc_stats_circ_close_ss_cwnd_ma,
+                                   circ->ccontrol->cwnd,
+                                   stats_circ_close_ss_cwnd_ma_count);
       }
     } else {
       stats_circ_close_cwnd_ma_count++;
-      STATS_UPDATE_AVG(cc_stats_circ_close_cwnd_ma,
-                       circ->ccontrol->cwnd, stats_circ_close_cwnd_ma_count);
+      cc_stats_circ_close_cwnd_ma =
+        stats_update_running_avg(cc_stats_circ_close_cwnd_ma,
+                                 circ->ccontrol->cwnd,
+                                 stats_circ_close_cwnd_ma_count);
     }
   }
 
diff --git a/src/core/or/congestion_control_flow.c b/src/core/or/congestion_control_flow.c
index cc120acd29..729e67b9a3 100644
--- a/src/core/or/congestion_control_flow.c
+++ b/src/core/or/congestion_control_flow.c
@@ -486,8 +486,10 @@ flow_control_decide_xoff(edge_connection_t *stream)
       tor_trace(TR_SUBSYS(cc), TR_EV(flow_decide_xoff_sending), stream);
 
       cc_stats_flow_xoff_outbuf_ma_count++;
-      STATS_UPDATE_AVG(cc_stats_flow_xoff_outbuf_ma,
-                       total_buffered, cc_stats_flow_xoff_outbuf_ma_count);
+      cc_stats_flow_xoff_outbuf_ma =
+        stats_update_running_avg(cc_stats_flow_xoff_outbuf_ma,
+                                 total_buffered,
+                                 cc_stats_flow_xoff_outbuf_ma_count);
 
       circuit_send_stream_xoff(stream);
 
@@ -645,8 +647,10 @@ flow_control_decide_xon(edge_connection_t *stream, size_t n_written)
       tor_trace(TR_SUBSYS(cc), TR_EV(flow_decide_xon_rate_change), stream);
 
       cc_stats_flow_xon_outbuf_ma_count++;
-      STATS_UPDATE_AVG(cc_stats_flow_xon_outbuf_ma,
-                       total_buffered, cc_stats_flow_xon_outbuf_ma_count);
+      cc_stats_flow_xon_outbuf_ma =
+        stats_update_running_avg(cc_stats_flow_xon_outbuf_ma,
+                                 total_buffered,
+                                 cc_stats_flow_xon_outbuf_ma_count);
 
       circuit_send_stream_xon(stream);
     }
diff --git a/src/core/or/congestion_control_vegas.c b/src/core/or/congestion_control_vegas.c
index 0aecf592aa..87f59d12fd 100644
--- a/src/core/or/congestion_control_vegas.c
+++ b/src/core/or/congestion_control_vegas.c
@@ -256,8 +256,9 @@ congestion_control_vegas_exit_slow_start(const circuit_t *circ,
 
   /* Update running cc->cwnd average for metrics. */
   stats_cwnd_exit_ss_ma_count++;
-  STATS_UPDATE_AVG(cc_stats_vegas_exit_ss_cwnd_ma,
-                   cc->cwnd, stats_cwnd_exit_ss_ma_count);
+  cc_stats_vegas_exit_ss_cwnd_ma =
+    stats_update_running_avg(cc_stats_vegas_exit_ss_cwnd_ma,
+                             cc->cwnd, stats_cwnd_exit_ss_ma_count);
 
   /* We need to report that slow start has exited ASAP,
    * for sbws bandwidth measurement. */
diff --git a/src/lib/math/stats.h b/src/lib/math/stats.h
index fae93c6213..328d61a9d6 100644
--- a/src/lib/math/stats.h
+++ b/src/lib/math/stats.h
@@ -13,7 +13,10 @@
 /** Update an average making it a "running average". The "avg" is the current
  * value that will be updated to the new one. The "value" is the new value to
  * add to the average and "n" is the new count as in including the "value". */
-#define STATS_UPDATE_AVG(avg, value, n) \
-  avg = ((avg) * ((n) - 1) + (value)) / (n)
+static inline double
+stats_update_running_avg(double avg, double value, double n)
+{
+  return ((avg * (n - 1)) + value) / n;
+}
 
 #endif /* !defined(TOR_STATS_H) */

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the tor-commits mailing list