FreeBSD kernel kern code
kern_clocksource.c File Reference
#include <sys/cdefs.h>
#include "opt_device_polling.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/bus.h>
#include <sys/limits.h>
#include <sys/lock.h>
#include <sys/kdb.h>
#include <sys/ktr.h>
#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/kernel.h>
#include <sys/sched.h>
#include <sys/smp.h>
#include <sys/sysctl.h>
#include <sys/timeet.h>
#include <sys/timetc.h>
#include <machine/atomic.h>
#include <machine/clock.h>
#include <machine/cpu.h>
#include <machine/smp.h>
#include "opt_ddb.h"
Include dependency graph for kern_clocksource.c:

Go to the source code of this file.

Data Structures

struct  pcpu_state
 

Macros

#define ET_HW_LOCK(state)
 
#define ET_HW_UNLOCK(state)
 

Functions

 __FBSDID ("$FreeBSD$")
 
static void setuptimer (void)
 
static void loadtimer (sbintime_t now, int first)
 
static int doconfigtimer (void)
 
static void configtimer (int start)
 
static int round_freq (struct eventtimer *et, int freq)
 
static sbintime_t getnextcpuevent (int idle)
 
static sbintime_t getnextevent (void)
 
static int handleevents (sbintime_t now, int fake)
 
 TUNABLE_STR ("kern.eventtimer.timer", timername, sizeof(timername))
 
 SYSCTL_INT (_kern_eventtimer, OID_AUTO, singlemul, CTLFLAG_RWTUN, &singlemul, 0, "Multiplier for periodic mode")
 
 SYSCTL_UINT (_kern_eventtimer, OID_AUTO, idletick, CTLFLAG_RWTUN, &idletick, 0, "Run periodic events when idle")
 
 TUNABLE_INT ("kern.eventtimer.periodic", &want_periodic)
 
 DPCPU_DEFINE_STATIC (struct pcpu_state, timerstate)
 
 DPCPU_DEFINE (sbintime_t, hardclocktime)
 
int hardclockintr (void)
 
static void timercb (struct eventtimer *et, void *arg)
 
void cpu_initclocks_bsp (void)
 
void cpu_initclocks_ap (void)
 
void suspendclock (void)
 
void resumeclock (void)
 
void cpu_startprofclock (void)
 
void cpu_stopprofclock (void)
 
sbintime_t cpu_idleclock (void)
 
void cpu_activeclock (void)
 
void cpu_et_frequency (struct eventtimer *et, uint64_t newfreq)
 
void cpu_new_callout (int cpu, sbintime_t bt, sbintime_t bt_opt)
 
static int sysctl_kern_eventtimer_timer (SYSCTL_HANDLER_ARGS)
 
 SYSCTL_PROC (_kern_eventtimer, OID_AUTO, timer, CTLTYPE_STRING|CTLFLAG_RW|CTLFLAG_MPSAFE, 0, 0, sysctl_kern_eventtimer_timer, "A", "Chosen event timer")
 
static int sysctl_kern_eventtimer_periodic (SYSCTL_HANDLER_ARGS)
 
 SYSCTL_PROC (_kern_eventtimer, OID_AUTO, periodic, CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_MPSAFE, 0, 0, sysctl_kern_eventtimer_periodic, "I", "Enable event timer periodic mode")
 

Variables

int cpu_disable_c2_sleep = 0
 
int cpu_disable_c3_sleep = 0
 
static struct mtx et_hw_mtx
 
static struct eventtimer * timer = NULL
 
static sbintime_t timerperiod
 
static sbintime_t statperiod
 
static sbintime_t profperiod
 
static sbintime_t nexttick
 
static u_int busy = 1
 
static int profiling
 
static char timername [32]
 
static int singlemul
 
static u_int idletick
 
static int periodic
 
static int want_periodic
 

Macro Definition Documentation

◆ ET_HW_LOCK

#define ET_HW_LOCK (   state)
Value:
{ \
if (timer->et_flags & ET_FLAGS_PERCPU) \
mtx_lock_spin(&(state)->et_hw_mtx); \
else \
mtx_lock_spin(&et_hw_mtx); \
}
static struct mtx et_hw_mtx
static struct eventtimer * timer

Definition at line 74 of file kern_clocksource.c.

◆ ET_HW_UNLOCK

#define ET_HW_UNLOCK (   state)
Value:
{ \
if (timer->et_flags & ET_FLAGS_PERCPU) \
mtx_unlock_spin(&(state)->et_hw_mtx); \
else \
mtx_unlock_spin(&et_hw_mtx); \
}

Definition at line 82 of file kern_clocksource.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ configtimer()

◆ cpu_activeclock()

void cpu_activeclock ( void  )

