diff --git a/port/linux/config/pika_config_pool.h b/port/linux/config/pika_config_pool.h new file mode 100644 index 000000000..19afb6464 --- /dev/null +++ b/port/linux/config/pika_config_pool.h @@ -0,0 +1,6 @@ +#undef PIKA_STACK_BUFF_SIZE +#define PIKA_STACK_BUFF_SIZE 2048 +#undef PIKA_POOL_ENABLE +#define PIKA_POOL_ENABLE 1 +#undef PIKA_POOL_SIZE +#define PIKA_POOL_SIZE 0x40000 \ No newline at end of file diff --git a/port/linux/gtest.sh b/port/linux/gtest.sh index c783c7a3f..562711987 100644 --- a/port/linux/gtest.sh +++ b/port/linux/gtest.sh @@ -1,4 +1,5 @@ sh init.sh cp config/pika_config_syntax_level_minimal.h config/pika_config.h && sh _gtest_once.sh && \ cp config/pika_config_optimize_speed.h config/pika_config.h && sh _gtest_once.sh && \ +cp config/pika_config_pool.h config/pika_config.h && sh _gtest_once.sh && \ cp config/pika_config_default.h config/pika_config.h && sh _gtest_once.sh diff --git a/port/linux/test/pika_config_gtest.c b/port/linux/test/pika_config_gtest.c index c1ac96502..ab9a37ede 100644 --- a/port/linux/test/pika_config_gtest.c +++ b/port/linux/test/pika_config_gtest.c @@ -3,12 +3,6 @@ #include #include "dataMemory.h" -#define use_const_pool 0 -#define use_dynamic_pool 0 - -#define pika_aline 8 -#define pika_pool_size 0x4000 - char log_buff[LOG_BUFF_MAX][LOG_SIZE] = {0}; uint32_t log_index = 0; @@ -32,12 +26,12 @@ uint8_t __is_quick_malloc(void) { return 0; } #if use_const_pool -uint8_t pika_bitmap[pika_pool_size / pika_aline / 8] = {0}; -uint8_t pika_pool_mem[pika_pool_size] = {0}; -Pool pikaPool = {.aline = pika_aline, +uint8_t pika_bitmap[PIKA_POOL_SIZE / PIKA_POOL_ALIGN / 8] = {0}; +uint8_t pika_pool_mem[PIKA_POOL_SIZE] = {0}; +Pool pikaPool = {.aline = PIKA_POOL_ALIGN, .bitmap = pika_bitmap, .mem = pika_pool_mem, - .size = pika_pool_size}; + .size = PIKA_POOL_SIZE}; void* __user_malloc(size_t size) { return pool_malloc(&pikaPool, size); } @@ -45,25 +39,3 @@ void __user_free(void* ptrm, size_t size) { pool_free(&pikaPool, ptrm, size); } #endif - -#if use_dynamic_pool -Pool pikaPool; -void* __user_malloc(size_t size) { - return pool_malloc(&pikaPool, size); -} -void __user_free(void* ptrm, size_t size) { - pool_free(&pikaPool, ptrm, size); -} -#endif - -void mem_pool_init(void) { - #if use_dynamic_pool - pikaPool = pool_init(pika_pool_size, pika_aline); - #endif -} - -void mem_pool_deinit(void) { - #if use_dynamic_pool - pool_deinit(&pikaPool); - #endif -} \ No newline at end of file diff --git a/port/linux/test/pool-test.cpp b/port/linux/test/pool-test.cpp index 52bcf7650..e0ebea384 100644 --- a/port/linux/test/pool-test.cpp +++ b/port/linux/test/pool-test.cpp @@ -1,5 +1,13 @@ #include "test_common.h" +extern "C" { +Pool pool_init(uint32_t size, uint8_t aline); +void* pool_malloc(Pool* pool, uint32_t size); +void pool_free(Pool* pool, void* mem, uint32_t size); +void pool_deinit(Pool* pool); +void pool_printBlocks(Pool* pool, uint32_t block_min, uint32_t block_max); +} + TEST(pool, init) { Pool p = pool_init(125, 4); EXPECT_EQ(p.aline, 4); diff --git a/src/dataMemory.c b/src/dataMemory.c index 63073e215..323bbb66c 100644 --- a/src/dataMemory.c +++ b/src/dataMemory.c @@ -109,6 +109,7 @@ Pool pool_init(uint32_t size, uint8_t aline) { pool.mem = __platform_malloc(pool_aline(&pool, pool.size)); pool.first_free_block = 0; pool.purl_free_block_start = 0; + pool.inited = 1; return pool; } @@ -295,3 +296,27 @@ uint8_t bitmap_get(BitMap bitmap, uint32_t index) { void bitmap_deinit(BitMap bitmap) { __platform_free(bitmap); } + +#if PIKA_POOL_ENABLE +Pool pikaPool = {0}; +void* __user_malloc(size_t size) { + return pool_malloc(&pikaPool, size); +} +void __user_free(void* ptrm, size_t size) { + pool_free(&pikaPool, ptrm, size); +} +#endif + +void mem_pool_init(void) { +#if PIKA_POOL_ENABLE + if (!pikaPool.inited) { + pikaPool = pool_init(PIKA_POOL_SIZE, PIKA_POOL_ALIGN); + } +#endif +} + +void mem_pool_deinit(void) { +#if PIKA_POOL_ENABLE + pool_deinit(&pikaPool); +#endif +} \ No newline at end of file diff --git a/src/dataMemory.h b/src/dataMemory.h index b3b6d528b..2c87dfbc3 100644 --- a/src/dataMemory.h +++ b/src/dataMemory.h @@ -54,6 +54,7 @@ struct Pool{ uint32_t size; uint32_t first_free_block; uint32_t purl_free_block_start; + PIKA_BOOL inited; ) }; /* clang-format on */ @@ -72,11 +73,8 @@ uint8_t bitmap_get(BitMap bitmap, uint32_t index); uint8_t bitmap_getByte(BitMap bitmap, uint32_t index); void bitmap_deinit(BitMap bitmap); -Pool pool_init(uint32_t size, uint8_t aline); -void* pool_malloc(Pool* pool, uint32_t size); -void pool_free(Pool* pool, void* mem, uint32_t size); -void pool_deinit(Pool* pool); -void pool_printBlocks(Pool* pool, uint32_t block_min, uint32_t block_max); +void mem_pool_deinit(void); +void mem_pool_init(void); #undef __DATA_MEMORY_CLASS_IMPLEMENT__ #endif diff --git a/src/pika_config_valid.h b/src/pika_config_valid.h index 4c22599f1..27c291dae 100644 --- a/src/pika_config_valid.h +++ b/src/pika_config_valid.h @@ -44,6 +44,9 @@ #define PIKA_SYNTEX_ITEM_FORMAT_ENABLE 1 #define PIKA_PLOOC_ENABLE 0 #define PIKA_STD_DEVICE_UNIX_TIME_ENABLE 1 + #define PIKA_POOL_ENABLE 0 + #define PIKA_POOL_SIZE 0x4000 + #define PIKA_POOL_ALIGN 8 /* optimize options */ #define PIKA_OPTIMIZE_SIZE 0