FreeBSD kernel kern code
kern_clocksource.c File Reference
#include <sys/cdefs.h>
#include "opt_device_polling.h"
#include "opt_kdtrace.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/bus.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 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)
 
#define FREQ2BT(freq, bt)
 
#define BT2FREQ(bt)
 

Functions

 __FBSDID ("$BSDSUniX$")
 
static void setuptimer (void)
 
static void loadtimer (struct bintime *now, int first)
 
static int doconfigtimer (void)
 
static void configtimer (int start)
 
static int round_freq (struct eventtimer *et, int freq)
 
static void getnextcpuevent (struct bintime *event, int idle)
 
static void getnextevent (struct bintime *event)
 
static int handleevents (struct bintime *now, int fake)
 
 TUNABLE_STR ("kern.eventtimer.timer", timername, sizeof(timername))
 
 TUNABLE_INT ("kern.eventtimer.singlemul",&singlemul)
 
 SYSCTL_INT (_kern_eventtimer, OID_AUTO, singlemul, CTLFLAG_RW,&singlemul, 0,"Multiplier for periodic mode")
 
 TUNABLE_INT ("kern.eventtimer.idletick",&idletick)
 
 SYSCTL_UINT (_kern_eventtimer, OID_AUTO, idletick, CTLFLAG_RW,&idletick, 0,"Run periodic events when idle")
 
 TUNABLE_INT ("kern.eventtimer.activetick",&activetick)
 
 SYSCTL_UINT (_kern_eventtimer, OID_AUTO, activetick, CTLFLAG_RW,&activetick, 0,"Run all periodic events when active")
 
 TUNABLE_INT ("kern.eventtimer.periodic",&want_periodic)
 
static DPCPU_DEFINE (struct pcpu_state, timerstate)
 
int hardclockintr (void)
 
static void timercb (struct eventtimer *et, void *arg)
 
void cpu_initclocks_bsp (void)
 
void cpu_initclocks_ap (void)
 
void cpu_startprofclock (void)
 
void cpu_stopprofclock (void)
 
void cpu_idleclock (void)
 
void cpu_activeclock (void)
 
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_deepest_sleep = 0
 
int cpu_disable_c2_sleep = 0
 
int cpu_disable_c3_sleep = 0
 
static struct mtx et_hw_mtx
 
static struct eventtimer * timer = NULL
 
static struct bintime timerperiod
 
static struct bintime hardperiod
 
static struct bintime statperiod
 
static struct bintime profperiod
 
static struct bintime nexttick
 
static struct bintime nexthard
 
static u_int busy = 0
 
static int profiling = 0
 
static char timername [32]
 
static int singlemul = 0
 
static u_int idletick = 0
 
static u_int activetick = 1
 
static int periodic = 0
 
static int want_periodic = 0
 

Macro Definition Documentation

#define BT2FREQ (   bt)
Value:
(((uint64_t)0x8000000000000000 + ((bt)->frac >> 2)) / \
((bt)->frac >> 1))

Definition at line 153 of file kern_clocksource.c.

Referenced by round_freq().

#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 eventtimer * timer
static struct mtx et_hw_mtx

Definition at line 81 of file kern_clocksource.c.

Referenced by configtimer(), cpu_idleclock(), cpu_initclocks_ap(), doconfigtimer(), handleevents(), and timercb().

#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); \
}
static struct eventtimer * timer
static struct mtx et_hw_mtx

Definition at line 89 of file kern_clocksource.c.

Referenced by configtimer(), cpu_idleclock(), cpu_initclocks_ap(), doconfigtimer(), handleevents(), and timercb().

#define FREQ2BT (   freq,
  bt 
)
Value:
{ \
(bt)->sec = 0; \
(bt)->frac = ((uint64_t)0x8000000000000000 / (freq)) << 1; \
}

Definition at line 148 of file kern_clocksource.c.

Referenced by cpu_initclocks_bsp(), and setuptimer().

Function Documentation

__FBSDID ( "$BSDSUniX$"  )
void cpu_activeclock ( void  )

Definition at line 805 of file kern_clocksource.c.

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

Here is the call graph for this function:

void cpu_idleclock ( void  )

Definition at line 772 of file kern_clocksource.c.

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

Here is the call graph for this function:

void cpu_initclocks_ap ( void  )

Definition at line 708 of file kern_clocksource.c.

References bintime(), binuptime(), ET_HW_LOCK, ET_HW_UNLOCK, handleevents(), hardclock_sync(), loadtimer(), nexttick, pcpu_state::now, timer, and timerperiod.

Here is the call graph for this function:

void cpu_initclocks_bsp ( void  )
void cpu_startprofclock ( void  )

Definition at line 732 of file kern_clocksource.c.

References configtimer(), and profiling.

Referenced by startprofclock().

Here is the call graph for this function:

Here is the caller graph for this function:

void cpu_stopprofclock ( void  )

Definition at line 752 of file kern_clocksource.c.

References configtimer(), and profiling.

Referenced by stopprofclock().

Here is the call graph for this function:

Here is the caller graph for this function:

static int doconfigtimer ( void  )
static

Definition at line 484 of file kern_clocksource.c.

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

Referenced by hardclockintr().

Here is the call graph for this function:

Here is the caller graph for this function:

static DPCPU_DEFINE ( struct pcpu_state  ,
timerstate   
)
static
static void getnextcpuevent ( struct bintime event,
int  idle 
)
static

Definition at line 269 of file kern_clocksource.c.

References bintime(), callout_tickstofirst(), hardperiod, hz, pcpu_state::nexthard, pcpu_state::nextprof, pcpu_state::nextstat, profiling, stathz, tc_min_ticktock_freq, and timer.

Referenced by cpu_idleclock(), and handleevents().

Here is the call graph for this function:

Here is the caller graph for this function:

static void getnextevent ( struct bintime event)
static

Definition at line 305 of file kern_clocksource.c.

References pcpu_state::idle, pcpu_state::nextevent, nexthard, and timer.

Referenced by loadtimer().

Here is the caller graph for this function:

static int handleevents ( struct bintime now,
int  fake 
)
static
int hardclockintr ( void  )

Definition at line 161 of file kern_clocksource.c.

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

Here is the call graph for this function:

static void loadtimer ( struct bintime now,
int  first 
)
static

Definition at line 413 of file kern_clocksource.c.

References bintime(), et_start(), getnextevent(), nexttick, pcpu_state::nexttick, timer, and timerperiod.

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 594 of file kern_clocksource.c.

References BT2FREQ.

Referenced by cpu_initclocks_bsp(), and setuptimer().

Here is the caller graph for this function:

static void setuptimer ( void  )
static

Definition at line 464 of file kern_clocksource.c.

References FREQ2BT, hz, 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:

SYSCTL_INT ( _kern_eventtimer  ,
OID_AUTO  ,
singlemul  ,
CTLFLAG_RW  ,
singlemul,
,
"Multiplier for periodic mode  
)
static int sysctl_kern_eventtimer_periodic ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 961 of file kern_clocksource.c.

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

Here is the call graph for this function:

static int sysctl_kern_eventtimer_timer ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 917 of file kern_clocksource.c.

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

Here is the call graph for this function:

SYSCTL_PROC ( _kern_eventtimer  ,
OID_AUTO  ,
timer  ,
CTLTYPE_STRING|CTLFLAG_RW|  CTLFLAG_MPSAFE,
,
,
sysctl_kern_eventtimer_timer  ,
"A"  ,
"Chosen event timer  
)
SYSCTL_PROC ( _kern_eventtimer  ,
OID_AUTO  ,
periodic  ,
CTLTYPE_INT|CTLFLAG_RW|  CTLFLAG_MPSAFE,
,
,
sysctl_kern_eventtimer_periodic  ,
"I"  ,
"Enable event timer periodic mode  
)
SYSCTL_UINT ( _kern_eventtimer  ,
OID_AUTO  ,
idletick  ,
CTLFLAG_RW  ,
idletick,
,
"Run periodic events when idle"   
)
SYSCTL_UINT ( _kern_eventtimer  ,
OID_AUTO  ,
activetick  ,
CTLFLAG_RW  ,
activetick,
,
"Run all periodic events when active"   
)
static void timercb ( struct eventtimer *  et,
void *  arg 
)
static

Definition at line 340 of file kern_clocksource.c.

References bintime(), binuptime(), busy, ET_HW_LOCK, ET_HW_UNLOCK, handleevents(), pcpu_state::ipi, pcpu_state::nextevent, nexttick, pcpu_state::nexttick, pcpu_state::now, 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 ( "kern.eventtimer.singlemul"  ,
singlemul 
)
TUNABLE_INT ( "kern.eventtimer.idletick"  ,
idletick 
)
TUNABLE_INT ( "kern.eventtimer.activetick"  ,
activetick 
)
TUNABLE_INT ( "kern.eventtimer.periodic"  ,
want_periodic 
)
TUNABLE_STR ( "kern.eventtimer.timer"  ,
timername  ,
sizeof(timername  
)

Variable Documentation

u_int activetick = 1
static

Definition at line 120 of file kern_clocksource.c.

int cpu_deepest_sleep = 0

Definition at line 62 of file kern_clocksource.c.

int cpu_disable_c2_sleep = 0

Definition at line 63 of file kern_clocksource.c.

Referenced by tc_windup().

int cpu_disable_c3_sleep = 0

Definition at line 64 of file kern_clocksource.c.

Referenced by cpu_initclocks_bsp(), and sysctl_kern_eventtimer_timer().

struct mtx et_hw_mtx
static

Definition at line 79 of file kern_clocksource.c.

Referenced by cpu_initclocks_bsp().

struct bintime hardperiod
static

Definition at line 99 of file kern_clocksource.c.

Referenced by cpu_initclocks_bsp(), getnextcpuevent(), and handleevents().

u_int idletick = 0
static

Definition at line 115 of file kern_clocksource.c.

struct bintime nexthard
static

Definition at line 103 of file kern_clocksource.c.

Referenced by getnextevent(), and handleevents().

struct bintime nexttick
static

Definition at line 102 of file kern_clocksource.c.

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

int periodic = 0
static

Definition at line 125 of file kern_clocksource.c.

Referenced by sysctl_kern_eventtimer_periodic().

int profiling = 0
static
struct bintime profperiod
static

Definition at line 101 of file kern_clocksource.c.

Referenced by cpu_initclocks_bsp(), and handleevents().

int singlemul = 0
static

Definition at line 110 of file kern_clocksource.c.

Referenced by setuptimer().

struct bintime statperiod
static

Definition at line 100 of file kern_clocksource.c.

Referenced by cpu_initclocks_bsp(), and handleevents().

char timername[32]
static

Definition at line 107 of file kern_clocksource.c.

Referenced by cpu_initclocks_bsp().

struct bintime timerperiod
static

Definition at line 98 of file kern_clocksource.c.

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

int want_periodic = 0
static

Definition at line 126 of file kern_clocksource.c.

Referenced by cpu_initclocks_bsp(), and sysctl_kern_eventtimer_timer().