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 | |
Jan Engelhardt | 03a4482 | 2008-02-08 04:21:19 -0800 | [diff] [blame] | 97 | extern const struct seq_operations cpuinfo_op; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | static int cpuinfo_open(struct inode *inode, struct file *file) |
| 99 | { |
| 100 | return seq_open(file, &cpuinfo_op); |
| 101 | } |
Neil Horman | 7170be5 | 2006-01-14 13:20:38 -0800 | [diff] [blame] | 102 | |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 103 | static const struct file_operations proc_cpuinfo_operations = { |
Joe Korty | 68eef3b | 2006-03-31 02:30:32 -0800 | [diff] [blame] | 104 | .open = cpuinfo_open, |
Neil Horman | 7170be5 | 2006-01-14 13:20:38 -0800 | [diff] [blame] | 105 | .read = seq_read, |
| 106 | .llseek = seq_lseek, |
| 107 | .release = seq_release, |
| 108 | }; |
| 109 | |
Joe Korty | 68eef3b | 2006-03-31 02:30:32 -0800 | [diff] [blame] | 110 | static int devinfo_show(struct seq_file *f, void *v) |
| 111 | { |
| 112 | int i = *(loff_t *) v; |
| 113 | |
| 114 | if (i < CHRDEV_MAJOR_HASH_SIZE) { |
| 115 | if (i == 0) |
| 116 | seq_printf(f, "Character devices:\n"); |
| 117 | chrdev_show(f, i); |
David Howells | 9361401 | 2006-09-30 20:45:40 +0200 | [diff] [blame] | 118 | } |
| 119 | #ifdef CONFIG_BLOCK |
| 120 | else { |
Joe Korty | 68eef3b | 2006-03-31 02:30:32 -0800 | [diff] [blame] | 121 | i -= CHRDEV_MAJOR_HASH_SIZE; |
| 122 | if (i == 0) |
| 123 | seq_printf(f, "\nBlock devices:\n"); |
| 124 | blkdev_show(f, i); |
| 125 | } |
David Howells | 9361401 | 2006-09-30 20:45:40 +0200 | [diff] [blame] | 126 | #endif |
Joe Korty | 68eef3b | 2006-03-31 02:30:32 -0800 | [diff] [blame] | 127 | return 0; |
| 128 | } |
| 129 | |
| 130 | static void *devinfo_start(struct seq_file *f, loff_t *pos) |
| 131 | { |
| 132 | if (*pos < (BLKDEV_MAJOR_HASH_SIZE + CHRDEV_MAJOR_HASH_SIZE)) |
| 133 | return pos; |
| 134 | return NULL; |
| 135 | } |
| 136 | |
| 137 | static void *devinfo_next(struct seq_file *f, void *v, loff_t *pos) |
| 138 | { |
| 139 | (*pos)++; |
| 140 | if (*pos >= (BLKDEV_MAJOR_HASH_SIZE + CHRDEV_MAJOR_HASH_SIZE)) |
| 141 | return NULL; |
| 142 | return pos; |
| 143 | } |
| 144 | |
| 145 | static void devinfo_stop(struct seq_file *f, void *v) |
| 146 | { |
| 147 | /* Nothing to do */ |
| 148 | } |
| 149 | |
Jan Engelhardt | 03a4482 | 2008-02-08 04:21:19 -0800 | [diff] [blame] | 150 | static const struct seq_operations devinfo_ops = { |
Joe Korty | 68eef3b | 2006-03-31 02:30:32 -0800 | [diff] [blame] | 151 | .start = devinfo_start, |
| 152 | .next = devinfo_next, |
| 153 | .stop = devinfo_stop, |
| 154 | .show = devinfo_show |
| 155 | }; |
| 156 | |
| 157 | static int devinfo_open(struct inode *inode, struct file *filp) |
| 158 | { |
| 159 | return seq_open(filp, &devinfo_ops); |
| 160 | } |
| 161 | |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 162 | static const struct file_operations proc_devinfo_operations = { |
Joe Korty | 68eef3b | 2006-03-31 02:30:32 -0800 | [diff] [blame] | 163 | .open = devinfo_open, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | .read = seq_read, |
| 165 | .llseek = seq_lseek, |
| 166 | .release = seq_release, |
| 167 | }; |
| 168 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | static int vmstat_open(struct inode *inode, struct file *file) |
| 170 | { |
| 171 | return seq_open(file, &vmstat_op); |
| 172 | } |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 173 | static const struct file_operations proc_vmstat_file_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | .open = vmstat_open, |
| 175 | .read = seq_read, |
| 176 | .llseek = seq_lseek, |
| 177 | .release = seq_release, |
| 178 | }; |
| 179 | |
David Howells | 9361401 | 2006-09-30 20:45:40 +0200 | [diff] [blame] | 180 | #ifdef CONFIG_BLOCK |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | static int partitions_open(struct inode *inode, struct file *file) |
| 182 | { |
| 183 | return seq_open(file, &partitions_op); |
| 184 | } |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 185 | static const struct file_operations proc_partitions_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | .open = partitions_open, |
| 187 | .read = seq_read, |
| 188 | .llseek = seq_lseek, |
| 189 | .release = seq_release, |
| 190 | }; |
| 191 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | static int diskstats_open(struct inode *inode, struct file *file) |
| 193 | { |
| 194 | return seq_open(file, &diskstats_op); |
| 195 | } |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 196 | static const struct file_operations proc_diskstats_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | .open = diskstats_open, |
| 198 | .read = seq_read, |
| 199 | .llseek = seq_lseek, |
| 200 | .release = seq_release, |
| 201 | }; |
David Howells | 9361401 | 2006-09-30 20:45:40 +0200 | [diff] [blame] | 202 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
| 204 | #ifdef CONFIG_MODULES |
Jan Engelhardt | 03a4482 | 2008-02-08 04:21:19 -0800 | [diff] [blame] | 205 | extern const struct seq_operations modules_op; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | static int modules_open(struct inode *inode, struct file *file) |
| 207 | { |
| 208 | return seq_open(file, &modules_op); |
| 209 | } |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 210 | static const struct file_operations proc_modules_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | .open = modules_open, |
| 212 | .read = seq_read, |
| 213 | .llseek = seq_lseek, |
| 214 | .release = seq_release, |
| 215 | }; |
| 216 | #endif |
| 217 | |
Linus Torvalds | 158a962 | 2008-01-02 13:04:48 -0800 | [diff] [blame] | 218 | #ifdef CONFIG_SLABINFO |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | static int slabinfo_open(struct inode *inode, struct file *file) |
| 220 | { |
| 221 | return seq_open(file, &slabinfo_op); |
| 222 | } |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 223 | static const struct file_operations proc_slabinfo_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | .open = slabinfo_open, |
| 225 | .read = seq_read, |
| 226 | .write = slabinfo_write, |
| 227 | .llseek = seq_lseek, |
| 228 | .release = seq_release, |
| 229 | }; |
Al Viro | 871751e | 2006-03-25 03:06:39 -0800 | [diff] [blame] | 230 | |
| 231 | #ifdef CONFIG_DEBUG_SLAB_LEAK |
Jan Engelhardt | 03a4482 | 2008-02-08 04:21:19 -0800 | [diff] [blame] | 232 | extern const struct seq_operations slabstats_op; |
Al Viro | 871751e | 2006-03-25 03:06:39 -0800 | [diff] [blame] | 233 | static int slabstats_open(struct inode *inode, struct file *file) |
| 234 | { |
| 235 | unsigned long *n = kzalloc(PAGE_SIZE, GFP_KERNEL); |
| 236 | int ret = -ENOMEM; |
| 237 | if (n) { |
| 238 | ret = seq_open(file, &slabstats_op); |
| 239 | if (!ret) { |
| 240 | struct seq_file *m = file->private_data; |
| 241 | *n = PAGE_SIZE / (2 * sizeof(unsigned long)); |
| 242 | m->private = n; |
| 243 | n = NULL; |
| 244 | } |
| 245 | kfree(n); |
| 246 | } |
| 247 | return ret; |
| 248 | } |
| 249 | |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 250 | static const struct file_operations proc_slabstats_operations = { |
Al Viro | 871751e | 2006-03-25 03:06:39 -0800 | [diff] [blame] | 251 | .open = slabstats_open, |
| 252 | .read = seq_read, |
| 253 | .llseek = seq_lseek, |
Martin Peschke | 09f0892 | 2007-05-08 00:29:26 -0700 | [diff] [blame] | 254 | .release = seq_release_private, |
Al Viro | 871751e | 2006-03-25 03:06:39 -0800 | [diff] [blame] | 255 | }; |
| 256 | #endif |
Matt Mackall | 10cef60 | 2006-01-08 01:01:45 -0800 | [diff] [blame] | 257 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | |
Christoph Lameter | a10aa57 | 2008-04-28 02:12:40 -0700 | [diff] [blame] | 259 | #ifdef CONFIG_MMU |
| 260 | static int vmalloc_open(struct inode *inode, struct file *file) |
| 261 | { |
Eric Dumazet | a47a126 | 2008-07-23 21:27:38 -0700 | [diff] [blame] | 262 | unsigned int *ptr = NULL; |
| 263 | int ret; |
| 264 | |
| 265 | if (NUMA_BUILD) |
| 266 | ptr = kmalloc(nr_node_ids * sizeof(unsigned int), GFP_KERNEL); |
| 267 | ret = seq_open(file, &vmalloc_op); |
| 268 | if (!ret) { |
| 269 | struct seq_file *m = file->private_data; |
| 270 | m->private = ptr; |
| 271 | } else |
| 272 | kfree(ptr); |
| 273 | return ret; |
Christoph Lameter | a10aa57 | 2008-04-28 02:12:40 -0700 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | static const struct file_operations proc_vmalloc_operations = { |
| 277 | .open = vmalloc_open, |
| 278 | .read = seq_read, |
| 279 | .llseek = seq_lseek, |
Eric Dumazet | a47a126 | 2008-07-23 21:27:38 -0700 | [diff] [blame] | 280 | .release = seq_release_private, |
Christoph Lameter | a10aa57 | 2008-04-28 02:12:40 -0700 | [diff] [blame] | 281 | }; |
| 282 | #endif |
| 283 | |
Jan Beulich | a2eddfa | 2008-05-12 15:44:41 +0200 | [diff] [blame] | 284 | #ifndef arch_irq_stat_cpu |
| 285 | #define arch_irq_stat_cpu(cpu) 0 |
| 286 | #endif |
| 287 | #ifndef arch_irq_stat |
| 288 | #define arch_irq_stat() 0 |
| 289 | #endif |
| 290 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | static int show_stat(struct seq_file *p, void *v) |
| 292 | { |
Yinghai Lu | c7fb03a | 2008-08-19 20:50:12 -0700 | [diff] [blame] | 293 | int i, j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | unsigned long jif; |
| 295 | cputime64_t user, nice, system, idle, iowait, irq, softirq, steal; |
Laurent Vivier | 5e84cfd | 2007-10-15 17:00:19 +0200 | [diff] [blame] | 296 | cputime64_t guest; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | u64 sum = 0; |
Tomas Janousek | 924b42d | 2007-07-15 23:39:42 -0700 | [diff] [blame] | 298 | struct timespec boottime; |
Yinghai Lu | c7fb03a | 2008-08-19 20:50:12 -0700 | [diff] [blame] | 299 | unsigned int per_irq_sum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | |
| 301 | user = nice = system = idle = iowait = |
| 302 | irq = softirq = steal = cputime64_zero; |
Laurent Vivier | 5e84cfd | 2007-10-15 17:00:19 +0200 | [diff] [blame] | 303 | guest = cputime64_zero; |
Tomas Janousek | 924b42d | 2007-07-15 23:39:42 -0700 | [diff] [blame] | 304 | getboottime(&boottime); |
| 305 | jif = boottime.tv_sec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | |
KAMEZAWA Hiroyuki | 0a94502 | 2006-03-28 01:56:37 -0800 | [diff] [blame] | 307 | for_each_possible_cpu(i) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | user = cputime64_add(user, kstat_cpu(i).cpustat.user); |
| 309 | nice = cputime64_add(nice, kstat_cpu(i).cpustat.nice); |
| 310 | system = cputime64_add(system, kstat_cpu(i).cpustat.system); |
| 311 | idle = cputime64_add(idle, kstat_cpu(i).cpustat.idle); |
| 312 | iowait = cputime64_add(iowait, kstat_cpu(i).cpustat.iowait); |
| 313 | irq = cputime64_add(irq, kstat_cpu(i).cpustat.irq); |
| 314 | softirq = cputime64_add(softirq, kstat_cpu(i).cpustat.softirq); |
| 315 | steal = cputime64_add(steal, kstat_cpu(i).cpustat.steal); |
Laurent Vivier | 5e84cfd | 2007-10-15 17:00:19 +0200 | [diff] [blame] | 316 | guest = cputime64_add(guest, kstat_cpu(i).cpustat.guest); |
Yinghai Lu | c7fb03a | 2008-08-19 20:50:12 -0700 | [diff] [blame] | 317 | |
Thomas Gleixner | 2be3b52 | 2008-10-16 14:50:27 +0200 | [diff] [blame] | 318 | for_each_irq_nr(j) |
Thomas Gleixner | 2cc21ef | 2008-10-15 14:16:55 +0200 | [diff] [blame] | 319 | sum += kstat_irqs_cpu(j, i); |
| 320 | |
Jan Beulich | a2eddfa | 2008-05-12 15:44:41 +0200 | [diff] [blame] | 321 | sum += arch_irq_stat_cpu(i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | } |
Jan Beulich | a2eddfa | 2008-05-12 15:44:41 +0200 | [diff] [blame] | 323 | sum += arch_irq_stat(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | |
Laurent Vivier | 5e84cfd | 2007-10-15 17:00:19 +0200 | [diff] [blame] | 325 | 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] | 326 | (unsigned long long)cputime64_to_clock_t(user), |
| 327 | (unsigned long long)cputime64_to_clock_t(nice), |
| 328 | (unsigned long long)cputime64_to_clock_t(system), |
| 329 | (unsigned long long)cputime64_to_clock_t(idle), |
| 330 | (unsigned long long)cputime64_to_clock_t(iowait), |
| 331 | (unsigned long long)cputime64_to_clock_t(irq), |
| 332 | (unsigned long long)cputime64_to_clock_t(softirq), |
Laurent Vivier | 5e84cfd | 2007-10-15 17:00:19 +0200 | [diff] [blame] | 333 | (unsigned long long)cputime64_to_clock_t(steal), |
| 334 | (unsigned long long)cputime64_to_clock_t(guest)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | for_each_online_cpu(i) { |
| 336 | |
| 337 | /* Copy values here to work around gcc-2.95.3, gcc-2.96 */ |
| 338 | user = kstat_cpu(i).cpustat.user; |
| 339 | nice = kstat_cpu(i).cpustat.nice; |
| 340 | system = kstat_cpu(i).cpustat.system; |
| 341 | idle = kstat_cpu(i).cpustat.idle; |
| 342 | iowait = kstat_cpu(i).cpustat.iowait; |
| 343 | irq = kstat_cpu(i).cpustat.irq; |
| 344 | softirq = kstat_cpu(i).cpustat.softirq; |
| 345 | steal = kstat_cpu(i).cpustat.steal; |
Laurent Vivier | 5e84cfd | 2007-10-15 17:00:19 +0200 | [diff] [blame] | 346 | guest = kstat_cpu(i).cpustat.guest; |
| 347 | seq_printf(p, |
| 348 | "cpu%d %llu %llu %llu %llu %llu %llu %llu %llu %llu\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | i, |
| 350 | (unsigned long long)cputime64_to_clock_t(user), |
| 351 | (unsigned long long)cputime64_to_clock_t(nice), |
| 352 | (unsigned long long)cputime64_to_clock_t(system), |
| 353 | (unsigned long long)cputime64_to_clock_t(idle), |
| 354 | (unsigned long long)cputime64_to_clock_t(iowait), |
| 355 | (unsigned long long)cputime64_to_clock_t(irq), |
| 356 | (unsigned long long)cputime64_to_clock_t(softirq), |
Laurent Vivier | 5e84cfd | 2007-10-15 17:00:19 +0200 | [diff] [blame] | 357 | (unsigned long long)cputime64_to_clock_t(steal), |
| 358 | (unsigned long long)cputime64_to_clock_t(guest)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | } |
| 360 | seq_printf(p, "intr %llu", (unsigned long long)sum); |
| 361 | |
Yinghai Lu | c7fb03a | 2008-08-19 20:50:12 -0700 | [diff] [blame] | 362 | /* sum again ? it could be updated? */ |
Thomas Gleixner | 2be3b52 | 2008-10-16 14:50:27 +0200 | [diff] [blame] | 363 | for_each_irq_nr(j) { |
Yinghai Lu | c7fb03a | 2008-08-19 20:50:12 -0700 | [diff] [blame] | 364 | per_irq_sum = 0; |
Yinghai Lu | c7fb03a | 2008-08-19 20:50:12 -0700 | [diff] [blame] | 365 | |
Thomas Gleixner | 2cc21ef | 2008-10-15 14:16:55 +0200 | [diff] [blame] | 366 | for_each_possible_cpu(i) |
| 367 | per_irq_sum += kstat_irqs_cpu(j, i); |
Yinghai Lu | c7fb03a | 2008-08-19 20:50:12 -0700 | [diff] [blame] | 368 | |
Yinghai Lu | c7fb03a | 2008-08-19 20:50:12 -0700 | [diff] [blame] | 369 | seq_printf(p, " %u", per_irq_sum); |
Yinghai Lu | c7fb03a | 2008-08-19 20:50:12 -0700 | [diff] [blame] | 370 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | |
| 372 | seq_printf(p, |
| 373 | "\nctxt %llu\n" |
| 374 | "btime %lu\n" |
| 375 | "processes %lu\n" |
| 376 | "procs_running %lu\n" |
| 377 | "procs_blocked %lu\n", |
| 378 | nr_context_switches(), |
| 379 | (unsigned long)jif, |
| 380 | total_forks, |
| 381 | nr_running(), |
| 382 | nr_iowait()); |
| 383 | |
| 384 | return 0; |
| 385 | } |
| 386 | |
| 387 | static int stat_open(struct inode *inode, struct file *file) |
| 388 | { |
| 389 | unsigned size = 4096 * (1 + num_possible_cpus() / 32); |
| 390 | char *buf; |
| 391 | struct seq_file *m; |
| 392 | int res; |
| 393 | |
| 394 | /* don't ask for more than the kmalloc() max size, currently 128 KB */ |
| 395 | if (size > 128 * 1024) |
| 396 | size = 128 * 1024; |
| 397 | buf = kmalloc(size, GFP_KERNEL); |
| 398 | if (!buf) |
| 399 | return -ENOMEM; |
| 400 | |
| 401 | res = single_open(file, show_stat, NULL); |
| 402 | if (!res) { |
| 403 | m = file->private_data; |
| 404 | m->buf = buf; |
| 405 | m->size = size; |
| 406 | } else |
| 407 | kfree(buf); |
| 408 | return res; |
| 409 | } |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 410 | static const struct file_operations proc_stat_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | .open = stat_open, |
| 412 | .read = seq_read, |
| 413 | .llseek = seq_lseek, |
| 414 | .release = single_release, |
| 415 | }; |
| 416 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | /* |
| 418 | * /proc/interrupts |
| 419 | */ |
| 420 | static void *int_seq_start(struct seq_file *f, loff_t *pos) |
| 421 | { |
Yinghai Lu | da27c11 | 2008-08-19 20:49:56 -0700 | [diff] [blame] | 422 | return (*pos <= nr_irqs) ? pos : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | } |
| 424 | |
Yinghai Lu | 52b1732 | 2008-08-19 20:50:20 -0700 | [diff] [blame] | 425 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | static void *int_seq_next(struct seq_file *f, void *v, loff_t *pos) |
| 427 | { |
| 428 | (*pos)++; |
Yinghai Lu | 52b1732 | 2008-08-19 20:50:20 -0700 | [diff] [blame] | 429 | return (*pos <= nr_irqs) ? pos : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | static void int_seq_stop(struct seq_file *f, void *v) |
| 433 | { |
| 434 | /* Nothing to do */ |
| 435 | } |
| 436 | |
Jan Engelhardt | 03a4482 | 2008-02-08 04:21:19 -0800 | [diff] [blame] | 437 | static const struct seq_operations int_seq_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | .start = int_seq_start, |
| 439 | .next = int_seq_next, |
| 440 | .stop = int_seq_stop, |
| 441 | .show = show_interrupts |
| 442 | }; |
| 443 | |
| 444 | static int interrupts_open(struct inode *inode, struct file *filp) |
| 445 | { |
| 446 | return seq_open(filp, &int_seq_ops); |
| 447 | } |
| 448 | |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 449 | static const struct file_operations proc_interrupts_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | .open = interrupts_open, |
| 451 | .read = seq_read, |
| 452 | .llseek = seq_lseek, |
| 453 | .release = seq_release, |
| 454 | }; |
| 455 | |
Thomas Petazzoni | bfcd17a | 2008-08-06 15:12:22 +0200 | [diff] [blame] | 456 | #ifdef CONFIG_FILE_LOCKING |
Pavel Emelyanov | 7f8ada9 | 2007-10-01 14:41:15 -0700 | [diff] [blame] | 457 | static int locks_open(struct inode *inode, struct file *filp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | { |
Pavel Emelyanov | 7f8ada9 | 2007-10-01 14:41:15 -0700 | [diff] [blame] | 459 | return seq_open(filp, &locks_seq_operations); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | } |
| 461 | |
Pavel Emelyanov | 7f8ada9 | 2007-10-01 14:41:15 -0700 | [diff] [blame] | 462 | static const struct file_operations proc_locks_operations = { |
| 463 | .open = locks_open, |
| 464 | .read = seq_read, |
| 465 | .llseek = seq_lseek, |
| 466 | .release = seq_release, |
| 467 | }; |
Thomas Petazzoni | bfcd17a | 2008-08-06 15:12:22 +0200 | [diff] [blame] | 468 | #endif /* CONFIG_FILE_LOCKING */ |
Pavel Emelyanov | 7f8ada9 | 2007-10-01 14:41:15 -0700 | [diff] [blame] | 469 | |
Matt Mackall | 1e88328 | 2008-02-04 22:29:07 -0800 | [diff] [blame] | 470 | #ifdef CONFIG_PROC_PAGE_MONITOR |
Matt Mackall | 161f47b | 2008-02-04 22:29:05 -0800 | [diff] [blame] | 471 | #define KPMSIZE sizeof(u64) |
| 472 | #define KPMMASK (KPMSIZE - 1) |
| 473 | /* /proc/kpagecount - an array exposing page counts |
| 474 | * |
| 475 | * Each entry is a u64 representing the corresponding |
| 476 | * physical page count. |
| 477 | */ |
| 478 | static ssize_t kpagecount_read(struct file *file, char __user *buf, |
| 479 | size_t count, loff_t *ppos) |
| 480 | { |
| 481 | u64 __user *out = (u64 __user *)buf; |
| 482 | struct page *ppage; |
| 483 | unsigned long src = *ppos; |
| 484 | unsigned long pfn; |
| 485 | ssize_t ret = 0; |
| 486 | u64 pcount; |
| 487 | |
| 488 | pfn = src / KPMSIZE; |
| 489 | count = min_t(size_t, count, (max_pfn * KPMSIZE) - src); |
| 490 | if (src & KPMMASK || count & KPMMASK) |
Thomas Tuttle | 4710d1a | 2008-06-05 22:46:58 -0700 | [diff] [blame] | 491 | return -EINVAL; |
Matt Mackall | 161f47b | 2008-02-04 22:29:05 -0800 | [diff] [blame] | 492 | |
| 493 | while (count > 0) { |
Matt Mackall | 304daa8 | 2008-02-04 22:29:06 -0800 | [diff] [blame] | 494 | ppage = NULL; |
| 495 | if (pfn_valid(pfn)) |
| 496 | ppage = pfn_to_page(pfn); |
| 497 | pfn++; |
Matt Mackall | 161f47b | 2008-02-04 22:29:05 -0800 | [diff] [blame] | 498 | if (!ppage) |
| 499 | pcount = 0; |
| 500 | else |
Thomas Tuttle | bbcdac0 | 2008-06-05 22:46:58 -0700 | [diff] [blame] | 501 | pcount = page_mapcount(ppage); |
Matt Mackall | 161f47b | 2008-02-04 22:29:05 -0800 | [diff] [blame] | 502 | |
| 503 | if (put_user(pcount, out++)) { |
| 504 | ret = -EFAULT; |
| 505 | break; |
| 506 | } |
| 507 | |
| 508 | count -= KPMSIZE; |
| 509 | } |
| 510 | |
| 511 | *ppos += (char __user *)out - buf; |
| 512 | if (!ret) |
| 513 | ret = (char __user *)out - buf; |
| 514 | return ret; |
| 515 | } |
| 516 | |
| 517 | static struct file_operations proc_kpagecount_operations = { |
| 518 | .llseek = mem_lseek, |
| 519 | .read = kpagecount_read, |
| 520 | }; |
| 521 | |
Matt Mackall | 304daa8 | 2008-02-04 22:29:06 -0800 | [diff] [blame] | 522 | /* /proc/kpageflags - an array exposing page flags |
| 523 | * |
| 524 | * Each entry is a u64 representing the corresponding |
| 525 | * physical page flags. |
| 526 | */ |
| 527 | |
| 528 | /* These macros are used to decouple internal flags from exported ones */ |
| 529 | |
| 530 | #define KPF_LOCKED 0 |
| 531 | #define KPF_ERROR 1 |
| 532 | #define KPF_REFERENCED 2 |
| 533 | #define KPF_UPTODATE 3 |
| 534 | #define KPF_DIRTY 4 |
| 535 | #define KPF_LRU 5 |
| 536 | #define KPF_ACTIVE 6 |
| 537 | #define KPF_SLAB 7 |
| 538 | #define KPF_WRITEBACK 8 |
| 539 | #define KPF_RECLAIM 9 |
| 540 | #define KPF_BUDDY 10 |
| 541 | |
| 542 | #define kpf_copy_bit(flags, srcpos, dstpos) (((flags >> srcpos) & 1) << dstpos) |
| 543 | |
| 544 | static ssize_t kpageflags_read(struct file *file, char __user *buf, |
| 545 | size_t count, loff_t *ppos) |
| 546 | { |
| 547 | u64 __user *out = (u64 __user *)buf; |
| 548 | struct page *ppage; |
| 549 | unsigned long src = *ppos; |
| 550 | unsigned long pfn; |
| 551 | ssize_t ret = 0; |
| 552 | u64 kflags, uflags; |
| 553 | |
| 554 | pfn = src / KPMSIZE; |
| 555 | count = min_t(unsigned long, count, (max_pfn * KPMSIZE) - src); |
| 556 | if (src & KPMMASK || count & KPMMASK) |
Thomas Tuttle | 4710d1a | 2008-06-05 22:46:58 -0700 | [diff] [blame] | 557 | return -EINVAL; |
Matt Mackall | 304daa8 | 2008-02-04 22:29:06 -0800 | [diff] [blame] | 558 | |
| 559 | while (count > 0) { |
| 560 | ppage = NULL; |
| 561 | if (pfn_valid(pfn)) |
| 562 | ppage = pfn_to_page(pfn); |
| 563 | pfn++; |
| 564 | if (!ppage) |
| 565 | kflags = 0; |
| 566 | else |
| 567 | kflags = ppage->flags; |
| 568 | |
| 569 | uflags = kpf_copy_bit(KPF_LOCKED, PG_locked, kflags) | |
| 570 | kpf_copy_bit(kflags, KPF_ERROR, PG_error) | |
| 571 | kpf_copy_bit(kflags, KPF_REFERENCED, PG_referenced) | |
| 572 | kpf_copy_bit(kflags, KPF_UPTODATE, PG_uptodate) | |
| 573 | kpf_copy_bit(kflags, KPF_DIRTY, PG_dirty) | |
| 574 | kpf_copy_bit(kflags, KPF_LRU, PG_lru) | |
| 575 | kpf_copy_bit(kflags, KPF_ACTIVE, PG_active) | |
| 576 | kpf_copy_bit(kflags, KPF_SLAB, PG_slab) | |
| 577 | kpf_copy_bit(kflags, KPF_WRITEBACK, PG_writeback) | |
| 578 | kpf_copy_bit(kflags, KPF_RECLAIM, PG_reclaim) | |
| 579 | kpf_copy_bit(kflags, KPF_BUDDY, PG_buddy); |
| 580 | |
| 581 | if (put_user(uflags, out++)) { |
| 582 | ret = -EFAULT; |
| 583 | break; |
| 584 | } |
| 585 | |
| 586 | count -= KPMSIZE; |
| 587 | } |
| 588 | |
| 589 | *ppos += (char __user *)out - buf; |
| 590 | if (!ret) |
| 591 | ret = (char __user *)out - buf; |
| 592 | return ret; |
| 593 | } |
| 594 | |
| 595 | static struct file_operations proc_kpageflags_operations = { |
| 596 | .llseek = mem_lseek, |
| 597 | .read = kpageflags_read, |
| 598 | }; |
Matt Mackall | 1e88328 | 2008-02-04 22:29:07 -0800 | [diff] [blame] | 599 | #endif /* CONFIG_PROC_PAGE_MONITOR */ |
Matt Mackall | 304daa8 | 2008-02-04 22:29:06 -0800 | [diff] [blame] | 600 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | struct proc_dir_entry *proc_root_kcore; |
| 602 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | void __init proc_misc_init(void) |
| 604 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | proc_symlink("mounts", NULL, "self/mounts"); |
| 606 | |
| 607 | /* And now for trickier ones */ |
Thomas Petazzoni | bfcd17a | 2008-08-06 15:12:22 +0200 | [diff] [blame] | 608 | #ifdef CONFIG_FILE_LOCKING |
Alexey Dobriyan | 0d5c9f5 | 2008-04-29 01:01:37 -0700 | [diff] [blame] | 609 | proc_create("locks", 0, NULL, &proc_locks_operations); |
Thomas Petazzoni | bfcd17a | 2008-08-06 15:12:22 +0200 | [diff] [blame] | 610 | #endif |
Alexey Dobriyan | 0d5c9f5 | 2008-04-29 01:01:37 -0700 | [diff] [blame] | 611 | proc_create("devices", 0, NULL, &proc_devinfo_operations); |
| 612 | proc_create("cpuinfo", 0, NULL, &proc_cpuinfo_operations); |
David Howells | 9361401 | 2006-09-30 20:45:40 +0200 | [diff] [blame] | 613 | #ifdef CONFIG_BLOCK |
Alexey Dobriyan | 0d5c9f5 | 2008-04-29 01:01:37 -0700 | [diff] [blame] | 614 | proc_create("partitions", 0, NULL, &proc_partitions_operations); |
David Howells | 9361401 | 2006-09-30 20:45:40 +0200 | [diff] [blame] | 615 | #endif |
Alexey Dobriyan | 0d5c9f5 | 2008-04-29 01:01:37 -0700 | [diff] [blame] | 616 | proc_create("stat", 0, NULL, &proc_stat_operations); |
| 617 | proc_create("interrupts", 0, NULL, &proc_interrupts_operations); |
Linus Torvalds | 158a962 | 2008-01-02 13:04:48 -0800 | [diff] [blame] | 618 | #ifdef CONFIG_SLABINFO |
Alexey Dobriyan | 0d5c9f5 | 2008-04-29 01:01:37 -0700 | [diff] [blame] | 619 | proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations); |
Al Viro | 871751e | 2006-03-25 03:06:39 -0800 | [diff] [blame] | 620 | #ifdef CONFIG_DEBUG_SLAB_LEAK |
Alexey Dobriyan | 0d5c9f5 | 2008-04-29 01:01:37 -0700 | [diff] [blame] | 621 | proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations); |
Al Viro | 871751e | 2006-03-25 03:06:39 -0800 | [diff] [blame] | 622 | #endif |
Matt Mackall | 10cef60 | 2006-01-08 01:01:45 -0800 | [diff] [blame] | 623 | #endif |
Christoph Lameter | a10aa57 | 2008-04-28 02:12:40 -0700 | [diff] [blame] | 624 | #ifdef CONFIG_MMU |
| 625 | proc_create("vmallocinfo", S_IRUSR, NULL, &proc_vmalloc_operations); |
| 626 | #endif |
Alexey Dobriyan | 0d5c9f5 | 2008-04-29 01:01:37 -0700 | [diff] [blame] | 627 | proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations); |
| 628 | proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops); |
| 629 | proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations); |
| 630 | proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations); |
David Howells | 9361401 | 2006-09-30 20:45:40 +0200 | [diff] [blame] | 631 | #ifdef CONFIG_BLOCK |
Alexey Dobriyan | 0d5c9f5 | 2008-04-29 01:01:37 -0700 | [diff] [blame] | 632 | proc_create("diskstats", 0, NULL, &proc_diskstats_operations); |
David Howells | 9361401 | 2006-09-30 20:45:40 +0200 | [diff] [blame] | 633 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | #ifdef CONFIG_MODULES |
Alexey Dobriyan | 0d5c9f5 | 2008-04-29 01:01:37 -0700 | [diff] [blame] | 635 | proc_create("modules", 0, NULL, &proc_modules_operations); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | #endif |
| 637 | #ifdef CONFIG_SCHEDSTATS |
Alexey Dobriyan | 0d5c9f5 | 2008-04-29 01:01:37 -0700 | [diff] [blame] | 638 | proc_create("schedstat", 0, NULL, &proc_schedstat_operations); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | #endif |
| 640 | #ifdef CONFIG_PROC_KCORE |
Alexey Dobriyan | 0d5c9f5 | 2008-04-29 01:01:37 -0700 | [diff] [blame] | 641 | proc_root_kcore = proc_create("kcore", S_IRUSR, NULL, &proc_kcore_operations); |
| 642 | if (proc_root_kcore) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | proc_root_kcore->size = |
| 644 | (size_t)high_memory - PAGE_OFFSET + PAGE_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | #endif |
Matt Mackall | 1e88328 | 2008-02-04 22:29:07 -0800 | [diff] [blame] | 646 | #ifdef CONFIG_PROC_PAGE_MONITOR |
Alexey Dobriyan | 0d5c9f5 | 2008-04-29 01:01:37 -0700 | [diff] [blame] | 647 | proc_create("kpagecount", S_IRUSR, NULL, &proc_kpagecount_operations); |
| 648 | proc_create("kpageflags", S_IRUSR, NULL, &proc_kpageflags_operations); |
Matt Mackall | 1e88328 | 2008-02-04 22:29:07 -0800 | [diff] [blame] | 649 | #endif |
Vivek Goyal | 666bfdd | 2005-06-25 14:58:21 -0700 | [diff] [blame] | 650 | #ifdef CONFIG_PROC_VMCORE |
Alexey Dobriyan | 0d5c9f5 | 2008-04-29 01:01:37 -0700 | [diff] [blame] | 651 | proc_vmcore = proc_create("vmcore", S_IRUSR, NULL, &proc_vmcore_operations); |
Vivek Goyal | 666bfdd | 2005-06-25 14:58:21 -0700 | [diff] [blame] | 652 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | } |