From patchwork Fri Sep 29 22:01:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 146803 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp74943vqb; Fri, 29 Sep 2023 15:28:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHWNPbL1Q0uDfZ1XTkw7zbCfLhp2hQJ/iV95umBYzuycH5bRD7w6+j2BTs9cnRHrX4Um6Xo X-Received: by 2002:a17:902:eb46:b0:1c4:749e:e725 with SMTP id i6-20020a170902eb4600b001c4749ee725mr5231664pli.0.1696026501241; Fri, 29 Sep 2023 15:28:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696026501; cv=none; d=google.com; s=arc-20160816; b=FlI4iOq9PFk+NFgTMhnkQ+y57RRZWpnPH7yFj/OrlPYdFkdc8FrUDEOWKOZiy4YeOz H+eLhFR4YMc6bnn6McV/UnsYzrY8/xyZDvNCcGN2o2YHN7oMC860ridI13vU1pbEy8tW mwQXj7ArCsTXNAEdA4t1/YYwTO95GQJzIwc23JgFjsjfbrecxcEUQWrhN5M5ahwFhXnp j5PgACKGDD6dbeEAj+s7Y/nJJSARwb4RenE3rCkrqmDsBmjU+zhKL2cgLkaGCcG3hP8d K7CSGjeHghMlskG2/nxdAywyagPwxyVA9WXFodieduV6v1/d0Y2EfyVB2XuthUTsMcjH nfhA== 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=6yeqXq6Jisz1doc9cw+rVu18BBKG3A2SSvRkcUGjEwE=; fh=kUV8DGrk6X6xgiBw6ycTpeDM4Frb97lANzT6t1nVsmA=; b=0aTNvn3mwe/3//bjMLUYeV8GeLgG+QzvGJ/7JNbgaLVwONH+MyvtW3dfyRVL80BSl8 KGdJ1prWlO/BD/pOPqSbZB+yjX+qKeaaJfoLEkvDS8Gqi3bpSHsc2nrasPdJadBrqxWR 4LbCnYmbkXVQ+2dwwA2o019BjLvfBUU4vPcKbrkFeF13pEHoR5vMAJknwNaJHl3t8Au8 qVDvH6GSOHXGh+T51W/v/AYke4d2886g6W9oqZRluLhlxuD/E4JMJOomvVb+9JHzDm6t vrKWpf6WgEV4vbjYh6fJ+IA1eei8o0n7xztkGqIylHuTIdz0bcK1WIy3CuynwOzRyKOP ncLg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id u16-20020a170902e81000b001b9e82a6beesi22879686plg.548.2023.09.29.15.27.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 15:28:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 4AC06828B8FD; Fri, 29 Sep 2023 15:01:45 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233791AbjI2WBW (ORCPT + 19 others); Fri, 29 Sep 2023 18:01:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232834AbjI2WBV (ORCPT ); Fri, 29 Sep 2023 18:01:21 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73697EB for ; Fri, 29 Sep 2023 15:01:19 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C1534C433C9; Fri, 29 Sep 2023 22:01:17 +0000 (UTC) Date: Fri, 29 Sep 2023 18:01:13 -0400 From: Steven Rostedt To: LKML , Linux trace kernel Cc: Masami Hiramatsu , Mark Rutland , Julia Lawall Subject: [PATCH] ring-buffer: Update "shortest_full" in polling Message-ID: <20230929180113.01c2cae3@rorschach.local.home> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Fri, 29 Sep 2023 15:01:45 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778412684598858824 X-GMAIL-MSGID: 1778412684598858824 From: "Steven Rostedt (Google)" It was discovered that the ring buffer polling was incorrectly stating that read would not block, but that's because polling did not take into account that reads will block if the "buffer-percent" was set. Instead, the ring buffer polling would say reads would not block if there was any data in the ring buffer. This was incorrect behavior from a user space point of view. This was fixed by commit 42fb0a1e84ff by having the polling code check if the ring buffer had more data than what the user specified "buffer percent" had. The problem now is that the polling code did not register itself to the writer that it wanted to wait for a specific "full" value of the ring buffer. The result was that the writer would wake the polling waiter whenever there was a new event. The polling waiter would then wake up, see that there's not enough data in the ring buffer to notify user space and then go back to sleep. The next event would wake it up again. Before the polling fix was added, the code would wake up around 100 times for a hackbench 30 benchmark. After the "fix", due to the constant waking of the writer, it would wake up over 11,0000 times! It would never leave the kernel, so the user space behavior was still "correct", but this definitely is not the desired effect. To fix this, have the polling code add what it's waiting for to the "shortest_full" variable, to tell the writer not to wake it up if the buffer is not as full as it expects to be. Note, after this fix, it appears that the waiter is now woken up around 2x the times it was before (~200). This is a tremendous improvement from the 11,000 times, but I will need to spend some time to see why polling is more aggressive in its wakeups than the read blocking code. Cc: stable@vger.kernel.org Fixes: 42fb0a1e84ff ("tracing/ring-buffer: Have polling block on watermark") Reported-by: Julia Lawall Signed-off-by: Steven Rostedt (Google) Tested-by: Julia Lawall --- kernel/trace/ring_buffer.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index 28daf0ce95c5..515cafdb18d9 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -1137,6 +1137,9 @@ __poll_t ring_buffer_poll_wait(struct trace_buffer *buffer, int cpu, if (full) { poll_wait(filp, &work->full_waiters, poll_table); work->full_waiters_pending = true; + if (!cpu_buffer->shortest_full || + cpu_buffer->shortest_full > full) + cpu_buffer->shortest_full = full; } else { poll_wait(filp, &work->waiters, poll_table); work->waiters_pending = true;