FreeBSD kernel kern code
kern_tc.c File Reference
#include <sys/cdefs.h>
#include "opt_compat.h"
#include "opt_ntp.h"
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/sysctl.h>
#include <sys/syslog.h>
#include <sys/systm.h>
#include <sys/timepps.h>
#include <sys/timetc.h>
#include <sys/timex.h>
#include <sys/vdso.h>
Include dependency graph for kern_tc.c:

Go to the source code of this file.

Data Structures

struct  timehands
 

Macros

#define LARGE_STEP   200
 

Functions

 __FBSDID ("$BSDSUniX$")
 
static u_int dummy_get_timecount (struct timecounter *tc)
 
static int sysctl_kern_boottime (SYSCTL_HANDLER_ARGS)
 
 SYSCTL_PROC (_kern, KERN_BOOTTIME, boottime, CTLTYPE_STRUCT|CTLFLAG_RD, NULL, 0, sysctl_kern_boottime,"S,timeval","System boottime")
 
 SYSCTL_NODE (_kern, OID_AUTO, timecounter, CTLFLAG_RW, 0,"")
 
static SYSCTL_NODE (_kern_timecounter, OID_AUTO, tc, CTLFLAG_RW, 0,"")
 
 SYSCTL_INT (_kern_timecounter, OID_AUTO, stepwarnings, CTLFLAG_RW,&timestepwarnings, 0,"Log time steps")
 
static void tc_windup (void)
 
static void cpu_tick_calibrate (int)
 
void dtrace_getnanotime (struct timespec *tsp)
 
static int sysctl_kern_timecounter_get (SYSCTL_HANDLER_ARGS)
 
static int sysctl_kern_timecounter_freq (SYSCTL_HANDLER_ARGS)
 
static __inline u_int tc_delta (struct timehands *th)
 
void binuptime (struct bintime *bt)
 
void nanouptime (struct timespec *tsp)
 
void microuptime (struct timeval *tvp)
 
void bintime (struct bintime *bt)
 
void nanotime (struct timespec *tsp)
 
void microtime (struct timeval *tvp)
 
void getbinuptime (struct bintime *bt)
 
void getnanouptime (struct timespec *tsp)
 
void getmicrouptime (struct timeval *tvp)
 
void getbintime (struct bintime *bt)
 
void getnanotime (struct timespec *tsp)
 
void getmicrotime (struct timeval *tvp)
 
void tc_init (struct timecounter *tc)
 
uint64_t tc_getfrequency (void)
 
void tc_setclock (struct timespec *ts)
 
static int sysctl_kern_timecounter_hardware (SYSCTL_HANDLER_ARGS)
 
 SYSCTL_PROC (_kern_timecounter, OID_AUTO, hardware, CTLTYPE_STRING|CTLFLAG_RW, 0, 0, sysctl_kern_timecounter_hardware,"A","Timecounter hardware selected")
 
static int sysctl_kern_timecounter_choice (SYSCTL_HANDLER_ARGS)
 
 SYSCTL_PROC (_kern_timecounter, OID_AUTO, choice, CTLTYPE_STRING|CTLFLAG_RD, 0, 0, sysctl_kern_timecounter_choice,"A","Timecounter hardware detected")
 
int pps_ioctl (u_long cmd, caddr_t data, struct pps_state *pps)
 
void pps_init (struct pps_state *pps)
 
void pps_capture (struct pps_state *pps)
 
void pps_event (struct pps_state *pps, int event)
 
 SYSCTL_INT (_kern_timecounter, OID_AUTO, tick, CTLFLAG_RD,&tc_tick, 0,"Approximate number of hardclock ticks in a millisecond")
 
void tc_ticktock (int cnt)
 
static void inittimecounter (void *dummy)
 
 SYSINIT (timecounter, SI_SUB_CLOCKS, SI_ORDER_SECOND, inittimecounter, NULL)
 
static uint64_t tc_cpu_ticks (void)
 
void cpu_tick_calibration (void)
 
void set_cputicker (cpu_tick_f *func, uint64_t freq, unsigned var)
 
uint64_t cpu_tickrate (void)
 
uint64_t cputick2usec (uint64_t tick)
 
