diff options
author | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2008-09-11 21:54:44 -0400 |
---|---|---|
committer | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2008-09-11 21:54:44 -0400 |
commit | dcf7ba77000800ab4e16b17b4f65abd05aebcbdd (patch) | |
tree | f6606cd6f5af694bb9df1d893c13f07c06b4fb6a | |
parent | ddb418f16e5a6e75e3d32cac31251b51e8bb82e8 (diff) |
binomial heaps: reuse heap_node slab for allocations
We already have a heap_node slab in litmus.c. We can reuse it for the
other allocations.
This patch also fixes a misnaming of heap_node_alloc/free.
-rw-r--r-- | include/litmus/heap.h | 18 | ||||
-rw-r--r-- | litmus/litmus.c | 10 |
2 files changed, 15 insertions, 13 deletions
diff --git a/include/litmus/heap.h b/include/litmus/heap.h index 508e0b9f16..e5b4746998 100644 --- a/include/litmus/heap.h +++ b/include/litmus/heap.h | |||
@@ -45,6 +45,9 @@ static inline void heap_node_init(struct heap_node** _h, void* value) | |||
45 | h->ref = _h; | 45 | h->ref = _h; |
46 | } | 46 | } |
47 | 47 | ||
48 | struct heap_node* heap_node_alloc(int gfp_flags); | ||
49 | void heap_node_free(struct heap_node* hn); | ||
50 | |||
48 | static inline int heap_node_in_heap(struct heap_node* h) | 51 | static inline int heap_node_in_heap(struct heap_node* h) |
49 | { | 52 | { |
50 | return h->degree != NOT_IN_HEAP; | 53 | return h->degree != NOT_IN_HEAP; |
@@ -298,22 +301,11 @@ static inline void heap_delete(heap_prio_t higher_prio, struct heap* heap, | |||
298 | node->degree = NOT_IN_HEAP; | 301 | node->degree = NOT_IN_HEAP; |
299 | } | 302 | } |
300 | 303 | ||
301 | /* un-inline, make it a kmemcache_t */ | ||
302 | static inline struct heap_node* alloc_heap_node(int gfp_flags) | ||
303 | { | ||
304 | return kmalloc(sizeof(struct heap_node), gfp_flags); | ||
305 | } | ||
306 | |||
307 | static inline void free_heap_node(struct heap_node* hn) | ||
308 | { | ||
309 | kfree(hn); | ||
310 | } | ||
311 | |||
312 | /* allocate a heap node for value and insert into the heap */ | 304 | /* allocate a heap node for value and insert into the heap */ |
313 | static inline int heap_add(heap_prio_t higher_prio, struct heap* heap, | 305 | static inline int heap_add(heap_prio_t higher_prio, struct heap* heap, |
314 | void* value, int gfp_flags) | 306 | void* value, int gfp_flags) |
315 | { | 307 | { |
316 | struct heap_node* hn = alloc_heap_node(gfp_flags); | 308 | struct heap_node* hn = heap_node_alloc(gfp_flags); |
317 | if (likely(hn)) { | 309 | if (likely(hn)) { |
318 | heap_node_init(&hn, value); | 310 | heap_node_init(&hn, value); |
319 | heap_insert(higher_prio, heap, hn); | 311 | heap_insert(higher_prio, heap, hn); |
@@ -328,7 +320,7 @@ static inline void* heap_take_del(heap_prio_t higher_prio, | |||
328 | void* ret = NULL; | 320 | void* ret = NULL; |
329 | if (hn) { | 321 | if (hn) { |
330 | ret = hn->value; | 322 | ret = hn->value; |
331 | free_heap_node(hn); | 323 | heap_node_free(hn); |
332 | } | 324 | } |
333 | return ret; | 325 | return ret; |
334 | } | 326 | } |
diff --git a/litmus/litmus.c b/litmus/litmus.c index 979985e4a3..c64a8f6aaa 100644 --- a/litmus/litmus.c +++ b/litmus/litmus.c | |||
@@ -32,6 +32,16 @@ static DEFINE_SPINLOCK(sched_sig_list_lock); | |||
32 | 32 | ||
33 | static struct kmem_cache * heap_node_cache; | 33 | static struct kmem_cache * heap_node_cache; |
34 | 34 | ||
35 | struct heap_node* heap_node_alloc(int gfp_flags) | ||
36 | { | ||
37 | return kmem_cache_alloc(heap_node_cache, gfp_flags); | ||
38 | } | ||
39 | |||
40 | void heap_node_free(struct heap_node* hn) | ||
41 | { | ||
42 | kmem_cache_free(heap_node_cache, hn); | ||
43 | } | ||
44 | |||
35 | /* | 45 | /* |
36 | * sys_set_task_rt_param | 46 | * sys_set_task_rt_param |
37 | * @pid: Pid of the task which scheduling parameters must be changed | 47 | * @pid: Pid of the task which scheduling parameters must be changed |