* [PATCH 24/29] Macro for moving average
@ 2007-04-12 21:17 Arnaldo Carvalho de Melo
2007-04-13 8:20 ` Gerrit Renker
0 siblings, 1 reply; 2+ messages in thread
From: Arnaldo Carvalho de Melo @ 2007-04-12 21:17 UTC (permalink / raw)
To: dccp
The moving average computation occurs so frequently in the CCID 3 code that
it merits a macro of its own.
Committer note: changed the patch to have it as an inline that returns the new
value, keeping the logic.
Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
Acked-by: Ian McDonald <ian.mcdonald@jandi.co.nz>
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
---
net/dccp/ccids/ccid3.c | 8 +++-----
net/dccp/ccids/lib/tfrc.h | 11 +++++++++++
2 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/net/dccp/ccids/ccid3.c b/net/dccp/ccids/ccid3.c
index 9474331..428aa92 100644
--- a/net/dccp/ccids/ccid3.c
+++ b/net/dccp/ccids/ccid3.c
@@ -183,7 +183,7 @@ static inline void ccid3_hc_tx_update_s(struct ccid3_hc_tx_sock *hctx, int len)
{
const u16 old_s = hctx->ccid3hctx_s;
- hctx->ccid3hctx_s = old_s = 0 ? len : (9 * old_s + len) / 10;
+ hctx->ccid3hctx_s = tfrc_ewma(hctx->ccid3hctx_s, len, 9);
if (hctx->ccid3hctx_s != old_s)
ccid3_update_send_interval(hctx);
@@ -474,8 +474,7 @@ static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
*
* q is a constant, RFC 3448 recommends 0.9
*/
- hctx->ccid3hctx_rtt = hctx->ccid3hctx_rtt = 0 ? r_sample
- : (9 * hctx->ccid3hctx_rtt + r_sample) / 10;
+ hctx->ccid3hctx_rtt = tfrc_ewma(hctx->ccid3hctx_rtt, r_sample, 9);
/*
* Update allowed sending rate as per draft rfc3448bis, 4.2/4.3
@@ -724,8 +723,7 @@ static inline void ccid3_hc_rx_update_s(struct ccid3_hc_rx_sock *hcrx, int len)
if (unlikely(len = 0)) /* don't update on empty packets (e.g. ACKs) */
ccid3_pr_debug("Packet payload length is 0 - not updating\n");
else
- hcrx->ccid3hcrx_s = hcrx->ccid3hcrx_s = 0 ? len :
- (9 * hcrx->ccid3hcrx_s + len) / 10;
+ hcrx->ccid3hcrx_s = tfrc_ewma(hcrx->ccid3hcrx_s, len, 9);
}
static void ccid3_hc_rx_send_feedback(struct sock *sk)
diff --git a/net/dccp/ccids/lib/tfrc.h b/net/dccp/ccids/lib/tfrc.h
index faf5f7e..6addc23 100644
--- a/net/dccp/ccids/lib/tfrc.h
+++ b/net/dccp/ccids/lib/tfrc.h
@@ -37,6 +37,17 @@ static inline u32 scaled_div32(u64 a, u32 b)
return result;
}
+/**
+ * Exponentially weighted moving average
+ * @weight: Weight to be used as damping factor, in units of 1/10
+ */
+static inline u32 tfrc_ewma(const u32 val, const u32 newval, const u8 weight)
+{
+ if (val != 0)
+ return (weight * val + (10 - weight) * newval) / 10;
+ return newval;
+}
+
extern u32 tfrc_calc_x(u16 s, u32 R, u32 p);
extern u32 tfrc_calc_x_reverse_lookup(u32 fvalue);
--
1.5.0.6
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 24/29] Macro for moving average
2007-04-12 21:17 [PATCH 24/29] Macro for moving average Arnaldo Carvalho de Melo
@ 2007-04-13 8:20 ` Gerrit Renker
0 siblings, 0 replies; 2+ messages in thread
From: Gerrit Renker @ 2007-04-13 8:20 UTC (permalink / raw)
To: dccp
Thanks a lot for the review & improving it. There is at least one more use of this function,
and it is now much better to read. Glad about it.
| The moving average computation occurs so frequently in the CCID 3 code that
| it merits a macro of its own.
|
| Committer note: changed the patch to have it as an inline that returns the new
| value, keeping the logic.
|
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-04-13 8:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-12 21:17 [PATCH 24/29] Macro for moving average Arnaldo Carvalho de Melo
2007-04-13 8:20 ` Gerrit Renker
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.