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