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.
Tags
None
Referenced Files
F174489751: D60187.id188484.diff
Sat, Oct 3, 3:58 PM
F174438236: D60187.id188269.diff
Sat, Oct 3, 5:33 AM
Unknown Object (File)
Fri, Oct 2, 5:09 AM
Unknown Object (File)
Fri, Oct 2, 2:52 AM
Unknown Object (File)
Thu, Oct 1, 10:49 PM
Unknown Object (File)
Thu, Oct 1, 12:40 AM
Unknown Object (File)
Thu, Oct 1, 12:07 AM
Subscribers

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

Event Timeline

This one requires a bit more study on my part...

sys/dev/hwpmc/hwpmc_soft.c
398

Note the use of TDA_HWPMC here.

412–422

I have a concern/question about this sharing of the AST handler for these distinct purposes; I am just not sure of the implications.

On the one hand, I believe it is always safe (even useful) to process any pending user callchains. This is why it is registered to run unconditionally; a pending AST from any source will still invoke this handler.

But what about the other case (above), where software PMCs are in use, and ast_sched(curthread, TDA_HWPMC) is called? Is there any downside/danger of invoking pmc_ast_load() on a thread that does not intend it?

Rebase on main (D60141 and D60185 are committed). No change.