Commit 75ba1d07 authored by Joe Perches's avatar Joe Perches Committed by Linus Torvalds

seq/proc: modify seq_put_decimal_[u]ll to take a const char *, not char

Allow some seq_puts removals by taking a string instead of a single
char.

[akpm@linux-foundation.org: update vmstat_show(), per Joe]
Link: http://lkml.kernel.org/r/667e1cf3d436de91a5698170a1e98d882905e956.1470704995.git.joe@perches.comSigned-off-by: default avatarJoe Perches <joe@perches.com>
Cc: Joe Perches <joe@perches.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent f7a5f132
This diff is collapsed.
...@@ -115,17 +115,16 @@ static int show_stat(struct seq_file *p, void *v) ...@@ -115,17 +115,16 @@ static int show_stat(struct seq_file *p, void *v)
} }
sum += arch_irq_stat(); sum += arch_irq_stat();
seq_puts(p, "cpu "); seq_put_decimal_ull(p, "cpu ", cputime64_to_clock_t(user));
seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user)); seq_put_decimal_ull(p, " ", cputime64_to_clock_t(nice));
seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice)); seq_put_decimal_ull(p, " ", cputime64_to_clock_t(system));
seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(system)); seq_put_decimal_ull(p, " ", cputime64_to_clock_t(idle));
seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(idle)); seq_put_decimal_ull(p, " ", cputime64_to_clock_t(iowait));
seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(iowait)); seq_put_decimal_ull(p, " ", cputime64_to_clock_t(irq));
seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(irq)); seq_put_decimal_ull(p, " ", cputime64_to_clock_t(softirq));
seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(softirq)); seq_put_decimal_ull(p, " ", cputime64_to_clock_t(steal));
seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(steal)); seq_put_decimal_ull(p, " ", cputime64_to_clock_t(guest));
seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(guest)); seq_put_decimal_ull(p, " ", cputime64_to_clock_t(guest_nice));
seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(guest_nice));
seq_putc(p, '\n'); seq_putc(p, '\n');
for_each_online_cpu(i) { for_each_online_cpu(i) {
...@@ -141,23 +140,23 @@ static int show_stat(struct seq_file *p, void *v) ...@@ -141,23 +140,23 @@ static int show_stat(struct seq_file *p, void *v)
guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST]; guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE]; guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
seq_printf(p, "cpu%d", i); seq_printf(p, "cpu%d", i);
seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user)); seq_put_decimal_ull(p, " ", cputime64_to_clock_t(user));
seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice)); seq_put_decimal_ull(p, " ", cputime64_to_clock_t(nice));
seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(system)); seq_put_decimal_ull(p, " ", cputime64_to_clock_t(system));
seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(idle)); seq_put_decimal_ull(p, " ", cputime64_to_clock_t(idle));
seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(iowait)); seq_put_decimal_ull(p, " ", cputime64_to_clock_t(iowait));
seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(irq)); seq_put_decimal_ull(p, " ", cputime64_to_clock_t(irq));
seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(softirq)); seq_put_decimal_ull(p, " ", cputime64_to_clock_t(softirq));
seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(steal)); seq_put_decimal_ull(p, " ", cputime64_to_clock_t(steal));
seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(guest)); seq_put_decimal_ull(p, " ", cputime64_to_clock_t(guest));
seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(guest_nice)); seq_put_decimal_ull(p, " ", cputime64_to_clock_t(guest_nice));
seq_putc(p, '\n'); seq_putc(p, '\n');
} }
seq_printf(p, "intr %llu", (unsigned long long)sum); seq_put_decimal_ull(p, "intr ", (unsigned long long)sum);
/* sum again ? it could be updated? */ /* sum again ? it could be updated? */
for_each_irq_nr(j) for_each_irq_nr(j)
seq_put_decimal_ull(p, ' ', kstat_irqs_usr(j)); seq_put_decimal_ull(p, " ", kstat_irqs_usr(j));
seq_printf(p, seq_printf(p,
"\nctxt %llu\n" "\nctxt %llu\n"
...@@ -171,10 +170,10 @@ static int show_stat(struct seq_file *p, void *v) ...@@ -171,10 +170,10 @@ static int show_stat(struct seq_file *p, void *v)
nr_running(), nr_running(),
nr_iowait()); nr_iowait());
seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq); seq_put_decimal_ull(p, "softirq ", (unsigned long long)sum_softirq);
for (i = 0; i < NR_SOFTIRQS; i++) for (i = 0; i < NR_SOFTIRQS; i++)
seq_put_decimal_ull(p, ' ', per_softirq_sums[i]); seq_put_decimal_ull(p, " ", per_softirq_sums[i]);
seq_putc(p, '\n'); seq_putc(p, '\n');
return 0; return 0;
......
...@@ -679,11 +679,11 @@ EXPORT_SYMBOL(seq_puts); ...@@ -679,11 +679,11 @@ EXPORT_SYMBOL(seq_puts);
/* /*
* A helper routine for putting decimal numbers without rich format of printf(). * A helper routine for putting decimal numbers without rich format of printf().
* only 'unsigned long long' is supported. * only 'unsigned long long' is supported.
* This routine will put one byte delimiter + number into seq_file. * This routine will put strlen(delimiter) + number into seq_file.
* This routine is very quick when you show lots of numbers. * This routine is very quick when you show lots of numbers.
* In usual cases, it will be better to use seq_printf(). It's easier to read. * In usual cases, it will be better to use seq_printf(). It's easier to read.
*/ */
void seq_put_decimal_ull(struct seq_file *m, char delimiter, void seq_put_decimal_ull(struct seq_file *m, const char *delimiter,
unsigned long long num) unsigned long long num)
{ {
int len; int len;
...@@ -691,8 +691,15 @@ void seq_put_decimal_ull(struct seq_file *m, char delimiter, ...@@ -691,8 +691,15 @@ void seq_put_decimal_ull(struct seq_file *m, char delimiter,
if (m->count + 2 >= m->size) /* we'll write 2 bytes at least */ if (m->count + 2 >= m->size) /* we'll write 2 bytes at least */
goto overflow; goto overflow;
if (delimiter) len = strlen(delimiter);
m->buf[m->count++] = delimiter; if (m->count + len >= m->size)
goto overflow;
memcpy(m->buf + m->count, delimiter, len);
m->count += len;
if (m->count + 1 >= m->size)
goto overflow;
if (num < 10) { if (num < 10) {
m->buf[m->count++] = num + '0'; m->buf[m->count++] = num + '0';
...@@ -702,6 +709,7 @@ void seq_put_decimal_ull(struct seq_file *m, char delimiter, ...@@ -702,6 +709,7 @@ void seq_put_decimal_ull(struct seq_file *m, char delimiter,
len = num_to_str(m->buf + m->count, m->size - m->count, num); len = num_to_str(m->buf + m->count, m->size - m->count, num);
if (!len) if (!len)
goto overflow; goto overflow;
m->count += len; m->count += len;
return; return;
...@@ -710,19 +718,42 @@ void seq_put_decimal_ull(struct seq_file *m, char delimiter, ...@@ -710,19 +718,42 @@ void seq_put_decimal_ull(struct seq_file *m, char delimiter,
} }
EXPORT_SYMBOL(seq_put_decimal_ull); EXPORT_SYMBOL(seq_put_decimal_ull);
void seq_put_decimal_ll(struct seq_file *m, char delimiter, long long num) void seq_put_decimal_ll(struct seq_file *m, const char *delimiter, long long num)
{ {
int len;
if (m->count + 3 >= m->size) /* we'll write 2 bytes at least */
goto overflow;
len = strlen(delimiter);
if (m->count + len >= m->size)
goto overflow;
memcpy(m->buf + m->count, delimiter, len);
m->count += len;
if (m->count + 2 >= m->size)
goto overflow;
if (num < 0) { if (num < 0) {
if (m->count + 3 >= m->size) { m->buf[m->count++] = '-';
seq_set_overflow(m);
return;
}
if (delimiter)
m->buf[m->count++] = delimiter;
num = -num; num = -num;
delimiter = '-';
} }
seq_put_decimal_ull(m, delimiter, num);
if (num < 10) {
m->buf[m->count++] = num + '0';
return;
}
len = num_to_str(m->buf + m->count, m->size - m->count, num);
if (!len)
goto overflow;
m->count += len;
return;
overflow:
seq_set_overflow(m);
} }
EXPORT_SYMBOL(seq_put_decimal_ll); EXPORT_SYMBOL(seq_put_decimal_ll);
......
...@@ -117,9 +117,9 @@ __printf(2, 3) ...@@ -117,9 +117,9 @@ __printf(2, 3)
void seq_printf(struct seq_file *m, const char *fmt, ...); void seq_printf(struct seq_file *m, const char *fmt, ...);
void seq_putc(struct seq_file *m, char c); void seq_putc(struct seq_file *m, char c);
void seq_puts(struct seq_file *m, const char *s); void seq_puts(struct seq_file *m, const char *s);
void seq_put_decimal_ull(struct seq_file *m, char delimiter, void seq_put_decimal_ull(struct seq_file *m, const char *delimiter,
unsigned long long num); unsigned long long num);
void seq_put_decimal_ll(struct seq_file *m, char delimiter, long long num); void seq_put_decimal_ll(struct seq_file *m, const char *delimiter, long long num);
void seq_escape(struct seq_file *m, const char *s, const char *esc); void seq_escape(struct seq_file *m, const char *s, const char *esc);
void seq_hex_dump(struct seq_file *m, const char *prefix_str, int prefix_type, void seq_hex_dump(struct seq_file *m, const char *prefix_str, int prefix_type,
......
...@@ -1515,7 +1515,7 @@ static int vmstat_show(struct seq_file *m, void *arg) ...@@ -1515,7 +1515,7 @@ static int vmstat_show(struct seq_file *m, void *arg)
unsigned long off = l - (unsigned long *)m->private; unsigned long off = l - (unsigned long *)m->private;
seq_puts(m, vmstat_text[off]); seq_puts(m, vmstat_text[off]);
seq_put_decimal_ull(m, ' ', *l); seq_put_decimal_ull(m, " ", *l);
seq_putc(m, '\n'); seq_putc(m, '\n');
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment