[TFRC]: Make the rx history slab be global

This is in preparation for merging the new rx history code written by Gerrit Renker.

Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Arnaldo Carvalho de Melo 2007-12-06 12:28:13 -02:00 committed by David S. Miller
parent e9c8b24a6a
commit 34a9e7ea91
3 changed files with 58 additions and 111 deletions

View File

@ -49,8 +49,6 @@ static int ccid3_debug;
#define ccid3_pr_debug(format, a...) #define ccid3_pr_debug(format, a...)
#endif #endif
static struct dccp_rx_hist *ccid3_rx_hist;
/* /*
* Transmitter Half-Connection Routines * Transmitter Half-Connection Routines
*/ */
@ -807,9 +805,9 @@ static int ccid3_hc_rx_detect_loss(struct sock *sk,
} }
detect_out: detect_out:
dccp_rx_hist_add_packet(ccid3_rx_hist, &hcrx->ccid3hcrx_hist, dccp_rx_hist_add_packet(&hcrx->ccid3hcrx_hist,
&hcrx->ccid3hcrx_li_hist, packet, &hcrx->ccid3hcrx_li_hist, packet,
hcrx->ccid3hcrx_seqno_nonloss); hcrx->ccid3hcrx_seqno_nonloss);
return loss; return loss;
} }
@ -852,8 +850,7 @@ static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
return; return;
} }
packet = dccp_rx_hist_entry_new(ccid3_rx_hist, opt_recv->dccpor_ndp, packet = dccp_rx_hist_entry_new(opt_recv->dccpor_ndp, skb, GFP_ATOMIC);
skb, GFP_ATOMIC);
if (unlikely(packet == NULL)) { if (unlikely(packet == NULL)) {
DCCP_WARN("%s(%p), Not enough mem to add rx packet " DCCP_WARN("%s(%p), Not enough mem to add rx packet "
"to history, consider it lost!\n", dccp_role(sk), sk); "to history, consider it lost!\n", dccp_role(sk), sk);
@ -936,7 +933,7 @@ static void ccid3_hc_rx_exit(struct sock *sk)
ccid3_hc_rx_set_state(sk, TFRC_RSTATE_TERM); ccid3_hc_rx_set_state(sk, TFRC_RSTATE_TERM);
/* Empty packet history */ /* Empty packet history */
dccp_rx_hist_purge(ccid3_rx_hist, &hcrx->ccid3hcrx_hist); dccp_rx_hist_purge(&hcrx->ccid3hcrx_hist);
/* Empty loss interval history */ /* Empty loss interval history */
dccp_li_hist_purge(&hcrx->ccid3hcrx_li_hist); dccp_li_hist_purge(&hcrx->ccid3hcrx_li_hist);
@ -1013,33 +1010,13 @@ MODULE_PARM_DESC(ccid3_debug, "Enable debug messages");
static __init int ccid3_module_init(void) static __init int ccid3_module_init(void)
{ {
int rc = -ENOBUFS; return ccid_register(&ccid3);
ccid3_rx_hist = dccp_rx_hist_new("ccid3");
if (ccid3_rx_hist == NULL)
goto out;
rc = ccid_register(&ccid3);
if (rc != 0)
goto out_free_rx;
out:
return rc;
out_free_rx:
dccp_rx_hist_delete(ccid3_rx_hist);
ccid3_rx_hist = NULL;
goto out;
} }
module_init(ccid3_module_init); module_init(ccid3_module_init);
static __exit void ccid3_module_exit(void) static __exit void ccid3_module_exit(void)
{ {
ccid_unregister(&ccid3); ccid_unregister(&ccid3);
if (ccid3_rx_hist != NULL) {
dccp_rx_hist_delete(ccid3_rx_hist);
ccid3_rx_hist = NULL;
}
} }
module_exit(ccid3_module_exit); module_exit(ccid3_module_exit);

View File

@ -114,49 +114,34 @@ EXPORT_SYMBOL_GPL(tfrc_tx_hist_rtt);
/* /*
* Receiver History Routines * Receiver History Routines
*/ */
struct dccp_rx_hist *dccp_rx_hist_new(const char *name) static struct kmem_cache *tfrc_rx_hist_slab;
struct dccp_rx_hist_entry *dccp_rx_hist_entry_new(const u32 ndp,
const struct sk_buff *skb,
const gfp_t prio)
{ {
struct dccp_rx_hist *hist = kmalloc(sizeof(*hist), GFP_ATOMIC); struct dccp_rx_hist_entry *entry = kmem_cache_alloc(tfrc_rx_hist_slab,
static const char dccp_rx_hist_mask[] = "rx_hist_%s"; prio);
char *slab_name;
if (hist == NULL) if (entry != NULL) {
goto out; const struct dccp_hdr *dh = dccp_hdr(skb);
slab_name = kmalloc(strlen(name) + sizeof(dccp_rx_hist_mask) - 1, entry->dccphrx_seqno = DCCP_SKB_CB(skb)->dccpd_seq;
GFP_ATOMIC); entry->dccphrx_ccval = dh->dccph_ccval;
if (slab_name == NULL) entry->dccphrx_type = dh->dccph_type;
goto out_free_hist; entry->dccphrx_ndp = ndp;
entry->dccphrx_tstamp = ktime_get_real();
}
sprintf(slab_name, dccp_rx_hist_mask, name); return entry;
hist->dccprxh_slab = kmem_cache_create(slab_name,
sizeof(struct dccp_rx_hist_entry),
0, SLAB_HWCACHE_ALIGN, NULL);
if (hist->dccprxh_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_rx_hist_entry_new);
EXPORT_SYMBOL_GPL(dccp_rx_hist_new); static inline void dccp_rx_hist_entry_delete(struct dccp_rx_hist_entry *entry)
void dccp_rx_hist_delete(struct dccp_rx_hist *hist)
{ {
const char* name = kmem_cache_name(hist->dccprxh_slab); kmem_cache_free(tfrc_rx_hist_slab, entry);
kmem_cache_destroy(hist->dccprxh_slab);
kfree(name);
kfree(hist);
} }
EXPORT_SYMBOL_GPL(dccp_rx_hist_delete);
int dccp_rx_hist_find_entry(const struct list_head *list, const u64 seq, int dccp_rx_hist_find_entry(const struct list_head *list, const u64 seq,
u8 *ccval) u8 *ccval)
{ {
@ -192,11 +177,10 @@ struct dccp_rx_hist_entry *
EXPORT_SYMBOL_GPL(dccp_rx_hist_find_data_packet); EXPORT_SYMBOL_GPL(dccp_rx_hist_find_data_packet);
void dccp_rx_hist_add_packet(struct dccp_rx_hist *hist, void dccp_rx_hist_add_packet(struct list_head *rx_list,
struct list_head *rx_list, struct list_head *li_list,
struct list_head *li_list, struct dccp_rx_hist_entry *packet,
struct dccp_rx_hist_entry *packet, u64 nonloss_seqno)
u64 nonloss_seqno)
{ {
struct dccp_rx_hist_entry *entry, *next; struct dccp_rx_hist_entry *entry, *next;
u8 num_later = 0; u8 num_later = 0;
@ -211,7 +195,7 @@ void dccp_rx_hist_add_packet(struct dccp_rx_hist *hist,
if (after48(nonloss_seqno, if (after48(nonloss_seqno,
entry->dccphrx_seqno)) { entry->dccphrx_seqno)) {
list_del_init(&entry->dccphrx_node); list_del_init(&entry->dccphrx_node);
dccp_rx_hist_entry_delete(hist, entry); dccp_rx_hist_entry_delete(entry);
} }
} else if (dccp_rx_hist_entry_data_packet(entry)) } else if (dccp_rx_hist_entry_data_packet(entry))
--num_later; --num_later;
@ -253,7 +237,7 @@ void dccp_rx_hist_add_packet(struct dccp_rx_hist *hist,
break; break;
case 3: case 3:
list_del_init(&entry->dccphrx_node); list_del_init(&entry->dccphrx_node);
dccp_rx_hist_entry_delete(hist, entry); dccp_rx_hist_entry_delete(entry);
break; break;
} }
} else if (dccp_rx_hist_entry_data_packet(entry)) } else if (dccp_rx_hist_entry_data_packet(entry))
@ -264,13 +248,13 @@ void dccp_rx_hist_add_packet(struct dccp_rx_hist *hist,
EXPORT_SYMBOL_GPL(dccp_rx_hist_add_packet); EXPORT_SYMBOL_GPL(dccp_rx_hist_add_packet);
void dccp_rx_hist_purge(struct dccp_rx_hist *hist, struct list_head *list) void dccp_rx_hist_purge(struct list_head *list)
{ {
struct dccp_rx_hist_entry *entry, *next; struct dccp_rx_hist_entry *entry, *next;
list_for_each_entry_safe(entry, next, list, dccphrx_node) { list_for_each_entry_safe(entry, next, list, dccphrx_node) {
list_del_init(&entry->dccphrx_node); list_del_init(&entry->dccphrx_node);
kmem_cache_free(hist->dccprxh_slab, entry); dccp_rx_hist_entry_delete(entry);
} }
} }
@ -281,8 +265,22 @@ __init int packet_history_init(void)
tfrc_tx_hist_slab = kmem_cache_create("tfrc_tx_hist", tfrc_tx_hist_slab = kmem_cache_create("tfrc_tx_hist",
sizeof(struct tfrc_tx_hist_entry), 0, sizeof(struct tfrc_tx_hist_entry), 0,
SLAB_HWCACHE_ALIGN, NULL); SLAB_HWCACHE_ALIGN, NULL);
if (tfrc_tx_hist_slab == NULL)
goto out_err;
return tfrc_tx_hist_slab == NULL ? -ENOBUFS : 0; tfrc_rx_hist_slab = kmem_cache_create("tfrc_rx_hist",
sizeof(struct dccp_rx_hist_entry), 0,
SLAB_HWCACHE_ALIGN, NULL);
if (tfrc_rx_hist_slab == NULL)
goto out_free_tx;
return 0;
out_free_tx:
kmem_cache_destroy(tfrc_tx_hist_slab);
tfrc_tx_hist_slab = NULL;
out_err:
return -ENOBUFS;
} }
void packet_history_exit(void) void packet_history_exit(void)
@ -291,4 +289,9 @@ void packet_history_exit(void)
kmem_cache_destroy(tfrc_tx_hist_slab); kmem_cache_destroy(tfrc_tx_hist_slab);
tfrc_tx_hist_slab = NULL; tfrc_tx_hist_slab = NULL;
} }
if (tfrc_rx_hist_slab != NULL) {
kmem_cache_destroy(tfrc_rx_hist_slab);
tfrc_rx_hist_slab = NULL;
}
} }

