From fc4ca923bbe7fb013ccc4e26a17be4c8b2d1e6ad Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Wed, 22 May 2019 15:16:11 -0400 Subject: [PATCH] mempool: fully use the inline free block bitmap on 64-bit targets The "bits" field in struct sys_mem_pool_lvl is unioned with a pointer. That leaves more space for inline free bits on 64-bit targets. Let's declare it as an array and adjust its size based on the pointer size. On 32-bit targets the generated code remains identical. Signed-off-by: Nicolas Pitre --- include/sys/mempool_base.h | 10 +++++----- lib/os/mempool.c | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/sys/mempool_base.h b/include/sys/mempool_base.h index 9b66d63b016..ef06450e4da 100644 --- a/include/sys/mempool_base.h +++ b/include/sys/mempool_base.h @@ -18,7 +18,7 @@ struct sys_mem_pool_lvl { union { u32_t *bits_p; - u32_t bits; + u32_t bits[sizeof(u32_t *)/4]; }; sys_dlist_t free_list; }; @@ -67,11 +67,11 @@ struct sys_mem_pool_base { #define Z_MPOOL_LBIT_WORDS_UNCLAMPED(n_max, l) \ ((((n_max) << (2*(l))) + 31) / 32) -/* One word gets stored free unioned with the pointer, otherwise the - * calculated unclamped value +/* One or two 32-bit words gets stored free unioned with the pointer, + * otherwise the calculated unclamped value */ -#define Z_MPOOL_LBIT_WORDS(n_max, l) \ - (Z_MPOOL_LBIT_WORDS_UNCLAMPED(n_max, l) < 2 ? 0 \ +#define Z_MPOOL_LBIT_WORDS(n_max, l) \ + (Z_MPOOL_LBIT_WORDS_UNCLAMPED(n_max, l) <= sizeof(u32_t *)/4 ? 0 \ : Z_MPOOL_LBIT_WORDS_UNCLAMPED(n_max, l)) /* How many bytes for the bitfields of a single level? */ diff --git a/lib/os/mempool.c b/lib/os/mempool.c index 75f42cc0187..c2f2db720e1 100644 --- a/lib/os/mempool.c +++ b/lib/os/mempool.c @@ -33,7 +33,7 @@ static int get_bit_ptr(struct sys_mem_pool_base *p, int level, int bn, u32_t **word) { u32_t *bitarray = level <= p->max_inline_level ? - &p->levels[level].bits : p->levels[level].bits_p; + p->levels[level].bits : p->levels[level].bits_p; *word = &bitarray[bn / 32]; @@ -104,7 +104,7 @@ void z_sys_mem_pool_base_init(struct sys_mem_pool_base *p) sys_dlist_init(&p->levels[i].free_list); - if (nblocks <= 32) { + if (nblocks <= sizeof(p->levels[i].bits)*8) { p->max_inline_level = i; } else { p->levels[i].bits_p = bits;