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