mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-09-24 10:17:28 +00:00
hv:Replace dynamic memory with static for sbuf
--Config LOG_BUF_SIZE 256KB for per cpu --Replace 'calloc' with static array for sbuf --Rename 'alloc_earlylog_sbuf' to 'init_earlylog_sbuf' --Remove deadcode sbuf_free v2-->v3: -- put the buffer into per_cpu data structure v1-->v2: -- add 'is_early_logbuf' in percpu data structure used for check if need to do 'do_copy_earlylog' Tracked-On: #861 Signed-off-by: Mingqiang Chi <mingqiang.chi@intel.com> Reviewed-by: Yan, Like <like.yan@intel.com> Reviewed-by: Jason Chen CJ <jason.cj.chen@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
@@ -25,63 +25,6 @@ uint32_t sbuf_next_ptr(uint32_t pos_arg,
|
||||
return pos;
|
||||
}
|
||||
|
||||
static inline uint32_t sbuf_calculate_allocate_size(uint32_t ele_num,
|
||||
uint32_t ele_size)
|
||||
{
|
||||
uint64_t sbuf_allocate_size;
|
||||
|
||||
sbuf_allocate_size = ele_num * ele_size;
|
||||
sbuf_allocate_size += SBUF_HEAD_SIZE;
|
||||
if (sbuf_allocate_size > SBUF_MAX_SIZE) {
|
||||
pr_err("%s, num=0x%x, size=0x%x exceed 0x%x",
|
||||
__func__, ele_num, ele_size, SBUF_MAX_SIZE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (uint32_t) sbuf_allocate_size;
|
||||
}
|
||||
|
||||
struct shared_buf *sbuf_allocate(uint32_t ele_num, uint32_t ele_size)
|
||||
{
|
||||
struct shared_buf *sbuf;
|
||||
uint32_t sbuf_allocate_size;
|
||||
|
||||
if ((ele_num == 0U) || (ele_size == 0U)) {
|
||||
pr_err("%s invalid parameter!", __func__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sbuf_allocate_size = sbuf_calculate_allocate_size(ele_num, ele_size);
|
||||
if (sbuf_allocate_size == 0U) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sbuf = calloc(1U, sbuf_allocate_size);
|
||||
if (sbuf == NULL) {
|
||||
pr_err("%s no memory!", __func__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sbuf->ele_num = ele_num;
|
||||
sbuf->ele_size = ele_size;
|
||||
sbuf->size = ele_num * ele_size;
|
||||
sbuf->magic = SBUF_MAGIC;
|
||||
pr_info("%s ele_num=0x%x, ele_size=0x%x allocated",
|
||||
__func__, ele_num, ele_size);
|
||||
return sbuf;
|
||||
}
|
||||
|
||||
void sbuf_free(struct shared_buf *sbuf)
|
||||
{
|
||||
if ((sbuf == NULL) || (sbuf->magic != SBUF_MAGIC)) {
|
||||
pr_err("%s invalid parameter!", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
sbuf->magic = 0UL;
|
||||
free(sbuf);
|
||||
}
|
||||
|
||||
uint32_t sbuf_get(struct shared_buf *sbuf, uint8_t *data)
|
||||
{
|
||||
const void *from;
|
||||
|
Reference in New Issue
Block a user