From nobody Thu Mar 24 15:23:25 2022 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id A77E81A3B6C2; Thu, 24 Mar 2022 15:23:25 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4KPTWd3377z4Yg1; Thu, 24 Mar 2022 15:23:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648135405; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=3ufDYXGUCxaipIuOs9Mb6Zhq+MlHOdiLVFY7bEhnBfI=; b=IMivGTFvtWILpZdSRkgpV2Lk1UwLb/qCJMuu9pA+GHnMKfvP1HuEB7Y03wZGqMRFMRhzIq fONRhEyBvuJ7uqWAMNPf3Jhdru2Q4nSCveqAodPn+y2W2sZdKjz0FOmuY2bxUkhAKh16cx 0V7L1O1gju8LCwOSDQrhra51nalfNNQZc+LHZE9nsT+KHYflN2mjl5eFyKTWhH4iyuATNe IpJFPs2fIoQoYYlRN6KtVEjn/fe81/Yu9LUfEjjAfkxfJtYO8aJ4EHj/Op+qFoq+bPSC1L A9W5BCAjY39PfIi6aCVkYzUDoAR282WvU7vKyHQ1HO6+apLSrWKu/x/qFcPnQQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 454221A891; Thu, 24 Mar 2022 15:23:25 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 22OFNPEK008625; Thu, 24 Mar 2022 15:23:25 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 22OFNPbd008624; Thu, 24 Mar 2022 15:23:25 GMT (envelope-from git) Date: Thu, 24 Mar 2022 15:23:25 GMT Message-Id: <202203241523.22OFNPbd008624@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: e7867aaa35d0 - stable/13 - clock_gettime: Fix CLOCK_THREAD_CPUTIME_ID race List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: e7867aaa35d0970baa33c2aaa959829d84034558 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648135405; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=3ufDYXGUCxaipIuOs9Mb6Zhq+MlHOdiLVFY7bEhnBfI=; b=wXHxbTM0jDGkcG066OGTkpA0l+ORAE1HLu+52DRoUgQcWVzTunP1EKDrWj0G8VAt8egWbQ 8FXY4ZZ4tr+5oI4bKpk7gFf/pF/dbdmMZ+dZKfJRsL4n4yPznWk+s3OJ1NJqs9UttQTEVi /5YgkNW3NWOC/8r57sE/tLqo1wnXK1hx4jwNkQUhst+pSot7RZ5iU7Mtf60rbURKRk4xJ7 44gBEgUe9SgTQKX5TAHwRyUD/zolv3CfSDKyKVGDRyrNPYiaYhTi75j3ccNjBb+FukvdSt 0bvUaB3eLfDqXWmEg4nebcNO2lwf/L4aDbWYjpqghn2qAj1Kt/aTSchPpCOAcw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1648135405; a=rsa-sha256; cv=none; b=t4dmsNIuRiaJmpL9c8QQyDFPegBaAcBrlJkVy0FbrU89BGJNmZt+pal68lgVHEMHzxYMkv vA8FHybH+5tT2ZiXy+cwqXuaEHZFgqtEXVo3YgCxT+Lf1g7honhwIKTWqdFANGTkrxySi3 elgC25OJ/Z5br5yqLewjIVfG8RFj39pS1fDjZwuydeDCqddU+2XfAdvVJB+F2IYq4Ritxk zOeesHd73MVcpvNw9VifNhwFnxN/j/tGp40aIUXQK7Xl3Lo3/rdjjP/EUFX5wV8gHu0s25 VRZBKt1SZz4DFLBlFswCm/oc74Mdm1btGvG8QPHmqPLM31ENQvUadxSMsZuLhQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=e7867aaa35d0970baa33c2aaa959829d84034558 commit e7867aaa35d0970baa33c2aaa959829d84034558 Author: firk AuthorDate: 2022-03-15 22:22:21 +0000 Commit: Mark Johnston 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);