diff options
author | Gerrit Renker <gerrit@erg.abdn.ac.uk> | 2008-09-04 01:30:19 -0400 |
---|---|---|
committer | Gerrit Renker <gerrit@erg.abdn.ac.uk> | 2008-09-04 01:45:34 -0400 |
commit | 535c55df136ad2783d444e54d518a8fae8bdbf79 (patch) | |
tree | 8f7b18bc7b82270e78061c4c22bf722534b743a1 /net/dccp | |
parent | 3306c781ff13aea89606435c134ec84e3c608681 (diff) |
dccp tfrc/ccid-3: Computing Loss Rate from Loss Event Rate
This adds a function to take care of the following cases occurring in the
computation of the Loss Rate p:
* 1/(2^32-1) is mapped into 0% as per RFC 4342, 8.5;
* 1/0 is mapped into the maximum of 100%;
* we want to avoid that p = 1/x is rounded down to 0 when x is very large,
since this means accidentally re-entering slow-start (indicated by p==0).
In the last case, the minimum-resolution value of p is returned.
Furthermore, a bug in ccid3_hc_rx_getsockopt is fixed (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);
Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
Diffstat (limited to 'net/dccp')
-rw-r--r-- | net/dccp/ccids/ccid3.c | 9 | ||||
-rw-r--r-- | net/dccp/ccids/lib/tfrc.h | 1 | ||||
-rw-r--r-- | net/dccp/ccids/lib/tfrc_equation.c | 17 |
3 files changed, 20 insertions, 7 deletions
diff --git a/net/dccp/ccids/ccid3.c b/net/dccp/ccids/ccid3.c index 4c422fb2189f..206204551f4d 100644 --- a/net/dccp/ccids/ccid3.c +++ b/net/dccp/ccids/ccid3.c | |||
@@ -410,10 +410,10 @@ static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb) | |||
410 | 410 | ||
411 | /* Update loss event rate (which is scaled by 1e6) */ | 411 | /* Update loss event rate (which is scaled by 1e6) */ |
412 | pinv = opt_recv->ccid3or_loss_event_rate; | 412 | pinv = opt_recv->ccid3or_loss_event_rate; |
413 | if (pinv == ~0U || pinv == 0) /* see RFC 4342, 8.5 */ | 413 | if (pinv == 0) |
414 | hctx->p = 0; | 414 | hctx->p = 0; |
415 | else /* can not exceed 100% */ | 415 | else |
416 | hctx->p = scaled_div(1, pinv); | 416 | hctx->p = tfrc_invert_loss_event_rate(pinv); |
417 | 417 | ||
418 | /* | 418 | /* |
419 | * Update allowed sending rate X as per draft rfc3448bis-00, 4.2/3 | 419 | * Update allowed sending rate X as per draft rfc3448bis-00, 4.2/3 |
@@ -854,8 +854,7 @@ static int ccid3_hc_rx_getsockopt(struct sock *sk, const int optname, int len, | |||
854 | return -EINVAL; | 854 | return -EINVAL; |
855 | rx_info.tfrcrx_x_recv = hcrx->x_recv; | 855 | rx_info.tfrcrx_x_recv = hcrx->x_recv; |
856 | rx_info.tfrcrx_rtt = hcrx->rtt; | 856 | rx_info.tfrcrx_rtt = hcrx->rtt; |
857 | rx_info.tfrcrx_p = hcrx->p_inverse == 0 ? ~0U : | 857 | rx_info.tfrcrx_p = tfrc_invert_loss_event_rate(hcrx->p_inverse); |
858 | scaled_div(1, hcrx->p_inverse); | ||
859 | len = sizeof(rx_info); | 858 | len = sizeof(rx_info); |
860 | val = &rx_info; | 859 | val = &rx_info; |
861 | break; | 860 | break; |
diff --git a/net/dccp/ccids/lib/tfrc.h b/net/dccp/ccids/lib/tfrc.h index ed9857527acf..bb47146ac7d1 100644 --- a/net/dccp/ccids/lib/tfrc.h +++ b/net/dccp/ccids/lib/tfrc.h | |||
@@ -58,6 +58,7 @@ static inline u32 tfrc_ewma(const u32 avg, const u32 newval, const u8 weight) | |||
58 | 58 | ||
59 | extern u32 tfrc_calc_x(u16 s, u32 R, u32 p); | 59 | extern u32 tfrc_calc_x(u16 s, u32 R, u32 p); |
60 | extern u32 tfrc_calc_x_reverse_lookup(u32 fvalue); | 60 | extern u32 tfrc_calc_x_reverse_lookup(u32 fvalue); |
61 | extern u32 tfrc_invert_loss_event_rate(u32 loss_event_rate); | ||
61 | 62 | ||
62 | extern int tfrc_tx_packet_history_init(void); | 63 | extern int tfrc_tx_packet_history_init(void); |
63 | extern void tfrc_tx_packet_history_exit(void); | 64 | extern void tfrc_tx_packet_history_exit(void); |
diff --git a/net/dccp/ccids/lib/tfrc_equation.c b/net/dccp/ccids/lib/tfrc_equation.c index 2f20a29cffe4..bc3dc2b2a849 100644 --- a/net/dccp/ccids/lib/tfrc_equation.c +++ b/net/dccp/ccids/lib/tfrc_equation.c | |||
@@ -658,7 +658,6 @@ u32 tfrc_calc_x(u16 s, u32 R, u32 p) | |||
658 | result = scaled_div(s, R); | 658 | result = scaled_div(s, R); |
659 | return scaled_div32(result, f); | 659 | return scaled_div32(result, f); |
660 | } | 660 | } |
661 | |||
662 | EXPORT_SYMBOL_GPL(tfrc_calc_x); | 661 | EXPORT_SYMBOL_GPL(tfrc_calc_x); |
663 | 662 | ||
664 | /** | 663 | /** |
@@ -693,5 +692,19 @@ u32 tfrc_calc_x_reverse_lookup(u32 fvalue) | |||
693 | index = tfrc_binsearch(fvalue, 0); | 692 | index = tfrc_binsearch(fvalue, 0); |
694 | return (index + 1) * 1000000 / TFRC_CALC_X_ARRSIZE; | 693 | return (index + 1) * 1000000 / TFRC_CALC_X_ARRSIZE; |
695 | } | 694 | } |
696 | |||
697 | EXPORT_SYMBOL_GPL(tfrc_calc_x_reverse_lookup); | 695 | EXPORT_SYMBOL_GPL(tfrc_calc_x_reverse_lookup); |
696 | |||
697 | /** | ||
698 | * tfrc_invert_loss_event_rate - Compute p so that 10^6 corresponds to 100% | ||
699 | * When @loss_event_rate is large, there is a chance that p is truncated to 0. | ||
700 | * To avoid re-entering slow-start in that case, we set p = TFRC_SMALLEST_P > 0. | ||
701 | */ | ||
702 | u32 tfrc_invert_loss_event_rate(u32 loss_event_rate) | ||
703 | { | ||
704 | if (loss_event_rate == UINT_MAX) /* see RFC 4342, 8.5 */ | ||
705 | return 0; | ||
706 | if (unlikely(loss_event_rate == 0)) /* map 1/0 into 100% */ | ||
707 | return 1000000; | ||
708 | return max_t(u32, scaled_div(1, loss_event_rate), TFRC_SMALLEST_P); | ||
709 | } | ||
710 | EXPORT_SYMBOL_GPL(tfrc_invert_loss_event_rate); | ||