linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexey Dobriyan <adobriyan@gmail.com>
To: akpm@linux-foundation.org
Cc: adobriyan@gmail.com, linux-kernel@vger.kernel.org,
	linux-fsdevel@vger.kernel.org, pmladek@suse.com,
	rostedt@goodmis.org, sergey.senozhatsky@gmail.com,
	andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk
Subject: [PATCH 11/15] print_integer, proc: rewrite /proc/*/stat via print_integer()
Date: Mon, 20 Apr 2020 23:57:39 +0300	[thread overview]
Message-ID: <20200420205743.19964-11-adobriyan@gmail.com> (raw)
In-Reply-To: <20200420205743.19964-1-adobriyan@gmail.com>

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---
 fs/proc/array.c | 192 ++++++++++++++++++++++++++++++------------------
 1 file changed, 122 insertions(+), 70 deletions(-)

diff --git a/fs/proc/array.c b/fs/proc/array.c
index 8e16f14bb05a..6986f9f68ab7 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -446,6 +446,9 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
 	u64 cgtime, gtime;
 	unsigned long rsslim = 0;
 	unsigned long flags;
+	char buf[11 * (1 + LEN_U32) + 7 * (1 + LEN_S32) + 19 * (1 + LEN_UL) +
+		 8 * (1 + LEN_U64) + 12];
+	char *p;
 
 	state = *get_task_state(task);
 	vsize = eip = esp = 0;
@@ -535,47 +538,54 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
 	/* convert nsec -> ticks */
 	start_time = nsec_to_clock_t(task->start_boottime);
 
-	seq_put_decimal_ull(m, "", pid_nr_ns(pid, ns));
-	seq_puts(m, " (");
+	p = buf + sizeof(buf);
+	*--p = '(';
+	*--p = ' ';
+	p = _print_integer_u32(p, pid_nr_ns(pid, ns));
+	seq_write(m, p, buf + sizeof(buf) - p);
+
 	proc_task_name(m, task, false);
-	seq_puts(m, ") ");
-	seq_putc(m, state);
-	seq_put_decimal_ll(m, " ", ppid);
-	seq_put_decimal_ll(m, " ", pgid);
-	seq_put_decimal_ll(m, " ", sid);
-	seq_put_decimal_ll(m, " ", tty_nr);
-	seq_put_decimal_ll(m, " ", tty_pgrp);
-	seq_put_decimal_ull(m, " ", task->flags);
-	seq_put_decimal_ull(m, " ", min_flt);
-	seq_put_decimal_ull(m, " ", cmin_flt);
-	seq_put_decimal_ull(m, " ", maj_flt);
-	seq_put_decimal_ull(m, " ", cmaj_flt);
-	seq_put_decimal_ull(m, " ", nsec_to_clock_t(utime));
-	seq_put_decimal_ull(m, " ", nsec_to_clock_t(stime));
-	seq_put_decimal_ll(m, " ", nsec_to_clock_t(cutime));
-	seq_put_decimal_ll(m, " ", nsec_to_clock_t(cstime));
-	seq_put_decimal_ll(m, " ", priority);
-	seq_put_decimal_ll(m, " ", nice);
-	seq_put_decimal_ll(m, " ", num_threads);
-	seq_put_decimal_ull(m, " ", 0);
-	seq_put_decimal_ull(m, " ", start_time);
-	seq_put_decimal_ull(m, " ", vsize);
-	seq_put_decimal_ull(m, " ", mm ? get_mm_rss(mm) : 0);
-	seq_put_decimal_ull(m, " ", rsslim);
-	seq_put_decimal_ull(m, " ", mm ? (permitted ? mm->start_code : 1) : 0);
-	seq_put_decimal_ull(m, " ", mm ? (permitted ? mm->end_code : 1) : 0);
-	seq_put_decimal_ull(m, " ", (permitted && mm) ? mm->start_stack : 0);
-	seq_put_decimal_ull(m, " ", esp);
-	seq_put_decimal_ull(m, " ", eip);
-	/* The signal information here is obsolete.
-	 * It must be decimal for Linux 2.0 compatibility.
-	 * Use /proc/#/status for real-time signals.
-	 */
-	seq_put_decimal_ull(m, " ", task->pending.signal.sig[0] & 0x7fffffffUL);
-	seq_put_decimal_ull(m, " ", task->blocked.sig[0] & 0x7fffffffUL);
-	seq_put_decimal_ull(m, " ", sigign.sig[0] & 0x7fffffffUL);
-	seq_put_decimal_ull(m, " ", sigcatch.sig[0] & 0x7fffffffUL);
 
