Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp28388rdb; Fri, 29 Sep 2023 15:28:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHHTkvxtgR0dFMH5Gjsa8nm3Vx3bhJelCmWLNFNjc1WmAyarRF8L3+JJjhARuxoqN0CJKCu X-Received: by 2002:a17:902:cec7:b0:1bc:506a:58f2 with SMTP id d7-20020a170902cec700b001bc506a58f2mr6040005plg.46.1696026507835; Fri, 29 Sep 2023 15:28:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696026507; cv=none; d=google.com; s=arc-20160816; b=sqTIldvxv7gqL+uM38h5fxhiOjgfLzUSkR9ipn27z0qVxlu/vM5zWYJOiauQo+svRo g8lNbl5UFcX3q8mj4cYaHTtiXJ2ILLvHEH2fDzh8I/A0aNhjHqPNV33AHGE96TqPefa2 zNnDGxob4dirqmd1vxkWExeSJqZQ8dyT9A+mOqCl2f6Ghozu85n09HYn5xaFHmtqC5JF I/PQCYCnnKtYGrHkGECcpKzgV4qAqZYbSB873TfJ3gduwDIOxs9A5ke9w+SM4Jo2ZDtR eRO9q8XcN9S3UVBcz8K7m7Wdd9cb8ZN01BQ8C9tL5tnt0eczcOf3djqiPBqHn4hWPzsN bYOg== 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 Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id p13-20020a170902e74d00b001c72dbaf7c3si7260923plf.240.2023.09.29.15.28.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 15:28:27 -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 64A6A8045962; Fri, 29 Sep 2023 15:01:31 -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 S233742AbjI2WBW (ORCPT + 99 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 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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:31 -0700 (PDT) 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) --- 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; -- 2.40.1