Search code examples
linux-kernelperfamd-processor

Why amd_pmu_v2_handle_irq being called when not using perf?


amd_pmu_v2_handle_irq should be used to handle PMU overflow in AMD processor. When I use perf top -ag in the system, it is heavily called.

But when I use the perf stat -a command, there are fewer calls to this function, why is that? And why is there a very small number of related calls when I am not using any perf command?


Solution

  • Does your system have the NMI watchdog timer enabled? It programs a counter to raise an interrupt infrequently. Check your dmesg for NMI watchdog: Enabled. Permanently consumes one hw-PMU counter.

    That message is what I see on Linux 6.5 on my Skylake, before kernel/nmi_watchdog = 0 in my sysctl config file disables it so all four programmable counters per logical core are available.


    Re: perf stat -a not needing many interrupts: total counts over the whole interval doesn't require statistical sampling. It can program with the overflow limits as wide as possible. When it wants to collect data at the end, it can read the counts out of each PMU counter (and add that to the max * overflows that got collected along the way). Interrupts only need to happen for events that exceeded what the PMU counter could hold.

    But perf top is like perf record, programming counters so they do overflow frequently, so it can record a sample (of process/program-counter) each time. This gives it something to show every few seconds with hot spots across the process(es) being profiled, not just total counts at the end like perf stat.

    perf stat is less intrusive, not interrupting the code being profiled much at all. (perf stat -I 1000 collects counter values every 1000 ms, but still doesn't need to know what happened within each interval.)