aboutsummaryrefslogtreecommitdiffstats
path: root/net/dccp/ccids/lib
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2007-05-28 17:53:08 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2007-07-11 01:15:23 -0400
commitcc4d6a3a34ce3976d7d01d044f3093cddc2921c2 (patch)
treeddf0a5d4aaac4661f3bb1fadd60082febc21b9ef /net/dccp/ccids/lib
parentc70b729e662a1b3ee2ef5370c1e4c9bc3ddc239f (diff)
loss_interval: Nuke dccp_li_hist
It had just a slab cache, so, for the sake of simplicity just make dccp_trfc_lib module init routine create the slab cache, no need for users of the lib to create a private loss_interval object. Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'net/dccp/ccids/lib')
-rw-r--r--net/dccp/ccids/lib/loss_interval.c92
-rw-r--r--net/dccp/ccids/lib/loss_interval.h12
2 files changed, 33 insertions, 71 deletions
diff --git a/net/dccp/ccids/lib/loss_interval.c b/net/dccp/ccids/lib/loss_interval.c
index 28eac9be6634..e6b1f0c913ec 100644
--- a/net/dccp/ccids/lib/loss_interval.c
+++ b/net/dccp/ccids/lib/loss_interval.c
@@ -18,71 +18,26 @@
18#include "packet_history.h" 18#include "packet_history.h"
19#include "tfrc.h" 19#include "tfrc.h"
20 20
21struct dccp_li_hist *dccp_li_hist_new(const char *name) 21struct kmem_cache *dccp_li_cachep __read_mostly;
22{
23 struct dccp_li_hist *hist = kmalloc(sizeof(*hist), GFP_ATOMIC);
24 static const char dccp_li_hist_mask[] = "li_hist_%s";
25 char *slab_name;
26
27 if (hist == NULL)
28 goto out;
29
30 slab_name = kmalloc(strlen(name) + sizeof(dccp_li_hist_mask) - 1,
31 GFP_ATOMIC);
32 if (slab_name == NULL)
33 goto out_free_hist;
34
35 sprintf(slab_name, dccp_li_hist_mask, name);
36 hist->dccplih_slab = kmem_cache_create(slab_name,
37 sizeof(struct dccp_li_hist_entry),
38 0, SLAB_HWCACHE_ALIGN,
39 NULL, NULL);
40 if (hist->dccplih_slab == NULL)
41 goto out_free_slab_name;
42out:
43 return hist;
44out_free_slab_name:
45 kfree(slab_name);
46out_free_hist:
47 kfree(hist);
48 hist = NULL;
49 goto out;
50}
51
52EXPORT_SYMBOL_GPL(dccp_li_hist_new);
53
54void dccp_li_hist_delete(struct dccp_li_hist *hist)
55{
56 const char* name = kmem_cache_name(hist->dccplih_slab);
57
58 kmem_cache_destroy(hist->dccplih_slab);
59 kfree(name);
60 kfree(hist);
61}
62
63EXPORT_SYMBOL_GPL(dccp_li_hist_delete);
64 22
65static inline struct dccp_li_hist_entry * 23static inline struct dccp_li_hist_entry *dccp_li_hist_entry_new(const gfp_t prio)
66 dccp_li_hist_entry_new(struct dccp_li_hist *hist,
67 const gfp_t prio)
68{ 24{
69 return kmem_cache_alloc(hist->dccplih_slab, prio); 25 return kmem_cache_alloc(dccp_li_cachep, prio);
70} 26}
71 27
72static inline void dccp_li_hist_entry_delete(struct dccp_li_hist *hist, 28static inline void dccp_li_hist_entry_delete(struct dccp_li_hist_entry *entry)
73 struct dccp_li_hist_entry *entry)
74{ 29{
75 if (entry != NULL) 30 if (entry != NULL)
76 kmem_cache_free(hist->dccplih_slab, entry); 31 kmem_cache_free(dccp_li_cachep, entry);
77} 32}
78 33
79void dccp_li_hist_purge(struct dccp_li_hist *hist, struct list_head *list) 34void dccp_li_hist_purge(struct list_head *list)
80{ 35{
81 struct dccp_li_hist_entry *entry, *next; 36 struct dccp_li_hist_entry *entry, *next;
82 37
83 list_for_each_entry_safe(entry, next, list, dccplih_node) { 38 list_for_each_entry_safe(entry, next, list, dccplih_node) {
84 list_del_init(&entry->dccplih_node); 39 list_del_init(&entry->dccplih_node);
85 kmem_cache_free(hist->dccplih_slab, entry); 40 kmem_cache_free(dccp_li_cachep, entry);
86 } 41 }
87} 42}
88 43
@@ -134,17 +89,16 @@ u32 dccp_li_hist_calc_i_mean(struct list_head *list)
134 89
135EXPORT_SYMBOL_GPL(dccp_li_hist_calc_i_mean); 90EXPORT_SYMBOL_GPL(dccp_li_hist_calc_i_mean);
136 91
137static int dccp_li_hist_interval_new(struct dccp_li_hist *hist, 92static int dccp_li_hist_interval_new(struct list_head *list,
138 struct list_head *list,
139 const u64 seq_loss, const u8 win_loss) 93 const u64 seq_loss, const u8 win_loss)
140{ 94{
141 struct dccp_li_hist_entry *entry; 95 struct dccp_li_hist_entry *entry;
142 int i; 96 int i;
143 97
144 for (i = 0; i < DCCP_LI_HIST_IVAL_F_LENGTH; i++) { 98 for (i = 0; i < DCCP_LI_HIST_IVAL_F_LENGTH; i++) {
145 entry = dccp_li_hist_entry_new(hist, GFP_ATOMIC); 99 entry = dccp_li_hist_entry_new(GFP_ATOMIC);
146 if (entry == NULL) { 100 if (entry == NULL) {
147 dccp_li_hist_purge(hist, list); 101 dccp_li_hist_purge(list);
148 DCCP_BUG("loss interval list entry is NULL"); 102 DCCP_BUG("loss interval list entry is NULL");
149 return 0; 103 return 0;
150 } 104 }
@@ -260,7 +214,7 @@ found:
260 return 1000000 / p; 214 return 1000000 / p;
261} 215}
262 216
263void dccp_li_update_li(struct sock *sk, struct dccp_li_hist *li_hist, 217void dccp_li_update_li(struct sock *sk,
264 struct list_head *li_hist_list, 218 struct list_head *li_hist_list,
265 struct list_head *hist_list, 219 struct list_head *hist_list,
266 struct timeval *last_feedback, u16 s, u32 bytes_recv, 220 struct timeval *last_feedback, u16 s, u32 bytes_recv,
@@ -270,8 +224,8 @@ void dccp_li_update_li(struct sock *sk, struct dccp_li_hist *li_hist,
270 u64 seq_temp; 224 u64 seq_temp;
271 225
272 if (list_empty(li_hist_list)) { 226 if (list_empty(li_hist_list)) {
273 if (!dccp_li_hist_interval_new(li_hist, li_hist_list, 227 if (!dccp_li_hist_interval_new(li_hist_list, seq_loss,
274 seq_loss, win_loss)) 228 win_loss))
275 return; 229 return;
276 230
277 head = list_entry(li_hist_list->next, struct dccp_li_hist_entry, 231 head = list_entry(li_hist_list->next, struct dccp_li_hist_entry,
@@ -293,7 +247,7 @@ void dccp_li_update_li(struct sock *sk, struct dccp_li_hist *li_hist,
293 /* new loss event detected */ 247 /* new loss event detected */
294 /* calculate last interval length */ 248 /* calculate last interval length */
295 seq_temp = dccp_delta_seqno(head->dccplih_seqno, seq_loss); 249 seq_temp = dccp_delta_seqno(head->dccplih_seqno, seq_loss);
296 entry = dccp_li_hist_entry_new(li_hist, GFP_ATOMIC); 250 entry = dccp_li_hist_entry_new(GFP_ATOMIC);
297 251
298 if (entry == NULL) { 252 if (entry == NULL) {
299 DCCP_BUG("out of memory - can not allocate entry"); 253 DCCP_BUG("out of memory - can not allocate entry");
@@ -304,7 +258,7 @@ void dccp_li_update_li(struct sock *sk, struct dccp_li_hist *li_hist,
304 258
305 tail = li_hist_list->prev; 259 tail = li_hist_list->prev;
306 list_del(tail); 260 list_del(tail);
307 kmem_cache_free(li_hist->dccplih_slab, tail); 261 kmem_cache_free(dccp_li_cachep, tail);
308 262
309 /* Create the newest interval */ 263 /* Create the newest interval */
310 entry->dccplih_seqno = seq_loss; 264 entry->dccplih_seqno = seq_loss;
@@ -314,3 +268,19 @@ void dccp_li_update_li(struct sock *sk, struct dccp_li_hist *li_hist,
314} 268}
315 269
316EXPORT_SYMBOL_GPL(dccp_li_update_li); 270EXPORT_SYMBOL_GPL(dccp_li_update_li);
271
272static __init int dccp_li_init(void)
273{
274 dccp_li_cachep = kmem_cache_create("dccp_li_hist",
275 sizeof(struct dccp_li_hist_entry),
276 0, SLAB_HWCACHE_ALIGN, NULL, NULL);
277 return dccp_li_cachep == NULL ? -ENOBUFS : 0;
278}
279
280static __exit void dccp_li_exit(void)
281{
282 kmem_cache_destroy(dccp_li_cachep);
283}
284
285module_init(dccp_li_init);
286module_exit(dccp_li_exit);
diff --git a/net/dccp/ccids/lib/loss_interval.h b/net/dccp/ccids/lib/loss_interval.h
index 8d3c9bfa4915..f35c11100fc6 100644
--- a/net/dccp/ccids/lib/loss_interval.h
+++ b/net/dccp/ccids/lib/loss_interval.h
@@ -19,13 +19,6 @@
19 19
20#define DCCP_LI_HIST_IVAL_F_LENGTH 8 20#define DCCP_LI_HIST_IVAL_F_LENGTH 8
21 21
22struct dccp_li_hist {
23 struct kmem_cache *dccplih_slab;
24};
25
26extern struct dccp_li_hist *dccp_li_hist_new(const char *name);
27extern void dccp_li_hist_delete(struct dccp_li_hist *hist);
28
29struct dccp_li_hist_entry { 22struct dccp_li_hist_entry {
30 struct list_head dccplih_node; 23 struct list_head dccplih_node;
31 u64 dccplih_seqno:48, 24 u64 dccplih_seqno:48,
@@ -33,12 +26,11 @@ struct dccp_li_hist_entry {
33 u32 dccplih_interval; 26 u32 dccplih_interval;
34}; 27};
35 28
36extern void dccp_li_hist_purge(struct dccp_li_hist *hist, 29extern void dccp_li_hist_purge(struct list_head *list);
37 struct list_head *list);
38 30
39extern u32 dccp_li_hist_calc_i_mean(struct list_head *list); 31extern u32 dccp_li_hist_calc_i_mean(struct list_head *list);
40 32
41extern void dccp_li_update_li(struct sock *sk, struct dccp_li_hist *li_hist, 33extern void dccp_li_update_li(struct sock *sk,
42 struct list_head *li_hist_list, 34 struct list_head *li_hist_list,
43 struct list_head *hist_list, 35 struct list_head *hist_list,
44 struct timeval *last_feedback, u16 s, 36 struct timeval *last_feedback, u16 s,