static int sysctl_fast_gettime (SYSCTL_HANDLER_ARGS)
 
 SYSCTL_PROC (_kern_timecounter, OID_AUTO, fast_gettime, CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_MPSAFE, NULL, 0, sysctl_fast_gettime,"I","Enable fast time of day")
 
uint32_t tc_fill_vdso_timehands (struct vdso_timehands *vdso_th)
 

Variables

static struct timecounter dummy_timecounter
 
static struct timehands th0
 
static struct timehands th9 = { NULL, 0, 0, 0, {0, 0}, {0, 0}, {0, 0}, 0, &th0}
 
static struct timehands th8 = { NULL, 0, 0, 0, {0, 0}, {0, 0}, {0, 0}, 0, &th9}
 
static struct timehands th7 = { NULL, 0, 0, 0, {0, 0}, {0, 0}, {0, 0}, 0, &th8}
 
static struct timehands th6 = { NULL, 0, 0, 0, {0, 0}, {0, 0}, {0, 0}, 0, &th7}
 
static struct timehands th5 = { NULL, 0, 0, 0, {0, 0}, {0, 0}, {0, 0}, 0, &th6}
 
static struct timehands th4 = { NULL, 0, 0, 0, {0, 0}, {0, 0}, {0, 0}, 0, &th5}
 
static struct timehands th3 = { NULL, 0, 0, 0, {0, 0}, {0, 0}, {0, 0}, 0, &th4}
 
static struct timehands th2 = { NULL, 0, 0, 0, {0, 0}, {0, 0}, {0, 0}, 0, &th3}
 
static struct timehands th1 = { NULL, 0, 0, 0, {0, 0}, {0, 0}, {0, 0}, 0, &th2}
 
static struct timehands *volatile timehands = &th0
 
struct timecounter * timecounter = &dummy_timecounter
 
static struct timecountertimecounters = &dummy_timecounter
 
int tc_min_ticktock_freq = 1
 
volatile time_t time_second = 1
 
volatile time_t time_uptime = 1
 
struct bintime boottimebin
 
struct timeval boottime
 
static int timestepwarnings
 
static int tc_tick
 
static int cpu_tick_variable
 
static uint64_t cpu_tick_frequency
 
cpu_tick_f * cpu_ticks = tc_cpu_ticks
 
static int vdso_th_enable = 1
 

Macro Definition Documentation

#define LARGE_STEP   200

Definition at line 32 of file kern_tc.c.

Referenced by tc_windup().

Function Documentation

__FBSDID ( "$BSDSUniX$"  )
static void cpu_tick_calibrate ( int  reset)
static

Definition at line 896 of file kern_tc.c.

References bintime(), bootverbose, cpu_tick_frequency, cpu_tick_variable, cpu_ticks, getbinuptime(), and printf().

Referenced by cpu_tick_calibration(), and tc_setclock().

Here is the call graph for this function:

Here is the caller graph for this function:

void cpu_tick_calibration ( void  )

Definition at line 877 of file kern_tc.c.

References cpu_tick_calibrate(), and time_uptime.

Referenced by hardclock(), and hardclock_cnt().

Here is the call graph for this function:

Here is the caller graph for this function:

uint64_t cpu_tickrate ( void  )

Definition at line 956 of file kern_tc.c.

References cpu_tick_frequency, cpu_ticks, tc_cpu_ticks(), and tc_getfrequency().

Referenced by cputick2usec(), kern_clock_getres(), and lim_cb().

Here is the call graph for this function:

Here is the caller graph for this function:

uint64_t cputick2usec ( uint64_t  tick)

Definition at line 975 of file kern_tc.c.

References cpu_tickrate().

Referenced by calcru1(), cputick2timespec(), fill_kinfo_proc_only(), and fill_kinfo_thread().

Here is the call graph for this function:

Here is the caller graph for this function:

void dtrace_getnanotime ( struct timespec *  tsp)

Definition at line 313 of file kern_tc.c.

References timehands::th_generation, timehands::th_nanotime, and timehands.

static u_int dummy_get_timecount ( struct timecounter tc)
static

Definition at line 41 of file kern_tc.c.

void getbintime ( struct bintime bt)

Definition at line 268 of file kern_tc.c.

References boottimebin, timehands::th_generation, timehands::th_offset, and timehands.

void getbinuptime ( struct bintime bt)

Definition at line 229 of file kern_tc.c.

References timehands::th_generation, timehands::th_offset, and timehands.

Referenced by cpu_tick_calibrate(), and init_va_filerev().

Here is the caller graph for this function:

void getmicrotime ( struct timeval *  tvp)

Definition at line 295 of file kern_tc.c.

References timehands::th_generation, timehands::th_microtime, and timehands.

Referenced by ttydisc_read_raw_read_timer().

Here is the caller graph for this function:

void getmicrouptime ( struct timeval *  tvp)

Definition at line 255 of file kern_tc.c.

References timehands::th_generation, timehands::th_offset, and timehands.

Referenced by kern_getitimer(), kern_select(), kern_setitimer(), kqueue_scan(), ratecheck(), realitexpire(), selsocket(), and sys_poll().

Here is the caller graph for this function:

void getnanotime ( struct timespec *  tsp)

Definition at line 282 of file kern_tc.c.

References timehands::th_generation, timehands::th_nanotime, and timehands.

Referenced by kern_clock_gettime(), kern_sem_wait(), mqueue_receive(), mqueue_send(), realtimer_clocktime(), resettodr(), and vfs_timestamp().

Here is the caller graph for this function:

void getnanouptime ( struct timespec *  tsp)
static void inittimecounter ( void *  dummy)
static

Definition at line 828 of file kern_tc.c.

References hz, printf(), tc_tick, tc_windup(), and timecounter.

Here is the call graph for this function:

void microtime ( struct timeval *  tvp)

Definition at line 220 of file kern_tc.c.

References bintime().

Referenced by settime(), sys_gettimeofday(), unp_internalize(), and vfs_timestamp().

Here is the call graph for this function:

Here is the caller graph for this function:

void microuptime ( struct timeval *  tvp)

Definition at line 194 of file kern_tc.c.

References bintime(), and binuptime().

Referenced by acct_process(), do_fork(), hardclock_device_poll(), netisr_poll(), netisr_pollmore(), proc0_post(), and tty_info().

Here is the call graph for this function:

Here is the caller graph for this function:

void nanotime ( struct timespec *  tsp)

Definition at line 211 of file kern_tc.c.

References bintime().

Referenced by kern_clock_gettime(), ntp_gettime1(), proc0_post(), tc_setclock(), and vfs_timestamp().

Here is the call graph for this function:

Here is the caller graph for this function:

void nanouptime ( struct timespec *  tsp)

Definition at line 185 of file kern_tc.c.

References bintime(), and binuptime().

Referenced by kern_clock_gettime().

Here is the call graph for this function:

Here is the caller graph for this function:

void pps_capture ( struct pps_state *  pps)

Definition at line 702 of file kern_tc.c.

References timehands::th_counter, timehands::th_generation, and timehands.

void pps_event ( struct pps_state *  pps,
int  event 
)

Definition at line 716 of file kern_tc.c.

References bintime(), boottimebin, and ts.

Here is the call graph for this function:

void pps_init ( struct pps_state *  pps)

Definition at line 692 of file kern_tc.c.

int pps_ioctl ( u_long  cmd,
caddr_t  data,
struct pps_state *  pps 
)

Definition at line 634 of file kern_tc.c.

void set_cputicker ( cpu_tick_f *  func,
uint64_t  freq,
unsigned  var 
)

Definition at line 943 of file kern_tc.c.

References cpu_tick_frequency, cpu_tick_variable, cpu_ticks, and tc_cpu_ticks().

Here is the call graph for this function:

static int sysctl_fast_gettime ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 990 of file kern_tc.c.

References sysctl_handle_int(), timekeep_push_vdso(), and vdso_th_enable.

Here is the call graph for this function:

SYSCTL_INT ( _kern_timecounter  ,
OID_AUTO  ,
stepwarnings  ,
CTLFLAG_RW  ,
timestepwarnings,
,
"Log time steps"   
)
SYSCTL_INT ( _kern_timecounter  ,
OID_AUTO  ,
tick  ,
CTLFLAG_RD  ,
tc_tick,
,
"Approximate number of hardclock ticks in a millisecond"   
)
static int sysctl_kern_boottime ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 116 of file kern_tc.c.

References boottime.

static int sysctl_kern_timecounter_choice ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 609 of file kern_tc.c.

References buf, sprintf(), timecounter, and timecounters.

Here is the call graph for this function:

static int sysctl_kern_timecounter_freq ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 141 of file kern_tc.c.

References sysctl_handle_64(), and timecounter.

Referenced by tc_init().

Here is the call graph for this function:

Here is the caller graph for this function:

static int sysctl_kern_timecounter_get ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 131 of file kern_tc.c.

References sysctl_handle_int(), and timecounter.

Referenced by tc_init().

Here is the call graph for this function:

Here is the caller graph for this function:

static int sysctl_kern_timecounter_hardware ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 574 of file kern_tc.c.

References sysctl_handle_string(), timecounter, timecounters, and timekeep_push_vdso().

Here is the call graph for this function:

SYSCTL_NODE ( _kern  ,
OID_AUTO  ,
timecounter  ,
CTLFLAG_RW  ,
,
""   
)
static SYSCTL_NODE ( _kern_timecounter  ,
OID_AUTO  ,
tc  ,
CTLFLAG_RW  ,
,
""   
)
static
SYSCTL_PROC ( _kern  ,
KERN_BOOTTIME  ,
boottime  ,
CTLTYPE_STRUCT|  CTLFLAG_RD,
NULL  ,
,
sysctl_kern_boottime  ,
S,
timeval"  ,
"System boottime  
)
SYSCTL_PROC ( _kern_timecounter  ,
OID_AUTO  ,
hardware  ,
CTLTYPE_STRING|  CTLFLAG_RW,
,
,
sysctl_kern_timecounter_hardware  ,
"A"  ,
"Timecounter hardware selected"   
)
SYSCTL_PROC ( _kern_timecounter  ,
OID_AUTO  ,
choice  ,
CTLTYPE_STRING|  CTLFLAG_RD,
,
,
sysctl_kern_timecounter_choice  ,
"A"  ,
"Timecounter hardware detected"   
)
SYSCTL_PROC ( _kern_timecounter  ,
OID_AUTO  ,
fast_gettime  ,
CTLTYPE_INT|CTLFLAG_RW|  CTLFLAG_MPSAFE,
NULL  ,
,
sysctl_fast_gettime  ,
"I"  ,
"Enable fast time of day"   
)
SYSINIT ( timecounter  ,
SI_SUB_CLOCKS  ,
SI_ORDER_SECOND  ,
inittimecounter  ,
NULL   
)
static uint64_t tc_cpu_ticks ( void  )
static

Definition at line 861 of file kern_tc.c.

References timehands::th_counter, and timecounter.

Referenced by cpu_tickrate(), and set_cputicker().

Here is the caller graph for this function:

static __inline u_int tc_delta ( struct timehands th)
static

Definition at line 155 of file kern_tc.c.

References timehands::th_counter, timehands::th_offset_count, and timecounter.

Referenced by binuptime(), and tc_windup().

Here is the caller graph for this function:

uint32_t tc_fill_vdso_timehands ( struct vdso_timehands *  vdso_th)

Definition at line 1007 of file kern_tc.c.

References boottimebin, cpu_fill_vdso_timehands(), timehands::th_counter, timehands::th_offset, timehands::th_offset_count, timehands::th_scale, timehands, and vdso_th_enable.

Referenced by timehands_update().

Here is the call graph for this function:

Here is the caller graph for this function:

uint64_t tc_getfrequency ( void  )

Definition at line 390 of file kern_tc.c.

References timehands::th_counter.

Referenced by cpu_tickrate(), and kern_clock_getres().

Here is the caller graph for this function:

void tc_init ( struct timecounter tc)

Definition at line 329 of file kern_tc.c.

References bootverbose, hz, printf(), sysctl_kern_timecounter_freq(), sysctl_kern_timecounter_get(), timecounter, and timecounters.

Here is the call graph for this function:

void tc_setclock ( struct timespec *  ts)

Definition at line 402 of file kern_tc.c.

