diff options
| author | Samuel Holland <[email protected]> | 2025-02-13 14:48:39 -0800 |
|---|---|---|
| committer | Anup Patel <[email protected]> | 2025-02-19 18:25:17 +0530 |
| commit | a2c172f526b52eb428d9077fab8cd8690c7e2f19 (patch) | |
| tree | 0b52a45b8d9f788a5814fd82d07ec565db440a5a /lib | |
| parent | f95d1140f61d4afdd922379bff40edf8556c64e4 (diff) | |
lib: utils/fdt: Allocate fdt_pmu_evt_select on the heap
This reduces .bss size by 8 KiB, and should reduce overall memory usage
since most platforms will have significantly fewer than 512 entries in
this table. At the same time, it removes the fixed table size limit.
Since the table is only used within fdt_pmu.c, instead of updating the
extern declaration, make the table local to this file.
Signed-off-by: Samuel Holland <[email protected]>
Reviewed-by: Anup Patel <[email protected]>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/utils/fdt/fdt_pmu.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/utils/fdt/fdt_pmu.c b/lib/utils/fdt/fdt_pmu.c index 22760603..ee76d87f 100644 --- a/lib/utils/fdt/fdt_pmu.c +++ b/lib/utils/fdt/fdt_pmu.c @@ -11,15 +11,14 @@ #include <libfdt.h> #include <sbi/sbi_hart.h> #include <sbi/sbi_error.h> +#include <sbi/sbi_heap.h> #include <sbi/sbi_pmu.h> #include <sbi/sbi_scratch.h> #include <sbi_utils/fdt/fdt_helper.h> #include <sbi_utils/fdt/fdt_pmu.h> -#define FDT_PMU_HW_EVENT_MAX (SBI_PMU_HW_EVENT_MAX * 2) - -struct fdt_pmu_hw_event_select_map fdt_pmu_evt_select[FDT_PMU_HW_EVENT_MAX] = {0}; -uint32_t hw_event_count; +static struct fdt_pmu_hw_event_select_map *fdt_pmu_evt_select; +static uint32_t hw_event_count; uint64_t fdt_pmu_get_select_value(uint32_t event_idx) { @@ -91,13 +90,19 @@ int fdt_pmu_setup(const void *fdt) "riscv,event-to-mhpmevent", &len); if (event_val) { len = len / (sizeof(u32) * 3); + + hw_event_count = len; + fdt_pmu_evt_select = sbi_calloc(hw_event_count, + sizeof(*fdt_pmu_evt_select)); + if (!fdt_pmu_evt_select) + return SBI_ENOMEM; + for (i = 0; i < len; i++) { - event = &fdt_pmu_evt_select[hw_event_count]; + event = &fdt_pmu_evt_select[i]; event->eidx = fdt32_to_cpu(event_val[3 * i]); event->select = fdt32_to_cpu(event_val[3 * i + 1]); event->select = (event->select << 32) | fdt32_to_cpu(event_val[3 * i + 2]); - hw_event_count++; } } |
