• Sandipan Das's avatar
    perf/x86/amd/core: Add PerfMonV2 overflow handling · 7685665c
    Sandipan Das authored
    If AMD Performance Monitoring Version 2 (PerfMonV2) is
    supported, use a new scheme to process Core PMC overflows
    in the NMI handler using the new global control and status
    registers. This will be bypassed on unsupported hardware
    (x86_pmu.version < 2).
    
    In x86_pmu_handle_irq(), overflows are detected by testing
    the contents of the PERF_CTR register for each active PMC in
    a loop. The new scheme instead inspects the overflow bits of
    the global status register.
    
    The Performance Counter Global Status (PerfCntrGlobalStatus)
    register has overflow (PerfCntrOvfl) bits for each PMC. This
    is, however, a read-only MSR. To acknowledge that overflows
    have been processed, the NMI handler must clear the bits by
    writing to the PerfCntrGlobalStatusClr register.
    
    In x86_pmu_handle_irq(), PMCs counting the same event that
    are started and stopped at the same time record slightly
    different counts due to delays in between reads from the
    PERF_CTR registers. This is fixed by stopping and starting
    the PMCs at the same before and with a single write to the
    Performance Counter Global Control (PerfCntrGlobalCtl) upon
    entering and before exiting the NMI handler.
    Signed-off-by: default avatarSandipan Das <sandipan.das@amd.com>
    Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
    Link: https://lkml.kernel.org/r/f20b7e4da0b0a83bdbe05857f354146623bc63ab.1650515382.git.sandipan.das@amd.com
    7685665c
core.c 37.9 KB