Page MenuHomeFreeBSD

hwpmc: PMC group syscalls, attach hook, and process-exit drain
Needs ReviewPublic

Authored by afscoelho_gmail.com on Jun 18 2026, 7:06 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Sep 20, 8:43 PM
Unknown Object (File)
Sat, Sep 19, 4:49 PM
Unknown Object (File)
Fri, Sep 11, 2:41 AM
Unknown Object (File)
Wed, Sep 9, 2:16 PM
Unknown Object (File)
Wed, Sep 9, 1:16 PM
Unknown Object (File)
Wed, Sep 9, 11:39 AM
Unknown Object (File)
Wed, Sep 2, 3:11 PM
Unknown Object (File)
Wed, Sep 2, 9:36 AM
Subscribers
None

Details

Summary

Wire the new PMU layer into hwpmc_mod.c:

  • PMC_OP_PMCGROUPCREATE / GROUPADD / GROUPCOMMIT / GROUPRELEASE handlers that drive pmu_group_*.
  • Deferred allocate path: when PMC_F_GROUP_DEFER is set, build a pmu_event via pmu_group_on_allocate and assign a unique per-owner deferred handle (struct pmc::pm_handle, value in PMC_HANDLE_DEFERRED_{BASE,MAX}). Userland receives pm_handle as the pmcid; the kernel keeps pm_id at PMC_ROW_UNASSIGNED until the group assigner rewrites it with the real HW row. pmc_find_pmc / pmc_find_pmc_descriptor_in_process now match against pm_handle so userland keeps working with the original pmcid even after the assigner rewrites pm_id.
  • Lazy attach assignment: pmc_attach_one_process runs pmu_assign_group against the target proc the first time a sibling of a committed-but-unassigned group is attached, so subsequent siblings see a valid ri. The PMCSTART / PMCSTOP / GETCAPS KASSERTs that previously compared pmcid to pm_id now compare to pm_handle (no semantic change for non-deferred PMCs since pm_handle == pm_id at allocation).
  • Process-exit drain: pmc_process_exit invokes pmu_pp_release_all before freeing pp. This severs every pmu_group still hooked off pp and tears down the per-pp rotation kthread, which itself holds pp as its arg. Without this, releasing a group after the target process exited would walk a freed pp and panic LIST_REMOVE with "Bad link prev->next != elm".
  • pmu_group_on_release is wired into pmc_release_pmc_descriptor and removes the pmu_event from the group TAILQ before freeing it, so a later sibling release does not walk a freed pe.
  • PMC_F_GROUP_MUX commit fallback: pmu_group_commit accepts groups with nevents > slots when MUX is requested and the multiplex layer time-slices them.
  • Lock shims for hwpmc_pmu.c. The new PMU layer needs to assert that pmc_sx is held exclusive and to drop/re-acquire it around the rotation kthread's tsleep. Rather than expose pmc_sx as a global symbol to a separate translation unit, hwpmc_mod.c provides hwpmc_pmu_sx_xlock / _xunlock / _assert_xlocked / _sleep wrappers and hwpmc_pmu.c calls those. These shims, like the group entry points, resolve to the PMU layer only on architectures that build it; on others hwpmc_mod.c simply never calls them.

Sponsored by: AMD
Signed-off-by: Raghavendra K T <raghavendra.kt@amd.com>

Diff Detail

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

Event Timeline

afscoelho_gmail.com updated this revision to Diff 185777.

Update to the rebuilt PerfMonV2 grouping and multiplexing stack. The former D57634 build-wiring change is folded into this revision because it is the activation switch for the PMU implementation.