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