mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
Merge mem pool config to kernal
only export the mem_pool_<> api add pool to test, move pool_init to dataMemory
This commit is contained in:
parent
e1834a2fbb
commit
1775b6e600
6
port/linux/config/pika_config_pool.h
Normal file
6
port/linux/config/pika_config_pool.h
Normal file
@ -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
|
@ -1,4 +1,5 @@
|
|||||||
sh init.sh
|
sh init.sh
|
||||||
cp config/pika_config_syntax_level_minimal.h config/pika_config.h && sh _gtest_once.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_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
|
cp config/pika_config_default.h config/pika_config.h && sh _gtest_once.sh
|
||||||
|
@ -3,12 +3,6 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "dataMemory.h"
|
#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};
|
char log_buff[LOG_BUFF_MAX][LOG_SIZE] = {0};
|
||||||
uint32_t log_index = 0;
|
uint32_t log_index = 0;
|
||||||
|
|
||||||
@ -32,12 +26,12 @@ uint8_t __is_quick_malloc(void) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#if use_const_pool
|
#if use_const_pool
|
||||||
uint8_t pika_bitmap[pika_pool_size / pika_aline / 8] = {0};
|
uint8_t pika_bitmap[PIKA_POOL_SIZE / PIKA_POOL_ALIGN / 8] = {0};
|
||||||
uint8_t pika_pool_mem[pika_pool_size] = {0};
|
uint8_t pika_pool_mem[PIKA_POOL_SIZE] = {0};
|
||||||
Pool pikaPool = {.aline = pika_aline,
|
Pool pikaPool = {.aline = PIKA_POOL_ALIGN,
|
||||||
.bitmap = pika_bitmap,
|
.bitmap = pika_bitmap,
|
||||||
.mem = pika_pool_mem,
|
.mem = pika_pool_mem,
|
||||||
.size = pika_pool_size};
|
.size = PIKA_POOL_SIZE};
|
||||||
void* __user_malloc(size_t size) {
|
void* __user_malloc(size_t size) {
|
||||||
return pool_malloc(&pikaPool, size);
|
return pool_malloc(&pikaPool, size);
|
||||||
}
|
}
|
||||||
@ -45,25 +39,3 @@ void __user_free(void* ptrm, size_t size) {
|
|||||||
pool_free(&pikaPool, ptrm, size);
|
pool_free(&pikaPool, ptrm, size);
|
||||||
}
|
}
|
||||||
#endif
|
#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
|
|
||||||
}
|
|
@ -1,5 +1,13 @@
|
|||||||
#include "test_common.h"
|
#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) {
|
TEST(pool, init) {
|
||||||
Pool p = pool_init(125, 4);
|
Pool p = pool_init(125, 4);
|
||||||
EXPECT_EQ(p.aline, 4);
|
EXPECT_EQ(p.aline, 4);
|
||||||
|
@ -109,6 +109,7 @@ Pool pool_init(uint32_t size, uint8_t aline) {
|
|||||||
pool.mem = __platform_malloc(pool_aline(&pool, pool.size));
|
pool.mem = __platform_malloc(pool_aline(&pool, pool.size));
|
||||||
pool.first_free_block = 0;
|
pool.first_free_block = 0;
|
||||||
pool.purl_free_block_start = 0;
|
pool.purl_free_block_start = 0;
|
||||||
|
pool.inited = 1;
|
||||||
return pool;
|
return pool;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -295,3 +296,27 @@ uint8_t bitmap_get(BitMap bitmap, uint32_t index) {
|
|||||||
void bitmap_deinit(BitMap bitmap) {
|
void bitmap_deinit(BitMap bitmap) {
|
||||||
__platform_free(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
|
||||||
|
}
|
@ -54,6 +54,7 @@ struct Pool{
|
|||||||
uint32_t size;
|
uint32_t size;
|
||||||
uint32_t first_free_block;
|
uint32_t first_free_block;
|
||||||
uint32_t purl_free_block_start;
|
uint32_t purl_free_block_start;
|
||||||
|
PIKA_BOOL inited;
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
/* clang-format on */
|
/* 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);
|
uint8_t bitmap_getByte(BitMap bitmap, uint32_t index);
|
||||||
void bitmap_deinit(BitMap bitmap);
|
void bitmap_deinit(BitMap bitmap);
|
||||||
|
|
||||||
Pool pool_init(uint32_t size, uint8_t aline);
|
void mem_pool_deinit(void);
|
||||||
void* pool_malloc(Pool* pool, uint32_t size);
|
void mem_pool_init(void);
|
||||||
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);
|
|
||||||
|
|
||||||
#undef __DATA_MEMORY_CLASS_IMPLEMENT__
|
#undef __DATA_MEMORY_CLASS_IMPLEMENT__
|
||||||
#endif
|
#endif
|
||||||
|
@ -44,6 +44,9 @@
|
|||||||
#define PIKA_SYNTEX_ITEM_FORMAT_ENABLE 1
|
#define PIKA_SYNTEX_ITEM_FORMAT_ENABLE 1
|
||||||
#define PIKA_PLOOC_ENABLE 0
|
#define PIKA_PLOOC_ENABLE 0
|
||||||
#define PIKA_STD_DEVICE_UNIX_TIME_ENABLE 1
|
#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 */
|
/* optimize options */
|
||||||
#define PIKA_OPTIMIZE_SIZE 0
|
#define PIKA_OPTIMIZE_SIZE 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user