diff options
-rw-r--r-- | src/core/or/circuitlist.c | 12 | ||||
-rw-r--r-- | src/core/or/congestion_control_flow.c | 12 | ||||
-rw-r--r-- | src/core/or/congestion_control_vegas.c | 5 | ||||
-rw-r--r-- | 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) */ |