View File

@ -66,34 +66,10 @@ struct dccp_rx_hist_entry {
ktime_t dccphrx_tstamp; ktime_t dccphrx_tstamp;
}; };
struct dccp_rx_hist { extern struct dccp_rx_hist_entry *
struct kmem_cache *dccprxh_slab; dccp_rx_hist_entry_new(const u32 ndp,
};
extern struct dccp_rx_hist *dccp_rx_hist_new(const char *name);
extern void dccp_rx_hist_delete(struct dccp_rx_hist *hist);
static inline struct dccp_rx_hist_entry *
dccp_rx_hist_entry_new(struct dccp_rx_hist *hist,
const u32 ndp,
const struct sk_buff *skb, const struct sk_buff *skb,
const gfp_t prio) const gfp_t prio);
{
struct dccp_rx_hist_entry *entry = kmem_cache_alloc(hist->dccprxh_slab,
prio);
if (entry != NULL) {
const struct dccp_hdr *dh = dccp_hdr(skb);
entry->dccphrx_seqno = DCCP_SKB_CB(skb)->dccpd_seq;
entry->dccphrx_ccval = dh->dccph_ccval;
entry->dccphrx_type = dh->dccph_type;
entry->dccphrx_ndp = ndp;
entry->dccphrx_tstamp = ktime_get_real();
}
return entry;
}
static inline struct dccp_rx_hist_entry * static inline struct dccp_rx_hist_entry *
dccp_rx_hist_head(struct list_head *list) dccp_rx_hist_head(struct list_head *list)
@ -111,21 +87,12 @@ extern int dccp_rx_hist_find_entry(const struct list_head *list, const u64 seq,
extern struct dccp_rx_hist_entry * extern struct dccp_rx_hist_entry *
dccp_rx_hist_find_data_packet(const struct list_head *list); dccp_rx_hist_find_data_packet(const struct list_head *list);
extern void dccp_rx_hist_add_packet(struct dccp_rx_hist *hist, extern void dccp_rx_hist_add_packet(struct list_head *rx_list,
struct list_head *rx_list,
struct list_head *li_list, struct list_head *li_list,
struct dccp_rx_hist_entry *packet, struct dccp_rx_hist_entry *packet,
u64 nonloss_seqno); u64 nonloss_seqno);
static inline void dccp_rx_hist_entry_delete(struct dccp_rx_hist *hist, extern void dccp_rx_hist_purge(struct list_head *list);
struct dccp_rx_hist_entry *entry)
{
if (entry != NULL)
kmem_cache_free(hist->dccprxh_slab, entry);
}
extern void dccp_rx_hist_purge(struct dccp_rx_hist *hist,
struct list_head *list);
static inline int static inline int
dccp_rx_hist_entry_data_packet(const struct dccp_rx_hist_entry *entry) dccp_rx_hist_entry_data_packet(const struct dccp_rx_hist_entry *entry)