+	p = buf + sizeof(buf);
+	*--p = '\n';
+	p = _print_integer_s32(p, permitted ? task->exit_code : 0);
+	*--p = ' ';
+	if (mm && permitted) {
+		p = _print_integer_ul(p, mm->env_end);
+		*--p = ' ';
+		p = _print_integer_ul(p, mm->env_start);
+		*--p = ' ';
+		p = _print_integer_ul(p, mm->arg_end);
+		*--p = ' ';
+		p = _print_integer_ul(p, mm->arg_start);
+		*--p = ' ';
+		p = _print_integer_ul(p, mm->start_brk);
+		*--p = ' ';
+		p = _print_integer_ul(p, mm->end_data);
+		*--p = ' ';
+		p = _print_integer_ul(p, mm->start_data);
+		*--p = ' ';
+	} else {
+		p = memcpy(p - 14, " 0 0 0 0 0 0 0", 14);
+	}
+	p = _print_integer_u64(p, nsec_to_clock_t(cgtime));
+	*--p = ' ';
+	p = _print_integer_u64(p, nsec_to_clock_t(gtime));
+	*--p = ' ';
+	p = _print_integer_u64(p, delayacct_blkio_ticks(task));
+	*--p = ' ';
+	p = _print_integer_u32(p, task->policy);
+	*--p = ' ';
+	p = _print_integer_u32(p, task->rt_priority);
+	*--p = ' ';
+	p = _print_integer_u32(p, task_cpu(task));
+	*--p = ' ';
+	p = _print_integer_s32(p, task->exit_signal);
+	*--p = ' ';
+	*--p = '0';
+	*--p = ' ';
+	*--p = '0';
+	*--p = ' ';
 	/*
 	 * We used to output the absolute kernel address, but that's an
 	 * information leak - so instead we show a 0/1 flag here, to signal
@@ -583,38 +593,80 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
 	 *
 	 * This works with older implementations of procps as well.
 	 */
-	if (wchan)
-		seq_puts(m, " 1");
-	else
-		seq_puts(m, " 0");
-
-	seq_put_decimal_ull(m, " ", 0);
-	seq_put_decimal_ull(m, " ", 0);
-	seq_put_decimal_ll(m, " ", task->exit_signal);
-	seq_put_decimal_ll(m, " ", task_cpu(task));
-	seq_put_decimal_ull(m, " ", task->rt_priority);
-	seq_put_decimal_ull(m, " ", task->policy);
-	seq_put_decimal_ull(m, " ", delayacct_blkio_ticks(task));
-	seq_put_decimal_ull(m, " ", nsec_to_clock_t(gtime));
-	seq_put_decimal_ll(m, " ", nsec_to_clock_t(cgtime));
-
-	if (mm && permitted) {
-		seq_put_decimal_ull(m, " ", mm->start_data);
-		seq_put_decimal_ull(m, " ", mm->end_data);
-		seq_put_decimal_ull(m, " ", mm->start_brk);
-		seq_put_decimal_ull(m, " ", mm->arg_start);
-		seq_put_decimal_ull(m, " ", mm->arg_end);
-		seq_put_decimal_ull(m, " ", mm->env_start);
-		seq_put_decimal_ull(m, " ", mm->env_end);
-	} else
-		seq_puts(m, " 0 0 0 0 0 0 0");
-
-	if (permitted)
-		seq_put_decimal_ll(m, " ", task->exit_code);
-	else
-		seq_puts(m, " 0");
+	*--p = '0' + !!wchan;
+	*--p = ' ';
+	/*
+	 * The signal information here is obsolete.
+	 * It must be decimal for Linux 2.0 compatibility.
+	 * Use /proc/#/status for real-time signals.
+	 */
+	p = _print_integer_u32(p, sigcatch.sig[0] & 0x7fffffff);
+	*--p = ' ';
+	p = _print_integer_u32(p, sigign.sig[0] & 0x7fffffff);
+	*--p = ' ';
+	p = _print_integer_u32(p, task->blocked.sig[0] & 0x7fffffff);
+	*--p = ' ';
+	p = _print_integer_u32(p, task->pending.signal.sig[0] & 0x7fffffff);
+	*--p = ' ';
+	p = _print_integer_ul(p, eip);
+	*--p = ' ';
+	p = _print_integer_ul(p, esp);
+	*--p = ' ';
+	p = _print_integer_ul(p, (permitted && mm) ? mm->start_stack : 0);
+	*--p = ' ';
+	p = _print_integer_ul(p, mm ? (permitted ? mm->end_code : 1) : 0);
+	*--p = ' ';
+	p = _print_integer_ul(p, mm ? (permitted ? mm->start_code : 1) : 0);
+	*--p = ' ';
+	p = _print_integer_ul(p, rsslim);
+	*--p = ' ';
+	p = _print_integer_ul(p, mm ? get_mm_rss(mm) : 0);
+	*--p = ' ';
+	p = _print_integer_ul(p, vsize);
+	*--p = ' ';
+	p = _print_integer_u64(p, start_time);
+	*--p = ' ';
+	*--p = '0';
+	*--p = ' ';
+	p = _print_integer_u32(p, num_threads);
+	*--p = ' ';
+	p = _print_integer_s32(p, nice);
+	*--p = ' ';
+	p = _print_integer_s32(p, priority);
+	*--p = ' ';
+	p = _print_integer_u64(p, nsec_to_clock_t(cstime));
+	*--p = ' ';
+	p = _print_integer_u64(p, nsec_to_clock_t(cutime));
+	*--p = ' ';
+	p = _print_integer_u64(p, nsec_to_clock_t(stime));
+	*--p = ' ';
+	p = _print_integer_u64(p, nsec_to_clock_t(utime));
+	*--p = ' ';
+	p = _print_integer_ul(p, cmaj_flt);
+	*--p = ' ';
+	p = _print_integer_ul(p, maj_flt);
+	*--p = ' ';
+	p = _print_integer_ul(p, cmin_flt);
+	*--p = ' ';
+	p = _print_integer_ul(p, min_flt);
+	*--p = ' ';
+	p = _print_integer_u32(p, task->flags);
+	*--p = ' ';
+	p = _print_integer_s32(p, tty_pgrp);
+	*--p = ' ';
+	p = _print_integer_u32(p, tty_nr);
+	*--p = ' ';
+	p = _print_integer_s32(p, sid);
+	*--p = ' ';
+	p = _print_integer_s32(p, pgid);
+	*--p = ' ';
+	p = _print_integer_u32(p, ppid);
+	*--p = ' ';
+	*--p = state;
+	*--p = ' ';
+	*--p = ')';
+	seq_write(m, p, buf + sizeof(buf) - p);
 
