platform: improve heap size handle
v2 cover platform: improve heap size handle
This patch is split into two parts:
1. the first part is used to adjust the default heap size and make it more driven by the CPU as most allocation is percpu. I think this could reduce the further enlarge for the default heap size.
2. the second part is introduce a DT-based "heap-size", so the platform can set the suitable heap-size. This is serve as a more generic solution for some platform.
Changed from v1:
1. add forgot BIT_ALIGN when processing DT-based "heap-size".
Inochi Amaoto (2):
platform: ensure enough heap size with debug triggers extension
platform: introduce DT-based configurable heap size
docs/opensbi_config.md | 4 ++++ include/sbi/sbi_platform.h | 2 +- platform/generic/platform.c | 28 +++++++++++++++++++++++++--- 3 files changed, 30 insertions(+), 4 deletions(-)
--
2.46.1
PATCH v2 1/2 platform: ensure enough heap size with debug triggers extension
DBTR introduce a big heap allocation to store hart state, this is allocated percpu and needs big space when CPU number is high.
Increase the percpu part to fix this problem, and decrease the fixed part to avoid too big heap size.
--- include/sbi/sbi_platform.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/sbi/sbi_platform.h +1 -1
@@ -152,7 +152,7 @@ struct sbi_platform_operations {/** Platform default heap size */ #define SBI_PLATFORM_DEFAULT_HEAP_SIZE (__num_hart) \ - (0x8000 + 0x800 * (__num_hart)) + (0x4000 + 0x2000 * (__num_hart))/** Representation of a platform */ struct sbi_platform {
Signature · 1 line
2.46.1
PATCH v2 1/2 platform: ensure enough heap size with debug triggers extension
Quoted 19 lines · On Fri, Sep 20, 2024 at 1:09?PM Inochi Amaoto <[email protected]> wrote:
DBTR introduce a big heap allocation to store hart state, this is allocated percpu and needs big space when CPU number is high.
Increase the percpu part to fix this problem, and decrease the fixed part to avoid too big heap size.
Fixes 97f234f (lib: sbi: Introduce the SBI debug triggers extension support)Signed-off-by Inochi Amaoto <[email protected]>Reviewed-by Xiang W <[email protected]>--- include/sbi/sbi_platform.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/sbi/sbi_platform.h +0
-0
include/sbi/sbi_platform.h struct sbi_platform_operations { · line 155
Quoted 5 lines
include/sbi/sbi_platform.h +1
-1@@ -152,7 +152,7 @@ struct sbi_platform_operations {/** Platform default heap size */ #define SBI_PLATFORM_DEFAULT_HEAP_SIZE (__num_hart) \ - (0x8000 + 0x800 * (__num_hart)) + (0x4000 + 0x2000 * (__num_hart))
The per-HART DTBR state is 1536 bytes so I don't see the point in such an arbitrary increase.
How about below ?
#define SBI_PLATFORM_DEFAULT_HEAP_SIZE(__num_hart) \
- (0x8000 + 0x800 * (__num_hart))
+ (0x8000 + 0x1000 * (__num_hart))
Regards,
Anup
Quoted 11 lines
include/sbi/sbi_platform.h +0
-1/** Representation of a platform */ struct sbi_platform { --2.46.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
PATCH v2 1/2 platform: ensure enough heap size with debug triggers extension
Quoted 35 lines · Anup Patel
Quoted 19 lines · On Fri, Sep 20, 2024 at 1:09?PM Inochi Amaoto <[email protected]> wrote:
DBTR introduce a big heap allocation to store hart state, this is allocated percpu and needs big space when CPU number is high.
Increase the percpu part to fix this problem, and decrease the fixed part to avoid too big heap size.
Fixes 97f234f (lib: sbi: Introduce the SBI debug triggers extension support)Signed-off-by Inochi Amaoto <[email protected]>Reviewed-by Xiang W <[email protected]>--- include/sbi/sbi_platform.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/sbi/sbi_platform.h +0
-0include/sbi/sbi_platform.h struct sbi_platform_operations { · line 155
Quoted 5 lines
include/sbi/sbi_platform.h +1
-1@@ -152,7 +152,7 @@ struct sbi_platform_operations {/** Platform default heap size */ #define SBI_PLATFORM_DEFAULT_HEAP_SIZE (__num_hart) \ - (0x8000 + 0x800 * (__num_hart)) + (0x4000 + 0x2000 * (__num_hart))The per-HART DTBR state is 1536 bytes so I don't see the point in such an arbitrary increase.
How about below ?
#define
SBI_PLATFORM_DEFAULT_HEAP_SIZE(__num_hart)\(quoted diff) +1
-1- (0x8000 + 0x800 * (__num_hart)) + (0x8000 + 0x1000 * (__num_hart))
Quoted 3 lines
Regards,
Anup
Yeah, it is OK for me. I will change the formula to 0x1000 per hart, thanks.
Regards,
Inochi
Quoted 11 lines
Quoted 11 lines
include/sbi/sbi_platform.h +0
-1/** Representation of a platform */ struct sbi_platform { --2.46.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
PATCH v2 2/2 platform: introduce DT-based configurable heap size
In reply to Inochi AmaotoThe default heap size will work for most platforms, but for some special platforms, the heap is too small to hold all the information or is too big so that it take too much ram. Introduce configurable heap should solve this problem and make all generic platforms happy.
Add DT-based heap-size for the generic platform.
--- docs/opensbi_config.md | 4 ++++ platform/generic/platform.c | 28 +++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-)
docs/opensbi_config.md +4 -0
@@ -23,6 +23,9 @@ The DT properties of a domain configuration DT node are as follows: set of harts is permitted to perform a cold boot. Otherwise, all harts are allowed to cold boot. +* **heap-size** (Optional) - When present, the SBI will initialize + the heap with the set value (This value is in byte). + * **system-suspend-test** (Optional) - When present, enable a system suspend test implementation which simply waits five seconds and issues a WFI.
@@ -36,6 +39,7 @@ The OpenSBI Configuration Node will be deleted at the end of cold boot opensbi-config { compatible = "opensbi,config"; cold-boot-harts = <&cpu1 &cpu2 &cpu3 &cpu4>; + heap-size = <0x400000>; system-suspend-test; }; };
platform/generic/platform.c +25 -3
@@ -69,6 +69,28 @@ static u32 fw_platform_calculate_heap_size(u32 hart_count)return BIT_ALIGN (heap_size,HEAP_BASE_ALIGN ); } +static u32 fw_platform_get_heap_size (const void *fdt,u32 hart_count) +{ +int chosen_offset, config_offset, len; +const fdt32_t *val; + +/* Get the heap size from device tree */ + chosen_offset =fdt_path_offset (fdt,"/chosen" ); +if (chosen_offset <0 ) + goto default_config; + + config_offset =fdt_node_offset_by_compatible (fdt, chosen_offset,"opensbi,config" ); +if (config_offset <0 ) + goto default_config; + + val = (fdt32_t *)fdt_getprop (fdt, config_offset,"heap-size" , &len); +if (len >0 && val) +return BIT_ALIGN (fdt32_to_cpu (*val),HEAP_BASE_ALIGN ); + +default_config: +return fw_platform_calculate_heap_size (hart_count); +} +extern struct sbi_platform platform;static bool platform_has_mlevel_imsic = false;static u32 generic_hart_index2id[SBI_HARTMASK_MAX_BITS ] = {0 };
@@ -76,9 +98,9 @@ static u32 generic_hart_index2id[SBI_HARTMASK_MAX_BITS] = { 0 }; static DECLARE_BITMAP(generic_coldboot_harts, SBI_HARTMASK_MAX_BITS);/* -* The fw_platform_coldboot_harts_init() function is called by fw_platform_init() +* The fw_platform_coldboot_harts_init() function is called by fw_platform_init() * function to initialize the cold boot harts allowed by the generic platform -* according to the DT property "cold-boot-harts" in "/chosen/opensbi-config" +* according to the DT property "cold-boot-harts" in "/chosen/opensbi-config" * DT node. If there is no "cold-boot-harts" in DT, all harts will be allowed. */ static void fw_platform_coldboot_harts_init (const void *fdt)
@@ -185,7 +207,7 @@ unsigned long fw_platform_init(unsigned long arg0, unsigned long arg1, } platform.hart_count = hart_count; - platform.heap_size =fw_platform_calculate_heap_size (hart_count); + platform.heap_size =fw_platform_get_heap_size (fdt, hart_count); platform_has_mlevel_imsic =fdt_check_imsic_mlevel (fdt);fw_platform_coldboot_harts_init (fdt);
Signature · 1 line
2.46.1
PATCH v2 2/2 platform: introduce DT-based configurable heap size
? 2024-09-20???? 15:37 +0800?Inochi Amaoto???
Quoted 50 lines
The default heap size will work for most platforms, but for some special platforms, the heap is too small to hold all the information or is too big so that it take too much ram. Introduce configurable heap should solve this problem and make all generic platforms happy.
Add DT-based heap-size for the generic platform.
Signed-off-by Inochi Amaoto <[email protected]>---
?docs/opensbi_config.md????? |? 4 ++++ ?platform/generic/platform.c | 28 +++++++++++++++++++++++++--- ?2 files changed, 29 insertions(+), 3 deletions(-)docs/opensbi_config.md +0
-0@@ -23,6 +23,9 @@ The DT properties of a domain configuration DT node are as follows:?? set of harts is permitted to perform a cold boot. Otherwise, all ?? harts are allowed to cold boot.
?docs/opensbi_config.md +3
-0+* **heap-size** (Optional) - When present, the SBI will initialize +? the heap with the set value (This value is in byte). +?* **system-suspend-test** (Optional) - When present, enable a system ?? suspend test implementation which simply waits five seconds and issues a WFI. ?
docs/opensbi_config.md +1
-0@@ -36,6 +39,7 @@ The OpenSBI Configuration Node will be deleted at the end of cold boot ???????? opensbi-config { ???????????? compatible = "opensbi,config"; ???????????? cold-boot-harts = <&cpu1 &cpu2 &cpu3 &cpu4>; +??????????? heap-size = <0x400000>; ???????????? system-suspend-test; ???????? }; ???? };platform/generic/platform.c +0
-0@@ -69,6 +69,28 @@ static u32 fw_platform_calculate_heap_size(u32 hart_count) ? return BIT_ALIGN(heap_size, HEAP_BASE_ALIGN); ?}?
platform/generic/platform.c +7
-0+static u32 fw_platform_get_heap_size (const void *fdt,u32 hart_count) +{ +int chosen_offset, config_offset, len; +const fdt32_t *val; + +/* Get the heap size from device tree */ + chosen_offset =fdt_path_offset (fdt,"/chosen" );
platform/generic/platform.c static u32 fw_platform_calculate_heap_size(u32 hart_count) · line 88
Quoted 10 lines
platform/generic/platform.c +10
-0+if (chosen_offset <0 ) + goto default_config; + + config_offset =fdt_node_offset_by_compatible (fdt, chosen_offset,"opensbi,config" ); +if (config_offset <0 ) + goto default_config; + + val = (fdt32_t *)fdt_getprop (fdt, config_offset,"heap-size" , &len); +if (len >0 && val) +return BIT_ALIGN (fdt32_to_cpu (*val),HEAP_BASE_ALIGN );
Look good to me
Quoted 29 lines
platform/generic/platform.c +5
-0+ +default_config: +return fw_platform_calculate_heap_size (hart_count); +} +?extern struct
sbi_platformplatform;
?static boolplatform_has_mlevel_imsic= false;
?static u32 generic_hart_index2id[SBI_HARTMASK_MAX_BITS] = { 0 };platform/generic/platform.c +0
-0@@ -76,9 +98,9 @@ static u32 generic_hart_index2id[SBI_HARTMASK_MAX_BITS] = { 0 }; ?static DECLARE_BITMAP(generic_coldboot_harts, SBI_HARTMASK_MAX_BITS);?
?/*
- * Thefw_platform_coldboot_harts_init()function is called byfw_platform_init()
+ * Thefw_platform_coldboot_harts_init()function is called byfw_platform_init()? * function to initialize the cold boot harts allowed by the generic platform
- * according to the DT property "cold-boot-harts" in "/chosen/opensbi-config"
+ * according to the DT property "cold-boot-harts" in "/chosen/opensbi-config" ? * DT node. If there is no "cold-boot-harts" in DT, all harts will be allowed. ? */
?static voidfw_platform_coldboot_harts_init(const void *fdt)platform/generic/platform.c +0
-0@@ -185,7 +207,7 @@ unsigned long fw_platform_init(unsigned long arg0, unsigned long arg1, ? }?
? platform.hart_count =hart_count;platform/generic/platform.c +1
-1- platform.heap_size =fw_platform_calculate_heap_size (hart_count); + platform.heap_size =fw_platform_get_heap_size (fdt, hart_count);?
platform_has_mlevel_imsic=fdt_check_imsic_mlevel(fdt);
?
?fw_platform_coldboot_harts_init(fdt);
PATCH v2 2/2 platform: introduce DT-based configurable heap size
Quoted 63 lines · Xiang W
? 2024-09-20???? 15:37 +0800?Inochi Amaoto???
Quoted 50 lines
The default heap size will work for most platforms, but for some special platforms, the heap is too small to hold all the information or is too big so that it take too much ram. Introduce configurable heap should solve this problem and make all generic platforms happy.
Add DT-based heap-size for the generic platform.
Signed-off-by Inochi Amaoto <[email protected]>---
?docs/opensbi_config.md????? |? 4 ++++ ?platform/generic/platform.c | 28 +++++++++++++++++++++++++--- ?2 files changed, 29 insertions(+), 3 deletions(-)docs/opensbi_config.md +0
-0@@ -23,6 +23,9 @@ The DT properties of a domain configuration DT node are as follows:?? set of harts is permitted to perform a cold boot. Otherwise, all ?? harts are allowed to cold boot.
?docs/opensbi_config.md +3
-0+* **heap-size** (Optional) - When present, the SBI will initialize +? the heap with the set value (This value is in byte). +?* **system-suspend-test** (Optional) - When present, enable a system ?? suspend test implementation which simply waits five seconds and issues a WFI. ?
docs/opensbi_config.md +1
-0@@ -36,6 +39,7 @@ The OpenSBI Configuration Node will be deleted at the end of cold boot ???????? opensbi-config { ???????????? compatible = "opensbi,config"; ???????????? cold-boot-harts = <&cpu1 &cpu2 &cpu3 &cpu4>; +??????????? heap-size = <0x400000>; ???????????? system-suspend-test; ???????? }; ???? };platform/generic/platform.c +0
-0@@ -69,6 +69,28 @@ static u32 fw_platform_calculate_heap_size(u32 hart_count) ? return BIT_ALIGN(heap_size, HEAP_BASE_ALIGN); ?}?
platform/generic/platform.c +7
-0+static u32 fw_platform_get_heap_size (const void *fdt,u32 hart_count) +{ +int chosen_offset, config_offset, len; +const fdt32_t *val; + +/* Get the heap size from device tree */ + chosen_offset =fdt_path_offset (fdt,"/chosen" );platform/generic/platform.c static u32 fw_platform_calculate_heap_size(u32 hart_count) · line 88
Quoted 10 lines
platform/generic/platform.c +10
-0+if (chosen_offset <0 ) + goto default_config; + + config_offset =fdt_node_offset_by_compatible (fdt, chosen_offset,"opensbi,config" ); +if (config_offset <0 ) + goto default_config; + + val = (fdt32_t *)fdt_getprop (fdt, config_offset,"heap-size" , &len); +if (len >0 && val) +return BIT_ALIGN (fdt32_to_cpu (*val),HEAP_BASE_ALIGN );Look good to me
Quoted 1 line
Reviewed-by Xiang W <[email protected]>
Thanks
Quoted 35 lines
Quoted 29 lines
platform/generic/platform.c +5
-0+ +default_config: +return fw_platform_calculate_heap_size (hart_count); +} +?extern struct
sbi_platformplatform;
?static boolplatform_has_mlevel_imsic= false;
?static u32 generic_hart_index2id[SBI_HARTMASK_MAX_BITS] = { 0 };platform/generic/platform.c +0
-0@@ -76,9 +98,9 @@ static u32 generic_hart_index2id[SBI_HARTMASK_MAX_BITS] = { 0 }; ?static DECLARE_BITMAP(generic_coldboot_harts, SBI_HARTMASK_MAX_BITS);?
?/*
- * Thefw_platform_coldboot_harts_init()function is called byfw_platform_init()
+ * Thefw_platform_coldboot_harts_init()function is called byfw_platform_init()? * function to initialize the cold boot harts allowed by the generic platform
- * according to the DT property "cold-boot-harts" in "/chosen/opensbi-config"
+ * according to the DT property "cold-boot-harts" in "/chosen/opensbi-config" ? * DT node. If there is no "cold-boot-harts" in DT, all harts will be allowed. ? */
?static voidfw_platform_coldboot_harts_init(const void *fdt)platform/generic/platform.c +0
-0@@ -185,7 +207,7 @@ unsigned long fw_platform_init(unsigned long arg0, unsigned long arg1, ? }?
? platform.hart_count =hart_count;platform/generic/platform.c +1
-1- platform.heap_size =fw_platform_calculate_heap_size (hart_count); + platform.heap_size =fw_platform_get_heap_size (fdt, hart_count);?
platform_has_mlevel_imsic=fdt_check_imsic_mlevel(fdt);
?
?fw_platform_coldboot_harts_init(fdt);Signature · 3 lines
opensbi mailing list opensbi at lists.infradead.org http://lists.infradead.org/mailman/listinfo/opensbi
PATCH v2 2/2 platform: introduce DT-based configurable heap size
In reply to Inochi AmaotoQuoted 19 lines · On Fri, Sep 20, 2024 at 1:09?PM Inochi Amaoto <[email protected]> wrote:
The default heap size will work for most platforms, but for some special platforms, the heap is too small to hold all the information or is too big so that it take too much ram. Introduce configurable heap should solve this problem and make all generic platforms happy.
Add DT-based heap-size for the generic platform.
Signed-off-by Inochi Amaoto <[email protected]>--- docs/opensbi_config.md | 4 ++++ platform/generic/platform.c | 28 +++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-)docs/opensbi_config.md +0
-0
docs/opensbi_config.md The DT properties of a domain configuration DT node are as follows: · line 27
Quoted 5 lines
docs/opensbi_config.md +2
-0@@ -23,6 +23,9 @@ The DT properties of a domain configuration DT node are as follows: set of harts is permitted to perform a cold boot. Otherwise, all harts are allowed to cold boot. +* **heap-size** (Optional) - When present, the SBI will initialize + the heap with the set value (This value is in byte).
The description can be "When present, the specified value is used as the size of the heap in bytes."
Quoted 70 lines
docs/opensbi_config.md +2
-0+ * **system-suspend-test** (Optional) - When present, enable a system suspend test implementation which simply waits five seconds and issues a WFI.@@ -36,6 +39,7 @@ The OpenSBI Configuration Node will be deleted at the end of cold boot opensbi-config { compatible = "opensbi,config"; cold-boot-harts = <&cpu1 &cpu2 &cpu3 &cpu4>; + heap-size = <0x400000>; system-suspend-test; }; };platform/generic/platform.c +25
-4@@ -69,6 +69,28 @@ static u32 fw_platform_calculate_heap_size(u32 hart_count)return BIT_ALIGN (heap_size,HEAP_BASE_ALIGN ); } +static u32 fw_platform_get_heap_size (const void *fdt,u32 hart_count) +{ +int chosen_offset, config_offset, len; +const fdt32_t *val; + +/* Get the heap size from device tree */ + chosen_offset =fdt_path_offset (fdt,"/chosen" ); +if (chosen_offset <0 ) + goto default_config; + + config_offset =fdt_node_offset_by_compatible (fdt, chosen_offset,"opensbi,config" ); +if (config_offset <0 ) + goto default_config; + + val = (fdt32_t *)fdt_getprop (fdt, config_offset,"heap-size" , &len); +if (len >0 && val) +return BIT_ALIGN (fdt32_to_cpu (*val),HEAP_BASE_ALIGN ); + +default_config: +return fw_platform_calculate_heap_size (hart_count); +} +extern struct sbi_platform platform;static bool platform_has_mlevel_imsic = false;static u32 generic_hart_index2id[SBI_HARTMASK_MAX_BITS ] = {0 };@@ -76,9 +98,9 @@ static u32 generic_hart_index2id[SBI_HARTMASK_MAX_BITS] = { 0 }; static DECLARE_BITMAP(generic_coldboot_harts, SBI_HARTMASK_MAX_BITS);/* -* The fw_platform_coldboot_harts_init() function is called by fw_platform_init() +* The fw_platform_coldboot_harts_init() function is called by fw_platform_init() * function to initialize the cold boot harts allowed by the generic platform -* according to the DT property "cold-boot-harts" in "/chosen/opensbi-config" +* according to the DT property "cold-boot-harts" in "/chosen/opensbi-config" * DT node. If there is no "cold-boot-harts" in DT, all harts will be allowed. */ static void fw_platform_coldboot_harts_init (const void *fdt)@@ -185,7 +207,7 @@ unsigned long fw_platform_init(unsigned long arg0, unsigned long arg1, } platform.hart_count = hart_count; - platform.heap_size =fw_platform_calculate_heap_size (hart_count); + platform.heap_size =fw_platform_get_heap_size (fdt, hart_count); platform_has_mlevel_imsic =fdt_check_imsic_mlevel (fdt);fw_platform_coldboot_harts_init (fdt); --2.46.1
Quoted 4 lines
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
Otherwise, this looks good to me.
Regards,
Anup