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
This commit is contained in:
firk 2022-03-15 18:22:21 -04:00 committed by Mark Johnston
parent fc7e121d88
commit 28d08dc7d0

View File

@ -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);