From nobody Thu Mar 17 19:40:14 2022 X-Original-To: dev-commits-src-all@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 DC61F1A26861; Thu, 17 Mar 2022 19:40:15 +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 4KKHYC031Sz3GkX; Thu, 17 Mar 2022 19:40:14 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1647546015; 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=woHFV7YXVTGu+Jp4clV5vShpcePDuG/cb0ievYPS/9Y=; b=nzzWcLtHVyAddI2z3lEhPx8E7NUHFa8hcw53P3vNH301VZspFCNzk7fJLJYT4waFooAJYW HeRHdDt3hXBLZ3s0rbQUSlFQmwzze5kLSqMczav9UO4yefIugUBNL43FWgfH5KfNv50lM7 aAy92T0Z62tRbI82gclVjCvIdixgzEwZERl0DNfpBIR0WFfCDLu6NClP3f7s3HdbUwws2h WBodLIRWG9tx0ljWoKeRd8BJDAL+3ph8OWKhWg1s76aMVCzHfAJ39mf015Yxo7g4FiXCtN Dchk7dBwGwNdPUn836iwkLPNj1U3rbjfPoxJ187r8aMBoXN8ZTPiDYpf99KM7A== 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 AF37010D9B; Thu, 17 Mar 2022 19:40:14 +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 22HJeEUw067333; Thu, 17 Mar 2022 19:40:14 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 22HJeE3d067329; Thu, 17 Mar 2022 19:40:14 GMT (envelope-from git) Date: Thu, 17 Mar 2022 19:40:14 GMT Message-Id: <202203171940.22HJeE3d067329@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 28d08dc7d051 - main - clock_gettime: Fix CLOCK_THREAD_CPUTIME_ID race List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/main X-Git-Reftype: branch X-Git-Commit: 28d08dc7d051a4e058cc0004cf4dd884f87037a2 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1647546015; 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=woHFV7YXVTGu+Jp4clV5vShpcePDuG/cb0ievYPS/9Y=; b=ldB6Wq5Y+NXd+5l4T2d7lQciJKbISLYDHVqBOSYsMuW/pVsZXDjCseHaOa86YWmpNs/cc+ wDsdJY61vo0xAlO4iG09DvxSvcN+YQYuv/43Dap0qJTGqDzgZo6PgkyaePQ8OexcO4ComH MIFf+84KbholNG8UYzfa2+GZ/FyW4V9famHJrC2tpy9c6BhIrmrPglMfMNSqfB9t/3a3mn TFhq6S+VBEnyLCFC5lR5dU81P6pe2+POo+iZ/OQmgZD34jK9V9eOKfivsHk8xo4HyKgqKj w4AW2THrL3YtahowluPPa7RMDpo/PhqYWO1tsYglEbi2TtFJh760ecupcb+cTA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1647546015; a=rsa-sha256; cv=none; b=aNmmrcnO24Vh7O76AfZ3iEHltJeJ0OH+cs9ETYOVFXE3BWpPDl38GFOkC4HVhcKYKOx+8D T9rDNqQoDfUyT3yP6x7EG3QESMGEjR2eX+Sq2IT0C+/M6b5WoZ+dWbQuSUGt3KZjZ04TkV l+jvMPvgkCo1d5yd+W0d3/uozIVWm3pgmZHk/amxlIKyxhxEEdet19d1VzNYXZ6fWMxnot eq0NLODMXF9ILWnl4wcpgWxpNEWPYBEoTT0ChXn7JNQlZZ/HvNEDWKAk0ehOc69AIYTfSB p/wjZsbGHZLLarhTZI6AfHDg2r8BtLUhQJi89pXa2kv62MhJhifRWjm/VOAiuw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=28d08dc7d051a4e058cc0004cf4dd884f87037a2 commit 28d08dc7d051a4e058cc0004cf4dd884f87037a2 Author: firk AuthorDate: 2022-03-15 22:22:21 +0000 Commit: Mark Johnston CommitDate: 2022-03-17 19:39:00 +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 MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D34568 --- 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);