: Bug fixes and smaller TX socket
Subsystems (2)
cover : Bug fixes and smaller TX socket
In reply to a message not in the archiveA small set of updates, including a bug fix and, by removing redundancies, reducing the size of the CCID-3/4 socket by a further 18 bytes.
All changes have been uploaded to
git://eden-feed.erg.abdn.ac.uk/dccp_exp [dccp,ccid4]
and the `ccid4' subtree has been updated to mirror the changes to CCID-3.
Patch #1: Removes the ugly history-lookup function tfrc_tx_hist_rtt(), since
its complex passing of return values triggered ambiguous bug warnings; further subsuming/replacing an earlier test tree patch. The code format is thanks to an earlier suggestion by Arnaldo.
Patch #2: Removes some redundancies (32 lines) in ccid3_hc_tx_parse_options().
Patch #3: Allows ccid_hc_{tx,rx}_parse_options() to check the packet type on
which options where received, as necessitated by RFC 4340, 10.3.
Patch #4: Finds that the `options_received' sub-struct of ccid3_hc_tx_sock
is redundant, and removes it altogether. The conversion of received
options now happens directly, in ccid3_hc_tx_parse_options().
---------------------------------
***** Test Tree Update Note *****
---------------------------------Work on the last patch further helped to fix an omission in an earlier test tree patch entitled "[CCID-3]: Remove dead states". The difference below includes:
* the unnecessary test ("state != NO_FBACK") was removed (the timer is first started when changing from NO_SENT => NO_FBACK and from then on the state toggles between FBACK and NO_FBACK);
* the timer is instead disarmed when the socket is no longer in the established state: when closing the connection, it is not necessary to restart the nofeedback timer -- the connection is in its last stages anyway, and the relevant retransmissions of Close or CloseReq packets then happen as a matter of course;
* I think that the following BUG_ON in ccid3_hc_tx_no_feedback_timer(),
BUG_ON(hctx->p && !hctx->x_calc),
is now also redundant since, as long as the TX side receives feedback, tx_packet_recv is called after tx_parse_options, so that p > 0 leads to calling tfrc_calc_x().
net/dccp/ccids/ccid3.c +5 -2
@@ -213,10 +213,13 @@ static void ccid3_hc_tx_no_feedback_timer(unsigned longccid3_pr_debug ("%s(%p, state=%s) - entry \n" ,dccp_role (sk), sk,ccid3_tx_state_name (hctx->state)); +/* Ignore and do not restart after leaving the established state */ +if ((1 << sk->sk_state) & ~(DCCPF_OPEN |DCCPF_PARTOPEN )) + goto out; + +/* Reset feedback state to "no feedback received" */ if (hctx->state =TFRC_SSTATE_FBACK )ccid3_hc_tx_set_state (sk,TFRC_SSTATE_NO_FBACK ); -else if (hctx->state !=TFRC_SSTATE_NO_FBACK ) - goto out;/* * Determine new allowed sending rate X as per draft rfc3448bis-00, 4.4
The University of Aberdeen is a charity registered in Scotland, No SC013683.
PATCH 1/4 : Remove ugly RTT-sampling history lookup
This removes the RTT-sampling function tfrc_tx_hist_rtt(), since
1. it suffered from complex passing of return values (the return value both
indicated successful lookup and at the same time doubled as RTT sample);
2. when for some odd reason the sample value equalled 0, this triggered a bug
warning about "bogus Ack", due to the ambiguity of the return value;
3. on a passive host which has not sent anything the TX history is empty and
thus will lead to unwanted "bogus Ack" warnings such as
ccid3_hc_tx_packet_recv: server(e7b7d518): DATAACK with bogus ACK-28197148
ccid3_hc_tx_packet_recv: server(e7b7d518): DATAACK with bogus ACK-26641606.So this patch makes everything explicit that previously was implicit.
Furthermore, the "bogus Ack" warning has been removed, since it can actually be triggered due to several reasons (network reordering, old packet, (3) above), hence it is not very useful.
The format of this code is thanks to a suggestion by Arnaldo doing an earlier discussion -- which is in fact the clearer variant.
--- net/dccp/ccids/ccid3.c | 34 ++++++++++++++++------------- net/dccp/ccids/lib/packet_history.c | 40 ----------------------------------- net/dccp/ccids/lib/packet_history.h | 22 ++++++++++++++++-- 3 files changed, 38 insertions(+), 58 deletions(-)
net/dccp/ccids/ccid3.c +19 -15
@@ -367,6 +367,7 @@ static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb) {struct ccid3_hc_tx_sock *hctx =ccid3_hc_tx_sk (sk);struct ccid3_options_received *opt_recv = &hctx->options_received; +struct tfrc_tx_hist_entry *acked;ktime_t now;unsigned long t_nfb;u32 pinv, r_sample;
@@ -380,17 +381,24 @@ static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb) hctx->state != TFRC_SSTATE_NO_FBACK)return ; - now =ktime_get_real (); - -/* Estimate RTT from history if ACK number is valid */ - r_sample =tfrc_tx_hist_rtt (hctx->hist, -DCCP_SKB_CB (skb)->dccpd_ack_seq, now); -if (r_sample =0 ) { -DCCP_WARN ("%s(%p): %s with bogus ACK-%llu\n" ,dccp_role (sk), sk, -dccp_packet_name (DCCP_SKB_CB (skb)->dccpd_type), - (unsigned long long )DCCP_SKB_CB (skb)->dccpd_ack_seq); +/* +* Locate the acknowledged packet in the TX history. +* +* Returning "entry not found" here can for instance happen when +* - the host has not sent out anything (e.g. a passive server), +* - the Ack is outdated (packet with higher Ack number was received), +* - it is a bogus Ack (for a packet not sent on this connection). +*/ + acked =tfrc_tx_hist_find_entry (hctx->hist,dccp_hdr_ack_seq (skb)); +if (acked =NULL )return ; - } +/* For the sake of RTT sampling, ignore/remove all older entries */ +tfrc_tx_hist_purge (&acked->next); + +/* Update the moving average for the RTT estimate (RFC 3448, 4.3) */ + now =ktime_get_real (); + r_sample =dccp_sample_rtt (sk,ktime_us_delta (now, acked->stamp)); + hctx->rtt =tfrc_ewma (hctx->rtt, r_sample,9 );/* Update receive rate in units of 64 * bytes/second */ hctx->x_recv = opt_recv->ccid3or_receive_rate;
@@ -402,11 +410,7 @@ static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb) hctx->p =0 ; else /* can not exceed 100% */ hctx->p = scaled_div(1, pinv); -/* -* Validate new RTT sample and update moving average -*/ - r_sample =dccp_sample_rtt (sk, r_sample); - hctx->rtt =tfrc_ewma (hctx->rtt, r_sample,9 ); +/* * Update allowed sending rate X as per draft rfc3448bis-00, 4.2/3 */
net/dccp/ccids/lib/packet_history.h +19 -3
@@ -40,12 +40,28 @@#include <linux/slab.h> #include "tfrc.h" -struct tfrc_tx_hist_entry ; +/** +* tfrc_tx_hist_entry - Simple singly-linked TX history list +* @next: next oldest entry (LIFO order) +* @seqno: sequence number of this entry +* @stamp: send time of packet with sequence number @seqno +*/ +struct tfrc_tx_hist_entry { +struct tfrc_tx_hist_entry *next; +u64 seqno; +ktime_t stamp; +}; + +static inline struct tfrc_tx_hist_entry * +tfrc_tx_hist_find_entry (struct tfrc_tx_hist_entry *head,u64 seqno) +{ +while (head !=NULL && head->seqno != seqno) + head = head->next; +return head; +}extern int tfrc_tx_hist_add (struct tfrc_tx_hist_entry **headp,u64 seqno);extern void tfrc_tx_hist_purge (struct tfrc_tx_hist_entry **headp); -extern u32 tfrc_tx_hist_rtt (struct tfrc_tx_hist_entry *head, -const u64 seqno,const ktime_t now);/* Subtraction a-b modulo-16, respects circular wrap-around */ #define SUB16 (a, b) (((a) + 16 - (b)) & 0xF)
net/dccp/ccids/lib/packet_history.c +0 -40
@@ -40,18 +40,6 @@#include "packet_history.h" #include "../../dccp.h" -/** -* tfrc_tx_hist_entry - Simple singly-linked TX history list -* @next: next oldest entry (LIFO order) -* @seqno: sequence number of this entry -* @stamp: send time of packet with sequence number @seqno -*/ -struct tfrc_tx_hist_entry { -struct tfrc_tx_hist_entry *next; -u64 seqno; -ktime_t stamp; -}; -/* * Transmitter History Routines */
@@ -73,15 +61,6 @@ void tfrc_tx_packet_history_exit(void) } } -static struct tfrc_tx_hist_entry * -tfrc_tx_hist_find_entry (struct tfrc_tx_hist_entry *head,u64 seqno) -{ -while (head !=NULL && head->seqno != seqno) - head = head->next; - -return head; -} -int tfrc_tx_hist_add (struct tfrc_tx_hist_entry **headp,u64 seqno) {struct tfrc_tx_hist_entry *entry =kmem_cache_alloc (tfrc_tx_hist_slab,gfp_any ());
@@ -111,25 +90,6 @@ void tfrc_tx_hist_purge(struct tfrc_tx_hist_entry **headp) }EXPORT_SYMBOL_GPL (tfrc_tx_hist_purge); -u32 tfrc_tx_hist_rtt (struct tfrc_tx_hist_entry *head,const u64 seqno, -const ktime_t now) -{ -u32 rtt =0 ; -struct tfrc_tx_hist_entry *packet =tfrc_tx_hist_find_entry (head, seqno); - -if (packet !=NULL ) { - rtt =ktime_us_delta (now, packet->stamp); -/* -* Garbage-collect older (irrelevant) entries: -*/ -tfrc_tx_hist_purge (&packet->next); - } - -return rtt; -} -EXPORT_SYMBOL_GPL (tfrc_tx_hist_rtt); - -/* * Receiver History Routines */
The University of Aberdeen is a charity registered in Scotland, No SC013683.
PATCH 2/4 : Simplify tx_parse_options
This simplifies and consolidates the TX option-parsing code:
1. The Loss Intervals option is not currently used, so dead code related to this option is removed. I am aware of no plans to support the option, but if someone wants to implement it (e.g. for inter-op tests), it is better to start afresh than having to also update currently unused code.
2. The Loss Event and Receive Rate options have a lot of code in common (both are 32 bit, both have same length etc.), so this is consolidated.
3. The test against GSR is not necessary, because
- on first loading CCID3, ccid_new() zeroes out all fields in the socket;
- ccid3_hc_tx_packet_recv() treats 0 and ~0U equivalently, due to
pinv = opt_recv->ccid3or_loss_event_rate;
if (pinv = ~0U || pinv = 0)
hctx->p = 0;
- as a result, the sequence number field is removed from opt_recv.
--- net/dccp/ccids/ccid3.c | 57 +++++++++++------------------------------------ net/dccp/ccids/ccid3.h | 3 -- 2 files changed, 14 insertions(+), 46 deletions(-)
net/dccp/ccids/ccid3.h +0 -3
@@ -60,9 +60,6 @@ enum ccid3_options { };struct ccid3_options_received { -u64 ccid3or_seqno:48 , - ccid3or_loss_intervals_idx:16 ; -u16 ccid3or_loss_intervals_len;u32 ccid3or_loss_event_rate;u32 ccid3or_receive_rate; };
net/dccp/ccids/ccid3.c +14 -43
74 lines not on this page · raw message
The University of Aberdeen is a charity registered in Scotland, No SC013683.
PATCH 3/4 : CCID-specific option parsing routines need to know the packet type
This patch ...
1. adds packet type information to ccid_hc_{rx,tx}_parse_options(). This is necessary, since table 3 in RFC 4340, 5.8 leaves it to the CCIDs to state which options may (not) appear on what packet type.
2. adds such a check for CCID-3's {Loss Event, Receive} Rate as specified in RFC 4340 8.3 ("Receive Rate options MUST NOT be sent on DCCP-Data packets") and 8.5 ("Loss Event Rate options MUST NOT be sent on DCCP-Data packets").
3. removes an unused argument `idx' from ccid_hc_{rx,tx}_parse_options(). This is also no longer necessary, since the CCID-specific option-parsing routines are passed every single parameter of the type-length-value option encoding.
Added documentation and made argument naming scheme consistent.
--- net/dccp/ccid.h | 46 +++++++++++++++++++++++----------------------- net/dccp/ccids/ccid2.c | 7 +++---- net/dccp/ccids/ccid3.c | 14 ++++++++------ net/dccp/options.c | 6 ++---- 4 files changed, 36 insertions(+), 37 deletions(-)
net/dccp/ccid.h +23 -23
@@ -60,18 +60,14 @@ struct ccid_operations {void (*ccid_hc_tx_exit)(struct sock *sk);void (*ccid_hc_rx_packet_recv)(struct sock *sk,struct sk_buff *skb); -int (*ccid_hc_rx_parse_options)(struct sock *sk, -unsigned char option, -unsigned char len,u16 idx, -unsigned char * value); +int (*ccid_hc_rx_parse_options)(struct sock *sk,u8 pkt, +u8 opt,u8 *val,u8 len);int (*ccid_hc_rx_insert_options)(struct sock *sk,struct sk_buff *skb);void (*ccid_hc_tx_packet_recv)(struct sock *sk,struct sk_buff *skb); -int (*ccid_hc_tx_parse_options)(struct sock *sk, -unsigned char option, -unsigned char len,u16 idx, -unsigned char * value); +int (*ccid_hc_tx_parse_options)(struct sock *sk,u8 pkt, +u8 opt,u8 *val,u8 len);int (*ccid_hc_tx_send_packet)(struct sock *sk,struct sk_buff *skb); void (*ccid_hc_tx_packet_sent)(struct sock *sk,
@@ -185,27 +181,31 @@ static inline void ccid_hc_tx_packet_recv(struct ccid *ccid, struct sock *sk, ccid->ccid_ops->ccid_hc_tx_packet_recv (sk, skb); } +/** +* ccid_hc_tx_parse_options - Parse CCID-specific options sent by the receiver +* @pkt: type of packet that @opt appears on (RFC 4340, 5.1: 4-bit value) +* @opt: the CCID-specific option type (RFC 4340, 5.8 and 10.3) +* @val: value of @opt +* @len: length of @val in bytes +*/ static inline int ccid_hc_tx_parse_options (struct ccid *ccid,struct sock *sk, -unsigned char option, -unsigned char len,u16 idx, -unsigned char * value) +u8 pkt,u8 opt,u8 *val,u8 len) { -int rc =0 ; -if (ccid->ccid_ops->ccid_hc_tx_parse_options !=NULL ) - rc = ccid->ccid_ops->ccid_hc_tx_parse_options (sk, option, len, idx, - value); -return rc; +if (ccid->ccid_ops->ccid_hc_tx_parse_options =NULL ) +return 0 ; +return ccid->ccid_ops->ccid_hc_tx_parse_options (sk, pkt, opt, val, len); } +/** +* ccid_hc_rx_parse_options - Parse CCID-specific options sent by the sender +* Arguments are analogous to ccid_hc_tx_parse_options() +*/ static inline int ccid_hc_rx_parse_options (struct ccid *ccid,struct sock *sk, -unsigned char option, -unsigned char len,u16 idx, -unsigned char * value) +u8 pkt,u8 opt,u8 *val,u8 len) { -int rc =0 ; -if (ccid->ccid_ops->ccid_hc_rx_parse_options !=NULL ) - rc = ccid->ccid_ops->ccid_hc_rx_parse_options (sk, option, len, idx, value); -return rc; +if (ccid->ccid_ops->ccid_hc_rx_parse_options =NULL ) +return 0 ; +return ccid->ccid_ops->ccid_hc_rx_parse_options (sk, pkt, opt, val, len); } static inline int ccid_hc_rx_insert_options(struct ccid *ccid, struct sock *sk,
net/dccp/options.c +2 -4
@@ -218,8 +218,7 @@ int dccp_parse_options(struct sock *sk, struct dccp_request_sock *dreq,break ; case DCCPO_MIN_RX_CCID_SPECIFIC ... DCCPO_MAX_RX_CCID_SPECIFIC:if (ccid_hc_rx_parse_options (dp->dccps_hc_rx_ccid, sk, - opt, len, value - options, - value) !=0 ) + pkt_type, opt, value, len)) goto out_invalid_option;break ;case DCCPO_ACK_VECTOR_0 :
@@ -234,8 +233,7 @@ int dccp_parse_options(struct sock *sk, struct dccp_request_sock *dreq,*/ case DCCPO_MIN_TX_CCID_SPECIFIC ... DCCPO_MAX_TX_CCID_SPECIFIC:if (ccid_hc_tx_parse_options (dp->dccps_hc_tx_ccid, sk, - opt, len, value - options, - value) !=0 ) + pkt_type, opt, value, len)) goto out_invalid_option;break ;default :
net/dccp/ccids/ccid2.c +3 -4
@@ -375,16 +375,15 @@ static void ccid2_congestion_event(struct sock *sk, struct ccid2_seq *seqp)ccid2_change_l_ack_ratio (sk, hctx->cwnd); } -static int ccid2_hc_tx_parse_options (struct sock *sk,unsigned char option, -unsigned char len,u16 idx, -unsigned char *value) +static int ccid2_hc_tx_parse_options (struct sock *sk,u8 packet_type, +u8 option,u8 *optval,u8 optlen) {struct ccid2_hc_tx_sock *hctx =ccid2_hc_tx_sk (sk);switch (option) {case DCCPO_ACK_VECTOR_0 :case DCCPO_ACK_VECTOR_1 : -return dccp_ackvec_parsed_add (&hctx->av_chunks, value, len, +return dccp_ackvec_parsed_add (&hctx->av_chunks, optval, optlen, option -DCCPO_ACK_VECTOR_0 ); }return 0 ;
net/dccp/ccids/ccid3.c +8 -6
@@ -474,9 +474,8 @@ done_computing_x: jiffies + usecs_to_jiffies(t_nfb)); } -static int ccid3_hc_tx_parse_options (struct sock *sk,unsigned char option, -unsigned char len,u16 idx, -unsigned char *value) +static int ccid3_hc_tx_parse_options (struct sock *sk,u8 packet_type, +u8 option,u8 *optval,u8 optlen) {struct ccid3_hc_tx_sock *hctx =ccid3_hc_tx_sk (sk);struct ccid3_options_received *opt_recv = &hctx->options_received;
@@ -485,12 +484,15 @@ static int ccid3_hc_tx_parse_options(struct sock *sk, unsigned char option,switch (option) {case TFRC_OPT_RECEIVE_RATE :case TFRC_OPT_LOSS_EVENT_RATE : -if (unlikely (len !=4 )) { +/* Must be ignored on Data packets, cf. RFC 4342 8.3 and 8.5 */ +if (packet_type =DCCP_PKT_DATA ) +break ; +if (unlikely (optlen !=4 )) {DCCP_WARN ("%s(%p), invalid len %d for %u\n" , -dccp_role (sk), sk, len, option); +dccp_role (sk), sk, optlen, option);return -EINVAL ; } - opt_val =ntohl (get_unaligned ((__be32 *)value)); + opt_val =ntohl (get_unaligned ((__be32 *)optval));if (option =TFRC_OPT_RECEIVE_RATE ) { opt_recv->ccid3or_receive_rate = opt_val;
The University of Aberdeen is a charity registered in Scotland, No SC013683.
PATCH 4/4 : Remove indirection when parsing options
The options_received' struct is redundant, since it re-duplicates the existing p' and `x_recv' fields. This patch removes the sub-struct and migrates the related format conversion operations (cf. below) to ccid3_hc_tx_parse_options().
The patch also adds a convenience function to convert a reciprocal value into the loss rate p, performing the scaling and considering the two special cases:
* 1/(2^32-1) is mapped into 0% as per RFC 4342, 8.5;
* 1/0 is mapped into the maximum of 100%.
This further fixes a bug in ccid3_hc_rx_getsockopt (1/0 was mapped into ~0U), which now allows to consistently print the scaled p-values as
printf("Loss Event Rate = %u.%04u %%\n", rx_info.tfrcrx_p / 10000,
rx_info.tfrcrx_p % 10000);Lastly, documentation about the scaling factor used for fractions was added.
----------------------------------------------
Why the fields are redundant [can be removed]
----------------------------------------------The Loss Event Rate p and the Receive Rate x_recv are initially 0 when first loading CCID-3, as ccid_new() zeroes out the entire ccid3_hc_tx_sock.
When Loss Event Rate or Receive Rate options are received, they are stored by ccid3_hc_tx_parse_options() into the fields ccid3or_loss_event_rate' and ccid3or_receive_rate' of the sub-struct `options_received' in ccid3_hc_tx_sock.
After parsing (considering only the established state - dccp_rcv_established()), the packet is passed on to ccid_hc_tx_packet_recv(). This calls the CCID-3 specific routine ccid3_hc_tx_packet_recv(), which performs the following copy operations between fields of ccid3_hc_tx_sock:
* hctx->options_received.ccid3or_receive_rate is copied into hctx->x_recv, after scaling it for fixpoint arithmetic, by 2^64;
* hctx->options_received.ccid3or_loss_event_rate is copied into hctx->p, considering the above special cases; in addition, a value of 0 here needs to be mapped into p=0 (when no Loss Event Rate option has been received yet).
--- net/dccp/ccids/ccid3.c | 27 +++++++++------------------ net/dccp/ccids/ccid3.h | 9 +-------- net/dccp/ccids/lib/tfrc.h | 26 ++++++++++++++++++++++++-- 3 files changed, 34 insertions(+), 28 deletions(-)
net/dccp/ccids/ccid3.c +9 -18
@@ -366,11 +366,10 @@ static void ccid3_hc_tx_packet_sent(struct sock *sk, unsigned int len) static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb) { struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); - struct ccid3_options_received *opt_recv = &hctx->options_received; struct tfrc_tx_hist_entry *acked; ktime_t now; unsigned long t_nfb; - u32 pinv, r_sample; + u32 r_sample; /* we are only interested in ACKs */ if (!(DCCP_SKB_CB(skb)->dccpd_type = DCCP_PKT_ACK ||
@@ -395,17 +394,6 @@ static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb) r_sample =dccp_sample_rtt (sk,ktime_us_delta (now, acked->stamp)); hctx->rtt =tfrc_ewma (hctx->rtt, r_sample,9 ); -/* Update receive rate in units of 64 * bytes/second */ - hctx->x_recv = opt_recv->ccid3or_receive_rate; - hctx->x_recv <<=6 ; - -/* Update loss event rate (which is scaled by 1e6) */ - pinv = opt_recv->ccid3or_loss_event_rate; -if (pinv = ~0U || pinv =0 )/* see RFC 4342, 8.5 */ - hctx->p =0 ; -else /* can not exceed 100% */ - hctx->p =scaled_div (1 , pinv); -/* * Update allowed sending rate X as per draft rfc3448bis-00, 4.2/3 */
@@ -478,7 +466,6 @@ static int ccid3_hc_tx_parse_options(struct sock *sk, u8 packet_type, u8 option, u8 *optval, u8 optlen) { struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); -struct ccid3_options_received *opt_recv = &hctx->options_received;__be32 opt_val;switch (option) {
@@ -495,11 +482,16 @@ static int ccid3_hc_tx_parse_options(struct sock *sk, u8 packet_type, opt_val =ntohl (get_unaligned ((__be32 *)optval));if (option =TFRC_OPT_RECEIVE_RATE ) { - opt_recv->ccid3or_receive_rate = opt_val; +/* Receive Rate is kept in units of 64 bytes/second */ + hctx->x_recv = opt_val; + hctx->x_recv <<=6 ; +ccid3_pr_debug ("%s(%p), RECEIVE_RATE=%u\n" ,dccp_role (sk), sk, opt_val); }else { - opt_recv->ccid3or_loss_event_rate = opt_val; +/* Update the fixpoint Loss Event Rate fraction */ + hctx->p =tfrc_invert_loss_rate (opt_val); +ccid3_pr_debug ("%s(%p), LOSS_EVENT_RATE=%u\n" ,dccp_role (sk), sk, opt_val); }
@@ -836,8 +828,7 @@ static int ccid3_hc_rx_getsockopt(struct sock *sk, const int optname, int len,return -EINVAL ; rx_info.tfrcrx_x_recv = hcrx->x_recv; rx_info.tfrcrx_rtt = hcrx->rtt; - rx_info.tfrcrx_p = hcrx->p_inverse =0 ? ~0U : -scaled_div (1 , hcrx->p_inverse); + rx_info.tfrcrx_p =tfrc_invert_loss_rate (hcrx->p_inverse); len =sizeof (rx_info); val = &rx_info;break ;
net/dccp/ccids/ccid3.h +1 -8
@@ -59,11 +59,6 @@ enum ccid3_options { TFRC_OPT_RECEIVE_RATE = 194, }; -struct ccid3_options_received { -u32 ccid3or_loss_event_rate; -u32 ccid3or_receive_rate; -}; -/* TFRC sender states */ enum ccid3_hc_tx_states {TFRC_SSTATE_NO_SENT =1 ,
@@ -77,7 +72,7 @@ enum ccid3_hc_tx_states {* @x_recv - Receive rate in 64 * bytes per second * @x_calc - Calculated rate in bytes per second * @rtt - Estimate of current round trip time in usecs -* @p - Current loss event rate (0-1) scaled by 1000000 +* @p - Current loss event rate (0-1) scaled by %TFRC_SCALE * @s - Packet size in bytes * @t_rto - Nofeedback Timer setting in usecs * @t_ipi - Interpacket (send) interval (RFC 3448, 4.6) in usecs
@@ -90,7 +85,6 @@ enum ccid3_hc_tx_states {* @t_nom - Nominal send time of next packet * @delta - Send timer delta (RFC 3448, 4.6) in usecs * @hist - Packet history -* @options_received - Parsed set of retrieved options */ struct ccid3_hc_tx_sock {u64 x;
@@ -109,7 +103,6 @@ struct ccid3_hc_tx_sock {ktime_t t_nom;u32 delta;struct tfrc_tx_hist_entry *hist; -struct ccid3_options_received options_received; };static inline struct ccid3_hc_tx_sock *ccid3_hc_tx_sk (const struct sock *sk)
net/dccp/ccids/lib/tfrc.h +24 -2
@@ -28,11 +28,20 @@ extern int tfrc_debug; #define tfrc_pr_debug(format, a...)#endif -/* integer-arithmetic divisions of type (a * 1000000)/b */ +/* +* Routines and constants to perform scaled fixpoint arithmetic. +* +* To avoid carrying around the remainder of division operations, we scale all +* division operations by %TFRC_SCALE. The current factor is balanced, i.e. will +* not produce u32 overflow under reasonable conditions. In places where very +* large values could occur, scaled_div32() performs an additional sanity check. +*/ +#define TFRC_SCALE 1000000 +static inline u64 scaled_div (u64 a,u32 b) {BUG_ON (b=0 ); - a *=1000000 ; + a *=TFRC_SCALE ;do_div (a, b);return a; }
@@ -50,6 +59,19 @@ static inline u32 scaled_div32(u64 a, u32 b) }/** +* tfrc_invert_loss_rate - Invert reciprocal to give scaled Loss Event Rate p +* Maps @reciprocal into a percentage p so that 100% corresponds to %TFRC_SCALE. +* The highest possible value, 1/0, is mapped into 100%. The smallest possible +* value 1/UINT_MAX is rounded down to 0, using the convention of RFC 4342, 8.5. +*/ +static inline u32 tfrc_invert_loss_rate (const u32 reciprocal) +{ +if (reciprocal =UINT_MAX ) +return 0 ; +return reciprocal <=1 ?TFRC_SCALE :scaled_div (1 , reciprocal); +} + +/** * tfrc_ewma - Exponentially weighted moving average * @weight: Weight to be used as damping factor, in units of 1/10 */
Signature · 5 lines
1.5.5 The University of Aberdeen is a charity registered in Scotland, No SC013683.