Definition at line 795 of file kern_clocksource.c.

References busy, handleevents(), pcpu_state::idle, pcpu_state::now, and periodic.

Here is the call graph for this function:

◆ cpu_et_frequency()

void cpu_et_frequency ( struct eventtimer *  et,
uint64_t  newfreq 
)

Definition at line 824 of file kern_clocksource.c.

References configtimer(), and timer.

Referenced by et_change_frequency().

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

◆ cpu_idleclock()

sbintime_t cpu_idleclock ( void  )

Definition at line 762 of file kern_clocksource.c.

References busy, ET_HW_LOCK, ET_HW_UNLOCK, getnextcpuevent(), pcpu_state::idle, idletick, loadtimer(), pcpu_state::nextevent, pcpu_state::now, periodic, and timer.

Here is the call graph for this function:

◆ cpu_initclocks_ap()

void cpu_initclocks_ap ( void  )

Definition at line 682 of file kern_clocksource.c.

References ET_HW_LOCK, ET_HW_UNLOCK, handleevents(), hardclock_sync(), and pcpu_state::now.

Here is the call graph for this function:

◆ cpu_initclocks_bsp()

◆ cpu_new_callout()

void cpu_new_callout ( int  cpu,
sbintime_t  bt,
sbintime_t  bt_opt 
)

Definition at line 838 of file kern_clocksource.c.

References bt, busy, ET_HW_LOCK, ET_HW_UNLOCK, pcpu_state::handle, loadtimer(), pcpu_state::nextcall, pcpu_state::nextcallopt, pcpu_state::nextevent, periodic, and timer.

Referenced by callout_cc_add(), and callout_process().

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

◆ cpu_startprofclock()

void cpu_startprofclock ( void  )

Definition at line 722 of file kern_clocksource.c.

References configtimer(), periodic, and profiling.

Referenced by startprofclock().

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

◆ cpu_stopprofclock()

void cpu_stopprofclock ( void  )

Definition at line 742 of file kern_clocksource.c.

References configtimer(), periodic, and profiling.

Referenced by stopprofclock().

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

◆ doconfigtimer()

static int doconfigtimer ( void  )
static

Definition at line 445 of file kern_clocksource.c.

References pcpu_state::action, busy, ET_HW_LOCK, ET_HW_UNLOCK, et_stop(), pcpu_state::handle, handleevents(), loadtimer(), pcpu_state::now, and timer.

Referenced by hardclockintr().

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

◆ DPCPU_DEFINE()

DPCPU_DEFINE ( sbintime_t  ,
hardclocktime   
)

◆ DPCPU_DEFINE_STATIC()

DPCPU_DEFINE_STATIC ( struct pcpu_state  ,
timerstate   
)

◆ getnextcpuevent()

static sbintime_t getnextcpuevent ( int  idle)
static

Definition at line 232 of file kern_clocksource.c.

References hz, pcpu_state::idle, pcpu_state::nextcall, pcpu_state::nexthard, pcpu_state::nextprof, pcpu_state::nextstat, profiling, tc_min_ticktock_freq, and tick_sbt.

Referenced by cpu_idleclock(), and handleevents().

Here is the caller graph for this function:

◆ getnextevent()

static sbintime_t getnextevent ( void  )
static

Definition at line 269 of file kern_clocksource.c.

References pcpu_state::nextevent, and timer.

Referenced by loadtimer().

Here is the caller graph for this function:

◆ handleevents()

static int handleevents ( sbintime_t  now,
int  fake 
)
static

◆ hardclockintr()

int hardclockintr ( void  )

Definition at line 136 of file kern_clocksource.c.

References busy, doconfigtimer(), handleevents(), and pcpu_state::now.

Here is the call graph for this function:

◆ loadtimer()

static void loadtimer ( sbintime_t  now,
int  first 
)
static

Definition at line 380 of file kern_clocksource.c.

References et_start(), getnextevent(), nexttick, pcpu_state::nexttick, pcpu_state::now, periodic, start, timer, and timerperiod.

Referenced by configtimer(), cpu_idleclock(), cpu_new_callout(), doconfigtimer(), and handleevents().

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

◆ resumeclock()

void resumeclock ( void  )

Definition at line 711 of file kern_clocksource.c.

References configtimer().

Here is the call graph for this function:

◆ round_freq()

static int round_freq ( struct eventtimer *  et,
int  freq 
)
static

Definition at line 570 of file kern_clocksource.c.

References panic().

Referenced by cpu_initclocks_bsp(), and setuptimer().

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

◆ setuptimer()

static void setuptimer ( void  )
static

Definition at line 425 of file kern_clocksource.c.

References hz, periodic, profhz, profiling, round_freq(), singlemul, stathz, timer, and timerperiod.

