Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp1952955rdh; Sat, 28 Oct 2023 14:31:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH1xUr2/OrnJVtAg6pGVtFcNSaToYptYGTfPpavvJdJjnUNVNmF98g+iJzJlr/0DfVu1NW0 X-Received: by 2002:a05:6a20:7d84:b0:158:17e6:7a6 with SMTP id v4-20020a056a207d8400b0015817e607a6mr9796009pzj.42.1698528685932; Sat, 28 Oct 2023 14:31:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698528685; cv=none; d=google.com; s=arc-20160816; b=CBbJhrxgu/vO8kUk71XIhRi92cn1NwQ3hDNbdQ6KyJMSFFmwNIOLn9R35mIbpKPLf5 ErUiyKuc1LGK1HiiZVvfHr5HRjbEZ/VCDQOKqd77qwAt11zj1o01U3Ug5tPDH7MIzyqB vP77XeqxbkdHPT9vU5IibaDRZZeYr9m3jfTPKU00PQq7TbiRd4FacDBd/24DeMnAgwBi dYjfDhzuPVk5m/NQwroeQNZkso450DU8IR7NJ2phtOIzksWw+t+PKCY+HYaQpMg5DRzo TITDvzC/z7ZYQOPq/lw18N5zPtyUD0P2c7fJofvKIzf3d0beaK3GEP4w3PY9qVp3vqXM 40Lw== 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 :references:in-reply-to:message-id:subject:cc:to:from:date; bh=wdCOTHI2DyJ0Y6suqYetyVKutc/LgEnAuKjoa/REmVc=; fh=z/iJs/XJkOmCitOxlKR1F5wMnBWgL3bRDhbW4cpCsKg=; b=hJKDMO7YEWC22U53I+COBbntN9GDEMmJVu+btkHUHKksFcnp6SgL0dvq4RHzi6/pfS pujokFPgrKJYPI/OYRxd97llPGM9NGiDzp7o/B2yXDQCAHDF3RNBPH8GTMdgO0JnpUJ4 dybsydIwMIj3WZ9arIa7i1v4TOdOO3Do2flKBojd9K05XuvoowHNOgYXvvogVjjVCPDD euq5NffkJAderqfJQJLcYpdfymD+ocuNHFWShdzlW+VUlWFyzGVFoUzfkxHs0okjZNih 6J+TLQfW7c0UaQ5j6M9J2HG0j43GOzywhxwYZnZ9plblE5bgjb7b2azaXepuRhZp2O/2 wBVg== 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:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id ca22-20020a056a02069600b005b8f446408dsi2875012pgb.449.2023.10.28.14.31.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Oct 2023 14:31:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id 644FC807C84F; Sat, 28 Oct 2023 14:30:23 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229667AbjJ1VaM (ORCPT + 99 others); Sat, 28 Oct 2023 17:30:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229446AbjJ1VaM (ORCPT ); Sat, 28 Oct 2023 17:30:12 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA0F2CA; Sat, 28 Oct 2023 14:30:09 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 95391C433C8; Sat, 28 Oct 2023 21:30:07 +0000 (UTC) Date: Sat, 28 Oct 2023 17:30:05 -0400 From: Steven Rostedt To: Christophe JAILLET Cc: Davidlohr Bueso , "Paul E. McKenney" , Josh Triplett , Frederic Weisbecker , Neeraj Upadhyay , Joel Fernandes , Boqun Feng , 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: <20231028173005.5d266f7a@rorschach.local.home> In-Reply-To: References: 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=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Sat, 28 Oct 2023 14:30:23 -0700 (PDT) On Sat, 28 Oct 2023 19:04:44 +0200 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. > Agreed. > Signed-off-by: Christophe JAILLET > --- > kernel/rcu/refscale.c | 20 +++++++++++++------- > 1 file changed, 13 insertions(+), 7 deletions(-) > > 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'); I was confused here thinking it was originally adding a '\n' to buf1 on i % 5, but it's adding it to buf! Yeah, using seq_buf is much less confusing and then less error prone. Reviewed-by: Steven Rostedt (Google) -- Steve > + > + 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);