FreeBSD kernel kern code
subr_clock.c File Reference
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/clock.h>
#include <sys/limits.h>
#include <sys/sysctl.h>
#include <sys/timetc.h>
Include dependency graph for subr_clock.c:

Go to the source code of this file.

Macros

#define FEBRUARY   2
 
#define days_in_year(y)   (leapyear(y) ? 366 : 365)
 
#define days_in_month(y, m)    (month_days[(m) - 1] + (m == FEBRUARY ? leapyear(y) : 0))
 
#define day_of_week(days)   (((days) + 4) % 7)
 

Functions

 __FBSDID ("$FreeBSD$")
 
static int sysctl_machdep_adjkerntz (SYSCTL_HANDLER_ARGS)
 
 SYSCTL_PROC (_machdep, OID_AUTO, adjkerntz, CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_MPSAFE, &adjkerntz, 0, sysctl_machdep_adjkerntz, "I", "Local offset from UTC in seconds")
 
 SYSCTL_INT (_debug, OID_AUTO, clocktime, CTLFLAG_RWTUN, &ct_debug, 0, "Enable printing of clocktime debugging")
 
 SYSCTL_INT (_machdep, OID_AUTO, wall_cmos_clock, CTLFLAG_RW, &wall_cmos_clock, 0, "Enables application of machdep.adjkerntz")
 
static int leapyear (int year)
 
int clock_ct_to_ts (const struct clocktime *ct, struct timespec *ts)
 
int clock_bcd_to_ts (const struct bcd_clocktime *bct, struct timespec *ts, bool ampm)
 
void clock_ts_to_ct (const struct timespec *ts, struct clocktime *ct)
 
void clock_ts_to_bcd (const struct timespec *ts, struct bcd_clocktime *bct, bool ampm)
 
void clock_print_bcd (const struct bcd_clocktime *bct, int nsdigits)
 
void clock_print_ct (const struct clocktime *ct, int nsdigits)
 
void clock_print_ts (const struct timespec *ts, int nsdigits)
 
int utc_offset (void)
 

Variables

static int adjkerntz
 
static int ct_debug
 
static int wall_cmos_clock
 
static const int month_days [12]
 
static const int recent_base_year = 2017
 
static const int recent_base_days = 17167
 
static u_int nsdivisors []
 

Macro Definition Documentation

◆ day_of_week

#define day_of_week (   days)    (((days) + 4) % 7)

Definition at line 92 of file subr_clock.c.

◆ days_in_month

#define days_in_month (   y,
 
)     (month_days[(m) - 1] + (m == FEBRUARY ? leapyear(y) : 0))

Definition at line 89 of file subr_clock.c.

◆ days_in_year

#define days_in_year (   y)    (leapyear(y) ? 366 : 365)

Definition at line 88 of file subr_clock.c.

◆ FEBRUARY

#define FEBRUARY   2

Definition at line 87 of file subr_clock.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ clock_bcd_to_ts()

int clock_bcd_to_ts ( const struct bcd_clocktime *  bct,
struct timespec *  ts,
bool  ampm 
)

Definition at line 199 of file subr_clock.c.

References clock_ct_to_ts(), ct_debug, printf(), and ts.

Here is the call graph for this function:

◆ clock_ct_to_ts()

int clock_ct_to_ts ( const struct clocktime *  ct,
struct timespec *  ts 
)

Definition at line 139 of file subr_clock.c.

References clock_print_ct(), ct_debug, days, days_in_month, days_in_year, printf(), recent_base_days, recent_base_year, and ts.

Referenced by clock_bcd_to_ts().

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

◆ clock_print_bcd()

void clock_print_bcd ( const struct bcd_clocktime *  bct,
int  nsdigits 
)

Definition at line 337 of file subr_clock.c.

References nsdivisors, and printf().

Referenced by clock_dbgprint_bcd().

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

◆ clock_print_ct()

void clock_print_ct ( const struct clocktime *  ct,
int  nsdigits 
)

Definition at line 355 of file subr_clock.c.

References nsdivisors, and printf().

Referenced by clock_ct_to_ts(), clock_dbgprint_ct(), clock_print_ts(), and clock_ts_to_ct().

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

◆ clock_print_ts()

void clock_print_ts ( const struct timespec *  ts,
int  nsdigits 
)

Definition at line 373 of file subr_clock.c.

References clock_print_ct(), clock_ts_to_ct(), and ts.

Referenced by clock_dbgprint_hdr(), and clock_dbgprint_ts().

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

◆ clock_ts_to_bcd()

void clock_ts_to_bcd ( const struct timespec *  ts,
struct bcd_clocktime *  bct,
bool  ampm 
)

Definition at line 309 of file subr_clock.c.

References clock_ts_to_ct(), and ts.

Here is the call graph for this function:

◆ clock_ts_to_ct()

void clock_ts_to_ct ( const struct timespec *  ts,
struct clocktime *  ct 
)

Definition at line 248 of file subr_clock.c.

References clock_print_ct(), ct_debug, day_of_week, days, days_in_month, days_in_year, printf(), recent_base_days, recent_base_year, and ts.

Referenced by clock_print_ts(), and clock_ts_to_bcd().

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

◆ leapyear()

static int leapyear ( int  year)
static

Definition at line 123 of file subr_clock.c.

◆ SYSCTL_INT() [1/2]

SYSCTL_INT ( _debug  ,
OID_AUTO  ,
clocktime  ,
CTLFLAG_RWTUN  ,
ct_debug,
,
"Enable printing of clocktime debugging"   
)

◆ SYSCTL_INT() [2/2]

SYSCTL_INT ( _machdep  ,
OID_AUTO  ,
wall_cmos_clock  ,
CTLFLAG_RW  ,
wall_cmos_clock,
,
"Enables application of machdep.adjkerntz  
)

◆ sysctl_machdep_adjkerntz()

static int sysctl_machdep_adjkerntz ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 61 of file subr_clock.c.

References resettodr(), and sysctl_handle_int().

Here is the call graph for this function:

◆ SYSCTL_PROC()

SYSCTL_PROC ( _machdep  ,
OID_AUTO  ,
adjkerntz  ,
CTLTYPE_INT|CTLFLAG_RW|  CTLFLAG_MPSAFE,
adjkerntz,
,
sysctl_machdep_adjkerntz  ,
"I"  ,
"Local offset from UTC in seconds"   
)

◆ utc_offset()

int utc_offset ( void  )

Definition at line 382 of file subr_clock.c.

References adjkerntz, and wall_cmos_clock.

Referenced by fattime2timespec(), kern_clock_settime(), read_clocks(), settime_task_func(), and timespec2fattime().

Here is the caller graph for this function:

Variable Documentation

◆ adjkerntz

int adjkerntz
static

Definition at line 59 of file subr_clock.c.

Referenced by utc_offset().

◆ ct_debug

int ct_debug
static

Definition at line 73 of file subr_clock.c.

Referenced by clock_bcd_to_ts(), clock_ct_to_ts(), and clock_ts_to_ct().

◆ month_days

const int month_days[12]
static
Initial value:
= {
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
}

Definition at line 94 of file subr_clock.c.

◆ nsdivisors

u_int nsdivisors[]
static
Initial value:
= {
1000000000, 100000000, 10000000, 1000000, 100000, 10000, 1000, 100, 10, 1
}

Definition at line 110 of file subr_clock.c.

Referenced by clock_print_bcd(), and clock_print_ct().

◆ recent_base_days

const int recent_base_days = 17167
static

Definition at line 104 of file subr_clock.c.

Referenced by clock_ct_to_ts(), and clock_ts_to_ct().

◆ recent_base_year

const int recent_base_year = 2017
static

Definition at line 103 of file subr_clock.c.

Referenced by clock_ct_to_ts(), and clock_ts_to_ct().

◆ wall_cmos_clock

int wall_cmos_clock
static

Definition at line 77 of file subr_clock.c.

Referenced by utc_offset().