Referenced by configtimer().

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

◆ suspendclock()

void suspendclock ( void  )

Definition at line 703 of file kern_clocksource.c.

References configtimer().

Here is the call graph for this function:

◆ SYSCTL_INT()

SYSCTL_INT ( _kern_eventtimer  ,
OID_AUTO  ,
singlemul  ,
CTLFLAG_RWTUN  ,
singlemul,
,
"Multiplier for periodic mode  
)

◆ sysctl_kern_eventtimer_periodic()

static int sysctl_kern_eventtimer_periodic ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 934 of file kern_clocksource.c.

References configtimer(), periodic, sysctl_handle_int(), and want_periodic.

Here is the call graph for this function:

◆ sysctl_kern_eventtimer_timer()

static int sysctl_kern_eventtimer_timer ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 890 of file kern_clocksource.c.

References buf, configtimer(), cpu_disable_c3_sleep, et_find(), et_free(), et_init(), periodic, snprintf(), sysctl_handle_string(), timer, timercb(), and want_periodic.

Here is the call graph for this function:

◆ SYSCTL_PROC() [1/2]

SYSCTL_PROC ( _kern_eventtimer  ,
OID_AUTO  ,
periodic  ,
CTLTYPE_INT|CTLFLAG_RW|  CTLFLAG_MPSAFE,
,
,
sysctl_kern_eventtimer_periodic  ,
"I"  ,
"Enable event timer periodic mode  
)

◆ SYSCTL_PROC() [2/2]

SYSCTL_PROC ( _kern_eventtimer  ,
OID_AUTO  ,
timer  ,
CTLTYPE_STRING|CTLFLAG_RW|  CTLFLAG_MPSAFE,
,
,
sysctl_kern_eventtimer_timer  ,
"A"  ,
"Chosen event timer  
)

◆ SYSCTL_UINT()

SYSCTL_UINT ( _kern_eventtimer  ,
OID_AUTO  ,
idletick  ,
CTLFLAG_RWTUN  ,
idletick,
,
"Run periodic events when idle"   
)

◆ timercb()

static void timercb ( struct eventtimer *  et,
void *  arg 
)
static

Definition at line 303 of file kern_clocksource.c.

References busy, ET_HW_LOCK, ET_HW_UNLOCK, handleevents(), pcpu_state::ipi, mp_ncpus, pcpu_state::nextevent, nexttick, pcpu_state::nexttick, pcpu_state::now, periodic, smp_started, and timerperiod.

Referenced by cpu_initclocks_bsp(), and sysctl_kern_eventtimer_timer().

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

◆ TUNABLE_INT()

TUNABLE_INT ( "kern.eventtimer.periodic"  ,
want_periodic 
)

◆ TUNABLE_STR()

TUNABLE_STR ( "kern.eventtimer.timer"  ,
timername  ,
sizeof(timername  
)

Variable Documentation

◆ busy

◆ cpu_disable_c2_sleep

int cpu_disable_c2_sleep = 0

Definition at line 59 of file kern_clocksource.c.

Referenced by tc_windup().

◆ cpu_disable_c3_sleep

int cpu_disable_c3_sleep = 0

Definition at line 60 of file kern_clocksource.c.

Referenced by cpu_initclocks_bsp(), and sysctl_kern_eventtimer_timer().

◆ et_hw_mtx

struct mtx et_hw_mtx
static

Definition at line 72 of file kern_clocksource.c.

Referenced by cpu_initclocks_bsp().

◆ idletick

u_int idletick
static

Definition at line 105 of file kern_clocksource.c.

Referenced by cpu_idleclock().

◆ nexttick

sbintime_t nexttick
static

Definition at line 94 of file kern_clocksource.c.

Referenced by configtimer(), loadtimer(), and timercb().

◆ periodic

◆ profiling

int profiling
static

◆ profperiod

sbintime_t profperiod
static

Definition at line 93 of file kern_clocksource.c.

Referenced by cpu_initclocks_bsp(), and handleevents().

◆ singlemul

int singlemul
static

Definition at line 101 of file kern_clocksource.c.

Referenced by cpu_initclocks_bsp(), and setuptimer().

◆ statperiod

sbintime_t statperiod
static

Definition at line 92 of file kern_clocksource.c.

Referenced by cpu_initclocks_bsp(), and handleevents().

◆ timer

◆ timername

char timername[32]
static

Definition at line 98 of file kern_clocksource.c.

Referenced by cpu_initclocks_bsp().

◆ timerperiod

sbintime_t timerperiod
static

Definition at line 91 of file kern_clocksource.c.

Referenced by configtimer(), loadtimer(), setuptimer(), and timercb().

◆ want_periodic

int want_periodic
static