From: neeraj.upadhyay@kernel.org
To: rcu@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com,
rostedt@goodmis.org, paulmck@kernel.org,
neeraj.upadhyay@kernel.org, neeraj.upadhyay@amd.com,
boqun.feng@gmail.com, joel@joelfernandes.org, urezki@gmail.com,
frederic@kernel.org,
Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
Davidlohr Bueso <dave@stgolabs.net>
Subject: [PATCH rcu 02/14] refscale: Optimize process_durations()
Date: Fri, 16 Aug 2024 12:32:44 +0530 [thread overview]
Message-ID: <20240816070256.60993-2-neeraj.upadhyay@kernel.org> (raw)
In-Reply-To: <20240816070209.GA60666@neeraj.linux>
From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
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.
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Tested-by: "Paul E. McKenney" <paulmck@kernel.org>
Reviewed-by: Davidlohr Bueso <dave@stgolabs.net>
Signed-off-by: Neeraj Upadhyay <neeraj.upadhyay@kernel.org>
---
kernel/rcu/refscale.c | 25 ++++++++++++++-----------
1 file changed, 14 insertions(+), 11 deletions(-)
diff --git a/kernel/rcu/refscale.c b/kernel/rcu/refscale.c
index f4ea5b1ec068..cfec0648e141 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>
@@ -891,32 +892,34 @@ 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;
- sprintf(buf, "Experiment #%d (Format: <THREAD-NUM>:<Total loop time in ns>)",
- exp_idx);
+ seq_buf_init(&s, buf, 800 + 64);
+
+ seq_buf_printf(&s, "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) {
- pr_alert("%s", buf);
- buf[0] = 0;
+ seq_buf_putc(&s, '\n');
+
+ if (seq_buf_used(&s) >= 800) {
+ pr_alert("%s", seq_buf_str(&s));
+ seq_buf_clear(&s);
}
- strcat(buf, buf1);
+
+ seq_buf_printf(&s, "%d: %llu\t", i, rt->last_duration_ns);
sum += rt->last_duration_ns;
}
- pr_alert("%s\n", buf);
+ pr_alert("%s\n", seq_buf_str(&s));
kfree(buf);
return sum;
--
2.40.1
next prev parent reply other threads:[~2024-08-16 7:04 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-16 7:02 [PATCH rcu 00/14] RCU scaling tests updates for v6.12 Neeraj Upadhyay
2024-08-16 7:02 ` [PATCH rcu 01/14] refscale: Add TINY scenario neeraj.upadhyay
2024-08-16 7:02 ` neeraj.upadhyay [this message]
2024-08-16 7:02 ` [PATCH rcu 03/14] rcuscale: Save a few lines with whitespace-only change neeraj.upadhyay
2024-08-16 7:02 ` [PATCH rcu 04/14] rcuscale: Dump stacks of stalled rcu_scale_writer() instances neeraj.upadhyay
2024-08-16 7:02 ` [PATCH rcu 05/14] rcuscale: Dump grace-period statistics when rcu_scale_writer() stalls neeraj.upadhyay
2024-08-16 7:02 ` [PATCH rcu 06/14] rcu: Mark callbacks not currently participating in barrier operation neeraj.upadhyay
2024-08-16 7:02 ` [PATCH rcu 07/14] rcuscale: Print detailed grace-period and barrier diagnostics neeraj.upadhyay
2024-08-16 7:02 ` [PATCH rcu 08/14] rcuscale: Provide clear error when async specified without primitives neeraj.upadhyay
2024-08-16 7:02 ` [PATCH rcu 09/14] rcuscale: Make all writer tasks report upon hang neeraj.upadhyay
2024-08-16 7:02 ` [PATCH rcu 10/14] rcuscale: Make rcu_scale_writer() tolerate repeated GFP_KERNEL failure neeraj.upadhyay
2024-08-16 7:02 ` [PATCH rcu 11/14] rcuscale: Use special allocator for rcu_scale_writer() neeraj.upadhyay
2024-08-16 7:02 ` [PATCH rcu 12/14] rcuscale: NULL out top-level pointers to heap memory neeraj.upadhyay
2024-08-16 7:02 ` [PATCH rcu 13/14] rcuscale: Count outstanding callbacks per-task rather than per-CPU neeraj.upadhyay
2024-08-16 7:02 ` [PATCH rcu 14/14] refscale: Constify struct ref_scale_ops neeraj.upadhyay
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=20240816070256.60993-2-neeraj.upadhyay@kernel.org \
--to=neeraj.upadhyay@kernel.org \
--cc=boqun.feng@gmail.com \
--cc=christophe.jaillet@wanadoo.fr \
--cc=dave@stgolabs.net \
--cc=frederic@kernel.org \
--cc=joel@joelfernandes.org \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=neeraj.upadhyay@amd.com \
--cc=paulmck@kernel.org \
--cc=rcu@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=urezki@gmail.com \
/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