FreeBSD kernel kern code
kern_timeout.c File Reference
#include <sys/cdefs.h>
#include "opt_kdtrace.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/bus.h>
#include <sys/callout.h>
#include <sys/condvar.h>
#include <sys/interrupt.h>
#include <sys/kernel.h>
#include <sys/ktr.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/sdt.h>
#include <sys/sleepqueue.h>
#include <sys/sysctl.h>
#include <sys/smp.h>
Include dependency graph for kern_timeout.c:

Go to the source code of this file.

Data Structures

struct  cc_mig_ent
 
struct  callout_cpu
 

Macros

#define CC_CPU(cpu)   &cc_cpu
 
#define CC_SELF()   &cc_cpu
 
#define CC_LOCK(cc)   mtx_lock_spin(&(cc)->cc_lock)
 
#define CC_UNLOCK(cc)   mtx_unlock_spin(&(cc)->cc_lock)
 
#define CC_LOCK_ASSERT(cc)   mtx_assert(&(cc)->cc_lock, MA_OWNED)
 
#define MAX_SOFTCLOCK_STEPS   100 /* Maximum allowed value of steps. */
 

Functions

 __FBSDID ("$BSDSUniX$")
 
 SDT_PROVIDER_DEFINE (callout_execute)
 
 SDT_PROBE_DEFINE1 (callout_execute, kernel,, callout__start,"struct callout *")
 
 SDT_PROBE_DEFINE1 (callout_execute, kernel,, callout__end,"struct callout *")
 
 SYSCTL_INT (_debug, OID_AUTO, to_avg_depth, CTLFLAG_RD,&avg_depth, 0,"Average number of items examined per softclock call. Units = 1/1000")
 
 SYSCTL_INT (_debug, OID_AUTO, to_avg_gcalls, CTLFLAG_RD,&avg_gcalls, 0,"Average number of Giant callouts made per softclock call. Units = 1/1000")
 
 SYSCTL_INT (_debug, OID_AUTO, to_avg_lockcalls, CTLFLAG_RD,&avg_lockcalls, 0,"Average number of lock callouts made per softclock call. Units = 1/1000")
 
 SYSCTL_INT (_debug, OID_AUTO, to_avg_mpcalls, CTLFLAG_RD,&avg_mpcalls, 0,"Average number of MP callouts made per softclock call. Units = 1/1000")
 
static MALLOC_DEFINE (M_CALLOUT,"callout","Callout datastructures")
 
static void cc_cme_cleanup (struct callout_cpu *cc)
 
static int cc_cme_migrating (struct callout_cpu *cc)
 
caddr_t kern_timeout_callwheel_alloc (caddr_t v)
 
static void callout_cpu_init (struct callout_cpu *cc)
 
void kern_timeout_callwheel_init (void)
 
static void start_softclock (void *dummy)
 
 SYSINIT (start_softclock, SI_SUB_SOFTINTR, SI_ORDER_FIRST, start_softclock, NULL)
 
void callout_tick (void)
 
int callout_tickstofirst (int limit)
 
static struct callout_cpucallout_lock (struct callout *c)
 
static void callout_cc_add (struct callout *c, struct callout_cpu *cc, int to_ticks, void(*func)(void *), void *arg, int cpu)
 
static void callout_cc_del (struct callout *c, struct callout_cpu *cc)
 
static void softclock_call_cc (struct callout *c, struct callout_cpu *cc, int *mpcalls, int *lockcalls, int *gcalls)
 
void softclock (void *arg)
 
struct callout_handle timeout (timeout_t *ftn, void *arg, int to_ticks)
 
void untimeout (timeout_t *ftn, void *arg, struct callout_handle handle)
 
void callout_handle_init (struct callout_handle *handle)
 
int callout_reset_on (struct callout *c, int to_ticks, void(*ftn)(void *), void *arg, int cpu)
 
int callout_schedule_on (struct callout *c, int to_ticks, int cpu)
 
int callout_schedule (struct callout *c, int to_ticks)
 
int _callout_stop_safe (struct callout *c, int safe)
 
void callout_init (struct callout *c, int mpsafe)
 
void _callout_init_lock (struct callout *c, struct lock_object *lock, int flags)
 

Variables

static int avg_depth
 
static int avg_gcalls
 
static int avg_lockcalls
 
static int avg_mpcalls
 
int callwheelsize
 
int callwheelbits
 
int callwheelmask
 
struct callout_cpu cc_cpu
 
static int timeout_cpu
 
void(* callout_new_inserted )(int cpu, int ticks) = NULL
 

Macro Definition Documentation

#define CC_CPU (   cpu)    &cc_cpu
#define CC_LOCK (   cc)    mtx_lock_spin(&(cc)->cc_lock)
#define CC_LOCK_ASSERT (   cc)    mtx_assert(&(cc)->cc_lock, MA_OWNED)

Definition at line 152 of file kern_timeout.c.

