Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/sys/kern/kern_clock.c,v rcsdiff: /ftp/cvs/cvsroot/src/sys/kern/kern_clock.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.130 retrieving revision 1.130.12.2 diff -u -p -r1.130 -r1.130.12.2 --- src/sys/kern/kern_clock.c 2011/10/30 01:57:40 1.130 +++ src/sys/kern/kern_clock.c 2017/12/03 11:38:44 1.130.12.2 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_clock.c,v 1.130 2011/10/30 01:57:40 christos Exp $ */ +/* $NetBSD: kern_clock.c,v 1.130.12.2 2017/12/03 11:38:44 jdolecek Exp $ */ /*- * Copyright (c) 2000, 2004, 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -69,10 +69,12 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_clock.c,v 1.130 2011/10/30 01:57:40 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_clock.c,v 1.130.12.2 2017/12/03 11:38:44 jdolecek Exp $"); -#include "opt_ntp.h" +#ifdef _KERNEL_OPT +#include "opt_dtrace.h" #include "opt_perfctrs.h" +#endif #include #include @@ -93,6 +95,15 @@ __KERNEL_RCSID(0, "$NetBSD: kern_clock.c #include #endif +#ifdef KDTRACE_HOOKS +#include +#include + +cyclic_clock_func_t cyclic_clock_func[MAXCPUS]; +#endif + +static int sysctl_kern_clockrate(SYSCTLFN_PROTO); + /* * Clock handling routines. * @@ -153,6 +164,7 @@ get_intr_timecount(struct timecounter *t void initclocks(void) { + static struct sysctllog *clog; int i; /* @@ -182,6 +194,19 @@ initclocks(void) panic("hardscheddiv"); } + sysctl_createv(&clog, 0, NULL, NULL, + CTLFLAG_PERMANENT, + CTLTYPE_STRUCT, "clockrate", + SYSCTL_DESCR("Kernel clock rates"), + sysctl_kern_clockrate, 0, NULL, + sizeof(struct clockinfo), + CTL_KERN, KERN_CLOCKRATE, CTL_EOL); + sysctl_createv(&clog, 0, NULL, NULL, + CTLFLAG_PERMANENT, + CTLTYPE_INT, "hardclock_ticks", + SYSCTL_DESCR("Number of hardclock ticks"), + NULL, 0, &hardclock_ticks, sizeof(hardclock_ticks), + CTL_KERN, KERN_HARDCLOCK_TICKS, CTL_EOL); } /* @@ -225,6 +250,13 @@ hardclock(struct clockframe *frame) * Update real-time timeout queue. */ callout_hardclock(); + +#ifdef KDTRACE_HOOKS + cyclic_clock_func_t func = cyclic_clock_func[cpu_index(ci)]; + if (func) { + (*func)((struct clockframe *)frame); + } +#endif } /* @@ -362,6 +394,7 @@ statclock(struct clockframe *frame) } if (CLKF_USERMODE(frame)) { + KASSERT(p != NULL); if ((p->p_stflag & PST_PROFIL) && profsrc == PROFSRC_CLOCK) addupc_intr(l, CLKF_PC(frame)); if (--spc->spc_pscnt > 0) { @@ -434,3 +467,24 @@ statclock(struct clockframe *frame) mutex_spin_exit(&p->p_stmutex); } } + +/* + * sysctl helper routine for kern.clockrate. Assembles a struct on + * the fly to be returned to the caller. + */ +static int +sysctl_kern_clockrate(SYSCTLFN_ARGS) +{ + struct clockinfo clkinfo; + struct sysctlnode node; + + clkinfo.tick = tick; + clkinfo.tickadj = tickadj; + clkinfo.hz = hz; + clkinfo.profhz = profhz; + clkinfo.stathz = stathz ? stathz : hz; + + node = *rnode; + node.sysctl_data = &clkinfo; + return (sysctl_lookup(SYSCTLFN_CALL(&node))); +}