proc_misc.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886
  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. #include <linux/types.h>
  18. #include <linux/errno.h>
  19. #include <linux/time.h>
  20. #include <linux/kernel.h>
  21. #include <linux/kernel_stat.h>
  22. #include <linux/fs.h>
  23. #include <linux/tty.h>
  24. #include <linux/string.h>
  25. #include <linux/mman.h>
  26. #include <linux/quicklist.h>
  27. #include <linux/proc_fs.h>
  28. #include <linux/ioport.h>
  29. #include <linux/mm.h>
  30. #include <linux/mmzone.h>
  31. #include <linux/pagemap.h>
  32. #include <linux/irq.h>
  33. #include <linux/interrupt.h>
  34. #include <linux/swap.h>
  35. #include <linux/slab.h>
  36. #include <linux/genhd.h>
  37. #include <linux/smp.h>
  38. #include <linux/signal.h>
  39. #include <linux/module.h>
  40. #include <linux/init.h>
  41. #include <linux/seq_file.h>
  42. #include <linux/times.h>
  43. #include <linux/profile.h>
  44. #include <linux/utsname.h>
  45. #include <linux/blkdev.h>
  46. #include <linux/hugetlb.h>
  47. #include <linux/jiffies.h>
  48. #include <linux/vmalloc.h>
  49. #include <linux/crash_dump.h>
  50. #include <linux/pid_namespace.h>
  51. #include <linux/bootmem.h>
  52. #include <asm/uaccess.h>
  53. #include <asm/pgtable.h>
  54. #include <asm/io.h>
  55. #include <asm/tlb.h>
  56. #include <asm/div64.h>
  57. #include "internal.h"
  58. /*
  59. * Warning: stuff below (imported functions) assumes that its output will fit
  60. * into one page. For some of those functions it may be wrong. Moreover, we
  61. * have a way to deal with that gracefully. Right now I used straightforward
  62. * wrappers, but this needs further analysis wrt potential overflows.
  63. */
  64. extern int get_hardware_list(char *);
  65. extern int get_stram_list(char *);
  66. extern int get_exec_domain_list(char *);
  67. static int proc_calc_metrics(char *page, char **start, off_t off,
  68. int count, int *eof, int len)
  69. {
  70. if (len <= off+count) *eof = 1;
  71. *start = page + off;
  72. len -= off;
  73. if (len>count) len = count;
  74. if (len<0) len = 0;
  75. return len;
  76. }
  77. int __attribute__((weak)) arch_report_meminfo(char *page)
  78. {
  79. return 0;
  80. }
  81. static int meminfo_read_proc(char *page, char **start, off_t off,
  82. int count, int *eof, void *data)
  83. {
  84. struct sysinfo i;
  85. int len;
  86. unsigned long committed;
  87. unsigned long allowed;
  88. struct vmalloc_info vmi;
  89. long cached;
  90. unsigned long pages[NR_LRU_LISTS];
  91. int lru;
  92. /*
  93. * display in kilobytes.
  94. */
  95. #define K(x) ((x) << (PAGE_SHIFT - 10))
  96. si_meminfo(&i);
  97. si_swapinfo(&i);
  98. committed = atomic_long_read(&vm_committed_space);
  99. allowed = ((totalram_pages - hugetlb_total_pages())
  100. * sysctl_overcommit_ratio / 100) + total_swap_pages;
  101. cached = global_page_state(NR_FILE_PAGES) -
  102. total_swapcache_pages - i.bufferram;
  103. if (cached < 0)
  104. cached = 0;
  105. get_vmalloc_info(&vmi);
  106. for (lru = LRU_BASE; lru < NR_LRU_LISTS; lru++)
  107. pages[lru] = global_page_state(NR_LRU_BASE + lru);
  108. /*
  109. * Tagged format, for easy grepping and expansion.
  110. */
  111. len = sprintf(page,
  112. "MemTotal: %8lu kB\n"
  113. "MemFree: %8lu kB\n"
  114. "Buffers: %8lu kB\n"
  115. "Cached: %8lu kB\n"
  116. "SwapCached: %8lu kB\n"
  117. "Active: %8lu kB\n"
  118. "Inactive: %8lu kB\n"
  119. "Active(anon): %8lu kB\n"
  120. "Inactive(anon): %8lu kB\n"
  121. "Active(file): %8lu kB\n"
  122. "Inactive(file): %8lu kB\n"
  123. #ifdef CONFIG_UNEVICTABLE_LRU
  124. "Unevictable: %8lu kB\n"
  125. "Mlocked: %8lu kB\n"
  126. #endif
  127. #ifdef CONFIG_HIGHMEM
  128. "HighTotal: %8lu kB\n"
  129. "HighFree: %8lu kB\n"
  130. "LowTotal: %8lu kB\n"
  131. "LowFree: %8lu kB\n"
  132. #endif
  133. "SwapTotal: %8lu kB\n"
  134. "SwapFree: %8lu kB\n"
  135. "Dirty: %8lu kB\n"
  136. "Writeback: %8lu kB\n"
  137. "AnonPages: %8lu kB\n"
  138. "Mapped: %8lu kB\n"
  139. "Slab: %8lu kB\n"
  140. "SReclaimable: %8lu kB\n"
  141. "SUnreclaim: %8lu kB\n"
  142. "PageTables: %8lu kB\n"
  143. #ifdef CONFIG_QUICKLIST
  144. "Quicklists: %8lu kB\n"
  145. #endif
  146. "NFS_Unstable: %8lu kB\n"
  147. "Bounce: %8lu kB\n"
  148. "WritebackTmp: %8lu kB\n"
  149. "CommitLimit: %8lu kB\n"
  150. "Committed_AS: %8lu kB\n"
  151. "VmallocTotal: %8lu kB\n"
  152. "VmallocUsed: %8lu kB\n"
  153. "VmallocChunk: %8lu kB\n",
  154. K(i.totalram),
  155. K(i.freeram),
  156. K(i.bufferram),
  157. K(cached),
  158. K(total_swapcache_pages),
  159. K(pages[LRU_ACTIVE_ANON] + pages[LRU_ACTIVE_FILE]),
  160. K(pages[LRU_INACTIVE_ANON] + pages[LRU_INACTIVE_FILE]),
  161. K(pages[LRU_ACTIVE_ANON]),
  162. K(pages[LRU_INACTIVE_ANON]),
  163. K(pages[LRU_ACTIVE_FILE]),
  164. K(pages[LRU_INACTIVE_FILE]),
  165. #ifdef CONFIG_UNEVICTABLE_LRU
  166. K(pages[LRU_UNEVICTABLE]),
  167. K(global_page_state(NR_MLOCK)),
  168. #endif
  169. #ifdef CONFIG_HIGHMEM
  170. K(i.totalhigh),
  171. K(i.freehigh),
  172. K(i.totalram-i.totalhigh),
  173. K(i.freeram-i.freehigh),
  174. #endif
  175. K(i.totalswap),
  176. K(i.freeswap),
  177. K(global_page_state(NR_FILE_DIRTY)),
  178. K(global_page_state(NR_WRITEBACK)),
  179. K(global_page_state(NR_ANON_PAGES)),
  180. K(global_page_state(NR_FILE_MAPPED)),
  181. K(global_page_state(NR_SLAB_RECLAIMABLE) +
  182. global_page_state(NR_SLAB_UNRECLAIMABLE)),
  183. K(global_page_state(NR_SLAB_RECLAIMABLE)),
  184. K(global_page_state(NR_SLAB_UNRECLAIMABLE)),
  185. K(global_page_state(NR_PAGETABLE)),
  186. #ifdef CONFIG_QUICKLIST
  187. K(quicklist_total_size()),
  188. #endif
  189. K(global_page_state(NR_UNSTABLE_NFS)),
  190. K(global_page_state(NR_BOUNCE)),
  191. K(global_page_state(NR_WRITEBACK_TEMP)),
  192. K(allowed),
  193. K(committed),
  194. (unsigned long)VMALLOC_TOTAL >> 10,
  195. vmi.used >> 10,
  196. vmi.largest_chunk >> 10
  197. );
  198. len += hugetlb_report_meminfo(page + len);
  199. len += arch_report_meminfo(page + len);
  200. return proc_calc_metrics(page, start, off, count, eof, len);
  201. #undef K
  202. }
  203. static int fragmentation_open(struct inode *inode, struct file *file)
  204. {
  205. (void)inode;
  206. return seq_open(file, &fragmentation_op);
  207. }
  208. static const struct file_operations fragmentation_file_operations = {
  209. .open = fragmentation_open,
  210. .read = seq_read,
  211. .llseek = seq_lseek,
  212. .release = seq_release,
  213. };
  214. static int pagetypeinfo_open(struct inode *inode, struct file *file)
  215. {
  216. return seq_open(file, &pagetypeinfo_op);
  217. }
  218. static const struct file_operations pagetypeinfo_file_ops = {
  219. .open = pagetypeinfo_open,
  220. .read = seq_read,
  221. .llseek = seq_lseek,
  222. .release = seq_release,
  223. };
  224. static int zoneinfo_open(struct inode *inode, struct file *file)
  225. {
  226. return seq_open(file, &zoneinfo_op);
  227. }
  228. static const struct file_operations proc_zoneinfo_file_operations = {
  229. .open = zoneinfo_open,
  230. .read = seq_read,
  231. .llseek = seq_lseek,
  232. .release = seq_release,
  233. };
  234. static int version_read_proc(char *page, char **start, off_t off,
  235. int count, int *eof, void *data)
  236. {
  237. int len;
  238. len = snprintf(page, PAGE_SIZE, linux_proc_banner,
  239. utsname()->sysname,
  240. utsname()->release,
  241. utsname()->version);
  242. return proc_calc_metrics(page, start, off, count, eof, len);
  243. }
  244. extern const struct seq_operations cpuinfo_op;
  245. static int cpuinfo_open(struct inode *inode, struct file *file)
  246. {
  247. return seq_open(file, &cpuinfo_op);
  248. }
  249. static const struct file_operations proc_cpuinfo_operations = {
  250. .open = cpuinfo_open,
  251. .read = seq_read,
  252. .llseek = seq_lseek,
  253. .release = seq_release,
  254. };
  255. static int devinfo_show(struct seq_file *f, void *v)
  256. {
  257. int i = *(loff_t *) v;
  258. if (i < CHRDEV_MAJOR_HASH_SIZE) {
  259. if (i == 0)
  260. seq_printf(f, "Character devices:\n");
  261. chrdev_show(f, i);
  262. }
  263. #ifdef CONFIG_BLOCK
  264. else {
  265. i -= CHRDEV_MAJOR_HASH_SIZE;
  266. if (i == 0)
  267. seq_printf(f, "\nBlock devices:\n");
  268. blkdev_show(f, i);
  269. }
  270. #endif
  271. return 0;
  272. }
  273. static void *devinfo_start(struct seq_file *f, loff_t *pos)
  274. {
  275. if (*pos < (BLKDEV_MAJOR_HASH_SIZE + CHRDEV_MAJOR_HASH_SIZE))
  276. return pos;
  277. return NULL;
  278. }
  279. static void *devinfo_next(struct seq_file *f, void *v, loff_t *pos)
  280. {
  281. (*pos)++;
  282. if (*pos >= (BLKDEV_MAJOR_HASH_SIZE + CHRDEV_MAJOR_HASH_SIZE))
  283. return NULL;
  284. return pos;
  285. }
  286. static void devinfo_stop(struct seq_file *f, void *v)
  287. {
  288. /* Nothing to do */
  289. }
  290. static const struct seq_operations devinfo_ops = {
  291. .start = devinfo_start,
  292. .next = devinfo_next,
  293. .stop = devinfo_stop,
  294. .show = devinfo_show
  295. };
  296. static int devinfo_open(struct inode *inode, struct file *filp)
  297. {
  298. return seq_open(filp, &devinfo_ops);
  299. }
  300. static const struct file_operations proc_devinfo_operations = {
  301. .open = devinfo_open,
  302. .read = seq_read,
  303. .llseek = seq_lseek,
  304. .release = seq_release,
  305. };
  306. static int vmstat_open(struct inode *inode, struct file *file)
  307. {
  308. return seq_open(file, &vmstat_op);
  309. }
  310. static const struct file_operations proc_vmstat_file_operations = {
  311. .open = vmstat_open,
  312. .read = seq_read,
  313. .llseek = seq_lseek,
  314. .release = seq_release,
  315. };
  316. #ifdef CONFIG_PROC_HARDWARE
  317. static int hardware_read_proc(char *page, char **start, off_t off,
  318. int count, int *eof, void *data)
  319. {
  320. int len = get_hardware_list(page);
  321. return proc_calc_metrics(page, start, off, count, eof, len);
  322. }
  323. #endif
  324. #ifdef CONFIG_STRAM_PROC
  325. static int stram_read_proc(char *page, char **start, off_t off,
  326. int count, int *eof, void *data)
  327. {
  328. int len = get_stram_list(page);
  329. return proc_calc_metrics(page, start, off, count, eof, len);
  330. }
  331. #endif
  332. #ifdef CONFIG_BLOCK
  333. static int partitions_open(struct inode *inode, struct file *file)
  334. {
  335. return seq_open(file, &partitions_op);
  336. }
  337. static const struct file_operations proc_partitions_operations = {
  338. .open = partitions_open,
  339. .read = seq_read,
  340. .llseek = seq_lseek,
  341. .release = seq_release,
  342. };
  343. static int diskstats_open(struct inode *inode, struct file *file)
  344. {
  345. return seq_open(file, &diskstats_op);
  346. }
  347. static const struct file_operations proc_diskstats_operations = {
  348. .open = diskstats_open,
  349. .read = seq_read,
  350. .llseek = seq_lseek,
  351. .release = seq_release,
  352. };
  353. #endif
  354. #ifdef CONFIG_MODULES
  355. extern const struct seq_operations modules_op;
  356. static int modules_open(struct inode *inode, struct file *file)
  357. {
  358. return seq_open(file, &modules_op);
  359. }
  360. static const struct file_operations proc_modules_operations = {
  361. .open = modules_open,
  362. .read = seq_read,
  363. .llseek = seq_lseek,
  364. .release = seq_release,
  365. };
  366. #endif
  367. #ifdef CONFIG_SLABINFO
  368. static int slabinfo_open(struct inode *inode, struct file *file)
  369. {
  370. return seq_open(file, &slabinfo_op);
  371. }
  372. static const struct file_operations proc_slabinfo_operations = {
  373. .open = slabinfo_open,
  374. .read = seq_read,
  375. .write = slabinfo_write,
  376. .llseek = seq_lseek,
  377. .release = seq_release,
  378. };
  379. #ifdef CONFIG_DEBUG_SLAB_LEAK
  380. extern const struct seq_operations slabstats_op;
  381. static int slabstats_open(struct inode *inode, struct file *file)
  382. {
  383. unsigned long *n = kzalloc(PAGE_SIZE, GFP_KERNEL);
  384. int ret = -ENOMEM;
  385. if (n) {
  386. ret = seq_open(file, &slabstats_op);
  387. if (!ret) {
  388. struct seq_file *m = file->private_data;
  389. *n = PAGE_SIZE / (2 * sizeof(unsigned long));
  390. m->private = n;
  391. n = NULL;
  392. }
  393. kfree(n);
  394. }
  395. return ret;
  396. }
  397. static const struct file_operations proc_slabstats_operations = {
  398. .open = slabstats_open,
  399. .read = seq_read,
  400. .llseek = seq_lseek,
  401. .release = seq_release_private,
  402. };
  403. #endif
  404. #endif
  405. #ifdef CONFIG_MMU
  406. static int vmalloc_open(struct inode *inode, struct file *file)
  407. {
  408. unsigned int *ptr = NULL;
  409. int ret;
  410. if (NUMA_BUILD)
  411. ptr = kmalloc(nr_node_ids * sizeof(unsigned int), GFP_KERNEL);
  412. ret = seq_open(file, &vmalloc_op);
  413. if (!ret) {
  414. struct seq_file *m = file->private_data;
  415. m->private = ptr;
  416. } else
  417. kfree(ptr);
  418. return ret;
  419. }
  420. static const struct file_operations proc_vmalloc_operations = {
  421. .open = vmalloc_open,
  422. .read = seq_read,
  423. .llseek = seq_lseek,
  424. .release = seq_release_private,
  425. };
  426. #endif
  427. #ifndef arch_irq_stat_cpu
  428. #define arch_irq_stat_cpu(cpu) 0
  429. #endif
  430. #ifndef arch_irq_stat
  431. #define arch_irq_stat() 0
  432. #endif
  433. static int show_stat(struct seq_file *p, void *v)
  434. {
  435. int i, j;
  436. unsigned long jif;
  437. cputime64_t user, nice, system, idle, iowait, irq, softirq, steal;
  438. cputime64_t guest;
  439. u64 sum = 0;
  440. struct timespec boottime;
  441. unsigned int per_irq_sum;
  442. user = nice = system = idle = iowait =
  443. irq = softirq = steal = cputime64_zero;
  444. guest = cputime64_zero;
  445. getboottime(&boottime);
  446. jif = boottime.tv_sec;
  447. for_each_possible_cpu(i) {
  448. user = cputime64_add(user, kstat_cpu(i).cpustat.user);
  449. nice = cputime64_add(nice, kstat_cpu(i).cpustat.nice);
  450. system = cputime64_add(system, kstat_cpu(i).cpustat.system);
  451. idle = cputime64_add(idle, kstat_cpu(i).cpustat.idle);
  452. iowait = cputime64_add(iowait, kstat_cpu(i).cpustat.iowait);
  453. irq = cputime64_add(irq, kstat_cpu(i).cpustat.irq);
  454. softirq = cputime64_add(softirq, kstat_cpu(i).cpustat.softirq);
  455. steal = cputime64_add(steal, kstat_cpu(i).cpustat.steal);
  456. guest = cputime64_add(guest, kstat_cpu(i).cpustat.guest);
  457. for_each_irq_nr(j)
  458. sum += kstat_irqs_cpu(j, i);
  459. sum += arch_irq_stat_cpu(i);
  460. }
  461. sum += arch_irq_stat();
  462. seq_printf(p, "cpu %llu %llu %llu %llu %llu %llu %llu %llu %llu\n",
  463. (unsigned long long)cputime64_to_clock_t(user),
  464. (unsigned long long)cputime64_to_clock_t(nice),
  465. (unsigned long long)cputime64_to_clock_t(system),
  466. (unsigned long long)cputime64_to_clock_t(idle),
  467. (unsigned long long)cputime64_to_clock_t(iowait),
  468. (unsigned long long)cputime64_to_clock_t(irq),
  469. (unsigned long long)cputime64_to_clock_t(softirq),
  470. (unsigned long long)cputime64_to_clock_t(steal),
  471. (unsigned long long)cputime64_to_clock_t(guest));
  472. for_each_online_cpu(i) {
  473. /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
  474. user = kstat_cpu(i).cpustat.user;
  475. nice = kstat_cpu(i).cpustat.nice;
  476. system = kstat_cpu(i).cpustat.system;
  477. idle = kstat_cpu(i).cpustat.idle;
  478. iowait = kstat_cpu(i).cpustat.iowait;
  479. irq = kstat_cpu(i).cpustat.irq;
  480. softirq = kstat_cpu(i).cpustat.softirq;
  481. steal = kstat_cpu(i).cpustat.steal;
  482. guest = kstat_cpu(i).cpustat.guest;
  483. seq_printf(p,
  484. "cpu%d %llu %llu %llu %llu %llu %llu %llu %llu %llu\n",
  485. i,
  486. (unsigned long long)cputime64_to_clock_t(user),
  487. (unsigned long long)cputime64_to_clock_t(nice),
  488. (unsigned long long)cputime64_to_clock_t(system),
  489. (unsigned long long)cputime64_to_clock_t(idle),
  490. (unsigned long long)cputime64_to_clock_t(iowait),
  491. (unsigned long long)cputime64_to_clock_t(irq),
  492. (unsigned long long)cputime64_to_clock_t(softirq),
  493. (unsigned long long)cputime64_to_clock_t(steal),
  494. (unsigned long long)cputime64_to_clock_t(guest));
  495. }
  496. seq_printf(p, "intr %llu", (unsigned long long)sum);
  497. /* sum again ? it could be updated? */
  498. for_each_irq_nr(j) {
  499. per_irq_sum = 0;
  500. for_each_possible_cpu(i)
  501. per_irq_sum += kstat_irqs_cpu(j, i);
  502. seq_printf(p, " %u", per_irq_sum);
  503. }
  504. seq_printf(p,
  505. "\nctxt %llu\n"
  506. "btime %lu\n"
  507. "processes %lu\n"
  508. "procs_running %lu\n"
  509. "procs_blocked %lu\n",
  510. nr_context_switches(),
  511. (unsigned long)jif,
  512. total_forks,
  513. nr_running(),
  514. nr_iowait());
  515. return 0;
  516. }
  517. static int stat_open(struct inode *inode, struct file *file)
  518. {
  519. unsigned size = 4096 * (1 + num_possible_cpus() / 32);
  520. char *buf;
  521. struct seq_file *m;
  522. int res;
  523. /* don't ask for more than the kmalloc() max size, currently 128 KB */
  524. if (size > 128 * 1024)
  525. size = 128 * 1024;
  526. buf = kmalloc(size, GFP_KERNEL);
  527. if (!buf)
  528. return -ENOMEM;
  529. res = single_open(file, show_stat, NULL);
  530. if (!res) {
  531. m = file->private_data;
  532. m->buf = buf;
  533. m->size = size;
  534. } else
  535. kfree(buf);
  536. return res;
  537. }
  538. static const struct file_operations proc_stat_operations = {
  539. .open = stat_open,
  540. .read = seq_read,
  541. .llseek = seq_lseek,
  542. .release = single_release,
  543. };
  544. /*
  545. * /proc/interrupts
  546. */
  547. static void *int_seq_start(struct seq_file *f, loff_t *pos)
  548. {
  549. return (*pos <= nr_irqs) ? pos : NULL;
  550. }
  551. static void *int_seq_next(struct seq_file *f, void *v, loff_t *pos)
  552. {
  553. (*pos)++;
  554. return (*pos <= nr_irqs) ? pos : NULL;
  555. }
  556. static void int_seq_stop(struct seq_file *f, void *v)
  557. {
  558. /* Nothing to do */
  559. }
  560. static const struct seq_operations int_seq_ops = {
  561. .start = int_seq_start,
  562. .next = int_seq_next,
  563. .stop = int_seq_stop,
  564. .show = show_interrupts
  565. };
  566. static int interrupts_open(struct inode *inode, struct file *filp)
  567. {
  568. return seq_open(filp, &int_seq_ops);
  569. }
  570. static const struct file_operations proc_interrupts_operations = {
  571. .open = interrupts_open,
  572. .read = seq_read,
  573. .llseek = seq_lseek,
  574. .release = seq_release,
  575. };
  576. static int filesystems_read_proc(char *page, char **start, off_t off,
  577. int count, int *eof, void *data)
  578. {
  579. int len = get_filesystem_list(page);
  580. return proc_calc_metrics(page, start, off, count, eof, len);
  581. }
  582. static int cmdline_read_proc(char *page, char **start, off_t off,
  583. int count, int *eof, void *data)
  584. {
  585. int len;
  586. len = sprintf(page, "%s\n", saved_command_line);
  587. return proc_calc_metrics(page, start, off, count, eof, len);
  588. }
  589. #ifdef CONFIG_FILE_LOCKING
  590. static int locks_open(struct inode *inode, struct file *filp)
  591. {
  592. return seq_open(filp, &locks_seq_operations);
  593. }
  594. static const struct file_operations proc_locks_operations = {
  595. .open = locks_open,
  596. .read = seq_read,
  597. .llseek = seq_lseek,
  598. .release = seq_release,
  599. };
  600. #endif /* CONFIG_FILE_LOCKING */
  601. static int execdomains_read_proc(char *page, char **start, off_t off,
  602. int count, int *eof, void *data)
  603. {
  604. int len = get_exec_domain_list(page);
  605. return proc_calc_metrics(page, start, off, count, eof, len);
  606. }
  607. #ifdef CONFIG_PROC_PAGE_MONITOR
  608. #define KPMSIZE sizeof(u64)
  609. #define KPMMASK (KPMSIZE - 1)
  610. /* /proc/kpagecount - an array exposing page counts
  611. *
  612. * Each entry is a u64 representing the corresponding
  613. * physical page count.
  614. */
  615. static ssize_t kpagecount_read(struct file *file, char __user *buf,
  616. size_t count, loff_t *ppos)
  617. {
  618. u64 __user *out = (u64 __user *)buf;
  619. struct page *ppage;
  620. unsigned long src = *ppos;
  621. unsigned long pfn;
  622. ssize_t ret = 0;
  623. u64 pcount;
  624. pfn = src / KPMSIZE;
  625. count = min_t(size_t, count, (max_pfn * KPMSIZE) - src);
  626. if (src & KPMMASK || count & KPMMASK)
  627. return -EINVAL;
  628. while (count > 0) {
  629. ppage = NULL;
  630. if (pfn_valid(pfn))
  631. ppage = pfn_to_page(pfn);
  632. pfn++;
  633. if (!ppage)
  634. pcount = 0;
  635. else
  636. pcount = page_mapcount(ppage);
  637. if (put_user(pcount, out++)) {
  638. ret = -EFAULT;
  639. break;
  640. }
  641. count -= KPMSIZE;
  642. }
  643. *ppos += (char __user *)out - buf;
  644. if (!ret)
  645. ret = (char __user *)out - buf;
  646. return ret;
  647. }
  648. static struct file_operations proc_kpagecount_operations = {
  649. .llseek = mem_lseek,
  650. .read = kpagecount_read,
  651. };
  652. /* /proc/kpageflags - an array exposing page flags
  653. *
  654. * Each entry is a u64 representing the corresponding
  655. * physical page flags.
  656. */
  657. /* These macros are used to decouple internal flags from exported ones */
  658. #define KPF_LOCKED 0
  659. #define KPF_ERROR 1
  660. #define KPF_REFERENCED 2
  661. #define KPF_UPTODATE 3
  662. #define KPF_DIRTY 4
  663. #define KPF_LRU 5
  664. #define KPF_ACTIVE 6
  665. #define KPF_SLAB 7
  666. #define KPF_WRITEBACK 8
  667. #define KPF_RECLAIM 9
  668. #define KPF_BUDDY 10
  669. #define kpf_copy_bit(flags, srcpos, dstpos) (((flags >> srcpos) & 1) << dstpos)
  670. static ssize_t kpageflags_read(struct file *file, char __user *buf,
  671. size_t count, loff_t *ppos)
  672. {
  673. u64 __user *out = (u64 __user *)buf;
  674. struct page *ppage;
  675. unsigned long src = *ppos;
  676. unsigned long pfn;
  677. ssize_t ret = 0;
  678. u64 kflags, uflags;
  679. pfn = src / KPMSIZE;
  680. count = min_t(unsigned long, count, (max_pfn * KPMSIZE) - src);
  681. if (src & KPMMASK || count & KPMMASK)
  682. return -EINVAL;
  683. while (count > 0) {
  684. ppage = NULL;
  685. if (pfn_valid(pfn))
  686. ppage = pfn_to_page(pfn);
  687. pfn++;
  688. if (!ppage)
  689. kflags = 0;
  690. else
  691. kflags = ppage->flags;
  692. uflags = kpf_copy_bit(KPF_LOCKED, PG_locked, kflags) |
  693. kpf_copy_bit(kflags, KPF_ERROR, PG_error) |
  694. kpf_copy_bit(kflags, KPF_REFERENCED, PG_referenced) |
  695. kpf_copy_bit(kflags, KPF_UPTODATE, PG_uptodate) |
  696. kpf_copy_bit(kflags, KPF_DIRTY, PG_dirty) |
  697. kpf_copy_bit(kflags, KPF_LRU, PG_lru) |
  698. kpf_copy_bit(kflags, KPF_ACTIVE, PG_active) |
  699. kpf_copy_bit(kflags, KPF_SLAB, PG_slab) |
  700. kpf_copy_bit(kflags, KPF_WRITEBACK, PG_writeback) |
  701. kpf_copy_bit(kflags, KPF_RECLAIM, PG_reclaim) |
  702. kpf_copy_bit(kflags, KPF_BUDDY, PG_buddy);
  703. if (put_user(uflags, out++)) {
  704. ret = -EFAULT;
  705. break;
  706. }
  707. count -= KPMSIZE;
  708. }
  709. *ppos += (char __user *)out - buf;
  710. if (!ret)
  711. ret = (char __user *)out - buf;
  712. return ret;
  713. }
  714. static struct file_operations proc_kpageflags_operations = {
  715. .llseek = mem_lseek,
  716. .read = kpageflags_read,
  717. };
  718. #endif /* CONFIG_PROC_PAGE_MONITOR */
  719. struct proc_dir_entry *proc_root_kcore;
  720. void __init proc_misc_init(void)
  721. {
  722. static struct {
  723. char *name;
  724. int (*read_proc)(char*,char**,off_t,int,int*,void*);
  725. } *p, simple_ones[] = {
  726. {"meminfo", meminfo_read_proc},
  727. {"version", version_read_proc},
  728. #ifdef CONFIG_PROC_HARDWARE
  729. {"hardware", hardware_read_proc},
  730. #endif
  731. #ifdef CONFIG_STRAM_PROC
  732. {"stram", stram_read_proc},
  733. #endif
  734. {"filesystems", filesystems_read_proc},
  735. {"cmdline", cmdline_read_proc},
  736. {"execdomains", execdomains_read_proc},
  737. {NULL,}
  738. };
  739. for (p = simple_ones; p->name; p++)
  740. create_proc_read_entry(p->name, 0, NULL, p->read_proc, NULL);
  741. proc_symlink("mounts", NULL, "self/mounts");
  742. /* And now for trickier ones */
  743. #ifdef CONFIG_PRINTK
  744. proc_create("kmsg", S_IRUSR, NULL, &proc_kmsg_operations);
  745. #endif
  746. #ifdef CONFIG_FILE_LOCKING
  747. proc_create("locks", 0, NULL, &proc_locks_operations);
  748. #endif
  749. proc_create("devices", 0, NULL, &proc_devinfo_operations);
  750. proc_create("cpuinfo", 0, NULL, &proc_cpuinfo_operations);
  751. #ifdef CONFIG_BLOCK
  752. proc_create("partitions", 0, NULL, &proc_partitions_operations);
  753. #endif
  754. proc_create("stat", 0, NULL, &proc_stat_operations);
  755. proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
  756. #ifdef CONFIG_SLABINFO
  757. proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations);
  758. #ifdef CONFIG_DEBUG_SLAB_LEAK
  759. proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
  760. #endif
  761. #endif
  762. #ifdef CONFIG_MMU
  763. proc_create("vmallocinfo", S_IRUSR, NULL, &proc_vmalloc_operations);
  764. #endif
  765. proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
  766. proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
  767. proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
  768. proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
  769. #ifdef CONFIG_BLOCK
  770. proc_create("diskstats", 0, NULL, &proc_diskstats_operations);
  771. #endif
  772. #ifdef CONFIG_MODULES
  773. proc_create("modules", 0, NULL, &proc_modules_operations);
  774. #endif
  775. #ifdef CONFIG_SCHEDSTATS
  776. proc_create("schedstat", 0, NULL, &proc_schedstat_operations);
  777. #endif
  778. #ifdef CONFIG_PROC_KCORE
  779. proc_root_kcore = proc_create("kcore", S_IRUSR, NULL, &proc_kcore_operations);
  780. if (proc_root_kcore)
  781. proc_root_kcore->size =
  782. (size_t)high_memory - PAGE_OFFSET + PAGE_SIZE;
  783. #endif
  784. #ifdef CONFIG_PROC_PAGE_MONITOR
  785. proc_create("kpagecount", S_IRUSR, NULL, &proc_kpagecount_operations);
  786. proc_create("kpageflags", S_IRUSR, NULL, &proc_kpageflags_operations);
  787. #endif
  788. #ifdef CONFIG_PROC_VMCORE
  789. proc_vmcore = proc_create("vmcore", S_IRUSR, NULL, &proc_vmcore_operations);
  790. #endif
  791. }