23#include "pedigree/kernel/process/InfoBlock.h"
30#include <sys/select.h>
31#include <sys/syscall.h>
39#error no infoblock address configured for this platform
44int __vdso_clock_gettime(clockid_t clock_id,
struct timespec* tp);
45int __vdso_gettimeofday(
struct timeval* tv,
void* tz);
46int __vdso_getcpu(
unsigned* cpu,
unsigned* node,
struct getcpu_cache* cache);
47time_t __vdso_time(time_t* tloc);
49int __vdso_clock_gettime(clockid_t clock_id,
struct timespec* tp) {
52 long result = SYS_clock_gettime;
53 __asm__
volatile(
"syscall"
55 :
"D"(clock_id),
"S"(tp)
56 :
"rcx",
"r11",
"memory",
"cc");
64 if (clock_id == CLOCK_REALTIME) {
66 }
else if (clock_id == CLOCK_MONOTONIC || clock_id == CLOCK_MONOTONIC_RAW) {
73 const uint64_t seconds = now / 1000000000U;
75 tp->tv_nsec = now - seconds * 1000000000U;
81int __vdso_gettimeofday(
struct timeval* tv,
void* tz) {
83 long result = SYS_gettimeofday;
84 __asm__
volatile(
"syscall" :
"+a"(result) :
"D"(tv),
"S"(tz) :
"rcx",
"r11",
"memory",
"cc");
89 uint64_t now = infoBlock->
now;
90 const uint64_t seconds = now / 1000000000U;
92 tv->tv_usec = (now - seconds * 1000000000U) / 1000U;
101int __vdso_getcpu(
unsigned* cpu,
unsigned* node,
struct getcpu_cache* cache) {
103 if (infoBlock->
vdso_features & INFO_BLOCK_VDSO_GETCPU_RDTSCP) {
104 unsigned ignored_low, ignored_high, aux;
105 __asm__
volatile(
"rdtscp" :
"=a"(ignored_low),
"=d"(ignored_high),
"=c"(aux) : :
"memory");
117 __asm__
volatile(
"syscall"
119 :
"D"(cpu),
"S"(node),
"d"(cache)
120 :
"rcx",
"r11",
"memory",
"cc");
130time_t __vdso_time(time_t* tloc) {
132 long result = SYS_time;
133 __asm__
volatile(
"syscall" :
"+a"(result) :
"D"(tloc) :
"rcx",
"r11",
"memory",
"cc");
134 return (time_t)result;
136 const time_t now = infoBlock->
now_s;
145__asm__(
".symver __vdso_clock_gettime,__vdso_clock_gettime@LINUX_2.6");
146__asm__(
".symver __vdso_gettimeofday,__vdso_gettimeofday@LINUX_2.6");
147__asm__(
".symver __vdso_getcpu,__vdso_getcpu@LINUX_2.6");
148__asm__(
".symver __vdso_time,__vdso_time@LINUX_2.6");
150int clock_gettime(clockid_t,
struct timespec*)
__attribute__((weak, alias(
"__vdso_clock_gettime")));
151int gettimeofday(
struct timeval* __restrict,
void* __restrict)
153int getcpu(
unsigned*,
unsigned*,
struct getcpu_cache*)
155time_t time(time_t*)
__attribute__((weak, alias(
"__vdso_time")));
uint64_t monotonic
Monotonic tick count in nanoseconds.
uint64_t now
Current timestamp in nanoseconds since the UNIX epoch.
uint32_t vdso_features
CPU-local vDSO capabilities published by the kernel.
uint64_t now_s
Current timestamp in seconds since the UNIX epoch.