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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
//! Memory profile provider — per-DIMM SPD / XMP / EXPO read-only view.
//!
//! Builds on the existing [`crate::memory_topology::MemoryTopologyMonitor`],
//! which already parses SMBIOS Type 17 records. We surface per-DIMM rated vs.
//! configured speed (the gap between them is the classic indicator that an
//! XMP/EXPO profile has *not* been activated), plus voltage, rank count, and
//! ECC status.
//!
//! True SPD byte-level XMP profile decode (Intel XMP 2.0/3.0 magic at SPD
//! offsets 384–509, AMD EXPO at 768–1023) requires direct SMBus / `i2c-dev`
//! access on Linux and an SMBus driver on Windows. The hooks are in place
//! for that next step but the bytes themselves are not read in this pass.
use super::{ProfileGroup, ProfileProvider, Setting, SettingRisk, SettingValue, Subsystem};
pub struct MemoryProfileProvider {
_private: (),
}
impl MemoryProfileProvider {
pub fn new() -> Self {
Self { _private: () }
}
}
impl Default for MemoryProfileProvider {
fn default() -> Self {
Self::new()
}
}
impl ProfileProvider for MemoryProfileProvider {
fn subsystem(&self) -> Subsystem {
Subsystem::Memory
}
fn snapshot(&mut self) -> Result<Vec<ProfileGroup>, String> {
let (mut groups, spd_unread) = super::split_scan(super::spd_xmp::scan_xmp_groups());
let monitor = match crate::memory_topology::MemoryTopologyMonitor::new() {
Ok(m) => m,
Err(e) => {
// Nothing was read: fail the provider and name every reason.
// Where the SPD scan did find something, keep it and show the
// missing topology as a note, not as a machine with no DIMMs.
if groups.is_empty() {
let mut reasons = spd_unread;
reasons.push(format!("DIMM topology unreadable: {e}"));
return Err(reasons.join("; "));
}
let mut g = ProfileGroup::new(
Subsystem::Memory,
"DIMM topology",
"DIMM SPD / configured",
"SMBIOS Type 17",
);
g.note(format!("not read: {e}"));
groups.push(g);
groups.extend(super::not_read_groups(
Subsystem::Memory,
"SPD/XMP",
&spd_unread,
));
return Ok(groups);
}
};
for dimm in monitor.populated_dimms() {
// Only the manufacturer and part number that were read go in the
// label. An empty manufacturer used to print the word "Unknown".
let make = [dimm.manufacturer.as_str(), dimm.part_number.as_str()]
.iter()
.filter(|s| !s.is_empty())
.copied()
.collect::<Vec<_>>()
.join(" ");
let size = dimm
.capacity_gib()
.map_or_else(|| "size not read".to_string(), |g| format!("{g:.2} GiB"));
let label = if make.is_empty() {
format!("{} ({} {:?})", dimm.locator, size, dimm.memory_type)
} else {
format!(
"{} — {} ({} {:?})",
dimm.locator, make, size, dimm.memory_type
)
};
let mut g = ProfileGroup::new(
Subsystem::Memory,
label,
"DIMM SPD / configured",
"SMBIOS Type 17",
);
// The locator is the stable identity; the label carries SPD fields that can vary.
g.key = Some(dimm.locator.clone());
// macOS reports no bank locator. Only a bank that was read gets a row.
if !dimm.bank.is_empty() {
g.push(Setting::info(
"bank",
"Bank Locator",
SettingValue::Text(dimm.bank.clone()),
));
}
// Rows only for what was read, following the voltage row below.
if let Some(rated) = dimm.speed_mts {
g.push(
Setting::info(
"rated_speed_mts",
"Rated Speed",
SettingValue::Uint(rated as u64),
)
.with_unit("MT/s")
.with_description("Maximum speed the DIMM is rated for (SPD)."),
);
}
if let Some(configured) = dimm.configured_speed_mts {
g.push(
Setting::info(
"configured_speed_mts",
"Configured Speed",
SettingValue::Uint(configured as u64),
)
.with_unit("MT/s")
.with_description(concat!(
"Speed the BIOS programmed at boot. If lower than Rated Speed, ",
"XMP/EXPO is likely disabled."
)),
);
}
// **The advice this tab exists to give was being suppressed.** Every
// DIMM reader filled a missing configured speed by copying the rated
// one, so the two were equal and `configured < rated` never held --
// on every Mac, and on every Windows machine where WMI returned no
// `ConfiguredClockSpeed`. Those are the machines where XMP/EXPO is
// most likely off, and they were told nothing.
match (dimm.configured_speed_mts, dimm.speed_mts) {
(Some(configured), Some(rated)) if configured < rated => {
g.note(format!(
concat!(
"DIMM is running at {} MT/s but is rated for {} MT/s — ",
"enable XMP/EXPO in BIOS to use the rated speed."
),
configured, rated
));
}
// Rated is known and configured is not: the one comparison this
// tab exists to make cannot be made, and saying so is better than
// a silence that reads as "your memory is at its rated speed".
(None, Some(_)) => {
g.note(concat!(
"This platform did not report the configured memory speed, ",
"so whether XMP/EXPO is enabled cannot be determined here."
));
}
_ => {}
}
g.push(Setting::info(
"memory_type",
"Memory Type",
SettingValue::Text(format!("{:?}", dimm.memory_type)),
));
g.push(Setting::info(
"form_factor",
"Form Factor",
SettingValue::Text(format!("{:?}", dimm.form_factor)),
));
// SMBIOS Type 17 defines zero in the voltage fields as "unknown",
// and this machine's firmware leaves them there --- so the row read
// "Voltage = 0 V [dangerous]" for a DDR5 module that necessarily runs
// near 1.1V. A zero volts no DIMM can have, marked dangerous so it
// reads as significant, is worse than no row at all.
if let Some(voltage) = dimm.voltage {
g.push(
Setting::info("voltage_v", "Voltage", SettingValue::Float(voltage))
.with_unit("V")
.with_risk(SettingRisk::Dangerous)
.with_description(
"DIMM operating voltage. Overriding via XMP/EXPO can affect stability.",
),
);
}
// Windows and macOS report no rank count; the row used to say 1.
if let Some(ranks) = dimm.ranks {
g.push(Setting::info(
"ranks",
"Ranks",
SettingValue::Uint(ranks as u64),
));
}
if let Some(w) = dimm.data_width_bits {
g.push(Setting::info(
"data_width_bits",
"Data Width",
SettingValue::Uint(w as u64),
));
}
if let Some(w) = dimm.total_width_bits {
g.push(Setting::info(
"total_width_bits",
"Total Width",
SettingValue::Uint(w as u64),
));
}
// No row rather than a false one: `is_ecc` is unanswerable when
// either width was not read.
if let Some(ecc) = dimm.is_ecc() {
g.push(Setting::info("ecc", "ECC", SettingValue::Bool(ecc)));
}
if !dimm.serial_number.is_empty() {
g.push(Setting::info(
"serial_number",
"Serial Number",
SettingValue::Text(dimm.serial_number.clone()),
));
}
g.note(
"Raw XMP/EXPO profile blocks (full sub-timings, secondary/tertiary \
straps, voltages per profile) require direct SPD/SMBus reads and \
are not yet implemented.",
);
groups.push(g);
}
groups.extend(super::not_read_groups(
Subsystem::Memory,
"SPD/XMP",
&spd_unread,
));
Ok(groups)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn smoke() {
let mut p = MemoryProfileProvider::new();
let _ = p.snapshot();
}
}