diff options
author | firk <firk@cantconnect.ru> | 2022-03-15 22:22:21 +0000 |
---|---|---|
committer | Mark Johnston <markj@FreeBSD.org> | 2022-03-17 19:39:00 +0000 |
commit | 28d08dc7d051a4e058cc0004cf4dd884f87037a2 (patch) | |
tree | 5bd1c8a93b6eee3adcd2ba42d1ec9bb3e49d073a | |
parent | fc7e121d88d65aabbb8ce87d8e1d13e3c3cf18eb (diff) | |
download | src-28d08dc7d051a4e058cc0004cf4dd884f87037a2.tar.gz src-28d08dc7d051a4e058cc0004cf4dd884f87037a2.zip |
clock_gettime: Fix CLOCK_THREAD_CPUTIME_ID race
Use a spinlock section instead of a critical section to synchronize with
statclock(). Otherwise the CLOCK_THREAD_CPUTIME_ID clock can appear to
go backwards.
PR: 262273
Reviewed by: markj
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D34568
-rw-r--r-- | sys/kern/kern_time.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c index 74e7c42004ad..0bab05c65ffc 100644 --- a/sys/kern/kern_time.c +++ b/sys/kern/kern_time.c @@ -256,11 +256,11 @@ kern_thread_cputime(struct thread *targettd, struct timespec *ats) uint64_t runtime, curtime, switchtime; if (targettd == NULL) { /* current thread */ - critical_enter(); + spinlock_enter(); switchtime = PCPU_GET(switchtime); curtime = cpu_ticks(); runtime = curthread->td_runtime; - critical_exit(); + spinlock_exit(); runtime += curtime - switchtime; } else { PROC_LOCK_ASSERT(targettd->td_proc, MA_OWNED); |