diff options
author | hunt <hunt> | 2006-01-25 09:17:05 +0000 |
---|---|---|
committer | hunt <hunt> | 2006-01-25 09:17:05 +0000 |
commit | 9a46e525c0f0c9615bbbf1a16272ee8b3b98d11f (patch) | |
tree | a788c667a2854233a43f5c48c425a81e0756b1e8 /runtime/user/alloc.c | |
parent | 98ec387a8443f7185814715175c4c0d86390c9b6 (diff) | |
download | systemtap-steved-9a46e525c0f0c9615bbbf1a16272ee8b3b98d11f.tar.gz systemtap-steved-9a46e525c0f0c9615bbbf1a16272ee8b3b98d11f.tar.xz systemtap-steved-9a46e525c0f0c9615bbbf1a16272ee8b3b98d11f.zip |
2006-01-25 Martin Hunt <hunt@redhat.com>
* alloc.c (_stp_alloc_percpu): New function.
(_stp_free_percpu): New function.
Diffstat (limited to 'runtime/user/alloc.c')
-rw-r--r-- | runtime/user/alloc.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/runtime/user/alloc.c b/runtime/user/alloc.c index 9ba720ab..361e7d98 100644 --- a/runtime/user/alloc.c +++ b/runtime/user/alloc.c @@ -14,4 +14,39 @@ void *__kmalloc(size_t size, gfp_t flags) return malloc(size); } +void *_stp_alloc_percpu(size_t size) +{ + int i; + struct percpu_data *pdata = malloc(sizeof (*pdata)); + if (!pdata) + return NULL; + + for_each_cpu(i) { + pdata->ptrs[i] = malloc(size); + if (!pdata->ptrs[i]) + goto unwind_oom; + memset(pdata->ptrs[i], 0, size); + } + + /* Catch derefs w/o wrappers */ + return (void *) (~(unsigned long) pdata); + +unwind_oom: + while (--i >= 0) { + free(pdata->ptrs[i]); + } + free(pdata); + return NULL; +} + +void _stp_free_percpu(const void *objp) +{ + int i; + struct percpu_data *p = (struct percpu_data *) (~(unsigned long) objp); + + for_each_cpu(i) + free(p->ptrs[i]); + free(p); +} + #endif /* _ALLOC_C_ */ |