diff options
author | Arnaldo Carvalho de Melo <acme@mandriva.com> | 2005-08-27 23:03:09 -0300 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2005-08-29 16:12:17 -0700 |
commit | ae6706f0678b89de07ad3b456893cc883584f711 (patch) | |
tree | d9d854ccb0bf7124d98dfaad959f34c11cceef23 | |
parent | cfc3c525a3b434cabf92bf7054f2c6c93497fbea (diff) | |
download | blackbird-op-linux-ae6706f0678b89de07ad3b456893cc883584f711.tar.gz blackbird-op-linux-ae6706f0678b89de07ad3b456893cc883584f711.zip |
[CCID3]: Move the loss interval code to loss_interval.[ch]
And put this into net/dccp/ccids/lib/, where packet_history.[ch] will also be
moved and then we'll have a tfrc_lib.ko module that will be used by
dccp_ccid3.ko and other CCIDs that are variations of TFRC (RFC 3448).
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | net/dccp/ccids/Makefile | 2 | ||||
-rw-r--r-- | net/dccp/ccids/ccid3.c | 155 | ||||
-rw-r--r-- | net/dccp/ccids/ccid3.h | 11 | ||||
-rw-r--r-- | net/dccp/ccids/lib/loss_interval.c | 144 | ||||
-rw-r--r-- | net/dccp/ccids/lib/loss_interval.h | 61 |
5 files changed, 234 insertions, 139 deletions
diff --git a/net/dccp/ccids/Makefile b/net/dccp/ccids/Makefile index 1c720131c5db..323b68f3b607 100644 --- a/net/dccp/ccids/Makefile +++ b/net/dccp/ccids/Makefile @@ -1,3 +1,3 @@ obj-$(CONFIG_IP_DCCP_CCID3) += dccp_ccid3.o -dccp_ccid3-y := ccid3.o +dccp_ccid3-y := ccid3.o lib/loss_interval.o diff --git a/net/dccp/ccids/ccid3.c b/net/dccp/ccids/ccid3.c index cfd11234d8f9..7468928b83c6 100644 --- a/net/dccp/ccids/ccid3.c +++ b/net/dccp/ccids/ccid3.c @@ -38,6 +38,7 @@ #include "../ccid.h" #include "../dccp.h" #include "../packet_history.h" +#include "lib/loss_interval.h" #include "ccid3.h" /* @@ -62,30 +63,7 @@ static int ccid3_debug; static struct dccp_tx_hist *ccid3_tx_hist; static struct dccp_rx_hist *ccid3_rx_hist; - -static kmem_cache_t *ccid3_loss_interval_hist_slab __read_mostly; - -static inline struct ccid3_loss_interval_hist_entry * - ccid3_loss_interval_hist_entry_new(const unsigned int __nocast prio) -{ - return kmem_cache_alloc(ccid3_loss_interval_hist_slab, prio); -} - -static inline void ccid3_loss_interval_hist_entry_delete(struct ccid3_loss_interval_hist_entry *entry) -{ - if (entry != NULL) - kmem_cache_free(ccid3_loss_interval_hist_slab, entry); -} - -static void ccid3_loss_interval_history_delete(struct list_head *hist) -{ - struct ccid3_loss_interval_hist_entry *entry, *next; - - list_for_each_entry_safe(entry, next, hist, ccid3lih_node) { - list_del_init(&entry->ccid3lih_node); - kmem_cache_free(ccid3_loss_interval_hist_slab, entry); - } -} +static struct dccp_li_hist *ccid3_li_hist; static int ccid3_init(struct sock *sk) { @@ -1414,7 +1392,7 @@ trim_history: */ num_later = TFRC_RECV_NUM_LATE_LOSS + 1; - if (!list_empty(&hcrx->ccid3hcrx_loss_interval_hist)) { + if (!list_empty(&hcrx->ccid3hcrx_li_hist)) { list_for_each_entry_safe(entry, next, &hcrx->ccid3hcrx_hist, dccphrx_node) { if (num_later == 0) { @@ -1555,15 +1533,6 @@ static void ccid3_hc_rx_insert_options(struct sock *sk, struct sk_buff *skb) &x_recv, sizeof(x_recv)); } -/* Weights used to calculate loss event rate */ -/* - * These are integers as per section 8 of RFC3448. We can then divide by 4 * - * when we use it. - */ -static const int ccid3_hc_rx_w[TFRC_RECV_IVAL_F_LENGTH] = { - 4, 4, 4, 4, 3, 2, 1, 1, -}; - /* * args: fvalue - function value to match * returns: p closest to that value @@ -1672,41 +1641,17 @@ static void ccid3_hc_rx_update_li(struct sock *sk, u64 seq_loss, u8 win_loss) { struct dccp_sock *dp = dccp_sk(sk); struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private; - struct ccid3_loss_interval_hist_entry *li_entry; - if (seq_loss != DCCP_MAX_SEQNO + 1) { - ccid3_pr_debug("%s, sk=%p, seq_loss=%llu, win_loss=%u, " - "packet loss detected\n", - dccp_role(sk), sk, seq_loss, win_loss); - - if (list_empty(&hcrx->ccid3hcrx_loss_interval_hist)) { - struct ccid3_loss_interval_hist_entry *li_tail = NULL; - int i; - - ccid3_pr_debug("%s, sk=%p, first loss event detected, " - "creating history\n", - dccp_role(sk), sk); - for (i = 0; i <= TFRC_RECV_IVAL_F_LENGTH; ++i) { - li_entry = ccid3_loss_interval_hist_entry_new(SLAB_ATOMIC); - if (li_entry == NULL) { - ccid3_loss_interval_history_delete(&hcrx->ccid3hcrx_loss_interval_hist); - ccid3_pr_debug("%s, sk=%p, not enough " - "mem for creating " - "history\n", - dccp_role(sk), sk); - return; - } - if (li_tail == NULL) - li_tail = li_entry; - list_add(&li_entry->ccid3lih_node, - &hcrx->ccid3hcrx_loss_interval_hist); - } + if (seq_loss != DCCP_MAX_SEQNO + 1 && + list_empty(&hcrx->ccid3hcrx_li_hist)) { + struct dccp_li_hist_entry *li_tail; - li_entry->ccid3lih_seqno = seq_loss; - li_entry->ccid3lih_win_count = win_loss; - - li_tail->ccid3lih_interval = ccid3_hc_rx_calc_first_li(sk); - } + li_tail = dccp_li_hist_interval_new(ccid3_li_hist, + &hcrx->ccid3hcrx_li_hist, + seq_loss, win_loss); + if (li_tail == NULL) + return; + li_tail->dccplih_interval = ccid3_hc_rx_calc_first_li(sk); } /* FIXME: find end of interval */ } @@ -1746,12 +1691,11 @@ static void ccid3_hc_rx_detect_loss(struct sock *sk) } if (a_loss == NULL) { - if (list_empty(&hcrx->ccid3hcrx_loss_interval_hist)) { + if (list_empty(&hcrx->ccid3hcrx_li_hist)) { /* no loss event have occured yet */ - ccid3_pr_debug("%s, sk=%p, TODO: find a lost data " - "packet by comparing to initial " - "seqno\n", - dccp_role(sk), sk); + LIMIT_NETDEBUG("%s: TODO: find a lost data packet by " + "comparing to initial seqno\n", + dccp_role(sk)); goto out_update_li; } else { pr_info("%s: %s, sk=%p, ERROR! Less than 4 data " @@ -1799,48 +1743,6 @@ out_update_li: ccid3_hc_rx_update_li(sk, seq_loss, win_loss); } -static u32 ccid3_hc_rx_calc_i_mean(struct sock *sk) -{ - struct dccp_sock *dp = dccp_sk(sk); - struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private; - struct ccid3_loss_interval_hist_entry *li_entry, *li_next; - int i = 0; - u32 i_tot; - u32 i_tot0 = 0; - u32 i_tot1 = 0; - u32 w_tot = 0; - - list_for_each_entry_safe(li_entry, li_next, - &hcrx->ccid3hcrx_loss_interval_hist, - ccid3lih_node) { - if (i < TFRC_RECV_IVAL_F_LENGTH) { - i_tot0 += li_entry->ccid3lih_interval * ccid3_hc_rx_w[i]; - w_tot += ccid3_hc_rx_w[i]; - } - - if (i != 0) - i_tot1 += li_entry->ccid3lih_interval * ccid3_hc_rx_w[i - 1]; - - if (++i > TFRC_RECV_IVAL_F_LENGTH) - break; - } - - if (i != TFRC_RECV_IVAL_F_LENGTH) { - pr_info("%s: %s, sk=%p, ERROR! Missing entry in " - "interval history!\n", - __FUNCTION__, dccp_role(sk), sk); - return 0; - } - - i_tot = max(i_tot0, i_tot1); - - /* FIXME: Why do we do this? -Ian McDonald */ - if (i_tot * 4 < w_tot) - i_tot = w_tot * 4; - - return i_tot * 4 / w_tot; -} - static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb) { struct dccp_sock *dp = dccp_sk(sk); @@ -1939,9 +1841,9 @@ static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb) p_prev = hcrx->ccid3hcrx_p; /* Calculate loss event rate */ - if (!list_empty(&hcrx->ccid3hcrx_loss_interval_hist)) + if (!list_empty(&hcrx->ccid3hcrx_li_hist)) /* Scaling up by 1000000 as fixed decimal */ - hcrx->ccid3hcrx_p = 1000000 / ccid3_hc_rx_calc_i_mean(sk); + hcrx->ccid3hcrx_p = 1000000 / dccp_li_hist_calc_i_mean(&hcrx->ccid3hcrx_li_hist); if (hcrx->ccid3hcrx_p > p_prev) { ccid3_hc_rx_send_feedback(sk); @@ -1971,7 +1873,7 @@ static int ccid3_hc_rx_init(struct sock *sk) hcrx->ccid3hcrx_state = TFRC_RSTATE_NO_DATA; INIT_LIST_HEAD(&hcrx->ccid3hcrx_hist); - INIT_LIST_HEAD(&hcrx->ccid3hcrx_loss_interval_hist); + INIT_LIST_HEAD(&hcrx->ccid3hcrx_li_hist); /* * XXX this seems to be paranoid, need to think more about this, for * now start with something different than zero. -acme @@ -1996,7 +1898,7 @@ static void ccid3_hc_rx_exit(struct sock *sk) dccp_rx_hist_purge(ccid3_rx_hist, &hcrx->ccid3hcrx_hist); /* Empty loss interval history */ - ccid3_loss_interval_history_delete(&hcrx->ccid3hcrx_loss_interval_hist); + dccp_li_hist_purge(ccid3_li_hist, &hcrx->ccid3hcrx_li_hist); kfree(dp->dccps_hc_rx_ccid_private); dp->dccps_hc_rx_ccid_private = NULL; @@ -2063,11 +1965,8 @@ static __init int ccid3_module_init(void) if (ccid3_tx_hist == NULL) goto out_free_rx; - ccid3_loss_interval_hist_slab = kmem_cache_create("li_hist_ccid3", - sizeof(struct ccid3_loss_interval_hist_entry), - 0, SLAB_HWCACHE_ALIGN, - NULL, NULL); - if (ccid3_loss_interval_hist_slab == NULL) + ccid3_li_hist = dccp_li_hist_new("ccid3"); + if (ccid3_li_hist == NULL) goto out_free_tx; rc = ccid_register(&ccid3); @@ -2077,8 +1976,8 @@ out: return rc; out_free_loss_interval_history: - kmem_cache_destroy(ccid3_loss_interval_hist_slab); - ccid3_loss_interval_hist_slab = NULL; + dccp_li_hist_delete(ccid3_li_hist); + ccid3_li_hist = NULL; out_free_tx: dccp_tx_hist_delete(ccid3_tx_hist); ccid3_tx_hist = NULL; @@ -2110,9 +2009,9 @@ static __exit void ccid3_module_exit(void) dccp_rx_hist_delete(ccid3_rx_hist); ccid3_rx_hist = NULL; } - if (ccid3_loss_interval_hist_slab != NULL) { - kmem_cache_destroy(ccid3_loss_interval_hist_slab); - ccid3_loss_interval_hist_slab = NULL; + if (ccid3_li_hist != NULL) { + dccp_li_hist_delete(ccid3_li_hist); + ccid3_li_hist = NULL; } } module_exit(ccid3_module_exit); diff --git a/net/dccp/ccids/ccid3.h b/net/dccp/ccids/ccid3.h index f8965700bbe9..f68d0b4e31e9 100644 --- a/net/dccp/ccids/ccid3.h +++ b/net/dccp/ccids/ccid3.h @@ -59,8 +59,6 @@ #define TFRC_SMALLEST_P 40 -#define TFRC_RECV_IVAL_F_LENGTH 8 - /* Number of later packets received before one is considered lost */ #define TFRC_RECV_NUM_LATE_LOSS 3 @@ -119,13 +117,6 @@ struct ccid3_hc_tx_sock { struct ccid3_options_received ccid3hctx_options_received; }; -struct ccid3_loss_interval_hist_entry { - struct list_head ccid3lih_node; - u64 ccid3lih_seqno:48, - ccid3lih_win_count:4; - u32 ccid3lih_interval; -}; - struct ccid3_hc_rx_sock { u64 ccid3hcrx_seqno_last_counter:48, ccid3hcrx_state:8, @@ -136,7 +127,7 @@ struct ccid3_hc_rx_sock { struct timeval ccid3hcrx_tstamp_last_feedback; struct timeval ccid3hcrx_tstamp_last_ack; struct list_head ccid3hcrx_hist; - struct list_head ccid3hcrx_loss_interval_hist; + struct list_head ccid3hcrx_li_hist; u16 ccid3hcrx_s; u32 ccid3hcrx_pinv; u32 ccid3hcrx_elapsed_time; diff --git a/net/dccp/ccids/lib/loss_interval.c b/net/dccp/ccids/lib/loss_interval.c new file mode 100644 index 000000000000..4c01a54143ad --- /dev/null +++ b/net/dccp/ccids/lib/loss_interval.c @@ -0,0 +1,144 @@ +/* + * net/dccp/ccids/lib/loss_interval.c + * + * Copyright (c) 2005 The University of Waikato, Hamilton, New Zealand. + * Copyright (c) 2005 Ian McDonald <iam4@cs.waikato.ac.nz> + * Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@conectiva.com.br> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include <linux/config.h> +#include <linux/module.h> + +#include "loss_interval.h" + +struct dccp_li_hist *dccp_li_hist_new(const char *name) +{ + struct dccp_li_hist *hist = kmalloc(sizeof(*hist), GFP_ATOMIC); + static const char dccp_li_hist_mask[] = "li_hist_%s"; + char *slab_name; + + if (hist == NULL) + goto out; + + slab_name = kmalloc(strlen(name) + sizeof(dccp_li_hist_mask) - 1, + GFP_ATOMIC); + if (slab_name == NULL) + goto out_free_hist; + + sprintf(slab_name, dccp_li_hist_mask, name); + hist->dccplih_slab = kmem_cache_create(slab_name, + sizeof(struct dccp_li_hist_entry), + 0, SLAB_HWCACHE_ALIGN, + NULL, NULL); + if (hist->dccplih_slab == NULL) + goto out_free_slab_name; +out: + return hist; +out_free_slab_name: + kfree(slab_name); +out_free_hist: + kfree(hist); + hist = NULL; + goto out; +} + +EXPORT_SYMBOL_GPL(dccp_li_hist_new); + +void dccp_li_hist_delete(struct dccp_li_hist *hist) +{ + const char* name = kmem_cache_name(hist->dccplih_slab); + + kmem_cache_destroy(hist->dccplih_slab); + kfree(name); + kfree(hist); +} + +EXPORT_SYMBOL_GPL(dccp_li_hist_delete); + +void dccp_li_hist_purge(struct dccp_li_hist *hist, struct list_head *list) +{ + struct dccp_li_hist_entry *entry, *next; + + list_for_each_entry_safe(entry, next, list, dccplih_node) { + list_del_init(&entry->dccplih_node); + kmem_cache_free(hist->dccplih_slab, entry); + } +} + +EXPORT_SYMBOL_GPL(dccp_li_hist_purge); + +/* Weights used to calculate loss event rate */ +/* + * These are integers as per section 8 of RFC3448. We can then divide by 4 * + * when we use it. + */ +static const int dccp_li_hist_w[DCCP_LI_HIST_IVAL_F_LENGTH] = { + 4, 4, 4, 4, 3, 2, 1, 1, +}; + +u32 dccp_li_hist_calc_i_mean(struct list_head *list) +{ + struct dccp_li_hist_entry *li_entry, *li_next; + int i = 0; + u32 i_tot; + u32 i_tot0 = 0; + u32 i_tot1 = 0; + u32 w_tot = 0; + + list_for_each_entry_safe(li_entry, li_next, list, dccplih_node) { + if (i < DCCP_LI_HIST_IVAL_F_LENGTH) { + i_tot0 += li_entry->dccplih_interval * dccp_li_hist_w[i]; + w_tot += dccp_li_hist_w[i]; + } + + if (i != 0) + i_tot1 += li_entry->dccplih_interval * dccp_li_hist_w[i - 1]; + + if (++i > DCCP_LI_HIST_IVAL_F_LENGTH) + break; + } + + if (i != DCCP_LI_HIST_IVAL_F_LENGTH) + return 0; + + i_tot = max(i_tot0, i_tot1); + + /* FIXME: Why do we do this? -Ian McDonald */ + if (i_tot * 4 < w_tot) + i_tot = w_tot * 4; + + return i_tot * 4 / w_tot; +} + +EXPORT_SYMBOL_GPL(dccp_li_hist_calc_i_mean); + +struct dccp_li_hist_entry *dccp_li_hist_interval_new(struct dccp_li_hist *hist, + struct list_head *list, + const u64 seq_loss, + const u8 win_loss) +{ + struct dccp_li_hist_entry *tail = NULL, *entry; + int i; + + for (i = 0; i <= DCCP_LI_HIST_IVAL_F_LENGTH; ++i) { + entry = dccp_li_hist_entry_new(hist, SLAB_ATOMIC); + if (entry == NULL) { + dccp_li_hist_purge(hist, list); + return NULL; + } + if (tail == NULL) + tail = entry; + list_add(&entry->dccplih_node, list); + } + + entry->dccplih_seqno = seq_loss; + entry->dccplih_win_count = win_loss; + return tail; +} + +EXPORT_SYMBOL_GPL(dccp_li_hist_interval_new); diff --git a/net/dccp/ccids/lib/loss_interval.h b/net/dccp/ccids/lib/loss_interval.h new file mode 100644 index 000000000000..13ad47ba1420 --- /dev/null +++ b/net/dccp/ccids/lib/loss_interval.h @@ -0,0 +1,61 @@ +#ifndef _DCCP_LI_HIST_ +#define _DCCP_LI_HIST_ +/* + * net/dccp/ccids/lib/loss_interval.h + * + * Copyright (c) 2005 The University of Waikato, Hamilton, New Zealand. + * Copyright (c) 2005 Ian McDonald <iam4@cs.waikato.ac.nz> + * Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@conectiva.com.br> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + */ + +#include <linux/config.h> +#include <linux/list.h> +#include <linux/slab.h> +#include <linux/time.h> + +#define DCCP_LI_HIST_IVAL_F_LENGTH 8 + +struct dccp_li_hist { + kmem_cache_t *dccplih_slab; +}; + +extern struct dccp_li_hist *dccp_li_hist_new(const char *name); +extern void dccp_li_hist_delete(struct dccp_li_hist *hist); + +struct dccp_li_hist_entry { + struct list_head dccplih_node; + u64 dccplih_seqno:48, + dccplih_win_count:4; + u32 dccplih_interval; +}; + +static inline struct dccp_li_hist_entry * + dccp_li_hist_entry_new(struct dccp_li_hist *hist, + const unsigned int __nocast prio) +{ + return kmem_cache_alloc(hist->dccplih_slab, prio); +} + +static inline void dccp_li_hist_entry_delete(struct dccp_li_hist *hist, + struct dccp_li_hist_entry *entry) +{ + if (entry != NULL) + kmem_cache_free(hist->dccplih_slab, entry); +} + +extern void dccp_li_hist_purge(struct dccp_li_hist *hist, + struct list_head *list); + +extern u32 dccp_li_hist_calc_i_mean(struct list_head *list); + +extern struct dccp_li_hist_entry * + dccp_li_hist_interval_new(struct dccp_li_hist *hist, + struct list_head *list, + const u64 seq_loss, + const u8 win_loss); +#endif /* _DCCP_LI_HIST_ */ |