From patchwork Mon Dec 18 19:42:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 18260 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp1488060dyi; Mon, 18 Dec 2023 11:43:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IFOTzMj28gyJNsaLUbaOe5kS8i+Jp2AZfWimbSJy1JZqfr3ZPGtv6YINWxStC2gg4ByP5hJ X-Received: by 2002:a17:902:ecc4:b0:1d3:6b4b:2bc0 with SMTP id a4-20020a170902ecc400b001d36b4b2bc0mr10325724plh.117.1702928600576; Mon, 18 Dec 2023 11:43:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702928600; cv=none; d=google.com; s=arc-20160816; b=NmontZrjY8BSAEMXNzftMOjmkLaZyDbs6PDEFtYYZ9JEg7U88D/GpMpz+t7A1UXNzE aXatwoMH61eoKM61PqUyUvlEvIuZ6EUv0hr6m5bBQec8BfSYva4nWhNoMixorefbp/s4 XCQTfmahqPE4l0QTGu8gfSjTotIvHYA0e6n4CoYzxjHzV9XLBYa0hCf3aPUpvU7e5aWh ar44bAzuogn3dfo+zAlJuD+zTogcqR2+/m7L3jdTE899QOw7Vv3I4cohkvWJ9lKq+RB7 vLgkxRBdvCg/CiwSQLto1611XJeC1B0SocaDUc0evGVwGFB/uQDjNt7b9IRw/bor+0I9 jYBg== 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=egUS5GOPg6a4gB+QbqdUG70BwrRpkpyCAEqWgYqk518=; fh=OI3eEy+AY0NH1j9zmiflrKRH8gD0OkiwAkNJqVJ3iV0=; b=e7o5s0evwH0HHPly/5LCIeAroSVxC4G5dgUX6nmF4bdwDI9T+QRV0pWpPdN2U0Xlhj OM+5MGLBdI1gar4sU/HTitOaeikzRmmNITByRzHcsms+l3ZRFRd44jot+FAvYALKNWx6 9T8EhxUMwl+LuiyqjNhnVwQzZGa0uv/YBOZ+mr6ib43omhjgK4a/CGb5LIYtRpNtdmat 2cDZTRe5o2hza7TCQ5nqKrDk1Ngsf6DH+bJSRZEnFqu3297JRyGvByAujYH0GJPi9/9A ynZ3tHA8xhXTJOAkhcJk0VszlNilRn0eOHCFGXfa6ybjRAi0aIdWhXq7YZjctT+SSMB0 u4Uw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-4303-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4303-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 be4-20020a170902aa0400b001d355536380si2552867plb.175.2023.12.18.11.43.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 11:43:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-4303-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-4303-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4303-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 53DE428495C for ; Mon, 18 Dec 2023 19:43:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B6E5D73486; Mon, 18 Dec 2023 19:42:41 +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 2433B71451; Mon, 18 Dec 2023 19:42:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AC713C433C8; Mon, 18 Dec 2023 19:42:39 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rFJWZ-000000038ki-3IfJ; Mon, 18 Dec 2023 14:43:35 -0500 Message-ID: <20231218194247.018725743@goodmis.org> User-Agent: quilt/0.67 Date: Mon, 18 Dec 2023 14:42:47 -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 v2 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: 1785650060241491969 X-GMAIL-MSGID: 1785650060241491969 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. Changes since v1: https://lore.kernel.org/all/20231215165512.280088765@goodmis.org/ - Restructured the rb_time_cmpxchg() to work the same for both 64-bit and 32-bit. - Fixed reading t->time to use local64_read() and not READ_ONCE(). 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 | 262 +++++++++------------------------------------ 1 file changed, 53 insertions(+), 209 deletions(-)