mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-23 12:43:55 +08:00
f867bac654
I found that blkp field was not used in kernel tree. As most of the times NR_CPUS is a power of two and kmalloc() memory blocks too, this extra field basically doubles the memory space allocated in __alloc_percpu() to store the 'struct percpu_data' (for example, if NR_CPUS=8 on i386, kmalloc(4*8+4) returns a 64 bytes block instead of a 32 bytes block after this patch) Signed-off-by: Eric Dumazet <dada1@cosmosbay.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
60 lines
1.5 KiB
C
60 lines
1.5 KiB
C
#ifndef __LINUX_PERCPU_H
|
|
#define __LINUX_PERCPU_H
|
|
#include <linux/spinlock.h> /* For preempt_disable() */
|
|
#include <linux/slab.h> /* For kmalloc() */
|
|
#include <linux/smp.h>
|
|
#include <linux/string.h> /* For memset() */
|
|
#include <asm/percpu.h>
|
|
|
|
/* Enough to cover all DEFINE_PER_CPUs in kernel, including modules. */
|
|
#ifndef PERCPU_ENOUGH_ROOM
|
|
#define PERCPU_ENOUGH_ROOM 32768
|
|
#endif
|
|
|
|
/* Must be an lvalue. */
|
|
#define get_cpu_var(var) (*({ preempt_disable(); &__get_cpu_var(var); }))
|
|
#define put_cpu_var(var) preempt_enable()
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
struct percpu_data {
|
|
void *ptrs[NR_CPUS];
|
|
};
|
|
|
|
/*
|
|
* Use this to get to a cpu's version of the per-cpu object allocated using
|
|
* alloc_percpu. Non-atomic access to the current CPU's version should
|
|
* probably be combined with get_cpu()/put_cpu().
|
|
*/
|
|
#define per_cpu_ptr(ptr, cpu) \
|
|
({ \
|
|
struct percpu_data *__p = (struct percpu_data *)~(unsigned long)(ptr); \
|
|
(__typeof__(ptr))__p->ptrs[(cpu)]; \
|
|
})
|
|
|
|
extern void *__alloc_percpu(size_t size);
|
|
extern void free_percpu(const void *);
|
|
|
|
#else /* CONFIG_SMP */
|
|
|
|
#define per_cpu_ptr(ptr, cpu) ({ (void)(cpu); (ptr); })
|
|
|
|
static inline void *__alloc_percpu(size_t size)
|
|
{
|
|
void *ret = kmalloc(size, GFP_KERNEL);
|
|
if (ret)
|
|
memset(ret, 0, size);
|
|
return ret;
|
|
}
|
|
static inline void free_percpu(const void *ptr)
|
|
{
|
|
kfree(ptr);
|
|
}
|
|
|
|
#endif /* CONFIG_SMP */
|
|
|
|
/* Simple wrapper for the common case: zeros memory. */
|
|
#define alloc_percpu(type) ((type *)(__alloc_percpu(sizeof(type))))
|
|
|
|
#endif /* __LINUX_PERCPU_H */
|