forked from Mirrors/opensbi
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 <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
This commit is contained in:

committed by
Anup Patel

parent
f95d1140f6
commit
a2c172f526
@@ -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++;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user