From patchwork Mon Dec 11 16:59:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 176808 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7193851vqy; Mon, 11 Dec 2023 08:59:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IFjJ64MyqLXpxGohjEJLWZ8XVJmdY8yDjsvbLCUMIVCxpQIU51wC46pEpil26WCIkU7B/2o X-Received: by 2002:a05:6a20:72a2:b0:18b:acc8:a5ed with SMTP id o34-20020a056a2072a200b0018bacc8a5edmr7219007pzk.8.1702313958075; Mon, 11 Dec 2023 08:59:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702313958; cv=none; d=google.com; s=arc-20160816; b=VJSy30H8bM2fcBOfW12JSUwMNTkBQfie1wymoP+3sAO0Nj0drjBrnLJLtCS2LnopaW oGBqyTroum4QIiBR6RZD/VASG6JlCdvg9zd1A1jHRrQnNWwEqdeHA3M1DL4QJqj6e3KQ R0IpzdpoUNhJCdmV9L6HbB/o3HMKj6y9iolWlEsoafWEd1/E9tvBMAoQAjG5Dqee0KmB 7oBlfimeDBqjA3MS/mcfo+FpbDfr8z1H8LNjx5K8nKKF2tTsC1jeLT8yujcqiw192TKX /NeEXAQ+jrhOXn/k1d+VePY8MuCRTPROys9MCQ0nxiA5nn7V1Ra5bCrxQCFyy49KYkAR EVpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:subject:cc:to:from:date; bh=rK9dw6vqS6MnNSTs/jt6CEi81K0ExEQ6AOko+DMs5Og=; fh=R8JZsVKDlS7lXIAvTNV55bsjlDBI0i4sqiOYXO4tZQA=; b=Qqht1WHoDSo15McvNBj4zusZqiQMX0F6xMxXvtpeNoeQfmQSHWVlMLOKYMtCkXF0Cl 0//3XegoqILWMLLptsNx80Uy3v7yp+B8dioQcuUUcS2yrQj2j2T7IPEYnmWtk5yZCgKA 807OlSX68uIhCJRODTGKKpBnQkP5XuhJUmJMVQ7FHw5YoCycnI5MoGOc0lRVmxjdk4TW W1kxAFAQX6aSKugDP9BaRz//C795NcbONq4oS6/S3Vh/UKDIzd92DR+zhvlwXge+fA6d UpXGF5C7ytRRWVPf+oOSKAVDuvVGFl4JbYQ/UpmKpb0cWVXSRyJqsjHpu3EEQftI7Y+p WTlg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id u8-20020a63df08000000b00585a5e9a965si6399985pgg.161.2023.12.11.08.59.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 08:59:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 701A08041EDC; Mon, 11 Dec 2023 08:59:13 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344041AbjLKQ7F (ORCPT + 99 others); Mon, 11 Dec 2023 11:59:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229587AbjLKQ7E (ORCPT ); Mon, 11 Dec 2023 11:59:04 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8EF18E for ; Mon, 11 Dec 2023 08:59:10 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A0FE0C433C7; Mon, 11 Dec 2023 16:59:09 +0000 (UTC) Date: Mon, 11 Dec 2023 11:59:49 -0500 From: Steven Rostedt To: LKML , Linux Trace Kernel Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers Subject: [PATCH] ring-buffer: Never use absolute timestamp for start event Message-ID: <20231211115949.4692e429@gandalf.local.home> X-Mailer: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Mon, 11 Dec 2023 08:59:13 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785005561227642488 X-GMAIL-MSGID: 1785005561227642488 From: "Steven Rostedt (Google)" On 32bit machines, the 64 bit timestamps are broken up into 32 bit words to keep from using local64_cmpxchg(), as that is very expensive on 32 bit architectures. On 32 bit architectures, reading these timestamps can happen in a middle of an update. In this case, the read returns "false", telling the caller that the timestamp is in the middle of an update, and it needs to assume it is corrupted. The code then accommodates this. When first reserving space on the ring buffer, a "before_stamp" and "write_stamp" are read. If they do not match, or if either is in the process of being updated (false was returned from the read), an absolute timestamp is added and the delta is not used, as that requires reading theses timestamps without being corrupted. The one case that this does not matter is if the event is the first event on the sub-buffer, in which case, the event uses the sub-buffer's timestamp and doesn't need the other stamps for calculating them. After some work to consolidate the code, if the before or write stamps are in the process of updating, an absolute timestamp will be added regardless if the event is the first event on the sub-buffer. This is wrong as it should not care about the success of these reads if it is the first event on the sub-buffer. Fix up the parenthesis so that even if the timestamps are corrupted, if the event is the first event on the sub-buffer (w == 0) it still does not force an absolute timestamp. Cc: stable@vger.kernel.org Fixes: 58fbc3c63275c ("ring-buffer: Consolidate add_timestamp to remove some branches") Signed-off-by: Steven Rostedt (Google) --- kernel/trace/ring_buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index 02bc9986fe0d..bc70cb9bbdb7 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -3584,7 +3584,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer, * absolute timestamp. * Don't bother if this is the start of a new page (w == 0). */ - if (unlikely(!a_ok || !b_ok || (info->before != info->after && w))) { + if (unlikely((!a_ok || !b_ok || info->before != info->after) && w)) { info->add_timestamp |= RB_ADD_STAMP_FORCE | RB_ADD_STAMP_EXTEND; info->length += RB_LEN_TIME_EXTEND; } else {