From nobody Mon Aug 19 11:03:29 2024 X-Original-To: dev-commits-src-main@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 4WnV813zsTz5Sp3n; Mon, 19 Aug 2024 11:03:29 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WnV811d17z4SGJ; Mon, 19 Aug 2024 11:03:29 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1724065409; 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=jQ0dvsMgLj7PwRKrpc8qJbG0/fWN85A+XLYP2OroQ+w=; b=jAAzp6zfTkJ54ouwiviTTuGDKgXALscuiR6LMcESoRq70Wom9SKiWid+go51JIsUw0qSEL qzd2ACSkTkK2YVXPzl8VZfUs7fKzL7FbmiIhgLrw+gjLhOw8x/qIGFDctlakWpTcV90L27 XNjBxnw8JPwUyCtxzIjZ8JCbpycbHymzvGclRCBLAXVkP5belKbKUufowKcbwbRomYYr42 auRrcKhK+cRToBPsigq26NjYdPQUzIOtYiJ5v7poAoYn5FWDoSn9Sf6GMuzsGR8kGtMF2f tP4BLBhfmEoS7cgjPf1qgUCtaCNFtGOcOgYyo0J6QUxrbZmW4hrd+PH8POwQOQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1724065409; a=rsa-sha256; cv=none; b=C9YvcEjh7ZjQPAxNNEdXN+Bo6hCQB9TXUGtrZ6w0+PinEPTY5qK9vyqeS5T7R50/VjoPQe 5AaB2vXYvi+yKbEAk3oXczxzHIBDBRSU3ceBdV/X4iSEwkwE2YHr36h06JflyZTfPN5thG HTp8QqK/tYD2NP8pwct7zTtGco+VY5mA2kVMl3FjPPaU3AmuYoy8eNgMDs9VPjYNtAOud1 HXGo+oITBg/u1DHaiDfgPb+WL7JuNwda/dQC8nFLxRaj+SA2CE5yx2P6hVoI8WUMY4VLSj FLiqR3WcEhx7z5U6Kco7DAQCCPPk8UlLiTJ8gFFPJRf0rdZCg/cHqHU/TDwMIg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1724065409; 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=jQ0dvsMgLj7PwRKrpc8qJbG0/fWN85A+XLYP2OroQ+w=; b=BZvH0tBrQ8Mtqgt6efGjzRCUbNPEueGXrN3uM6AtFXcX1rYLDM9df8GOCITRypHv70arcu ZNd71EvgHEMAgtbgkDgWsjjk+DbZVX8fiSUcRk3Tx12Yz/9wvOoQjc6+Tt+FdeqxU+J+we 6IXMAIBj0MP9UJFNhYQPlkGFX8FTQIBsS7LG1OQG7o1taXQzxX3HeEVIhZzEzb7iQcyBFl TCQzSv2Yuj9ofx1L4NnbwEqtMBLpuQKkPUCMhC1CEBkAumVcyEZei6+gehycg3VE4lqIl9 GnOxcm0p57Is1ovwgTu2lc0+54sgh1YUPWYxWihoKcDHjfcW2kYCT/+EU9CAJw== 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 4WnV811F1BzF9n; Mon, 19 Aug 2024 11:03:29 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 47JB3TsF037635; Mon, 19 Aug 2024 11:03:29 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 47JB3T2R037632; Mon, 19 Aug 2024 11:03:29 GMT (envelope-from git) Date: Mon, 19 Aug 2024 11:03:29 GMT Message-Id: <202408191103.47JB3T2R037632@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Andrew Turner Subject: git: 44e1cfca417c - main - buf_ring: Use atomic operations with br_cons_tail List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: andrew X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 44e1cfca417c5ef0db908f3836ec3ba704ef1de2 Auto-Submitted: auto-generated The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=44e1cfca417c5ef0db908f3836ec3ba704ef1de2 commit 44e1cfca417c5ef0db908f3836ec3ba704ef1de2 Author: Andrew Turner AuthorDate: 2024-08-19 09:06:52 +0000 Commit: Andrew Turner CommitDate: 2024-08-19 10:53:11 +0000 buf_ring: Use atomic operations with br_cons_tail Use an atomic operation with a memory barrier loading br_cons_tail from the producer thread and storing to it in the consumer thread. On dequeue we need to read the pointer value from the buf_ring before moving the consumer tail as that indicates the entry is available to be used. The store release atomic operation guarantees this. In the enqueueing thread we then need to use a load acquire atomic operation to ensure writing to this entry can only happen after the tail has been read and checked. Reported by: Ali Saidi Co-developed by: Ali Saidi Reviewed by: markj Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D46152 --- sys/sys/buf_ring.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sys/sys/buf_ring.h b/sys/sys/buf_ring.h index dec0f971ae44..9aeb5aa19fa8 100644 --- a/sys/sys/buf_ring.h +++ b/sys/sys/buf_ring.h @@ -91,7 +91,7 @@ buf_ring_enqueue(struct buf_ring *br, void *buf) do { prod_head = br->br_prod_head; prod_next = prod_head + 1; - cons_tail = br->br_cons_tail; + cons_tail = atomic_load_acq_32(&br->br_cons_tail); if ((int32_t)(cons_tail + br->br_prod_size - prod_next) < 1) { rmb(); @@ -229,7 +229,7 @@ buf_ring_dequeue_sc(struct buf_ring *br) panic("inconsistent list cons_tail=%d cons_head=%d", br->br_cons_tail, cons_head); #endif - br->br_cons_tail = cons_next; + atomic_store_rel_32(&br->br_cons_tail, cons_next); return (buf); } @@ -257,7 +257,7 @@ buf_ring_advance_sc(struct buf_ring *br) #ifdef DEBUG_BUFRING br->br_ring[cons_head & mask] = NULL; #endif - br->br_cons_tail = cons_next; + atomic_store_rel_32(&br->br_cons_tail, cons_next); } /*