Referenced by callout_cc_add().

#define CC_SELF ( )    &cc_cpu

Definition at line 148 of file kern_timeout.c.

Referenced by callout_tick(), and callout_tickstofirst().

#define CC_UNLOCK (   cc)    mtx_unlock_spin(&(cc)->cc_lock)
#define MAX_SOFTCLOCK_STEPS   100 /* Maximum allowed value of steps. */

Referenced by softclock().

Function Documentation

__FBSDID ( "$BSDSUniX$"  )
void _callout_init_lock ( struct callout *  c,
struct lock_object *  lock,
int  flags 
)

Definition at line 1056 of file kern_timeout.c.

References timeout_cpu.

static void callout_cc_add ( struct callout *  c,
struct callout_cpu cc,
int  to_ticks,
void(*)(void *)  func,
void *  arg,
int  cpu 
)
static

Definition at line 416 of file kern_timeout.c.

References callout_new_inserted, callwheelmask, callout_cpu::cc_callwheel, callout_cpu::cc_firsttick, CC_LOCK_ASSERT, callout_cpu::cc_ticks, and ticks.

Referenced by callout_reset_on(), and softclock_call_cc().

Here is the caller graph for this function:

static void callout_cc_del ( struct callout *  c,
struct callout_cpu cc 
)
static

Definition at line 439 of file kern_timeout.c.

References callout_cpu::cc_callfree.

Referenced by _callout_stop_safe(), and softclock_call_cc().

Here is the caller graph for this function:

static void callout_cpu_init ( struct callout_cpu cc)
static

Definition at line 235 of file kern_timeout.c.

References callout_init(), callwheelsize, callout_cpu::cc_callfree, callout_cpu::cc_callout, callout_cpu::cc_callwheel, cc_cme_cleanup(), callout_cpu::cc_lock, mtx_init(), and ncallout.

Referenced by kern_timeout_callwheel_init(), and start_softclock().

Here is the call graph for this function:

Here is the caller graph for this function:

void callout_handle_init ( struct callout_handle *  handle)

Definition at line 760 of file kern_timeout.c.

void callout_init ( struct callout *  c,
int  mpsafe 
)

Definition at line 1040 of file kern_timeout.c.

References Giant, and timeout_cpu.

Referenced by callout_cpu_init(), constty_set(), domaininit(), filt_timerattach(), proc0_init(), start_periodic_resettodr(), synch_setup(), and thread_link().

Here is the caller graph for this function:

static struct callout_cpu* callout_lock ( struct callout *  c)
static

Definition at line 392 of file kern_timeout.c.

References CC_CPU, CC_LOCK, and CC_UNLOCK.

Referenced by _callout_stop_safe(), callout_reset_on(), and untimeout().

Here is the caller graph for this function:

int callout_reset_on ( struct callout *  c,
int  to_ticks,
void(*)(void *)  ftn,
void *  arg,
int  cpu 
)

Definition at line 782 of file kern_timeout.c.

References callout_cc_add(), callout_lock(), callwheelmask, callout_cpu::cc_callwheel, callout_cpu::cc_cancel, callout_cpu::cc_curr, callout_cpu::cc_next, CC_UNLOCK, and callout_cpu::cc_waiting.

Referenced by callout_schedule(), and callout_schedule_on().

Here is the call graph for this function:

Here is the caller graph for this function:

int callout_schedule ( struct callout *  c,
int  to_ticks 
)

Definition at line 867 of file kern_timeout.c.

References callout_reset_on().

Referenced by logtimeout(), and periodic_resettodr().

Here is the call graph for this function:

Here is the caller graph for this function:

int callout_schedule_on ( struct callout *  c,
int  to_ticks,
int  cpu 
)

Definition at line 861 of file kern_timeout.c.

References callout_reset_on().

Here is the call graph for this function:

void callout_tick ( void  )

Definition at line 334 of file kern_timeout.c.

References callwheelmask, callout_cpu::cc_callwheel, callout_cpu::cc_cookie, callout_cpu::cc_firsttick, callout_cpu::cc_lock, CC_SELF, callout_cpu::cc_softticks, callout_cpu::cc_ticks, swi_sched(), and ticks.

Referenced by hardclock_cnt(), and hardclock_cpu().

Here is the call graph for this function:

Here is the caller graph for this function:

int callout_tickstofirst ( int  limit)

Definition at line 365 of file kern_timeout.c.

References callwheelmask, callout_cpu::cc_callwheel, callout_cpu::cc_firsttick, callout_cpu::cc_lock, CC_SELF, callout_cpu::cc_ticks, and ncallout.

Referenced by getnextcpuevent().

Here is the caller graph for this function:

static void cc_cme_cleanup ( struct callout_cpu cc)
static

