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