]>
Commit | Line | Data |
---|---|---|
a9caa3de | 1 | #include <linux/fs.h> |
96177602 AD |
2 | #include <linux/init.h> |
3 | #include <linux/proc_fs.h> | |
4 | #include <linux/sched.h> | |
a9caa3de | 5 | #include <linux/seq_file.h> |
96177602 | 6 | #include <linux/time.h> |
96830a57 | 7 | #include <linux/kernel_stat.h> |
96177602 | 8 | |
a9caa3de | 9 | static int uptime_proc_show(struct seq_file *m, void *v) |
96177602 AD |
10 | { |
11 | struct timespec uptime; | |
12 | struct timespec idle; | |
c3e0ef9a MS |
13 | u64 nsec; |
14 | u32 rem; | |
96830a57 | 15 | int i; |
96830a57 | 16 | |
7fb1327e | 17 | nsec = 0; |
96830a57 | 18 | for_each_possible_cpu(i) |
7fb1327e | 19 | nsec += (__force u64) kcpustat_cpu(i).cpustat[CPUTIME_IDLE]; |
96177602 | 20 | |
1d98a5fa | 21 | get_monotonic_boottime(&uptime); |
c3e0ef9a MS |
22 | idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem); |
23 | idle.tv_nsec = rem; | |
a9caa3de | 24 | seq_printf(m, "%lu.%02lu %lu.%02lu\n", |
96177602 AD |
25 | (unsigned long) uptime.tv_sec, |
26 | (uptime.tv_nsec / (NSEC_PER_SEC / 100)), | |
27 | (unsigned long) idle.tv_sec, | |
28 | (idle.tv_nsec / (NSEC_PER_SEC / 100))); | |
a9caa3de | 29 | return 0; |
96177602 AD |
30 | } |
31 | ||
a9caa3de AD |
32 | static int uptime_proc_open(struct inode *inode, struct file *file) |
33 | { | |
34 | return single_open(file, uptime_proc_show, NULL); | |
35 | } | |
36 | ||
37 | static const struct file_operations uptime_proc_fops = { | |
38 | .open = uptime_proc_open, | |
39 | .read = seq_read, | |
40 | .llseek = seq_lseek, | |
41 | .release = single_release, | |
42 | }; | |
43 | ||
96177602 AD |
44 | static int __init proc_uptime_init(void) |
45 | { | |
a9caa3de | 46 | proc_create("uptime", 0, NULL, &uptime_proc_fops); |
96177602 AD |
47 | return 0; |
48 | } | |
abaf3787 | 49 | fs_initcall(proc_uptime_init); |