Blame view
fs/proc/uptime.c
1.23 KB
a9caa3de2
|
1 |
#include <linux/fs.h> |
961776028
|
2 3 4 |
#include <linux/init.h> #include <linux/proc_fs.h> #include <linux/sched.h> |
a9caa3de2
|
5 |
#include <linux/seq_file.h> |
961776028
|
6 |
#include <linux/time.h> |
96830a57d
|
7 |
#include <linux/kernel_stat.h> |
bfc3f0281
|
8 |
#include <linux/cputime.h> |
961776028
|
9 |
|
a9caa3de2
|
10 |
static int uptime_proc_show(struct seq_file *m, void *v) |
961776028
|
11 12 13 |
{ struct timespec uptime; struct timespec idle; |
612ef28a0
|
14 |
u64 idletime; |
c3e0ef9a2
|
15 16 |
u64 nsec; u32 rem; |
96830a57d
|
17 |
int i; |
96830a57d
|
18 |
|
c3e0ef9a2
|
19 |
idletime = 0; |
96830a57d
|
20 |
for_each_possible_cpu(i) |
612ef28a0
|
21 |
idletime += (__force u64) kcpustat_cpu(i).cpustat[CPUTIME_IDLE]; |
961776028
|
22 |
|
1d98a5fa1
|
23 |
get_monotonic_boottime(&uptime); |
c3e0ef9a2
|
24 25 26 |
nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC; idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem); idle.tv_nsec = rem; |
a9caa3de2
|
27 28 |
seq_printf(m, "%lu.%02lu %lu.%02lu ", |
961776028
|
29 30 31 32 |
(unsigned long) uptime.tv_sec, (uptime.tv_nsec / (NSEC_PER_SEC / 100)), (unsigned long) idle.tv_sec, (idle.tv_nsec / (NSEC_PER_SEC / 100))); |
a9caa3de2
|
33 |
return 0; |
961776028
|
34 |
} |
a9caa3de2
|
35 36 37 38 39 40 41 42 43 44 45 |
static int uptime_proc_open(struct inode *inode, struct file *file) { return single_open(file, uptime_proc_show, NULL); } static const struct file_operations uptime_proc_fops = { .open = uptime_proc_open, .read = seq_read, .llseek = seq_lseek, .release = single_release, }; |
961776028
|
46 47 |
static int __init proc_uptime_init(void) { |
a9caa3de2
|
48 |
proc_create("uptime", 0, NULL, &uptime_proc_fops); |
961776028
|
49 50 |
return 0; } |
abaf3787a
|
51 |
fs_initcall(proc_uptime_init); |