diff --git a/arch/arm64/kernel/perfctr.c b/arch/arm64/kernel/perfctr.c index 2989a427..639d6409 100644 --- a/arch/arm64/kernel/perfctr.c +++ b/arch/arm64/kernel/perfctr.c @@ -184,25 +184,13 @@ int ihk_mc_perfctr_read_mask(unsigned long counter_mask, unsigned long *value) return 0; } -int ihk_mc_perfctr_alloc(struct thread *thread, int cpu_cycles) +int ihk_mc_perfctr_alloc(struct thread *thread, struct mc_perf_event *event) { - int ret = -EINVAL; - int i = 1; const int counters = ihk_mc_perf_get_num_counters(); - // Counter 0 is only used for CPU cycles on ARM - if (cpu_cycles) { - i = 0; - } - - for (; i < counters; i++) { - if (!(thread->pmc_alloc_map & (1 << i))) { - ret = i; - break; - } - } - - return ret; + return cpu_pmu.get_event_idx(counters, + thread->pmc_alloc_map, + event->hw_config); } unsigned long ihk_mc_perfctr_read(int counter) diff --git a/arch/x86_64/kernel/perfctr.c b/arch/x86_64/kernel/perfctr.c index 505c3a00..8c4b8b88 100644 --- a/arch/x86_64/kernel/perfctr.c +++ b/arch/x86_64/kernel/perfctr.c @@ -377,7 +377,7 @@ int ihk_mc_perfctr_read_mask(unsigned long counter_mask, unsigned long *value) return 0; } -int ihk_mc_perfctr_alloc(struct thread *thread, int cpu_cycles) +int ihk_mc_perfctr_alloc(struct thread *thread, struct mc_perf_event *event) { int ret = -EINVAL; int i = 0; diff --git a/kernel/syscall.c b/kernel/syscall.c index f0dc405c..f2637293 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -4187,9 +4187,7 @@ SYSCALL_DECLARE(perf_event_open) event->pid = pid; - counter_idx = ihk_mc_perfctr_alloc(thread, - (attr->type == PERF_TYPE_HARDWARE && - attr->config == PERF_COUNT_HW_CPU_CYCLES)); + counter_idx = ihk_mc_perfctr_alloc(thread, event); if (counter_idx < 0) { return counter_idx; } diff --git a/lib/include/ihk/perfctr.h b/lib/include/ihk/perfctr.h index a2038ce4..1a7b806a 100644 --- a/lib/include/ihk/perfctr.h +++ b/lib/include/ihk/perfctr.h @@ -72,7 +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_perfctr_alloc(struct thread *thread, int cpu_cycles); +int ihk_mc_perfctr_alloc(struct thread *thread, struct mc_perf_event *event); int ihk_mc_perf_counter_mask_check(unsigned long counter_mask); int ihk_mc_perf_get_num_counters(void);