FreeBSD kernel kern code
kern_clock.c File Reference
#include <sys/cdefs.h>
#include "opt_kdb.h"
#include "opt_device_polling.h"
#include "opt_hwpmc_hooks.h"
#include "opt_ntp.h"
#include "opt_watchdog.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/callout.h>
#include <sys/epoch.h>
#include <sys/eventhandler.h>
#include <sys/gtaskqueue.h>
#include <sys/kdb.h>
#include <sys/kernel.h>
#include <sys/kthread.h>
#include <sys/ktr.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/resource.h>
#include <sys/resourcevar.h>
#include <sys/sched.h>
#include <sys/sdt.h>
#include <sys/signalvar.h>
#include <sys/sleepqueue.h>
#include <sys/smp.h>
#include <vm/vm.h>
#include <vm/pmap.h>
#include <vm/vm_map.h>
#include <sys/sysctl.h>
#include <sys/bus.h>
#include <sys/interrupt.h>
#include <sys/limits.h>
#include <sys/timetc.h>
#include <sys/watchdog.h>
Include dependency graph for kern_clock.c:

Go to the source code of this file.

Functions

 __FBSDID ("$FreeBSD$")
 
 SDT_PROVIDER_DECLARE (sched)
 
 SDT_PROBE_DEFINE2 (sched,,, tick, "struct thread *", "struct proc *")
 
static int sysctl_kern_cp_time (SYSCTL_HANDLER_ARGS)
 
 SYSCTL_PROC (_kern, OID_AUTO, cp_time, CTLTYPE_LONG|CTLFLAG_RD|CTLFLAG_MPSAFE, 0, 0, sysctl_kern_cp_time, "LU", "CPU time statistics")
 
static int sysctl_kern_cp_times (SYSCTL_HANDLER_ARGS)
 
 SYSCTL_PROC (_kern, OID_AUTO, cp_times, CTLTYPE_LONG|CTLFLAG_RD|CTLFLAG_MPSAFE, 0, 0, sysctl_kern_cp_times, "LU", "per-CPU time statistics")
 
void read_cpu_time (long *cp_time)
 
static void watchdog_fire (void)
 
static void watchdog_config (void *, u_int, int *)
 
static void watchdog_attach (void)
 
 DPCPU_DEFINE_STATIC (int, pcputicks)
 
static void initclocks (void *dummy __unused)
 
 SYSINIT (clocks, SI_SUB_CLOCKS, SI_ORDER_FIRST, initclocks, NULL)
 
static __noinline void hardclock_itimer (struct thread *td, struct pstats *pstats, int cnt, int usermode)
 
void hardclock (int cnt, int usermode)
 
void hardclock_sync (int cpu)
 
int tvtohz (struct timeval *tv)
 
void startprofclock (struct proc *p)
 
void stopprofclock (struct proc *p)
 
void statclock (int cnt, int usermode)
 
void profclock (int cnt, int usermode, uintfptr_t pc)
 
static int sysctl_kern_clockrate (SYSCTL_HANDLER_ARGS)
 
 SYSCTL_PROC (_kern, KERN_CLOCKRATE, clockrate, CTLTYPE_STRUCT|CTLFLAG_RD|CTLFLAG_MPSAFE, 0, 0, sysctl_kern_clockrate, "S,clockinfo", "Rate and period of various kernel clocks")
 
static void watchdog_config (void *unused __unused, u_int cmd, int *error)
 

Variables

static struct mtx time_lock
 
static long empty [CPUSTATES]
 
static int watchdog_ticks
 
static int watchdog_enabled
 
int stathz
 
int profhz
 
int profprocs
 
volatile int ticks
 
int psratio
 

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ DPCPU_DEFINE_STATIC()

DPCPU_DEFINE_STATIC ( int  ,
pcputicks   
)

◆ hardclock()

void hardclock ( int  cnt,
int  usermode 
)

Definition at line 453 of file kern_clock.c.

References clk_intr_event, clock, cpu_tick_calibration(), hardclock_device_poll(), hardclock_itimer(), intr_event_handle(), tc_ticktock(), ticks, watchdog_enabled, watchdog_fire(), and watchdog_ticks.

Referenced by handleevents().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hardclock_itimer()

static __noinline void hardclock_itimer ( struct thread *  td,
struct pstats *  pstats,
int  cnt,
int  usermode 
)
static

Definition at line 423 of file kern_clock.c.

References flags, itimerdecr(), and tick.

Referenced by hardclock().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hardclock_sync()

void hardclock_sync ( int  cpu)

Definition at line 516 of file kern_clock.c.

References ticks.

Referenced by configtimer(), and cpu_initclocks_ap().

Here is the caller graph for this function:

◆ initclocks()

static void initclocks ( void *dummy  __unused)
static

Definition at line 392 of file kern_clock.c.

References hz, profhz, psratio, stathz, time_lock, and watchdog_attach().

Here is the call graph for this function:

◆ profclock()

void profclock ( int  cnt,
int  usermode,
uintfptr_t  pc 
)

Definition at line 721 of file kern_clock.c.

References addupc_intr(), and clock.

Referenced by handleevents().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_cpu_time()

void read_cpu_time ( long *  cp_time)

Definition at line 318 of file kern_clock.c.

References pcpu_find().

Referenced by sysctl_kern_cp_time().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SDT_PROBE_DEFINE2()

