[PATCH 1/3] percpu: Add alloc_percpu_aligned()

From: Huang, Ying
Date: Wed Aug 02 2017 - 04:52:39 EST


From: Huang Ying <ying.huang@xxxxxxxxx>

To allocate percpu memory that is aligned with cache line size
dynamically. We can statically allocate percpu memory that is aligned
with cache line size with DEFINE_PER_CPU_ALIGNED(), but we have no
correspondent API for dynamic allocation.

Signed-off-by: "Huang, Ying" <ying.huang@xxxxxxxxx>
Cc: Tejun Heo <tj@xxxxxxxxxx>
Cc: Christoph Lameter <cl@xxxxxxxxx>
---
include/linux/percpu.h | 3 +++
1 file changed, 3 insertions(+)

diff --git a/include/linux/percpu.h b/include/linux/percpu.h
index 491b3f5a5f8a..8b80a965d64a 100644
--- a/include/linux/percpu.h
+++ b/include/linux/percpu.h
@@ -129,5 +129,8 @@ extern phys_addr_t per_cpu_ptr_to_phys(void *addr);
#define alloc_percpu(type) \
(typeof(type) __percpu *)__alloc_percpu(sizeof(type), \
__alignof__(type))
+#define alloc_percpu_aligned(type) \
+ ((typeof(type) __percpu *)__alloc_percpu(sizeof(type), \
+ max_t(unsigned int, cache_line_size(), __alignof__(type))))

#endif /* __LINUX_PERCPU_H */
--
2.13.2