mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-04 12:26:56 +07:00
847d357635
Rather than simply NOP out preempt_enable() and preempt_disable(), keep track of preempt_count and display it regularly in case either the test suite or the code under test is forgetting to balance the enables & disables. Only found a test-case that was forgetting to re-enable preemption, but it's a possibility worth checking. Link: http://lkml.kernel.org/r/1480369871-5271-39-git-send-email-mawilcox@linuxonhyperv.com Signed-off-by: Matthew Wilcox <willy@infradead.org> Tested-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Cc: Konstantin Khlebnikov <koct9i@gmail.com> Cc: Ross Zwisler <ross.zwisler@linux.intel.com> Cc: Matthew Wilcox <mawilcox@microsoft.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
67 lines
1.2 KiB
C
67 lines
1.2 KiB
C
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <malloc.h>
|
|
#include <unistd.h>
|
|
#include <assert.h>
|
|
|
|
#include <linux/mempool.h>
|
|
#include <linux/slab.h>
|
|
#include <urcu/uatomic.h>
|
|
|
|
int nr_allocated;
|
|
int preempt_count;
|
|
|
|
void *mempool_alloc(mempool_t *pool, int gfp_mask)
|
|
{
|
|
return pool->alloc(gfp_mask, pool->data);
|
|
}
|
|
|
|
void mempool_free(void *element, mempool_t *pool)
|
|
{
|
|
pool->free(element, pool->data);
|
|
}
|
|
|
|
mempool_t *mempool_create(int min_nr, mempool_alloc_t *alloc_fn,
|
|
mempool_free_t *free_fn, void *pool_data)
|
|
{
|
|
mempool_t *ret = malloc(sizeof(*ret));
|
|
|
|
ret->alloc = alloc_fn;
|
|
ret->free = free_fn;
|
|
ret->data = pool_data;
|
|
return ret;
|
|
}
|
|
|
|
void *kmem_cache_alloc(struct kmem_cache *cachep, int flags)
|
|
{
|
|
void *ret;
|
|
|
|
if (flags & __GFP_NOWARN)
|
|
return NULL;
|
|
|
|
ret = malloc(cachep->size);
|
|
if (cachep->ctor)
|
|
cachep->ctor(ret);
|
|
uatomic_inc(&nr_allocated);
|
|
return ret;
|
|
}
|
|
|
|
void kmem_cache_free(struct kmem_cache *cachep, void *objp)
|
|
{
|
|
assert(objp);
|
|
uatomic_dec(&nr_allocated);
|
|
memset(objp, 0, cachep->size);
|
|
free(objp);
|
|
}
|
|
|
|
struct kmem_cache *
|
|
kmem_cache_create(const char *name, size_t size, size_t offset,
|
|
unsigned long flags, void (*ctor)(void *))
|
|
{
|
|
struct kmem_cache *ret = malloc(sizeof(*ret));
|
|
|
|
ret->size = size;
|
|
ret->ctor = ctor;
|
|
return ret;
|
|
}
|