]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
a9caa3de | 2 | #include <linux/fs.h> |
96177602 AD |
3 | #include <linux/init.h> |
4 | #include <linux/proc_fs.h> | |
5 | #include <linux/sched.h> | |
a9caa3de | 6 | #include <linux/seq_file.h> |
96177602 | 7 | #include <linux/time.h> |
96830a57 | 8 | #include <linux/kernel_stat.h> |
96177602 | 9 | |
a9caa3de | 10 | static int uptime_proc_show(struct seq_file *m, void *v) |
96177602 | 11 | { |
bdf228a2 | 12 | struct timespec64 uptime; |
95582b00 | 13 | struct timespec64 idle; |
c3e0ef9a MS |
14 | u64 nsec; |
15 | u32 rem; | |
96830a57 | 16 | int i; |
96830a57 | 17 | |
7fb1327e | 18 | nsec = 0; |
96830a57 | 19 | for_each_possible_cpu(i) |
7fb1327e | 20 | nsec += (__force u64) kcpustat_cpu(i).cpustat[CPUTIME_IDLE]; |
96177602 | 21 | |
bdf228a2 | 22 | ktime_get_boottime_ts64(&uptime); |
c3e0ef9a MS |
23 | idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem); |
24 | idle.tv_nsec = rem; | |
a9caa3de | 25 | seq_printf(m, "%lu.%02lu %lu.%02lu\n", |
96177602 AD |
26 | (unsigned long) uptime.tv_sec, |
27 | (uptime.tv_nsec / (NSEC_PER_SEC / 100)), | |
28 | (unsigned long) idle.tv_sec, | |
29 | (idle.tv_nsec / (NSEC_PER_SEC / 100))); | |
a9caa3de | 30 | return 0; |
96177602 AD |
31 | } |
32 | ||
96177602 AD |
33 | static int __init proc_uptime_init(void) |
34 | { | |
3f3942ac | 35 | proc_create_single("uptime", 0, NULL, uptime_proc_show); |
96177602 AD |
36 | return 0; |
37 | } | |
abaf3787 | 38 | fs_initcall(proc_uptime_init); |