SDT_PROBE_DEFINE2 ( sched  ,
tick  ,
"struct thread *"  ,
"struct proc *"   
)

◆ SDT_PROVIDER_DECLARE()

SDT_PROVIDER_DECLARE ( sched  )

◆ startprofclock()

void startprofclock ( struct proc *  p)

Definition at line 589 of file kern_clock.c.

References cpu_startprofclock(), profprocs, and time_lock.

Referenced by do_fork(), and sys_profil().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ statclock()

void statclock ( int  cnt,
int  usermode 
)

Definition at line 637 of file kern_clock.c.

References clock, cpu_ticks, hz, sched_clock(), sched_tdname(), stathz, and tick.

Referenced by handleevents().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stopprofclock()

void stopprofclock ( struct proc *  p)

Definition at line 608 of file kern_clock.c.

References cpu_stopprofclock(), profprocs, and time_lock.

Referenced by addupc_task(), do_execve(), exit1(), and sys_profil().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sysctl_kern_clockrate()

static int sysctl_kern_clockrate ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 764 of file kern_clock.c.

References hz, profhz, stathz, sysctl_handle_opaque(), and tick.

Here is the call graph for this function:

◆ sysctl_kern_cp_time()

static int sysctl_kern_cp_time ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 100 of file kern_clock.c.

References read_cpu_time().

Here is the call graph for this function:

◆ sysctl_kern_cp_times()

static int sysctl_kern_cp_times ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 133 of file kern_clock.c.

References empty, mp_maxid, and pcpu_find().

Here is the call graph for this function:

◆ SYSCTL_PROC() [1/3]

SYSCTL_PROC ( _kern  ,
KERN_CLOCKRATE  ,
clockrate  ,
CTLTYPE_STRUCT|CTLFLAG_RD|  CTLFLAG_MPSAFE,
,
,
sysctl_kern_clockrate  ,
S,
clockinfo"  ,
"Rate and period of various kernel clocks"   
)

◆ SYSCTL_PROC() [2/3]

SYSCTL_PROC ( _kern  ,
OID_AUTO  ,
cp_time  ,
CTLTYPE_LONG|CTLFLAG_RD|  CTLFLAG_MPSAFE,
,
,
sysctl_kern_cp_time  ,
"LU"  ,
"CPU time statistics"   
)

◆ SYSCTL_PROC() [3/3]

SYSCTL_PROC ( _kern  ,
OID_AUTO  ,
cp_times  ,
CTLTYPE_LONG|CTLFLAG_RD|  CTLFLAG_MPSAFE,
,
,
sysctl_kern_cp_times  ,
"LU"  ,
"per-CPU time statistics"   
)

◆ SYSINIT()

SYSINIT ( clocks  ,
SI_SUB_CLOCKS  ,
SI_ORDER_FIRST  ,
initclocks  ,
NULL   
)

◆ tvtohz()

int tvtohz ( struct timeval *  tv)

Definition at line 529 of file kern_clock.c.

References hz, printf(), tick, and ticks.

Referenced by kern_aio_suspend(), kern_aio_waitcomplete(), kern_sem_wait(), kern_sigtimedwait(), kern_thr_suspend(), mqueue_receive(), mqueue_send(), pps_fetch(), realtimer_expire_l(), realtimer_settime(), tstohz(), and ttydisc_read_raw_read_timer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ watchdog_attach()

static void watchdog_attach ( void  )
static

Definition at line 340 of file kern_clock.c.

References watchdog_config().

Referenced by initclocks().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ watchdog_config() [1/2]

static void watchdog_config ( void *  ,
u_int  ,
int *   
)
static

Referenced by watchdog_attach().

Here is the caller graph for this function:

◆ watchdog_config() [2/2]

static void watchdog_config ( void *unused  __unused,
u_int  cmd,
int *  error 
)
static

Definition at line 784 of file kern_clock.c.

References hz, watchdog_enabled, and watchdog_ticks.

◆ watchdog_fire()

static void watchdog_fire ( void  )
static

Definition at line 803 of file kern_clock.c.

References kdb_backtrace(), kdb_enter(), panic(), and printf().

Referenced by hardclock().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ empty

long empty[CPUSTATES]
static

Definition at line 130 of file kern_clock.c.

Referenced by domainset_empty_vm(), sysctl_kern_cp_times(), and turnstile_signal().

◆ profhz

int profhz

Definition at line 378 of file kern_clock.c.

Referenced by cpu_initclocks_bsp(), initclocks(), setuptimer(), and sysctl_kern_clockrate().

◆ profprocs

int profprocs

Definition at line 379 of file kern_clock.c.

Referenced by startprofclock(), and stopprofclock().

◆ psratio

int psratio

Definition at line 381 of file kern_clock.c.

Referenced by initclocks(), and userret().

◆ stathz

◆ ticks

◆ time_lock

struct mtx time_lock
static

Definition at line 94 of file kern_clock.c.

Referenced by initclocks(), startprofclock(), and stopprofclock().

◆ watchdog_enabled

int watchdog_enabled
static

Definition at line 335 of file kern_clock.c.

Referenced by hardclock(), and watchdog_config().

◆ watchdog_ticks

int watchdog_ticks
static

Definition at line 334 of file kern_clock.c.

Referenced by hardclock(), and watchdog_config().