vm, kernel, top: report memory usage of vm, kernel
[minix.git] / servers / procfs / root.c
blob6b4f2279314bc1d548f8d60b58582ac50a5d2d85
1 /* ProcFS - root.c - by Alen Stojanov and David van Moolenbroek */
3 #include "inc.h"
4 #include <machine/pci.h>
5 #include <minix/dmap.h>
6 #include "cpuinfo.h"
8 static void root_hz(void);
9 static void root_uptime(void);
10 static void root_loadavg(void);
11 static void root_kinfo(void);
12 static void root_meminfo(void);
13 static void root_pci(void);
14 static void root_dmap(void);
16 struct file root_files[] = {
17 { "hz", REG_ALL_MODE, (data_t) root_hz },
18 { "uptime", REG_ALL_MODE, (data_t) root_uptime },
19 { "loadavg", REG_ALL_MODE, (data_t) root_loadavg },
20 { "kinfo", REG_ALL_MODE, (data_t) root_kinfo },
21 { "meminfo", REG_ALL_MODE, (data_t) root_meminfo },
22 { "pci", REG_ALL_MODE, (data_t) root_pci },
23 { "dmap", REG_ALL_MODE, (data_t) root_dmap },
24 { "cpuinfo", REG_ALL_MODE, (data_t) root_cpuinfo },
25 { NULL, 0, NULL }
28 /*===========================================================================*
29 * root_hz *
30 *===========================================================================*/
31 static void root_hz(void)
33 /* Print the system clock frequency.
36 buf_printf("%lu\n", (long) sys_hz());
39 /*===========================================================================*
40 * root_loadavg *
41 *===========================================================================*/
42 static void root_loadavg(void)
44 /* Print load averages.
46 struct load loads[3];
47 ldiv_t avg[3];
49 if (procfs_getloadavg(loads, 3) != 3)
50 return;
52 avg[0] = ldiv(100L * loads[0].proc_load / loads[0].ticks, 100);
53 avg[1] = ldiv(100L * loads[1].proc_load / loads[1].ticks, 100);
54 avg[2] = ldiv(100L * loads[2].proc_load / loads[2].ticks, 100);
56 buf_printf("%ld.%0.2ld %ld.%02ld %ld.%02ld\n",
57 avg[0].quot, avg[0].rem, avg[1].quot, avg[1].rem,
58 avg[2].quot, avg[2].rem);
61 /*===========================================================================*
62 * root_uptime *
63 *===========================================================================*/
64 static void root_uptime(void)
66 /* Print the current uptime.
68 clock_t ticks;
69 ldiv_t division;
71 if (getuptime(&ticks) != OK)
72 return;
73 division = ldiv(100L * ticks / sys_hz(), 100L);
75 buf_printf("%ld.%0.2ld\n", division.quot, division.rem);
78 /*===========================================================================*
79 * root_kinfo *
80 *===========================================================================*/
81 static void root_kinfo(void)
83 /* Print general kernel information.
85 struct kinfo kinfo;
87 if (sys_getkinfo(&kinfo) != OK)
88 return;
90 buf_printf("%u %u\n", kinfo.nr_procs, kinfo.nr_tasks);
93 /*===========================================================================*
94 * root_meminfo *
95 *===========================================================================*/
96 static void root_meminfo(void)
98 /* Print general memory information.
100 struct vm_stats_info vsi;
102 if (vm_info_stats(&vsi) != OK)
103 return;
105 buf_printf("%u %lu %lu %lu %lu\n", vsi.vsi_pagesize,
106 vsi.vsi_total, vsi.vsi_free, vsi.vsi_largest, vsi.vsi_cached);
109 /*===========================================================================*
110 * root_pci *
111 *===========================================================================*/
112 static void root_pci(void)
114 /* Print information about PCI devices present in the system.
116 u16_t vid, did;
117 u8_t bcr, scr, pifr;
118 char *slot_name, *dev_name;
119 int r, devind;
120 static int first = TRUE;
122 /* This should be taken care of behind the scenes by the PCI lib. */
123 if (first) {
124 pci_init();
125 first = FALSE;
128 /* Iterate over all devices, printing info for each of them. */
129 r = pci_first_dev(&devind, &vid, &did);
130 while (r == 1) {
131 slot_name = pci_slot_name(devind);
132 dev_name = pci_dev_name(vid, did);
134 bcr = pci_attr_r8(devind, PCI_BCR);
135 scr = pci_attr_r8(devind, PCI_SCR);
136 pifr = pci_attr_r8(devind, PCI_PIFR);
138 buf_printf("%s %x/%x/%x %04X:%04X %s\n",
139 slot_name ? slot_name : "-",
140 bcr, scr, pifr, vid, did,
141 dev_name ? dev_name : "");
143 r = pci_next_dev(&devind, &vid, &did);
147 /*===========================================================================*
148 * root_dmap *
149 *===========================================================================*/
150 static void root_dmap(void)
152 struct dmap dmap[NR_DEVICES];
153 int i;
155 if (getsysinfo(VFS_PROC_NR, SI_DMAP_TAB, dmap, sizeof(dmap)) != OK)
156 return;
158 for (i = 0; i < NR_DEVICES; i++) {
159 if (dmap[i].dmap_driver == NONE)
160 continue;
162 buf_printf("%u %s %u\n", i, dmap[i].dmap_label,
163 dmap[i].dmap_driver);