Extend scheduler tracepoints to follow CPU jumping.
authormpi <mpi@openbsd.org>
Mon, 14 Aug 2023 08:33:24 +0000 (08:33 +0000)
committermpi <mpi@openbsd.org>
Mon, 14 Aug 2023 08:33:24 +0000 (08:33 +0000)
- 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
sys/kern/kern_fork.c
sys/kern/kern_sched.c
sys/kern/kern_synch.c
sys/kern/sched_bsd.c

index dc23981..0d67832 100644 (file)
@@ -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 <mpi@openbsd.org>
@@ -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),
index 97c9c4b..8d1f245 100644 (file)
@@ -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 <sys/ptrace.h>
 #include <sys/atomic.h>
 #include <sys/unistd.h>
+#include <sys/tracepoint.h>
 
 #include <sys/syscallargs.h>
 
@@ -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);
 }
index 87755c6..c0e6658 100644 (file)
@@ -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 <art@openbsd.org>
  *
@@ -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;
 
index cd1f4ea..591fa77 100644 (file)
@@ -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);
        }
 }
index 7ffdc2e..ae38ac6 100644 (file)
@@ -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;