From 2a2b075826208cc0d54a98b2ddda905c3b9fac80 Mon Sep 17 00:00:00 2001 From: Peter Mitsis Date: Thu, 6 Oct 2016 16:27:01 -0400 Subject: [PATCH] unified: Tweak K_MEMORY_POOL_DEFINE() macro - Renames to K_MEM_POOL_DEFINE() for consistency - Adds alignment parameter to align the pool buffer. Jira: ZEP-926 Change-Id: I6cf0a1ce45c3a0fc5f0675047d8928659df1e75e Signed-off-by: Peter Mitsis --- doc/kernel_v2/memory/pools.rst | 5 +++-- include/kernel.h | 25 +++++++++++++++++++++---- scripts/sysgen | 2 +- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/doc/kernel_v2/memory/pools.rst b/doc/kernel_v2/memory/pools.rst index 494aa3d9cf5..5a09eb94718 100644 --- a/doc/kernel_v2/memory/pools.rst +++ b/doc/kernel_v2/memory/pools.rst @@ -121,7 +121,8 @@ A memory pool can only be defined and initialized at compile time by calling :c:macro:`K_MEM_POOL_DEFINE()`. The following code defines and initializes a memory pool that has 3 blocks -of 4096 bytes each, which can be partitioned into blocks as small as 64 bytes. +of 4096 bytes each, which can be partitioned into blocks as small as 64 bytes +and is aligned to a 4-byte boundary. (That is, the memory pool supports block sizes of 4096, 1024, 256, and 64 bytes.) Observe that the macro defines all of the memory pool data structures, @@ -129,7 +130,7 @@ as well as its buffer. .. code-block:: c - K_MEM_POOL_DEFINE(my_map, 64, 4096, 3); + K_MEM_POOL_DEFINE(my_map, 64, 4096, 3, 4); Allocating a Memory Block ========================= diff --git a/include/kernel.h b/include/kernel.h index 8c674ffb4e0..1ead09c1465 100644 --- a/include/kernel.h +++ b/include/kernel.h @@ -1399,13 +1399,30 @@ __asm__(".macro _build_mem_pool name, min_size, max_size, n_max\n\t" extern uint32_t _mem_pool_block_set_count_##name; \ extern struct k_mem_pool_block_set _mem_pool_block_sets_##name[] -#define _MEMORY_POOL_BUFFER_DEFINE(name, max_size, n_max) \ - char __noinit _mem_pool_buffer_##name[(max_size) * (n_max)] +#define _MEMORY_POOL_BUFFER_DEFINE(name, max_size, n_max, align) \ + char __noinit __aligned(align) \ + _mem_pool_buffer_##name[(max_size) * (n_max)] -#define K_MEMORY_POOL_DEFINE(name, min_size, max_size, n_max) \ +/** + * @brief Define a memory pool + * + * This declares and initializes a memory pool whose buffer is aligned to + * a @a align -byte boundary. The new memory pool can be passed to the + * kernel's memory pool functions. + * + * Note that for each of the minimum sized blocks to be aligned to @a align + * bytes, then @a min_size must be a multiple of @a align. + * + * @param name Name of the memory pool + * @param min_size Minimum block size in the pool + * @param max_size Maximum block size in the pool + * @param n_max Number of maximum sized blocks in the pool + * @param align Alignment of the memory pool's buffer + */ +#define K_MEM_POOL_DEFINE(name, min_size, max_size, n_max, align) \ _MEMORY_POOL_QUAD_BLOCK_DEFINE(name, min_size, max_size, n_max); \ _MEMORY_POOL_BLOCK_SETS_DEFINE(name, min_size, max_size, n_max); \ - _MEMORY_POOL_BUFFER_DEFINE(name, max_size, n_max); \ + _MEMORY_POOL_BUFFER_DEFINE(name, max_size, n_max, align); \ __asm__("_build_mem_pool " STRINGIFY(name) " " STRINGIFY(min_size) " " \ STRINGIFY(max_size) " " STRINGIFY(n_max) "\n\t"); \ extern struct k_mem_pool name diff --git a/scripts/sysgen b/scripts/sysgen index 8d9cce32c0a..1a725b544be 100755 --- a/scripts/sysgen +++ b/scripts/sysgen @@ -895,7 +895,7 @@ def kernel_main_c_pools(): min_block_size = pool[1] max_block_size = pool[2] num_maximal_blocks = pool[3] - pool_descriptors += "K_MEMORY_POOL_DEFINE(_k_mem_pool_obj_%s, %d, %d, %d);\n" % \ + pool_descriptors += "K_MEM_POOL_DEFINE(_k_mem_pool_obj_%s, %d, %d, %d, 4);\n" % \ (pool[0], min_block_size, max_block_size, num_maximal_blocks) kernel_main_c_out(pool_descriptors)