proc_misc.c 23 KB

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