Page MenuHomeFreeBSD

hwpmc: load a started PMC on threads that already run
Needs ReviewPublic

Authored by afscoelho_gmail.com on Wed, Sep 30, 9:10 PM.

Details

Reviewers
mhorne
ali_mashtizadeh.com
gnn
Group Reviewers
pmc
Summary

A process-mode PMC is loaded only at context switch-in. After
pmcstat -t starts a PMC on a process, its running threads keep
running without it. At the end of a time slice the scheduler can pick
the same thread and skip the switch hooks, so a CPU-bound thread alone
on its CPU counts 0 until it blocks.

At PMC_OP_PMCSTART for a process-mode PMC, send the TDA_HWPMC AST to
the running threads of each target. The handler loads the PMCs that
are not loaded on the CPU yet.

Add a test: start a counting PMC on a child that spins and never
blocks, and check that it counts.

Sponsored by: AMD

Test Plan

Start a counting PMC on a CPU-bound process that never blocks:

<cpu-bound loop> & ; pmcstat -t $! -p instructions -w 1 ; kill the loop

Before: DTrace shows no amd_start_pmc_v2 call in the target, and the
final count is 0.
After: the PMC is loaded at start, and the final count is correct.

Note: PMCRW still returns the value saved at the last switch-out, so
the -w interval values stay 0 while such a target does not switch out.
That is a separate issue.

tests/sys/pmc/pmc_attach_running_test fails before and passes after.
Tested with kyua tests/sys/pmc on a kernel with INVARIANTS and WITNESS.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 77564
Build 74447: arc lint + arc unit