Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * linux/fs/proc/proc_misc.c | |
3 | * | |
4 | * linux/fs/proc/array.c | |
5 | * Copyright (C) 1992 by Linus Torvalds | |
6 | * based on ideas by Darren Senn | |
7 | * | |
8 | * This used to be the part of array.c. See the rest of history and credits | |
9 | * there. I took this into a separate file and switched the thing to generic | |
10 | * proc_file_inode_operations, leaving in array.c only per-process stuff. | |
11 | * Inumbers allocation made dynamic (via create_proc_entry()). AV, May 1999. | |
12 | * | |
13 | * Changes: | |
14 | * Fulton Green : Encapsulated position metric calculations. | |
15 | * <kernel@FultonGreen.com> | |
16 | */ | |
17 | ||
18 | #include <linux/types.h> | |
19 | #include <linux/errno.h> | |
20 | #include <linux/time.h> | |
21 | #include <linux/kernel.h> | |
22 | #include <linux/kernel_stat.h> | |
7170be5f | 23 | #include <linux/fs.h> |
1da177e4 LT |
24 | #include <linux/tty.h> |
25 | #include <linux/string.h> | |
26 | #include <linux/mman.h> | |
4b856152 | 27 | #include <linux/quicklist.h> |
1da177e4 LT |
28 | #include <linux/proc_fs.h> |
29 | #include <linux/ioport.h> | |
1da177e4 LT |
30 | #include <linux/mm.h> |
31 | #include <linux/mmzone.h> | |
32 | #include <linux/pagemap.h> | |
c7fb03a4 | 33 | #include <linux/irq.h> |
f74596d0 | 34 | #include <linux/interrupt.h> |
1da177e4 LT |
35 | #include <linux/swap.h> |
36 | #include <linux/slab.h> | |
a0db701a | 37 | #include <linux/genhd.h> |
1da177e4 LT |
38 | #include <linux/smp.h> |
39 | #include <linux/signal.h> | |
40 | #include <linux/module.h> | |
41 | #include <linux/init.h> | |
1da177e4 LT |
42 | #include <linux/seq_file.h> |
43 | #include <linux/times.h> | |
44 | #include <linux/profile.h> | |
7bf65382 | 45 | #include <linux/utsname.h> |
1da177e4 LT |
46 | #include <linux/blkdev.h> |
47 | #include <linux/hugetlb.h> | |
48 | #include <linux/jiffies.h> | |
49 | #include <linux/sysrq.h> | |
50 | #include <linux/vmalloc.h> | |
666bfddb | 51 | #include <linux/crash_dump.h> |
61a58c6c | 52 | #include <linux/pid_namespace.h> |
161f47bf | 53 | #include <linux/bootmem.h> |
1da177e4 LT |
54 | #include <asm/uaccess.h> |
55 | #include <asm/pgtable.h> | |
56 | #include <asm/io.h> | |
57 | #include <asm/tlb.h> | |
58 | #include <asm/div64.h> | |
59 | #include "internal.h" | |
60 | ||
61 | #define LOAD_INT(x) ((x) >> FSHIFT) | |
62 | #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100) | |
63 | /* | |
64 | * Warning: stuff below (imported functions) assumes that its output will fit | |
65 | * into one page. For some of those functions it may be wrong. Moreover, we | |
66 | * have a way to deal with that gracefully. Right now I used straightforward | |
67 | * wrappers, but this needs further analysis wrt potential overflows. | |
68 | */ | |
69 | extern int get_hardware_list(char *); | |
70 | extern int get_stram_list(char *); | |
1da177e4 | 71 | extern int get_exec_domain_list(char *); |
1da177e4 LT |
72 | |
73 | static int proc_calc_metrics(char *page, char **start, off_t off, | |
74 | int count, int *eof, int len) | |
75 | { | |
76 | if (len <= off+count) *eof = 1; | |
77 | *start = page + off; | |
78 | len -= off; | |
79 | if (len>count) len = count; | |
80 | if (len<0) len = 0; | |
81 | return len; | |
82 | } | |
83 | ||
84 | static int loadavg_read_proc(char *page, char **start, off_t off, | |
85 | int count, int *eof, void *data) | |
86 | { | |
87 | int a, b, c; | |
88 | int len; | |
07a154b2 MS |
89 | unsigned long seq; |
90 | ||
91 | do { | |
92 | seq = read_seqbegin(&xtime_lock); | |
93 | a = avenrun[0] + (FIXED_1/200); | |
94 | b = avenrun[1] + (FIXED_1/200); | |
95 | c = avenrun[2] + (FIXED_1/200); | |
96 | } while (read_seqretry(&xtime_lock, seq)); | |
1da177e4 | 97 | |
1da177e4 LT |
98 | len = sprintf(page,"%d.%02d %d.%02d %d.%02d %ld/%d %d\n", |
99 | LOAD_INT(a), LOAD_FRAC(a), | |
100 | LOAD_INT(b), LOAD_FRAC(b), | |
101 | LOAD_INT(c), LOAD_FRAC(c), | |
2894d650 SB |
102 | nr_running(), nr_threads, |
103 | task_active_pid_ns(current)->last_pid); | |
1da177e4 LT |
104 | return proc_calc_metrics(page, start, off, count, eof, len); |
105 | } | |
106 | ||
107 | static int uptime_read_proc(char *page, char **start, off_t off, | |
108 | int count, int *eof, void *data) | |
109 | { | |
110 | struct timespec uptime; | |
111 | struct timespec idle; | |
112 | int len; | |
113 | cputime_t idletime = cputime_add(init_task.utime, init_task.stime); | |
114 | ||
115 | do_posix_clock_monotonic_gettime(&uptime); | |
d6214141 | 116 | monotonic_to_bootbased(&uptime); |
1da177e4 LT |
117 | cputime_to_timespec(idletime, &idle); |
118 | len = sprintf(page,"%lu.%02lu %lu.%02lu\n", | |
119 | (unsigned long) uptime.tv_sec, | |
120 | (uptime.tv_nsec / (NSEC_PER_SEC / 100)), | |
121 | (unsigned long) idle.tv_sec, | |
122 | (idle.tv_nsec / (NSEC_PER_SEC / 100))); | |
123 | ||
124 | return proc_calc_metrics(page, start, off, count, eof, len); | |
125 | } | |
126 | ||
ce0c0e50 AK |
127 | int __attribute__((weak)) arch_report_meminfo(char *page) |
128 | { | |
129 | return 0; | |
130 | } | |
131 | ||
1da177e4 LT |
132 | static int meminfo_read_proc(char *page, char **start, off_t off, |
133 | int count, int *eof, void *data) | |
134 | { | |
135 | struct sysinfo i; | |
136 | int len; | |
1da177e4 LT |
137 | unsigned long committed; |
138 | unsigned long allowed; | |
139 | struct vmalloc_info vmi; | |
4c4c402d | 140 | long cached; |
1da177e4 | 141 | |
1da177e4 LT |
142 | /* |
143 | * display in kilobytes. | |
144 | */ | |
145 | #define K(x) ((x) << (PAGE_SHIFT - 10)) | |
146 | si_meminfo(&i); | |
147 | si_swapinfo(&i); | |
80119ef5 | 148 | committed = atomic_long_read(&vm_committed_space); |
1da177e4 LT |
149 | allowed = ((totalram_pages - hugetlb_total_pages()) |
150 | * sysctl_overcommit_ratio / 100) + total_swap_pages; | |
151 | ||
347ce434 CL |
152 | cached = global_page_state(NR_FILE_PAGES) - |
153 | total_swapcache_pages - i.bufferram; | |
4c4c402d MH |
154 | if (cached < 0) |
155 | cached = 0; | |
156 | ||
1da177e4 LT |
157 | get_vmalloc_info(&vmi); |
158 | ||
159 | /* | |
160 | * Tagged format, for easy grepping and expansion. | |
161 | */ | |
162 | len = sprintf(page, | |
163 | "MemTotal: %8lu kB\n" | |
164 | "MemFree: %8lu kB\n" | |
165 | "Buffers: %8lu kB\n" | |
166 | "Cached: %8lu kB\n" | |
167 | "SwapCached: %8lu kB\n" | |
168 | "Active: %8lu kB\n" | |
169 | "Inactive: %8lu kB\n" | |
182e8e23 | 170 | #ifdef CONFIG_HIGHMEM |
1da177e4 LT |
171 | "HighTotal: %8lu kB\n" |
172 | "HighFree: %8lu kB\n" | |
173 | "LowTotal: %8lu kB\n" | |
174 | "LowFree: %8lu kB\n" | |
182e8e23 | 175 | #endif |
1da177e4 LT |
176 | "SwapTotal: %8lu kB\n" |
177 | "SwapFree: %8lu kB\n" | |
178 | "Dirty: %8lu kB\n" | |
179 | "Writeback: %8lu kB\n" | |
f3dbd344 | 180 | "AnonPages: %8lu kB\n" |
1da177e4 LT |
181 | "Mapped: %8lu kB\n" |
182 | "Slab: %8lu kB\n" | |
972d1a7b CL |
183 | "SReclaimable: %8lu kB\n" |
184 | "SUnreclaim: %8lu kB\n" | |
df849a15 | 185 | "PageTables: %8lu kB\n" |
d7a3e495 HD |
186 | #ifdef CONFIG_QUICKLIST |
187 | "Quicklists: %8lu kB\n" | |
188 | #endif | |
f5ef68da | 189 | "NFS_Unstable: %8lu kB\n" |
d2c5e30c | 190 | "Bounce: %8lu kB\n" |
fc3ba692 | 191 | "WritebackTmp: %8lu kB\n" |
1da177e4 LT |
192 | "CommitLimit: %8lu kB\n" |
193 | "Committed_AS: %8lu kB\n" | |
1da177e4 LT |
194 | "VmallocTotal: %8lu kB\n" |
195 | "VmallocUsed: %8lu kB\n" | |
d7a3e495 | 196 | "VmallocChunk: %8lu kB\n", |
1da177e4 LT |
197 | K(i.totalram), |
198 | K(i.freeram), | |
199 | K(i.bufferram), | |
4c4c402d | 200 | K(cached), |
1da177e4 | 201 | K(total_swapcache_pages), |
65e458d4 CL |
202 | K(global_page_state(NR_ACTIVE)), |
203 | K(global_page_state(NR_INACTIVE)), | |
182e8e23 | 204 | #ifdef CONFIG_HIGHMEM |
1da177e4 LT |
205 | K(i.totalhigh), |
206 | K(i.freehigh), | |
207 | K(i.totalram-i.totalhigh), | |
208 | K(i.freeram-i.freehigh), | |
182e8e23 | 209 | #endif |
1da177e4 LT |
210 | K(i.totalswap), |
211 | K(i.freeswap), | |
b1e7a8fd | 212 | K(global_page_state(NR_FILE_DIRTY)), |
ce866b34 | 213 | K(global_page_state(NR_WRITEBACK)), |
f3dbd344 | 214 | K(global_page_state(NR_ANON_PAGES)), |
65ba55f5 | 215 | K(global_page_state(NR_FILE_MAPPED)), |
972d1a7b CL |
216 | K(global_page_state(NR_SLAB_RECLAIMABLE) + |
217 | global_page_state(NR_SLAB_UNRECLAIMABLE)), | |
218 | K(global_page_state(NR_SLAB_RECLAIMABLE)), | |
219 | K(global_page_state(NR_SLAB_UNRECLAIMABLE)), | |
df849a15 | 220 | K(global_page_state(NR_PAGETABLE)), |
d7a3e495 HD |
221 | #ifdef CONFIG_QUICKLIST |
222 | K(quicklist_total_size()), | |
223 | #endif | |
fd39fc85 | 224 | K(global_page_state(NR_UNSTABLE_NFS)), |
d2c5e30c | 225 | K(global_page_state(NR_BOUNCE)), |
fc3ba692 | 226 | K(global_page_state(NR_WRITEBACK_TEMP)), |
1da177e4 LT |
227 | K(allowed), |
228 | K(committed), | |
1da177e4 LT |
229 | (unsigned long)VMALLOC_TOTAL >> 10, |
230 | vmi.used >> 10, | |
d7a3e495 | 231 | vmi.largest_chunk >> 10 |
1da177e4 LT |
232 | ); |
233 | ||
234 | len += hugetlb_report_meminfo(page + len); | |
235 | ||
ce0c0e50 AK |
236 | len += arch_report_meminfo(page + len); |
237 | ||
1da177e4 LT |
238 | return proc_calc_metrics(page, start, off, count, eof, len); |
239 | #undef K | |
240 | } | |
241 | ||
1da177e4 LT |
242 | static int fragmentation_open(struct inode *inode, struct file *file) |
243 | { | |
244 | (void)inode; | |
245 | return seq_open(file, &fragmentation_op); | |
246 | } | |
247 | ||
00977a59 | 248 | static const struct file_operations fragmentation_file_operations = { |
1da177e4 LT |
249 | .open = fragmentation_open, |
250 | .read = seq_read, | |
251 | .llseek = seq_lseek, | |
252 | .release = seq_release, | |
253 | }; | |
254 | ||
467c996c MG |
255 | static int pagetypeinfo_open(struct inode *inode, struct file *file) |
256 | { | |
257 | return seq_open(file, &pagetypeinfo_op); | |
258 | } | |
259 | ||
260 | static const struct file_operations pagetypeinfo_file_ops = { | |
261 | .open = pagetypeinfo_open, | |
262 | .read = seq_read, | |
263 | .llseek = seq_lseek, | |
264 | .release = seq_release, | |
265 | }; | |
266 | ||
295ab934 ND |
267 | static int zoneinfo_open(struct inode *inode, struct file *file) |
268 | { | |
269 | return seq_open(file, &zoneinfo_op); | |
270 | } | |
271 | ||
00977a59 | 272 | static const struct file_operations proc_zoneinfo_file_operations = { |
295ab934 ND |
273 | .open = zoneinfo_open, |
274 | .read = seq_read, | |
275 | .llseek = seq_lseek, | |
276 | .release = seq_release, | |
277 | }; | |
278 | ||
1da177e4 LT |
279 | static int version_read_proc(char *page, char **start, off_t off, |
280 | int count, int *eof, void *data) | |
281 | { | |
282 | int len; | |
283 | ||
3eb3c740 | 284 | len = snprintf(page, PAGE_SIZE, linux_proc_banner, |
8993780a LT |
285 | utsname()->sysname, |
286 | utsname()->release, | |
287 | utsname()->version); | |
1da177e4 LT |
288 | return proc_calc_metrics(page, start, off, count, eof, len); |
289 | } | |
290 | ||
03a44825 | 291 | extern const struct seq_operations cpuinfo_op; |
1da177e4 LT |
292 | static int cpuinfo_open(struct inode *inode, struct file *file) |
293 | { | |
294 | return seq_open(file, &cpuinfo_op); | |
295 | } | |
7170be5f | 296 | |
00977a59 | 297 | static const struct file_operations proc_cpuinfo_operations = { |
68eef3b4 JK |
298 | .open = cpuinfo_open, |
299 | .read = seq_read, | |
300 | .llseek = seq_lseek, | |
301 | .release = seq_release, | |
7170be5f NH |
302 | }; |
303 | ||
68eef3b4 | 304 | static int devinfo_show(struct seq_file *f, void *v) |
7170be5f | 305 | { |
68eef3b4 JK |
306 | int i = *(loff_t *) v; |
307 | ||
308 | if (i < CHRDEV_MAJOR_HASH_SIZE) { | |
309 | if (i == 0) | |
310 | seq_printf(f, "Character devices:\n"); | |
311 | chrdev_show(f, i); | |
9361401e DH |
312 | } |
313 | #ifdef CONFIG_BLOCK | |
314 | else { | |
68eef3b4 JK |
315 | i -= CHRDEV_MAJOR_HASH_SIZE; |
316 | if (i == 0) | |
317 | seq_printf(f, "\nBlock devices:\n"); | |
318 | blkdev_show(f, i); | |
7170be5f | 319 | } |
9361401e | 320 | #endif |
68eef3b4 | 321 | return 0; |
7170be5f NH |
322 | } |
323 | ||
68eef3b4 | 324 | static void *devinfo_start(struct seq_file *f, loff_t *pos) |
7170be5f | 325 | { |
68eef3b4 JK |
326 | if (*pos < (BLKDEV_MAJOR_HASH_SIZE + CHRDEV_MAJOR_HASH_SIZE)) |
327 | return pos; | |
328 | return NULL; | |
7170be5f NH |
329 | } |
330 | ||
68eef3b4 | 331 | static void *devinfo_next(struct seq_file *f, void *v, loff_t *pos) |
7170be5f | 332 | { |
68eef3b4 JK |
333 | (*pos)++; |
334 | if (*pos >= (BLKDEV_MAJOR_HASH_SIZE + CHRDEV_MAJOR_HASH_SIZE)) | |
335 | return NULL; | |
336 | return pos; | |
7170be5f NH |
337 | } |
338 | ||
68eef3b4 | 339 | static void devinfo_stop(struct seq_file *f, void *v) |
7170be5f | 340 | { |
68eef3b4 | 341 | /* Nothing to do */ |
7170be5f NH |
342 | } |
343 | ||
03a44825 | 344 | static const struct seq_operations devinfo_ops = { |
68eef3b4 JK |
345 | .start = devinfo_start, |
346 | .next = devinfo_next, | |
347 | .stop = devinfo_stop, | |
348 | .show = devinfo_show | |
7170be5f NH |
349 | }; |
350 | ||
68eef3b4 | 351 | static int devinfo_open(struct inode *inode, struct file *filp) |
7170be5f | 352 | { |
68eef3b4 | 353 | return seq_open(filp, &devinfo_ops); |
7170be5f NH |
354 | } |
355 | ||
00977a59 | 356 | static const struct file_operations proc_devinfo_operations = { |
7170be5f NH |
357 | .open = devinfo_open, |
358 | .read = seq_read, | |
359 | .llseek = seq_lseek, | |
360 | .release = seq_release, | |
361 | }; | |
362 | ||
1da177e4 LT |
363 | static int vmstat_open(struct inode *inode, struct file *file) |
364 | { | |
365 | return seq_open(file, &vmstat_op); | |
366 | } | |
00977a59 | 367 | static const struct file_operations proc_vmstat_file_operations = { |
1da177e4 LT |
368 | .open = vmstat_open, |
369 | .read = seq_read, | |
370 | .llseek = seq_lseek, | |
371 | .release = seq_release, | |
372 | }; | |
373 | ||
374 | #ifdef CONFIG_PROC_HARDWARE | |
375 | static int hardware_read_proc(char *page, char **start, off_t off, | |
376 | int count, int *eof, void *data) | |
377 | { | |
378 | int len = get_hardware_list(page); | |
379 | return proc_calc_metrics(page, start, off, count, eof, len); | |
380 | } | |
381 | #endif | |
382 | ||
383 | #ifdef CONFIG_STRAM_PROC | |
384 | static int stram_read_proc(char *page, char **start, off_t off, | |
385 | int count, int *eof, void *data) | |
386 | { | |
387 | int len = get_stram_list(page); | |
388 | return proc_calc_metrics(page, start, off, count, eof, len); | |
389 | } | |
390 | #endif | |
391 | ||
9361401e | 392 | #ifdef CONFIG_BLOCK |
1da177e4 LT |
393 | static int partitions_open(struct inode *inode, struct file *file) |
394 | { | |
395 | return seq_open(file, &partitions_op); | |
396 | } | |
00977a59 | 397 | static const struct file_operations proc_partitions_operations = { |
1da177e4 LT |
398 | .open = partitions_open, |
399 | .read = seq_read, | |
400 | .llseek = seq_lseek, | |
401 | .release = seq_release, | |
402 | }; | |
403 | ||
1da177e4 LT |
404 | static int diskstats_open(struct inode *inode, struct file *file) |
405 | { | |
406 | return seq_open(file, &diskstats_op); | |
407 | } | |
00977a59 | 408 | static const struct file_operations proc_diskstats_operations = { |
1da177e4 LT |
409 | .open = diskstats_open, |
410 | .read = seq_read, | |
411 | .llseek = seq_lseek, | |
412 | .release = seq_release, | |
413 | }; | |
9361401e | 414 | #endif |
1da177e4 LT |
415 | |
416 | #ifdef CONFIG_MODULES | |
03a44825 | 417 | extern const struct seq_operations modules_op; |
1da177e4 LT |
418 | static int modules_open(struct inode *inode, struct file *file) |
419 | { | |
420 | return seq_open(file, &modules_op); | |
421 | } | |
00977a59 | 422 | static const struct file_operations proc_modules_operations = { |
1da177e4 LT |
423 | .open = modules_open, |
424 | .read = seq_read, | |
425 | .llseek = seq_lseek, | |
426 | .release = seq_release, | |
427 | }; | |
428 | #endif | |
429 | ||
158a9624 | 430 | #ifdef CONFIG_SLABINFO |
1da177e4 LT |
431 | static int slabinfo_open(struct inode *inode, struct file *file) |
432 | { | |
433 | return seq_open(file, &slabinfo_op); | |
434 | } | |
00977a59 | 435 | static const struct file_operations proc_slabinfo_operations = { |
1da177e4 LT |
436 | .open = slabinfo_open, |
437 | .read = seq_read, | |
438 | .write = slabinfo_write, | |
439 | .llseek = seq_lseek, | |
440 | .release = seq_release, | |
441 | }; | |
871751e2 AV |
442 | |
443 | #ifdef CONFIG_DEBUG_SLAB_LEAK | |
03a44825 | 444 | extern const struct seq_operations slabstats_op; |
871751e2 AV |
445 | static int slabstats_open(struct inode *inode, struct file *file) |
446 | { | |
447 | unsigned long *n = kzalloc(PAGE_SIZE, GFP_KERNEL); | |
448 | int ret = -ENOMEM; | |
449 | if (n) { | |
450 | ret = seq_open(file, &slabstats_op); | |
451 | if (!ret) { | |
452 | struct seq_file *m = file->private_data; | |
453 | *n = PAGE_SIZE / (2 * sizeof(unsigned long)); | |
454 | m->private = n; | |
455 | n = NULL; | |
456 | } | |
457 | kfree(n); | |
458 | } | |
459 | return ret; | |
460 | } | |
461 | ||
00977a59 | 462 | static const struct file_operations proc_slabstats_operations = { |
871751e2 AV |
463 | .open = slabstats_open, |
464 | .read = seq_read, | |
465 | .llseek = seq_lseek, | |
09f0892e | 466 | .release = seq_release_private, |
871751e2 AV |
467 | }; |
468 | #endif | |
10cef602 | 469 | #endif |
1da177e4 | 470 | |
a10aa579 CL |
471 | #ifdef CONFIG_MMU |
472 | static int vmalloc_open(struct inode *inode, struct file *file) | |
473 | { | |
a47a126a ED |
474 | unsigned int *ptr = NULL; |
475 | int ret; | |
476 | ||
477 | if (NUMA_BUILD) | |
478 | ptr = kmalloc(nr_node_ids * sizeof(unsigned int), GFP_KERNEL); | |
479 | ret = seq_open(file, &vmalloc_op); | |
480 | if (!ret) { | |
481 | struct seq_file *m = file->private_data; | |
482 | m->private = ptr; | |
483 | } else | |
484 | kfree(ptr); | |
485 | return ret; | |
a10aa579 CL |
486 | } |
487 | ||
488 | static const struct file_operations proc_vmalloc_operations = { | |
489 | .open = vmalloc_open, | |
490 | .read = seq_read, | |
491 | .llseek = seq_lseek, | |
a47a126a | 492 | .release = seq_release_private, |
a10aa579 CL |
493 | }; |
494 | #endif | |
495 | ||
a2eddfa9 JB |
496 | #ifndef arch_irq_stat_cpu |
497 | #define arch_irq_stat_cpu(cpu) 0 | |
498 | #endif | |
499 | #ifndef arch_irq_stat | |
500 | #define arch_irq_stat() 0 | |
501 | #endif | |
502 | ||
1da177e4 LT |
503 | static int show_stat(struct seq_file *p, void *v) |
504 | { | |
c7fb03a4 | 505 | int i, j; |
1da177e4 LT |
506 | unsigned long jif; |
507 | cputime64_t user, nice, system, idle, iowait, irq, softirq, steal; | |
5e84cfde | 508 | cputime64_t guest; |
1da177e4 | 509 | u64 sum = 0; |
924b42d5 | 510 | struct timespec boottime; |
c7fb03a4 YL |
511 | unsigned int per_irq_sum; |
512 | #ifdef CONFIG_GENERIC_HARDIRQS | |
513 | struct irq_desc *desc; | |
514 | #endif | |
1da177e4 LT |
515 | |
516 | user = nice = system = idle = iowait = | |
517 | irq = softirq = steal = cputime64_zero; | |
5e84cfde | 518 | guest = cputime64_zero; |
924b42d5 TJ |
519 | getboottime(&boottime); |
520 | jif = boottime.tv_sec; | |
1da177e4 | 521 | |
0a945022 | 522 | for_each_possible_cpu(i) { |
1da177e4 LT |
523 | user = cputime64_add(user, kstat_cpu(i).cpustat.user); |
524 | nice = cputime64_add(nice, kstat_cpu(i).cpustat.nice); | |
525 | system = cputime64_add(system, kstat_cpu(i).cpustat.system); | |
526 | idle = cputime64_add(idle, kstat_cpu(i).cpustat.idle); | |
527 | iowait = cputime64_add(iowait, kstat_cpu(i).cpustat.iowait); | |
528 | irq = cputime64_add(irq, kstat_cpu(i).cpustat.irq); | |
529 | softirq = cputime64_add(softirq, kstat_cpu(i).cpustat.softirq); | |
530 | steal = cputime64_add(steal, kstat_cpu(i).cpustat.steal); | |
5e84cfde | 531 | guest = cputime64_add(guest, kstat_cpu(i).cpustat.guest); |
c7fb03a4 YL |
532 | for_each_irq_desc(j, desc) |
533 | { | |
534 | unsigned int temp; | |
535 | ||
536 | temp = kstat_irqs_cpu(j, i); | |
4004c69a | 537 | sum += temp; |
4004c69a | 538 | } |
a2eddfa9 | 539 | sum += arch_irq_stat_cpu(i); |
1da177e4 | 540 | } |
a2eddfa9 | 541 | sum += arch_irq_stat(); |
1da177e4 | 542 | |
5e84cfde | 543 | seq_printf(p, "cpu %llu %llu %llu %llu %llu %llu %llu %llu %llu\n", |
1da177e4 LT |
544 | (unsigned long long)cputime64_to_clock_t(user), |
545 | (unsigned long long)cputime64_to_clock_t(nice), | |
546 | (unsigned long long)cputime64_to_clock_t(system), | |
547 | (unsigned long long)cputime64_to_clock_t(idle), | |
548 | (unsigned long long)cputime64_to_clock_t(iowait), | |
549 | (unsigned long long)cputime64_to_clock_t(irq), | |
550 | (unsigned long long)cputime64_to_clock_t(softirq), | |
5e84cfde LV |
551 | (unsigned long long)cputime64_to_clock_t(steal), |
552 | (unsigned long long)cputime64_to_clock_t(guest)); | |
1da177e4 LT |
553 | for_each_online_cpu(i) { |
554 | ||
555 | /* Copy values here to work around gcc-2.95.3, gcc-2.96 */ | |
556 | user = kstat_cpu(i).cpustat.user; | |
557 | nice = kstat_cpu(i).cpustat.nice; | |
558 | system = kstat_cpu(i).cpustat.system; | |
559 | idle = kstat_cpu(i).cpustat.idle; | |
560 | iowait = kstat_cpu(i).cpustat.iowait; | |
561 | irq = kstat_cpu(i).cpustat.irq; | |
562 | softirq = kstat_cpu(i).cpustat.softirq; | |
563 | steal = kstat_cpu(i).cpustat.steal; | |
5e84cfde LV |
564 | guest = kstat_cpu(i).cpustat.guest; |
565 | seq_printf(p, | |
566 | "cpu%d %llu %llu %llu %llu %llu %llu %llu %llu %llu\n", | |
1da177e4 LT |
567 | i, |
568 | (unsigned long long)cputime64_to_clock_t(user), | |
569 | (unsigned long long)cputime64_to_clock_t(nice), | |
570 | (unsigned long long)cputime64_to_clock_t(system), | |
571 | (unsigned long long)cputime64_to_clock_t(idle), | |
572 | (unsigned long long)cputime64_to_clock_t(iowait), | |
573 | (unsigned long long)cputime64_to_clock_t(irq), | |
574 | (unsigned long long)cputime64_to_clock_t(softirq), | |
5e84cfde LV |
575 | (unsigned long long)cputime64_to_clock_t(steal), |
576 | (unsigned long long)cputime64_to_clock_t(guest)); | |
1da177e4 LT |
577 | } |
578 | seq_printf(p, "intr %llu", (unsigned long long)sum); | |
579 | ||
c7fb03a4 YL |
580 | /* sum again ? it could be updated? */ |
581 | for_each_irq_desc(j, desc) | |
582 | { | |
583 | per_irq_sum = 0; | |
584 | for_each_possible_cpu(i) { | |
585 | unsigned int temp; | |
586 | ||
587 | temp = kstat_irqs_cpu(j, i); | |
588 | per_irq_sum += temp; | |
589 | } | |
590 | ||
591 | #ifdef CONFIG_HAVE_SPARSE_IRQ | |
592 | seq_printf(p, " %u:%u", j, per_irq_sum); | |
593 | #else | |
594 | seq_printf(p, " %u", per_irq_sum); | |
595 | #endif | |
596 | } | |
1da177e4 LT |
597 | |
598 | seq_printf(p, | |
599 | "\nctxt %llu\n" | |
600 | "btime %lu\n" | |
601 | "processes %lu\n" | |
602 | "procs_running %lu\n" | |
603 | "procs_blocked %lu\n", | |
604 | nr_context_switches(), | |
605 | (unsigned long)jif, | |
606 | total_forks, | |
607 | nr_running(), | |
608 | nr_iowait()); | |
609 | ||
610 | return 0; | |
611 | } | |
612 | ||
613 | static int stat_open(struct inode *inode, struct file *file) | |
614 | { | |
615 | unsigned size = 4096 * (1 + num_possible_cpus() / 32); | |
616 | char *buf; | |
617 | struct seq_file *m; | |
618 | int res; | |
619 | ||
620 | /* don't ask for more than the kmalloc() max size, currently 128 KB */ | |
621 | if (size > 128 * 1024) | |
622 | size = 128 * 1024; | |
623 | buf = kmalloc(size, GFP_KERNEL); | |
624 | if (!buf) | |
625 | return -ENOMEM; | |
626 | ||
627 | res = single_open(file, show_stat, NULL); | |
628 | if (!res) { | |
629 | m = file->private_data; | |
630 | m->buf = buf; | |
631 | m->size = size; | |
632 | } else | |
633 | kfree(buf); | |
634 | return res; | |
635 | } | |
00977a59 | 636 | static const struct file_operations proc_stat_operations = { |
1da177e4 LT |
637 | .open = stat_open, |
638 | .read = seq_read, | |
639 | .llseek = seq_lseek, | |
640 | .release = single_release, | |
641 | }; | |
642 | ||
1da177e4 LT |
643 | /* |
644 | * /proc/interrupts | |
645 | */ | |
646 | static void *int_seq_start(struct seq_file *f, loff_t *pos) | |
647 | { | |
52b17329 YL |
648 | #ifdef CONFIG_HAVE_SPARSE_IRQ |
649 | struct irq_desc *desc; | |
650 | int irq; | |
651 | int count = *pos; | |
652 | ||
653 | for_each_irq_desc(irq, desc) { | |
654 | if (count-- == 0) | |
655 | return desc; | |
656 | } | |
657 | ||
658 | return NULL; | |
659 | #else | |
da27c118 | 660 | return (*pos <= nr_irqs) ? pos : NULL; |
52b17329 | 661 | #endif |
1da177e4 LT |
662 | } |
663 | ||
52b17329 | 664 | |
1da177e4 LT |
665 | static void *int_seq_next(struct seq_file *f, void *v, loff_t *pos) |
666 | { | |
52b17329 YL |
667 | #ifdef CONFIG_HAVE_SPARSE_IRQ |
668 | struct irq_desc *desc; | |
669 | ||
670 | desc = ((struct irq_desc *)v)->next; | |
1da177e4 | 671 | (*pos)++; |
52b17329 YL |
672 | |
673 | return desc; | |
674 | #else | |
675 | (*pos)++; | |
676 | return (*pos <= nr_irqs) ? pos : NULL; | |
677 | #endif | |
1da177e4 LT |
678 | } |
679 | ||
680 | static void int_seq_stop(struct seq_file *f, void *v) | |
681 | { | |
682 | /* Nothing to do */ | |
683 | } | |
684 | ||
03a44825 | 685 | static const struct seq_operations int_seq_ops = { |
1da177e4 LT |
686 | .start = int_seq_start, |
687 | .next = int_seq_next, | |
688 | .stop = int_seq_stop, | |
689 | .show = show_interrupts | |
690 | }; | |
691 | ||
692 | static int interrupts_open(struct inode *inode, struct file *filp) | |
693 | { | |
694 | return seq_open(filp, &int_seq_ops); | |
695 | } | |
696 | ||
00977a59 | 697 | static const struct file_operations proc_interrupts_operations = { |
1da177e4 LT |
698 | .open = interrupts_open, |
699 | .read = seq_read, | |
700 | .llseek = seq_lseek, | |
701 | .release = seq_release, | |
702 | }; | |
703 | ||
704 | static int filesystems_read_proc(char *page, char **start, off_t off, | |
705 | int count, int *eof, void *data) | |
706 | { | |
707 | int len = get_filesystem_list(page); | |
708 | return proc_calc_metrics(page, start, off, count, eof, len); | |
709 | } | |
710 | ||
711 | static int cmdline_read_proc(char *page, char **start, off_t off, | |
712 | int count, int *eof, void *data) | |
713 | { | |
714 | int len; | |
715 | ||
716 | len = sprintf(page, "%s\n", saved_command_line); | |
717 | return proc_calc_metrics(page, start, off, count, eof, len); | |
718 | } | |
719 | ||
bfcd17a6 | 720 | #ifdef CONFIG_FILE_LOCKING |
7f8ada98 | 721 | static int locks_open(struct inode *inode, struct file *filp) |
1da177e4 | 722 | { |
7f8ada98 | 723 | return seq_open(filp, &locks_seq_operations); |
1da177e4 LT |
724 | } |
725 | ||
7f8ada98 PE |
726 | static const struct file_operations proc_locks_operations = { |
727 | .open = locks_open, | |
728 | .read = seq_read, | |
729 | .llseek = seq_lseek, | |
730 | .release = seq_release, | |
731 | }; | |
bfcd17a6 | 732 | #endif /* CONFIG_FILE_LOCKING */ |
7f8ada98 | 733 | |
1da177e4 LT |
734 | static int execdomains_read_proc(char *page, char **start, off_t off, |
735 | int count, int *eof, void *data) | |
736 | { | |
737 | int len = get_exec_domain_list(page); | |
738 | return proc_calc_metrics(page, start, off, count, eof, len); | |
739 | } | |
740 | ||
741 | #ifdef CONFIG_MAGIC_SYSRQ | |
742 | /* | |
743 | * writing 'C' to /proc/sysrq-trigger is like sysrq-C | |
744 | */ | |
745 | static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf, | |
746 | size_t count, loff_t *ppos) | |
747 | { | |
748 | if (count) { | |
749 | char c; | |
750 | ||
751 | if (get_user(c, buf)) | |
752 | return -EFAULT; | |
7d12e780 | 753 | __handle_sysrq(c, NULL, 0); |
1da177e4 LT |
754 | } |
755 | return count; | |
756 | } | |
757 | ||
00977a59 | 758 | static const struct file_operations proc_sysrq_trigger_operations = { |
1da177e4 LT |
759 | .write = write_sysrq_trigger, |
760 | }; | |
761 | #endif | |
762 | ||
1e883281 | 763 | #ifdef CONFIG_PROC_PAGE_MONITOR |
161f47bf MM |
764 | #define KPMSIZE sizeof(u64) |
765 | #define KPMMASK (KPMSIZE - 1) | |
766 | /* /proc/kpagecount - an array exposing page counts | |
767 | * | |
768 | * Each entry is a u64 representing the corresponding | |
769 | * physical page count. | |
770 | */ | |
771 | static ssize_t kpagecount_read(struct file *file, char __user *buf, | |
772 | size_t count, loff_t *ppos) | |
773 | { | |
774 | u64 __user *out = (u64 __user *)buf; | |
775 | struct page *ppage; | |
776 | unsigned long src = *ppos; | |
777 | unsigned long pfn; | |
778 | ssize_t ret = 0; | |
779 | u64 pcount; | |
780 | ||
781 | pfn = src / KPMSIZE; | |
782 | count = min_t(size_t, count, (max_pfn * KPMSIZE) - src); | |
783 | if (src & KPMMASK || count & KPMMASK) | |
4710d1ac | 784 | return -EINVAL; |
161f47bf MM |
785 | |
786 | while (count > 0) { | |
304daa81 MM |
787 | ppage = NULL; |
788 | if (pfn_valid(pfn)) | |
789 | ppage = pfn_to_page(pfn); | |
790 | pfn++; | |
161f47bf MM |
791 | if (!ppage) |
792 | pcount = 0; | |
793 | else | |
bbcdac0c | 794 | pcount = page_mapcount(ppage); |
161f47bf MM |
795 | |
796 | if (put_user(pcount, out++)) { | |
797 | ret = -EFAULT; | |
798 | break; | |
799 | } | |
800 | ||
801 | count -= KPMSIZE; | |
802 | } | |
803 | ||
804 | *ppos += (char __user *)out - buf; | |
805 | if (!ret) | |
806 | ret = (char __user *)out - buf; | |
807 | return ret; | |
808 | } | |
809 | ||
810 | static struct file_operations proc_kpagecount_operations = { | |
811 | .llseek = mem_lseek, | |
812 | .read = kpagecount_read, | |
813 | }; | |
814 | ||
304daa81 MM |
815 | /* /proc/kpageflags - an array exposing page flags |
816 | * | |
817 | * Each entry is a u64 representing the corresponding | |
818 | * physical page flags. | |
819 | */ | |
820 | ||
821 | /* These macros are used to decouple internal flags from exported ones */ | |
822 | ||
823 | #define KPF_LOCKED 0 | |
824 | #define KPF_ERROR 1 | |
825 | #define KPF_REFERENCED 2 | |
826 | #define KPF_UPTODATE 3 | |
827 | #define KPF_DIRTY 4 | |
828 | #define KPF_LRU 5 | |
829 | #define KPF_ACTIVE 6 | |
830 | #define KPF_SLAB 7 | |
831 | #define KPF_WRITEBACK 8 | |
832 | #define KPF_RECLAIM 9 | |
833 | #define KPF_BUDDY 10 | |
834 | ||
835 | #define kpf_copy_bit(flags, srcpos, dstpos) (((flags >> srcpos) & 1) << dstpos) | |
836 | ||
837 | static ssize_t kpageflags_read(struct file *file, char __user *buf, | |
838 | size_t count, loff_t *ppos) | |
839 | { | |
840 | u64 __user *out = (u64 __user *)buf; | |
841 | struct page *ppage; | |
842 | unsigned long src = *ppos; | |
843 | unsigned long pfn; | |
844 | ssize_t ret = 0; | |
845 | u64 kflags, uflags; | |
846 | ||
847 | pfn = src / KPMSIZE; | |
848 | count = min_t(unsigned long, count, (max_pfn * KPMSIZE) - src); | |
849 | if (src & KPMMASK || count & KPMMASK) | |
4710d1ac | 850 | return -EINVAL; |
304daa81 MM |
851 | |
852 | while (count > 0) { | |
853 | ppage = NULL; | |
854 | if (pfn_valid(pfn)) | |
855 | ppage = pfn_to_page(pfn); | |
856 | pfn++; | |
857 | if (!ppage) | |
858 | kflags = 0; | |
859 | else | |
860 | kflags = ppage->flags; | |
861 | ||
862 | uflags = kpf_copy_bit(KPF_LOCKED, PG_locked, kflags) | | |
863 | kpf_copy_bit(kflags, KPF_ERROR, PG_error) | | |
864 | kpf_copy_bit(kflags, KPF_REFERENCED, PG_referenced) | | |
865 | kpf_copy_bit(kflags, KPF_UPTODATE, PG_uptodate) | | |
866 | kpf_copy_bit(kflags, KPF_DIRTY, PG_dirty) | | |
867 | kpf_copy_bit(kflags, KPF_LRU, PG_lru) | | |
868 | kpf_copy_bit(kflags, KPF_ACTIVE, PG_active) | | |
869 | kpf_copy_bit(kflags, KPF_SLAB, PG_slab) | | |
870 | kpf_copy_bit(kflags, KPF_WRITEBACK, PG_writeback) | | |
871 | kpf_copy_bit(kflags, KPF_RECLAIM, PG_reclaim) | | |
872 | kpf_copy_bit(kflags, KPF_BUDDY, PG_buddy); | |
873 | ||
874 | if (put_user(uflags, out++)) { | |
875 | ret = -EFAULT; | |
876 | break; | |
877 | } | |
878 | ||
879 | count -= KPMSIZE; | |
880 | } | |
881 | ||
882 | *ppos += (char __user *)out - buf; | |
883 | if (!ret) | |
884 | ret = (char __user *)out - buf; | |
885 | return ret; | |
886 | } | |
887 | ||
888 | static struct file_operations proc_kpageflags_operations = { | |
889 | .llseek = mem_lseek, | |
890 | .read = kpageflags_read, | |
891 | }; | |
1e883281 | 892 | #endif /* CONFIG_PROC_PAGE_MONITOR */ |
304daa81 | 893 | |
1da177e4 LT |
894 | struct proc_dir_entry *proc_root_kcore; |
895 | ||
1da177e4 LT |
896 | void __init proc_misc_init(void) |
897 | { | |
1da177e4 LT |
898 | static struct { |
899 | char *name; | |
900 | int (*read_proc)(char*,char**,off_t,int,int*,void*); | |
901 | } *p, simple_ones[] = { | |
902 | {"loadavg", loadavg_read_proc}, | |
903 | {"uptime", uptime_read_proc}, | |
904 | {"meminfo", meminfo_read_proc}, | |
905 | {"version", version_read_proc}, | |
906 | #ifdef CONFIG_PROC_HARDWARE | |
907 | {"hardware", hardware_read_proc}, | |
908 | #endif | |
909 | #ifdef CONFIG_STRAM_PROC | |
910 | {"stram", stram_read_proc}, | |
911 | #endif | |
1da177e4 LT |
912 | {"filesystems", filesystems_read_proc}, |
913 | {"cmdline", cmdline_read_proc}, | |
1da177e4 LT |
914 | {"execdomains", execdomains_read_proc}, |
915 | {NULL,} | |
916 | }; | |
917 | for (p = simple_ones; p->name; p++) | |
918 | create_proc_read_entry(p->name, 0, NULL, p->read_proc, NULL); | |
919 | ||
920 | proc_symlink("mounts", NULL, "self/mounts"); | |
921 | ||
922 | /* And now for trickier ones */ | |
c36264df | 923 | #ifdef CONFIG_PRINTK |
c74c120a | 924 | proc_create("kmsg", S_IRUSR, NULL, &proc_kmsg_operations); |
c36264df | 925 | #endif |
bfcd17a6 | 926 | #ifdef CONFIG_FILE_LOCKING |
0d5c9f5f | 927 | proc_create("locks", 0, NULL, &proc_locks_operations); |
bfcd17a6 | 928 | #endif |
0d5c9f5f AD |
929 | proc_create("devices", 0, NULL, &proc_devinfo_operations); |
930 | proc_create("cpuinfo", 0, NULL, &proc_cpuinfo_operations); | |
9361401e | 931 | #ifdef CONFIG_BLOCK |
0d5c9f5f | 932 | proc_create("partitions", 0, NULL, &proc_partitions_operations); |
9361401e | 933 | #endif |
0d5c9f5f AD |
934 | proc_create("stat", 0, NULL, &proc_stat_operations); |
935 | proc_create("interrupts", 0, NULL, &proc_interrupts_operations); | |
158a9624 | 936 | #ifdef CONFIG_SLABINFO |
0d5c9f5f | 937 | proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations); |
871751e2 | 938 | #ifdef CONFIG_DEBUG_SLAB_LEAK |
0d5c9f5f | 939 | proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations); |
871751e2 | 940 | #endif |
a10aa579 CL |
941 | #endif |
942 | #ifdef CONFIG_MMU | |
943 | proc_create("vmallocinfo", S_IRUSR, NULL, &proc_vmalloc_operations); | |
10cef602 | 944 | #endif |
0d5c9f5f AD |
945 | proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations); |
946 | proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops); | |
947 | proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations); | |
948 | proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations); | |
9361401e | 949 | #ifdef CONFIG_BLOCK |
0d5c9f5f | 950 | proc_create("diskstats", 0, NULL, &proc_diskstats_operations); |
9361401e | 951 | #endif |
1da177e4 | 952 | #ifdef CONFIG_MODULES |
0d5c9f5f | 953 | proc_create("modules", 0, NULL, &proc_modules_operations); |
1da177e4 LT |
954 | #endif |
955 | #ifdef CONFIG_SCHEDSTATS | |
0d5c9f5f | 956 | proc_create("schedstat", 0, NULL, &proc_schedstat_operations); |
1da177e4 LT |
957 | #endif |
958 | #ifdef CONFIG_PROC_KCORE | |
0d5c9f5f AD |
959 | proc_root_kcore = proc_create("kcore", S_IRUSR, NULL, &proc_kcore_operations); |
960 | if (proc_root_kcore) | |
1da177e4 LT |
961 | proc_root_kcore->size = |
962 | (size_t)high_memory - PAGE_OFFSET + PAGE_SIZE; | |
1da177e4 | 963 | #endif |
1e883281 | 964 | #ifdef CONFIG_PROC_PAGE_MONITOR |
0d5c9f5f AD |
965 | proc_create("kpagecount", S_IRUSR, NULL, &proc_kpagecount_operations); |
966 | proc_create("kpageflags", S_IRUSR, NULL, &proc_kpageflags_operations); | |
1e883281 | 967 | #endif |
666bfddb | 968 | #ifdef CONFIG_PROC_VMCORE |
0d5c9f5f | 969 | proc_vmcore = proc_create("vmcore", S_IRUSR, NULL, &proc_vmcore_operations); |
666bfddb | 970 | #endif |
1da177e4 | 971 | #ifdef CONFIG_MAGIC_SYSRQ |
0d5c9f5f | 972 | proc_create("sysrq-trigger", S_IWUSR, NULL, &proc_sysrq_trigger_operations); |
1da177e4 | 973 | #endif |
1da177e4 | 974 | } |