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:40 -0400 |
commit | 24b8d343215919c7a2ba18b9f89a0961e1459cad (patch) | |
tree | 2b97062dae6e80bb178a0cd0354aa71fe884ef30 /net/dccp | |
parent | 8b67ad12b04ef7bdf5d2b4de24fe5a609b26cf12 (diff) |
dccp tfrc: Receiver history initialisation routine
This patch
1) separates history allocation and initialisation, to facilitate early
loss detection (implemented by a subsequent patch);
2) removes duplication by using the existing tfrc_rx_hist_purge() if the
allocation fails. This is now possible, since the initialisation routine
3) zeroes out the entire history before using it.
Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
Diffstat (limited to 'net/dccp')
-rw-r--r-- | net/dccp/ccids/ccid3.c | 2 | ||||
-rw-r--r-- | net/dccp/ccids/lib/packet_history.c | 52 | ||||
-rw-r--r-- | net/dccp/ccids/lib/packet_history.h | 2 |
3 files changed, 32 insertions, 24 deletions
diff --git a/net/dccp/ccids/ccid3.c b/net/dccp/ccids/ccid3.c index 5470a978be02..36f4992f3c38 100644 --- a/net/dccp/ccids/ccid3.c +++ b/net/dccp/ccids/ccid3.c | |||
@@ -766,7 +766,7 @@ static int ccid3_hc_rx_init(struct ccid *ccid, struct sock *sk) | |||
766 | 766 | ||
767 | hcrx->state = TFRC_RSTATE_NO_DATA; | 767 | hcrx->state = TFRC_RSTATE_NO_DATA; |
768 | tfrc_lh_init(&hcrx->li_hist); | 768 | tfrc_lh_init(&hcrx->li_hist); |
769 | return tfrc_rx_hist_alloc(&hcrx->hist); | 769 | return tfrc_rx_hist_init(&hcrx->hist, sk); |
770 | } | 770 | } |
771 | 771 | ||
772 | static void ccid3_hc_rx_exit(struct sock *sk) | 772 | static void ccid3_hc_rx_exit(struct sock *sk) |
diff --git a/net/dccp/ccids/lib/packet_history.c b/net/dccp/ccids/lib/packet_history.c index 5c4450866904..5b4e1cf8439d 100644 --- a/net/dccp/ccids/lib/packet_history.c +++ b/net/dccp/ccids/lib/packet_history.c | |||
@@ -352,28 +352,6 @@ int tfrc_rx_handle_loss(struct tfrc_rx_hist *h, | |||
352 | } | 352 | } |
353 | EXPORT_SYMBOL_GPL(tfrc_rx_handle_loss); | 353 | EXPORT_SYMBOL_GPL(tfrc_rx_handle_loss); |
354 | 354 | ||
355 | int tfrc_rx_hist_alloc(struct tfrc_rx_hist *h) | ||
356 | { | ||
357 | int i; | ||
358 | |||
359 | for (i = 0; i <= TFRC_NDUPACK; i++) { | ||
360 | h->ring[i] = kmem_cache_alloc(tfrc_rx_hist_slab, GFP_ATOMIC); | ||
361 | if (h->ring[i] == NULL) | ||
362 | goto out_free; | ||
363 | } | ||
364 | |||
365 | h->loss_count = h->loss_start = 0; | ||
366 | return 0; | ||
367 | |||
368 | out_free: | ||
369 | while (i-- != 0) { | ||
370 | kmem_cache_free(tfrc_rx_hist_slab, h->ring[i]); | ||
371 | h->ring[i] = NULL; | ||
372 | } | ||
373 | return -ENOBUFS; | ||
374 | } | ||
375 | EXPORT_SYMBOL_GPL(tfrc_rx_hist_alloc); | ||
376 | |||
377 | void tfrc_rx_hist_purge(struct tfrc_rx_hist *h) | 355 | void tfrc_rx_hist_purge(struct tfrc_rx_hist *h) |
378 | { | 356 | { |
379 | int i; | 357 | int i; |
@@ -386,6 +364,36 @@ void tfrc_rx_hist_purge(struct tfrc_rx_hist *h) | |||
386 | } | 364 | } |
387 | EXPORT_SYMBOL_GPL(tfrc_rx_hist_purge); | 365 | EXPORT_SYMBOL_GPL(tfrc_rx_hist_purge); |
388 | 366 | ||
367 | static int tfrc_rx_hist_alloc(struct tfrc_rx_hist *h) | ||
368 | { | ||
369 | int i; | ||
370 | |||
371 | memset(h, 0, sizeof(*h)); | ||
372 | |||
373 | for (i = 0; i <= TFRC_NDUPACK; i++) { | ||
374 | h->ring[i] = kmem_cache_alloc(tfrc_rx_hist_slab, GFP_ATOMIC); | ||
375 | if (h->ring[i] == NULL) { | ||
376 | tfrc_rx_hist_purge(h); | ||
377 | return -ENOBUFS; | ||
378 | } | ||
379 | } | ||
380 | return 0; | ||
381 | } | ||
382 | |||
383 | int tfrc_rx_hist_init(struct tfrc_rx_hist *h, struct sock *sk) | ||
384 | { | ||
385 | if (tfrc_rx_hist_alloc(h)) | ||
386 | return -ENOBUFS; | ||
387 | /* | ||
388 | * Initialise first entry with GSR to start loss detection as early as | ||
389 | * possible. Code using this must not use any other fields. The entry | ||
390 | * will be overwritten once the CCID updates its received packets. | ||
391 | */ | ||
392 | tfrc_rx_hist_loss_prev(h)->tfrchrx_seqno = dccp_sk(sk)->dccps_gsr; | ||
393 | return 0; | ||
394 | } | ||
395 | EXPORT_SYMBOL_GPL(tfrc_rx_hist_init); | ||
396 | |||
389 | /** | 397 | /** |
390 | * tfrc_rx_hist_rtt_last_s - reference entry to compute RTT samples against | 398 | * tfrc_rx_hist_rtt_last_s - reference entry to compute RTT samples against |
391 | */ | 399 | */ |
diff --git a/net/dccp/ccids/lib/packet_history.h b/net/dccp/ccids/lib/packet_history.h index 221d8102da51..e9d8097947d5 100644 --- a/net/dccp/ccids/lib/packet_history.h +++ b/net/dccp/ccids/lib/packet_history.h | |||
@@ -153,7 +153,7 @@ extern int tfrc_rx_handle_loss(struct tfrc_rx_hist *h, | |||
153 | struct sock *sk); | 153 | struct sock *sk); |
154 | extern u32 tfrc_rx_hist_sample_rtt(struct tfrc_rx_hist *h, | 154 | extern u32 tfrc_rx_hist_sample_rtt(struct tfrc_rx_hist *h, |
155 | const struct sk_buff *skb); | 155 | const struct sk_buff *skb); |
156 | extern int tfrc_rx_hist_alloc(struct tfrc_rx_hist *h); | 156 | extern int tfrc_rx_hist_init(struct tfrc_rx_hist *h, struct sock *sk); |
157 | extern void tfrc_rx_hist_purge(struct tfrc_rx_hist *h); | 157 | extern void tfrc_rx_hist_purge(struct tfrc_rx_hist *h); |
158 | 158 | ||
159 | #endif /* _DCCP_PKT_HIST_ */ | 159 | #endif /* _DCCP_PKT_HIST_ */ |