diff options
author | 2020-09-16 00:00:40 +0000 | |
---|---|---|
committer | 2020-09-16 00:00:40 +0000 | |
commit | 97c55bccda719b6393e9cf9bae335fc9f9ec1dc8 (patch) | |
tree | b06f992acc478aee1fe331dfea0ad7e4d646ae39 /sys/kern/kern_tc.c | |
parent | rework a sentence in abl.4, and add an entry for it to acpi.4; (diff) | |
download | wireguard-openbsd-97c55bccda719b6393e9cf9bae335fc9f9ec1dc8.tar.xz wireguard-openbsd-97c55bccda719b6393e9cf9bae335fc9f9ec1dc8.zip |
timecounting: provide a naptime variable for userspace via kvm_read(3)
vmstat(8) uses kvm_read(3) to extract the naptime from the kernel.
Problem is, I deleted `naptime' from the global namespace when I moved
it into the timehands. This patch restores it. It gets updated from
tc_windup(). Only userspace should use it, and only when the kernel
is dead.
We need to tweak a variable in tc_setclock() to avoid shadowing the
(once again) global naptime.
Diffstat (limited to 'sys/kern/kern_tc.c')
-rw-r--r-- | sys/kern/kern_tc.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/sys/kern/kern_tc.c b/sys/kern/kern_tc.c index 025db8384c2..d19381a669f 100644 --- a/sys/kern/kern_tc.c +++ b/sys/kern/kern_tc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_tc.c,v 1.68 2020/07/20 22:40:53 deraadt Exp $ */ +/* $OpenBSD: kern_tc.c,v 1.69 2020/09/16 00:00:40 cheloha Exp $ */ /* * Copyright (c) 2000 Poul-Henning Kamp <phk@FreeBSD.org> @@ -110,6 +110,7 @@ static SLIST_HEAD(, timecounter) tc_list = SLIST_HEAD_INITIALIZER(tc_list); * These are updated from tc_windup(). They are useful when * examining kernel core dumps. */ +volatile time_t naptime = 0; volatile time_t time_second = 1; volatile time_t time_uptime = 0; @@ -475,7 +476,7 @@ tc_setrealtimeclock(const struct timespec *ts) void tc_setclock(const struct timespec *ts) { - struct bintime naptime, old_naptime, uptime, utc; + struct bintime new_naptime, old_naptime, uptime, utc; struct timespec tmp; static int first = 1; #ifndef SMALL_KERNEL @@ -503,11 +504,11 @@ tc_setclock(const struct timespec *ts) old_naptime = timehands->th_naptime; /* XXX fiddle all the little crinkly bits around the fiords... */ tc_windup(NULL, &uptime, NULL); - naptime = timehands->th_naptime; + new_naptime = timehands->th_naptime; mtx_leave(&windup_mtx); - if (bintimecmp(&old_naptime, &naptime, ==)) { + if (bintimecmp(&old_naptime, &new_naptime, ==)) { BINTIME_TO_TIMESPEC(&uptime, &tmp); printf("%s: cannot rewind uptime to %lld.%09ld\n", __func__, (long long)tmp.tv_sec, tmp.tv_nsec); @@ -515,7 +516,7 @@ tc_setclock(const struct timespec *ts) #ifndef SMALL_KERNEL /* convert the bintime to ticks */ - bintimesub(&naptime, &old_naptime, &elapsed); + bintimesub(&new_naptime, &old_naptime, &elapsed); adj_ticks = (uint64_t)hz * elapsed.sec + (((uint64_t)1000000 * (uint32_t)(elapsed.frac >> 32)) >> 32) / tick; if (adj_ticks > 0) { @@ -611,6 +612,7 @@ tc_windup(struct bintime *new_boottime, struct bintime *new_offset, if (new_offset != NULL && bintimecmp(&th->th_offset, new_offset, <)) { bintimesub(new_offset, &th->th_offset, &bt); bintimeadd(&th->th_naptime, &bt, &th->th_naptime); + naptime = th->th_naptime.sec; th->th_offset = *new_offset; } |