* [PATCH 0/6] Small seqfile-use improvements
@ 2014-09-12 9:25 Rasmus Villemoes
2014-09-12 9:25 ` [PATCH 1/6] Coccinelle: Semantic patch for replacing puts with putc Rasmus Villemoes
` (5 more replies)
0 siblings, 6 replies; 20+ messages in thread
From: Rasmus Villemoes @ 2014-09-12 9:25 UTC (permalink / raw)
To: Julia Lawall, Steven Rostedt, Ingo Molnar; +Cc: linux-kernel, Rasmus Villemoes
Patches 1-3 are semantic patches for replacing certain seq_* calls
with simpler equivalents, e.g. seq_printf(m, "literal") -> seq_puts(m,
"literal"). 1 and 3 are guaranteed to preserve the semantics of the
code. 2 may change it slightly, since if the seq_file overflows midway
through a series of seq_puts calls, some of the strings have been
printed; after applying 2, it is all-or-nothing. However, consecutive
seq_puts calls with literal strings is mostly used to print long
headers, so overflow is very unlikely.
As an example, I applied these coccinelle scripts to kernel/trace/.
The net result is a nice round, but admittedly tiny, 256 byte .text
reduction.
Rasmus Villemoes (6):
Coccinelle: Semantic patch for replacing puts with putc
Coccinelle: Semantic patch for joining seq_puts calls
Coccinelle: Semantic patch for replacing seq_printf calls with
equivalent but simpler functions
trace: Replace seq_printf by simpler equivalents
trace: Merge consecutive seq_puts calls
trace: Replace single-character seq_puts with seq_putc
kernel/trace/ftrace.c | 30 +++---
kernel/trace/trace.c | 86 ++++++++-------
kernel/trace/trace_branch.c | 31 +++---
kernel/trace/trace_events.c | 4 +-
kernel/trace/trace_events_trigger.c | 6 +-
kernel/trace/trace_functions.c | 2 +-
kernel/trace/trace_functions_graph.c | 28 ++---
kernel/trace/trace_kprobe.c | 12 +--
kernel/trace/trace_printk.c | 2 +-
kernel/trace/trace_uprobe.c | 4 +-
scripts/coccinelle/api/seq_printf.cocci | 156 +++++++++++++++++++++++++++
scripts/coccinelle/api/seq_puts_concat.cocci | 71 ++++++++++++
scripts/coccinelle/api/seq_putsc.cocci | 61 +++++++++++
13 files changed, 393 insertions(+), 100 deletions(-)
create mode 100644 scripts/coccinelle/api/seq_printf.cocci
create mode 100644 scripts/coccinelle/api/seq_puts_concat.cocci
create mode 100644 scripts/coccinelle/api/seq_putsc.cocci
--
2.0.4
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH 1/6] Coccinelle: Semantic patch for replacing puts with putc
2014-09-12 9:25 [PATCH 0/6] Small seqfile-use improvements Rasmus Villemoes
@ 2014-09-12 9:25 ` Rasmus Villemoes
2014-09-12 11:08 ` SF Markus Elfring
2014-09-12 9:25 ` [PATCH 2/6] Coccinelle: Semantic patch for joining seq_puts calls Rasmus Villemoes
` (4 subsequent siblings)
5 siblings, 1 reply; 20+ messages in thread
From: Rasmus Villemoes @ 2014-09-12 9:25 UTC (permalink / raw)
To: Julia Lawall, Steven Rostedt, Ingo Molnar; +Cc: linux-kernel, Rasmus Villemoes
Using seq_puts to write a one-character string is suboptimal,
since puts has to call strlen(). Replace those instances with
putc. This also tends to give a tiny code size reduction at the
call site.
seq_put[sc] return -1 on error, 0 on success.
trace_seq_put[sc] return how much was written, which is either 0 or 1.
In both cases, _putc is a drop-in replacement for _puts when the
argument is a one-character string.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
scripts/coccinelle/api/seq_putsc.cocci | 61 ++++++++++++++++++++++++++++++++++
1 file changed, 61 insertions(+)
create mode 100644 scripts/coccinelle/api/seq_putsc.cocci
diff --git a/scripts/coccinelle/api/seq_putsc.cocci b/scripts/coccinelle/api/seq_putsc.cocci
new file mode 100644
index 0000000..bb11097
--- /dev/null
+++ b/scripts/coccinelle/api/seq_putsc.cocci
@@ -0,0 +1,61 @@
+/// Using seq_puts to write a one-character string is suboptimal,
+/// since puts has to call strlen(). Replace those instances with
+/// putc. This also tends to give a tiny code size reduction at the
+/// call site.
+///
+/// seq_put[sc] return -1 on error, 0 on success.
+/// trace_seq_put[sc] return how much was written, which is either 0 or 1.
+///
+/// In both cases, _putc is a drop-in replacement for _puts when the
+/// argument is a one-character string.
+///
+//
+// Confidence: High
+// Options: --no-includes --include-headers
+//
+// Since the changes to any given line should consist of changing an s
+// to a c and two " to ', the generated patches should be easy to
+// proofread.
+
+virtual patch
+virtual context
+virtual org
+virtual report
+
+@putc1 depends on patch@
+position p;
+expression s;
+constant c;
+@@
+ \(trace_seq_puts@p\|seq_puts@p\)(s, c)
+
+// Use python to check whether the string constant consists of a
+// single character, and if so, create an "identifier" containing that
+// single character as a C literal.
+@script:python putc2@
+s << putc1.s;
+c << putc1.c;
+ch;
+@@
+import re
+import sys
+
+m = re.match("^\"(.|\\\\.)\"$", c)
+if not m:
+ cocci.include_match(False)
+else:
+ coccinelle.ch = "'" + m.group(1) + "'"
+
+@putc3 depends on patch@
+position putc1.p;
+expression putc1.s;
+constant putc1.c;
+identifier putc2.ch;
+@@
+(
+- seq_puts@p(s, c)
++ seq_putc(s, ch)
+|
+- trace_seq_puts@p(s, c)
++ trace_seq_putc(s, ch)
+)
--
2.0.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 2/6] Coccinelle: Semantic patch for joining seq_puts calls
2014-09-12 9:25 [PATCH 0/6] Small seqfile-use improvements Rasmus Villemoes
2014-09-12 9:25 ` [PATCH 1/6] Coccinelle: Semantic patch for replacing puts with putc Rasmus Villemoes
@ 2014-09-12 9:25 ` Rasmus Villemoes
2014-09-12 9:25 ` [PATCH 3/6] Coccinelle: Semantic patch for replacing seq_printf calls with equivalent but simpler functions Rasmus Villemoes
` (3 subsequent siblings)
5 siblings, 0 replies; 20+ messages in thread
From: Rasmus Villemoes @ 2014-09-12 9:25 UTC (permalink / raw)
To: Julia Lawall, Steven Rostedt, Ingo Molnar; +Cc: linux-kernel, Rasmus Villemoes
Consecutive calls of seq_puts with literal strings, where the return
value is not checked, might as well be replaced by a single call with
the combined string. This gives smaller generated code (less function
calls), a slight .rodata reduction, since nul and padding bytes are
eliminated, and hits fewer cache lines (nothing guarantees that the
linker places string literals which are used together close together
in the final image).
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
scripts/coccinelle/api/seq_puts_concat.cocci | 71 ++++++++++++++++++++++++++++
1 file changed, 71 insertions(+)
create mode 100644 scripts/coccinelle/api/seq_puts_concat.cocci
diff --git a/scripts/coccinelle/api/seq_puts_concat.cocci b/scripts/coccinelle/api/seq_puts_concat.cocci
new file mode 100644
index 0000000..0e7afc3
--- /dev/null
+++ b/scripts/coccinelle/api/seq_puts_concat.cocci
@@ -0,0 +1,71 @@
+/// Consecutive calls of seq_puts with literal strings, where the
+/// return value is not checked, might as well be replaced by a single
+/// call with the combined string. This gives smaller generated code
+/// (less function calls), a slight .rodata reduction, since nul and
+/// padding bytes are eliminated, and hits fewer cache lines (nothing
+/// guarantees that the linker places string literals which are used
+/// together close together in the final image).
+///
+/// Two small, but in practice irrelevant, issues:
+///
+/// (1) If one of the strings is also used elsewhere, this reduces the
+/// possiblity for the linker to do string merging (thus increasing
+/// .rodata), but these multiple seq_puts calls are mostly to print
+/// multi-line headers in various /proc or /sys files.
+///
+/// (2) seq_puts is all-or-nothing, so if there is not room for the
+/// entire string, one would previously get some of the strings
+/// printed, but not all; combining the strings means nothing is
+/// printed. So this formally changes the semantics of the
+/// code. However, usually there is room.
+///
+///
+//
+// Run and apply repeatedly until no furter patches are generated,
+// then fix up the whitespace.
+//
+// Confidence: High
+// Options: --no-includes --include-headers
+
+
+virtual patch
+virtual context
+virtual org
+virtual report
+
+// Prevent "token already tagged" error
+@r@
+position p;
+@@
+ seq_puts(...);
+ seq_puts(...);
+ seq_puts@p(...);
+
+
+@concat1 depends on patch@
+expression s;
+constant c1, c2;
+position p1 != r.p, p2 != r.p;
+@@
+ seq_puts@p1(s, c1);
+ seq_puts@p2(s, c2);
+
+@script:python concat2@
+c1 << concat1.c1;
+c2 << concat1.c2;
+c3;
+@@
+
+// The indentation probably needs to be fixed manually
+coccinelle.c3 = c1 + "\n\t" + c2
+
+@concat3 depends on patch@
+identifier concat2.c3;
+expression concat1.s;
+constant concat1.c1, concat1.c2;
+position concat1.p1, concat1.p2;
+@@
+- seq_puts@p1(s, c1);
+- seq_puts@p2(s, c2);
++ seq_puts(s, c3);
+
--
2.0.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 3/6] Coccinelle: Semantic patch for replacing seq_printf calls with equivalent but simpler functions
2014-09-12 9:25 [PATCH 0/6] Small seqfile-use improvements Rasmus Villemoes
2014-09-12 9:25 ` [PATCH 1/6] Coccinelle: Semantic patch for replacing puts with putc Rasmus Villemoes
2014-09-12 9:25 ` [PATCH 2/6] Coccinelle: Semantic patch for joining seq_puts calls Rasmus Villemoes
@ 2014-09-12 9:25 ` Rasmus Villemoes
2014-09-12 9:25 ` [PATCH 4/6] trace: Replace seq_printf by simpler equivalents Rasmus Villemoes
` (2 subsequent siblings)
5 siblings, 0 replies; 20+ messages in thread
From: Rasmus Villemoes @ 2014-09-12 9:25 UTC (permalink / raw)
To: Julia Lawall, Steven Rostedt, Ingo Molnar; +Cc: linux-kernel, Rasmus Villemoes
Using seq_printf to print a simple string is a lot more expensive than
it needs to be, since seq_puts exists [1]. This semantic patch
purposely also matches non-literals, since in that case it is also
safer to use puts.
We also handle the cases where the format string is exactly "%s" or
"%c" and replace with puts/putc.
[1] printf must push all the, in this case non-existent, varargs into
a va_arg structure on the stack, then vprintf takes over and calls
vsnprintf, ...
seq_{printf,puts,putc} all return -1 on error, 0 on success.
trace_seq_{printf,puts,putc} all return 0 on failure, but printf and
putc return 1 on success, puts returns the length of the
string. Therefore, we only do the printf->puts conversion where the
return value of trace_seq_printf is either unused or used as a
boolean; the printf->putc conversion can safely be done anywhere.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
scripts/coccinelle/api/seq_printf.cocci | 156 ++++++++++++++++++++++++++++++++
1 file changed, 156 insertions(+)
create mode 100644 scripts/coccinelle/api/seq_printf.cocci
diff --git a/scripts/coccinelle/api/seq_printf.cocci b/scripts/coccinelle/api/seq_printf.cocci
new file mode 100644
index 0000000..c5525bf
--- /dev/null
+++ b/scripts/coccinelle/api/seq_printf.cocci
@@ -0,0 +1,156 @@
+/// Using seq_printf to print a simple string is a lot more expensive
+/// than it needs to be, since seq_puts exists [1]. This semantic
+/// patch purposely also matches non-literals, since in that case it
+/// is also safer to use puts.
+///
+/// We also handle the cases where the format string is exactly "%s"
+/// or "%c" and replace with puts/putc.
+///
+/// [1] printf must push all the, in this case non-existent, varargs
+/// into a va_arg structure on the stack, then vprintf takes over and
+/// calls vsnprintf, ...
+///
+/// seq_{printf,puts,putc} all return -1 on error, 0 on success.
+///
+/// trace_seq_{printf,puts,putc} all return 0 on failure, but printf
+/// and putc return 1 on success, puts returns the length of the
+/// string. Therefore, we only do the printf->puts conversion where
+/// the return value of trace_seq_printf is either unused or used as a
+/// boolean; the printf->putc conversion can safely be done anywhere.
+///
+//
+// Confidence: High
+// Options: --no-includes --include-headers
+//
+
+virtual patch
+virtual context
+virtual org
+virtual report
+
+
+// In order to DTRT when the format string contains %%, we need to
+// process it with python. If t is actually an expression and not just
+// a string literal, it is very unlikely to contain two adjacent %
+// characters. But note that this does not handle the case where t is
+// either a macro or a const char* which happens to point to a string
+// containing two %%. git grep 'define.*%%' shows that macros
+// containing %% are usually used in inline asm, and register
+// specifiers tend to be unusable as format specifiers.
+@p1a depends on patch@
+expression s;
+expression t;
+position p;
+@@
+ seq_printf@p(s, t)
+
+@script:python p1b@
+t << p1a.t;
+tt;
+@@
+import re
+coccinelle.tt = re.sub('%%', '%', t)
+
+@p1c depends on p1a@
+expression p1a.s;
+expression p1a.t;
+position p1a.p;
+identifier p1b.tt;
+@@
+- seq_printf@p(s, t)
++ seq_puts(s, tt)
+
+// Using the string literal "%s" seems to be broken with my version of
+// coccinelle (it matches any format string containing a single format
+// specifier), so use a slightly uglier method.
+@p2 depends on patch@
+expression s;
+expression t;
+format f =~ "^s$";
+@@
+- seq_printf(s, "%@f@", t)
++ seq_puts(s, t)
+
+@p3 depends on patch@
+expression s;
+expression t;
+format f =~ "^c$";
+@@
+- seq_printf(s, "%@f@", t)
++ seq_putc(s, t)
+
+
+
+
+@tp1a depends on patch@
+expression s;
+expression t;
+position p;
+@@
+ trace_seq_printf@p(s, t);
+
+@script:python tp1b@
+t << tp1a.t;
+tt;
+@@
+import re
+coccinelle.tt = re.sub('%%', '%', t)
+
+@tp1c depends on tp1a@
+expression tp1a.s;
+expression tp1a.t;
+position tp1a.p;
+identifier tp1b.tt;
+@@
+- trace_seq_printf@p(s, t);
++ trace_seq_puts(s, tt);
+
+@tp2 depends on patch@
+expression s;
+expression t;
+format f =~ "^s$";
+@@
+- trace_seq_printf(s, "%@f@", t);
++ trace_seq_puts(s, t);
+
+
+@tp3a depends on patch@
+expression s;
+expression t;
+position p;
+@@
+ !trace_seq_printf@p(s, t)
+
+@script:python tp3b@
+t << tp3a.t;
+tt;
+@@
+import re
+coccinelle.tt = re.sub('%%', '%', t)
+
+@tp3c depends on tp3a@
+expression tp3a.s;
+expression tp3a.t;
+position tp3a.p;
+identifier tp3b.tt;
+@@
+- !trace_seq_printf@p(s, t)
++ !trace_seq_puts(s, tt)
+
+@tp4 depends on patch@
+expression s;
+expression t;
+format f =~ "^s$";
+@@
+- !trace_seq_printf(s, "%@f@", t)
++ !trace_seq_puts(s, t)
+
+
+@tp5 depends on patch@
+expression s;
+expression t;
+format f =~ "^c$";
+@@
+- trace_seq_printf(s, "%@f@", t)
++ trace_seq_putc(s, t)
+
--
2.0.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 4/6] trace: Replace seq_printf by simpler equivalents
2014-09-12 9:25 [PATCH 0/6] Small seqfile-use improvements Rasmus Villemoes
` (2 preceding siblings ...)
2014-09-12 9:25 ` [PATCH 3/6] Coccinelle: Semantic patch for replacing seq_printf calls with equivalent but simpler functions Rasmus Villemoes
@ 2014-09-12 9:25 ` Rasmus Villemoes
2014-11-05 22:34 ` Steven Rostedt
2014-11-08 20:42 ` [PATCH v2 0/3] trace: Use simpler seq_file functions Rasmus Villemoes
2014-09-12 9:25 ` [PATCH 5/6] trace: Merge consecutive seq_puts calls Rasmus Villemoes
2014-09-12 9:25 ` [PATCH 6/6] trace: Replace single-character seq_puts with seq_putc Rasmus Villemoes
5 siblings, 2 replies; 20+ messages in thread
From: Rasmus Villemoes @ 2014-09-12 9:25 UTC (permalink / raw)
To: Julia Lawall, Steven Rostedt, Ingo Molnar; +Cc: linux-kernel, Rasmus Villemoes
Using seq_printf to print a simple string or a single character is a
lot more expensive than it needs to be, since seq_puts and seq_putc
exist.
These patches do
seq_printf(m, s) -> seq_puts(m, s)
seq_printf(m, "%s", s) -> seq_puts(m, s)
seq_printf(m, "%c", c) -> seq_putc(m, c)
Subsequent patches will simplify further.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
kernel/trace/ftrace.c | 30 ++++++++++++------------
kernel/trace/trace.c | 44 ++++++++++++++++++------------------
kernel/trace/trace_branch.c | 24 +++++++++-----------
kernel/trace/trace_events.c | 4 ++--
kernel/trace/trace_events_trigger.c | 2 +-
kernel/trace/trace_functions.c | 2 +-
kernel/trace/trace_functions_graph.c | 28 +++++++++++------------
kernel/trace/trace_kprobe.c | 4 ++--
kernel/trace/trace_uprobe.c | 2 +-
9 files changed, 69 insertions(+), 71 deletions(-)
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 5916a8e..7b9ce28 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -556,13 +556,13 @@ static int function_stat_cmp(void *p1, void *p2)
static int function_stat_headers(struct seq_file *m)
{
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
- seq_printf(m, " Function "
- "Hit Time Avg s^2\n"
- " -------- "
- "--- ---- --- ---\n");
+ seq_puts(m,
+ " Function " "Hit Time Avg s^2\n"
+ " -------- " "--- ---- --- ---\n");
#else
- seq_printf(m, " Function Hit\n"
- " -------- ---\n");
+ seq_puts(m,
+ " Function Hit\n"
+ " -------- ---\n");
#endif
return 0;
}
@@ -589,7 +589,7 @@ static int function_stat_show(struct seq_file *m, void *v)
seq_printf(m, " %-30.30s %10lu", str, rec->counter);
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
- seq_printf(m, " ");
+ seq_puts(m, " ");
avg = rec->time;
do_div(avg, rec->counter);
@@ -2941,9 +2941,9 @@ static int t_show(struct seq_file *m, void *v)
if (iter->flags & FTRACE_ITER_PRINTALL) {
if (iter->flags & FTRACE_ITER_NOTRACE)
- seq_printf(m, "#### no functions disabled ####\n");
+ seq_puts(m, "#### no functions disabled ####\n");
else
- seq_printf(m, "#### all functions enabled ####\n");
+ seq_puts(m, "#### all functions enabled ####\n");
return 0;
}
@@ -2965,11 +2965,11 @@ static int t_show(struct seq_file *m, void *v)
seq_printf(m, "\ttramp: %pS",
(void *)ops->trampoline);
else
- seq_printf(m, "\ttramp: ERROR!");
+ seq_puts(m, "\ttramp: ERROR!");
}
}
- seq_printf(m, "\n");
+ seq_puts(m, "\n");
return 0;
}
@@ -4149,9 +4149,9 @@ static int g_show(struct seq_file *m, void *v)
struct ftrace_graph_data *fgd = m->private;
if (fgd->table == ftrace_graph_funcs)
- seq_printf(m, "#### all functions enabled ####\n");
+ seq_puts(m, "#### all functions enabled ####\n");
else
- seq_printf(m, "#### no functions disabled ####\n");
+ seq_puts(m, "#### no functions disabled ####\n");
return 0;
}
@@ -4989,12 +4989,12 @@ static int fpid_show(struct seq_file *m, void *v)
const struct ftrace_pid *fpid = list_entry(v, struct ftrace_pid, list);
if (v == (void *)1) {
- seq_printf(m, "no pid\n");
+ seq_puts(m, "no pid\n");
return 0;
}
if (fpid->pid == ftrace_swapper_pid)
- seq_printf(m, "swapper tasks\n");
+ seq_puts(m, "swapper tasks\n");
else
seq_printf(m, "%u\n", pid_vnr(fpid->pid));
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 8a52839..77bb64f 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -2859,44 +2859,44 @@ static void test_ftrace_alive(struct seq_file *m)
{
if (!ftrace_is_dead())
return;
- seq_printf(m, "# WARNING: FUNCTION TRACING IS CORRUPTED\n");
- seq_printf(m, "# MAY BE MISSING FUNCTION EVENTS\n");
+ seq_puts(m, "# WARNING: FUNCTION TRACING IS CORRUPTED\n");
+ seq_puts(m, "# MAY BE MISSING FUNCTION EVENTS\n");
}
#ifdef CONFIG_TRACER_MAX_TRACE
static void show_snapshot_main_help(struct seq_file *m)
{
- seq_printf(m, "# echo 0 > snapshot : Clears and frees snapshot buffer\n");
- seq_printf(m, "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n");
- seq_printf(m, "# Takes a snapshot of the main buffer.\n");
- seq_printf(m, "# echo 2 > snapshot : Clears snapshot buffer (but does not allocate or free)\n");
- seq_printf(m, "# (Doesn't have to be '2' works with any number that\n");
- seq_printf(m, "# is not a '0' or '1')\n");
+ seq_puts(m, "# echo 0 > snapshot : Clears and frees snapshot buffer\n");
+ seq_puts(m, "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n");
+ seq_puts(m, "# Takes a snapshot of the main buffer.\n");
+ seq_puts(m, "# echo 2 > snapshot : Clears snapshot buffer (but does not allocate or free)\n");
+ seq_puts(m, "# (Doesn't have to be '2' works with any number that\n");
+ seq_puts(m, "# is not a '0' or '1')\n");
}
static void show_snapshot_percpu_help(struct seq_file *m)
{
- seq_printf(m, "# echo 0 > snapshot : Invalid for per_cpu snapshot file.\n");
+ seq_puts(m, "# echo 0 > snapshot : Invalid for per_cpu snapshot file.\n");
#ifdef CONFIG_RING_BUFFER_ALLOW_SWAP
- seq_printf(m, "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n");
- seq_printf(m, "# Takes a snapshot of the main buffer for this cpu.\n");
+ seq_puts(m, "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n");
+ seq_puts(m, "# Takes a snapshot of the main buffer for this cpu.\n");
#else
- seq_printf(m, "# echo 1 > snapshot : Not supported with this kernel.\n");
- seq_printf(m, "# Must use main snapshot file to allocate.\n");
+ seq_puts(m, "# echo 1 > snapshot : Not supported with this kernel.\n");
+ seq_puts(m, "# Must use main snapshot file to allocate.\n");
#endif
- seq_printf(m, "# echo 2 > snapshot : Clears this cpu's snapshot buffer (but does not allocate)\n");
- seq_printf(m, "# (Doesn't have to be '2' works with any number that\n");
- seq_printf(m, "# is not a '0' or '1')\n");
+ seq_puts(m, "# echo 2 > snapshot : Clears this cpu's snapshot buffer (but does not allocate)\n");
+ seq_puts(m, "# (Doesn't have to be '2' works with any number that\n");
+ seq_puts(m, "# is not a '0' or '1')\n");
}
static void print_snapshot_help(struct seq_file *m, struct trace_iterator *iter)
{
if (iter->tr->allocated_snapshot)
- seq_printf(m, "#\n# * Snapshot is allocated *\n#\n");
+ seq_puts(m, "#\n# * Snapshot is allocated *\n#\n");
else
- seq_printf(m, "#\n# * Snapshot is freed *\n#\n");
+ seq_puts(m, "#\n# * Snapshot is freed *\n#\n");
- seq_printf(m, "# Snapshot commands:\n");
+ seq_puts(m, "# Snapshot commands:\n");
if (iter->cpu_file == RING_BUFFER_ALL_CPUS)
show_snapshot_main_help(m);
else
@@ -3250,7 +3250,7 @@ static int t_show(struct seq_file *m, void *v)
if (!t)
return 0;
- seq_printf(m, "%s", t->name);
+ seq_puts(m, t->name);
if (t->next)
seq_putc(m, ' ');
else
@@ -5752,10 +5752,10 @@ ftrace_snapshot_print(struct seq_file *m, unsigned long ip,
seq_printf(m, "%ps:", (void *)ip);
- seq_printf(m, "snapshot");
+ seq_puts(m, "snapshot");
if (count == -1)
- seq_printf(m, ":unlimited\n");
+ seq_puts(m, ":unlimited\n");
else
seq_printf(m, ":count=%ld\n", count);
diff --git a/kernel/trace/trace_branch.c b/kernel/trace/trace_branch.c
index 697fb9b..c38f8fa 100644
--- a/kernel/trace/trace_branch.c
+++ b/kernel/trace/trace_branch.c
@@ -233,12 +233,13 @@ extern unsigned long __stop_annotated_branch_profile[];
static int annotated_branch_stat_headers(struct seq_file *m)
{
- seq_printf(m, " correct incorrect %% ");
- seq_printf(m, " Function "
- " File Line\n"
- " ------- --------- - "
- " -------- "
- " ---- ----\n");
+ seq_puts(m, " correct incorrect % ");
+ seq_puts(m,
+ " Function "
+ " File Line\n"
+ " ------- --------- - "
+ " -------- "
+ " ---- ----\n");
return 0;
}
@@ -274,7 +275,7 @@ static int branch_stat_show(struct seq_file *m, void *v)
seq_printf(m, "%8lu %8lu ", p->correct, p->incorrect);
if (percent < 0)
- seq_printf(m, " X ");
+ seq_puts(m, " X ");
else
seq_printf(m, "%3ld ", percent);
seq_printf(m, "%-30.30s %-20.20s %d\n", p->func, f, p->line);
@@ -362,12 +363,9 @@ extern unsigned long __stop_branch_profile[];
static int all_branch_stat_headers(struct seq_file *m)
{
- seq_printf(m, " miss hit %% ");
- seq_printf(m, " Function "
- " File Line\n"
- " ------- --------- - "
- " -------- "
- " ---- ----\n");
+ seq_puts(m, " miss hit % ");
+ seq_puts(m,
+ " Function " " File Line\n" " ------- --------- - " " -------- " " ---- ----\n");
return 0;
}
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index ef06ce7..32f0199 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -918,7 +918,7 @@ static int f_show(struct seq_file *m, void *v)
case FORMAT_HEADER:
seq_printf(m, "name: %s\n", ftrace_event_name(call));
seq_printf(m, "ID: %d\n", call->event.type);
- seq_printf(m, "format:\n");
+ seq_puts(m, "format:\n");
return 0;
case FORMAT_FIELD_SEPERATOR:
@@ -1988,7 +1988,7 @@ event_enable_print(struct seq_file *m, unsigned long ip,
ftrace_event_name(data->file->event_call));
if (data->count == -1)
- seq_printf(m, ":unlimited\n");
+ seq_puts(m, ":unlimited\n");
else
seq_printf(m, ":count=%ld\n", data->count);
diff --git a/kernel/trace/trace_events_trigger.c b/kernel/trace/trace_events_trigger.c
index 4747b47..3d89ffc 100644
--- a/kernel/trace/trace_events_trigger.c
+++ b/kernel/trace/trace_events_trigger.c
@@ -373,7 +373,7 @@ event_trigger_print(const char *name, struct seq_file *m,
{
long count = (long)data;
- seq_printf(m, "%s", name);
+ seq_puts(m, name);
if (count == -1)
seq_puts(m, ":unlimited");
diff --git a/kernel/trace/trace_functions.c b/kernel/trace/trace_functions.c
index 57f0ec9..a8e0c76 100644
--- a/kernel/trace/trace_functions.c
+++ b/kernel/trace/trace_functions.c
@@ -361,7 +361,7 @@ ftrace_probe_print(const char *name, struct seq_file *m,
seq_printf(m, "%ps:%s", (void *)ip, name);
if (count == -1)
- seq_printf(m, ":unlimited\n");
+ seq_puts(m, ":unlimited\n");
else
seq_printf(m, ":count=%ld\n", count);
diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c
index f0a0c98..29ba611 100644
--- a/kernel/trace/trace_functions_graph.c
+++ b/kernel/trace/trace_functions_graph.c
@@ -1407,32 +1407,32 @@ static void __print_graph_headers_flags(struct seq_file *s, u32 flags)
print_lat_header(s, flags);
/* 1st line */
- seq_printf(s, "#");
+ seq_puts(s, "#");
if (flags & TRACE_GRAPH_PRINT_ABS_TIME)
- seq_printf(s, " TIME ");
+ seq_puts(s, " TIME ");
if (flags & TRACE_GRAPH_PRINT_CPU)
- seq_printf(s, " CPU");
+ seq_puts(s, " CPU");
if (flags & TRACE_GRAPH_PRINT_PROC)
- seq_printf(s, " TASK/PID ");
+ seq_puts(s, " TASK/PID ");
if (lat)
- seq_printf(s, "||||");
+ seq_puts(s, "||||");
if (flags & TRACE_GRAPH_PRINT_DURATION)
- seq_printf(s, " DURATION ");
- seq_printf(s, " FUNCTION CALLS\n");
+ seq_puts(s, " DURATION ");
+ seq_puts(s, " FUNCTION CALLS\n");
/* 2nd line */
- seq_printf(s, "#");
+ seq_puts(s, "#");
if (flags & TRACE_GRAPH_PRINT_ABS_TIME)
- seq_printf(s, " | ");
+ seq_puts(s, " | ");
if (flags & TRACE_GRAPH_PRINT_CPU)
- seq_printf(s, " | ");
+ seq_puts(s, " | ");
if (flags & TRACE_GRAPH_PRINT_PROC)
- seq_printf(s, " | | ");
+ seq_puts(s, " | | ");
if (lat)
- seq_printf(s, "||||");
+ seq_puts(s, "||||");
if (flags & TRACE_GRAPH_PRINT_DURATION)
- seq_printf(s, " | | ");
- seq_printf(s, " | | | |\n");
+ seq_puts(s, " | | ");
+ seq_puts(s, " | | | |\n");
}
static void print_graph_headers(struct seq_file *s)
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index 282f6e4..ce2ea71 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -826,7 +826,7 @@ static int probes_seq_show(struct seq_file *m, void *v)
struct trace_kprobe *tk = v;
int i;
- seq_printf(m, "%c", trace_kprobe_is_return(tk) ? 'r' : 'p');
+ seq_putc(m, trace_kprobe_is_return(tk) ? 'r' : 'p');
seq_printf(m, ":%s/%s", tk->tp.call.class->system,
ftrace_event_name(&tk->tp.call));
@@ -840,7 +840,7 @@ static int probes_seq_show(struct seq_file *m, void *v)
for (i = 0; i < tk->tp.nr_args; i++)
seq_printf(m, " %s=%s", tk->tp.args[i].name, tk->tp.args[i].comm);
- seq_printf(m, "\n");
+ seq_puts(m, "\n");
return 0;
}
diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c
index 33ff6a2..184aec1 100644
--- a/kernel/trace/trace_uprobe.c
+++ b/kernel/trace/trace_uprobe.c
@@ -606,7 +606,7 @@ static int probes_seq_show(struct seq_file *m, void *v)
for (i = 0; i < tu->tp.nr_args; i++)
seq_printf(m, " %s=%s", tu->tp.args[i].name, tu->tp.args[i].comm);
- seq_printf(m, "\n");
+ seq_puts(m, "\n");
return 0;
}
--
2.0.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 5/6] trace: Merge consecutive seq_puts calls
2014-09-12 9:25 [PATCH 0/6] Small seqfile-use improvements Rasmus Villemoes
` (3 preceding siblings ...)
2014-09-12 9:25 ` [PATCH 4/6] trace: Replace seq_printf by simpler equivalents Rasmus Villemoes
@ 2014-09-12 9:25 ` Rasmus Villemoes
2014-09-12 9:25 ` [PATCH 6/6] trace: Replace single-character seq_puts with seq_putc Rasmus Villemoes
5 siblings, 0 replies; 20+ messages in thread
From: Rasmus Villemoes @ 2014-09-12 9:25 UTC (permalink / raw)
To: Julia Lawall, Steven Rostedt, Ingo Molnar; +Cc: linux-kernel, Rasmus Villemoes
Consecutive seq_puts calls with literal strings can be merged to a
single call. This reduces the size of the generated code, and can also
lead to slight .rodata reduction (because of fewer nul and padding
bytes). It should also shave a off a few clock cycles.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
kernel/trace/trace.c | 72 +++++++++++++++++++++++++--------------------
kernel/trace/trace_branch.c | 13 ++++----
2 files changed, 46 insertions(+), 39 deletions(-)
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 77bb64f..14fb877 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -2508,14 +2508,15 @@ get_total_entries(struct trace_buffer *buf,
static void print_lat_help_header(struct seq_file *m)
{
- seq_puts(m, "# _------=> CPU# \n");
- seq_puts(m, "# / _-----=> irqs-off \n");
- seq_puts(m, "# | / _----=> need-resched \n");
- seq_puts(m, "# || / _---=> hardirq/softirq \n");
- seq_puts(m, "# ||| / _--=> preempt-depth \n");
- seq_puts(m, "# |||| / delay \n");
- seq_puts(m, "# cmd pid ||||| time | caller \n");
- seq_puts(m, "# \\ / ||||| \\ | / \n");
+ seq_puts(m,
+ "# _------=> CPU# \n"
+ "# / _-----=> irqs-off \n"
+ "# | / _----=> need-resched \n"
+ "# || / _---=> hardirq/softirq \n"
+ "# ||| / _--=> preempt-depth \n"
+ "# |||| / delay \n"
+ "# cmd pid ||||| time | caller \n"
+ "# \\ / ||||| \\ | / \n");
}
static void print_event_info(struct trace_buffer *buf, struct seq_file *m)
@@ -2532,20 +2533,22 @@ static void print_event_info(struct trace_buffer *buf, struct seq_file *m)
static void print_func_help_header(struct trace_buffer *buf, struct seq_file *m)
{
print_event_info(buf, m);
- seq_puts(m, "# TASK-PID CPU# TIMESTAMP FUNCTION\n");
- seq_puts(m, "# | | | | |\n");
+ seq_puts(m,
+ "# TASK-PID CPU# TIMESTAMP FUNCTION\n"
+ "# | | | | |\n");
}
static void print_func_help_header_irq(struct trace_buffer *buf, struct seq_file *m)
{
print_event_info(buf, m);
- seq_puts(m, "# _-----=> irqs-off\n");
- seq_puts(m, "# / _----=> need-resched\n");
- seq_puts(m, "# | / _---=> hardirq/softirq\n");
- seq_puts(m, "# || / _--=> preempt-depth\n");
- seq_puts(m, "# ||| / delay\n");
- seq_puts(m, "# TASK-PID CPU# |||| TIMESTAMP FUNCTION\n");
- seq_puts(m, "# | | | |||| | |\n");
+ seq_puts(m,
+ "# _-----=> irqs-off\n"
+ "# / _----=> need-resched\n"
+ "# | / _---=> hardirq/softirq\n"
+ "# || / _--=> preempt-depth\n"
+ "# ||| / delay\n"
+ "# TASK-PID CPU# |||| TIMESTAMP FUNCTION\n"
+ "# | | | |||| | |\n");
}
void
@@ -2859,34 +2862,39 @@ static void test_ftrace_alive(struct seq_file *m)
{
if (!ftrace_is_dead())
return;
- seq_puts(m, "# WARNING: FUNCTION TRACING IS CORRUPTED\n");
- seq_puts(m, "# MAY BE MISSING FUNCTION EVENTS\n");
+ seq_puts(m,
+ "# WARNING: FUNCTION TRACING IS CORRUPTED\n"
+ "# MAY BE MISSING FUNCTION EVENTS\n");
}
#ifdef CONFIG_TRACER_MAX_TRACE
static void show_snapshot_main_help(struct seq_file *m)
{
- seq_puts(m, "# echo 0 > snapshot : Clears and frees snapshot buffer\n");
- seq_puts(m, "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n");
- seq_puts(m, "# Takes a snapshot of the main buffer.\n");
- seq_puts(m, "# echo 2 > snapshot : Clears snapshot buffer (but does not allocate or free)\n");
- seq_puts(m, "# (Doesn't have to be '2' works with any number that\n");
- seq_puts(m, "# is not a '0' or '1')\n");
+ seq_puts(m,
+ "# echo 0 > snapshot : Clears and frees snapshot buffer\n"
+ "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n"
+ "# Takes a snapshot of the main buffer.\n"
+ "# echo 2 > snapshot : Clears snapshot buffer (but does not allocate or free)\n"
+ "# (Doesn't have to be '2' works with any number that\n"
+ "# is not a '0' or '1')\n");
}
static void show_snapshot_percpu_help(struct seq_file *m)
{
seq_puts(m, "# echo 0 > snapshot : Invalid for per_cpu snapshot file.\n");
#ifdef CONFIG_RING_BUFFER_ALLOW_SWAP
- seq_puts(m, "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n");
- seq_puts(m, "# Takes a snapshot of the main buffer for this cpu.\n");
+ seq_puts(m,
+ "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n"
+ "# Takes a snapshot of the main buffer for this cpu.\n");
#else
- seq_puts(m, "# echo 1 > snapshot : Not supported with this kernel.\n");
- seq_puts(m, "# Must use main snapshot file to allocate.\n");
+ seq_puts(m,
+ "# echo 1 > snapshot : Not supported with this kernel.\n"
+ "# Must use main snapshot file to allocate.\n");
#endif
- seq_puts(m, "# echo 2 > snapshot : Clears this cpu's snapshot buffer (but does not allocate)\n");
- seq_puts(m, "# (Doesn't have to be '2' works with any number that\n");
- seq_puts(m, "# is not a '0' or '1')\n");
+ seq_puts(m,
+ "# echo 2 > snapshot : Clears this cpu's snapshot buffer (but does not allocate)\n"
+ "# (Doesn't have to be '2' works with any number that\n"
+ "# is not a '0' or '1')\n");
}
static void print_snapshot_help(struct seq_file *m, struct trace_iterator *iter)
diff --git a/kernel/trace/trace_branch.c b/kernel/trace/trace_branch.c
index c38f8fa..c7e1567 100644
--- a/kernel/trace/trace_branch.c
+++ b/kernel/trace/trace_branch.c
@@ -163,10 +163,9 @@ static enum print_line_t trace_branch_print(struct trace_iterator *iter,
static void branch_print_header(struct seq_file *s)
{
- seq_puts(s, "# TASK-PID CPU# TIMESTAMP CORRECT"
- " FUNC:FILE:LINE\n");
- seq_puts(s, "# | | | | | "
- " |\n");
+ seq_puts(s,
+ "# TASK-PID CPU# TIMESTAMP CORRECT" " FUNC:FILE:LINE\n"
+ "# | | | | | " " |\n");
}
static struct trace_event_functions trace_branch_funcs = {
@@ -233,8 +232,8 @@ extern unsigned long __stop_annotated_branch_profile[];
static int annotated_branch_stat_headers(struct seq_file *m)
{
- seq_puts(m, " correct incorrect % ");
seq_puts(m,
+ " correct incorrect % "
" Function "
" File Line\n"
" ------- --------- - "
@@ -363,9 +362,9 @@ extern unsigned long __stop_branch_profile[];
static int all_branch_stat_headers(struct seq_file *m)
{
- seq_puts(m, " miss hit % ");
seq_puts(m,
- " Function " " File Line\n" " ------- --------- - " " -------- " " ---- ----\n");
+ " miss hit % " " Function " " File Line\n"
+ " ------- --------- - " " -------- " " ---- ----\n");
return 0;
}
--
2.0.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 6/6] trace: Replace single-character seq_puts with seq_putc
2014-09-12 9:25 [PATCH 0/6] Small seqfile-use improvements Rasmus Villemoes
` (4 preceding siblings ...)
2014-09-12 9:25 ` [PATCH 5/6] trace: Merge consecutive seq_puts calls Rasmus Villemoes
@ 2014-09-12 9:25 ` Rasmus Villemoes
5 siblings, 0 replies; 20+ messages in thread
From: Rasmus Villemoes @ 2014-09-12 9:25 UTC (permalink / raw)
To: Julia Lawall, Steven Rostedt, Ingo Molnar; +Cc: linux-kernel, Rasmus Villemoes
Printing a single character to a seqfile might as well be done with
seq_putc instead of seq_puts; this avoids a strlen() call and a memory
access. It also shaves another few bytes off the generated code.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
kernel/trace/ftrace.c | 2 +-
kernel/trace/trace_events_trigger.c | 4 ++--
kernel/trace/trace_functions_graph.c | 4 ++--
kernel/trace/trace_kprobe.c | 10 +++++-----
kernel/trace/trace_printk.c | 2 +-
kernel/trace/trace_uprobe.c | 4 ++--
6 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 7b9ce28..e931730 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -2969,7 +2969,7 @@ static int t_show(struct seq_file *m, void *v)
}
}
- seq_puts(m, "\n");
+ seq_putc(m, '\n');
return 0;
}
diff --git a/kernel/trace/trace_events_trigger.c b/kernel/trace/trace_events_trigger.c
index 3d89ffc..8712df9 100644
--- a/kernel/trace/trace_events_trigger.c
+++ b/kernel/trace/trace_events_trigger.c
@@ -383,7 +383,7 @@ event_trigger_print(const char *name, struct seq_file *m,
if (filter_str)
seq_printf(m, " if %s\n", filter_str);
else
- seq_puts(m, "\n");
+ seq_putc(m, '\n');
return 0;
}
@@ -1105,7 +1105,7 @@ event_enable_trigger_print(struct seq_file *m, struct event_trigger_ops *ops,
if (data->filter_str)
seq_printf(m, " if %s\n", data->filter_str);
else
- seq_puts(m, "\n");
+ seq_putc(m, '\n');
return 0;
}
diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c
index 29ba611..a82d1d3 100644
--- a/kernel/trace/trace_functions_graph.c
+++ b/kernel/trace/trace_functions_graph.c
@@ -1407,7 +1407,7 @@ static void __print_graph_headers_flags(struct seq_file *s, u32 flags)
print_lat_header(s, flags);
/* 1st line */
- seq_puts(s, "#");
+ seq_putc(s, '#');
if (flags & TRACE_GRAPH_PRINT_ABS_TIME)
seq_puts(s, " TIME ");
if (flags & TRACE_GRAPH_PRINT_CPU)
@@ -1421,7 +1421,7 @@ static void __print_graph_headers_flags(struct seq_file *s, u32 flags)
seq_puts(s, " FUNCTION CALLS\n");
/* 2nd line */
- seq_puts(s, "#");
+ seq_putc(s, '#');
if (flags & TRACE_GRAPH_PRINT_ABS_TIME)
seq_puts(s, " | ");
if (flags & TRACE_GRAPH_PRINT_CPU)
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index ce2ea71..ef7e7f1 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -840,7 +840,7 @@ static int probes_seq_show(struct seq_file *m, void *v)
for (i = 0; i < tk->tp.nr_args; i++)
seq_printf(m, " %s=%s", tk->tp.args[i].name, tk->tp.args[i].comm);
- seq_puts(m, "\n");
+ seq_putc(m, '\n');
return 0;
}
@@ -1030,7 +1030,7 @@ print_kprobe_event(struct trace_iterator *iter, int flags,
if (!seq_print_ip_sym(s, field->ip, flags | TRACE_ITER_SYM_OFFSET))
goto partial;
- if (!trace_seq_puts(s, ")"))
+ if (!trace_seq_putc(s, ')'))
goto partial;
data = (u8 *)&field[1];
@@ -1039,7 +1039,7 @@ print_kprobe_event(struct trace_iterator *iter, int flags,
data + tp->args[i].offset, field))
goto partial;
- if (!trace_seq_puts(s, "\n"))
+ if (!trace_seq_putc(s, '\n'))
goto partial;
return TRACE_TYPE_HANDLED;
@@ -1072,7 +1072,7 @@ print_kretprobe_event(struct trace_iterator *iter, int flags,
if (!seq_print_ip_sym(s, field->func, flags & ~TRACE_ITER_SYM_OFFSET))
goto partial;
- if (!trace_seq_puts(s, ")"))
+ if (!trace_seq_putc(s, ')'))
goto partial;
data = (u8 *)&field[1];
@@ -1081,7 +1081,7 @@ print_kretprobe_event(struct trace_iterator *iter, int flags,
data + tp->args[i].offset, field))
goto partial;
- if (!trace_seq_puts(s, "\n"))
+ if (!trace_seq_putc(s, '\n'))
goto partial;
return TRACE_TYPE_HANDLED;
diff --git a/kernel/trace/trace_printk.c b/kernel/trace/trace_printk.c
index 2900817..c4e70b6 100644
--- a/kernel/trace/trace_printk.c
+++ b/kernel/trace/trace_printk.c
@@ -305,7 +305,7 @@ static int t_show(struct seq_file *m, void *v)
seq_puts(m, "\\t");
break;
case '\\':
- seq_puts(m, "\\");
+ seq_putc(m, '\\');
break;
case '"':
seq_puts(m, "\\\"");
diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c
index 184aec1..e35327c 100644
--- a/kernel/trace/trace_uprobe.c
+++ b/kernel/trace/trace_uprobe.c
@@ -606,7 +606,7 @@ static int probes_seq_show(struct seq_file *m, void *v)
for (i = 0; i < tu->tp.nr_args; i++)
seq_printf(m, " %s=%s", tu->tp.args[i].name, tu->tp.args[i].comm);
- seq_puts(m, "\n");
+ seq_putc(m, '\n');
return 0;
}
@@ -872,7 +872,7 @@ print_uprobe_event(struct trace_iterator *iter, int flags, struct trace_event *e
goto partial;
}
- if (trace_seq_puts(s, "\n"))
+ if (trace_seq_putc(s, '\n'))
return TRACE_TYPE_HANDLED;
partial:
--
2.0.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: [PATCH 1/6] Coccinelle: Semantic patch for replacing puts with putc
2014-09-12 9:25 ` [PATCH 1/6] Coccinelle: Semantic patch for replacing puts with putc Rasmus Villemoes
@ 2014-09-12 11:08 ` SF Markus Elfring
0 siblings, 0 replies; 20+ messages in thread
From: SF Markus Elfring @ 2014-09-12 11:08 UTC (permalink / raw)
To: Rasmus Villemoes
Cc: Coccinelle, Steven Rostedt, Ingo Molnar, kernel-janitors,
linux-kernel
> Using seq_puts to write a one-character string is suboptimal,
> since puts has to call strlen().
Are there any more functions which work with such strings in a similar way?
Would it make sense to look also at other function names?
Regards,
Markus
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 4/6] trace: Replace seq_printf by simpler equivalents
2014-09-12 9:25 ` [PATCH 4/6] trace: Replace seq_printf by simpler equivalents Rasmus Villemoes
@ 2014-11-05 22:34 ` Steven Rostedt
2014-11-05 22:44 ` Rasmus Villemoes
2014-11-05 22:51 ` Joe Perches
2014-11-08 20:42 ` [PATCH v2 0/3] trace: Use simpler seq_file functions Rasmus Villemoes
1 sibling, 2 replies; 20+ messages in thread
From: Steven Rostedt @ 2014-11-05 22:34 UTC (permalink / raw)
To: Rasmus Villemoes; +Cc: Julia Lawall, Ingo Molnar, linux-kernel
On Fri, 12 Sep 2014 11:25:52 +0200
Rasmus Villemoes <linux@rasmusvillemoes.dk> wrote:
> Using seq_printf to print a simple string or a single character is a
> lot more expensive than it needs to be, since seq_puts and seq_putc
> exist.
>
> These patches do
>
> seq_printf(m, s) -> seq_puts(m, s)
> seq_printf(m, "%s", s) -> seq_puts(m, s)
> seq_printf(m, "%c", c) -> seq_putc(m, c)
>
> Subsequent patches will simplify further.
>
> Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
> ---
> kernel/trace/ftrace.c | 30 ++++++++++++------------
> kernel/trace/trace.c | 44 ++++++++++++++++++------------------
> kernel/trace/trace_branch.c | 24 +++++++++-----------
> kernel/trace/trace_events.c | 4 ++--
> kernel/trace/trace_events_trigger.c | 2 +-
> kernel/trace/trace_functions.c | 2 +-
> kernel/trace/trace_functions_graph.c | 28 +++++++++++------------
> kernel/trace/trace_kprobe.c | 4 ++--
> kernel/trace/trace_uprobe.c | 2 +-
> 9 files changed, 69 insertions(+), 71 deletions(-)
>
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index 5916a8e..7b9ce28 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -556,13 +556,13 @@ static int function_stat_cmp(void *p1, void *p2)
> static int function_stat_headers(struct seq_file *m)
> {
> #ifdef CONFIG_FUNCTION_GRAPH_TRACER
> - seq_printf(m, " Function "
> - "Hit Time Avg s^2\n"
> - " -------- "
> - "--- ---- --- ---\n");
> + seq_puts(m,
> + " Function " "Hit Time Avg s^2\n"
> + " -------- " "--- ---- --- ---\n");
Please keep the original format. I know that it's considered bad form
to split strings like this, but I consider this one of the exceptions
to the rule.
> #else
> - seq_printf(m, " Function Hit\n"
> - " -------- ---\n");
> + seq_puts(m,
> + " Function Hit\n"
> + " -------- ---\n");
> #endif
> return 0;
> }
> @@ -3250,7 +3250,7 @@ static int t_show(struct seq_file *m, void *v)
> if (!t)
> return 0;
>
> - seq_printf(m, "%s", t->name);
> + seq_puts(m, t->name);
This is wrong and dangerous.
What happens if "t->name" contains "%d" or "%s"?
> if (t->next)
> seq_putc(m, ' ');
> else
> @@ -5752,10 +5752,10 @@ ftrace_snapshot_print(struct seq_file *m, unsigned long ip,
>
> seq_printf(m, "%ps:", (void *)ip);
>
> - seq_printf(m, "snapshot");
> + seq_puts(m, "snapshot");
>
> if (count == -1)
> - seq_printf(m, ":unlimited\n");
> + seq_puts(m, ":unlimited\n");
> else
> seq_printf(m, ":count=%ld\n", count);
>
> static int all_branch_stat_headers(struct seq_file *m)
> {
> - seq_printf(m, " miss hit %% ");
> - seq_printf(m, " Function "
> - " File Line\n"
> - " ------- --------- - "
> - " -------- "
> - " ---- ----\n");
> + seq_puts(m, " miss hit % ");
> + seq_puts(m,
> + " Function " " File Line\n" " ------- --------- - " " -------- " " ---- ----\n");
Again, keep the original formatting. We can fix it up later, but not
with this patch.
> return 0;
> }
>
> --- a/kernel/trace/trace_events_trigger.c
> +++ b/kernel/trace/trace_events_trigger.c
> @@ -373,7 +373,7 @@ event_trigger_print(const char *name, struct seq_file *m,
> {
> long count = (long)data;
>
> - seq_printf(m, "%s", name);
> + seq_puts(m, name);
Again, this is wrong and dangerous.
-- Steve
>
> if (count == -1)
> seq_puts(m, ":unlimited");
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 4/6] trace: Replace seq_printf by simpler equivalents
2014-11-05 22:34 ` Steven Rostedt
@ 2014-11-05 22:44 ` Rasmus Villemoes
2014-11-06 0:34 ` Steven Rostedt
2014-11-05 22:51 ` Joe Perches
1 sibling, 1 reply; 20+ messages in thread
From: Rasmus Villemoes @ 2014-11-05 22:44 UTC (permalink / raw)
To: Steven Rostedt; +Cc: Julia Lawall, Ingo Molnar, linux-kernel
On Wed, Nov 05 2014, Steven Rostedt <rostedt@goodmis.org> wrote:
> On Fri, 12 Sep 2014 11:25:52 +0200
> Rasmus Villemoes <linux@rasmusvillemoes.dk> wrote:
>
>> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
>> index 5916a8e..7b9ce28 100644
>> --- a/kernel/trace/ftrace.c
>> +++ b/kernel/trace/ftrace.c
>> @@ -556,13 +556,13 @@ static int function_stat_cmp(void *p1, void *p2)
>> static int function_stat_headers(struct seq_file *m)
>> {
>> #ifdef CONFIG_FUNCTION_GRAPH_TRACER
>> - seq_printf(m, " Function "
>> - "Hit Time Avg s^2\n"
>> - " -------- "
>> - "--- ---- --- ---\n");
>> + seq_puts(m,
>> + " Function " "Hit Time Avg s^2\n"
>> + " -------- " "--- ---- --- ---\n");
>
> Please keep the original format. I know that it's considered bad form
> to split strings like this, but I consider this one of the exceptions
> to the rule.
OK. Want me to resend?
>> @@ -3250,7 +3250,7 @@ static int t_show(struct seq_file *m, void *v)
>> if (!t)
>> return 0;
>>
>> - seq_printf(m, "%s", t->name);
>> + seq_puts(m, t->name);
>
> This is wrong and dangerous.
>
> What happens if "t->name" contains "%d" or "%s"?
Then those characters will be printed to the seq_file, just as they
would previously? puts doesn't interpret its string argument in any
way...
>> --- a/kernel/trace/trace_events_trigger.c
>> +++ b/kernel/trace/trace_events_trigger.c
>> @@ -373,7 +373,7 @@ event_trigger_print(const char *name, struct seq_file *m,
>> {
>> long count = (long)data;
>>
>> - seq_printf(m, "%s", name);
>> + seq_puts(m, name);
>
> Again, this is wrong and dangerous.
I'm pretty sure it's neither :-)
Rasmus
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 4/6] trace: Replace seq_printf by simpler equivalents
2014-11-05 22:34 ` Steven Rostedt
2014-11-05 22:44 ` Rasmus Villemoes
@ 2014-11-05 22:51 ` Joe Perches
2014-11-06 0:38 ` Steven Rostedt
1 sibling, 1 reply; 20+ messages in thread
From: Joe Perches @ 2014-11-05 22:51 UTC (permalink / raw)
To: Steven Rostedt; +Cc: Rasmus Villemoes, Julia Lawall, Ingo Molnar, linux-kernel
On Wed, 2014-11-05 at 17:34 -0500, Steven Rostedt wrote:
> On Fri, 12 Sep 2014 11:25:52 +0200 Rasmus Villemoes <linux@rasmusvillemoes.dk> wrote:
> > Using seq_printf to print a simple string or a single character is a
> > lot more expensive than it needs to be, since seq_puts and seq_putc
> > exist.
[]
> > diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
[]
> @@ -556,13 +556,13 @@ static int function_stat_cmp(void *p1, void *p2)
> > static int function_stat_headers(struct seq_file *m)
> > {
> > #ifdef CONFIG_FUNCTION_GRAPH_TRACER
> > - seq_printf(m, " Function "
> > - "Hit Time Avg s^2\n"
> > - " -------- "
> > - "--- ---- --- ---\n");
> > + seq_puts(m,
> > + " Function " "Hit Time Avg s^2\n"
> > + " -------- " "--- ---- --- ---\n");
>
> Please keep the original format. I know that it's considered bad form
> to split strings like this, but I consider this one of the exceptions
> to the rule.
Why is that?
btw: when the strings fragments are put on the same line,
it's nicer to take out the intermediate joining " " bits too.
I'd've probably used 2 seq_puts calls like:
seq_puts(m, " Function Hit Time Avg s^2\n");
seq_puts(m, " -------- --- ---- --- ---\n");
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 4/6] trace: Replace seq_printf by simpler equivalents
2014-11-05 22:44 ` Rasmus Villemoes
@ 2014-11-06 0:34 ` Steven Rostedt
0 siblings, 0 replies; 20+ messages in thread
From: Steven Rostedt @ 2014-11-06 0:34 UTC (permalink / raw)
To: Rasmus Villemoes; +Cc: Julia Lawall, Ingo Molnar, linux-kernel
On Wed, 05 Nov 2014 23:44:17 +0100
Rasmus Villemoes <linux@rasmusvillemoes.dk> wrote:
> On Wed, Nov 05 2014, Steven Rostedt <rostedt@goodmis.org> wrote:
>
> > On Fri, 12 Sep 2014 11:25:52 +0200
> > Rasmus Villemoes <linux@rasmusvillemoes.dk> wrote:
> >
> >> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> >> index 5916a8e..7b9ce28 100644
> >> --- a/kernel/trace/ftrace.c
> >> +++ b/kernel/trace/ftrace.c
> >> @@ -556,13 +556,13 @@ static int function_stat_cmp(void *p1, void *p2)
> >> static int function_stat_headers(struct seq_file *m)
> >> {
> >> #ifdef CONFIG_FUNCTION_GRAPH_TRACER
> >> - seq_printf(m, " Function "
> >> - "Hit Time Avg s^2\n"
> >> - " -------- "
> >> - "--- ---- --- ---\n");
> >> + seq_puts(m,
> >> + " Function " "Hit Time Avg s^2\n"
> >> + " -------- " "--- ---- --- ---\n");
> >
> > Please keep the original format. I know that it's considered bad form
> > to split strings like this, but I consider this one of the exceptions
> > to the rule.
>
> OK. Want me to resend?
Yeah, can you.
>
> >> @@ -3250,7 +3250,7 @@ static int t_show(struct seq_file *m, void *v)
> >> if (!t)
> >> return 0;
> >>
> >> - seq_printf(m, "%s", t->name);
> >> + seq_puts(m, t->name);
> >
> > This is wrong and dangerous.
> >
> > What happens if "t->name" contains "%d" or "%s"?
>
> Then those characters will be printed to the seq_file, just as they
> would previously? puts doesn't interpret its string argument in any
> way...
>
> >> --- a/kernel/trace/trace_events_trigger.c
> >> +++ b/kernel/trace/trace_events_trigger.c
> >> @@ -373,7 +373,7 @@ event_trigger_print(const char *name, struct seq_file *m,
> >> {
> >> long count = (long)data;
> >>
> >> - seq_printf(m, "%s", name);
> >> + seq_puts(m, name);
> >
> > Again, this is wrong and dangerous.
>
> I'm pretty sure it's neither :-)
Ah you're correct. I was thinking of it as a printf and not a puts.
Never mind ;-) /me needs to work on only 3 different projects at once,
not 4. :-p
-- Steve
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 4/6] trace: Replace seq_printf by simpler equivalents
2014-11-05 22:51 ` Joe Perches
@ 2014-11-06 0:38 ` Steven Rostedt
2014-11-06 0:47 ` Joe Perches
0 siblings, 1 reply; 20+ messages in thread
From: Steven Rostedt @ 2014-11-06 0:38 UTC (permalink / raw)
To: Joe Perches; +Cc: Rasmus Villemoes, Julia Lawall, Ingo Molnar, linux-kernel
On Wed, 05 Nov 2014 14:51:48 -0800
Joe Perches <joe@perches.com> wrote:
> On Wed, 2014-11-05 at 17:34 -0500, Steven Rostedt wrote:
> > On Fri, 12 Sep 2014 11:25:52 +0200 Rasmus Villemoes <linux@rasmusvillemoes.dk> wrote:
> > > Using seq_printf to print a simple string or a single character is a
> > > lot more expensive than it needs to be, since seq_puts and seq_putc
> > > exist.
> []
> > > diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> []
> > @@ -556,13 +556,13 @@ static int function_stat_cmp(void *p1, void *p2)
> > > static int function_stat_headers(struct seq_file *m)
> > > {
> > > #ifdef CONFIG_FUNCTION_GRAPH_TRACER
> > > - seq_printf(m, " Function "
> > > - "Hit Time Avg s^2\n"
> > > - " -------- "
> > > - "--- ---- --- ---\n");
> > > + seq_puts(m,
> > > + " Function " "Hit Time Avg s^2\n"
> > > + " -------- " "--- ---- --- ---\n");
> >
> > Please keep the original format. I know that it's considered bad form
> > to split strings like this, but I consider this one of the exceptions
> > to the rule.
>
> Why is that?
>
> btw: when the strings fragments are put on the same line,
> it's nicer to take out the intermediate joining " " bits too.
>
> I'd've probably used 2 seq_puts calls like:
>
> seq_puts(m, " Function Hit Time Avg s^2\n");
> seq_puts(m, " -------- --- ---- --- ---\n");
>
In this case it's just that I hate that big white space followed by
content.
Maybe I'll change my mind in the future, but for now, I'd rather just
leave it as is.
-- Steve
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 4/6] trace: Replace seq_printf by simpler equivalents
2014-11-06 0:38 ` Steven Rostedt
@ 2014-11-06 0:47 ` Joe Perches
0 siblings, 0 replies; 20+ messages in thread
From: Joe Perches @ 2014-11-06 0:47 UTC (permalink / raw)
To: Steven Rostedt; +Cc: Rasmus Villemoes, Julia Lawall, Ingo Molnar, linux-kernel
On Wed, 2014-11-05 at 19:38 -0500, Steven Rostedt wrote:
> On Wed, 05 Nov 2014 14:51:48 -0800 Joe Perches <joe@perches.com> wrote:
[]
> > > I know that it's considered bad form
> > > to split strings like this, but I consider this one of the exceptions
> > > to the rule.
> >
> > Why is that?
> >
> > btw: when the strings fragments are put on the same line,
> > it's nicer to take out the intermediate joining " " bits too.
> >
> > I'd've probably used 2 seq_puts calls like:
> >
> > seq_puts(m, " Function Hit Time Avg s^2\n");
> > seq_puts(m, " -------- --- ---- --- ---\n");
> >
>
> In this case it's just that I hate that big white space followed by
> content.
>
> Maybe I'll change my mind in the future, but for now, I'd rather just
> leave it as is.
My eyes generally skip over the embedded whitespace.
It's also generally less code space to use a single format string
instead of something like:
printf(" %-39s%-7s%-16s%-16s%s\n", "Function", "Hit", "Time", "Avg", "s^2");
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v2 0/3] trace: Use simpler seq_file functions
2014-09-12 9:25 ` [PATCH 4/6] trace: Replace seq_printf by simpler equivalents Rasmus Villemoes
2014-11-05 22:34 ` Steven Rostedt
@ 2014-11-08 20:42 ` Rasmus Villemoes
2014-11-08 20:42 ` [PATCH v2 1/3] trace: Replace seq_printf by simpler equivalents Rasmus Villemoes
` (2 more replies)
1 sibling, 3 replies; 20+ messages in thread
From: Rasmus Villemoes @ 2014-11-08 20:42 UTC (permalink / raw)
To: Steven Rostedt, Ingo Molnar; +Cc: linux-kernel, Joe Perches, Rasmus Villemoes
Using printf to print a simple string or puts to print a single
character is more expensive than it needs to be. Also, consecutive
puts calls can be replaced by a single call. These patches do this to
kernel/trace/, saving ~256 bytes of .text.
v2: Keep the original splitting of strings across lines.
Rasmus Villemoes (3):
trace: Replace seq_printf by simpler equivalents
trace: Merge consecutive seq_puts calls
trace: Replace single-character seq_puts with seq_putc
kernel/trace/ftrace.c | 30 +++++++-------
kernel/trace/trace.c | 78 ++++++++++++++++++------------------
kernel/trace/trace_branch.c | 32 +++++++--------
kernel/trace/trace_events.c | 4 +-
kernel/trace/trace_events_trigger.c | 6 +--
kernel/trace/trace_functions.c | 2 +-
kernel/trace/trace_functions_graph.c | 28 ++++++-------
kernel/trace/trace_kprobe.c | 12 +++---
kernel/trace/trace_printk.c | 2 +-
kernel/trace/trace_uprobe.c | 4 +-
10 files changed, 99 insertions(+), 99 deletions(-)
--
2.0.4
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v2 1/3] trace: Replace seq_printf by simpler equivalents
2014-11-08 20:42 ` [PATCH v2 0/3] trace: Use simpler seq_file functions Rasmus Villemoes
@ 2014-11-08 20:42 ` Rasmus Villemoes
2014-11-14 2:31 ` Steven Rostedt
2014-11-08 20:42 ` [PATCH v2 2/3] trace: Merge consecutive seq_puts calls Rasmus Villemoes
2014-11-08 20:42 ` [PATCH v2 3/3] trace: Replace single-character seq_puts with seq_putc Rasmus Villemoes
2 siblings, 1 reply; 20+ messages in thread
From: Rasmus Villemoes @ 2014-11-08 20:42 UTC (permalink / raw)
To: Steven Rostedt, Ingo Molnar; +Cc: linux-kernel, Joe Perches, Rasmus Villemoes
Using seq_printf to print a simple string or a single character is a
lot more expensive than it needs to be, since seq_puts and seq_putc
exist.
These patches do
seq_printf(m, s) -> seq_puts(m, s)
seq_printf(m, "%s", s) -> seq_puts(m, s)
seq_printf(m, "%c", c) -> seq_putc(m, c)
Subsequent patches will simplify further.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
kernel/trace/ftrace.c | 30 ++++++++++++------------
kernel/trace/trace.c | 44 ++++++++++++++++++------------------
kernel/trace/trace_branch.c | 26 ++++++++++-----------
kernel/trace/trace_events.c | 4 ++--
kernel/trace/trace_events_trigger.c | 2 +-
kernel/trace/trace_functions.c | 2 +-
kernel/trace/trace_functions_graph.c | 28 +++++++++++------------
kernel/trace/trace_kprobe.c | 4 ++--
kernel/trace/trace_uprobe.c | 2 +-
9 files changed, 71 insertions(+), 71 deletions(-)
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 5916a8e..7890718 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -556,13 +556,13 @@ static int function_stat_cmp(void *p1, void *p2)
static int function_stat_headers(struct seq_file *m)
{
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
- seq_printf(m, " Function "
- "Hit Time Avg s^2\n"
- " -------- "
- "--- ---- --- ---\n");
+ seq_puts(m, " Function "
+ "Hit Time Avg s^2\n"
+ " -------- "
+ "--- ---- --- ---\n");
#else
- seq_printf(m, " Function Hit\n"
- " -------- ---\n");
+ seq_puts(m, " Function Hit\n"
+ " -------- ---\n");
#endif
return 0;
}
@@ -589,7 +589,7 @@ static int function_stat_show(struct seq_file *m, void *v)
seq_printf(m, " %-30.30s %10lu", str, rec->counter);
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
- seq_printf(m, " ");
+ seq_puts(m, " ");
avg = rec->time;
do_div(avg, rec->counter);
@@ -2941,9 +2941,9 @@ static int t_show(struct seq_file *m, void *v)
if (iter->flags & FTRACE_ITER_PRINTALL) {
if (iter->flags & FTRACE_ITER_NOTRACE)
- seq_printf(m, "#### no functions disabled ####\n");
+ seq_puts(m, "#### no functions disabled ####\n");
else
- seq_printf(m, "#### all functions enabled ####\n");
+ seq_puts(m, "#### all functions enabled ####\n");
return 0;
}
@@ -2965,11 +2965,11 @@ static int t_show(struct seq_file *m, void *v)
seq_printf(m, "\ttramp: %pS",
(void *)ops->trampoline);
else
- seq_printf(m, "\ttramp: ERROR!");
+ seq_puts(m, "\ttramp: ERROR!");
}
}
- seq_printf(m, "\n");
+ seq_puts(m, "\n");
return 0;
}
@@ -4149,9 +4149,9 @@ static int g_show(struct seq_file *m, void *v)
struct ftrace_graph_data *fgd = m->private;
if (fgd->table == ftrace_graph_funcs)
- seq_printf(m, "#### all functions enabled ####\n");
+ seq_puts(m, "#### all functions enabled ####\n");
else
- seq_printf(m, "#### no functions disabled ####\n");
+ seq_puts(m, "#### no functions disabled ####\n");
return 0;
}
@@ -4989,12 +4989,12 @@ static int fpid_show(struct seq_file *m, void *v)
const struct ftrace_pid *fpid = list_entry(v, struct ftrace_pid, list);
if (v == (void *)1) {
- seq_printf(m, "no pid\n");
+ seq_puts(m, "no pid\n");
return 0;
}
if (fpid->pid == ftrace_swapper_pid)
- seq_printf(m, "swapper tasks\n");
+ seq_puts(m, "swapper tasks\n");
else
seq_printf(m, "%u\n", pid_vnr(fpid->pid));
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 8a52839..77bb64f 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -2859,44 +2859,44 @@ static void test_ftrace_alive(struct seq_file *m)
{
if (!ftrace_is_dead())
return;
- seq_printf(m, "# WARNING: FUNCTION TRACING IS CORRUPTED\n");
- seq_printf(m, "# MAY BE MISSING FUNCTION EVENTS\n");
+ seq_puts(m, "# WARNING: FUNCTION TRACING IS CORRUPTED\n");
+ seq_puts(m, "# MAY BE MISSING FUNCTION EVENTS\n");
}
#ifdef CONFIG_TRACER_MAX_TRACE
static void show_snapshot_main_help(struct seq_file *m)
{
- seq_printf(m, "# echo 0 > snapshot : Clears and frees snapshot buffer\n");
- seq_printf(m, "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n");
- seq_printf(m, "# Takes a snapshot of the main buffer.\n");
- seq_printf(m, "# echo 2 > snapshot : Clears snapshot buffer (but does not allocate or free)\n");
- seq_printf(m, "# (Doesn't have to be '2' works with any number that\n");
- seq_printf(m, "# is not a '0' or '1')\n");
+ seq_puts(m, "# echo 0 > snapshot : Clears and frees snapshot buffer\n");
+ seq_puts(m, "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n");
+ seq_puts(m, "# Takes a snapshot of the main buffer.\n");
+ seq_puts(m, "# echo 2 > snapshot : Clears snapshot buffer (but does not allocate or free)\n");
+ seq_puts(m, "# (Doesn't have to be '2' works with any number that\n");
+ seq_puts(m, "# is not a '0' or '1')\n");
}
static void show_snapshot_percpu_help(struct seq_file *m)
{
- seq_printf(m, "# echo 0 > snapshot : Invalid for per_cpu snapshot file.\n");
+ seq_puts(m, "# echo 0 > snapshot : Invalid for per_cpu snapshot file.\n");
#ifdef CONFIG_RING_BUFFER_ALLOW_SWAP
- seq_printf(m, "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n");
- seq_printf(m, "# Takes a snapshot of the main buffer for this cpu.\n");
+ seq_puts(m, "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n");
+ seq_puts(m, "# Takes a snapshot of the main buffer for this cpu.\n");
#else
- seq_printf(m, "# echo 1 > snapshot : Not supported with this kernel.\n");
- seq_printf(m, "# Must use main snapshot file to allocate.\n");
+ seq_puts(m, "# echo 1 > snapshot : Not supported with this kernel.\n");
+ seq_puts(m, "# Must use main snapshot file to allocate.\n");
#endif
- seq_printf(m, "# echo 2 > snapshot : Clears this cpu's snapshot buffer (but does not allocate)\n");
- seq_printf(m, "# (Doesn't have to be '2' works with any number that\n");
- seq_printf(m, "# is not a '0' or '1')\n");
+ seq_puts(m, "# echo 2 > snapshot : Clears this cpu's snapshot buffer (but does not allocate)\n");
+ seq_puts(m, "# (Doesn't have to be '2' works with any number that\n");
+ seq_puts(m, "# is not a '0' or '1')\n");
}
static void print_snapshot_help(struct seq_file *m, struct trace_iterator *iter)
{
if (iter->tr->allocated_snapshot)
- seq_printf(m, "#\n# * Snapshot is allocated *\n#\n");
+ seq_puts(m, "#\n# * Snapshot is allocated *\n#\n");
else
- seq_printf(m, "#\n# * Snapshot is freed *\n#\n");
+ seq_puts(m, "#\n# * Snapshot is freed *\n#\n");
- seq_printf(m, "# Snapshot commands:\n");
+ seq_puts(m, "# Snapshot commands:\n");
if (iter->cpu_file == RING_BUFFER_ALL_CPUS)
show_snapshot_main_help(m);
else
@@ -3250,7 +3250,7 @@ static int t_show(struct seq_file *m, void *v)
if (!t)
return 0;
- seq_printf(m, "%s", t->name);
+ seq_puts(m, t->name);
if (t->next)
seq_putc(m, ' ');
else
@@ -5752,10 +5752,10 @@ ftrace_snapshot_print(struct seq_file *m, unsigned long ip,
seq_printf(m, "%ps:", (void *)ip);
- seq_printf(m, "snapshot");
+ seq_puts(m, "snapshot");
if (count == -1)
- seq_printf(m, ":unlimited\n");
+ seq_puts(m, ":unlimited\n");
else
seq_printf(m, ":count=%ld\n", count);
diff --git a/kernel/trace/trace_branch.c b/kernel/trace/trace_branch.c
index 697fb9b..126c622 100644
--- a/kernel/trace/trace_branch.c
+++ b/kernel/trace/trace_branch.c
@@ -233,12 +233,12 @@ extern unsigned long __stop_annotated_branch_profile[];
static int annotated_branch_stat_headers(struct seq_file *m)
{
- seq_printf(m, " correct incorrect %% ");
- seq_printf(m, " Function "
- " File Line\n"
- " ------- --------- - "
- " -------- "
- " ---- ----\n");
+ seq_puts(m, " correct incorrect % ");
+ seq_puts(m, " Function "
+ " File Line\n"
+ " ------- --------- - "
+ " -------- "
+ " ---- ----\n");
return 0;
}
@@ -274,7 +274,7 @@ static int branch_stat_show(struct seq_file *m, void *v)
seq_printf(m, "%8lu %8lu ", p->correct, p->incorrect);
if (percent < 0)
- seq_printf(m, " X ");
+ seq_puts(m, " X ");
else
seq_printf(m, "%3ld ", percent);
seq_printf(m, "%-30.30s %-20.20s %d\n", p->func, f, p->line);
@@ -362,12 +362,12 @@ extern unsigned long __stop_branch_profile[];
static int all_branch_stat_headers(struct seq_file *m)
{
- seq_printf(m, " miss hit %% ");
- seq_printf(m, " Function "
- " File Line\n"
- " ------- --------- - "
- " -------- "
- " ---- ----\n");
+ seq_puts(m, " miss hit % ");
+ seq_puts(m, " Function "
+ " File Line\n"
+ " ------- --------- - "
+ " -------- "
+ " ---- ----\n");
return 0;
}
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index ef06ce7..32f0199 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -918,7 +918,7 @@ static int f_show(struct seq_file *m, void *v)
case FORMAT_HEADER:
seq_printf(m, "name: %s\n", ftrace_event_name(call));
seq_printf(m, "ID: %d\n", call->event.type);
- seq_printf(m, "format:\n");
+ seq_puts(m, "format:\n");
return 0;
case FORMAT_FIELD_SEPERATOR:
@@ -1988,7 +1988,7 @@ event_enable_print(struct seq_file *m, unsigned long ip,
ftrace_event_name(data->file->event_call));
if (data->count == -1)
- seq_printf(m, ":unlimited\n");
+ seq_puts(m, ":unlimited\n");
else
seq_printf(m, ":count=%ld\n", data->count);
diff --git a/kernel/trace/trace_events_trigger.c b/kernel/trace/trace_events_trigger.c
index 4747b47..3d89ffc 100644
--- a/kernel/trace/trace_events_trigger.c
+++ b/kernel/trace/trace_events_trigger.c
@@ -373,7 +373,7 @@ event_trigger_print(const char *name, struct seq_file *m,
{
long count = (long)data;
- seq_printf(m, "%s", name);
+ seq_puts(m, name);
if (count == -1)
seq_puts(m, ":unlimited");
diff --git a/kernel/trace/trace_functions.c b/kernel/trace/trace_functions.c
index 57f0ec9..a8e0c76 100644
--- a/kernel/trace/trace_functions.c
+++ b/kernel/trace/trace_functions.c
@@ -361,7 +361,7 @@ ftrace_probe_print(const char *name, struct seq_file *m,
seq_printf(m, "%ps:%s", (void *)ip, name);
if (count == -1)
- seq_printf(m, ":unlimited\n");
+ seq_puts(m, ":unlimited\n");
else
seq_printf(m, ":count=%ld\n", count);
diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c
index f0a0c98..29ba611 100644
--- a/kernel/trace/trace_functions_graph.c
+++ b/kernel/trace/trace_functions_graph.c
@@ -1407,32 +1407,32 @@ static void __print_graph_headers_flags(struct seq_file *s, u32 flags)
print_lat_header(s, flags);
/* 1st line */
- seq_printf(s, "#");
+ seq_puts(s, "#");
if (flags & TRACE_GRAPH_PRINT_ABS_TIME)
- seq_printf(s, " TIME ");
+ seq_puts(s, " TIME ");
if (flags & TRACE_GRAPH_PRINT_CPU)
- seq_printf(s, " CPU");
+ seq_puts(s, " CPU");
if (flags & TRACE_GRAPH_PRINT_PROC)
- seq_printf(s, " TASK/PID ");
+ seq_puts(s, " TASK/PID ");
if (lat)
- seq_printf(s, "||||");
+ seq_puts(s, "||||");
if (flags & TRACE_GRAPH_PRINT_DURATION)
- seq_printf(s, " DURATION ");
- seq_printf(s, " FUNCTION CALLS\n");
+ seq_puts(s, " DURATION ");
+ seq_puts(s, " FUNCTION CALLS\n");
/* 2nd line */
- seq_printf(s, "#");
+ seq_puts(s, "#");
if (flags & TRACE_GRAPH_PRINT_ABS_TIME)
- seq_printf(s, " | ");
+ seq_puts(s, " | ");
if (flags & TRACE_GRAPH_PRINT_CPU)
- seq_printf(s, " | ");
+ seq_puts(s, " | ");
if (flags & TRACE_GRAPH_PRINT_PROC)
- seq_printf(s, " | | ");
+ seq_puts(s, " | | ");
if (lat)
- seq_printf(s, "||||");
+ seq_puts(s, "||||");
if (flags & TRACE_GRAPH_PRINT_DURATION)
- seq_printf(s, " | | ");
- seq_printf(s, " | | | |\n");
+ seq_puts(s, " | | ");
+ seq_puts(s, " | | | |\n");
}
static void print_graph_headers(struct seq_file *s)
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index 282f6e4..ce2ea71 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -826,7 +826,7 @@ static int probes_seq_show(struct seq_file *m, void *v)
struct trace_kprobe *tk = v;
int i;
- seq_printf(m, "%c", trace_kprobe_is_return(tk) ? 'r' : 'p');
+ seq_putc(m, trace_kprobe_is_return(tk) ? 'r' : 'p');
seq_printf(m, ":%s/%s", tk->tp.call.class->system,
ftrace_event_name(&tk->tp.call));
@@ -840,7 +840,7 @@ static int probes_seq_show(struct seq_file *m, void *v)
for (i = 0; i < tk->tp.nr_args; i++)
seq_printf(m, " %s=%s", tk->tp.args[i].name, tk->tp.args[i].comm);
- seq_printf(m, "\n");
+ seq_puts(m, "\n");
return 0;
}
diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c
index 33ff6a2..184aec1 100644
--- a/kernel/trace/trace_uprobe.c
+++ b/kernel/trace/trace_uprobe.c
@@ -606,7 +606,7 @@ static int probes_seq_show(struct seq_file *m, void *v)
for (i = 0; i < tu->tp.nr_args; i++)
seq_printf(m, " %s=%s", tu->tp.args[i].name, tu->tp.args[i].comm);
- seq_printf(m, "\n");
+ seq_puts(m, "\n");
return 0;
}
--
2.0.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH v2 2/3] trace: Merge consecutive seq_puts calls
2014-11-08 20:42 ` [PATCH v2 0/3] trace: Use simpler seq_file functions Rasmus Villemoes
2014-11-08 20:42 ` [PATCH v2 1/3] trace: Replace seq_printf by simpler equivalents Rasmus Villemoes
@ 2014-11-08 20:42 ` Rasmus Villemoes
2014-11-08 20:42 ` [PATCH v2 3/3] trace: Replace single-character seq_puts with seq_putc Rasmus Villemoes
2 siblings, 0 replies; 20+ messages in thread
From: Rasmus Villemoes @ 2014-11-08 20:42 UTC (permalink / raw)
To: Steven Rostedt, Ingo Molnar; +Cc: linux-kernel, Joe Perches, Rasmus Villemoes
Consecutive seq_puts calls with literal strings can be merged to a
single call. This reduces the size of the generated code, and can also
lead to slight .rodata reduction (because of fewer nul and padding
bytes). It should also shave a off a few clock cycles.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
kernel/trace/trace.c | 64 ++++++++++++++++++++++-----------------------
kernel/trace/trace_branch.c | 14 +++++-----
2 files changed, 39 insertions(+), 39 deletions(-)
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 77bb64f..32fb5a4 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -2508,14 +2508,14 @@ get_total_entries(struct trace_buffer *buf,
static void print_lat_help_header(struct seq_file *m)
{
- seq_puts(m, "# _------=> CPU# \n");
- seq_puts(m, "# / _-----=> irqs-off \n");
- seq_puts(m, "# | / _----=> need-resched \n");
- seq_puts(m, "# || / _---=> hardirq/softirq \n");
- seq_puts(m, "# ||| / _--=> preempt-depth \n");
- seq_puts(m, "# |||| / delay \n");
- seq_puts(m, "# cmd pid ||||| time | caller \n");
- seq_puts(m, "# \\ / ||||| \\ | / \n");
+ seq_puts(m, "# _------=> CPU# \n"
+ "# / _-----=> irqs-off \n"
+ "# | / _----=> need-resched \n"
+ "# || / _---=> hardirq/softirq \n"
+ "# ||| / _--=> preempt-depth \n"
+ "# |||| / delay \n"
+ "# cmd pid ||||| time | caller \n"
+ "# \\ / ||||| \\ | / \n");
}
static void print_event_info(struct trace_buffer *buf, struct seq_file *m)
@@ -2532,20 +2532,20 @@ static void print_event_info(struct trace_buffer *buf, struct seq_file *m)
static void print_func_help_header(struct trace_buffer *buf, struct seq_file *m)
{
print_event_info(buf, m);
- seq_puts(m, "# TASK-PID CPU# TIMESTAMP FUNCTION\n");
- seq_puts(m, "# | | | | |\n");
+ seq_puts(m, "# TASK-PID CPU# TIMESTAMP FUNCTION\n"
+ "# | | | | |\n");
}
static void print_func_help_header_irq(struct trace_buffer *buf, struct seq_file *m)
{
print_event_info(buf, m);
- seq_puts(m, "# _-----=> irqs-off\n");
- seq_puts(m, "# / _----=> need-resched\n");
- seq_puts(m, "# | / _---=> hardirq/softirq\n");
- seq_puts(m, "# || / _--=> preempt-depth\n");
- seq_puts(m, "# ||| / delay\n");
- seq_puts(m, "# TASK-PID CPU# |||| TIMESTAMP FUNCTION\n");
- seq_puts(m, "# | | | |||| | |\n");
+ seq_puts(m, "# _-----=> irqs-off\n"
+ "# / _----=> need-resched\n"
+ "# | / _---=> hardirq/softirq\n"
+ "# || / _--=> preempt-depth\n"
+ "# ||| / delay\n"
+ "# TASK-PID CPU# |||| TIMESTAMP FUNCTION\n"
+ "# | | | |||| | |\n");
}
void
@@ -2859,34 +2859,34 @@ static void test_ftrace_alive(struct seq_file *m)
{
if (!ftrace_is_dead())
return;
- seq_puts(m, "# WARNING: FUNCTION TRACING IS CORRUPTED\n");
- seq_puts(m, "# MAY BE MISSING FUNCTION EVENTS\n");
+ seq_puts(m, "# WARNING: FUNCTION TRACING IS CORRUPTED\n"
+ "# MAY BE MISSING FUNCTION EVENTS\n");
}
#ifdef CONFIG_TRACER_MAX_TRACE
static void show_snapshot_main_help(struct seq_file *m)
{
- seq_puts(m, "# echo 0 > snapshot : Clears and frees snapshot buffer\n");
- seq_puts(m, "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n");
- seq_puts(m, "# Takes a snapshot of the main buffer.\n");
- seq_puts(m, "# echo 2 > snapshot : Clears snapshot buffer (but does not allocate or free)\n");
- seq_puts(m, "# (Doesn't have to be '2' works with any number that\n");
- seq_puts(m, "# is not a '0' or '1')\n");
+ seq_puts(m, "# echo 0 > snapshot : Clears and frees snapshot buffer\n"
+ "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n"
+ "# Takes a snapshot of the main buffer.\n"
+ "# echo 2 > snapshot : Clears snapshot buffer (but does not allocate or free)\n"
+ "# (Doesn't have to be '2' works with any number that\n"
+ "# is not a '0' or '1')\n");
}
static void show_snapshot_percpu_help(struct seq_file *m)
{
seq_puts(m, "# echo 0 > snapshot : Invalid for per_cpu snapshot file.\n");
#ifdef CONFIG_RING_BUFFER_ALLOW_SWAP
- seq_puts(m, "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n");
- seq_puts(m, "# Takes a snapshot of the main buffer for this cpu.\n");
+ seq_puts(m, "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n"
+ "# Takes a snapshot of the main buffer for this cpu.\n");
#else
- seq_puts(m, "# echo 1 > snapshot : Not supported with this kernel.\n");
- seq_puts(m, "# Must use main snapshot file to allocate.\n");
+ seq_puts(m, "# echo 1 > snapshot : Not supported with this kernel.\n"
+ "# Must use main snapshot file to allocate.\n");
#endif
- seq_puts(m, "# echo 2 > snapshot : Clears this cpu's snapshot buffer (but does not allocate)\n");
- seq_puts(m, "# (Doesn't have to be '2' works with any number that\n");
- seq_puts(m, "# is not a '0' or '1')\n");
+ seq_puts(m, "# echo 2 > snapshot : Clears this cpu's snapshot buffer (but does not allocate)\n"
+ "# (Doesn't have to be '2' works with any number that\n"
+ "# is not a '0' or '1')\n");
}
static void print_snapshot_help(struct seq_file *m, struct trace_iterator *iter)
diff --git a/kernel/trace/trace_branch.c b/kernel/trace/trace_branch.c
index 126c622..a3916f6 100644
--- a/kernel/trace/trace_branch.c
+++ b/kernel/trace/trace_branch.c
@@ -164,9 +164,9 @@ static enum print_line_t trace_branch_print(struct trace_iterator *iter,
static void branch_print_header(struct seq_file *s)
{
seq_puts(s, "# TASK-PID CPU# TIMESTAMP CORRECT"
- " FUNC:FILE:LINE\n");
- seq_puts(s, "# | | | | | "
- " |\n");
+ " FUNC:FILE:LINE\n"
+ "# | | | | | "
+ " |\n");
}
static struct trace_event_functions trace_branch_funcs = {
@@ -233,8 +233,8 @@ extern unsigned long __stop_annotated_branch_profile[];
static int annotated_branch_stat_headers(struct seq_file *m)
{
- seq_puts(m, " correct incorrect % ");
- seq_puts(m, " Function "
+ seq_puts(m, " correct incorrect % "
+ " Function "
" File Line\n"
" ------- --------- - "
" -------- "
@@ -362,8 +362,8 @@ extern unsigned long __stop_branch_profile[];
static int all_branch_stat_headers(struct seq_file *m)
{
- seq_puts(m, " miss hit % ");
- seq_puts(m, " Function "
+ seq_puts(m, " miss hit % "
+ " Function "
" File Line\n"
" ------- --------- - "
" -------- "
--
2.0.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH v2 3/3] trace: Replace single-character seq_puts with seq_putc
2014-11-08 20:42 ` [PATCH v2 0/3] trace: Use simpler seq_file functions Rasmus Villemoes
2014-11-08 20:42 ` [PATCH v2 1/3] trace: Replace seq_printf by simpler equivalents Rasmus Villemoes
2014-11-08 20:42 ` [PATCH v2 2/3] trace: Merge consecutive seq_puts calls Rasmus Villemoes
@ 2014-11-08 20:42 ` Rasmus Villemoes
2014-11-14 2:34 ` Steven Rostedt
2 siblings, 1 reply; 20+ messages in thread
From: Rasmus Villemoes @ 2014-11-08 20:42 UTC (permalink / raw)
To: Steven Rostedt, Ingo Molnar; +Cc: linux-kernel, Joe Perches, Rasmus Villemoes
Printing a single character to a seqfile might as well be done with
seq_putc instead of seq_puts; this avoids a strlen() call and a memory
access. It also shaves another few bytes off the generated code.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
kernel/trace/ftrace.c | 2 +-
kernel/trace/trace_events_trigger.c | 4 ++--
kernel/trace/trace_functions_graph.c | 4 ++--
kernel/trace/trace_kprobe.c | 10 +++++-----
kernel/trace/trace_printk.c | 2 +-
kernel/trace/trace_uprobe.c | 4 ++--
6 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 7890718..9ffd006 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -2969,7 +2969,7 @@ static int t_show(struct seq_file *m, void *v)
}
}
- seq_puts(m, "\n");
+ seq_putc(m, '\n');
return 0;
}
diff --git a/kernel/trace/trace_events_trigger.c b/kernel/trace/trace_events_trigger.c
index 3d89ffc..8712df9 100644
--- a/kernel/trace/trace_events_trigger.c
+++ b/kernel/trace/trace_events_trigger.c
@@ -383,7 +383,7 @@ event_trigger_print(const char *name, struct seq_file *m,
if (filter_str)
seq_printf(m, " if %s\n", filter_str);
else
- seq_puts(m, "\n");
+ seq_putc(m, '\n');
return 0;
}
@@ -1105,7 +1105,7 @@ event_enable_trigger_print(struct seq_file *m, struct event_trigger_ops *ops,
if (data->filter_str)
seq_printf(m, " if %s\n", data->filter_str);
else
- seq_puts(m, "\n");
+ seq_putc(m, '\n');
return 0;
}
diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c
index 29ba611..a82d1d3 100644
--- a/kernel/trace/trace_functions_graph.c
+++ b/kernel/trace/trace_functions_graph.c
@@ -1407,7 +1407,7 @@ static void __print_graph_headers_flags(struct seq_file *s, u32 flags)
print_lat_header(s, flags);
/* 1st line */
- seq_puts(s, "#");
+ seq_putc(s, '#');
if (flags & TRACE_GRAPH_PRINT_ABS_TIME)
seq_puts(s, " TIME ");
if (flags & TRACE_GRAPH_PRINT_CPU)
@@ -1421,7 +1421,7 @@ static void __print_graph_headers_flags(struct seq_file *s, u32 flags)
seq_puts(s, " FUNCTION CALLS\n");
/* 2nd line */
- seq_puts(s, "#");
+ seq_putc(s, '#');
if (flags & TRACE_GRAPH_PRINT_ABS_TIME)
seq_puts(s, " | ");
if (flags & TRACE_GRAPH_PRINT_CPU)
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index ce2ea71..ef7e7f1 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -840,7 +840,7 @@ static int probes_seq_show(struct seq_file *m, void *v)
for (i = 0; i < tk->tp.nr_args; i++)
seq_printf(m, " %s=%s", tk->tp.args[i].name, tk->tp.args[i].comm);
- seq_puts(m, "\n");
+ seq_putc(m, '\n');
return 0;
}
@@ -1030,7 +1030,7 @@ print_kprobe_event(struct trace_iterator *iter, int flags,
if (!seq_print_ip_sym(s, field->ip, flags | TRACE_ITER_SYM_OFFSET))
goto partial;
- if (!trace_seq_puts(s, ")"))
+ if (!trace_seq_putc(s, ')'))
goto partial;
data = (u8 *)&field[1];
@@ -1039,7 +1039,7 @@ print_kprobe_event(struct trace_iterator *iter, int flags,
data + tp->args[i].offset, field))
goto partial;
- if (!trace_seq_puts(s, "\n"))
+ if (!trace_seq_putc(s, '\n'))
goto partial;
return TRACE_TYPE_HANDLED;
@@ -1072,7 +1072,7 @@ print_kretprobe_event(struct trace_iterator *iter, int flags,
if (!seq_print_ip_sym(s, field->func, flags & ~TRACE_ITER_SYM_OFFSET))
goto partial;
- if (!trace_seq_puts(s, ")"))
+ if (!trace_seq_putc(s, ')'))
goto partial;
data = (u8 *)&field[1];
@@ -1081,7 +1081,7 @@ print_kretprobe_event(struct trace_iterator *iter, int flags,
data + tp->args[i].offset, field))
goto partial;
- if (!trace_seq_puts(s, "\n"))
+ if (!trace_seq_putc(s, '\n'))
goto partial;
return TRACE_TYPE_HANDLED;
diff --git a/kernel/trace/trace_printk.c b/kernel/trace/trace_printk.c
index 2900817..c4e70b6 100644
--- a/kernel/trace/trace_printk.c
+++ b/kernel/trace/trace_printk.c
@@ -305,7 +305,7 @@ static int t_show(struct seq_file *m, void *v)
seq_puts(m, "\\t");
break;
case '\\':
- seq_puts(m, "\\");
+ seq_putc(m, '\\');
break;
case '"':
seq_puts(m, "\\\"");
diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c
index 184aec1..e35327c 100644
--- a/kernel/trace/trace_uprobe.c
+++ b/kernel/trace/trace_uprobe.c
@@ -606,7 +606,7 @@ static int probes_seq_show(struct seq_file *m, void *v)
for (i = 0; i < tu->tp.nr_args; i++)
seq_printf(m, " %s=%s", tu->tp.args[i].name, tu->tp.args[i].comm);
- seq_puts(m, "\n");
+ seq_putc(m, '\n');
return 0;
}
@@ -872,7 +872,7 @@ print_uprobe_event(struct trace_iterator *iter, int flags, struct trace_event *e
goto partial;
}
- if (trace_seq_puts(s, "\n"))
+ if (trace_seq_putc(s, '\n'))
return TRACE_TYPE_HANDLED;
partial:
--
2.0.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: [PATCH v2 1/3] trace: Replace seq_printf by simpler equivalents
2014-11-08 20:42 ` [PATCH v2 1/3] trace: Replace seq_printf by simpler equivalents Rasmus Villemoes
@ 2014-11-14 2:31 ` Steven Rostedt
0 siblings, 0 replies; 20+ messages in thread
From: Steven Rostedt @ 2014-11-14 2:31 UTC (permalink / raw)
To: Rasmus Villemoes; +Cc: Ingo Molnar, linux-kernel, Joe Perches
On Sat, 8 Nov 2014 21:42:10 +0100
Rasmus Villemoes <linux@rasmusvillemoes.dk> wrote:
> - seq_printf(m, "\n");
> + seq_puts(m, "\n");
>
> @@ -840,7 +840,7 @@ static int probes_seq_show(struct seq_file *m, void *v)
>
> for (i = 0; i < tk->tp.nr_args; i++)
> seq_printf(m, " %s=%s", tk->tp.args[i].name, tk->tp.args[i].comm);
> - seq_printf(m, "\n");
> + seq_puts(m, "\n");
>
> return 0;
> }
> diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c
> index 33ff6a2..184aec1 100644
> --- a/kernel/trace/trace_uprobe.c
> +++ b/kernel/trace/trace_uprobe.c
> @@ -606,7 +606,7 @@ static int probes_seq_show(struct seq_file *m, void *v)
> for (i = 0; i < tu->tp.nr_args; i++)
> seq_printf(m, " %s=%s", tu->tp.args[i].name, tu->tp.args[i].comm);
>
> - seq_printf(m, "\n");
> + seq_puts(m, "\n");
These can actually be seq_putc(m, '\n');
I saw this because one of them conflicted with a change I already had.
No need to resend, I'll just update them myself. Trivial enough.
-- Steve
> return 0;
> }
>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH v2 3/3] trace: Replace single-character seq_puts with seq_putc
2014-11-08 20:42 ` [PATCH v2 3/3] trace: Replace single-character seq_puts with seq_putc Rasmus Villemoes
@ 2014-11-14 2:34 ` Steven Rostedt
0 siblings, 0 replies; 20+ messages in thread
From: Steven Rostedt @ 2014-11-14 2:34 UTC (permalink / raw)
To: Rasmus Villemoes; +Cc: Ingo Molnar, linux-kernel, Joe Perches
On Sat, 8 Nov 2014 21:42:12 +0100
Rasmus Villemoes <linux@rasmusvillemoes.dk> wrote:
> Printing a single character to a seqfile might as well be done with
> seq_putc instead of seq_puts; this avoids a strlen() call and a memory
> access. It also shaves another few bytes off the generated code.
>
> Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
> ---
> kernel/trace/ftrace.c | 2 +-
> kernel/trace/trace_events_trigger.c | 4 ++--
> kernel/trace/trace_functions_graph.c | 4 ++--
> kernel/trace/trace_kprobe.c | 10 +++++-----
> kernel/trace/trace_printk.c | 2 +-
> kernel/trace/trace_uprobe.c | 4 ++--
> 6 files changed, 13 insertions(+), 13 deletions(-)
>
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index 7890718..9ffd006 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -2969,7 +2969,7 @@ static int t_show(struct seq_file *m, void *v)
> }
> }
>
> - seq_puts(m, "\n");
> + seq_putc(m, '\n');
Ah, you did it here. Well, it is fine to have it in the first patch
anyway.
-- Steve
^ permalink raw reply [flat|nested] 20+ messages in thread
end of thread, other threads:[~2014-11-14 2:34 UTC | newest]
Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-12 9:25 [PATCH 0/6] Small seqfile-use improvements Rasmus Villemoes
2014-09-12 9:25 ` [PATCH 1/6] Coccinelle: Semantic patch for replacing puts with putc Rasmus Villemoes
2014-09-12 11:08 ` SF Markus Elfring
2014-09-12 9:25 ` [PATCH 2/6] Coccinelle: Semantic patch for joining seq_puts calls Rasmus Villemoes
2014-09-12 9:25 ` [PATCH 3/6] Coccinelle: Semantic patch for replacing seq_printf calls with equivalent but simpler functions Rasmus Villemoes
2014-09-12 9:25 ` [PATCH 4/6] trace: Replace seq_printf by simpler equivalents Rasmus Villemoes
2014-11-05 22:34 ` Steven Rostedt
2014-11-05 22:44 ` Rasmus Villemoes
2014-11-06 0:34 ` Steven Rostedt
2014-11-05 22:51 ` Joe Perches
2014-11-06 0:38 ` Steven Rostedt
2014-11-06 0:47 ` Joe Perches
2014-11-08 20:42 ` [PATCH v2 0/3] trace: Use simpler seq_file functions Rasmus Villemoes
2014-11-08 20:42 ` [PATCH v2 1/3] trace: Replace seq_printf by simpler equivalents Rasmus Villemoes
2014-11-14 2:31 ` Steven Rostedt
2014-11-08 20:42 ` [PATCH v2 2/3] trace: Merge consecutive seq_puts calls Rasmus Villemoes
2014-11-08 20:42 ` [PATCH v2 3/3] trace: Replace single-character seq_puts with seq_putc Rasmus Villemoes
2014-11-14 2:34 ` Steven Rostedt
2014-09-12 9:25 ` [PATCH 5/6] trace: Merge consecutive seq_puts calls Rasmus Villemoes
2014-09-12 9:25 ` [PATCH 6/6] trace: Replace single-character seq_puts with seq_putc Rasmus Villemoes
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox