AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
time.c File Reference

The wall clock: the date and time of day. More...

#include <core/system.h>
#include <core/time.h>
#include <core/arch.h>
#include <core/printk.h>

Go to the source code of this file.

Functions

int gettime (struct timespec *ts)
 Reads the wall clock (CLOCK_REALTIME).
void time_resync (void)
 Sets the wall clock from the real time clock again, if they are 2 seconds or more apart.
int gettimeofday (struct timeval *tv, struct timezone *tz)
 Reads the wall clock, in microseconds, for gettimeofday().

Variables

static time_t clock_base_sec
static uint64_t clock_base_ns
static int clock_set

Detailed Description

The wall clock: the date and time of day.

The real time clock (the CMOS clock on the PC) only counts seconds, so it is read once, and from then on the wall clock follows the kernel's monotonic clock (arch_rtime_ns()), which counts much finer. time_resync() sets it from the real time clock again now and then, in case the two drift apart.

Definition in file time.c.

Function Documentation

◆ gettime()

int gettime ( struct timespec * ts)

Reads the wall clock (CLOCK_REALTIME).

The first call reads the real time clock.

Parameters
tsset to the time, since the epoch
Returns
0, or a negative errno if the real time clock can't be read

Definition at line 29 of file time.c.

References arch_rtime_ns(), arch_time_get(), clock_base_ns, clock_base_sec, clock_set, gettime(), timespec::tv_nsec, and timespec::tv_sec.

Referenced by cpio_root_node(), devfs_init(), devpts_init(), ext2_inode_discard(), ext2_vlink(), ext2_vmknod(), ext2_vrename(), ext2_vunlink(), gettime(), gettimeofday(), procfs_init(), procfs_vget(), pseudofs_vmknod(), sys_clock_gettime(), time_resync(), tmpfs_mount(), vfs_chmod(), vfs_chown(), and vfs_utimens().

◆ gettimeofday()

int gettimeofday ( struct timeval * tv,
struct timezone * tz )

Reads the wall clock, in microseconds, for gettimeofday().

Parameters
tvif not NULL, set to the time, since the epoch
tzif not NULL, set to UTC (the kernel has no time zones)
Returns
0, or a negative errno if the real time clock can't be read

Definition at line 78 of file time.c.

References gettime(), gettimeofday(), timespec::tv_nsec, timespec::tv_sec, timeval::tv_sec, timeval::tv_usec, timezone::tz_dsttime, and timezone::tz_minuteswest.

Referenced by gettimeofday(), and sys_gettimeofday().

◆ time_resync()

void time_resync ( void )

Sets the wall clock from the real time clock again, if they are 2 seconds or more apart.

The tick calls it now and then: the monotonic clock, which the wall clock follows, may count a little fast or slow.

Definition at line 54 of file time.c.

References arch_rtime_ns(), arch_time_get(), clock_base_ns, clock_base_sec, clock_set, gettime(), printk(), time_resync(), and timespec::tv_sec.

Referenced by sched_tick(), time_resync(), and x86_sched_handler().

Variable Documentation

◆ clock_base_ns

uint64_t clock_base_ns
static

Definition at line 19 of file time.c.

Referenced by gettime(), and time_resync().

◆ clock_base_sec

time_t clock_base_sec
static

Definition at line 18 of file time.c.

Referenced by gettime(), and time_resync().

◆ clock_set

int clock_set
static

Definition at line 20 of file time.c.

Referenced by gettime(), and time_resync().