-	seq_putc(m, '\n');
 	if (mm)
 		mmput(mm);
 	return 0;
-- 
2.24.1


  parent reply	other threads:[~2020-04-20 20:58 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-20 20:57 [PATCH 01/15] sched: make nr_running() return "unsigned int" Alexey Dobriyan
2020-04-20 20:57 ` [PATCH 02/15] sched: make nr_iowait_cpu() " Alexey Dobriyan
2020-04-20 20:57 ` [PATCH 03/15] print_integer: new and improved way of printing integers Alexey Dobriyan
2020-04-20 21:19   ` Andy Shevchenko
2020-04-20 21:27     ` Andy Shevchenko
2020-04-21  1:54       ` Steven Rostedt
2020-04-21 16:49         ` Alexey Dobriyan
2020-04-21 21:08           ` Steven Rostedt
2020-04-23  3:42           ` Sergey Senozhatsky
2020-04-21 16:31     ` Alexey Dobriyan
2020-04-21 16:59   ` Matthew Wilcox
2020-04-20 20:57 ` [PATCH 04/15] print_integer, proc: rewrite /proc/self via print_integer() Alexey Dobriyan
2020-04-20 20:57 ` [PATCH 05/15] print_integer, proc: rewrite /proc/thread-self " Alexey Dobriyan
2020-04-20 20:57 ` [PATCH 06/15] print_integer, proc: rewrite /proc/loadavg " Alexey Dobriyan
2020-04-20 20:57 ` [PATCH 07/15] print_integer, proc: rewrite /proc/stat " Alexey Dobriyan
2020-04-20 20:57 ` [PATCH 08/15] print_integer, proc: rewrite /proc/uptime " Alexey Dobriyan
2020-04-20 20:57 ` [PATCH 09/15] proc: s/p/tsk/ Alexey Dobriyan
2020-04-20 20:57 ` [PATCH 10/15] print_integer, proc: rewrite /proc/*/fd via print_integer() Alexey Dobriyan
2020-04-20 20:57 ` Alexey Dobriyan [this message]
2020-04-20 20:57 ` [PATCH 12/15] print_integer, proc: rewrite /proc/*/statm " Alexey Dobriyan
2020-04-20 20:57 ` [PATCH 13/15] print_integer, printf: rewrite num_to_str() " Alexey Dobriyan
2020-04-20 20:57 ` [PATCH 14/15] print_integer, printf: rewrite the rest of lib/vsprintf.c " Alexey Dobriyan
2020-04-21  2:01   ` Steven Rostedt
2020-04-20 20:57 ` [PATCH 15/15] print_integer, proc: rewrite /proc/meminfo " Alexey Dobriyan
2020-04-20 21:05 ` [PATCH 01/15] sched: make nr_running() return "unsigned int" Matthew Wilcox
2020-04-21 17:06   ` Alexey Dobriyan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200420205743.19964-11-adobriyan@gmail.com \
    --to=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=pmladek@suse.com \
    --cc=rostedt@goodmis.org \
    --cc=sergey.senozhatsky@gmail.com \
    --subject='Re: [PATCH 11/15] print_integer, proc: rewrite /proc/*/stat via print_integer()' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
on how to clone and mirror all data and code used for this inbox