Blame view

fs/proc/uptime.c 1.23 KB
a9caa3de2   Alexey Dobriyan   Revert "proc: rev...
1
  #include <linux/fs.h>
961776028   Alexey Dobriyan   proc: switch /pro...
2
3
4
  #include <linux/init.h>
  #include <linux/proc_fs.h>
  #include <linux/sched.h>
a9caa3de2   Alexey Dobriyan   Revert "proc: rev...
5
  #include <linux/seq_file.h>
961776028   Alexey Dobriyan   proc: switch /pro...
6
  #include <linux/time.h>
96830a57d   Michael Abbott   [PATCH] Fix idle ...
7
  #include <linux/kernel_stat.h>
bfc3f0281   Frederic Weisbecker   cputime: Default ...
8
  #include <linux/cputime.h>
961776028   Alexey Dobriyan   proc: switch /pro...
9

a9caa3de2   Alexey Dobriyan   Revert "proc: rev...
10
  static int uptime_proc_show(struct seq_file *m, void *v)
961776028   Alexey Dobriyan   proc: switch /pro...
11
12
13
  {
  	struct timespec uptime;
  	struct timespec idle;
612ef28a0   Martin Schwidefsky   Merge branch 'sch...
14
  	u64 idletime;
c3e0ef9a2   Martin Schwidefsky   [S390] fix cputim...
15
16
  	u64 nsec;
  	u32 rem;
96830a57d   Michael Abbott   [PATCH] Fix idle ...
17
  	int i;
96830a57d   Michael Abbott   [PATCH] Fix idle ...
18

c3e0ef9a2   Martin Schwidefsky   [S390] fix cputim...
19
  	idletime = 0;
96830a57d   Michael Abbott   [PATCH] Fix idle ...
20
  	for_each_possible_cpu(i)
612ef28a0   Martin Schwidefsky   Merge branch 'sch...
21
  		idletime += (__force u64) kcpustat_cpu(i).cpustat[CPUTIME_IDLE];
961776028   Alexey Dobriyan   proc: switch /pro...
22

1d98a5fa1   Oleg Nesterov   fs/proc/uptime.c:...
23
  	get_monotonic_boottime(&uptime);
c3e0ef9a2   Martin Schwidefsky   [S390] fix cputim...
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   Alexey Dobriyan   Revert "proc: rev...
27
28
  	seq_printf(m, "%lu.%02lu %lu.%02lu
  ",
961776028   Alexey Dobriyan   proc: switch /pro...
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   Alexey Dobriyan   Revert "proc: rev...
33
  	return 0;
961776028   Alexey Dobriyan   proc: switch /pro...
34
  }
a9caa3de2   Alexey Dobriyan   Revert "proc: rev...
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   Alexey Dobriyan   proc: switch /pro...
46
47
  static int __init proc_uptime_init(void)
  {
a9caa3de2   Alexey Dobriyan   Revert "proc: rev...
48
  	proc_create("uptime", 0, NULL, &uptime_proc_fops);
961776028   Alexey Dobriyan   proc: switch /pro...
49
50
  	return 0;
  }
abaf3787a   Paul Gortmaker   fs/proc: don't us...
51
  fs_initcall(proc_uptime_init);