References bintime(), binuptime(), boottime, boottimebin, cpu_tick_calibrate(), log(), nanotime(), tc_windup(), and timestepwarnings.

Referenced by inittodr(), and settime().

Here is the call graph for this function:

Here is the caller graph for this function:

void tc_ticktock ( int  cnt)

Definition at line 816 of file kern_tc.c.

References count, tc_tick, and tc_windup().

Referenced by hardclock(), and hardclock_cnt().

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

struct timeval boottime

Definition at line 98 of file kern_tc.c.

Referenced by acct_process(), fill_kinfo_proc_only(), sysctl_kern_boottime(), and tc_setclock().

struct bintime boottimebin

Definition at line 97 of file kern_tc.c.

Referenced by bintime(), getbintime(), pps_event(), tc_fill_vdso_timehands(), tc_setclock(), and tc_windup().

uint64_t cpu_tick_frequency
static

Definition at line 858 of file kern_tc.c.

Referenced by cpu_tick_calibrate(), cpu_tickrate(), and set_cputicker().

int cpu_tick_variable
static

Definition at line 857 of file kern_tc.c.

Referenced by cpu_tick_calibrate(), and set_cputicker().

struct timecounter dummy_timecounter
static
Initial value:
= {
dummy_get_timecount, 0, ~0u, 1000000, "dummy", -1000000
}
static u_int dummy_get_timecount(struct timecounter *tc)
Definition: kern_tc.c:41

Definition at line 48 of file kern_tc.c.

int tc_min_ticktock_freq = 1

Definition at line 92 of file kern_tc.c.

Referenced by getnextcpuevent(), and tc_windup().

int tc_tick
static

Definition at line 811 of file kern_tc.c.

Referenced by inittimecounter(), and tc_ticktock().

static struct timehands th0
static
Initial value:
= {
0,
(uint64_t)-1 / 1000000,
0,
{1, 0},
{0, 0},
{0, 0},
1,
&th1
}
static struct timecounter dummy_timecounter
Definition: kern_tc.c:48
static struct timehands th1
Definition: kern_tc.c:75

Definition at line 66 of file kern_tc.c.

struct timehands th1 = { NULL, 0, 0, 0, {0, 0}, {0, 0}, {0, 0}, 0, &th2}
static

Definition at line 75 of file kern_tc.c.

struct timehands th2 = { NULL, 0, 0, 0, {0, 0}, {0, 0}, {0, 0}, 0, &th3}
static

Definition at line 74 of file kern_tc.c.

struct timehands th3 = { NULL, 0, 0, 0, {0, 0}, {0, 0}, {0, 0}, 0, &th4}
static

Definition at line 73 of file kern_tc.c.

struct timehands th4 = { NULL, 0, 0, 0, {0, 0}, {0, 0}, {0, 0}, 0, &th5}
static

Definition at line 72 of file kern_tc.c.

struct timehands th5 = { NULL, 0, 0, 0, {0, 0}, {0, 0}, {0, 0}, 0, &th6}
static

Definition at line 71 of file kern_tc.c.

struct timehands th6 = { NULL, 0, 0, 0, {0, 0}, {0, 0}, {0, 0}, 0, &th7}
static

Definition at line 70 of file kern_tc.c.

struct timehands th7 = { NULL, 0, 0, 0, {0, 0}, {0, 0}, {0, 0}, 0, &th8}
static

Definition at line 69 of file kern_tc.c.

struct timehands th8 = { NULL, 0, 0, 0, {0, 0}, {0, 0}, {0, 0}, 0, &th9}
static

Definition at line 68 of file kern_tc.c.

struct timehands th9 = { NULL, 0, 0, 0, {0, 0}, {0, 0}, {0, 0}, 0, &th0}
static

Definition at line 67 of file kern_tc.c.

volatile time_t time_uptime = 1
struct timecounter* timecounters = &dummy_timecounter
static
int timestepwarnings
static

Definition at line 106 of file kern_tc.c.

Referenced by tc_setclock().

int vdso_th_enable = 1
static

Definition at line 988 of file kern_tc.c.

Referenced by sysctl_fast_gettime(), and tc_fill_vdso_timehands().