diff options
author | Remy Noel <mocramis@gmail.com> | 2018-04-30 20:55:28 +0200 |
---|---|---|
committer | Remy Noel <mocramis@gmail.com> | 2018-05-03 14:21:10 +0200 |
commit | 8f7aeebfc21af051ecb914d286564a10492927a0 (patch) | |
tree | 3a4e131977aefbb2cdce854b52381d64eea46f7e /arch/x86/machine/pmu_amd.c | |
parent | c4ba76cc4f84a25b259e9089b5e49a6edc015f1d (diff) |
perfmon: add polling overflow implementation in perfmon
Diffstat (limited to 'arch/x86/machine/pmu_amd.c')
-rw-r--r-- | arch/x86/machine/pmu_amd.c | 38 |
1 files changed, 4 insertions, 34 deletions
diff --git a/arch/x86/machine/pmu_amd.c b/arch/x86/machine/pmu_amd.c index 34df620..8e56bfa 100644 --- a/arch/x86/machine/pmu_amd.c +++ b/arch/x86/machine/pmu_amd.c @@ -21,6 +21,7 @@ #include <stdint.h> #include <kern/init.h> +#include <kern/clock.h> #include <kern/log.h> #include <kern/perfmon.h> #include <machine/cpu.h> @@ -175,7 +176,6 @@ pmu_amd_start(unsigned int pmc_id, unsigned int raw_event_id) /* TODO Handle PERFMON_EF_KERN/PERFMON_EF_USER */ high = code->event_select >> 8; low = PMU_AMD_EVTSEL_EN - | PMU_AMD_EVTSEL_INT | PMU_AMD_EVTSEL_OS | PMU_AMD_EVTSEL_USR | (code->umask << 8) @@ -205,38 +205,6 @@ pmu_amd_write(unsigned int pmc_id, uint64_t value) cpu_set_msr64(PMU_AMD_MSR_PERCTR0 + pmc_id, value); } -/* - * TODO Make the perfmon module handle basic overflow handling by polling - * counters. - */ -static void -pmu_amd_handle_of_intr_v1(void) -{ - struct pmu_amd *pmu; - uint64_t value, prev; - unsigned int mask; - - pmu = pmu_amd_get(); - - for (unsigned int pmc_id = 0; pmc_id != PMU_AMD_NR_PMCS; pmc_id++) { - mask = (1U << pmc_id); - - if (pmu->pmc_bm & mask) { - continue; - } - - value = pmu_amd_read(pmc_id); - prev = perfmon_cpu_pmc_get_prev(pmc_id); - - if (prev > value) { - /* Overflow */ - perfmon_cpu_pmc_inc_of(pmc_id); - /* Prevents us from overflowing twice */ - perfmon_cpu_pmc_set_prev(pmc_id, value); - } - } -} - static int __init pmu_amd_setup(void) { @@ -259,7 +227,9 @@ pmu_amd_setup(void) pmu->pmc_bm = (1U << PMU_AMD_NR_PMCS) - 1; pmu_driver.pmc_width = PMU_AMD_PMC_WIDTH; - pmu_driver.of_max_ticks = 1UL << (pmu_driver.pmc_width - 1); + /* Set max_tick to half the number of instruction per seconds. */ + pmu_driver.of_max_ticks = + (1UL << (pmu_driver.pmc_width - 1)) / (cpu_get_freq() / CLOCK_FREQ); pmu_driver.ops.info = pmu_amd_info; pmu_driver.ops.translate = pmu_amd_translate; |