dccp ccid-3: Further updates (second set)
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): dccp_ccid-3_second_set_of_updates
cover dccp ccid-3: Further updates (second set)
This second patch set continues the work on CCID-3, to update with regard to rfc3448bis, and to prepare for ECN support. Review and comments are welcome.
Patch #1: Migrates sampling of `s' and counting received bytes into tfrc_lib. Patch #2: Removes redundant RX states.
Patch #3: Continued RTT sampling and migration of RTT sampling into tfrc_lib. Patch #4: Isolates the min/max clamping functionality from dccp_sample_rtt(). Patch #5: Optimises the RTT sampling algorithm to increase number of samples. Patch #6: Updates computation of X_recv following changes to RFC 4342. Patch #7: Makes rx_handle_loss() the main point for dealing with congestion.
The now-updated test tree is available via
git://eden-feed.erg.abdn.ac.uk/dccp_exp (subtree `dccp')
There is also a web view available.
CCID-4 Notes:
-------------
All changes have been ported to the CCID-4 tree as well and are on
git://eden-feed.erg.abdn.ac.uk/dccp_exp (subtree `ccid4')
The following patches became obsolete as a result of this:
[CCID-3/4] Share TFRC receiver states via tfrc_ccids [CCID-3/4] Share ccid3_rx_state_name function via tfrc_ccids
PATCH 1/7 dccp tfrc: Let dccp_tfrc_lib do the sampling work
This migrates more TFRC-related code into the dccp_tfrc_lib:
* sampling of the packet size `s' (which is only needed until the first loss interval is computed (ccid3_first_li));
* updating the byte-counter `bytes_recvd' in between sending feedbacks.
The result is a better separation of CCID-3 specific and TFRC specific code, which aids future integration with ECN and e.g. CCID-4.
Further changes:
----------------
* replaced magic number of 536 with equivalent constant TCP_MIN_RCVMSS; (this constant is also used when no estimate for `s' is available).
--- net/dccp/ccids/ccid3.c | 38 +++++++--------------------------- net/dccp/ccids/ccid3.h | 4 --- net/dccp/ccids/lib/packet_history.c | 10 +++++++++ net/dccp/ccids/lib/packet_history.h | 16 ++++++++++++++ net/dccp/proto.c | 2 +- 5 files changed, 35 insertions(+), 35 deletions(-)
net/dccp/ccids/lib/packet_history.h +16 -0
@@ -91,12 +91,16 @@ struct tfrc_rx_hist_entry {* @loss_count: Number of entries in circular history * @loss_start: Movable index (for loss detection) * @rtt_sample_prev: Used during RTT sampling, points to candidate entry +* @packet_size: Packet size in bytes (as per RFC 3448, 3.1) +* @bytes_recvd: Number of bytes received since last sending feedback */ struct tfrc_rx_hist {struct tfrc_rx_hist_entry *ring[TFRC_NDUPACK +1 ];u8 loss_count:2 , loss_start:2 ;#define rtt_sample_prev loss_start +u32 packet_size, + bytes_recvd; };/**
@@ -140,6 +144,18 @@ static inline bool tfrc_rx_hist_loss_pending(const struct tfrc_rx_hist *h)return h->loss_count >0 ; } +/* +* Accessor functions to retrieve parameters sampled by the RX history +*/ +static inline u32 tfrc_rx_hist_packet_size (const struct tfrc_rx_hist *h) +{ +if (h->packet_size =0 ) { +DCCP_WARN ("No sample for s, using fallback\n" ); +return TCP_MIN_RCVMSS ; + } +return h->packet_size; +} +extern void tfrc_rx_hist_add_packet (struct tfrc_rx_hist *h,const struct sk_buff *skb,const u64 ndp);
net/dccp/ccids/lib/packet_history.c +10 -0
@@ -352,6 +352,16 @@ int tfrc_rx_handle_loss(struct tfrc_rx_hist *h,__three_after_loss (h); } +/* +* Update moving-average of `s' and the sum of received payload bytes. +*/ +if (dccp_data_packet (skb)) { +const u32 payload = skb->len -dccp_hdr (skb)->dccph_doff *4 ; + + h->packet_size =tfrc_ewma (h->packet_size, payload,9 ); + h->bytes_recvd += payload; + } +/* RFC 3448, 6.1: update I_0, whose growth implies p <= p_prev */ if (!is_new_loss)tfrc_lh_update_i_mean (lh, skb);
net/dccp/ccids/ccid3.h +0 -4
@@ -124,25 +124,21 @@ enum ccid3_hc_rx_states {* * @last_counter - Tracks window counter (RFC 4342, 8.1) * @state - Receiver state, one of %ccid3_hc_rx_states -* @bytes_recv - Total sum of DCCP payload bytes * @x_recv - Receiver estimate of send rate (RFC 3448, sec. 4.3) * @rtt - Receiver estimate of RTT * @tstamp_last_feedback - Time at which last feedback was sent * @hist - Packet history (loss detection + RTT sampling) * @li_hist - Loss Interval database -* @s - Received packet size in bytes * @p_inverse - Inverse of Loss Event Rate (RFC 4342, sec. 8.5) */ struct ccid3_hc_rx_sock {u8 last_counter:4 ;enum ccid3_hc_rx_states state:8 ; -u32 bytes_recv;u32 x_recv;u32 rtt;ktime_t tstamp_last_feedback;struct tfrc_rx_hist hist;struct tfrc_loss_hist li_hist; -u16 s;#define p_inverse li_hist.i_mean };
net/dccp/ccids/ccid3.c +8 -30
@@ -590,12 +590,9 @@ static void ccid3_hc_rx_send_feedback(struct sock *sk,* would bring X down to s/t_mbi. That is why we return * X_recv according to rfc3448bis-06 for the moment. */ -u32 rtt = hcrx->rtt ? :DCCP_FALLBACK_RTT , s = hcrx->s; +u32 rtt = hcrx->rtt ? :DCCP_FALLBACK_RTT , + s =tfrc_rx_hist_packet_size (&hcrx->hist); -if (s =0 ) { -DCCP_WARN ("No sample for s, using fallback\n" ); - s =TCP_MIN_RCVMSS ; - } hcrx->x_recv =scaled_div32 (s,2 * rtt);break ; }
@@ -617,7 +614,7 @@ static void ccid3_hc_rx_send_feedback(struct sock *sk,if (delta <=0 )DCCP_BUG ("delta (%ld) <= 0" , (long )delta);else - hcrx->x_recv =scaled_div32 (hcrx->bytes_recv, delta); + hcrx->x_recv =scaled_div32 (hcrx->hist.bytes_recvd, delta);break ;default :return ;
@@ -628,7 +625,7 @@ static void ccid3_hc_rx_send_feedback(struct sock *sk, hcrx->tstamp_last_feedback = now; hcrx->last_counter =dccp_hdr (skb)->dccph_ccval; - hcrx->bytes_recv =0 ; + hcrx->hist.bytes_recvd =0 ; dp->dccps_hc_rx_insert_options =1 ;dccp_send_ack (sk);
@@ -669,7 +666,8 @@ static int ccid3_hc_rx_insert_options(struct sock *sk, struct sk_buff *skb)static u32 ccid3_first_li (struct sock *sk) {struct ccid3_hc_rx_sock *hcrx =ccid3_hc_rx_sk (sk); -u32 x_recv, p, delta; +u32 x_recv, p, delta, + s =tfrc_rx_hist_packet_size (&hcrx->hist);u64 fval;/*
@@ -686,7 +684,7 @@ static u32 ccid3_first_li(struct sock *sk) } delta =ktime_to_us (net_timedelta (hcrx->tstamp_last_feedback)); - x_recv =scaled_div32 (hcrx->bytes_recv, delta); + x_recv =scaled_div32 (hcrx->hist.bytes_recvd, delta);if (x_recv =0 ) {/* would also trigger divide-by-zero */ DCCP_WARN ("X_recv=0\n" );if (hcrx->x_recv =0 ) {
@@ -696,8 +694,7 @@ static u32 ccid3_first_li(struct sock *sk) x_recv = hcrx->x_recv; } - fval =scaled_div (hcrx->s, hcrx->rtt); - fval =scaled_div32 (fval, x_recv); + fval =scaled_div32 (scaled_div (s, hcrx->rtt), x_recv); p =tfrc_calc_x_reverse_lookup (fval); ccid3_pr_debug("%s(%p), receive rate=%u bytes/s, implied "
@@ -724,31 +721,12 @@ static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)if (unlikely (hcrx->state =TFRC_RSTATE_NO_DATA )) {if (is_data_packet) { -const u32 payload = skb->len -dccp_hdr (skb)->dccph_doff *4 ; do_feedback =CCID3_FBACK_INITIAL ;ccid3_hc_rx_set_state (sk,TFRC_RSTATE_DATA ); - hcrx->s = payload; -/* -* Not necessary to update bytes_recv here, -* since X_recv = 0 for the first feedback packet (cf. -* RFC 3448, 6.3) -- gerrit -*/ } goto update_records; } -if (tfrc_rx_hist_duplicate (&hcrx->hist, skb)) -return ;/* done receiving */ - -if (is_data_packet) { -const u32 payload = skb->len -dccp_hdr (skb)->dccph_doff *4 ; -/* -* Update moving-average of s and the sum of received payload bytes -*/ - hcrx->s =tfrc_ewma (hcrx->s, payload,9 ); - hcrx->bytes_recv += payload; - } -if (tfrc_rx_hist_loss_pending (&hcrx->hist))return ;/* done receiving */
net/dccp/proto.c +1 -1
@@ -185,7 +185,7 @@ int dccp_init_sock(struct sock *sk, const __u8 ctl_sock_initialized) sk->sk_state =DCCP_CLOSED ; sk->sk_write_space = dccp_write_space; icsk->icsk_sync_mss = dccp_sync_mss; - dp->dccps_mss_cache =536 ; + dp->dccps_mss_cache =TCP_MIN_RCVMSS ; dp->dccps_rate_last = jiffies; dp->dccps_role =DCCP_ROLE_UNDEFINED ; dp->dccps_service =DCCP_SERVICE_CODE_IS_ABSENT ;
PATCH 2/7 dccp ccid-3: Remove redundant RX states
The only state information that the CCID-3 receiver keeps is whether initial feedback has been sent or not. Further, this overlaps with use of feedback:
* state = TFRC_RSTATE_NO_DATA as long as no feedback has been sent;
* state = TFRC_RSTATE_DATA as soon as the first feedback has been sent.
This patch reduces the duplication, by memorising the type of the last feedback.
--- net/dccp/ccids/ccid3.c | 47 +++++------------------------------------------ net/dccp/ccids/ccid3.h | 14 ++++++++------ 2 files changed, 13 insertions(+), 48 deletions(-)
net/dccp/ccids/ccid3.h +8 -6
@@ -114,16 +114,18 @@ static inline struct ccid3_hc_tx_sock *ccid3_hc_tx_sk(const struct sock *sk)return hctx; } -/* TFRC receiver states */ -enum ccid3_hc_rx_states { -TFRC_RSTATE_NO_DATA =1 , -TFRC_RSTATE_DATA , + +enum ccid3_fback_type { +CCID3_FBACK_NONE =0 , +CCID3_FBACK_INITIAL , +CCID3_FBACK_PERIODIC , +CCID3_FBACK_PARAM_CHANGE };/** struct ccid3_hc_rx_sock - CCID3 receiver half-connection socket * * @last_counter - Tracks window counter (RFC 4342, 8.1) -* @state - Receiver state, one of %ccid3_hc_rx_states +* @feedback - The type of the feedback last sent * @x_recv - Receiver estimate of send rate (RFC 3448, sec. 4.3) * @rtt - Receiver estimate of RTT * @tstamp_last_feedback - Time at which last feedback was sent
@@ -133,7 +135,7 @@ enum ccid3_hc_rx_states {*/ struct ccid3_hc_rx_sock {u8 last_counter:4 ; -enum ccid3_hc_rx_states state:8 ; +enum ccid3_fback_type feedback:4 ;u32 x_recv;u32 rtt;ktime_t tstamp_last_feedback;
net/dccp/ccids/ccid3.c +5 -42
90 lines not on this page · raw message
PATCH 3/7 dccp ccid-3: Always perform receiver RTT sampling
This updates the CCID-3 receiver in part with regard to errata 610 and 611
(http://www.rfc-editor.org/errata_list.php), which change RFC 4342 to use the definition of the Receive Rate X_recv as specified in rfc3448bis.
This requires to constantly sample the RTT throughout the connection, and to reuse the RX history for sampling after dealing with a loss.
Since this is all TFRC-based functionality, the RTT estimation is now also performed by the dccp_tfrc_lib module. This further simplifies the CCID-3 code.
The patch does not resolve how to compute X_recv if the interval is less than 1 RTT. A FIXME has been added (and is resolved by a subsequent patch).
--- net/dccp/ccids/ccid3.c | 43 ++++++++----------------- net/dccp/ccids/ccid3.h | 2 - net/dccp/ccids/lib/packet_history.c | 60 +++++++++++++++++++++++++--------- net/dccp/ccids/lib/packet_history.h | 17 +++++++++- 4 files changed, 73 insertions(+), 49 deletions(-)
net/dccp/ccids/lib/packet_history.h +15 -2
@@ -91,6 +91,7 @@ struct tfrc_rx_hist_entry {* @loss_count: Number of entries in circular history * @loss_start: Movable index (for loss detection) * @rtt_sample_prev: Used during RTT sampling, points to candidate entry +* @rtt_estimate: Receiver RTT estimate * @packet_size: Packet size in bytes (as per RFC 3448, 3.1) * @bytes_recvd: Number of bytes received since last sending feedback */
@@ -98,7 +99,10 @@ struct tfrc_rx_hist {struct tfrc_rx_hist_entry *ring[TFRC_NDUPACK +1 ]; u8 loss_count:2, loss_start:2; +/* Receiver RTT sampling */ #define rtt_sample_prev loss_start +u32 rtt_estimate; +/* Receiver sampling of application payload lengths */ u32 packet_size, bytes_recvd; };
@@ -154,6 +158,15 @@ static inline u32 tfrc_rx_hist_packet_size(const struct tfrc_rx_hist *h)return TCP_MIN_RCVMSS ; }return h->packet_size; + +} +static inline u32 tfrc_rx_hist_rtt (const struct tfrc_rx_hist *h) +{ +if (h->rtt_estimate =0 ) { +DCCP_WARN ("No RTT estimate available, using fallback RTT\n" ); +return DCCP_FALLBACK_RTT ; + } +return h->rtt_estimate; } extern void tfrc_rx_hist_add_packet(struct tfrc_rx_hist *h,
@@ -167,8 +180,8 @@ extern int tfrc_rx_handle_loss(struct tfrc_rx_hist *h, struct sk_buff *skb, const u64 ndp, u32 (*first_li)(struct sock *sk), struct sock *sk); -extern u32 tfrc_rx_hist_sample_rtt (struct tfrc_rx_hist *h, -const struct sk_buff *skb); +extern void tfrc_rx_hist_sample_rtt (struct tfrc_rx_hist *h, +const struct sk_buff *skb);extern int tfrc_rx_hist_init (struct tfrc_rx_hist *h,struct sock *sk);extern void tfrc_rx_hist_purge (struct tfrc_rx_hist *h);
net/dccp/ccids/lib/packet_history.c +44 -16
105 lines not on this page · raw message
net/dccp/ccids/ccid3.h +0 -2
@@ -127,7 +127,6 @@ enum ccid3_fback_type {* @last_counter - Tracks window counter (RFC 4342, 8.1) * @feedback - The type of the feedback last sent * @x_recv - Receiver estimate of send rate (RFC 3448, sec. 4.3) -* @rtt - Receiver estimate of RTT * @tstamp_last_feedback - Time at which last feedback was sent * @hist - Packet history (loss detection + RTT sampling) * @li_hist - Loss Interval database
@@ -137,7 +136,6 @@ struct ccid3_hc_rx_sock { u8 last_counter:4; enum ccid3_fback_type feedback:4;u32 x_recv; -u32 rtt;ktime_t tstamp_last_feedback;struct tfrc_rx_hist hist;struct tfrc_loss_hist li_hist;
net/dccp/ccids/ccid3.c +14 -29
93 lines not on this page · raw message
PATCH 4/7 dccp: Clamping RTT values
This extracts the clamping part of dccp_sample_rtt() and makes it available to other parts of the code (as e.g. used in the next patch).
Note: The function dccp_sample_rtt() now reduces to subtracting the elapsed time. This could be eliminated but would require shorter prefixes and thus is not done by this patch - maybe an idea for later.
--- net/dccp/dccp.h | 9 ++++++++- net/dccp/input.c | 11 +---------- 2 files changed, 9 insertions(+), 11 deletions(-)
net/dccp/dccp.h +8 -1
@@ -333,7 +333,14 @@ extern struct sk_buff *dccp_ctl_make_reset(struct sock *sk,extern int dccp_send_reset (struct sock *sk,enum dccp_reset_codes code);extern void dccp_send_close (struct sock *sk,const int active);extern int dccp_invalid_packet (struct sk_buff *skb); -extern u32 dccp_sample_rtt (struct sock *sk,long delta); + +static inline u32 dccp_sane_rtt (long usec_sample) +{ +if (unlikely (usec_sample <=0 || usec_sample >DCCP_SANE_RTT_MAX )) +DCCP_WARN ("RTT sample %ld out of bounds!\n" , usec_sample); +return clamp_val (usec_sample,DCCP_SANE_RTT_MIN ,DCCP_SANE_RTT_MAX ); +} +extern u32 dccp_sample_rtt (struct sock *sk,long delta);static inline int dccp_bad_service_code (const struct sock *sk,const __be32 service)
net/dccp/input.c +1 -10
@@ -707,16 +707,7 @@ u32 dccp_sample_rtt(struct sock *sk, long delta)/* dccpor_elapsed_time is either zeroed out or set and > 0 */ delta -=dccp_sk (sk)->dccps_options_received.dccpor_elapsed_time *10 ; -if (unlikely (delta <=0 )) { -DCCP_WARN ("unusable RTT sample %ld, using min\n" , delta); -return DCCP_SANE_RTT_MIN ; - } -if (unlikely (delta >DCCP_SANE_RTT_MAX )) { -DCCP_WARN ("RTT sample %ld too large, using max\n" , delta); -return DCCP_SANE_RTT_MAX ; - } - -return delta; +return dccp_sane_rtt (delta); }EXPORT_SYMBOL_GPL (dccp_sample_rtt);
PATCH 5/7 dccp tfrc: Increase number of RTT samples
This improves the receiver RTT sampling algorithm so that it tries harder to get as many RTT samples as possible, using several optimisations.
Applicability and background
----------------------------
The algorithm uses timestamps and differences of the CCval window counter to guess the RTT, using concepts presented in RFC 4340, 8.1.
There exist 4 cases for the CCVal difference:
* = 0: less than RTT/4 passed since last packet -- unusable sample;
* > 4: (much) more than 1 RTT has passed since last packet -- also unusable;
* = 4: "perfect" sample (exactly one RTT has passed since last packet);
* 1..3: sub-optimal sample (between RTT/4 and 3*RTT/4 has passed).
In the last case the algorithm so far tried to optimise by storing away the candidate and then re-trying next time. This had the following problems:
* a large number of samples is needed to smooth out the given inaccuracies;
* the sender may not be sending enough packets to warrant a "next time";
* hence it is better to use suboptimal samples whenever possible.
As a consequence, the algorithm now stores away the current sample only if the difference is 0.
A realistic example to illustrate the failure of the (previous) algorithm is MP3 streaming, where packets are sent at a rate of less than one packet per RTT. Which means that suitable samples may be absent for a very long time.
The effectiveness of using suboptimal samples (with a delta between 1 and 4) was confirmed by instrumenting the algorithm with counters. The results of two 20 second test runs were:
* With the old algorithm and a total of 38442 function calls, only 394 of these calls resulted in usable RTT samples (about 1%), 378 out of these were "perfect" samples, and 28013 (unused) samples had a delta of 1..3.
* With the new algorithm and a total of 37057 function calls, 1702 usable RTT samples were retrieved (about 4.6%), 5 out of these were "perfect" samples.
This means an almost five-fold increase in the number of samples.
--- net/dccp/ccids/lib/packet_history.c | 83 ++++++++++------------------------- 1 files changed, 24 insertions(+), 59 deletions(-)
net/dccp/ccids/lib/packet_history.c +24 -59
@@ -428,31 +428,16 @@ int tfrc_rx_hist_init(struct tfrc_rx_hist *h, struct sock *sk)EXPORT_SYMBOL_GPL (tfrc_rx_hist_init);/** -* tfrc_rx_hist_rtt_last_s - reference entry to compute RTT samples against -*/ -static inline struct tfrc_rx_hist_entry * -tfrc_rx_hist_rtt_last_s (const struct tfrc_rx_hist *h) -{ -return h->ring[0 ]; -} - -/** -* tfrc_rx_hist_rtt_prev_s: previously suitable (wrt rtt_last_s) RTT-sampling entry -*/ -static inline struct tfrc_rx_hist_entry * -tfrc_rx_hist_rtt_prev_s (const struct tfrc_rx_hist *h) -{ -return h->ring[h->rtt_sample_prev]; -} - -/** * tfrc_rx_hist_sample_rtt - Sample RTT from timestamp / CCVal -* Based on ideas presented in RFC 4342, 8.1. Returns 0 if it was not able -* to compute a sample with given data - calling function should check this. +* Based on ideas presented in RFC 4342, 8.1. This function expects that no loss +* is pending and uses the following history entries (via rtt_sample_prev): +* - h->ring[0] contains the most recent history entry prior to @skb; +* - h->ring[1] is an unused `dummy' entry when the current difference is 0; */ void tfrc_rx_hist_sample_rtt (struct tfrc_rx_hist *h,const struct sk_buff *skb) { -u32 sample =0 , delta_v; +struct tfrc_rx_hist_entry *last = h->ring[0 ]; +u32 sample, delta_v;/* * When not to sample:
@@ -466,47 +451,27 @@ void tfrc_rx_hist_sample_rtt(struct tfrc_rx_hist *h, const struct sk_buff *skb) tfrc_rx_hist_loss_pending(h))return ; - delta_v =SUB16 (dccp_hdr (skb)->dccph_ccval, -tfrc_rx_hist_rtt_last_s (h)->tfrchrx_ccval); - -if (delta_v <1 || delta_v >4 ) {/* unsuitable CCVal delta */ -if (h->rtt_sample_prev =2 ) {/* previous candidate stored */ - sample =SUB16 (tfrc_rx_hist_rtt_prev_s (h)->tfrchrx_ccval, -tfrc_rx_hist_rtt_last_s (h)->tfrchrx_ccval); -if (sample) - sample =4 / sample * -ktime_us_delta (tfrc_rx_hist_rtt_prev_s (h)->tfrchrx_tstamp, -tfrc_rx_hist_rtt_last_s (h)->tfrchrx_tstamp); -else /* -* FIXME: This condition is in principle not -* possible but occurs when CCID is used for -* two-way data traffic. I have tried to trace -* it, but the cause does not seem to be here. -*/ -DCCP_BUG ("please report to [email protected]" -" => prev = %u, last = %u" , -tfrc_rx_hist_rtt_prev_s (h)->tfrchrx_ccval, -tfrc_rx_hist_rtt_last_s (h)->tfrchrx_ccval); - }else if (delta_v <1 ) { - h->rtt_sample_prev =1 ; - goto keep_ref_for_next_time; - } - - }else if (delta_v =4 )/* optimal match */ - sample =ktime_to_us (net_timedelta (tfrc_rx_hist_rtt_last_s (h)->tfrchrx_tstamp)); -else {/* suboptimal match */ - h->rtt_sample_prev =2 ; - goto keep_ref_for_next_time; - } + h->rtt_sample_prev =0 ;/* reset previous candidate */ -if (unlikely (sample >DCCP_SANE_RTT_MAX )) { -DCCP_WARN ("RTT sample %u too large, using max\n" , sample); - sample =DCCP_SANE_RTT_MAX ; + delta_v =SUB16 (dccp_hdr (skb)->dccph_ccval, last->tfrchrx_ccval); +if (delta_v =0 ) {/* less than RTT/4 difference */ + h->rtt_sample_prev =1 ; +return ; } + sample =dccp_sane_rtt (ktime_to_us (net_timedelta (last->tfrchrx_tstamp))); - h->rtt_sample_prev =0 ;/* use current entry as next reference */ -keep_ref_for_next_time: +if (delta_v <=4 )/* between RTT/4 and RTT */ + sample *=4 / delta_v; +else if (!(sample < h->rtt_estimate && sample > h->rtt_estimate/2 )) +/* +* Optimisation: CCVal difference is greater than 1 RTT, yet the +* sample is less than the local RTT estimate; which means that +* the RTT estimate is too high. +* To avoid noise, it is not done if the sample is below RTT/2. +*/ +return ; - h->rtt_estimate =tfrc_ewma (h->rtt_estimate, sample,9 ); +/* Use a lower weight than usual to increase responsiveness */ + h->rtt_estimate =tfrc_ewma (h->rtt_estimate, sample,5 ); }EXPORT_SYMBOL_GPL (tfrc_rx_hist_sample_rtt);
PATCH 6/7 dccp ccid-3: Update the computation of X_recv
This updates the computation of X_recv with regard to Errata 610/611 for RFC 4342 and draft rfc3448bis-06, ensuring that at least an interval of 1 RTT is used to compute X_recv.
That change is wrapped into a new function, ccid3_hc_rx_x_recv().
Further changes:
----------------
* feedback is not sent when no data packets arrived (bytes_recv = 0), as per rfc3448bis-06, 6.2;
* take the timestamp for the feedback /after/ dccp_send_ack() returns, to avoid taking the transmission time into account (in case layer-2 is busy);
* clearer handling of failure in ccid3_first_li().
--- net/dccp/ccids/ccid3.c | 64 +++++++++++++---------------------- net/dccp/ccids/lib/packet_history.c | 30 ++++++++++++++++ net/dccp/ccids/lib/packet_history.h | 13 ++++++- 3 files changed, 66 insertions(+), 41 deletions(-)
net/dccp/ccids/ccid3.c +24 -40
@@ -533,9 +533,6 @@ static void ccid3_hc_rx_send_feedback(struct sock *sk, enum ccid3_fback_type fbtype) {struct ccid3_hc_rx_sock *hcrx =ccid3_hc_rx_sk (sk); -struct dccp_sock *dp =dccp_sk (sk); -ktime_t now =ktime_get_real (); -s64 delta =0 ;switch (fbtype) {case CCID3_FBACK_INITIAL :
@@ -565,42 +562,33 @@ static void ccid3_hc_rx_send_feedback(struct sock *sk,/* * When parameters change (new loss or p > p_prev), we do not * have a reliable estimate for R_m of [RFC 3448, 6.2] and so -* need to reuse the previous value of X_recv. However, when -* X_recv was 0 (due to early loss), this would kill X down to -* s/t_mbi (i.e. one packet in 64 seconds). -* To avoid such drastic reduction, we approximate X_recv as -* the number of bytes since last feedback. -* This is a safe fallback, since X is bounded above by X_calc. +* always check whether at least RTT time units were covered. */ -if (hcrx->x_recv >0 ) -break ; -/* fall through */ + hcrx->x_recv =tfrc_rx_hist_x_recv (&hcrx->hist, hcrx->x_recv); +break ;case CCID3_FBACK_PERIODIC :/* -* FIXME: check if delta is less than or equal to 1 RTT using -* the receiver RTT sample. This is described in Errata 610/611 -* of RFC 4342 which reference section 6.2 of RFC 3448. +* Step (2) of rfc3448bis-06, 6.2: +* - if no data packets have been received, just restart timer +* - if data packets have been received, re-compute X_recv */ - delta =ktime_us_delta (now, hcrx->tstamp_last_feedback); -if (delta <=0 ) -DCCP_BUG ("delta (%ld) <= 0" , (long )delta); -else - hcrx->x_recv =scaled_div32 (hcrx->hist.bytes_recvd, delta); +if (hcrx->hist.bytes_recvd =0 ) + goto prepare_for_next_time; + hcrx->x_recv =tfrc_rx_hist_x_recv (&hcrx->hist, hcrx->x_recv);break ;default :return ; } -ccid3_pr_debug ("Interval %ldusec, X_recv=%u, 1/p=%u\n" , - (long )delta, hcrx->x_recv, hcrx->p_inverse); +ccid3_pr_debug ("X_recv=%u, 1/p=%u\n" , hcrx->x_recv, hcrx->p_inverse); - hcrx->tstamp_last_feedback = now; - hcrx->last_counter =dccp_hdr (skb)->dccph_ccval; - hcrx->hist.bytes_recvd =0 ; - hcrx->feedback = fbtype; - - dp->dccps_hc_rx_insert_options =1 ; +dccp_sk (sk)->dccps_hc_rx_insert_options =1 ;dccp_send_ack (sk); + +prepare_for_next_time: +tfrc_rx_hist_restart_byte_counter (&hcrx->hist); + hcrx->last_counter =dccp_hdr (skb)->dccph_ccval; + hcrx->feedback = fbtype; }static int ccid3_hc_rx_insert_options (struct sock *sk,struct sk_buff *skb)
@@ -639,7 +627,7 @@ static u32 ccid3_first_li(struct sock *sk) {struct ccid3_hc_rx_sock *hcrx =ccid3_hc_rx_sk (sk);u32 s =tfrc_rx_hist_packet_size (&hcrx->hist), - rtt =tfrc_rx_hist_rtt (&hcrx->hist), x_recv, p, delta; + rtt =tfrc_rx_hist_rtt (&hcrx->hist), x_recv, p;u64 fval;/*
@@ -650,16 +638,9 @@ static u32 ccid3_first_li(struct sock *sk)if (unlikely (hcrx->feedback =CCID3_FBACK_NONE ))return 5 ; - delta =ktime_to_us (net_timedelta (hcrx->tstamp_last_feedback)); - x_recv =scaled_div32 (hcrx->hist.bytes_recvd, delta); -if (x_recv =0 ) {/* would also trigger divide-by-zero */ -DCCP_WARN ("X_recv=0\n" ); -if (hcrx->x_recv =0 ) { -DCCP_BUG ("stored value of X_recv is zero" ); -return ~0U ; - } - x_recv = hcrx->x_recv; - } + x_recv =tfrc_rx_hist_x_recv (&hcrx->hist, hcrx->x_recv); +if (x_recv =0 ) + goto failed; fval =scaled_div32 (scaled_div (s, rtt), x_recv); p =tfrc_calc_x_reverse_lookup (fval);
@@ -667,7 +648,10 @@ static u32 ccid3_first_li(struct sock *sk)ccid3_pr_debug ("%s(%p), receive rate=%u bytes/s, implied " "loss rate=%u\n" ,dccp_role (sk), sk, x_recv, p); -return p =0 ? ~0U :scaled_div (1 , p); +if (p >0 ) +return scaled_div (1 , p); +failed: +return UINT_MAX ; }static void ccid3_hc_rx_packet_recv (struct sock *sk,struct sk_buff *skb)
net/dccp/ccids/lib/packet_history.h +12 -1
@@ -93,7 +93,8 @@ struct tfrc_rx_hist_entry {* @rtt_sample_prev: Used during RTT sampling, points to candidate entry * @rtt_estimate: Receiver RTT estimate * @packet_size: Packet size in bytes (as per RFC 3448, 3.1) -* @bytes_recvd: Number of bytes received since last sending feedback +* @bytes_recvd: Number of bytes received since @bytes_start +* @bytes_start: Start time for counting @bytes_recvd */ struct tfrc_rx_hist {struct tfrc_rx_hist_entry *ring[TFRC_NDUPACK +1 ];
@@ -105,6 +106,7 @@ struct tfrc_rx_hist {/* Receiver sampling of application payload lengths */ u32 packet_size, bytes_recvd; +ktime_t bytes_start; };/**
@@ -169,6 +171,15 @@ static inline u32 tfrc_rx_hist_rtt(const struct tfrc_rx_hist *h)return h->rtt_estimate; } +static inline void tfrc_rx_hist_restart_byte_counter (struct tfrc_rx_hist *h) +{ + h->bytes_recvd =0 ; + h->bytes_start =ktime_get_real (); +} + +extern u32 tfrc_rx_hist_x_recv (struct tfrc_rx_hist *h,const u32 last_x_recv); + +extern void tfrc_rx_hist_add_packet (struct tfrc_rx_hist *h,const struct sk_buff *skb,const u64 ndp);
net/dccp/ccids/lib/packet_history.c +30 -0
@@ -385,6 +385,36 @@ int tfrc_rx_handle_loss(struct tfrc_rx_hist *h, }EXPORT_SYMBOL_GPL (tfrc_rx_handle_loss); +/* Compute the sending rate X_recv measured between feedback intervals */ +u32 tfrc_rx_hist_x_recv (struct tfrc_rx_hist *h,const u32 last_x_recv) +{ +u64 bytes = h->bytes_recvd, last_rtt = h->rtt_estimate; +s64 delta =ktime_to_us (net_timedelta (h->bytes_start)); + +WARN_ON (delta <=0 ); +/* +* Ensure that the sampling interval for X_recv is at least one RTT, +* by extending the sampling interval backwards in time, over the last +* R_(m-1) seconds, as per rfc3448bis-06, 6.2. +* To reduce noise (e.g. when the RTT changes often), this is only +* done when delta is smaller than RTT/2. +*/ +if (last_x_recv >0 && delta < last_rtt/2 ) { +tfrc_pr_debug ("delta < RTT => %ld us < %u us\n" , + (long )delta, (unsigned )last_rtt); + + delta = (bytes ? delta :0 ) + last_rtt; + bytes +=div_u64 ((u64 )last_x_recv * last_rtt,USEC_PER_SEC ); + } + +if (unlikely (bytes =0 )) { +DCCP_WARN ("X_recv = 0, using old value of %u\n" , last_x_recv); +return last_x_recv; + } +return scaled_div32 (bytes, delta); +} +EXPORT_SYMBOL_GPL (tfrc_rx_hist_x_recv); +void tfrc_rx_hist_purge (struct tfrc_rx_hist *h) {int i;
PATCH 7/7 dccp ccid-3: Update the RX history records in one place
This patch is a requirement for enabling ECN support later on. With that change in mind, the following preparations are done:
* lets tfrc_rx_congestion_event() always update the RX history records, since this routine needs to be called for each non-duplicate packet anyway;
* renamed handle_loss() into congestion_event() since it returns true when a congestion event happens (it will eventually also take care of ECN packets);
* changed all involved boolean-type functions to a return type of `bool'.
Updating the RX history records is now only necessary for the packets received up to sending the first feedback.
--- net/dccp/ccids/ccid3.c | 37 ++++++++++------------------------ net/dccp/ccids/lib/loss_interval.c | 10 ++++---- net/dccp/ccids/lib/loss_interval.h | 2 +- net/dccp/ccids/lib/packet_history.c | 37 +++++++++++++++++------------------ net/dccp/ccids/lib/packet_history.h | 10 ++++---- 5 files changed, 40 insertions(+), 56 deletions(-)
net/dccp/ccids/lib/packet_history.h +5 -5
@@ -186,11 +186,11 @@ extern void tfrc_rx_hist_add_packet(struct tfrc_rx_hist *h,extern int tfrc_rx_hist_duplicate (struct tfrc_rx_hist *h,struct sk_buff *skb);struct tfrc_loss_hist ; -extern int tfrc_rx_handle_loss (struct tfrc_rx_hist *h, -struct tfrc_loss_hist *lh, -struct sk_buff *skb,const u64 ndp, -u32 (*first_li)(struct sock *sk), -struct sock *sk); +extern bool tfrc_rx_congestion_event (struct tfrc_rx_hist *h, +struct tfrc_loss_hist *lh, +struct sk_buff *skb,const u64 ndp, +u32 (*first_li)(struct sock *sk), +struct sock *sk);extern void tfrc_rx_hist_sample_rtt (struct tfrc_rx_hist *h,const struct sk_buff *skb);extern int tfrc_rx_hist_init (struct tfrc_rx_hist *h,struct sock *sk);
net/dccp/ccids/lib/packet_history.c +18 -19
@@ -192,10 +192,8 @@ static void __do_track_loss(struct tfrc_rx_hist *h, struct sk_buff *skb, u64 n1)u64 s0 =tfrc_rx_hist_loss_prev (h)->tfrchrx_seqno, s1 =DCCP_SKB_CB (skb)->dccpd_seq; -if (!dccp_loss_free (s0, s1, n1)) {/* gap between S0 and S1 */ +if (!dccp_loss_free (s0, s1, n1))/* gap between S0 and S1 */ h->loss_count =1 ; -tfrc_rx_hist_entry_from_skb (tfrc_rx_hist_entry (h,1 ), skb, n1); - } }static void __one_after_loss (struct tfrc_rx_hist *h,struct sk_buff *skb,u32 n2)
@@ -328,13 +326,13 @@ static void __three_after_loss(struct tfrc_rx_hist *h) }/** -* tfrc_rx_handle_loss - Loss detection and further processing -* @h: The non-empty RX history object -* @lh: Loss Intervals database to update -* @skb: Currently received packet -* @ndp: The NDP count belonging to @skb -* @calc_first_li: Caller-dependent computation of first loss interval in @lh -* @sk: Used by @calc_first_li (see tfrc_lh_interval_add) +* tfrc_rx_congestion_event - Loss detection and further processing +* @h: The non-empty RX history object +* @lh: Loss Intervals database to update +* @skb: Currently received packet +* @ndp: The NDP count belonging to @skb +* @first_li: Caller-dependent computation of first loss interval in @lh +* @sk: Used by @calc_first_li (see tfrc_lh_interval_add) * Chooses action according to pending loss, updates LI database when a new * loss was detected, and does required post-processing. Returns 1 when caller * should send feedback, 0 otherwise.
@@ -342,12 +340,12 @@ static void __three_after_loss(struct tfrc_rx_hist *h)* records accordingly, the caller should not perform any more RX history * operations when loss_count is greater than 0 after calling this function. */ -int tfrc_rx_handle_loss (struct tfrc_rx_hist *h, -struct tfrc_loss_hist *lh, -struct sk_buff *skb,const u64 ndp, -u32 (*calc_first_li)(struct sock *),struct sock *sk) +bool tfrc_rx_congestion_event (struct tfrc_rx_hist *h, +struct tfrc_loss_hist *lh, +struct sk_buff *skb,const u64 ndp, +u32 (*first_li)(struct sock *),struct sock *sk) { -int is_new_loss =0 ; +bool new_event = false;if (tfrc_rx_hist_duplicate (h, skb))return 0 ;
@@ -355,6 +353,7 @@ int tfrc_rx_handle_loss(struct tfrc_rx_hist *h,if (h->loss_count =0 ) {__do_track_loss (h, skb, ndp);tfrc_rx_hist_sample_rtt (h, skb); +tfrc_rx_hist_add_packet (h, skb, ndp); }else if (h->loss_count =1 ) {__one_after_loss (h, skb, ndp); }else if (h->loss_count !=2 ) {
@@ -363,7 +362,7 @@ int tfrc_rx_handle_loss(struct tfrc_rx_hist *h,/* * Update Loss Interval database and recycle RX records */ - is_new_loss =tfrc_lh_interval_add (lh, h, calc_first_li, sk); + new_event =tfrc_lh_interval_add (lh, h, first_li, sk);__three_after_loss (h); }
@@ -378,12 +377,12 @@ int tfrc_rx_handle_loss(struct tfrc_rx_hist *h, }/* RFC 3448, 6.1: update I_0, whose growth implies p <= p_prev */ -if (!is_new_loss) +if (!new_event)tfrc_lh_update_i_mean (lh, skb); -return is_new_loss; +return new_event; } -EXPORT_SYMBOL_GPL (tfrc_rx_handle_loss); +EXPORT_SYMBOL_GPL (tfrc_rx_congestion_event);/* Compute the sending rate X_recv measured between feedback intervals */ u32 tfrc_rx_hist_x_recv (struct tfrc_rx_hist *h,const u32 last_x_recv)
net/dccp/ccids/lib/loss_interval.h +1 -1
@@ -67,7 +67,7 @@ static inline u8 tfrc_lh_length(struct tfrc_loss_hist *lh)struct tfrc_rx_hist ; -extern int tfrc_lh_interval_add (struct tfrc_loss_hist *,struct tfrc_rx_hist *, +extern bool tfrc_lh_interval_add (struct tfrc_loss_hist *,struct tfrc_rx_hist *,u32 (*first_li)(struct sock *),struct sock *);extern void tfrc_lh_update_i_mean (struct tfrc_loss_hist *lh,struct sk_buff *);extern void tfrc_lh_cleanup (struct tfrc_loss_hist *lh);
net/dccp/ccids/lib/loss_interval.c +5 -5
@@ -140,18 +140,18 @@ static inline u8 tfrc_lh_is_new_loss(struct tfrc_loss_interval *cur,* @sk: Used by @calc_first_li in caller-specific way (subtyping) * Updates I_mean and returns 1 if a new interval has in fact been added to @lh. */ -int tfrc_lh_interval_add (struct tfrc_loss_hist *lh,struct tfrc_rx_hist *rh, -u32 (*calc_first_li)(struct sock *),struct sock *sk) +bool tfrc_lh_interval_add (struct tfrc_loss_hist *lh,struct tfrc_rx_hist *rh, +u32 (*calc_first_li)(struct sock *),struct sock *sk) {struct tfrc_loss_interval *cur =tfrc_lh_peek (lh), *new;if (cur !=NULL && !tfrc_lh_is_new_loss (cur,tfrc_rx_hist_loss_prev (rh))) -return 0 ; +return false; new =tfrc_lh_demand_next (lh);if (unlikely (new =NULL )) {DCCP_CRIT ("Cannot allocate/add loss record." ); -return 0 ; +return false; } new->li_seqno =tfrc_rx_hist_loss_prev (rh)->tfrchrx_seqno;
@@ -169,7 +169,7 @@ int tfrc_lh_interval_add(struct tfrc_loss_hist *lh, struct tfrc_rx_hist *rh,tfrc_lh_calc_i_mean (lh); } -return 1 ; +return true; }EXPORT_SYMBOL_GPL (tfrc_lh_interval_add);
net/dccp/ccids/ccid3.c +11 -26
@@ -657,41 +657,26 @@ failed:static void ccid3_hc_rx_packet_recv (struct sock *sk,struct sk_buff *skb) {struct ccid3_hc_rx_sock *hcrx =ccid3_hc_rx_sk (sk); -enum ccid3_fback_type do_feedback =CCID3_FBACK_NONE ;const u64 ndp =dccp_sk (sk)->dccps_options_received.dccpor_ndp;const bool is_data_packet =dccp_data_packet (skb);/* * Perform loss detection and handle pending losses */ -if (tfrc_rx_handle_loss (&hcrx->hist, &hcrx->li_hist, - skb, ndp, ccid3_first_li, sk)) { - do_feedback =CCID3_FBACK_PARAM_CHANGE ; - goto done_receiving; - } - -if (unlikely (hcrx->feedback =CCID3_FBACK_NONE )) { -if (is_data_packet) - do_feedback =CCID3_FBACK_INITIAL ; - goto update_records; - } - -if (tfrc_rx_hist_loss_pending (&hcrx->hist)) -return ;/* done receiving */ - +if (tfrc_rx_congestion_event (&hcrx->hist, &hcrx->li_hist, + skb, ndp, ccid3_first_li, sk)) +ccid3_hc_rx_send_feedback (sk, skb,CCID3_FBACK_PARAM_CHANGE ); +/* +* Feedback for first non-empty data packet (RFC 3448, 6.3) +*/ +else if (unlikely (hcrx->feedback =CCID3_FBACK_NONE && is_data_packet)) +ccid3_hc_rx_send_feedback (sk, skb,CCID3_FBACK_INITIAL );/* * Check if the periodic once-per-RTT feedback is due; RFC 4342, 10.3 */ -if (is_data_packet && -SUB16 (dccp_hdr (skb)->dccph_ccval, hcrx->last_counter) >3 ) - do_feedback =CCID3_FBACK_PERIODIC ; - -update_records: -tfrc_rx_hist_add_packet (&hcrx->hist, skb, ndp); - -done_receiving: -if (do_feedback) -ccid3_hc_rx_send_feedback (sk, skb, do_feedback); +else if (!tfrc_rx_hist_loss_pending (&hcrx->hist) && is_data_packet && +SUB16 (dccp_hdr (skb)->dccph_ccval, hcrx->last_counter) >3 ) +ccid3_hc_rx_send_feedback (sk, skb,CCID3_FBACK_PERIODIC ); }static int ccid3_hc_rx_init (struct ccid *ccid,struct sock *sk)
Re: [PATCH 5/7] dccp tfrc: Increase number of RTT samples
In reply to Gerrit RenkerQuoted 36 lines · Gerrit Renker
This improves the receiver RTT sampling algorithm so that it tries harder to get as many RTT samples as possible, using several optimisations.
Applicability and background
----------------------------
The algorithm uses timestamps and differences of the CCval window counter to guess the RTT, using concepts presented in RFC 4340, 8.1.There exist 4 cases for the CCVal difference:
* = 0: less than RTT/4 passed since last packet -- unusable sample;
* > 4: (much) more than 1 RTT has passed since last packet -- also unusable;
* = 4: "perfect" sample (exactly one RTT has passed since last packet);
* 1..3: sub-optimal sample (between RTT/4 and 3*RTT/4 has passed).In the last case the algorithm so far tried to optimise by storing away the candidate and then re-trying next time. This had the following problems:
* a large number of samples is needed to smooth out the given inaccuracies;
* the sender may not be sending enough packets to warrant a "next time";
* hence it is better to use suboptimal samples whenever possible.
As a consequence, the algorithm now stores away the current sample only if the difference is 0.A realistic example to illustrate the failure of the (previous) algorithm is MP3 streaming, where packets are sent at a rate of less than one packet per RTT. Which means that suitable samples may be absent for a very long time.
The effectiveness of using suboptimal samples (with a delta between 1 and 4) was confirmed by instrumenting the algorithm with counters. The results of two 20 second test runs were:
* With the old algorithm and a total of 38442 function calls, only 394 of these calls resulted in usable RTT samples (about 1%), 378 out of these were "perfect" samples, and 28013 (unused) samples had a delta of 1..3.
* With the new algorithm and a total of 37057 function calls, 1702 usable RTT samples were retrieved (about 4.6%), 5 out of these were "perfect" samples.
This means an almost five-fold increase in the number of samples.
Quoted 1 line
Signed-off-by Gerrit Renker <[email protected]>
Great work. This should make a real improvement.
Re: [PATCH 5/7] dccp tfrc: Increase number of RTT samples
| > The effectiveness of using suboptimal samples (with a delta between 1 and 4) was | > confirmed by instrumenting the algorithm with counters. The results of two 20 | > second test runs were: | > * With the old algorithm and a total of 38442 function calls, only 394 of these | > calls resulted in usable RTT samples (about 1%), 378 out of these were | > "perfect" samples, and 28013 (unused) samples had a delta of 1..3. | > * With the new algorithm and a total of 37057 function calls, 1702 usable RTT | > samples were retrieved (about 4.6%), 5 out of these were "perfect" samples. | > This means an almost five-fold increase in the number of samples. | > | | Great work. This should make a real improvement. |
Unfortunately it does not change some of the conceptual problems. When the sender is sending at a rate of less than one packet per RTT then it can happen that there are no usable RTT samples for a long while.
MP3 streaming is an example, and there are other audio/voice streaming formats which also do not need to send more than one packet per RTT.
In one case of MP3 streaming there was not a single usable RTT estimate over the course of almost 1-2 hours (found via printk to syslot). What happens if meanwhile the link properties change?
I am not at all happy with this algorithm, it is probably as good as it can get, but it won't help if the sending rate is low.