From b945367c9062eb8d2b6a2692fc2ff0c33c228b83 Mon Sep 17 00:00:00 2001 From: "TOIDA,Suguru" Date: Tue, 9 Apr 2019 16:20:33 +0900 Subject: [PATCH] pmu: add ihk_mc_perfctr_value function Change-Id: I88d25586dd470737a3eac4c3a4f1955ae6e41d64 --- arch/arm64/kernel/perfctr.c | 8 ++++++++ arch/x86_64/kernel/perfctr.c | 8 ++++++++ kernel/syscall.c | 4 ++-- lib/include/ihk/perfctr.h | 1 + 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/perfctr.c b/arch/arm64/kernel/perfctr.c index 2021ff7e..2b77c9f3 100644 --- a/arch/arm64/kernel/perfctr.c +++ b/arch/arm64/kernel/perfctr.c @@ -198,6 +198,14 @@ unsigned long ihk_mc_perfctr_read(int counter) return count; } +unsigned long ihk_mc_perfctr_value(int counter, unsigned long correction) +{ + unsigned long count = ihk_mc_perfctr_read(counter) + correction; + + count &= ((1UL << 32) - 1); + return count; +} + int ihk_mc_perfctr_alloc_counter(unsigned int *type, unsigned long *config, unsigned long pmc_status) { diff --git a/arch/x86_64/kernel/perfctr.c b/arch/x86_64/kernel/perfctr.c index 8c4b8b88..22da38f1 100644 --- a/arch/x86_64/kernel/perfctr.c +++ b/arch/x86_64/kernel/perfctr.c @@ -421,6 +421,14 @@ unsigned long ihk_mc_perfctr_read(int counter) return retval; } +unsigned long ihk_mc_perfctr_value(int counter, unsigned long correction) +{ + unsigned long count = ihk_mc_perfctr_read(counter) + correction; + + count &= 0x000000ffffffffffL; + return count; +} + // read by rdmsr unsigned long ihk_mc_perfctr_read_msr(int counter) { diff --git a/kernel/syscall.c b/kernel/syscall.c index f2637293..90fc81ff 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -3723,8 +3723,8 @@ unsigned long perf_event_read_value(struct mc_perf_event *event) int counter_id = event->counter_id; if(event->pid == 0) { - pmc_count = ihk_mc_perfctr_read(counter_id) + event->attr.sample_freq; - pmc_count &= 0x000000ffffffffffL; // 40bit MASK + pmc_count = ihk_mc_perfctr_value(counter_id, + event->attr.sample_freq); } rtn_count += event->count + pmc_count; diff --git a/lib/include/ihk/perfctr.h b/lib/include/ihk/perfctr.h index 1a7b806a..01bb2c1d 100644 --- a/lib/include/ihk/perfctr.h +++ b/lib/include/ihk/perfctr.h @@ -70,6 +70,7 @@ int ihk_mc_perfctr_reset(int counter); int ihk_mc_perfctr_set(int counter, long value); 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_value(int counter, unsigned long correction); 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, struct mc_perf_event *event);