mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-24 22:58:50 +01:00
math: Replace naughty macro by an inline function
Part of #40708 Signed-off-by: David Goulet <dgoulet@torproject.org>
This commit is contained in:
parent
fec9757a37
commit
2066e0494c
4 changed files with 24 additions and 12 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -256,7 +256,8 @@ 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_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,
|
||||
|
|
|
@ -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) */
|
||||
|
|
Loading…
Add table
Reference in a new issue