proc_misc.c 24 KB

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