From patchwork Mon Dec 11 16:44:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 176805 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7185316vqy; Mon, 11 Dec 2023 08:43:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IG9ObJ+RcDSteByP/11+xmj+GFDXVb+hWr5SIqRmNuAGUJEXZ3H6oq9JC5GA7+0rVFjZPwd X-Received: by 2002:a17:90b:b93:b0:286:9e2f:475c with SMTP id bd19-20020a17090b0b9300b002869e2f475cmr3602293pjb.47.1702313029110; Mon, 11 Dec 2023 08:43:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702313029; cv=none; d=google.com; s=arc-20160816; b=lT0jA/igOgbsx5erczseR6ZpyPDjmM4hPQySsx6M/rKeoMVwDJxYPF7XpcmF7FOICg hwukZTPw1keki9Z9M4tLzqyGh6nbOXibCoytyEaG2eI/LHLobcXtjcq0U50m0f9rIVTT 04o/WV4iDt1QP9b4Yt6RtyEKEbqFTsuQgWrkazcVd3UERCKEYUFrTL4pGn0E1cDccLLK oKf9Db3Kx1A2gTu4afH4PNHvYstY3R2vXGXxt1P72MD6jbKpPgTNQd+Pd3nctfSkOaEW uotGvQ97vUlynXjOh0/6LjVnzCqnrmdecPC+4VZPsibKFk4fNBFr0epNWAvEk3ykOUG0 SriA== 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=XAJF/R7ofygE8GIO5FB1IOXJSdGBnbQGl9MPcEo3/rM=; fh=R8JZsVKDlS7lXIAvTNV55bsjlDBI0i4sqiOYXO4tZQA=; b=WHprMc08jl7Tt7KqTrkcUAAxg6EB9zsNWwVDH53F4aeGKvfSUX2/pbQGGAzXNtqUkV jnRs0GBrY55tppad7/PeSTa2I9mvIQNnREeIoNP8kIFQGhKK72kZD7MGrGYYV4RmzCL0 mV5KGoL+Re5Z4X54qUg2nghqjZJBRpD4fAaw2E1o6ylOgxxuBbWFsAcYt/9XOJJqPaWT bTzxAtaZQWaPMiO4MdLRJoBnDWxjSH038/P67B0liHDpZIuEHljfz/zebRG4A6shRMb8 8ykJ3KlUCmxjZ6tO6qwIDBuB/Xk5B+OFW1siLK3f+mrU3zrRl4QknVKs9bpTLRFTy7OC ojBQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id z7-20020a17090abd8700b00285cc4f0e09si6412904pjr.185.2023.12.11.08.43.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 08:43:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id 66984803BF31; Mon, 11 Dec 2023 08:43:45 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344208AbjLKQnh (ORCPT + 99 others); Mon, 11 Dec 2023 11:43:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234618AbjLKQng (ORCPT ); Mon, 11 Dec 2023 11:43:36 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 510B198 for ; Mon, 11 Dec 2023 08:43:42 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4D78BC433C8; Mon, 11 Dec 2023 16:43:41 +0000 (UTC) Date: Mon, 11 Dec 2023 11:44:20 -0500 From: Steven Rostedt To: LKML , Linux Trace Kernel Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers Subject: [PATCH] ring-buffer: Do not update before stamp when switching sub-buffers Message-ID: <20231211114420.36dde01b@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 morse.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 (morse.vger.email [0.0.0.0]); Mon, 11 Dec 2023 08:43:45 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785004586340728734 X-GMAIL-MSGID: 1785004586340728734 From: "Steven Rostedt (Google)" The ring buffer timestamps are synchronized by two timestamp placeholders. One is the "before_stamp" and the other is the "write_stamp" (sometimes referred to as the "after stamp" but only in the comments. These two stamps are key to knowing how to handle nested events coming in with a lockless system. When moving across sub-buffers, the before stamp is updated but the write stamp is not. There's an effort to put back the before stamp to something that seems logical in case there's nested events. But as the current event is about to cross sub-buffers, and so will any new nested event that happens, updating the before stamp is useless, and could even introduce new race conditions. The first event on a sub-buffer simply uses the sub-buffer's timestamp and keeps a "delta" of zero. The "before_stamp" and "write_stamp" are not used in the algorithm in this case. There's no reason to try to fix the before_stamp when this happens. As a bonus, it removes a cmpxchg() when crossing sub-buffers! Cc: stable@vger.kernel.org Fixes: a389d86f7fd09 ("ring-buffer: Have nested events still record running time stamp") Signed-off-by: Steven Rostedt (Google) Reviewed-by: Masami Hiramatsu (Google) --- kernel/trace/ring_buffer.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index 2596fa7b748a..02bc9986fe0d 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -3607,14 +3607,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer, /* See if we shot pass the end of this buffer page */ if (unlikely(write > BUF_PAGE_SIZE)) { - /* before and after may now different, fix it up*/ - b_ok = rb_time_read(&cpu_buffer->before_stamp, &info->before); - a_ok = rb_time_read(&cpu_buffer->write_stamp, &info->after); - if (a_ok && b_ok && info->before != info->after) - (void)rb_time_cmpxchg(&cpu_buffer->before_stamp, - info->before, info->after); - if (a_ok && b_ok) - check_buffer(cpu_buffer, info, CHECK_FULL_PAGE); + check_buffer(cpu_buffer, info, CHECK_FULL_PAGE); return rb_move_tail(cpu_buffer, tail, info); }