lkml.org 
[lkml]   [2020]   [Apr]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 08/15] print_integer, proc: rewrite /proc/uptime via print_integer()
Date
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.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
\
 
 \ /
  Last update: 2020-04-20 22:59    [W:0.088 / U:0.812 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site