Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 24 Mar 2022 15:23:25 GMT
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: e7867aaa35d0 - stable/13 - clock_gettime: Fix CLOCK_THREAD_CPUTIME_ID race
Message-ID:  <202203241523.22OFNPbd008624@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=e7867aaa35d0970baa33c2aaa959829d84034558

commit e7867aaa35d0970baa33c2aaa959829d84034558
Author:     firk <firk@cantconnect.ru>
AuthorDate: 2022-03-15 22:22:21 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2022-03-24 14:28:27 +0000

    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
    
    (cherry picked from commit 28d08dc7d051a4e058cc0004cf4dd884f87037a2)
---
 sys/kern/kern_time.c | 4 ++--
 1 file 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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202203241523.22OFNPbd008624>