[PATCH 2/3] platform: generic: Extra memory for housekeeping

Xiang W wxjstz at 126.com
Tue Aug 5 18:37:21 PDT 2025


在 2025-08-06三的 09:02 +0800,wu.fei9 at sanechips.com.cn写道:
> Allocate the extra housekeeping metadata for heap or the expected free
> memory size cannot be achieved.
> 
> Signed-off-by: Wu Fei <wu.fei9 at sanechips.com.cn>
> ---
>  include/sbi/sbi_heap.h      | 3 +++
>  lib/sbi/sbi_heap.c          | 5 +++++
>  platform/generic/platform.c | 1 +
>  3 files changed, 9 insertions(+)
> 
> diff --git a/include/sbi/sbi_heap.h b/include/sbi/sbi_heap.h
> index a4b3f0c..3d3feee 100644
> --- a/include/sbi/sbi_heap.h
> +++ b/include/sbi/sbi_heap.h
> @@ -98,4 +98,7 @@ int sbi_heap_init_new(struct sbi_heap_control *hpctrl, unsigned long base,
>                        unsigned long size);
>  int sbi_heap_alloc_new(struct sbi_heap_control **hpctrl);
> 
> +/** Return the total heap size with housekeeping **/
> +unsigned long sbi_heap_total_size(unsigned long usable_size);
> +
>  #endif
> diff --git a/lib/sbi/sbi_heap.c b/lib/sbi/sbi_heap.c
> index 646c2e0..7aa27b1 100644
> --- a/lib/sbi/sbi_heap.c
> +++ b/lib/sbi/sbi_heap.c
> @@ -279,3 +279,8 @@ int sbi_heap_alloc_new(struct sbi_heap_control **hpctrl)
>         *hpctrl = sbi_calloc(1, sizeof(struct sbi_heap_control));
>         return 0;
>  }
> +
> +unsigned long sbi_heap_total_size(unsigned long usable_size)
> +{
> +       return usable_size + usable_size / (HEAP_HOUSEKEEPING_FACTOR - 1);
This patch will conflict with the patch 
https://patchwork.ozlabs.org/project/opensbi/patch/20250617032306.1494528-3-samuel.holland@sifive.com/. 
If more memory is needed, it is recommended to implement it through other means.

Regards,
Xiang W
> +}
> diff --git a/platform/generic/platform.c b/platform/generic/platform.c
> index 47e771a..442f7d5 100644
> --- a/platform/generic/platform.c
> +++ b/platform/generic/platform.c
> @@ -41,6 +41,7 @@ static u32 fw_platform_calculate_heap_size(u32 hart_count)
> 
>         /* For TLB fifo */
>         heap_size += SBI_TLB_INFO_SIZE * (hart_count) * (hart_count);
> +       heap_size = sbi_heap_total_size(heap_size);
> 
>         return BIT_ALIGN(heap_size, HEAP_BASE_ALIGN);
>  }
> --
> 2.43.0




More information about the opensbi mailing list