[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200420205743.19964-8-adobriyan@gmail.com>
Date: Mon, 20 Apr 2020 23:57:36 +0300
From: Alexey Dobriyan <adobriyan@...il.com>
To: akpm@...ux-foundation.org
Cc: adobriyan@...il.com, linux-kernel@...r.kernel.org,
linux-fsdevel@...r.kernel.org, pmladek@...e.com,
rostedt@...dmis.org, sergey.senozhatsky@...il.com,
andriy.shevchenko@...ux.intel.com, linux@...musvillemoes.dk
Subject: [PATCH 08/15] print_integer, proc: rewrite /proc/uptime via print_integer()
Signed-off-by: Alexey Dobriyan <adobriyan@...il.com>
---
fs/proc/uptime.c | 24 +++++++++++++++++++-----
1 file changed, 19 insertions(+), 5 deletions(-)
diff --git a/fs/proc/uptime.c b/fs/proc/uptime.c
index 5a1b228964fb..a8190078d595 100644
--- a/fs/proc/uptime.c
+++ b/fs/proc/uptime.c
@@ -8,10 +8,14 @@
#include <linux/time_namespace.h>
#include <linux/kernel_stat.h>
+#include "../../lib/print-integer.h"
+
static int uptime_proc_show(struct seq_file *m, void *v)
{
struct timespec64 uptime;
struct timespec64 idle;
+ char buf[(LEN_UL + 1 + 2 + 1) * 2];
+ char *p = buf + sizeof(buf);
u64 nsec;
u32 rem;
int i;
@@ -25,11 +29,21 @@ static int uptime_proc_show(struct seq_file *m, void *v)
idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
idle.tv_nsec = rem;
- seq_printf(m, "%lu.%02lu %lu.%02lu\n",
- (unsigned long) uptime.tv_sec,
- (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
- (unsigned long) idle.tv_sec,
- (idle.tv_nsec / (NSEC_PER_SEC / 100)));
+
+ *--p = '\n';
+ --p; /* overwritten */
+ *--p = '0';
+ (void)_print_integer_u32(p + 2, idle.tv_nsec / (NSEC_PER_SEC / 100));
+ *--p = '.';
+ p = _print_integer_ul(p, (unsigned long)idle.tv_sec);
+ *--p = ' ';
+ --p; /* overwritten */
+ *--p = '0';
+ (void)_print_integer_u32(p + 2, uptime.tv_nsec / (NSEC_PER_SEC / 100));
+ *--p = '.';
+ p = _print_integer_ul(p, (unsigned long)uptime.tv_sec);
+
+ seq_write(m, p, buf + sizeof(buf) - p);
return 0;
}
--
2.24.1
Powered by blists - more mailing lists