diff --git a/arch/arm64/kernel/perfctr.c b/arch/arm64/kernel/perfctr.c index 518173ab..b9beb948 100644 --- a/arch/arm64/kernel/perfctr.c +++ b/arch/arm64/kernel/perfctr.c @@ -183,3 +183,8 @@ int ihk_mc_perfctr_fixed_init(int counter, int mode) { return -1; } + +int ihk_mc_perf_get_num_counters(void) +{ + return cpu_pmu.per_cpu[ihk_mc_get_processor_id()].num_events; +} diff --git a/arch/x86_64/kernel/perfctr.c b/arch/x86_64/kernel/perfctr.c index cc10f3c1..1075921a 100644 --- a/arch/x86_64/kernel/perfctr.c +++ b/arch/x86_64/kernel/perfctr.c @@ -498,3 +498,8 @@ int ihk_mc_perfctr_alloc_counter(unsigned int *type, unsigned long *config, unsi return ret; } + +int ihk_mc_perf_get_num_counters(void) +{ + return NUM_PERF_COUNTERS; +} diff --git a/kernel/syscall.c b/kernel/syscall.c index 986f9ba1..8ae1f538 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -3768,9 +3768,10 @@ perf_counter_alloc(struct thread *thread) { int ret = -EINVAL; int i = 0; + const int counters = ihk_mc_perf_get_num_counters(); // find avail generic counter - for (i = 0; i < NUM_PERF_COUNTERS; i++) { + for (i = 0; i < counters; i++) { if(!(thread->pmc_alloc_map & (1 << i))) { ret = i; break; diff --git a/lib/include/ihk/perfctr.h b/lib/include/ihk/perfctr.h index 89fdbb95..bd8fa16f 100644 --- a/lib/include/ihk/perfctr.h +++ b/lib/include/ihk/perfctr.h @@ -72,6 +72,7 @@ int ihk_mc_perfctr_read_mask(unsigned long counter_mask, unsigned long *value); unsigned long ihk_mc_perfctr_read(int counter); unsigned long ihk_mc_perfctr_read_msr(int counter); int ihk_mc_perfctr_alloc_counter(unsigned int *type, unsigned long *config, unsigned long pmc_status); +int ihk_mc_perf_get_num_counters(void); #endif