git: 1bb8b1d99a6c - main - hwpmc: switch in process PMCs on a thread's first run
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 13 Nov 2026 14:32:25 UTC
The branch main has been updated by mhorne:
URL: https://cgit.FreeBSD.org/src/commit/?id=1bb8b1d99a6cfb81e5b8234434b7ea098d6bef44
commit 1bb8b1d99a6cfb81e5b8234434b7ea098d6bef44
Author: Andre Silva <andasilv@amd.com>
AuthorDate: 2026-11-13 14:28:14 +0000
Commit: Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2026-11-13 14:32:21 +0000
hwpmc: switch in process PMCs on a thread's first run
A new thread starts in fork_exit(), not mi_switch(), so its PMCs are
not loaded until its next context switch. Call the switch-in hook
there.
Reviewed by: kib, Osvaldo Janeri Filho <ojanerif@amd.com>, mhorne
MFC after: 1 week
Sponsored by: Advanced Micro Devices, Inc.
Differential Revision: https://reviews.freebsd.org/D60565
---
sys/kern/kern_fork.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c
index 9175a48c47ee..25aebe3dad3c 100644
--- a/sys/kern/kern_fork.c
+++ b/sys/kern/kern_fork.c
@@ -34,6 +34,7 @@
* SUCH DAMAGE.
*/
+#include "opt_hwpmc_hooks.h"
#include "opt_ktrace.h"
#include "opt_kstack_pages.h"
@@ -57,6 +58,9 @@
#include <sys/msan.h>
#include <sys/mutex.h>
#include <sys/priv.h>
+#ifdef HWPMC_HOOKS
+#include <sys/pmckern.h>
+#endif
#include <sys/proc.h>
#include <sys/procdesc.h>
#include <sys/ptrace.h>
@@ -1231,6 +1235,12 @@ fork_exit(void (*callout)(void *, struct trapframe *), void *arg,
sched_fork_exit(td);
+#ifdef HWPMC_HOOKS
+ /* First-run threads bypass the normal scheduler switch-in path. */
+ if (PMC_PROC_IS_USING_PMCS(p))
+ PMC_SWITCH_CONTEXT(td, PMC_FN_CSW_IN);
+#endif
+
/*
* Processes normally resume in mi_switch() after being
* cpu_switch()'ed to, but when children start up they arrive here