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