Skip to content

Commit 4e39bb4

Browse files
tititiou36Neeraj Upadhyay
authored andcommitted
refscale: Optimize process_durations()
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 <[email protected]> Tested-by: "Paul E. McKenney" <[email protected]> Reviewed-by: Davidlohr Bueso <[email protected]> Signed-off-by: Neeraj Upadhyay <[email protected]>
1 parent 3e49aea commit 4e39bb4

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

kernel/rcu/refscale.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <linux/rcupdate_trace.h>
2929
#include <linux/reboot.h>
3030
#include <linux/sched.h>
31+
#include <linux/seq_buf.h>
3132
#include <linux/spinlock.h>
3233
#include <linux/smp.h>
3334
#include <linux/stat.h>
@@ -891,32 +892,34 @@ static u64 process_durations(int n)
891892
{
892893
int i;
893894
struct reader_task *rt;
894-
char buf1[64];
895+
struct seq_buf s;
895896
char *buf;
896897
u64 sum = 0;
897898

898899
buf = kmalloc(800 + 64, GFP_KERNEL);
899900
if (!buf)
900901
return 0;
901-
buf[0] = 0;
902-
sprintf(buf, "Experiment #%d (Format: <THREAD-NUM>:<Total loop time in ns>)",
903-
exp_idx);
902+
seq_buf_init(&s, buf, 800 + 64);
903+
904+
seq_buf_printf(&s, "Experiment #%d (Format: <THREAD-NUM>:<Total loop time in ns>)",
905+
exp_idx);
904906

905907
for (i = 0; i < n && !torture_must_stop(); i++) {
906908
rt = &(reader_tasks[i]);
907-
sprintf(buf1, "%d: %llu\t", i, rt->last_duration_ns);
908909

909910
if (i % 5 == 0)
910-
strcat(buf, "\n");
911-
if (strlen(buf) >= 800) {
912-
pr_alert("%s", buf);
913-
buf[0] = 0;
911+
seq_buf_putc(&s, '\n');
912+
913+
if (seq_buf_used(&s) >= 800) {
914+
pr_alert("%s", seq_buf_str(&s));
915+
seq_buf_clear(&s);
914916
}
915-
strcat(buf, buf1);
917+
918+
seq_buf_printf(&s, "%d: %llu\t", i, rt->last_duration_ns);
916919

917920
sum += rt->last_duration_ns;
918921
}
919-
pr_alert("%s\n", buf);
922+
pr_alert("%s\n", seq_buf_str(&s));
920923

921924
kfree(buf);
922925
return sum;

0 commit comments

Comments
 (0)