From: Steven Rostedt <rostedt@goodmis.org>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Cc: Davidlohr Bueso <dave@stgolabs.net>,
"Paul E. McKenney" <paulmck@kernel.org>,
Josh Triplett <josh@joshtriplett.org>,
Frederic Weisbecker <frederic@kernel.org>,
Neeraj Upadhyay <quic_neeraju@quicinc.com>,
Joel Fernandes <joel@joelfernandes.org>,
Boqun Feng <boqun.feng@gmail.com>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Lai Jiangshan <jiangshanlai@gmail.com>,
Zqiang <qiang.zhang1211@gmail.com>,
linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org,
rcu@vger.kernel.org
Subject: Re: [PATCH] refscale: Optimize process_durations()
Date: Sat, 28 Oct 2023 17:30:05 -0400 [thread overview]
Message-ID: <20231028173005.5d266f7a@rorschach.local.home> (raw)
In-Reply-To: <bbbab32e3e104bdc2238724a6a4a85e539f49ddd.1698512661.git.christophe.jaillet@wanadoo.fr>
On Sat, 28 Oct 2023 19:04:44 +0200
Christophe JAILLET <christophe.jaillet@wanadoo.fr> 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 <christophe.jaillet@wanadoo.fr>
> ---
> 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 <linux/rcupdate_trace.h>
> #include <linux/reboot.h>
> #include <linux/sched.h>
> +#include <linux/seq_buf.h>
> #include <linux/spinlock.h>
> #include <linux/smp.h>
> #include <linux/stat.h>
> @@ -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: <THREAD-NUM>:<Total loop time in ns>)",
> 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) <rostedt@goodmis.org>
-- 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);
next prev parent reply other threads:[~2023-10-28 21:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-28 17:04 Christophe JAILLET
2023-10-28 21:30 ` Steven Rostedt [this message]
2023-10-30 16:55 ` Davidlohr Bueso
2023-10-31 18:21 ` Paul E. McKenney
2023-10-31 22:47 ` Paul E. McKenney
2023-11-01 7:41 ` Christophe JAILLET
2023-11-01 10:24 ` Paul E. McKenney
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231028173005.5d266f7a@rorschach.local.home \
--to=rostedt@goodmis.org \
--cc=boqun.feng@gmail.com \
--cc=christophe.jaillet@wanadoo.fr \
--cc=dave@stgolabs.net \
--cc=frederic@kernel.org \
--cc=jiangshanlai@gmail.com \
--cc=joel@joelfernandes.org \
--cc=josh@joshtriplett.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=paulmck@kernel.org \
--cc=qiang.zhang1211@gmail.com \
--cc=quic_neeraju@quicinc.com \
--cc=rcu@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®