Commit 8591cf43224980a0bc9216a4e50b0a740f8cba35

Authored by Alexey Dobriyan
1 parent fe2510426a

proc: move /proc/cpuinfo code to fs/proc/cpuinfo.c

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>

Showing 3 changed files with 25 additions and 14 deletions Inline Diff

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