From 9b3d5a4a61e736e632580cdab31293cbdf8b6a92 Mon Sep 17 00:00:00 2001 From: mpi Date: Mon, 14 Aug 2023 08:33:24 +0000 Subject: [PATCH] Extend scheduler tracepoints to follow CPU jumping. - Add two new tracpoints sched:fork & sched:steal - Include selected CPU number in sched:wakeup - Add sched:unsleep corresponding to sched:sleep which matches add/removal of threads on the sleep queue ok claudio@ --- sys/dev/dt/dt_prov_static.c | 10 ++++++++-- sys/kern/kern_fork.c | 5 ++++- sys/kern/kern_sched.c | 5 ++++- sys/kern/kern_synch.c | 4 ++-- sys/kern/sched_bsd.c | 7 +++++-- 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/sys/dev/dt/dt_prov_static.c b/sys/dev/dt/dt_prov_static.c index dc2398175dd..0d67832806c 100644 --- a/sys/dev/dt/dt_prov_static.c +++ b/sys/dev/dt/dt_prov_static.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dt_prov_static.c,v 1.20 2023/07/06 19:46:53 kn Exp $ */ +/* $OpenBSD: dt_prov_static.c,v 1.21 2023/08/14 08:33:24 mpi Exp $ */ /* * Copyright (c) 2019 Martin Pieuchot @@ -39,11 +39,14 @@ struct dt_provider dt_prov_static = { */ DT_STATIC_PROBE2(sched, dequeue, "pid_t", "pid_t"); DT_STATIC_PROBE2(sched, enqueue, "pid_t", "pid_t"); +DT_STATIC_PROBE3(sched, fork, "pid_t", "pid_t", "int"); DT_STATIC_PROBE2(sched, off__cpu, "pid_t", "pid_t"); DT_STATIC_PROBE0(sched, on__cpu); DT_STATIC_PROBE0(sched, remain__cpu); DT_STATIC_PROBE0(sched, sleep); -DT_STATIC_PROBE0(sched, wakeup); +DT_STATIC_PROBE3(sched, steal, "pid_t", "pid_t", "int"); +DT_STATIC_PROBE2(sched, unsleep, "pid_t", "pid_t"); +DT_STATIC_PROBE3(sched, wakeup, "pid_t", "pid_t", "int"); /* * Raw syscalls @@ -106,10 +109,13 @@ struct dt_probe *const dtps_static[] = { /* Scheduler */ &_DT_STATIC_P(sched, dequeue), &_DT_STATIC_P(sched, enqueue), + &_DT_STATIC_P(sched, fork), &_DT_STATIC_P(sched, off__cpu), &_DT_STATIC_P(sched, on__cpu), &_DT_STATIC_P(sched, remain__cpu), &_DT_STATIC_P(sched, sleep), + &_DT_STATIC_P(sched, steal), + &_DT_STATIC_P(sched, unsleep), &_DT_STATIC_P(sched, wakeup), /* Raw syscalls */ &_DT_STATIC_P(raw_syscalls, sys_enter), diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c index 97c9c4b7c5c..8d1f245935a 100644 --- a/sys/kern/kern_fork.c +++ b/sys/kern/kern_fork.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_fork.c,v 1.248 2023/07/02 11:16:03 deraadt Exp $ */ +/* $OpenBSD: kern_fork.c,v 1.249 2023/08/14 08:33:24 mpi Exp $ */ /* $NetBSD: kern_fork.c,v 1.29 1996/02/09 18:59:34 christos Exp $ */ /* @@ -56,6 +56,7 @@ #include #include #include +#include #include @@ -316,6 +317,8 @@ fork_thread_start(struct proc *p, struct proc *parent, int flags) SCHED_LOCK(s); ci = sched_choosecpu_fork(parent, flags); + TRACEPOINT(sched, fork, p->p_tid + THREAD_PID_OFFSET, + p->p_p->ps_pid, CPU_INFO_UNIT(ci)); setrunqueue(ci, p, p->p_usrpri); SCHED_UNLOCK(s); } diff --git a/sys/kern/kern_sched.c b/sys/kern/kern_sched.c index 87755c6649c..c0e66583e89 100644 --- a/sys/kern/kern_sched.c +++ b/sys/kern/kern_sched.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sched.c,v 1.85 2023/08/11 22:02:50 cheloha Exp $ */ +/* $OpenBSD: kern_sched.c,v 1.86 2023/08/14 08:33:24 mpi Exp $ */ /* * Copyright (c) 2007, 2008 Artur Grabowski * @@ -548,6 +548,9 @@ sched_steal_proc(struct cpu_info *self) if (best == NULL) return (NULL); + TRACEPOINT(sched, steal, best->p_tid + THREAD_PID_OFFSET, + best->p_p->ps_pid, CPU_INFO_UNIT(self)); + remrunqueue(best); best->p_cpu = self; diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c index cd1f4eafcf8..591fa77a736 100644 --- a/sys/kern/kern_synch.c +++ b/sys/kern/kern_synch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_synch.c,v 1.196 2023/08/10 20:44:52 claudio Exp $ */ +/* $OpenBSD: kern_synch.c,v 1.197 2023/08/14 08:33:24 mpi Exp $ */ /* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */ /* @@ -520,7 +520,7 @@ unsleep(struct proc *p) if (p->p_wchan != NULL) { TAILQ_REMOVE(&slpque[LOOKUP(p->p_wchan)], p, p_runq); p->p_wchan = NULL; - TRACEPOINT(sched, wakeup, p->p_tid + THREAD_PID_OFFSET, + TRACEPOINT(sched, unsleep, p->p_tid + THREAD_PID_OFFSET, p->p_p->ps_pid); } } diff --git a/sys/kern/sched_bsd.c b/sys/kern/sched_bsd.c index 7ffdc2ed2a6..ae38ac60a34 100644 --- a/sys/kern/sched_bsd.c +++ b/sys/kern/sched_bsd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sched_bsd.c,v 1.80 2023/08/11 22:02:50 cheloha Exp $ */ +/* $OpenBSD: sched_bsd.c,v 1.81 2023/08/14 08:33:24 mpi Exp $ */ /* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */ /*- @@ -462,6 +462,7 @@ setrunnable(struct proc *p) atomic_setbits_int(&p->p_siglist, sigmask(pr->ps_xsig)); prio = p->p_usrpri; unsleep(p); + setrunqueue(NULL, p, prio); break; case SSLEEP: prio = p->p_slppri; @@ -470,9 +471,11 @@ setrunnable(struct proc *p) /* if not yet asleep, don't add to runqueue */ if (ISSET(p->p_flag, P_WSLEEP)) return; + setrunqueue(NULL, p, prio); + TRACEPOINT(sched, wakeup, p->p_tid + THREAD_PID_OFFSET, + p->p_p->ps_pid, CPU_INFO_UNIT(p->p_cpu)); break; } - setrunqueue(NULL, p, prio); if (p->p_slptime > 1) { uint32_t newcpu; -- 2.20.1