proc_misc.c 24 KB

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