The manual
ginnOS
The reference: libc, the libraries and the kernel
Toggle main menu visibility
Loading...
Searching...
No Matches
clock.h
Go to the documentation of this file.
1
#pragma once
2
3
/**
4
* the system clocks.
5
*
6
* CLOCK_REALTIME seconds since 1970 (from the RTC at boot, then the
7
* timer ticks)
8
* CLOCK_MONOTONIC time since boot; never set, never goes back
9
* CLOCK_PROCESS_CPUTIME_ID user and system time of the calling process
10
*
11
* the resolution is one timer tick (10 ms at 100 Hz).
12
*/
13
14
#include "
common/stdint.h
"
15
16
#define CLOCK_REALTIME 0
17
#define CLOCK_MONOTONIC 1
18
#define CLOCK_PROCESS_CPUTIME_ID 2
19
20
#define NSEC_PER_SEC 1000000000u
21
22
/**
23
* struct timespec (ABI: long seconds and nanoseconds, as the libc's
24
* <time.h> has it).
25
*/
26
struct
ktimespec
27
{
28
long
tv_sec
;
29
long
tv_nsec
;
30
};
31
32
/**
33
* read the wall-clock time from the RTC. call once at boot.
34
*/
35
void
clock_init
(
void
);
36
37
/**
38
* set up the queue nanosleep sleeps on. call once at boot, before the
39
* first nanosleep.
40
*/
41
void
clock_init_sleep
(
void
);
42
43
/**
44
* the wall-clock time in seconds since 1970 (0 if the RTC gave none).
45
*/
46
uint32_t
clock_realtime_seconds
(
void
);
47
48
/**
49
* a timespec from a number of timer ticks.
50
*/
51
void
clock_ticks_to_timespec
(
uint64_t
ticks,
struct
ktimespec
*out);
52
53
/**
54
* the timer ticks that cover at least a time span (rounded up).
55
*/
56
uint64_t
clock_timespec_to_ticks
(
const
struct
ktimespec
*span);
57
58
/**
59
* the wall-clock time as a timespec.
60
*/
61
void
clock_realtime
(
struct
ktimespec
*out);
clock_ticks_to_timespec
void clock_ticks_to_timespec(uint64_t ticks, struct ktimespec *out)
a timespec from a number of timer ticks.
Definition
clock.c:25
clock_init
void clock_init(void)
read the wall-clock time from the RTC.
Definition
clock.c:11
clock_timespec_to_ticks
uint64_t clock_timespec_to_ticks(const struct ktimespec *span)
the timer ticks that cover at least a time span (rounded up).
Definition
clock.c:114
clock_realtime
void clock_realtime(struct ktimespec *out)
the realtime clock as a timespec: the boot time plus the ticks since.
Definition
clock.c:35
clock_init_sleep
void clock_init_sleep(void)
set up the queue nanosleep sleeps on.
Definition
clock.c:54
clock_realtime_seconds
uint32_t clock_realtime_seconds(void)
the wall-clock time in seconds since 1970 (0 if the RTC gave none).
Definition
clock.c:20
stdint.h
uint32_t
unsigned int uint32_t
Definition
fb.h:17
uint64_t
__UINT64_TYPE__ uint64_t
Definition
stdint.h:17
ktimespec
struct timespec (ABI: long seconds and nanoseconds, as the libc's <time.h> has it).
Definition
clock.h:27
ktimespec::tv_sec
long tv_sec
Definition
clock.h:28
ktimespec::tv_nsec
long tv_nsec
Definition
clock.h:29
src
kernel
time
clock.h
Generated by
1.18.0