Received: by 2002:a05:7412:f589:b0:e2:908c:2ebd with SMTP id eh9csp560777rdb; Tue, 31 Oct 2023 15:47:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFBPxG7DMf89aYDBaA/lVgtOfym0cuLUo31ijYys95vlGK1H9cjgeisJyyJHQ0OdhztxVTi X-Received: by 2002:a17:902:ce88:b0:1cc:636f:f37c with SMTP id f8-20020a170902ce8800b001cc636ff37cmr4723733plg.13.1698792470075; Tue, 31 Oct 2023 15:47:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698792470; cv=none; d=google.com; s=arc-20160816; b=bFXDYKc+/SqKOvkKDSIWNVjKFJTkziwgP5lXjWGe28cUpupMuPjhKrmGvT2wBd6fiB J99Q29H1284Ln+xlKnFVsLjo9Fk7FCtzVy33L0qveK1gC4BsewinZhsIbL0PO2mdyycc onyfYJGgFf5/JTpIEgcFzEW/jKEi8os2Rf3eW6qJkF8+1JffM49QnM4T2ODWI3AkL5gb K5V8/B9QmGggqP/OxQkCPGsadk1YCVnCjWeeE2KmxWpcU5Zg9XlC5qxvevMD10BtUdwy anZAsfZHIIkXGEAgZnQRbzHyYpIzhoKG7rUGONbQPQtOkhpRfHYt3OoOPQKyyau2Jwk1 Ioog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=ftAR+yR6Lq4fTtCedxOoQZmq6NncO+dp99FAFOOTGR0=; fh=nVbaEK/Jxe+A4TFF30wTE2uV6FOzX4RvKr8FcL2X/vw=; b=ft5R2VX6x3M9kQMyygKmlRKtnVJ/+zneTLlP76O+yexX8LEhjnnE4KoUHSfrcNiHN7 BwUsZH861WbGn6qiWKR20bpeu5FRhSSmfUKOGdtLx42e+1fCAVlo3ixs5jBPArfJVLF9 BNkH4aLBTVahr1zmkfDkcY/98wMR9/4J7dZJnwQuyiO03UZi+b3ga/rXXJD7+zvTPMVA b5wHwKmz7woOBLHfoTCJpqrl2zvz1f1UkOiiEUFM+ggDzJf80vwtJeInR+RDkAkeLrKq NtU9rKsQut4m2wfzj9hLUFTXbu5giICW1iTPpkFijxvHdqZRlmgmdpERnYCPNSQBLp6q b0XQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rNt+AXsT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id q8-20020a17090311c800b001cc18133022si1725592plh.285.2023.10.31.15.47.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 15:47:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rNt+AXsT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 1756A81121E4; Tue, 31 Oct 2023 15:47:49 -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 S1344739AbjJaWrs (ORCPT + 99 others); Tue, 31 Oct 2023 18:47:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344196AbjJaWrr (ORCPT ); Tue, 31 Oct 2023 18:47:47 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5004EB9; Tue, 31 Oct 2023 15:47:45 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E213AC433C9; Tue, 31 Oct 2023 22:47:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698792465; bh=uW1kAs4Hu3zlaOFxuayVPq7jvgYsrqUYDI9NXhfEGuo=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=rNt+AXsTxLmRoM+i2Do/iF1sAU4KhXvDy83JQ+60HSLXrKTsLJVGclCtwydrwoLyY DfJji34SEEEO7tyfNNa3nuB8tcNGcY+TOObTBeJC9uMKJnAz1UpJpf3LQDa7Vyd98E V1RakDJsQx7tEQSQNrGcn8NDvdEvDNdQHjSNkA9jhtgurHIAGOZl7D7CqTRIKUHI4h TxCvEYvOGJfWaSmHDYyeIzAGnE+KLAmHgOeKD3uTdgLkYlWtE7L4+kmYZU2QOZa0+a 3pLWlzJtDY/pV5peuW1mav85dJmDKCBGXsTNeucldgS3rsNcDXQJ1rk1kn1btavK+o XTvrMrttx5YsQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 75B1CCE0DE2; Tue, 31 Oct 2023 15:47:44 -0700 (PDT) Date: Tue, 31 Oct 2023 15:47:44 -0700 From: "Paul E. McKenney" To: Christophe JAILLET Cc: Davidlohr Bueso , Josh Triplett , Frederic Weisbecker , Neeraj Upadhyay , Joel Fernandes , Boqun Feng , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang , linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, rcu@vger.kernel.org Subject: Re: [PATCH] refscale: Optimize process_durations() Message-ID: Reply-To: paulmck@kernel.org References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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]); Tue, 31 Oct 2023 15:47:49 -0700 (PDT) On Tue, Oct 31, 2023 at 11:21:14AM -0700, Paul E. McKenney wrote: > On Mon, Oct 30, 2023 at 09:55:16AM -0700, Davidlohr Bueso wrote: > > On Sat, 28 Oct 2023, Christophe JAILLET wrote: > > > > > process_durations() is not a hot path, but there is no good reason to > > > iterate over and over the data already in 'buf'. > > > > > > Using a seq_buf saves some useless strcat() and the need of a temp buffer. > > > Data is written directly at the correct place. > > > > Makes sense. > > > > Reviewed-by: Davidlohr Bueso > > Queued and pushed, thank you all! But an allmodconfig build complains about seq_buf_putc() being undefined, that is, not exported. I suspect that other seq_buf_*() functions in this patch might also be complained about. I am dropping this for the moment. Please make it pass an allmodconfig build so that I can pull it in again. Please see below for the commit. Thanx, Paul ------------------------------------------------------------------------ commit a1ef9b4cff53c509f412c354c715449d7f2e159b Author: Christophe JAILLET Date: Sat Oct 28 19:04:44 2023 +0200 refscale: Optimize process_durations() The process_durations() function is not on a hot path, but there is still no good reason to iterate over and over the data already in 'buf', but this is exactly what the current use of strlen() and strcat() do. Using a seq_buf saves some useless strcat() and the need of a temp buffer. Data is written directly at the correct place. Signed-off-by: Christophe JAILLET Reviewed-by: Steven Rostedt (Google) Reviewed-by: Davidlohr Bueso Signed-off-by: Paul E. McKenney diff --git a/kernel/rcu/refscale.c b/kernel/rcu/refscale.c index 2c2648a3ad30..861485d865ec 100644 --- a/kernel/rcu/refscale.c +++ b/kernel/rcu/refscale.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -890,31 +891,36 @@ static u64 process_durations(int n) { int i; struct reader_task *rt; - char buf1[64]; + struct seq_buf s; char *buf; u64 sum = 0; buf = kmalloc(800 + 64, GFP_KERNEL); if (!buf) return 0; - buf[0] = 0; + + seq_buf_init(&s, buf, 800 + 64); + sprintf(buf, "Experiment #%d (Format: :)", exp_idx); for (i = 0; i < n && !torture_must_stop(); i++) { rt = &(reader_tasks[i]); - sprintf(buf1, "%d: %llu\t", i, rt->last_duration_ns); if (i % 5 == 0) - strcat(buf, "\n"); - if (strlen(buf) >= 800) { + seq_buf_putc(&s, '\n'); + + if (seq_buf_used(&s) >= 800) { + seq_buf_terminate(&s); pr_alert("%s", buf); - buf[0] = 0; + seq_buf_clear(&s); } - strcat(buf, buf1); + + seq_buf_printf(&s, "%d: %llu\t", i, rt->last_duration_ns); sum += rt->last_duration_ns; } + seq_buf_terminate(&s); pr_alert("%s\n", buf); kfree(buf);