Module Name: src Committed By: riastradh Date: Fri Oct 28 21:53:26 UTC 2022
Modified Files: src/sys/kern: kern_timeout.c Log Message: callout(9): Sprinkle dtrace probes. To generate a diff of this commit: cvs rdiff -u -r1.71 -r1.72 src/sys/kern/kern_timeout.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/kern_timeout.c diff -u src/sys/kern/kern_timeout.c:1.71 src/sys/kern/kern_timeout.c:1.72 --- src/sys/kern/kern_timeout.c:1.71 Fri Oct 28 21:52:22 2022 +++ src/sys/kern/kern_timeout.c Fri Oct 28 21:53:26 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_timeout.c,v 1.71 2022/10/28 21:52:22 riastradh Exp $ */ +/* $NetBSD: kern_timeout.c,v 1.72 2022/10/28 21:53:26 riastradh Exp $ */ /*- * Copyright (c) 2003, 2006, 2007, 2008, 2009, 2019 The NetBSD Foundation, Inc. @@ -59,7 +59,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: kern_timeout.c,v 1.71 2022/10/28 21:52:22 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_timeout.c,v 1.72 2022/10/28 21:53:26 riastradh Exp $"); /* * Timeouts are kept in a hierarchical timing wheel. The c_time is the @@ -96,6 +96,7 @@ __KERNEL_RCSID(0, "$NetBSD: kern_timeout #include <sys/intr.h> #include <sys/cpu.h> #include <sys/kmem.h> +#include <sys/sdt.h> #ifdef DDB #include <machine/db_machdep.h> @@ -180,6 +181,7 @@ struct callout_cpu { struct callout_circq cc_wheel[BUCKETS]; /* Queues of timeouts */ char cc_name1[12]; char cc_name2[12]; + struct cpu_info *cc_cpu; }; #ifdef DDB @@ -193,6 +195,57 @@ static void callout_wait(callout_impl_t static struct callout_cpu callout_cpu0 __cacheline_aligned; static void *callout_sih __read_mostly; +SDT_PROBE_DEFINE2(sdt, kernel, callout, init, + "struct callout *"/*ch*/, + "unsigned"/*flags*/); +SDT_PROBE_DEFINE1(sdt, kernel, callout, destroy, + "struct callout *"/*ch*/); +SDT_PROBE_DEFINE4(sdt, kernel, callout, setfunc, + "struct callout *"/*ch*/, + "void (*)(void *)"/*func*/, + "void *"/*arg*/, + "unsigned"/*flags*/); +SDT_PROBE_DEFINE5(sdt, kernel, callout, schedule, + "struct callout *"/*ch*/, + "void (*)(void *)"/*func*/, + "void *"/*arg*/, + "unsigned"/*flags*/, + "int"/*ticks*/); +SDT_PROBE_DEFINE6(sdt, kernel, callout, migrate, + "struct callout *"/*ch*/, + "void (*)(void *)"/*func*/, + "void *"/*arg*/, + "unsigned"/*flags*/, + "struct cpu_info *"/*ocpu*/, + "struct cpu_info *"/*ncpu*/); +SDT_PROBE_DEFINE4(sdt, kernel, callout, entry, + "struct callout *"/*ch*/, + "void (*)(void *)"/*func*/, + "void *"/*arg*/, + "unsigned"/*flags*/); +SDT_PROBE_DEFINE4(sdt, kernel, callout, return, + "struct callout *"/*ch*/, + "void (*)(void *)"/*func*/, + "void *"/*arg*/, + "unsigned"/*flags*/); +SDT_PROBE_DEFINE5(sdt, kernel, callout, stop, + "struct callout *"/*ch*/, + "void (*)(void *)"/*func*/, + "void *"/*arg*/, + "unsigned"/*flags*/, + "bool"/*expired*/); +SDT_PROBE_DEFINE4(sdt, kernel, callout, halt, + "struct callout *"/*ch*/, + "void (*)(void *)"/*func*/, + "void *"/*arg*/, + "unsigned"/*flags*/); +SDT_PROBE_DEFINE5(sdt, kernel, callout, halt__done, + "struct callout *"/*ch*/, + "void (*)(void *)"/*func*/, + "void *"/*arg*/, + "unsigned"/*flags*/, + "bool"/*expired*/); + static inline kmutex_t * callout_lock(callout_impl_t *c) { @@ -270,6 +323,7 @@ callout_init_cpu(struct cpu_info *ci) evcnt_attach_dynamic(&cc->cc_ev_block, EVCNT_TYPE_MISC, NULL, "callout", cc->cc_name2); + cc->cc_cpu = ci; ci->ci_data.cpu_callout = cc; } @@ -287,6 +341,8 @@ callout_init(callout_t *cs, u_int flags) KASSERT((flags & ~CALLOUT_FLAGMASK) == 0); + SDT_PROBE2(sdt, kernel, callout, init, cs, flags); + cc = curcpu()->ci_data.cpu_callout; c->c_func = NULL; c->c_magic = CALLOUT_MAGIC; @@ -309,6 +365,8 @@ callout_destroy(callout_t *cs) { callout_impl_t *c = (callout_impl_t *)cs; + SDT_PROBE1(sdt, kernel, callout, destroy, cs); + KASSERTMSG(c->c_magic == CALLOUT_MAGIC, "callout %p: c_magic (%#x) != CALLOUT_MAGIC (%#x)", c, c->c_magic, CALLOUT_MAGIC); @@ -339,6 +397,9 @@ callout_schedule_locked(callout_impl_t * struct callout_cpu *cc, *occ; int old_time; + SDT_PROBE5(sdt, kernel, callout, schedule, + c, c->c_func, c->c_arg, c->c_flags, to_ticks); + KASSERT(to_ticks >= 0); KASSERT(c->c_func != NULL); @@ -377,6 +438,9 @@ callout_schedule_locked(callout_impl_t * c->c_flags |= CALLOUT_PENDING; CIRCQ_INSERT(&c->c_list, &cc->cc_todo); mutex_spin_exit(cc->cc_lock); + SDT_PROBE6(sdt, kernel, callout, migrate, + c, c->c_func, c->c_arg, c->c_flags, + occ->cc_cpu, cc->cc_cpu); } mutex_spin_exit(lock); } @@ -397,6 +461,7 @@ callout_reset(callout_t *cs, int to_tick KASSERT(func != NULL); lock = callout_lock(c); + SDT_PROBE4(sdt, kernel, callout, setfunc, cs, func, arg, c->c_flags); c->c_func = func; c->c_arg = arg; callout_schedule_locked(c, lock, to_ticks); @@ -454,6 +519,9 @@ callout_stop(callout_t *cs) cc->cc_cancel = c; } + SDT_PROBE5(sdt, kernel, callout, stop, + c, c->c_func, c->c_arg, c->c_flags, expired); + mutex_spin_exit(lock); return expired; @@ -482,6 +550,8 @@ callout_halt(callout_t *cs, void *interl /* Fast path. */ lock = callout_lock(c); + SDT_PROBE4(sdt, kernel, callout, halt, + c, c->c_func, c->c_arg, c->c_flags); flags = c->c_flags; if ((flags & CALLOUT_PENDING) != 0) CIRCQ_REMOVE(&c->c_list); @@ -490,6 +560,8 @@ callout_halt(callout_t *cs, void *interl callout_wait(c, interlock, lock); return true; } + SDT_PROBE5(sdt, kernel, callout, halt__done, + c, c->c_func, c->c_arg, c->c_flags, /*expired*/false); mutex_spin_exit(lock); return false; } @@ -557,6 +629,9 @@ callout_wait(callout_impl_t *c, void *in c->c_flags &= ~(CALLOUT_PENDING|CALLOUT_FIRED); } + SDT_PROBE5(sdt, kernel, callout, halt__done, + c, c->c_func, c->c_arg, c->c_flags, /*expired*/true); + mutex_spin_exit(lock); if (__predict_false(relock != NULL)) mutex_enter(relock); @@ -611,6 +686,7 @@ callout_setfunc(callout_t *cs, void (*fu KASSERT(func != NULL); lock = callout_lock(c); + SDT_PROBE4(sdt, kernel, callout, setfunc, cs, func, arg, c->c_flags); c->c_func = func; c->c_arg = arg; mutex_spin_exit(lock); @@ -741,6 +817,7 @@ callout_softclock(void *v) void (*func)(void *); void *arg; int mpsafe, count, ticks, delta; + u_int flags; lwp_t *l; l = curlwp; @@ -774,15 +851,18 @@ callout_softclock(void *v) func = c->c_func; arg = c->c_arg; cc->cc_active = c; + flags = c->c_flags; mutex_spin_exit(cc->cc_lock); KASSERT(func != NULL); + SDT_PROBE4(sdt, kernel, callout, entry, c, func, arg, flags); if (__predict_false(!mpsafe)) { KERNEL_LOCK(1, NULL); (*func)(arg); KERNEL_UNLOCK_ONE(NULL); } else (*func)(arg); + SDT_PROBE4(sdt, kernel, callout, return, c, func, arg, flags); KASSERTMSG(l->l_blcnt == 0, "callout %p func %p leaked %d biglocks", c, func, l->l_blcnt);