From patchwork Fri Dec 15 16:55:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 18142 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp9418959dys; Fri, 15 Dec 2023 08:56:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IEfxQcCYHoNJOMelbYx69ZADFN1MNdx2pj0ofITJjCL2ywoEL6yWCjg7oKNlkop4PqhTE2F X-Received: by 2002:a05:6870:769d:b0:203:8511:d6b2 with SMTP id dx29-20020a056870769d00b002038511d6b2mr110842oab.109.1702659374204; Fri, 15 Dec 2023 08:56:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702659374; cv=none; d=google.com; s=arc-20160816; b=Z3EFwGiWfQe+46Timh2/XKP5iuyjtGbsXNXRWXLQ9W41qt5hmVjgbUBnd1MzzaIHxE Nrbr9BQQ1+kLeuvWRp2bssVR5pm96LdEwHqBh9weqZNp+PkzQ+5Z+8Ik5tscOsf2xT7t vVKue0gUcP6zI+giHeJn1hc6Ub7KPVh5KgsbDrRPF0pLbh+q3aBMmkbWXvhbiBMruXnf Ly0PVtBSUCLtxcUz1QZEVT25IOAT8l8QtMPCQ8iQdpnGlnd1AyrqdMZ6Gn0FM3CLKeWz wRsRE0ED4uYpowBgrZm1FtylxSBVYsm7Xo36rC4WfDkIsg6bmXZZa6en6zX3bCTkTQKW E/vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:subject:cc:to :from:date:user-agent:message-id; bh=tNamgUj0tU/FiuYDgMSDWHUDJiFo/jIIcOy8ONt6yi4=; fh=OI3eEy+AY0NH1j9zmiflrKRH8gD0OkiwAkNJqVJ3iV0=; b=EV6jsXESI1Gdo9pHVlPADChNWaiB/4bLiOh4D8HrkBobiTRUu/aGMcre6ih/nwo8b/ Z0pDzWyeMu9xQoh4n5eohleNelU8twnQ8fo3iFKgm58EV1WSFyK81pJTOQldykpXP6mm pgKnbvkSXEMTcsqbGhwJfArdVvnOjxoh9EBZPuDSnia6MjFmt9oSNoQzoOefnrwKTOsa NLCKiJzKGL1elEuyrc8005nIQBajT0CChqdRYiL27eEUwg5knfnAdkgrz7jYNw0RYfUQ iM7R/ntSDj0VkxyY8wug5i+28IaHrhAYHuucw0KmJ79nR5DODuWVoRyofe5wuH27JBNy Z/SQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-1338-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1338-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id bx2-20020a056a02050200b005a9fde46fa0si13570078pgb.130.2023.12.15.08.56.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 08:56:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-1338-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-1338-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1338-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id E62022855FA for ; Fri, 15 Dec 2023 16:56:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B42BE4174B; Fri, 15 Dec 2023 16:55:40 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C5A2E3FB0B; Fri, 15 Dec 2023 16:55:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 56D52C433C8; Fri, 15 Dec 2023 16:55:38 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rEBUC-00000002vv7-011l; Fri, 15 Dec 2023 11:56:28 -0500 Message-ID: <20231215165512.280088765@goodmis.org> User-Agent: quilt/0.67 Date: Fri, 15 Dec 2023 11:55:12 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Linus Torvalds Subject: [PATCH 0/2] tracing: Replace final 64-bit cmpxchg with compare and update if available Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785367756029495845 X-GMAIL-MSGID: 1785367756029495845 With the introduction of a389d86f7fd09 ("ring-buffer: Have nested events still record running time stamp"), the timestamps required needing 64-bit cmpxchg. As some architectures do no even have a 64-bit cmpxchg, the code for 32-bit architectures used 3 32-bit words that represented the 64-bit timestamp and this also required performing 3 32-bit cmpxchg where a single 64-bit would do. While debugging the ring-buffer, it was found that the locations of 3 of the 4 cmpxchg() were actually causing bugs, and the code was restructured to remove them! See: https://lore.kernel.org/linux-trace-kernel/20231211114420.36dde01b@gandalf.local.home https://lore.kernel.org/linux-trace-kernel/20231214222921.193037a7@gandalf.local.home https://lore.kernel.org/linux-trace-kernel/20231215081810.1f4f38fe@rorschach.local.home The only remaining cmpcxhg() is in a slow path that gets hit if an interrupt were to come in during the allocation of an event and itself would right an event to the same buffer. The interrupted event would detect this, and use the cmpxchg for two purposes. One was to know if the interrupt happened before it allocated its space (where it can use the timestamp that was found), and the other is to set the write_stamp back to matching the before_stamp, where the event after the interrupted event would not need to add an absolute timestamp (it's 8 bytes added to the ring buffer). The first purpose of the cmpxchg could also be done with a simple compare. The second purpose (avoiding the addition of the absolute timestamp) requires the cmpxchg. Considering the complexity of the 32-bit version of the 64-bit cmpxchg, avoiding an added absolute timestamp doesn't justify it. The first patch replaces the last 64-bit cmpxchg() with a rb_time_cmp_and_update() that will return true if the timestamp matches the expected result. It will optionally update the timestamp with the "set" parameter if cmpxchg is available. The second patch removes the 32-bit version of the 64-bit cmpxchg and simply does the compare. This also removes the complex logic of that code. The difference now is that 32-bit architectures will have to add an absolute timestamp to an event that follows an event that suffered the race condition. Steven Rostedt (Google) (2): ring-buffer: Replace rb_time_cmpxchg() with rb_time_cmp_and_update() ring-buffer: Remove 32bit timestamp logic ---- kernel/trace/ring_buffer.c | 247 +++++++-------------------------------------- 1 file changed, 36 insertions(+), 211 deletions(-)