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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
//! Port of `dragonflybsd/DragonFlyBSDMachine.c` + `.h` — the DragonFly BSD
//! per-host state and its `sysctl`/`libkvm` scan layer.
//!
//! The struct model and the small pure accessors are ported here. The scan
//! functions (`Machine_new`/`Machine_scan`/`DragonFlyBSDMachine_scan*`) drive
//! `sysctl`/`kvm_*`, which exist only on DragonFly BSD; like the `linux/` scan
//! layer they are ported-but-only-runnable on their platform. They are kept as
//! faithful `todo!()` stubs (named after the C functions so the port gate
//! accepts the module) until ported behind `#[cfg(target_os = "dragonfly")]`
//! with the DragonFly `sys/sysctl.h` / `sys/user.h` bindings.
use c_void;
use crateHashtable;
use crateMachine;
/// Port of `typedef struct CPUData_` (`DragonFlyBSDMachine.h:26`) — the
/// per-CPU load percentages computed each scan from the `kern.cp_time(s)`
/// sysctl deltas.
/// Port of `typedef struct DragonFlyBSDMachine_` (`DragonFlyBSDMachine.h`).
/// "Extends" [`Machine`] via the embedded `super_`, plus the DragonFly kvm
/// handle, jail table, page-size / scale constants, memory partition sizes,
/// per-CPU data, and the `cp_time(s)` old/new tick buffers.
///
/// `kd` (C `kvm_t*`) is an opaque `*mut c_void` (no `libkvm` on non-DragonFly
/// hosts); `jails` (C `Hashtable*` of jailid → hostname) is an owned
/// [`Hashtable`]; `memory_t` fields are `u64`; the `cp_time*` arrays are
/// `Vec<u64>` (C `unsigned long*`, `xCalloc`-sized per CPU).
///
/// No `#[derive(Debug)]`: the `jails` [`Hashtable`] holds trait-object values
/// and is not `Debug`. Constructed by the (stubbed) [`Machine_new`].
/// Port of `bool Machine_isCPUonline(const Machine* host, unsigned int id)`
/// (`DragonFlyBSDMachine.c:369`). DragonFly does not yet expose per-CPU
/// online/offline state, so every existing CPU is reported online (verbatim
/// C behavior, including the `id < existingCPUs` precondition).
/// Port of `int Machine_getCPUPhysicalCoreID(const Machine* host, unsigned int
/// id)` (`DragonFlyBSDMachine.c:377`). DragonFly does not expose topology, so
/// the physical core id is the CPU id itself.
/// Port of `int Machine_getCPUThreadIndex(const Machine* host, unsigned int
/// id)` (`DragonFlyBSDMachine.c:383`). No SMT topology on DragonFly, so every
/// CPU is thread index 0.
/// TODO: port of `Machine* Machine_new(UsersTable* usersTable, uid_t userId)`
/// (`DragonFlyBSDMachine.c:41`). Opens `kvm_openfiles`, reads page size /
/// physmem / v_page_count via `sysctl(name)tomib`, and allocates the CPU /
/// cp_time buffers — DragonFly `sys/sysctl.h` + `libkvm`, gated to
/// `#[cfg(target_os = "dragonfly")]` when ported.
/// TODO: port of `void Machine_delete(Machine* super)`
/// (`DragonFlyBSDMachine.c:119`). `kvm_close` + `Hashtable_delete(jails)` +
/// `free` of the cpu / cp_time buffers; Rust `Drop` releases the owned Vecs,
/// but the `kvm_t*` close is DragonFly-only.
/// TODO: port of `static void DragonFlyBSDMachine_scanCPUTime(Machine* super)`
/// (`DragonFlyBSDMachine.c:141`). Reads `kern.cp_time` / `kern.cp_times` via
/// sysctl and computes per-CPU load deltas. DragonFly sysctl.
/// TODO: port of `static void DragonFlyBSDMachine_scanMemoryInfo(Machine*
/// super)` (`DragonFlyBSDMachine.c:223`). Reads the `vm.stats.vm.*` counters
/// via sysctl for wired/active/inactive/cache/buffers memory. DragonFly sysctl.
/// TODO: port of `static void DragonFlyBSDMachine_scanJails(DragonFlyBSDMachine*
/// this)` (`DragonFlyBSDMachine.c:294`). Enumerates jails via `kern.jail`
/// sysctl into the `jails` hashtable. DragonFly sysctl.
/// TODO: port of `char* DragonFlyBSDMachine_readJailName(const
/// DragonFlyBSDMachine* host, int jailid)` (`DragonFlyBSDMachine.c:348`).
/// Looks up `jailid` in the `jails` hashtable (populated by the stubbed
/// [`DragonFlyBSDMachine_scanJails`]) and duplicates the hostname, else `"-"`.
/// Blocked on the jails hashtable being populated (needs the sysctl scan) and
/// on modeling its `char*` string values.
/// TODO: port of `void Machine_scan(Machine* super)`
/// (`DragonFlyBSDMachine.c:361`). Orchestrates the per-tick scan:
/// `DragonFlyBSDMachine_scanMemoryInfo` + `DragonFlyBSDMachine_scanCPUTime`
/// (both stubbed above, DragonFly sysctl).