proc_misc.c 23 KB

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