Locked by cc_lock: cc_curr - If a callout is in progress, it is curr_callout. If curr_callout is non-NULL, threads waiting in callout_drain() will be woken up as soon as the relevant callout completes. cc_cancel - Changing to 1 with both callout_lock and c_lock held guarantees that the current callout will not run. The softclock() function sets this to 0 before it drops callout_lock to acquire c_lock, and it calls the handler only if curr_cancelled is still 0 after c_lock is successfully acquired. cc_waiting - If a thread is waiting in callout_drain(), then callout_wait is nonzero. Set only when curr_callout is non-NULL.

Definition at line 180 of file kern_timeout.c.

Referenced by callout_cpu_init(), and softclock_call_cc().

Here is the caller graph for this function:

static int cc_cme_migrating ( struct callout_cpu cc)
static

Definition at line 195 of file kern_timeout.c.

Referenced by _callout_stop_safe(), and softclock_call_cc().

Here is the caller graph for this function:

caddr_t kern_timeout_callwheel_alloc ( caddr_t  v)
void kern_timeout_callwheel_init ( void  )

Definition at line 294 of file kern_timeout.c.

References callout_cpu_init(), CC_CPU, and timeout_cpu.

Here is the call graph for this function:

static MALLOC_DEFINE ( M_CALLOUT  ,
"callout"  ,
"Callout datastructures"   
)
static
SDT_PROBE_DEFINE1 ( callout_execute  ,
kernel  ,
callout__start  ,
"struct callout *"   
)
SDT_PROBE_DEFINE1 ( callout_execute  ,
kernel  ,
callout__end  ,
"struct callout *"   
)
SDT_PROVIDER_DEFINE ( callout_execute  )
void softclock ( void *  arg)

Definition at line 632 of file kern_timeout.c.

References avg_depth, avg_gcalls, avg_lockcalls, avg_mpcalls, callwheelmask, callout_cpu::cc_callwheel, CC_LOCK, callout_cpu::cc_next, callout_cpu::cc_softticks, callout_cpu::cc_ticks, CC_UNLOCK, MAX_SOFTCLOCK_STEPS, and softclock_call_cc().

Referenced by start_softclock().

Here is the call graph for this function:

Here is the caller graph for this function:

static void softclock_call_cc ( struct callout *  c,
struct callout_cpu cc,
int *  mpcalls,
int *  lockcalls,
int *  gcalls 
)
static

Definition at line 449 of file kern_timeout.c.

References bintime(), binuptime(), callout_cc_add(), callout_cc_del(), callout_cpu::cc_cancel, cc_cme_cleanup(), cc_cme_migrating(), callout_cpu::cc_curr, CC_LOCK, CC_UNLOCK, callout_cpu::cc_waiting, Giant, panic(), printf(), and wakeup().

Referenced by softclock().

Here is the call graph for this function:

Here is the caller graph for this function:

static void start_softclock ( void *  dummy)
static
SYSCTL_INT ( _debug  ,
OID_AUTO  ,
to_avg_depth  ,
CTLFLAG_RD  ,
avg_depth,
 
)
SYSCTL_INT ( _debug  ,
OID_AUTO  ,
to_avg_gcalls  ,
CTLFLAG_RD  ,
avg_gcalls,
 
)
SYSCTL_INT ( _debug  ,
OID_AUTO  ,
to_avg_lockcalls  ,
CTLFLAG_RD  ,
avg_lockcalls,
 
)
SYSCTL_INT ( _debug  ,
OID_AUTO  ,
to_avg_mpcalls  ,
CTLFLAG_RD  ,
avg_mpcalls,
 
)
SYSINIT ( start_softclock  ,
SI_SUB_SOFTINTR  ,
SI_ORDER_FIRST  ,
start_softclock  ,
NULL   
)
struct callout_handle timeout ( timeout_t *  ftn,
void *  arg,
int  to_ticks 
)
void untimeout ( timeout_t *  ftn,
void *  arg,
struct callout_handle  handle 
)

Definition at line 738 of file kern_timeout.c.

References callout_lock(), and CC_UNLOCK.

Here is the call graph for this function:

Variable Documentation

int avg_depth
static

Definition at line 69 of file kern_timeout.c.

Referenced by softclock().

int avg_gcalls
static

Definition at line 72 of file kern_timeout.c.

Referenced by softclock().

int avg_lockcalls
static

Definition at line 75 of file kern_timeout.c.

Referenced by softclock().

int avg_mpcalls
static

Definition at line 78 of file kern_timeout.c.

Referenced by softclock().

void(* callout_new_inserted) (int cpu, int ticks) = NULL

Definition at line 155 of file kern_timeout.c.

Referenced by callout_cc_add(), and cpu_initclocks_bsp().

int callwheelbits

Definition at line 85 of file kern_timeout.c.

Referenced by kern_timeout_callwheel_alloc().

int callwheelsize

Definition at line 85 of file kern_timeout.c.

Referenced by callout_cpu_init(), kern_timeout_callwheel_alloc(), and start_softclock().

struct callout_cpu cc_cpu

Definition at line 146 of file kern_timeout.c.