Page MenuHomeFreeBSD

hwpmc : fix perf counter MSR access
Needs ReviewPublic

Authored by on Fri, Sep 6, 4:54 PM.



amd_intr() does not account for the offset (0x200) in the counter MSR address and ends up accessing invalid regions while reading counter value after the 4th counter (0xC001000[8,9,..]) and erroneously updates the counter values for counters [1-4].

Test Plan

Tested on amd64 platform

Diff Detail

rS FreeBSD src repository
Lint Skipped
Unit Tests Skipped

Event Timeline edited the test plan for this revision. (Show Details)

amd_intr() should only check core pmcs for interrupts since other types of pmcs (L3,DF) cannot generate interrupts.

Newer AMD processors have an NMI latency, due to which pmc NMI's are ignored in certain scenarios such as:
Stopping a pmc ( pcd_stop_pmc() (hwpmc_mod.c)) followed by marking the pmc as free ( pcd_config_pmc( , , NULL)). In this scenario we receive an NMI after the pmc has been marked free and the interrupt ends being ignored.

A similar fix for linux was done here:

PMCs interrupting at the same time are collapsed into one interrupt. With the current interrupt handler, the majority of samples are missing for one of the event when two such events are used (unhalted_cpu_cycles and retired_intructions). Out of the two, the one which is allocated first reports all the samples while the other one reports negligible numbers.

Adding a fix for NMI latency.
Similar fix done in linux:

Although it it did not work for linux due to reasons mentioned here:
I think it should work fine on freebsd. Please correct me if I'm wrong.