From 8f3f3991023702d597728be7e37b1e46b3ad7e46 Mon Sep 17 00:00:00 2001 From: pirofti <> Date: Mon, 6 Jul 2020 13:33:06 +0000 Subject: Add support for timeconting in userland. This diff exposes parts of clock_gettime(2) and gettimeofday(2) to userland via libc eliberating processes from the need for a context switch everytime they want to count the passage of time. If a timecounter clock can be exposed to userland than it needs to set its tc_user member to a non-zero value. Tested with one or multiple counters per architecture. The timing data is shared through a pointer found in the new ELF auxiliary vector AUX_openbsd_timekeep containing timehands information that is frequently updated by the kernel. Timing differences between the last kernel update and the current time are adjusted in userland by the tc_get_timecount() function inside the MD usertc.c file. This permits a much more responsive environment, quite visible in browsers, office programs and gaming (apparently one is are able to fly in Minecraft now). Tested by robert@, sthen@, naddy@, kmos@, phessler@, and many others! OK from at least kettenis@, cheloha@, naddy@, sthen@ --- src/regress/lib/libc/timekeep/test_clock_gettime.c | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/regress/lib/libc/timekeep/test_clock_gettime.c (limited to 'src/regress/lib/libc/timekeep/test_clock_gettime.c') diff --git a/src/regress/lib/libc/timekeep/test_clock_gettime.c b/src/regress/lib/libc/timekeep/test_clock_gettime.c new file mode 100644 index 0000000000..cc1d8e36e3 --- /dev/null +++ b/src/regress/lib/libc/timekeep/test_clock_gettime.c @@ -0,0 +1,43 @@ +/* $OpenBSD: test_clock_gettime.c,v 1.1 2020/07/06 13:33:06 pirofti Exp $ */ +/* + * Copyright (c) 2020 Paul Irofti + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include + +#define ASSERT_EQ(a, b) assert((a) == (b)) + +void +check() +{ + struct timespec tp = {0}; + + ASSERT_EQ(0, clock_gettime(CLOCK_REALTIME, &tp)); + ASSERT_EQ(0, clock_gettime(CLOCK_MONOTONIC, &tp)); + ASSERT_EQ(0, clock_gettime(CLOCK_BOOTTIME, &tp)); + ASSERT_EQ(0, clock_gettime(CLOCK_UPTIME, &tp)); + + + ASSERT_EQ(0, clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tp)); + ASSERT_EQ(0, clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp)); + +} + +int main() +{ + check(); + return 0; +} -- cgit v1.2.3-55-g6feb