Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Neil Horman | 7170be5 | 2006-01-14 13:20:38 -0800 | [diff] [blame] | 23 | #include <linux/fs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/tty.h> |
| 25 | #include <linux/string.h> |
| 26 | #include <linux/mman.h> |
KOSAKI Motohiro | 4b85615 | 2008-09-02 14:35:53 -0700 | [diff] [blame] | 27 | #include <linux/quicklist.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/proc_fs.h> |
| 29 | #include <linux/ioport.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/mm.h> |
| 31 | #include <linux/mmzone.h> |
| 32 | #include <linux/pagemap.h> |
Yinghai Lu | c7fb03a | 2008-08-19 20:50:12 -0700 | [diff] [blame] | 33 | #include <linux/irq.h> |
Adrian Bunk | f74596d | 2008-02-06 01:36:35 -0800 | [diff] [blame] | 34 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <linux/swap.h> |
| 36 | #include <linux/slab.h> |
Adrian Bunk | a0db701 | 2008-03-04 11:23:50 +0100 | [diff] [blame] | 37 | #include <linux/genhd.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include <linux/smp.h> |
| 39 | #include <linux/signal.h> |
| 40 | #include <linux/module.h> |
| 41 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <linux/seq_file.h> |
| 43 | #include <linux/times.h> |
| 44 | #include <linux/profile.h> |
Andrew Morton | 7bf6538 | 2006-12-08 02:41:14 -0800 | [diff] [blame] | 45 | #include <linux/utsname.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #include <linux/blkdev.h> |
| 47 | #include <linux/hugetlb.h> |
| 48 | #include <linux/jiffies.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #include <linux/vmalloc.h> |
Vivek Goyal | 666bfdd | 2005-06-25 14:58:21 -0700 | [diff] [blame] | 50 | #include <linux/crash_dump.h> |
Sukadev Bhattiprolu | 61a58c6 | 2006-12-08 02:37:58 -0800 | [diff] [blame] | 51 | #include <linux/pid_namespace.h> |
Matt Mackall | 161f47b | 2008-02-04 22:29:05 -0800 | [diff] [blame] | 52 | #include <linux/bootmem.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | #include <asm/uaccess.h> |
| 54 | #include <asm/pgtable.h> |
| 55 | #include <asm/io.h> |
| 56 | #include <asm/tlb.h> |
| 57 | #include <asm/div64.h> |
| 58 | #include "internal.h" |
| 59 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | static int fragmentation_open(struct inode *inode, struct file *file) |
| 61 | { |
| 62 | (void)inode; |
| 63 | return seq_open(file, &fragmentation_op); |
| 64 | } |
| 65 | |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 66 | static const struct file_operations fragmentation_file_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | .open = fragmentation_open, |
| 68 | .read = seq_read, |
| 69 | .llseek = seq_lseek, |
| 70 | .release = seq_release, |
| 71 | }; |
| 72 | |
Mel Gorman | 467c996 | 2007-10-16 01:26:02 -0700 | [diff] [blame] | 73 | static int pagetypeinfo_open(struct inode *inode, struct file *file) |
| 74 | { |
| 75 | return seq_open(file, &pagetypeinfo_op); |
| 76 | } |
| 77 | |
| 78 | static const struct file_operations pagetypeinfo_file_ops = { |
| 79 | .open = pagetypeinfo_open, |
| 80 | .read = seq_read, |
| 81 | .llseek = seq_lseek, |
| 82 | .release = seq_release, |
| 83 | }; |
| 84 | |
Nikita Danilov | 295ab93 | 2005-06-21 17:14:38 -0700 | [diff] [blame] | 85 | static int zoneinfo_open(struct inode *inode, struct file *file) |
| 86 | { |
| 87 | return seq_open(file, &zoneinfo_op); |
| 88 | } |
| 89 | |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 90 | static const struct file_operations proc_zoneinfo_file_operations = { |
Nikita Danilov | 295ab93 | 2005-06-21 17:14:38 -0700 | [diff] [blame] | 91 | .open = zoneinfo_open, |
| 92 | .read = seq_read, |
| 93 | .llseek = seq_lseek, |
| 94 | .release = seq_release, |
| 95 | }; |
| 96 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | static int vmstat_open(struct inode *inode, struct file *file) |
| 98 | { |
| 99 | return seq_open(file, &vmstat_op); |
| 100 | } |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 101 | static const struct file_operations proc_vmstat_file_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | .open = vmstat_open, |
| 103 | .read = seq_read, |
| 104 | .llseek = seq_lseek, |
| 105 | .release = seq_release, |
| 106 | }; |
| 107 | |
David Howells | 9361401 | 2006-09-30 20:45:40 +0200 | [diff] [blame] | 108 | #ifdef CONFIG_BLOCK |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | static int diskstats_open(struct inode *inode, struct file *file) |
| 110 | { |
| 111 | return seq_open(file, &diskstats_op); |
| 112 | } |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 113 | static const struct file_operations proc_diskstats_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | .open = diskstats_open, |
| 115 | .read = seq_read, |
| 116 | .llseek = seq_lseek, |
| 117 | .release = seq_release, |
| 118 | }; |
David Howells | 9361401 | 2006-09-30 20:45:40 +0200 | [diff] [blame] | 119 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | |
| 121 | #ifdef CONFIG_MODULES |
Jan Engelhardt | 03a4482 | 2008-02-08 04:21:19 -0800 | [diff] [blame] | 122 | extern const struct seq_operations modules_op; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | static int modules_open(struct inode *inode, struct file *file) |
| 124 | { |
| 125 | return seq_open(file, &modules_op); |
| 126 | } |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 127 | static const struct file_operations proc_modules_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | .open = modules_open, |
| 129 | .read = seq_read, |
| 130 | .llseek = seq_lseek, |
| 131 | .release = seq_release, |
| 132 | }; |
| 133 | #endif |
| 134 | |
Linus Torvalds | 158a962 | 2008-01-02 13:04:48 -0800 | [diff] [blame] | 135 | #ifdef CONFIG_SLABINFO |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | static int slabinfo_open(struct inode *inode, struct file *file) |
| 137 | { |
| 138 | return seq_open(file, &slabinfo_op); |
| 139 | } |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 140 | static const struct file_operations proc_slabinfo_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | .open = slabinfo_open, |
| 142 | .read = seq_read, |
| 143 | .write = slabinfo_write, |
| 144 | .llseek = seq_lseek, |
| 145 | .release = seq_release, |
| 146 | }; |
Al Viro | 871751e | 2006-03-25 03:06:39 -0800 | [diff] [blame] | 147 | |
| 148 | #ifdef CONFIG_DEBUG_SLAB_LEAK |
Jan Engelhardt | 03a4482 | 2008-02-08 04:21:19 -0800 | [diff] [blame] | 149 | extern const struct seq_operations slabstats_op; |
Al Viro | 871751e | 2006-03-25 03:06:39 -0800 | [diff] [blame] | 150 | static int slabstats_open(struct inode *inode, struct file *file) |
| 151 | { |
| 152 | unsigned long *n = kzalloc(PAGE_SIZE, GFP_KERNEL); |
| 153 | int ret = -ENOMEM; |
| 154 | if (n) { |
| 155 | ret = seq_open(file, &slabstats_op); |
| 156 | if (!ret) { |
| 157 | struct seq_file *m = file->private_data; |
| 158 | *n = PAGE_SIZE / (2 * sizeof(unsigned long)); |
| 159 | m->private = n; |
| 160 | n = NULL; |
| 161 | } |
| 162 | kfree(n); |
| 163 | } |
| 164 | return ret; |
| 165 | } |
| 166 | |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 167 | static const struct file_operations proc_slabstats_operations = { |
Al Viro | 871751e | 2006-03-25 03:06:39 -0800 | [diff] [blame] | 168 | .open = slabstats_open, |
| 169 | .read = seq_read, |
| 170 | .llseek = seq_lseek, |
Martin Peschke | 09f0892 | 2007-05-08 00:29:26 -0700 | [diff] [blame] | 171 | .release = seq_release_private, |
Al Viro | 871751e | 2006-03-25 03:06:39 -0800 | [diff] [blame] | 172 | }; |
| 173 | #endif |
Matt Mackall | 10cef60 | 2006-01-08 01:01:45 -0800 | [diff] [blame] | 174 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
Christoph Lameter | a10aa57 | 2008-04-28 02:12:40 -0700 | [diff] [blame] | 176 | #ifdef CONFIG_MMU |
| 177 | static int vmalloc_open(struct inode *inode, struct file *file) |
| 178 | { |
Eric Dumazet | a47a126 | 2008-07-23 21:27:38 -0700 | [diff] [blame] | 179 | unsigned int *ptr = NULL; |
| 180 | int ret; |
| 181 | |
| 182 | if (NUMA_BUILD) |
| 183 | ptr = kmalloc(nr_node_ids * sizeof(unsigned int), GFP_KERNEL); |
| 184 | ret = seq_open(file, &vmalloc_op); |
| 185 | if (!ret) { |
| 186 | struct seq_file *m = file->private_data; |
| 187 | m->private = ptr; |
| 188 | } else |
| 189 | kfree(ptr); |
| 190 | return ret; |
Christoph Lameter | a10aa57 | 2008-04-28 02:12:40 -0700 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | static const struct file_operations proc_vmalloc_operations = { |
| 194 | .open = vmalloc_open, |
| 195 | .read = seq_read, |
| 196 | .llseek = seq_lseek, |
Eric Dumazet | a47a126 | 2008-07-23 21:27:38 -0700 | [diff] [blame] | 197 | .release = seq_release_private, |
Christoph Lameter | a10aa57 | 2008-04-28 02:12:40 -0700 | [diff] [blame] | 198 | }; |
| 199 | #endif |
| 200 | |
Jan Beulich | a2eddfa | 2008-05-12 15:44:41 +0200 | [diff] [blame] | 201 | #ifndef arch_irq_stat_cpu |
| 202 | #define arch_irq_stat_cpu(cpu) 0 |
| 203 | #endif |
| 204 | #ifndef arch_irq_stat |
| 205 | #define arch_irq_stat() 0 |
| 206 | #endif |
| 207 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | static int show_stat(struct seq_file *p, void *v) |
| 209 | { |
Yinghai Lu | c7fb03a | 2008-08-19 20:50:12 -0700 | [diff] [blame] | 210 | int i, j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | unsigned long jif; |
| 212 | cputime64_t user, nice, system, idle, iowait, irq, softirq, steal; |
Laurent Vivier | 5e84cfd | 2007-10-15 17:00:19 +0200 | [diff] [blame] | 213 | cputime64_t guest; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | u64 sum = 0; |
Tomas Janousek | 924b42d | 2007-07-15 23:39:42 -0700 | [diff] [blame] | 215 | struct timespec boottime; |
Yinghai Lu | c7fb03a | 2008-08-19 20:50:12 -0700 | [diff] [blame] | 216 | unsigned int per_irq_sum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | |
| 218 | user = nice = system = idle = iowait = |
| 219 | irq = softirq = steal = cputime64_zero; |
Laurent Vivier | 5e84cfd | 2007-10-15 17:00:19 +0200 | [diff] [blame] | 220 | guest = cputime64_zero; |
Tomas Janousek | 924b42d | 2007-07-15 23:39:42 -0700 | [diff] [blame] | 221 | getboottime(&boottime); |
| 222 | jif = boottime.tv_sec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
KAMEZAWA Hiroyuki | 0a94502 | 2006-03-28 01:56:37 -0800 | [diff] [blame] | 224 | for_each_possible_cpu(i) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | user = cputime64_add(user, kstat_cpu(i).cpustat.user); |
| 226 | nice = cputime64_add(nice, kstat_cpu(i).cpustat.nice); |
| 227 | system = cputime64_add(system, kstat_cpu(i).cpustat.system); |
| 228 | idle = cputime64_add(idle, kstat_cpu(i).cpustat.idle); |
| 229 | iowait = cputime64_add(iowait, kstat_cpu(i).cpustat.iowait); |
| 230 | irq = cputime64_add(irq, kstat_cpu(i).cpustat.irq); |
| 231 | softirq = cputime64_add(softirq, kstat_cpu(i).cpustat.softirq); |
| 232 | steal = cputime64_add(steal, kstat_cpu(i).cpustat.steal); |
Laurent Vivier | 5e84cfd | 2007-10-15 17:00:19 +0200 | [diff] [blame] | 233 | guest = cputime64_add(guest, kstat_cpu(i).cpustat.guest); |
Yinghai Lu | c7fb03a | 2008-08-19 20:50:12 -0700 | [diff] [blame] | 234 | |
Thomas Gleixner | 2be3b52 | 2008-10-16 14:50:27 +0200 | [diff] [blame] | 235 | for_each_irq_nr(j) |
Thomas Gleixner | 2cc21ef | 2008-10-15 14:16:55 +0200 | [diff] [blame] | 236 | sum += kstat_irqs_cpu(j, i); |
| 237 | |
Jan Beulich | a2eddfa | 2008-05-12 15:44:41 +0200 | [diff] [blame] | 238 | sum += arch_irq_stat_cpu(i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | } |
Jan Beulich | a2eddfa | 2008-05-12 15:44:41 +0200 | [diff] [blame] | 240 | sum += arch_irq_stat(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | |
Laurent Vivier | 5e84cfd | 2007-10-15 17:00:19 +0200 | [diff] [blame] | 242 | seq_printf(p, "cpu %llu %llu %llu %llu %llu %llu %llu %llu %llu\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | (unsigned long long)cputime64_to_clock_t(user), |
| 244 | (unsigned long long)cputime64_to_clock_t(nice), |
| 245 | (unsigned long long)cputime64_to_clock_t(system), |
| 246 | (unsigned long long)cputime64_to_clock_t(idle), |
| 247 | (unsigned long long)cputime64_to_clock_t(iowait), |
| 248 | (unsigned long long)cputime64_to_clock_t(irq), |
| 249 | (unsigned long long)cputime64_to_clock_t(softirq), |
Laurent Vivier | 5e84cfd | 2007-10-15 17:00:19 +0200 | [diff] [blame] | 250 | (unsigned long long)cputime64_to_clock_t(steal), |
| 251 | (unsigned long long)cputime64_to_clock_t(guest)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | for_each_online_cpu(i) { |
| 253 | |
| 254 | /* Copy values here to work around gcc-2.95.3, gcc-2.96 */ |
| 255 | user = kstat_cpu(i).cpustat.user; |
| 256 | nice = kstat_cpu(i).cpustat.nice; |
| 257 | system = kstat_cpu(i).cpustat.system; |
| 258 | idle = kstat_cpu(i).cpustat.idle; |
| 259 | iowait = kstat_cpu(i).cpustat.iowait; |
| 260 | irq = kstat_cpu(i).cpustat.irq; |
| 261 | softirq = kstat_cpu(i).cpustat.softirq; |
| 262 | steal = kstat_cpu(i).cpustat.steal; |
Laurent Vivier | 5e84cfd | 2007-10-15 17:00:19 +0200 | [diff] [blame] | 263 | guest = kstat_cpu(i).cpustat.guest; |
| 264 | seq_printf(p, |
| 265 | "cpu%d %llu %llu %llu %llu %llu %llu %llu %llu %llu\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | i, |
| 267 | (unsigned long long)cputime64_to_clock_t(user), |
| 268 | (unsigned long long)cputime64_to_clock_t(nice), |
| 269 | (unsigned long long)cputime64_to_clock_t(system), |
| 270 | (unsigned long long)cputime64_to_clock_t(idle), |
| 271 | (unsigned long long)cputime64_to_clock_t(iowait), |
| 272 | (unsigned long long)cputime64_to_clock_t(irq), |
| 273 | (unsigned long long)cputime64_to_clock_t(softirq), |
Laurent Vivier | 5e84cfd | 2007-10-15 17:00:19 +0200 | [diff] [blame] | 274 | (unsigned long long)cputime64_to_clock_t(steal), |
| 275 | (unsigned long long)cputime64_to_clock_t(guest)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | } |
| 277 | seq_printf(p, "intr %llu", (unsigned long long)sum); |
| 278 | |
Yinghai Lu | c7fb03a | 2008-08-19 20:50:12 -0700 | [diff] [blame] | 279 | /* sum again ? it could be updated? */ |
Thomas Gleixner | 2be3b52 | 2008-10-16 14:50:27 +0200 | [diff] [blame] | 280 | for_each_irq_nr(j) { |
Yinghai Lu | c7fb03a | 2008-08-19 20:50:12 -0700 | [diff] [blame] | 281 | per_irq_sum = 0; |
Yinghai Lu | c7fb03a | 2008-08-19 20:50:12 -0700 | [diff] [blame] | 282 | |
Thomas Gleixner | 2cc21ef | 2008-10-15 14:16:55 +0200 | [diff] [blame] | 283 | for_each_possible_cpu(i) |
| 284 | per_irq_sum += kstat_irqs_cpu(j, i); |
Yinghai Lu | c7fb03a | 2008-08-19 20:50:12 -0700 | [diff] [blame] | 285 | |
Yinghai Lu | c7fb03a | 2008-08-19 20:50:12 -0700 | [diff] [blame] | 286 | seq_printf(p, " %u", per_irq_sum); |
Yinghai Lu | c7fb03a | 2008-08-19 20:50:12 -0700 | [diff] [blame] | 287 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | |
| 289 | seq_printf(p, |
| 290 | "\nctxt %llu\n" |
| 291 | "btime %lu\n" |
| 292 | "processes %lu\n" |
| 293 | "procs_running %lu\n" |
| 294 | "procs_blocked %lu\n", |
| 295 | nr_context_switches(), |
| 296 | (unsigned long)jif, |
| 297 | total_forks, |
| 298 | nr_running(), |
| 299 | nr_iowait()); |
| 300 | |
| 301 | return 0; |
| 302 | } |
| 303 | |
| 304 | static int stat_open(struct inode *inode, struct file *file) |
| 305 | { |
| 306 | unsigned size = 4096 * (1 + num_possible_cpus() / 32); |
| 307 | char *buf; |
| 308 | struct seq_file *m; |
| 309 | int res; |
| 310 | |
| 311 | /* don't ask for more than the kmalloc() max size, currently 128 KB */ |
| 312 | if (size > 128 * 1024) |
| 313 | size = 128 * 1024; |
| 314 | buf = kmalloc(size, GFP_KERNEL); |
| 315 | if (!buf) |
| 316 | return -ENOMEM; |
| 317 | |
| 318 | res = single_open(file, show_stat, NULL); |
| 319 | if (!res) { |
| 320 | m = file->private_data; |
| 321 | m->buf = buf; |
| 322 | m->size = size; |
| 323 | } else |
| 324 | kfree(buf); |
| 325 | return res; |
| 326 | } |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 327 | static const struct file_operations proc_stat_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | .open = stat_open, |
| 329 | .read = seq_read, |
| 330 | .llseek = seq_lseek, |
| 331 | .release = single_release, |
| 332 | }; |
| 333 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | /* |
| 335 | * /proc/interrupts |
| 336 | */ |
| 337 | static void *int_seq_start(struct seq_file *f, loff_t *pos) |
| 338 | { |
Yinghai Lu | da27c11 | 2008-08-19 20:49:56 -0700 | [diff] [blame] | 339 | return (*pos <= nr_irqs) ? pos : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | } |
| 341 | |
Yinghai Lu | 52b1732 | 2008-08-19 20:50:20 -0700 | [diff] [blame] | 342 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | static void *int_seq_next(struct seq_file *f, void *v, loff_t *pos) |
| 344 | { |
| 345 | (*pos)++; |
Yinghai Lu | 52b1732 | 2008-08-19 20:50:20 -0700 | [diff] [blame] | 346 | return (*pos <= nr_irqs) ? pos : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | static void int_seq_stop(struct seq_file *f, void *v) |
| 350 | { |
| 351 | /* Nothing to do */ |
| 352 | } |
| 353 | |
Jan Engelhardt | 03a4482 | 2008-02-08 04:21:19 -0800 | [diff] [blame] | 354 | static const struct seq_operations int_seq_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | .start = int_seq_start, |
| 356 | .next = int_seq_next, |
| 357 | .stop = int_seq_stop, |
| 358 | .show = show_interrupts |
| 359 | }; |
| 360 | |
| 361 | static int interrupts_open(struct inode *inode, struct file *filp) |
| 362 | { |
| 363 | return seq_open(filp, &int_seq_ops); |
| 364 | } |
| 365 | |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 366 | static const struct file_operations proc_interrupts_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | .open = interrupts_open, |
| 368 | .read = seq_read, |
| 369 | .llseek = seq_lseek, |
| 370 | .release = seq_release, |
| 371 | }; |
| 372 | |
Matt Mackall | 1e88328 | 2008-02-04 22:29:07 -0800 | [diff] [blame] | 373 | #ifdef CONFIG_PROC_PAGE_MONITOR |
Matt Mackall | 161f47b | 2008-02-04 22:29:05 -0800 | [diff] [blame] | 374 | #define KPMSIZE sizeof(u64) |
| 375 | #define KPMMASK (KPMSIZE - 1) |
| 376 | /* /proc/kpagecount - an array exposing page counts |
| 377 | * |
| 378 | * Each entry is a u64 representing the corresponding |
| 379 | * physical page count. |
| 380 | */ |
| 381 | static ssize_t kpagecount_read(struct file *file, char __user *buf, |
| 382 | size_t count, loff_t *ppos) |
| 383 | { |
| 384 | u64 __user *out = (u64 __user *)buf; |
| 385 | struct page *ppage; |
| 386 | unsigned long src = *ppos; |
| 387 | unsigned long pfn; |
| 388 | ssize_t ret = 0; |
| 389 | u64 pcount; |
| 390 | |
| 391 | pfn = src / KPMSIZE; |
| 392 | count = min_t(size_t, count, (max_pfn * KPMSIZE) - src); |
| 393 | if (src & KPMMASK || count & KPMMASK) |
Thomas Tuttle | 4710d1a | 2008-06-05 22:46:58 -0700 | [diff] [blame] | 394 | return -EINVAL; |
Matt Mackall | 161f47b | 2008-02-04 22:29:05 -0800 | [diff] [blame] | 395 | |
| 396 | while (count > 0) { |
Matt Mackall | 304daa8 | 2008-02-04 22:29:06 -0800 | [diff] [blame] | 397 | ppage = NULL; |
| 398 | if (pfn_valid(pfn)) |
| 399 | ppage = pfn_to_page(pfn); |
| 400 | pfn++; |
Matt Mackall | 161f47b | 2008-02-04 22:29:05 -0800 | [diff] [blame] | 401 | if (!ppage) |
| 402 | pcount = 0; |
| 403 | else |
Thomas Tuttle | bbcdac0 | 2008-06-05 22:46:58 -0700 | [diff] [blame] | 404 | pcount = page_mapcount(ppage); |
Matt Mackall | 161f47b | 2008-02-04 22:29:05 -0800 | [diff] [blame] | 405 | |
| 406 | if (put_user(pcount, out++)) { |
| 407 | ret = -EFAULT; |
| 408 | break; |
| 409 | } |
| 410 | |
| 411 | count -= KPMSIZE; |
| 412 | } |
| 413 | |
| 414 | *ppos += (char __user *)out - buf; |
| 415 | if (!ret) |
| 416 | ret = (char __user *)out - buf; |
| 417 | return ret; |
| 418 | } |
| 419 | |
| 420 | static struct file_operations proc_kpagecount_operations = { |
| 421 | .llseek = mem_lseek, |
| 422 | .read = kpagecount_read, |
| 423 | }; |
| 424 | |
Matt Mackall | 304daa8 | 2008-02-04 22:29:06 -0800 | [diff] [blame] | 425 | /* /proc/kpageflags - an array exposing page flags |
| 426 | * |
| 427 | * Each entry is a u64 representing the corresponding |
| 428 | * physical page flags. |
| 429 | */ |
| 430 | |
| 431 | /* These macros are used to decouple internal flags from exported ones */ |
| 432 | |
| 433 | #define KPF_LOCKED 0 |
| 434 | #define KPF_ERROR 1 |
| 435 | #define KPF_REFERENCED 2 |
| 436 | #define KPF_UPTODATE 3 |
| 437 | #define KPF_DIRTY 4 |
| 438 | #define KPF_LRU 5 |
| 439 | #define KPF_ACTIVE 6 |
| 440 | #define KPF_SLAB 7 |
| 441 | #define KPF_WRITEBACK 8 |
| 442 | #define KPF_RECLAIM 9 |
| 443 | #define KPF_BUDDY 10 |
| 444 | |
| 445 | #define kpf_copy_bit(flags, srcpos, dstpos) (((flags >> srcpos) & 1) << dstpos) |
| 446 | |
| 447 | static ssize_t kpageflags_read(struct file *file, char __user *buf, |
| 448 | size_t count, loff_t *ppos) |
| 449 | { |
| 450 | u64 __user *out = (u64 __user *)buf; |
| 451 | struct page *ppage; |
| 452 | unsigned long src = *ppos; |
| 453 | unsigned long pfn; |
| 454 | ssize_t ret = 0; |
| 455 | u64 kflags, uflags; |
| 456 | |
| 457 | pfn = src / KPMSIZE; |
| 458 | count = min_t(unsigned long, count, (max_pfn * KPMSIZE) - src); |
| 459 | if (src & KPMMASK || count & KPMMASK) |
Thomas Tuttle | 4710d1a | 2008-06-05 22:46:58 -0700 | [diff] [blame] | 460 | return -EINVAL; |
Matt Mackall | 304daa8 | 2008-02-04 22:29:06 -0800 | [diff] [blame] | 461 | |
| 462 | while (count > 0) { |
| 463 | ppage = NULL; |
| 464 | if (pfn_valid(pfn)) |
| 465 | ppage = pfn_to_page(pfn); |
| 466 | pfn++; |
| 467 | if (!ppage) |
| 468 | kflags = 0; |
| 469 | else |
| 470 | kflags = ppage->flags; |
| 471 | |
| 472 | uflags = kpf_copy_bit(KPF_LOCKED, PG_locked, kflags) | |
| 473 | kpf_copy_bit(kflags, KPF_ERROR, PG_error) | |
| 474 | kpf_copy_bit(kflags, KPF_REFERENCED, PG_referenced) | |
| 475 | kpf_copy_bit(kflags, KPF_UPTODATE, PG_uptodate) | |
| 476 | kpf_copy_bit(kflags, KPF_DIRTY, PG_dirty) | |
| 477 | kpf_copy_bit(kflags, KPF_LRU, PG_lru) | |
| 478 | kpf_copy_bit(kflags, KPF_ACTIVE, PG_active) | |
| 479 | kpf_copy_bit(kflags, KPF_SLAB, PG_slab) | |
| 480 | kpf_copy_bit(kflags, KPF_WRITEBACK, PG_writeback) | |
| 481 | kpf_copy_bit(kflags, KPF_RECLAIM, PG_reclaim) | |
| 482 | kpf_copy_bit(kflags, KPF_BUDDY, PG_buddy); |
| 483 | |
| 484 | if (put_user(uflags, out++)) { |
| 485 | ret = -EFAULT; |
| 486 | break; |
| 487 | } |
| 488 | |
| 489 | count -= KPMSIZE; |
| 490 | } |
| 491 | |
| 492 | *ppos += (char __user *)out - buf; |
| 493 | if (!ret) |
| 494 | ret = (char __user *)out - buf; |
| 495 | return ret; |
| 496 | } |
| 497 | |
| 498 | static struct file_operations proc_kpageflags_operations = { |
| 499 | .llseek = mem_lseek, |
| 500 | .read = kpageflags_read, |
| 501 | }; |
Matt Mackall | 1e88328 | 2008-02-04 22:29:07 -0800 | [diff] [blame] | 502 | #endif /* CONFIG_PROC_PAGE_MONITOR */ |
Matt Mackall | 304daa8 | 2008-02-04 22:29:06 -0800 | [diff] [blame] | 503 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | struct proc_dir_entry *proc_root_kcore; |
| 505 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | void __init proc_misc_init(void) |
| 507 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | proc_symlink("mounts", NULL, "self/mounts"); |
| 509 | |
| 510 | /* And now for trickier ones */ |
Alexey Dobriyan | 0d5c9f5 | 2008-04-29 01:01:37 -0700 | [diff] [blame] | 511 | proc_create("stat", 0, NULL, &proc_stat_operations); |
| 512 | proc_create("interrupts", 0, NULL, &proc_interrupts_operations); |
Linus Torvalds | 158a962 | 2008-01-02 13:04:48 -0800 | [diff] [blame] | 513 | #ifdef CONFIG_SLABINFO |
Alexey Dobriyan | 0d5c9f5 | 2008-04-29 01:01:37 -0700 | [diff] [blame] | 514 | proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations); |
Al Viro | 871751e | 2006-03-25 03:06:39 -0800 | [diff] [blame] | 515 | #ifdef CONFIG_DEBUG_SLAB_LEAK |
Alexey Dobriyan | 0d5c9f5 | 2008-04-29 01:01:37 -0700 | [diff] [blame] | 516 | proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations); |
Al Viro | 871751e | 2006-03-25 03:06:39 -0800 | [diff] [blame] | 517 | #endif |
Matt Mackall | 10cef60 | 2006-01-08 01:01:45 -0800 | [diff] [blame] | 518 | #endif |
Christoph Lameter | a10aa57 | 2008-04-28 02:12:40 -0700 | [diff] [blame] | 519 | #ifdef CONFIG_MMU |
| 520 | proc_create("vmallocinfo", S_IRUSR, NULL, &proc_vmalloc_operations); |
| 521 | #endif |
Alexey Dobriyan | 0d5c9f5 | 2008-04-29 01:01:37 -0700 | [diff] [blame] | 522 | proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations); |
| 523 | proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops); |
| 524 | proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations); |
| 525 | proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations); |
David Howells | 9361401 | 2006-09-30 20:45:40 +0200 | [diff] [blame] | 526 | #ifdef CONFIG_BLOCK |
Alexey Dobriyan | 0d5c9f5 | 2008-04-29 01:01:37 -0700 | [diff] [blame] | 527 | proc_create("diskstats", 0, NULL, &proc_diskstats_operations); |
David Howells | 9361401 | 2006-09-30 20:45:40 +0200 | [diff] [blame] | 528 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | #ifdef CONFIG_MODULES |
Alexey Dobriyan | 0d5c9f5 | 2008-04-29 01:01:37 -0700 | [diff] [blame] | 530 | proc_create("modules", 0, NULL, &proc_modules_operations); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | #endif |
| 532 | #ifdef CONFIG_SCHEDSTATS |
Alexey Dobriyan | 0d5c9f5 | 2008-04-29 01:01:37 -0700 | [diff] [blame] | 533 | proc_create("schedstat", 0, NULL, &proc_schedstat_operations); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | #endif |
| 535 | #ifdef CONFIG_PROC_KCORE |
Alexey Dobriyan | 0d5c9f5 | 2008-04-29 01:01:37 -0700 | [diff] [blame] | 536 | proc_root_kcore = proc_create("kcore", S_IRUSR, NULL, &proc_kcore_operations); |
| 537 | if (proc_root_kcore) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | proc_root_kcore->size = |
| 539 | (size_t)high_memory - PAGE_OFFSET + PAGE_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | #endif |
Matt Mackall | 1e88328 | 2008-02-04 22:29:07 -0800 | [diff] [blame] | 541 | #ifdef CONFIG_PROC_PAGE_MONITOR |
Alexey Dobriyan | 0d5c9f5 | 2008-04-29 01:01:37 -0700 | [diff] [blame] | 542 | proc_create("kpagecount", S_IRUSR, NULL, &proc_kpagecount_operations); |
| 543 | proc_create("kpageflags", S_IRUSR, NULL, &proc_kpageflags_operations); |
Matt Mackall | 1e88328 | 2008-02-04 22:29:07 -0800 | [diff] [blame] | 544 | #endif |
Vivek Goyal | 666bfdd | 2005-06-25 14:58:21 -0700 | [diff] [blame] | 545 | #ifdef CONFIG_PROC_VMCORE |
Alexey Dobriyan | 0d5c9f5 | 2008-04-29 01:01:37 -0700 | [diff] [blame] | 546 | proc_vmcore = proc_create("vmcore", S_IRUSR, NULL, &proc_vmcore_operations); |
Vivek Goyal | 666bfdd | 2005-06-25 14:58:21 -0700 | [diff] [blame] | 547 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | } |