amd-debug-tools 0.2.18__tar.gz → 0.2.20__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {amd_debug_tools-0.2.18/src/amd_debug_tools.egg-info → amd_debug_tools-0.2.20}/PKG-INFO +1 -1
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/amd_debug/common.py +43 -12
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/amd_debug/database.py +81 -7
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/amd_debug/failures.py +13 -1
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/amd_debug/kernel.py +31 -0
- amd_debug_tools-0.2.20/src/amd_debug/power_rails.py +195 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/amd_debug/prerequisites.py +31 -6
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/amd_debug/s2idle.py +8 -2
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/amd_debug/sleep_report.py +174 -22
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/amd_debug/templates/html +11 -2
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/amd_debug/validator.py +20 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/amd_debug/wake.py +27 -20
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20/src/amd_debug_tools.egg-info}/PKG-INFO +1 -1
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/amd_debug_tools.egg-info/SOURCES.txt +4 -0
- amd_debug_tools-0.2.20/src/amd_debug_tools.egg-info/scm_file_list.json +67 -0
- amd_debug_tools-0.2.20/src/amd_debug_tools.egg-info/scm_version.json +8 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/amd_debug_tools.egg-info/top_level.txt +1 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/test_common.py +16 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/test_database.py +118 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/test_installer.py +194 -2
- amd_debug_tools-0.2.20/src/test_kernel.py +408 -0
- amd_debug_tools-0.2.20/src/test_power_rails.py +373 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/test_prerequisites.py +150 -0
- amd_debug_tools-0.2.20/src/test_pstate.py +323 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/test_sleep_report.py +47 -2
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/test_validator.py +315 -3
- amd_debug_tools-0.2.20/src/test_wake.py +540 -0
- amd_debug_tools-0.2.18/src/test_kernel.py +0 -206
- amd_debug_tools-0.2.18/src/test_pstate.py +0 -164
- amd_debug_tools-0.2.18/src/test_wake.py +0 -216
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/.github/workflows/ci.yml +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/.github/workflows/mirror.yml +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/.gitignore +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/.pre-commit-config.yaml +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/.vscode/settings.json +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/LICENSE +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/Makefile +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/README.md +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/amd_bios.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/amd_pstate.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/amd_s2idle.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/amd_ttm.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/docs/amd-bios.md +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/docs/amd-pstate.md +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/docs/amd-s2idle.md +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/docs/amd-ttm.md +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/docs/in-tree.md +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/install_deps.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/psr.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/pyproject.toml +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/setup.cfg +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/amd_debug/__init__.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/amd_debug/acpi.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/amd_debug/bash/amd-s2idle +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/amd_debug/battery.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/amd_debug/bios.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/amd_debug/display.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/amd_debug/installer.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/amd_debug/pstate.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/amd_debug/s2idle-hook +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/amd_debug/templates/md +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/amd_debug/templates/stdout +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/amd_debug/templates/txt +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/amd_debug/ttm.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/amd_debug_tools.egg-info/dependency_links.txt +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/amd_debug_tools.egg-info/entry_points.txt +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/amd_debug_tools.egg-info/requires.txt +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/launcher.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/test_acpi.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/test_batteries.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/test_bios.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/test_display.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/test_failures.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/test_launcher.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/test_s2idle.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.20}/src/test_ttm.py +0 -0
|
@@ -13,6 +13,8 @@ import time
|
|
|
13
13
|
import struct
|
|
14
14
|
import subprocess
|
|
15
15
|
import sys
|
|
16
|
+
import stat
|
|
17
|
+
import pathlib
|
|
16
18
|
from ast import literal_eval
|
|
17
19
|
from datetime import date, timedelta
|
|
18
20
|
|
|
@@ -133,18 +135,46 @@ def _configure_log(prefix) -> str:
|
|
|
133
135
|
path = os.environ.get("XDG_DATA_HOME") or os.path.join(
|
|
134
136
|
home, ".local", "share", "amd-debug-tools"
|
|
135
137
|
)
|
|
136
|
-
|
|
137
|
-
log
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
138
|
+
|
|
139
|
+
# Prevent symlink attacks on log directory/file when running as root
|
|
140
|
+
path_obj = pathlib.Path(path)
|
|
141
|
+
|
|
142
|
+
try:
|
|
143
|
+
if path_obj.exists():
|
|
144
|
+
if path_obj.is_symlink():
|
|
145
|
+
raise ValueError(f"Log directory is a symlink: {path}")
|
|
146
|
+
else:
|
|
147
|
+
os.makedirs(path, mode=0o755, exist_ok=True)
|
|
148
|
+
if path_obj.is_symlink():
|
|
149
|
+
raise ValueError(f"Log directory became a symlink during creation: {path}")
|
|
150
|
+
|
|
144
151
|
if "SUDO_UID" in os.environ:
|
|
145
|
-
os.
|
|
146
|
-
|
|
147
|
-
|
|
152
|
+
os.lchown(path, int(os.environ["SUDO_UID"]), int(os.environ["SUDO_GID"]))
|
|
153
|
+
except (ValueError, OSError) as e:
|
|
154
|
+
logging.warning(f"Cannot create safe log directory: {e}")
|
|
155
|
+
log = "/dev/null"
|
|
156
|
+
level = logging.WARNING
|
|
157
|
+
else:
|
|
158
|
+
log = os.path.join(path, f"{prefix}-{date.today()}.txt")
|
|
159
|
+
|
|
160
|
+
try:
|
|
161
|
+
fd = os.open(
|
|
162
|
+
log,
|
|
163
|
+
os.O_WRONLY | os.O_CREAT | os.O_NOFOLLOW,
|
|
164
|
+
mode=stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH, # 0o644
|
|
165
|
+
)
|
|
166
|
+
try:
|
|
167
|
+
os.close(fd)
|
|
168
|
+
if "SUDO_UID" in os.environ:
|
|
169
|
+
os.lchown(log, int(os.environ["SUDO_UID"]), int(os.environ["SUDO_GID"]))
|
|
170
|
+
except Exception:
|
|
171
|
+
os.close(fd)
|
|
172
|
+
raise
|
|
173
|
+
except FileExistsError:
|
|
174
|
+
if os.path.islink(log):
|
|
175
|
+
raise ValueError(f"Log file is a symlink: {log}")
|
|
176
|
+
|
|
177
|
+
level = logging.DEBUG
|
|
148
178
|
else:
|
|
149
179
|
log = "/dev/null"
|
|
150
180
|
level = logging.WARNING
|
|
@@ -364,7 +394,7 @@ def read_msr(msr, cpu):
|
|
|
364
394
|
"""Read a Model-Specific Register (MSR) value from the CPU."""
|
|
365
395
|
p = f"/dev/cpu/{cpu}/msr"
|
|
366
396
|
if not os.path.exists(p) and is_root():
|
|
367
|
-
|
|
397
|
+
subprocess.run(["/sbin/modprobe", "msr"], check=False)
|
|
368
398
|
try:
|
|
369
399
|
f = os.open(p, os.O_RDONLY)
|
|
370
400
|
except OSError as exc:
|
|
@@ -392,6 +422,7 @@ def relaunch_sudo() -> None:
|
|
|
392
422
|
"DBUS_SESSION_BUS_ADDRESS",
|
|
393
423
|
"XDG_SESSION_TYPE",
|
|
394
424
|
"XDG_DATA_DIRS",
|
|
425
|
+
"KDE_SESSION_VERSION",
|
|
395
426
|
"SSH_CLIENT",
|
|
396
427
|
"SSH_TTY"
|
|
397
428
|
]:
|
|
@@ -6,7 +6,7 @@ import os
|
|
|
6
6
|
|
|
7
7
|
from amd_debug.common import read_file
|
|
8
8
|
|
|
9
|
-
SCHEMA_VERSION =
|
|
9
|
+
SCHEMA_VERSION = 2
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
def migrate(cur, user_version) -> None:
|
|
@@ -17,6 +17,18 @@ def migrate(cur, user_version) -> None:
|
|
|
17
17
|
# - add priority column
|
|
18
18
|
if val == 0:
|
|
19
19
|
cur.execute("ALTER TABLE debug ADD COLUMN priority INTEGER")
|
|
20
|
+
# Schema 2
|
|
21
|
+
# - add power_rails table
|
|
22
|
+
if val == 1:
|
|
23
|
+
cur.execute(
|
|
24
|
+
"CREATE TABLE IF NOT EXISTS power_rails ("
|
|
25
|
+
"t0 INTEGER, "
|
|
26
|
+
"label TEXT, "
|
|
27
|
+
"e0 REAL, "
|
|
28
|
+
"e1 REAL, "
|
|
29
|
+
"scale REAL, "
|
|
30
|
+
"PRIMARY KEY(t0, label))"
|
|
31
|
+
)
|
|
20
32
|
# Update schema if necessary
|
|
21
33
|
if val != user_version:
|
|
22
34
|
cur.execute(f"PRAGMA user_version = {user_version}")
|
|
@@ -32,12 +44,8 @@ class SleepDatabase:
|
|
|
32
44
|
self.debug_cnt = 0
|
|
33
45
|
|
|
34
46
|
if not dbf:
|
|
35
|
-
# if we were packaged we would have a directory in /var/lib
|
|
36
47
|
path = os.path.join("/", "var", "lib", "amd-s2idle")
|
|
37
|
-
|
|
38
|
-
path = os.path.join("/", "var", "local", "lib", "amd-s2idle")
|
|
39
|
-
os.makedirs(path, exist_ok=True)
|
|
40
|
-
|
|
48
|
+
os.makedirs(path, mode=0o700, exist_ok=True)
|
|
41
49
|
dbf = os.path.join(path, "data.db")
|
|
42
50
|
new = not os.path.exists(dbf)
|
|
43
51
|
self.db = sqlite3.connect(dbf)
|
|
@@ -85,6 +93,15 @@ class SleepDatabase:
|
|
|
85
93
|
"full INTEGER,"
|
|
86
94
|
"unit TEXT)"
|
|
87
95
|
)
|
|
96
|
+
cur.execute(
|
|
97
|
+
"CREATE TABLE IF NOT EXISTS power_rails ("
|
|
98
|
+
"t0 INTEGER,"
|
|
99
|
+
"label TEXT,"
|
|
100
|
+
"e0 REAL,"
|
|
101
|
+
"e1 REAL,"
|
|
102
|
+
"scale REAL,"
|
|
103
|
+
"PRIMARY KEY(t0, label))"
|
|
104
|
+
)
|
|
88
105
|
self.prereq_data_cnt = 0
|
|
89
106
|
|
|
90
107
|
if new:
|
|
@@ -167,7 +184,7 @@ class SleepDatabase:
|
|
|
167
184
|
else:
|
|
168
185
|
cur.execute(
|
|
169
186
|
"""
|
|
170
|
-
INSERT into battery (t0, name, b0, b1, full, unit)
|
|
187
|
+
INSERT into battery (t0, name, b0, b1, full, unit)
|
|
171
188
|
VALUES (?, ?, ?, ?, ?, ?)
|
|
172
189
|
""",
|
|
173
190
|
(
|
|
@@ -180,6 +197,46 @@ class SleepDatabase:
|
|
|
180
197
|
),
|
|
181
198
|
)
|
|
182
199
|
|
|
200
|
+
def record_power_rail_energy(self, label, energy, scale):
|
|
201
|
+
"""Helper function to record power rail energy
|
|
202
|
+
|
|
203
|
+
Args:
|
|
204
|
+
label: Rail label (e.g., "CPU_VDDCR_PH1_IN_POWER_1")
|
|
205
|
+
energy: Raw energy accumulator value
|
|
206
|
+
scale: Scale factor to convert raw to Joules
|
|
207
|
+
|
|
208
|
+
First call (prep): INSERT with e0
|
|
209
|
+
Second call (post): UPDATE with e1
|
|
210
|
+
"""
|
|
211
|
+
assert self.db
|
|
212
|
+
assert self.last_suspend
|
|
213
|
+
cur = self.db.cursor()
|
|
214
|
+
cur.execute(
|
|
215
|
+
"SELECT e0 FROM power_rails WHERE t0=? AND label=?",
|
|
216
|
+
(int(self.last_suspend.strftime("%Y%m%d%H%M%S")), label),
|
|
217
|
+
)
|
|
218
|
+
result = cur.fetchone()
|
|
219
|
+
if result is None:
|
|
220
|
+
# First call (prep): INSERT with e0
|
|
221
|
+
cur.execute(
|
|
222
|
+
"""
|
|
223
|
+
INSERT INTO power_rails (t0, label, e0, e1, scale)
|
|
224
|
+
VALUES (?, ?, ?, NULL, ?)
|
|
225
|
+
""",
|
|
226
|
+
(
|
|
227
|
+
int(self.last_suspend.strftime("%Y%m%d%H%M%S")),
|
|
228
|
+
label,
|
|
229
|
+
energy,
|
|
230
|
+
scale,
|
|
231
|
+
),
|
|
232
|
+
)
|
|
233
|
+
else:
|
|
234
|
+
# Second call (post): UPDATE with e1
|
|
235
|
+
cur.execute(
|
|
236
|
+
"UPDATE power_rails SET e1=? WHERE t0=? AND label=?",
|
|
237
|
+
(energy, int(self.last_suspend.strftime("%Y%m%d%H%M%S")), label),
|
|
238
|
+
)
|
|
239
|
+
|
|
183
240
|
def record_cycle_data(self, message, symbol) -> None:
|
|
184
241
|
"""Helper function to record a message to cycle_data database"""
|
|
185
242
|
assert self.last_suspend
|
|
@@ -316,6 +373,23 @@ class SleepDatabase:
|
|
|
316
373
|
)
|
|
317
374
|
return cur.fetchall()
|
|
318
375
|
|
|
376
|
+
def report_power_rails(self, t0=None) -> list:
|
|
377
|
+
"""Helper function to report power rails for a given timestamp
|
|
378
|
+
|
|
379
|
+
Returns:
|
|
380
|
+
List of tuples: (t0, label, e0, e1, scale)
|
|
381
|
+
"""
|
|
382
|
+
assert self.db
|
|
383
|
+
if t0 is None:
|
|
384
|
+
assert self.last_suspend
|
|
385
|
+
t0 = self.last_suspend
|
|
386
|
+
cur = self.db.cursor()
|
|
387
|
+
cur.execute(
|
|
388
|
+
"SELECT * FROM power_rails WHERE t0=?",
|
|
389
|
+
(int(t0.strftime("%Y%m%d%H%M%S")),),
|
|
390
|
+
)
|
|
391
|
+
return cur.fetchall()
|
|
392
|
+
|
|
319
393
|
def get_last_prereq_ts(self) -> int:
|
|
320
394
|
"""Helper function to report the last line from prereq database"""
|
|
321
395
|
assert self.db
|
|
@@ -441,7 +441,7 @@ class LowHardwareSleepResidency(S0i3Failure):
|
|
|
441
441
|
super().__init__()
|
|
442
442
|
self.description = "System had low hardware sleep residency"
|
|
443
443
|
self.explanation = (
|
|
444
|
-
f"The system was asleep for {
|
|
444
|
+
f"The system was asleep for {duration}, but only spent {percent:.2%} "
|
|
445
445
|
"of this time in a hardware sleep state. In sleep cycles that are at least "
|
|
446
446
|
"60 seconds long it's expected you spend above 90 percent of the cycle in "
|
|
447
447
|
"hardware sleep."
|
|
@@ -653,3 +653,15 @@ class MissingAmdCaptureModule(S0i3Failure):
|
|
|
653
653
|
"If the module is not available, disable the camera in the BIOS to prevent issues."
|
|
654
654
|
)
|
|
655
655
|
self.url = "https://gitlab.freedesktop.org/drm/amd/-/issues/4869"
|
|
656
|
+
|
|
657
|
+
|
|
658
|
+
class NpuIommu(S0i3Failure):
|
|
659
|
+
"""IOMMU configuration incompatible with NPU"""
|
|
660
|
+
|
|
661
|
+
def __init__(self):
|
|
662
|
+
super().__init__()
|
|
663
|
+
self.description = "IOMMU configuration incompatible with NPU"
|
|
664
|
+
self.explanation = (
|
|
665
|
+
"The NPU requires a properly configured IOMMU to function correctly. "
|
|
666
|
+
"Ensure that the IOMMU is enabled and configured in the BIOS."
|
|
667
|
+
)
|
|
@@ -94,6 +94,30 @@ def get_kernel_command_line() -> str:
|
|
|
94
94
|
return " ".join([x for x in cmdline.split() if not x.startswith(tuple(filtered))])
|
|
95
95
|
|
|
96
96
|
|
|
97
|
+
def redact_sensitive(text: str) -> str:
|
|
98
|
+
"""Redact high-confidence sensitive tokens from captured log text.
|
|
99
|
+
|
|
100
|
+
Only obviously-sensitive patterns are scrubbed so that the remaining
|
|
101
|
+
content keeps its diagnostic value:
|
|
102
|
+
- MAC addresses
|
|
103
|
+
- UUIDs (e.g. LUKS/filesystem identifiers)
|
|
104
|
+
- key/secret/password/token assignments
|
|
105
|
+
"""
|
|
106
|
+
text = re.sub(r"([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}", "<redacted-mac>", text)
|
|
107
|
+
text = re.sub(
|
|
108
|
+
r"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-"
|
|
109
|
+
r"[0-9a-fA-F]{4}-[0-9a-fA-F]{12}",
|
|
110
|
+
"<redacted-uuid>",
|
|
111
|
+
text,
|
|
112
|
+
)
|
|
113
|
+
text = re.sub(
|
|
114
|
+
r"(?i)\b(key|secret|password|passwd|token)=\S+",
|
|
115
|
+
r"\1=<redacted>",
|
|
116
|
+
text,
|
|
117
|
+
)
|
|
118
|
+
return text
|
|
119
|
+
|
|
120
|
+
|
|
97
121
|
def sscanf_bios_args(line):
|
|
98
122
|
"""Extracts the format string and arguments from a BIOS trace line"""
|
|
99
123
|
if re.search(r"ex_trace_point", line):
|
|
@@ -128,6 +152,13 @@ def sscanf_bios_args(line):
|
|
|
128
152
|
else:
|
|
129
153
|
break
|
|
130
154
|
|
|
155
|
+
# Reject unexpected conversions or oversized field widths from
|
|
156
|
+
# untrusted firmware-supplied format strings.
|
|
157
|
+
if re.search(r"%(?![xXdD%])", format_string) or re.search(
|
|
158
|
+
r"%\d{4,}", format_string
|
|
159
|
+
):
|
|
160
|
+
return None
|
|
161
|
+
|
|
131
162
|
try:
|
|
132
163
|
return format_string % tuple(converted_args)
|
|
133
164
|
except TypeError:
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MIT
|
|
2
|
+
"""Discovery and reading of IIO power monitor rails.
|
|
3
|
+
|
|
4
|
+
This module discovers power monitoring chips via the Linux IIO (Industrial I/O)
|
|
5
|
+
sysfs interface and reads energy accumulator values for suspend power consumption analysis.
|
|
6
|
+
|
|
7
|
+
Each power monitor chip exposes N rails (typically 1-4). For rail N, the IIO
|
|
8
|
+
driver provides:
|
|
9
|
+
- in_powerN_label -- human-readable rail name
|
|
10
|
+
- in_energyN_raw -- raw energy accumulator value
|
|
11
|
+
- in_energyN_scale -- scale factor to convert raw to Joules
|
|
12
|
+
|
|
13
|
+
We capture energy accumulators before and after suspend, then calculate average
|
|
14
|
+
power as: Power (W) = ΔEnergy (J) / Δtime (s)
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
from dataclasses import dataclass
|
|
20
|
+
from pathlib import Path
|
|
21
|
+
from typing import Set
|
|
22
|
+
|
|
23
|
+
IIO_DEVICES_ROOT = Path("/sys/bus/iio/devices")
|
|
24
|
+
|
|
25
|
+
# Supported power monitor chip names (extensible set)
|
|
26
|
+
SUPPORTED_POWER_CHIPS: Set[str] = {
|
|
27
|
+
"pac1954",
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
# Maximum channel number to scan (some future chips may have more)
|
|
31
|
+
MAX_CHANNELS = 16
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _read_text(path: Path) -> str:
|
|
35
|
+
"""Read and strip text from a sysfs file."""
|
|
36
|
+
return path.read_text().strip()
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _read_float(path: Path) -> float:
|
|
40
|
+
"""Read a floating-point value from a sysfs file."""
|
|
41
|
+
return float(_read_text(path))
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@dataclass(frozen=True)
|
|
45
|
+
class PowerRail:
|
|
46
|
+
"""A single named power rail on an IIO power monitor chip.
|
|
47
|
+
|
|
48
|
+
Attributes:
|
|
49
|
+
device: IIO device name (e.g., "iio:device0")
|
|
50
|
+
channel: Channel number (1..N)
|
|
51
|
+
label: Human-readable rail name (e.g., "CPU_VDDCR_PH1_IN_POWER_1")
|
|
52
|
+
sysfs: Path to the device directory in sysfs
|
|
53
|
+
energy_scale: Scale factor to convert raw energy to Joules
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
device: str
|
|
57
|
+
channel: int
|
|
58
|
+
label: str
|
|
59
|
+
sysfs: Path
|
|
60
|
+
energy_scale: float
|
|
61
|
+
|
|
62
|
+
def read_energy_raw(self) -> float:
|
|
63
|
+
"""Read the current raw energy accumulator value.
|
|
64
|
+
|
|
65
|
+
Returns:
|
|
66
|
+
Raw energy accumulator value (units depend on chip, use energy_scale
|
|
67
|
+
to convert to Joules)
|
|
68
|
+
|
|
69
|
+
Raises:
|
|
70
|
+
OSError: If the sysfs file cannot be read
|
|
71
|
+
"""
|
|
72
|
+
return _read_float(self.sysfs / f"in_energy{self.channel}_raw")
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _discover_chip_rails(device_dir: Path, chip_ids: Set[str] = None) -> list[PowerRail]:
|
|
76
|
+
"""Discover all enabled power rails for a single IIO device.
|
|
77
|
+
|
|
78
|
+
Args:
|
|
79
|
+
device_dir: Path to the IIO device directory (e.g., /sys/bus/iio/devices/iio:device0)
|
|
80
|
+
chip_ids: Set of supported chip IDs to filter by (default: SUPPORTED_POWER_CHIPS)
|
|
81
|
+
|
|
82
|
+
Returns:
|
|
83
|
+
List of PowerRail objects for enabled rails on this device
|
|
84
|
+
"""
|
|
85
|
+
if chip_ids is None:
|
|
86
|
+
chip_ids = SUPPORTED_POWER_CHIPS
|
|
87
|
+
|
|
88
|
+
# Check if this is a supported power monitor chip
|
|
89
|
+
name_path = device_dir / "name"
|
|
90
|
+
if not name_path.exists():
|
|
91
|
+
return []
|
|
92
|
+
|
|
93
|
+
chip_name = _read_text(name_path)
|
|
94
|
+
if chip_name not in chip_ids:
|
|
95
|
+
return []
|
|
96
|
+
|
|
97
|
+
device_id = device_dir.name
|
|
98
|
+
rails: list[PowerRail] = []
|
|
99
|
+
|
|
100
|
+
# Scan for power rails (channel 1..MAX_CHANNELS)
|
|
101
|
+
for n in range(1, MAX_CHANNELS + 1):
|
|
102
|
+
label_path = device_dir / f"in_power{n}_label"
|
|
103
|
+
if not label_path.exists():
|
|
104
|
+
continue
|
|
105
|
+
|
|
106
|
+
label = _read_text(label_path)
|
|
107
|
+
if not label:
|
|
108
|
+
continue # Unwired or disabled rail
|
|
109
|
+
|
|
110
|
+
# Read the energy scale factor
|
|
111
|
+
scale_path = device_dir / f"in_energy{n}_scale"
|
|
112
|
+
if not scale_path.exists():
|
|
113
|
+
continue # No energy accumulator for this rail
|
|
114
|
+
|
|
115
|
+
try:
|
|
116
|
+
energy_scale = _read_float(scale_path)
|
|
117
|
+
rails.append(
|
|
118
|
+
PowerRail(
|
|
119
|
+
device=device_id,
|
|
120
|
+
channel=n,
|
|
121
|
+
label=label,
|
|
122
|
+
sysfs=device_dir,
|
|
123
|
+
energy_scale=energy_scale,
|
|
124
|
+
)
|
|
125
|
+
)
|
|
126
|
+
except (FileNotFoundError, ValueError, OSError):
|
|
127
|
+
# Skip rails with missing or invalid scale files
|
|
128
|
+
continue
|
|
129
|
+
|
|
130
|
+
return rails
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def discover_rails(
|
|
134
|
+
iio_root: Path = IIO_DEVICES_ROOT,
|
|
135
|
+
chip_ids: Set[str] = None,
|
|
136
|
+
) -> list[PowerRail]:
|
|
137
|
+
"""Discover all IIO power monitor rails on the system.
|
|
138
|
+
|
|
139
|
+
Args:
|
|
140
|
+
iio_root: Root directory for IIO devices (default: /sys/bus/iio/devices)
|
|
141
|
+
chip_ids: Set of supported chip IDs (default: SUPPORTED_POWER_CHIPS)
|
|
142
|
+
|
|
143
|
+
Returns:
|
|
144
|
+
List of all discovered PowerRail objects, sorted by device name
|
|
145
|
+
"""
|
|
146
|
+
if not iio_root.exists():
|
|
147
|
+
return []
|
|
148
|
+
|
|
149
|
+
rails: list[PowerRail] = []
|
|
150
|
+
for device_dir in sorted(iio_root.glob("iio:device*")):
|
|
151
|
+
rails.extend(_discover_chip_rails(device_dir, chip_ids))
|
|
152
|
+
|
|
153
|
+
return rails
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
class PowerRails:
|
|
157
|
+
"""Manages discovery and reading of IIO power monitor rails.
|
|
158
|
+
|
|
159
|
+
This class discovers available power monitor chips at initialization and
|
|
160
|
+
provides methods to read energy accumulator values from the discovered rails.
|
|
161
|
+
|
|
162
|
+
Attributes:
|
|
163
|
+
rails: List of discovered PowerRail objects
|
|
164
|
+
"""
|
|
165
|
+
|
|
166
|
+
def __init__(self, iio_root: Path = IIO_DEVICES_ROOT):
|
|
167
|
+
"""Initialize and discover power rails.
|
|
168
|
+
|
|
169
|
+
Args:
|
|
170
|
+
iio_root: Root directory for IIO devices (allows testing with mock paths)
|
|
171
|
+
"""
|
|
172
|
+
self.iio_root = iio_root
|
|
173
|
+
self.rails = discover_rails(iio_root)
|
|
174
|
+
|
|
175
|
+
def get_rails(self) -> list[PowerRail]:
|
|
176
|
+
"""Get the list of discovered power rails.
|
|
177
|
+
|
|
178
|
+
Returns:
|
|
179
|
+
List of PowerRail objects
|
|
180
|
+
"""
|
|
181
|
+
return self.rails
|
|
182
|
+
|
|
183
|
+
def read_rail_energy(self, rail: PowerRail) -> float:
|
|
184
|
+
"""Read the current energy accumulator for a specific rail.
|
|
185
|
+
|
|
186
|
+
Args:
|
|
187
|
+
rail: PowerRail object to read from
|
|
188
|
+
|
|
189
|
+
Returns:
|
|
190
|
+
Raw energy accumulator value
|
|
191
|
+
|
|
192
|
+
Raises:
|
|
193
|
+
OSError: If the sysfs file cannot be read
|
|
194
|
+
"""
|
|
195
|
+
return rail.read_energy_raw()
|
|
@@ -20,7 +20,13 @@ import pyudev
|
|
|
20
20
|
|
|
21
21
|
from amd_debug.wake import WakeIRQ
|
|
22
22
|
from amd_debug.display import Display
|
|
23
|
-
from amd_debug.kernel import
|
|
23
|
+
from amd_debug.kernel import (
|
|
24
|
+
get_kernel_log,
|
|
25
|
+
redact_sensitive,
|
|
26
|
+
SystemdLogger,
|
|
27
|
+
CySystemdLogger,
|
|
28
|
+
DmesgLogger,
|
|
29
|
+
)
|
|
24
30
|
from amd_debug.common import (
|
|
25
31
|
apply_prefix_wrapper,
|
|
26
32
|
BIT,
|
|
@@ -67,6 +73,7 @@ from amd_debug.failures import (
|
|
|
67
73
|
MissingThunderbolt,
|
|
68
74
|
MissingXhciHcd,
|
|
69
75
|
MSRFailure,
|
|
76
|
+
NpuIommu,
|
|
70
77
|
RogAllyMcuPowerSave,
|
|
71
78
|
RogAllyOldMcu,
|
|
72
79
|
SleepModeWrong,
|
|
@@ -343,21 +350,39 @@ class PrerequisiteValidator(AmdTool):
|
|
|
343
350
|
|
|
344
351
|
def check_amd_xdna(self):
|
|
345
352
|
"""Check for AMD XDNA driver"""
|
|
353
|
+
amdxdna_path = os.path.join("/", "sys", "module", "amdxdna")
|
|
354
|
+
driver_loaded = os.path.exists(amdxdna_path)
|
|
355
|
+
# No driver loaded means HW should be power gated, should be OK.
|
|
356
|
+
if not driver_loaded:
|
|
357
|
+
return True
|
|
358
|
+
|
|
359
|
+
# IOMMU disabled can cause problems with the NPU
|
|
360
|
+
found_iommu = False
|
|
361
|
+
for _dev in self.pyudev.list_devices(subsystem="iommu"):
|
|
362
|
+
found_iommu = True
|
|
363
|
+
break
|
|
346
364
|
for device in self.pyudev.list_devices(subsystem="pci", PCI_CLASS="118000"):
|
|
347
365
|
slot = device.properties["PCI_SLOT_NAME"]
|
|
348
366
|
driver = device.properties.get("DRIVER")
|
|
349
367
|
pci_id = device.properties.get("PCI_ID")
|
|
350
368
|
if not pci_id.startswith("1022"):
|
|
351
369
|
continue
|
|
352
|
-
if not driver:
|
|
353
|
-
self.db.record_prereq(f"NPU device in {slot} missing driver", "🚦")
|
|
354
|
-
self.failures += [MissingDriver(slot)]
|
|
355
370
|
p = os.path.join(device.sys_path, "fw_version")
|
|
356
371
|
if os.path.exists(p):
|
|
357
372
|
xdna_fw_version = read_file(p)
|
|
358
373
|
self.db.record_prereq(
|
|
359
374
|
f"NPU loaded with firmware {xdna_fw_version}", "✅"
|
|
360
375
|
)
|
|
376
|
+
if not found_iommu and driver:
|
|
377
|
+
self.db.record_prereq("NPU is not supported with IOMMU disabled", "❌")
|
|
378
|
+
self.failures += [NpuIommu()]
|
|
379
|
+
return False
|
|
380
|
+
if not driver:
|
|
381
|
+
self.db.record_prereq(
|
|
382
|
+
f"NPU device in {slot} didn't bind a driver", "🚦"
|
|
383
|
+
)
|
|
384
|
+
self.failures += [MissingDriver(slot)]
|
|
385
|
+
|
|
361
386
|
return True
|
|
362
387
|
|
|
363
388
|
def check_amd_hsmp(self):
|
|
@@ -1158,7 +1183,7 @@ class PrerequisiteValidator(AmdTool):
|
|
|
1158
1183
|
"""Read CPUID using kernel userspace interface"""
|
|
1159
1184
|
p = os.path.join("/", "dev", "cpu", f"{cpu}", "cpuid")
|
|
1160
1185
|
if not os.path.exists(p):
|
|
1161
|
-
|
|
1186
|
+
subprocess.run(["/sbin/modprobe", "cpuid"], check=False)
|
|
1162
1187
|
with open(p, "rb") as f:
|
|
1163
1188
|
position = (subleaf << 32) | leaf
|
|
1164
1189
|
f.seek(position)
|
|
@@ -1432,7 +1457,7 @@ class PrerequisiteValidator(AmdTool):
|
|
|
1432
1457
|
result = False
|
|
1433
1458
|
if not result:
|
|
1434
1459
|
self.db.record_prereq(Headers.BrokenPrerequisites, "🚫")
|
|
1435
|
-
self.db.record_debug(self.kernel_log.get_full_log())
|
|
1460
|
+
self.db.record_debug(redact_sensitive(self.kernel_log.get_full_log()))
|
|
1436
1461
|
self.db.sync()
|
|
1437
1462
|
clear_temporary_message(len(msg))
|
|
1438
1463
|
return result
|
|
@@ -20,7 +20,7 @@ from amd_debug.common import (
|
|
|
20
20
|
from amd_debug.validator import SleepValidator
|
|
21
21
|
from amd_debug.installer import Installer
|
|
22
22
|
from amd_debug.prerequisites import PrerequisiteValidator
|
|
23
|
-
from amd_debug.sleep_report import SleepReport
|
|
23
|
+
from amd_debug.sleep_report import SleepReport, confirm_overwrite_report
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
class Defaults:
|
|
@@ -62,7 +62,7 @@ def display_report_file(fname, fmt) -> None:
|
|
|
62
62
|
if user:
|
|
63
63
|
env_vars = []
|
|
64
64
|
for var in ["DISPLAY", "WAYLAND_DISPLAY", "XAUTHORITY", "XDG_RUNTIME_DIR",
|
|
65
|
-
"DBUS_SESSION_BUS_ADDRESS", "XDG_SESSION_TYPE", "XDG_DATA_DIRS"]:
|
|
65
|
+
"DBUS_SESSION_BUS_ADDRESS", "XDG_SESSION_TYPE", "XDG_DATA_DIRS", "KDE_SESSION_VERSION"]:
|
|
66
66
|
value = os.environ.get(var)
|
|
67
67
|
if value:
|
|
68
68
|
env_vars.append(f"{var}={value}")
|
|
@@ -179,6 +179,9 @@ def report(since, until, fname, fmt, tool_debug, report_debug) -> bool:
|
|
|
179
179
|
)
|
|
180
180
|
except KeyboardInterrupt:
|
|
181
181
|
sys.exit("\nReport generation cancelled")
|
|
182
|
+
if not confirm_overwrite_report(fname):
|
|
183
|
+
print("Report generation cancelled")
|
|
184
|
+
return False
|
|
182
185
|
try:
|
|
183
186
|
app = SleepReport(
|
|
184
187
|
since=since,
|
|
@@ -226,6 +229,9 @@ def run_test_cycle(
|
|
|
226
229
|
except KeyboardInterrupt:
|
|
227
230
|
sys.exit("\nTest cancelled")
|
|
228
231
|
|
|
232
|
+
if not confirm_overwrite_report(fname):
|
|
233
|
+
sys.exit("Test cancelled")
|
|
234
|
+
|
|
229
235
|
try:
|
|
230
236
|
app = PrerequisiteValidator(debug)
|
|
231
237
|
run = app.run()
|