[PATCH 06/15] print_integer, proc: rewrite /proc/loadavg via print_integer()

From: Alexey Dobriyan
Date: Mon Apr 20 2020 - 16:59:00 EST


Signed-off-by: Alexey Dobriyan <adobriyan@xxxxxxxxx>
---
fs/proc/loadavg.c | 26 ++++++++++++++++++++------
1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/fs/proc/loadavg.c b/fs/proc/loadavg.c
index f32878d9a39f..4540a894db22 100644
--- a/fs/proc/loadavg.c
+++ b/fs/proc/loadavg.c
@@ -9,19 +9,33 @@
#include <linux/seq_file.h>
#include <linux/seqlock.h>
#include <linux/time.h>
+#include "../../lib/print-integer.h"

static int loadavg_proc_show(struct seq_file *m, void *v)
{
unsigned long avnrun[3];
+ char buf[3 * (LEN_UL + 1 + 2 + 1) + 10 + 1 + 10 + 1 + 10 + 1];
+ char *p = buf + sizeof(buf);
+ int i;
+
+ *--p = '\n';
+ p = _print_integer_u32(p, idr_get_cursor(&task_active_pid_ns(current)->idr) - 1);
+ *--p = ' ';
+ p = _print_integer_u32(p, nr_threads);
+ *--p = '/';
+ p = _print_integer_u32(p, nr_running());

get_avenrun(avnrun, FIXED_1/200, 0);
+ for (i = 2; i >= 0; i--) {
+ *--p = ' ';
+ --p; /* overwritten */
+ *--p = '0'; /* conditionally overwritten */
+ (void)_print_integer_u32(p + 2, LOAD_FRAC(avnrun[i]));
+ *--p = '.';
+ p = _print_integer_ul(p, LOAD_INT(avnrun[i]));
+ }

- seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %u/%d %d\n",
- LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
- LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
- LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
- nr_running(), nr_threads,
- idr_get_cursor(&task_active_pid_ns(current)->idr) - 1);
+ seq_write(m, p, buf + sizeof(buf) - p);
return 0;
}

--
2.24.1