From patchwork Tue Dec 12 12:18:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 177291 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7680596vqy; Tue, 12 Dec 2023 04:18:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IEujIyTkJUYhya/sr/BSviJ0FirF4757DWLRrsqn21AtzS4R3mey4aLOmWOP+jn33jbj8el X-Received: by 2002:a05:6a00:b8e:b0:6ce:751c:c943 with SMTP id g14-20020a056a000b8e00b006ce751cc943mr2894862pfj.7.1702383487380; Tue, 12 Dec 2023 04:18:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702383487; cv=none; d=google.com; s=arc-20160816; b=Z24ZULjDSEniUB0gxUQ0R4sEHh8MvACoMxEYhdhe1QffxTmbdK/WBmk7J8GoFqdmhD kbL8Qb2Dz3xqYOx1C0V7wJ2v7tuzWhZwEWGOXUqQurdsAwCuZF1viYAbCB/pzFDu1tpG N9nYJwUkySbuxWU3wAsIRvchjB01+cpBZdw6xCn+YzK9z5JrS2GAIODe01UlvNrB7C+k 9pkgr6V3wtZ40aDAcBfTgiaXwxO2fGKVZmUKHrGFojSdWhkQjb+3jf1jJQ1HCXUJd5Kq D8dLcujUh2Af5jgir2wIgjs8C9YK4Zmyqk/h7BgseDPua/qW0A2Lv9nxSyUpnCECoX9a LHIQ== 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=lij93HwKo3ABwQ5d0M0Ekw/af7XHs2fOgtsrEGiwsAI=; fh=R8JZsVKDlS7lXIAvTNV55bsjlDBI0i4sqiOYXO4tZQA=; b=bcCDTW63P8q/DUkrMCV70WHMrwzYr3GKckgOrvzn8I3YaUSUOmh4zYPQKtw/vUSK9L BUl7uiqNj+q7B2v01PUKTCRSv087mkIrNFTIXn8blYYDnybbLZRHx4zQ8bbPPp8bvr9p gQHhfNgTaMyV8l79PcJLLdOezX7lJPw9VTcWDMBNgkOS5/N0POwlVxLu9tUhE9uXCZCS 9MUNZkEPrlSdjROmaNvUizslSCT4e71HS+4xnOW5AaTz87kudkwiyCGVtLDch0tqAzWe sXGpETQjcJCfvR72lD+33OX7DmsxYWAWOzsKvhIrJ22avW756Ksds32yo7+8gw1XC1Jc yc8g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id e8-20020a056a001a8800b006ceb40f5acesi7788679pfv.334.2023.12.12.04.18.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 04:18:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id 6933F80532D5; Tue, 12 Dec 2023 04:18:03 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232372AbjLLMRx (ORCPT + 99 others); Tue, 12 Dec 2023 07:17:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346464AbjLLMRu (ORCPT ); Tue, 12 Dec 2023 07:17:50 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FB3AD5 for ; Tue, 12 Dec 2023 04:17:57 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1C084C433B7; Tue, 12 Dec 2023 12:17:56 +0000 (UTC) Date: Tue, 12 Dec 2023 07:18:37 -0500 From: Steven Rostedt To: LKML , Linux Trace Kernel Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers Subject: [PATCH v2] ring-buffer: Never use absolute timestamp for first event Message-ID: <20231212071837.5fdd6c13@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 agentk.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 (agentk.vger.email [0.0.0.0]); Tue, 12 Dec 2023 04:18:03 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785078467683864543 X-GMAIL-MSGID: 1785078467683864543 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. It's actually likely that w is not zero, but move it out of the unlikeyl() and test it first. It should be in hot cache anyway, and there's no reason to do the rest of the test for the first event on the sub-buffer. And this prevents having to test all the 'or' statements in that case. Cc: stable@vger.kernel.org Fixes: 58fbc3c63275c ("ring-buffer: Consolidate add_timestamp to remove some branches") Signed-off-by: Steven Rostedt (Google) --- Changes since v2: https://lore.kernel.org/linux-trace-kernel/20231211115949.4692e429@gandalf.local.home - Move the test to 'w' out of the unlikely and do it first. It's already in hot cache, and the rest of test shouldn't be done if 'w' is zero. 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 b416bdf6c44a..095b86081ea8 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -3581,7 +3581,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 (w && unlikely(!a_ok || !b_ok || info->before != info->after)) { info->add_timestamp |= RB_ADD_STAMP_FORCE | RB_ADD_STAMP_EXTEND; info->length += RB_LEN_TIME_EXTEND; } else {