summaryrefslogtreecommitdiff
path: root/src/regress/lib/libc/timekeep/test_clock_gettime.c
diff options
context:
space:
mode:
authorpirofti <>2020-07-06 13:33:06 +0000
committerpirofti <>2020-07-06 13:33:06 +0000
commit8f3f3991023702d597728be7e37b1e46b3ad7e46 (patch)
treeef9ff1387be3a6d8c07e9b6b6f87416080f68262 /src/regress/lib/libc/timekeep/test_clock_gettime.c
parentc09004d5abb7461b1cd8e9ffd0624c1185603fba (diff)
downloadopenbsd-8f3f3991023702d597728be7e37b1e46b3ad7e46.tar.gz
openbsd-8f3f3991023702d597728be7e37b1e46b3ad7e46.tar.bz2
openbsd-8f3f3991023702d597728be7e37b1e46b3ad7e46.zip
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@
Diffstat (limited to 'src/regress/lib/libc/timekeep/test_clock_gettime.c')
-rw-r--r--src/regress/lib/libc/timekeep/test_clock_gettime.c43
1 files changed, 43 insertions, 0 deletions
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 @@
1/* $OpenBSD: test_clock_gettime.c,v 1.1 2020/07/06 13:33:06 pirofti Exp $ */
2/*
3 * Copyright (c) 2020 Paul Irofti <paul@irofti.net>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <assert.h>
19#include <time.h>
20
21#define ASSERT_EQ(a, b) assert((a) == (b))
22
23void
24check()
25{
26 struct timespec tp = {0};
27
28 ASSERT_EQ(0, clock_gettime(CLOCK_REALTIME, &tp));
29 ASSERT_EQ(0, clock_gettime(CLOCK_MONOTONIC, &tp));
30 ASSERT_EQ(0, clock_gettime(CLOCK_BOOTTIME, &tp));
31 ASSERT_EQ(0, clock_gettime(CLOCK_UPTIME, &tp));
32
33
34 ASSERT_EQ(0, clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tp));
35 ASSERT_EQ(0, clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp));
36
37}
38
39int main()
40{
41 check();
42 return 0;
43}