diff options
author | Martin Pieuchot <mpi@cvs.openbsd.org> | 2020-01-21 16:16:24 +0000 |
---|---|---|
committer | Martin Pieuchot <mpi@cvs.openbsd.org> | 2020-01-21 16:16:24 +0000 |
commit | 212ddbc939b030707a86d34d9b97f4cd4c815b21 (patch) | |
tree | e602c11381c1507e54ac0b2e4c65c87b7dd5dfe3 /sys/kern | |
parent | 15cee70a046f6b2951ff8bd4ab20dbfc2ef519d5 (diff) |
Import dt(4) a driver and framework for Dynamic Profiling.
The design is fairly simple: events, in the form of descriptors on a
ring, are being produced in any kernel context and being consumed by
a userland process reading /dev/dt.
Code and hooks are all guarded under '#if NDT > 0' so this commit
shouldn't introduce any change as long as dt(4) is disable in GENERIC.
ok kettenis@, visa@, jasper@, deraadt@
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/kern_clock.c | 13 | ||||
-rw-r--r-- | sys/kern/kern_sched.c | 5 | ||||
-rw-r--r-- | sys/kern/kern_synch.c | 7 | ||||
-rw-r--r-- | sys/kern/sched_bsd.c | 7 |
4 files changed, 28 insertions, 4 deletions
diff --git a/sys/kern/kern_clock.c b/sys/kern/kern_clock.c index 0a3679b0510..b6e0ca4f65a 100644 --- a/sys/kern/kern_clock.c +++ b/sys/kern/kern_clock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_clock.c,v 1.100 2019/11/02 16:56:17 cheloha Exp $ */ +/* $OpenBSD: kern_clock.c,v 1.101 2020/01/21 16:16:23 mpi Exp $ */ /* $NetBSD: kern_clock.c,v 1.34 1996/06/09 04:51:03 briggs Exp $ */ /*- @@ -55,6 +55,11 @@ #include <sys/gmon.h> #endif +#include "dt.h" +#if NDT > 0 +#include <dev/dt/dtvar.h> +#endif + /* * Clock handling routines. * @@ -168,6 +173,12 @@ hardclock(struct clockframe *frame) if (--ci->ci_schedstate.spc_rrticks <= 0) roundrobin(ci); +#if NDT > 0 + DT_ENTER(profile, NULL); + if (CPU_IS_PRIMARY(ci)) + DT_ENTER(interval, NULL); +#endif + /* * If we are not the primary CPU, we're not allowed to do * any more work. diff --git a/sys/kern/kern_sched.c b/sys/kern/kern_sched.c index 46de8fa7800..e25993099ee 100644 --- a/sys/kern/kern_sched.c +++ b/sys/kern/kern_sched.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sched.c,v 1.62 2019/11/04 18:06:03 visa Exp $ */ +/* $OpenBSD: kern_sched.c,v 1.63 2020/01/21 16:16:23 mpi Exp $ */ /* * Copyright (c) 2007, 2008 Artur Grabowski <art@openbsd.org> * @@ -26,6 +26,7 @@ #include <sys/mutex.h> #include <sys/task.h> #include <sys/smr.h> +#include <sys/tracepoint.h> #include <uvm/uvm_extern.h> @@ -261,6 +262,7 @@ setrunqueue(struct cpu_info *ci, struct proc *p, uint8_t prio) spc = &p->p_cpu->ci_schedstate; spc->spc_nrun++; + TRACEPOINT(sched, enqueue, p->p_tid, p->p_p->ps_pid); TAILQ_INSERT_TAIL(&spc->spc_qs[queue], p, p_runq); spc->spc_whichqs |= (1 << queue); @@ -282,6 +284,7 @@ remrunqueue(struct proc *p) SCHED_ASSERT_LOCKED(); spc = &p->p_cpu->ci_schedstate; spc->spc_nrun--; + TRACEPOINT(sched, dequeue, p->p_tid, p->p_p->ps_pid); TAILQ_REMOVE(&spc->spc_qs[queue], p, p_runq); if (TAILQ_EMPTY(&spc->spc_qs[queue])) { diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c index 02c733ad8f1..3ca58be881e 100644 --- a/sys/kern/kern_synch.c +++ b/sys/kern/kern_synch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_synch.c,v 1.159 2020/01/21 15:20:47 visa Exp $ */ +/* $OpenBSD: kern_synch.c,v 1.160 2020/01/21 16:16:23 mpi Exp $ */ /* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */ /* @@ -51,6 +51,8 @@ #include <sys/refcnt.h> #include <sys/atomic.h> #include <sys/witness.h> +#include <sys/tracepoint.h> + #include <ddb/db_output.h> #include <machine/spinlock.h> @@ -380,6 +382,8 @@ sleep_setup(struct sleep_state *sls, const volatile void *ident, int prio, SCHED_LOCK(sls->sls_s); + TRACEPOINT(sched, sleep, NULL); + p->p_wchan = ident; p->p_wmesg = wmesg; p->p_slptime = 0; @@ -552,6 +556,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, p->p_p->ps_pid); } } diff --git a/sys/kern/sched_bsd.c b/sys/kern/sched_bsd.c index 3b8c4a80536..9172bc7e24e 100644 --- a/sys/kern/sched_bsd.c +++ b/sys/kern/sched_bsd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sched_bsd.c,v 1.60 2019/12/11 07:30:09 guenther Exp $ */ +/* $OpenBSD: sched_bsd.c,v 1.61 2020/01/21 16:16:23 mpi Exp $ */ /* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */ /*- @@ -48,6 +48,7 @@ #include <sys/sched.h> #include <sys/timeout.h> #include <sys/smr.h> +#include <sys/tracepoint.h> #ifdef KTRACE #include <sys/ktrace.h> @@ -392,8 +393,12 @@ mi_switch(void) if (p != nextproc) { uvmexp.swtch++; + TRACEPOINT(sched, off__cpu, nextproc->p_tid, + nextproc->p_p->ps_pid); cpu_switchto(p, nextproc); + TRACEPOINT(sched, on__cpu, NULL); } else { + TRACEPOINT(sched, remain__cpu, NULL); p->p_stat = SONPROC; } |