1 /* MIB service - hw.c - implementation of the CTL_HW subtree */
6 static const char mach
[] = "i386"; /* machine (cpu) type */
7 static const char arch
[] = "i386"; /* architecture */
9 static const char mach
[] = "evbarm"; /* machine (cpu) type */
10 static const char arch
[] = "evbarm"; /* architecture */
12 #error "unknown machine architecture"
16 * Implementation of CTL_HW HW_PHYSMEM/HW_PHYSMEM64.
19 mib_hw_physmem(struct mib_call
* call __unused
, struct mib_node
* node
,
20 struct mib_oldp
* oldp
, struct mib_newp
* newp __unused
)
22 struct vm_stats_info vsi
;
26 if (vm_info_stats(&vsi
) != OK
)
29 physmem64
= (u_quad_t
)vsi
.vsi_total
* vsi
.vsi_pagesize
;
31 if (node
->node_size
== sizeof(int)) {
32 if (physmem64
> UINT_MAX
)
35 physmem
= (unsigned int)physmem64
;
37 return mib_copyout(oldp
, 0, &physmem
, sizeof(physmem
));
39 return mib_copyout(oldp
, 0, &physmem64
, sizeof(physmem64
));
43 * Implementation of CTL_HW HW_USERMEM/HW_USERMEM64.
46 mib_hw_usermem(struct mib_call
* call __unused
, struct mib_node
* node
,
47 struct mib_oldp
* oldp
, struct mib_newp
* newp __unused
)
49 struct vm_stats_info vsi
;
50 struct vm_usage_info vui
;
54 if (vm_info_stats(&vsi
) != OK
)
57 usermem64
= (u_quad_t
)vsi
.vsi_total
* vsi
.vsi_pagesize
;
59 if (vm_info_usage(KERNEL
, &vui
) != OK
)
62 if (usermem64
>= vui
.vui_total
)
63 usermem64
-= vui
.vui_total
;
67 if (node
->node_size
== sizeof(int)) {
68 if (usermem64
> UINT_MAX
)
71 usermem
= (unsigned int)usermem64
;
73 return mib_copyout(oldp
, 0, &usermem
, sizeof(usermem
));
75 return mib_copyout(oldp
, 0, &usermem64
, sizeof(usermem64
));
79 * Implementation of CTL_HW HW_NCPUONLINE.
82 mib_hw_ncpuonline(struct mib_call
* call __unused
,
83 struct mib_node
* node __unused
, struct mib_oldp
* oldp
,
84 struct mib_newp
* newp __unused
)
86 struct machine machine
;
89 if (sys_getmachine(&machine
) != OK
)
92 ncpuonline
= machine
.processors_count
;
94 return mib_copyout(oldp
, 0, &ncpuonline
, sizeof(ncpuonline
));
97 /* The CTL_HW nodes. */
98 static struct mib_node mib_hw_table
[] = {
99 /* 1*/ [HW_MACHINE
] = MIB_STRING(_P
| _RO
, mach
, "machine",
101 /* 2*/ /* HW_MODEL: not yet supported */
102 /* 3*/ [HW_NCPU
] = MIB_INT(_P
| _RO
, CONFIG_MAX_CPUS
,
103 "ncpu", "Number of CPUs configured"),
104 /* 4*/ [HW_BYTEORDER
] = MIB_INT(_P
| _RO
, BYTE_ORDER
, "byteorder",
105 "System byte order"),
106 /* 5*/ [HW_PHYSMEM
] = MIB_FUNC(_P
| _RO
| CTLFLAG_UNSIGNED
|
107 CTLTYPE_INT
, sizeof(int), mib_hw_physmem
,
108 "physmem", "Bytes of physical memory"),
109 /* 6*/ [HW_USERMEM
] = MIB_FUNC(_P
| _RO
| CTLFLAG_UNSIGNED
|
110 CTLTYPE_INT
, sizeof(int), mib_hw_usermem
,
111 "usermem", "Bytes of non-kernel memory"),
112 /* 7*/ [HW_PAGESIZE
] = MIB_INT(_P
| _RO
, PAGE_SIZE
, "pagesize",
113 "Software page size"),
114 /* 8*/ /* HW_DISKNAMES: not yet supported */
115 /* 9*/ /* HW_IOSTATS: not yet supported */
116 /*10*/ [HW_MACHINE_ARCH
] = MIB_STRING(_P
| _RO
, arch
, "machine_arch",
117 "Machine CPU class"),
118 /*11*/ /* HW_ALIGNBYTES: not yet supported */
119 /*12*/ /* HW_CNMAGIC: not yet supported */
120 /*13*/ [HW_PHYSMEM64
] = MIB_FUNC(_P
| _RO
| CTLTYPE_QUAD
,
121 sizeof(u_quad_t
), mib_hw_physmem
,
122 "physmem64", "Bytes of physical memory"),
123 /*14*/ [HW_USERMEM64
] = MIB_FUNC(_P
| _RO
| CTLTYPE_QUAD
,
124 sizeof(u_quad_t
), mib_hw_usermem
,
125 "usermem64", "Bytes of non-kernel memory"),
126 /*15*/ /* HW_IOSTATNAMES: not yet supported */
127 /*16*/ [HW_NCPUONLINE
] = MIB_FUNC(_P
| _RO
| CTLTYPE_INT
, sizeof(int),
128 mib_hw_ncpuonline
, "ncpuonline",
129 "Number of CPUs online"),
133 * Initialize the CTL_HW subtree.
136 mib_hw_init(struct mib_node
* node
)
139 MIB_INIT_ENODE(node
, mib_hw_table
);