This source file includes following definitions.
- procfs_domeminfo
- procfs_docpuinfo
- procfs_getcpuinfstr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/time.h>
42 #include <sys/kernel.h>
43 #include <sys/proc.h>
44 #include <sys/vnode.h>
45
46 #include <miscfs/procfs/procfs.h>
47
48 #include <uvm/uvm_extern.h>
49
50 #define PGTOB(p) ((unsigned long)(p) << PAGE_SHIFT)
51 #define PGTOKB(p) ((unsigned long)(p) << (PAGE_SHIFT - 10))
52
53
54
55
56
57 int
58 procfs_domeminfo(struct proc *curp, struct proc *p, struct pfsnode *pfs,
59 struct uio *uio)
60 {
61 char buf[512], *cp;
62 int len, error;
63
64 len = snprintf(buf, sizeof buf,
65 " total: used: free: shared: buffers: cached:\n"
66 "Mem: %8lu %8lu %8lu %8lu %8lu %8lu\n"
67 "Swap: %8lu %8lu %8lu\n"
68 "MemTotal: %8lu kB\n"
69 "MemFree: %8lu kB\n"
70 "MemShared: %8lu kB\n"
71 "Buffers: %8lu kB\n"
72 "Cached: %8lu kB\n"
73 "SwapTotal: %8lu kB\n"
74 "SwapFree: %8lu kB\n",
75 PGTOB(uvmexp.npages),
76 PGTOB(uvmexp.npages - uvmexp.free),
77 PGTOB(uvmexp.free),
78 0L,
79 0L,
80 0L,
81 PGTOB(uvmexp.swpages),
82 PGTOB(uvmexp.swpginuse),
83 PGTOB(uvmexp.swpages - uvmexp.swpginuse),
84 PGTOKB(uvmexp.npages),
85 PGTOKB(uvmexp.free),
86 0L,
87 0L,
88 0L,
89 PGTOKB(uvmexp.swpages),
90 PGTOKB(uvmexp.swpages - uvmexp.swpginuse));
91
92 if (len <= 0 || len >= sizeof buf ||
93 len < uio->uio_offset || uio->uio_resid == 0)
94 return EINVAL;
95
96 len -= uio->uio_offset;
97 cp = buf + uio->uio_offset;
98 len = imin(len, uio->uio_resid);
99 error = uiomove(cp, len, uio);
100 return error;
101 }
102
103 int
104 procfs_docpuinfo(struct proc *curp, struct proc *p, struct pfsnode *pfs,
105 struct uio *uio)
106 {
107 char buf[512], *cp;
108 int len, error;
109
110 len = sizeof buf;
111 if (procfs_getcpuinfstr(buf, &len) < 0)
112 return EIO;
113
114 if (len == 0 || uio->uio_offset > sizeof(buf))
115 return 0;
116
117 len -= uio->uio_offset;
118 cp = buf + uio->uio_offset;
119 len = imin(len, uio->uio_resid);
120 if (len <= 0)
121 error = 0;
122 else
123 error = uiomove(cp, len, uio);
124 return error;
125 }
126
127 #ifndef __i386__
128 int
129 procfs_getcpuinfstr(char *buf, int *len)
130 {
131 *len = 0;
132
133 return 0;
134 }
135 #endif