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/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_UNEVICTABLE_LRU
  162. "Unevictable: %8lu kB\n"
  163. #endif
  164. #ifdef CONFIG_HIGHMEM
  165. "HighTotal: %8lu kB\n"
  166. "HighFree: %8lu kB\n"
  167. "LowTotal: %8lu kB\n"
  168. "LowFree: %8lu kB\n"
  169. #endif
  170. "SwapTotal: %8lu kB\n"
  171. "SwapFree: %8lu kB\n"
  172. "Dirty: %8lu kB\n"
  173. "Writeback: %8lu kB\n"
  174. "AnonPages: %8lu kB\n"
  175. "Mapped: %8lu kB\n"
  176. "Slab: %8lu kB\n"
  177. "SReclaimable: %8lu kB\n"
  178. "SUnreclaim: %8lu kB\n"
  179. "PageTables: %8lu kB\n"
  180. #ifdef CONFIG_QUICKLIST
  181. "Quicklists: %8lu kB\n"
  182. #endif
  183. "NFS_Unstable: %8lu kB\n"
  184. "Bounce: %8lu kB\n"
  185. "WritebackTmp: %8lu kB\n"
  186. "CommitLimit: %8lu kB\n"
  187. "Committed_AS: %8lu kB\n"
  188. "VmallocTotal: %8lu kB\n"
  189. "VmallocUsed: %8lu kB\n"
  190. "VmallocChunk: %8lu kB\n",
  191. K(i.totalram),
  192. K(i.freeram),
  193. K(i.bufferram),
  194. K(cached),
  195. K(total_swapcache_pages),
  196. K(pages[LRU_ACTIVE_ANON] + pages[LRU_ACTIVE_FILE]),
  197. K(pages[LRU_INACTIVE_ANON] + pages[LRU_INACTIVE_FILE]),
  198. K(pages[LRU_ACTIVE_ANON]),
  199. K(pages[LRU_INACTIVE_ANON]),
  200. K(pages[LRU_ACTIVE_FILE]),
  201. K(pages[LRU_INACTIVE_FILE]),
  202. #ifdef CONFIG_UNEVICTABLE_LRU
  203. K(pages[LRU_UNEVICTABLE]),
  204. #endif
  205. #ifdef CONFIG_HIGHMEM
  206. K(i.totalhigh),
  207. K(i.freehigh),
  208. K(i.totalram-i.totalhigh),
  209. K(i.freeram-i.freehigh),
  210. #endif
  211. K(i.totalswap),
  212. K(i.freeswap),
  213. K(global_page_state(NR_FILE_DIRTY)),
  214. K(global_page_state(NR_WRITEBACK)),
  215. K(global_page_state(NR_ANON_PAGES)),
  216. K(global_page_state(NR_FILE_MAPPED)),
  217. K(global_page_state(NR_SLAB_RECLAIMABLE) +
  218. global_page_state(NR_SLAB_UNRECLAIMABLE)),
  219. K(global_page_state(NR_SLAB_RECLAIMABLE)),
  220. K(global_page_state(NR_SLAB_UNRECLAIMABLE)),
  221. K(global_page_state(NR_PAGETABLE)),
  222. #ifdef CONFIG_QUICKLIST
  223. K(quicklist_total_size()),
  224. #endif
  225. K(global_page_state(NR_UNSTABLE_NFS)),
  226. K(global_page_state(NR_BOUNCE)),
  227. K(global_page_state(NR_WRITEBACK_TEMP)),
  228. K(allowed),
  229. K(committed),
  230. (unsigned long)VMALLOC_TOTAL >> 10,
  231. vmi.used >> 10,
  232. vmi.largest_chunk >> 10
  233. );
  234. len += hugetlb_report_meminfo(page + len);
  235. len += arch_report_meminfo(page + len);
  236. return proc_calc_metrics(page, start, off, count, eof, len);
  237. #undef K
  238. }
  239. static int fragmentation_open(struct inode *inode, struct file *file)
  240. {
  241. (void)inode;
  242. return seq_open(file, &fragmentation_op);
  243. }
  244. static const struct file_operations fragmentation_file_operations = {
  245. .open = fragmentation_open,
  246. .read = seq_read,
  247. .llseek = seq_lseek,
  248. .release = seq_release,
  249. };
  250. static int pagetypeinfo_open(struct inode *inode, struct file *file)
  251. {
  252. return seq_open(file, &pagetypeinfo_op);
  253. }
  254. static const struct file_operations pagetypeinfo_file_ops = {
  255. .open = pagetypeinfo_open,
  256. .read = seq_read,
  257. .llseek = seq_lseek,
  258. .release = seq_release,
  259. };
  260. static int zoneinfo_open(struct inode *inode, struct file *file)
  261. {
  262. return seq_open(file, &zoneinfo_op);
  263. }
  264. static const struct file_operations proc_zoneinfo_file_operations = {
  265. .open = zoneinfo_open,
  266. .read = seq_read,
  267. .llseek = seq_lseek,
  268. .release = seq_release,
  269. };
  270. static int version_read_proc(char *page, char **start, off_t off,
  271. int count, int *eof, void *data)
  272. {
  273. int len;
  274. len = snprintf(page, PAGE_SIZE, linux_proc_banner,
  275. utsname()->sysname,
  276. utsname()->release,
  277. utsname()->version);
  278. return proc_calc_metrics(page, start, off, count, eof, len);
  279. }
  280. extern const struct seq_operations cpuinfo_op;
  281. static int cpuinfo_open(struct inode *inode, struct file *file)
  282. {
  283. return seq_open(file, &cpuinfo_op);
  284. }
  285. static const struct file_operations proc_cpuinfo_operations = {
  286. .open = cpuinfo_open,
  287. .read = seq_read,
  288. .llseek = seq_lseek,
  289. .release = seq_release,
  290. };
  291. static int devinfo_show(struct seq_file *f, void *v)
  292. {
  293. int i = *(loff_t *) v;
  294. if (i < CHRDEV_MAJOR_HASH_SIZE) {
  295. if (i == 0)
  296. seq_printf(f, "Character devices:\n");
  297. chrdev_show(f, i);
  298. }
  299. #ifdef CONFIG_BLOCK
  300. else {
  301. i -= CHRDEV_MAJOR_HASH_SIZE;
  302. if (i == 0)
  303. seq_printf(f, "\nBlock devices:\n");
  304. blkdev_show(f, i);
  305. }
  306. #endif
  307. return 0;
  308. }
  309. static void *devinfo_start(struct seq_file *f, loff_t *pos)
  310. {
  311. if (*pos < (BLKDEV_MAJOR_HASH_SIZE + CHRDEV_MAJOR_HASH_SIZE))
  312. return pos;
  313. return NULL;
  314. }
  315. static void *devinfo_next(struct seq_file *f, void *v, loff_t *pos)
  316. {
  317. (*pos)++;
  318. if (*pos >= (BLKDEV_MAJOR_HASH_SIZE + CHRDEV_MAJOR_HASH_SIZE))
  319. return NULL;
  320. return pos;
  321. }
  322. static void devinfo_stop(struct seq_file *f, void *v)
  323. {
  324. /* Nothing to do */
  325. }
  326. static const struct seq_operations devinfo_ops = {
  327. .start = devinfo_start,
  328. .next = devinfo_next,
  329. .stop = devinfo_stop,
  330. .show = devinfo_show
  331. };
  332. static int devinfo_open(struct inode *inode, struct file *filp)
  333. {
  334. return seq_open(filp, &devinfo_ops);
  335. }
  336. static const struct file_operations proc_devinfo_operations = {
  337. .open = devinfo_open,
  338. .read = seq_read,
  339. .llseek = seq_lseek,
  340. .release = seq_release,
  341. };
  342. static int vmstat_open(struct inode *inode, struct file *file)
  343. {
  344. return seq_open(file, &vmstat_op);
  345. }
  346. static const struct file_operations proc_vmstat_file_operations = {
  347. .open = vmstat_open,
  348. .read = seq_read,
  349. .llseek = seq_lseek,
  350. .release = seq_release,
  351. };
  352. #ifdef CONFIG_PROC_HARDWARE
  353. static int hardware_read_proc(char *page, char **start, off_t off,
  354. int count, int *eof, void *data)
  355. {
  356. int len = get_hardware_list(page);
  357. return proc_calc_metrics(page, start, off, count, eof, len);
  358. }
  359. #endif
  360. #ifdef CONFIG_STRAM_PROC
  361. static int stram_read_proc(char *page, char **start, off_t off,
  362. int count, int *eof, void *data)
  363. {
  364. int len = get_stram_list(page);
  365. return proc_calc_metrics(page, start, off, count, eof, len);
  366. }
  367. #endif
  368. #ifdef CONFIG_BLOCK
  369. static int partitions_open(struct inode *inode, struct file *file)
  370. {
  371. return seq_open(file, &partitions_op);
  372. }
  373. static const struct file_operations proc_partitions_operations = {
  374. .open = partitions_open,
  375. .read = seq_read,
  376. .llseek = seq_lseek,
  377. .release = seq_release,
  378. };
  379. static int diskstats_open(struct inode *inode, struct file *file)
  380. {
  381. return seq_open(file, &diskstats_op);
  382. }
  383. static const struct file_operations proc_diskstats_operations = {
  384. .open = diskstats_open,
  385. .read = seq_read,
  386. .llseek = seq_lseek,
  387. .release = seq_release,
  388. };
  389. #endif
  390. #ifdef CONFIG_MODULES
  391. extern const struct seq_operations modules_op;
  392. static int modules_open(struct inode *inode, struct file *file)
  393. {
  394. return seq_open(file, &modules_op);
  395. }
  396. static const struct file_operations proc_modules_operations = {
  397. .open = modules_open,
  398. .read = seq_read,
  399. .llseek = seq_lseek,
  400. .release = seq_release,
  401. };
  402. #endif
  403. #ifdef CONFIG_SLABINFO
  404. static int slabinfo_open(struct inode *inode, struct file *file)
  405. {
  406. return seq_open(file, &slabinfo_op);
  407. }
  408. static const struct file_operations proc_slabinfo_operations = {
  409. .open = slabinfo_open,
  410. .read = seq_read,
  411. .write = slabinfo_write,
  412. .llseek = seq_lseek,
  413. .release = seq_release,
  414. };
  415. #ifdef CONFIG_DEBUG_SLAB_LEAK
  416. extern const struct seq_operations slabstats_op;
  417. static int slabstats_open(struct inode *inode, struct file *file)
  418. {
  419. unsigned long *n = kzalloc(PAGE_SIZE, GFP_KERNEL);
  420. int ret = -ENOMEM;
  421. if (n) {
  422. ret = seq_open(file, &slabstats_op);
  423. if (!ret) {
  424. struct seq_file *m = file->private_data;
  425. *n = PAGE_SIZE / (2 * sizeof(unsigned long));
  426. m->private = n;
  427. n = NULL;
  428. }
  429. kfree(n);
  430. }
  431. return ret;
  432. }
  433. static const struct file_operations proc_slabstats_operations = {
  434. .open = slabstats_open,
  435. .read = seq_read,
  436. .llseek = seq_lseek,
  437. .release = seq_release_private,
  438. };
  439. #endif
  440. #endif
  441. #ifdef CONFIG_MMU
  442. static int vmalloc_open(struct inode *inode, struct file *file)
  443. {
  444. unsigned int *ptr = NULL;
  445. int ret;
  446. if (NUMA_BUILD)
  447. ptr = kmalloc(nr_node_ids * sizeof(unsigned int), GFP_KERNEL);
  448. ret = seq_open(file, &vmalloc_op);
  449. if (!ret) {
  450. struct seq_file *m = file->private_data;
  451. m->private = ptr;
  452. } else
  453. kfree(ptr);
  454. return ret;
  455. }
  456. static const struct file_operations proc_vmalloc_operations = {
  457. .open = vmalloc_open,
  458. .read = seq_read,
  459. .llseek = seq_lseek,
  460. .release = seq_release_private,
  461. };
  462. #endif
  463. #ifndef arch_irq_stat_cpu
  464. #define arch_irq_stat_cpu(cpu) 0
  465. #endif
  466. #ifndef arch_irq_stat
  467. #define arch_irq_stat() 0
  468. #endif
  469. static int show_stat(struct seq_file *p, void *v)
  470. {
  471. int i;
  472. unsigned long jif;
  473. cputime64_t user, nice, system, idle, iowait, irq, softirq, steal;
  474. cputime64_t guest;
  475. u64 sum = 0;
  476. struct timespec boottime;
  477. unsigned int *per_irq_sum;
  478. per_irq_sum = kzalloc(sizeof(unsigned int)*NR_IRQS, GFP_KERNEL);
  479. if (!per_irq_sum)
  480. return -ENOMEM;
  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. int j;
  488. user = cputime64_add(user, kstat_cpu(i).cpustat.user);
  489. nice = cputime64_add(nice, kstat_cpu(i).cpustat.nice);
  490. system = cputime64_add(system, kstat_cpu(i).cpustat.system);
  491. idle = cputime64_add(idle, kstat_cpu(i).cpustat.idle);
  492. iowait = cputime64_add(iowait, kstat_cpu(i).cpustat.iowait);
  493. irq = cputime64_add(irq, kstat_cpu(i).cpustat.irq);
  494. softirq = cputime64_add(softirq, kstat_cpu(i).cpustat.softirq);
  495. steal = cputime64_add(steal, kstat_cpu(i).cpustat.steal);
  496. guest = cputime64_add(guest, kstat_cpu(i).cpustat.guest);
  497. for (j = 0; j < NR_IRQS; j++) {
  498. unsigned int temp = kstat_cpu(i).irqs[j];
  499. sum += temp;
  500. per_irq_sum[j] += temp;
  501. }
  502. sum += arch_irq_stat_cpu(i);
  503. }
  504. sum += arch_irq_stat();
  505. seq_printf(p, "cpu %llu %llu %llu %llu %llu %llu %llu %llu %llu\n",
  506. (unsigned long long)cputime64_to_clock_t(user),
  507. (unsigned long long)cputime64_to_clock_t(nice),
  508. (unsigned long long)cputime64_to_clock_t(system),
  509. (unsigned long long)cputime64_to_clock_t(idle),
  510. (unsigned long long)cputime64_to_clock_t(iowait),
  511. (unsigned long long)cputime64_to_clock_t(irq),
  512. (unsigned long long)cputime64_to_clock_t(softirq),
  513. (unsigned long long)cputime64_to_clock_t(steal),
  514. (unsigned long long)cputime64_to_clock_t(guest));
  515. for_each_online_cpu(i) {
  516. /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
  517. user = kstat_cpu(i).cpustat.user;
  518. nice = kstat_cpu(i).cpustat.nice;
  519. system = kstat_cpu(i).cpustat.system;
  520. idle = kstat_cpu(i).cpustat.idle;
  521. iowait = kstat_cpu(i).cpustat.iowait;
  522. irq = kstat_cpu(i).cpustat.irq;
  523. softirq = kstat_cpu(i).cpustat.softirq;
  524. steal = kstat_cpu(i).cpustat.steal;
  525. guest = kstat_cpu(i).cpustat.guest;
  526. seq_printf(p,
  527. "cpu%d %llu %llu %llu %llu %llu %llu %llu %llu %llu\n",
  528. i,
  529. (unsigned long long)cputime64_to_clock_t(user),
  530. (unsigned long long)cputime64_to_clock_t(nice),
  531. (unsigned long long)cputime64_to_clock_t(system),
  532. (unsigned long long)cputime64_to_clock_t(idle),
  533. (unsigned long long)cputime64_to_clock_t(iowait),
  534. (unsigned long long)cputime64_to_clock_t(irq),
  535. (unsigned long long)cputime64_to_clock_t(softirq),
  536. (unsigned long long)cputime64_to_clock_t(steal),
  537. (unsigned long long)cputime64_to_clock_t(guest));
  538. }
  539. seq_printf(p, "intr %llu", (unsigned long long)sum);
  540. for (i = 0; i < NR_IRQS; i++)
  541. seq_printf(p, " %u", per_irq_sum[i]);
  542. seq_printf(p,
  543. "\nctxt %llu\n"
  544. "btime %lu\n"
  545. "processes %lu\n"
  546. "procs_running %lu\n"
  547. "procs_blocked %lu\n",
  548. nr_context_switches(),
  549. (unsigned long)jif,
  550. total_forks,
  551. nr_running(),
  552. nr_iowait());
  553. kfree(per_irq_sum);
  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. if (*pos > NR_IRQS)
  594. return NULL;
  595. return pos;
  596. }
  597. static void int_seq_stop(struct seq_file *f, void *v)
  598. {
  599. /* Nothing to do */
  600. }
  601. static const struct seq_operations int_seq_ops = {
  602. .start = int_seq_start,
  603. .next = int_seq_next,
  604. .stop = int_seq_stop,
  605. .show = show_interrupts
  606. };
  607. static int interrupts_open(struct inode *inode, struct file *filp)
  608. {
  609. return seq_open(filp, &int_seq_ops);
  610. }
  611. static const struct file_operations proc_interrupts_operations = {
  612. .open = interrupts_open,
  613. .read = seq_read,
  614. .llseek = seq_lseek,
  615. .release = seq_release,
  616. };
  617. static int filesystems_read_proc(char *page, char **start, off_t off,
  618. int count, int *eof, void *data)
  619. {
  620. int len = get_filesystem_list(page);
  621. return proc_calc_metrics(page, start, off, count, eof, len);
  622. }
  623. static int cmdline_read_proc(char *page, char **start, off_t off,
  624. int count, int *eof, void *data)
  625. {
  626. int len;
  627. len = sprintf(page, "%s\n", saved_command_line);
  628. return proc_calc_metrics(page, start, off, count, eof, len);
  629. }
  630. #ifdef CONFIG_FILE_LOCKING
  631. static int locks_open(struct inode *inode, struct file *filp)
  632. {
  633. return seq_open(filp, &locks_seq_operations);
  634. }
  635. static const struct file_operations proc_locks_operations = {
  636. .open = locks_open,
  637. .read = seq_read,
  638. .llseek = seq_lseek,
  639. .release = seq_release,
  640. };
  641. #endif /* CONFIG_FILE_LOCKING */
  642. static int execdomains_read_proc(char *page, char **start, off_t off,
  643. int count, int *eof, void *data)
  644. {
  645. int len = get_exec_domain_list(page);
  646. return proc_calc_metrics(page, start, off, count, eof, len);
  647. }
  648. #ifdef CONFIG_PROC_PAGE_MONITOR
  649. #define KPMSIZE sizeof(u64)
  650. #define KPMMASK (KPMSIZE - 1)
  651. /* /proc/kpagecount - an array exposing page counts
  652. *
  653. * Each entry is a u64 representing the corresponding
  654. * physical page count.
  655. */
  656. static ssize_t kpagecount_read(struct file *file, char __user *buf,
  657. size_t count, loff_t *ppos)
  658. {
  659. u64 __user *out = (u64 __user *)buf;
  660. struct page *ppage;
  661. unsigned long src = *ppos;
  662. unsigned long pfn;
  663. ssize_t ret = 0;
  664. u64 pcount;
  665. pfn = src / KPMSIZE;
  666. count = min_t(size_t, count, (max_pfn * KPMSIZE) - src);
  667. if (src & KPMMASK || count & KPMMASK)
  668. return -EINVAL;
  669. while (count > 0) {
  670. ppage = NULL;
  671. if (pfn_valid(pfn))
  672. ppage = pfn_to_page(pfn);
  673. pfn++;
  674. if (!ppage)
  675. pcount = 0;
  676. else
  677. pcount = page_mapcount(ppage);
  678. if (put_user(pcount, out++)) {
  679. ret = -EFAULT;
  680. break;
  681. }
  682. count -= KPMSIZE;
  683. }
  684. *ppos += (char __user *)out - buf;
  685. if (!ret)
  686. ret = (char __user *)out - buf;
  687. return ret;
  688. }
  689. static struct file_operations proc_kpagecount_operations = {
  690. .llseek = mem_lseek,
  691. .read = kpagecount_read,
  692. };
  693. /* /proc/kpageflags - an array exposing page flags
  694. *
  695. * Each entry is a u64 representing the corresponding
  696. * physical page flags.
  697. */
  698. /* These macros are used to decouple internal flags from exported ones */
  699. #define KPF_LOCKED 0
  700. #define KPF_ERROR 1
  701. #define KPF_REFERENCED 2
  702. #define KPF_UPTODATE 3
  703. #define KPF_DIRTY 4
  704. #define KPF_LRU 5
  705. #define KPF_ACTIVE 6
  706. #define KPF_SLAB 7
  707. #define KPF_WRITEBACK 8
  708. #define KPF_RECLAIM 9
  709. #define KPF_BUDDY 10
  710. #define kpf_copy_bit(flags, srcpos, dstpos) (((flags >> srcpos) & 1) << dstpos)
  711. static ssize_t kpageflags_read(struct file *file, char __user *buf,
  712. size_t count, loff_t *ppos)
  713. {
  714. u64 __user *out = (u64 __user *)buf;
  715. struct page *ppage;
  716. unsigned long src = *ppos;
  717. unsigned long pfn;
  718. ssize_t ret = 0;
  719. u64 kflags, uflags;
  720. pfn = src / KPMSIZE;
  721. count = min_t(unsigned long, count, (max_pfn * KPMSIZE) - src);
  722. if (src & KPMMASK || count & KPMMASK)
  723. return -EINVAL;
  724. while (count > 0) {
  725. ppage = NULL;
  726. if (pfn_valid(pfn))
  727. ppage = pfn_to_page(pfn);
  728. pfn++;
  729. if (!ppage)
  730. kflags = 0;
  731. else
  732. kflags = ppage->flags;
  733. uflags = kpf_copy_bit(KPF_LOCKED, PG_locked, kflags) |
  734. kpf_copy_bit(kflags, KPF_ERROR, PG_error) |
  735. kpf_copy_bit(kflags, KPF_REFERENCED, PG_referenced) |
  736. kpf_copy_bit(kflags, KPF_UPTODATE, PG_uptodate) |
  737. kpf_copy_bit(kflags, KPF_DIRTY, PG_dirty) |
  738. kpf_copy_bit(kflags, KPF_LRU, PG_lru) |
  739. kpf_copy_bit(kflags, KPF_ACTIVE, PG_active) |
  740. kpf_copy_bit(kflags, KPF_SLAB, PG_slab) |
  741. kpf_copy_bit(kflags, KPF_WRITEBACK, PG_writeback) |
  742. kpf_copy_bit(kflags, KPF_RECLAIM, PG_reclaim) |
  743. kpf_copy_bit(kflags, KPF_BUDDY, PG_buddy);
  744. if (put_user(uflags, out++)) {
  745. ret = -EFAULT;
  746. break;
  747. }
  748. count -= KPMSIZE;
  749. }
  750. *ppos += (char __user *)out - buf;
  751. if (!ret)
  752. ret = (char __user *)out - buf;
  753. return ret;
  754. }
  755. static struct file_operations proc_kpageflags_operations = {
  756. .llseek = mem_lseek,
  757. .read = kpageflags_read,
  758. };
  759. #endif /* CONFIG_PROC_PAGE_MONITOR */
  760. struct proc_dir_entry *proc_root_kcore;
  761. void __init proc_misc_init(void)
  762. {
  763. static struct {
  764. char *name;
  765. int (*read_proc)(char*,char**,off_t,int,int*,void*);
  766. } *p, simple_ones[] = {
  767. {"loadavg", loadavg_read_proc},
  768. {"uptime", uptime_read_proc},
  769. {"meminfo", meminfo_read_proc},
  770. {"version", version_read_proc},
  771. #ifdef CONFIG_PROC_HARDWARE
  772. {"hardware", hardware_read_proc},
  773. #endif
  774. #ifdef CONFIG_STRAM_PROC
  775. {"stram", stram_read_proc},
  776. #endif
  777. {"filesystems", filesystems_read_proc},
  778. {"cmdline", cmdline_read_proc},
  779. {"execdomains", execdomains_read_proc},
  780. {NULL,}
  781. };
  782. for (p = simple_ones; p->name; p++)
  783. create_proc_read_entry(p->name, 0, NULL, p->read_proc, NULL);
  784. proc_symlink("mounts", NULL, "self/mounts");
  785. /* And now for trickier ones */
  786. #ifdef CONFIG_PRINTK
  787. proc_create("kmsg", S_IRUSR, NULL, &proc_kmsg_operations);
  788. #endif
  789. #ifdef CONFIG_FILE_LOCKING
  790. proc_create("locks", 0, NULL, &proc_locks_operations);
  791. #endif
  792. proc_create("devices", 0, NULL, &proc_devinfo_operations);
  793. proc_create("cpuinfo", 0, NULL, &proc_cpuinfo_operations);
  794. #ifdef CONFIG_BLOCK
  795. proc_create("partitions", 0, NULL, &proc_partitions_operations);
  796. #endif
  797. proc_create("stat", 0, NULL, &proc_stat_operations);
  798. proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
  799. #ifdef CONFIG_SLABINFO
  800. proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations);
  801. #ifdef CONFIG_DEBUG_SLAB_LEAK
  802. proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
  803. #endif
  804. #endif
  805. #ifdef CONFIG_MMU
  806. proc_create("vmallocinfo", S_IRUSR, NULL, &proc_vmalloc_operations);
  807. #endif
  808. proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
  809. proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
  810. proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
  811. proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
  812. #ifdef CONFIG_BLOCK
  813. proc_create("diskstats", 0, NULL, &proc_diskstats_operations);
  814. #endif
  815. #ifdef CONFIG_MODULES
  816. proc_create("modules", 0, NULL, &proc_modules_operations);
  817. #endif
  818. #ifdef CONFIG_SCHEDSTATS
  819. proc_create("schedstat", 0, NULL, &proc_schedstat_operations);
  820. #endif
  821. #ifdef CONFIG_PROC_KCORE
  822. proc_root_kcore = proc_create("kcore", S_IRUSR, NULL, &proc_kcore_operations);
  823. if (proc_root_kcore)
  824. proc_root_kcore->size =
  825. (size_t)high_memory - PAGE_OFFSET + PAGE_SIZE;
  826. #endif
  827. #ifdef CONFIG_PROC_PAGE_MONITOR
  828. proc_create("kpagecount", S_IRUSR, NULL, &proc_kpagecount_operations);
  829. proc_create("kpageflags", S_IRUSR, NULL, &proc_kpageflags_operations);
  830. #endif
  831. #ifdef CONFIG_PROC_VMCORE
  832. proc_vmcore = proc_create("vmcore", S_IRUSR, NULL, &proc_vmcore_operations);
  833. #endif
  834. }