zenmaster 1.2.1__tar.gz → 1.2.2__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.
- {zenmaster-1.2.1/zenmaster.egg-info → zenmaster-1.2.2}/PKG-INFO +2 -2
- {zenmaster-1.2.1 → zenmaster-1.2.2}/README.md +1 -1
- {zenmaster-1.2.1 → zenmaster-1.2.2}/pyproject.toml +1 -1
- {zenmaster-1.2.1 → zenmaster-1.2.2}/zenmaster/__init__.py +1 -1
- {zenmaster-1.2.1 → zenmaster-1.2.2}/zenmaster/hardware.py +12 -1
- {zenmaster-1.2.1 → zenmaster-1.2.2}/zenmaster/linux.py +26 -17
- {zenmaster-1.2.1 → zenmaster-1.2.2}/zenmaster/macos.py +16 -7
- {zenmaster-1.2.1 → zenmaster-1.2.2}/zenmaster/mailbox.py +19 -10
- {zenmaster-1.2.1 → zenmaster-1.2.2}/zenmaster/smu.py +20 -19
- {zenmaster-1.2.1 → zenmaster-1.2.2}/zenmaster/windows.py +55 -42
- {zenmaster-1.2.1 → zenmaster-1.2.2/zenmaster.egg-info}/PKG-INFO +2 -2
- {zenmaster-1.2.1 → zenmaster-1.2.2}/LICENSE +0 -0
- {zenmaster-1.2.1 → zenmaster-1.2.2}/setup.cfg +0 -0
- {zenmaster-1.2.1 → zenmaster-1.2.2}/zenmaster/RyzenSMU.bin +0 -0
- {zenmaster-1.2.1 → zenmaster-1.2.2}/zenmaster/__main__.py +0 -0
- {zenmaster-1.2.1 → zenmaster-1.2.2}/zenmaster/apply.py +0 -0
- {zenmaster-1.2.1 → zenmaster-1.2.2}/zenmaster/cli.py +0 -0
- {zenmaster-1.2.1 → zenmaster-1.2.2}/zenmaster/directhw.py +0 -0
- {zenmaster-1.2.1 → zenmaster-1.2.2}/zenmaster/errors.py +0 -0
- {zenmaster-1.2.1 → zenmaster-1.2.2}/zenmaster/iokit.py +0 -0
- {zenmaster-1.2.1 → zenmaster-1.2.2}/zenmaster/iopci.py +0 -0
- {zenmaster-1.2.1 → zenmaster-1.2.2}/zenmaster/pmtable.py +0 -0
- {zenmaster-1.2.1 → zenmaster-1.2.2}/zenmaster/py.typed +0 -0
- {zenmaster-1.2.1 → zenmaster-1.2.2}/zenmaster/runner.py +0 -0
- {zenmaster-1.2.1 → zenmaster-1.2.2}/zenmaster/sensors.py +0 -0
- {zenmaster-1.2.1 → zenmaster-1.2.2}/zenmaster/update.py +0 -0
- {zenmaster-1.2.1 → zenmaster-1.2.2}/zenmaster.egg-info/SOURCES.txt +0 -0
- {zenmaster-1.2.1 → zenmaster-1.2.2}/zenmaster.egg-info/dependency_links.txt +0 -0
- {zenmaster-1.2.1 → zenmaster-1.2.2}/zenmaster.egg-info/entry_points.txt +0 -0
- {zenmaster-1.2.1 → zenmaster-1.2.2}/zenmaster.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: zenmaster
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.2
|
|
4
4
|
Summary: Adjust power management settings for Ryzen CPUs on Linux, Windows, and macOS
|
|
5
5
|
Author-email: oxGorou <lekhanhbinh2901@gmail.com>
|
|
6
6
|
License-Expression: GPL-3.0-only
|
|
@@ -193,7 +193,7 @@ print(f"SMN 0x0005A380 = 0x{value:08X}")
|
|
|
193
193
|
|
|
194
194
|
## Technical Comparison: ZenMaster vs. RyzenAdj
|
|
195
195
|
|
|
196
|
-
| Feature | RyzenAdj | ZenMaster v1.2.
|
|
196
|
+
| Feature | RyzenAdj | ZenMaster v1.2.2 |
|
|
197
197
|
|---|---|---|
|
|
198
198
|
| **Installation** | Compilation from source (`cmake`, `make`, `libpci-dev`) | `pip install zenmaster` (pure Python package) |
|
|
199
199
|
| **Supported Families** | ~15 APU and desktop families | 44 families (Zen 1 to Zen 5/6, Desktop, Mobile, Threadripper, Server EPYC via HSMP) |
|
|
@@ -162,7 +162,7 @@ print(f"SMN 0x0005A380 = 0x{value:08X}")
|
|
|
162
162
|
|
|
163
163
|
## Technical Comparison: ZenMaster vs. RyzenAdj
|
|
164
164
|
|
|
165
|
-
| Feature | RyzenAdj | ZenMaster v1.2.
|
|
165
|
+
| Feature | RyzenAdj | ZenMaster v1.2.2 |
|
|
166
166
|
|---|---|---|
|
|
167
167
|
| **Installation** | Compilation from source (`cmake`, `make`, `libpci-dev`) | `pip install zenmaster` (pure Python package) |
|
|
168
168
|
| **Supported Families** | ~15 APU and desktop families | 44 families (Zen 1 to Zen 5/6, Desktop, Mobile, Threadripper, Server EPYC via HSMP) |
|
|
@@ -26,7 +26,7 @@ from zenmaster.errors import (
|
|
|
26
26
|
try:
|
|
27
27
|
__version__ = version("zenmaster")
|
|
28
28
|
except PackageNotFoundError:
|
|
29
|
-
__version__ = "1.2.
|
|
29
|
+
__version__ = "1.2.2"
|
|
30
30
|
|
|
31
31
|
__all__ = [
|
|
32
32
|
"CpuInfo", "detect", "resolve", "apply", "ApplyResult", "runner", "smu", "sensors", "table",
|
|
@@ -97,7 +97,16 @@ def _libSystem() -> ctypes.CDLL | None:
|
|
|
97
97
|
global _libc
|
|
98
98
|
if _libc is None:
|
|
99
99
|
try:
|
|
100
|
-
|
|
100
|
+
libc = ctypes.CDLL("/usr/lib/libSystem.B.dylib")
|
|
101
|
+
libc.sysctlbyname.restype = ctypes.c_int
|
|
102
|
+
libc.sysctlbyname.argtypes = [
|
|
103
|
+
ctypes.c_char_p,
|
|
104
|
+
ctypes.c_void_p,
|
|
105
|
+
ctypes.POINTER(ctypes.c_size_t),
|
|
106
|
+
ctypes.c_void_p,
|
|
107
|
+
ctypes.c_size_t,
|
|
108
|
+
]
|
|
109
|
+
_libc = libc
|
|
101
110
|
except (OSError, Exception):
|
|
102
111
|
return None
|
|
103
112
|
return _libc
|
|
@@ -128,6 +137,8 @@ def _sysctl_int(name: str) -> int:
|
|
|
128
137
|
size = ctypes.c_size_t(ctypes.sizeof(val))
|
|
129
138
|
if libc.sysctlbyname(name.encode(), ctypes.byref(val), ctypes.byref(size), None, 0) != 0:
|
|
130
139
|
return 0
|
|
140
|
+
if size.value == 4:
|
|
141
|
+
return int(ctypes.c_int32(val.value & 0xFFFFFFFF).value)
|
|
131
142
|
return int(val.value)
|
|
132
143
|
except (OSError, Exception):
|
|
133
144
|
return 0
|
|
@@ -13,7 +13,7 @@ from zenmaster.errors import BackendUnavailable, SMUNotInitialized
|
|
|
13
13
|
from zenmaster.pmtable import PM_TABLE_CMDS, TABLE_SIZES, DEFAULT_TABLE_SIZE
|
|
14
14
|
from zenmaster.mailbox import (
|
|
15
15
|
MP1, MP1_DEFAULT, RSMU, RSMU_DEFAULT, HSMP, HSMP_DEFAULT, NARGS,
|
|
16
|
-
transfer_with_retry,
|
|
16
|
+
DEFAULT_TIMEOUT, poll_response, transfer_with_retry,
|
|
17
17
|
)
|
|
18
18
|
from zenmaster.smu import SMU_OK, SMU_FAILED, SMU_REJECTED_PREREQ, ModuleStatus
|
|
19
19
|
|
|
@@ -90,7 +90,7 @@ MIN_VERSION = (0, 1, 7)
|
|
|
90
90
|
|
|
91
91
|
_POLL_N = 100
|
|
92
92
|
_SLEEP_S = 0.0001
|
|
93
|
-
_DEADLINE =
|
|
93
|
+
_DEADLINE = DEFAULT_TIMEOUT
|
|
94
94
|
_lock = threading.Lock()
|
|
95
95
|
_backend: str | None = None
|
|
96
96
|
_fd: int | None = None
|
|
@@ -163,7 +163,7 @@ def secure_boot_enabled() -> bool:
|
|
|
163
163
|
try:
|
|
164
164
|
out = subprocess.run(
|
|
165
165
|
["mokutil", "--sb-state"],
|
|
166
|
-
capture_output=True, text=True, timeout=
|
|
166
|
+
capture_output=True, text=True, timeout=5,
|
|
167
167
|
).stdout.lower()
|
|
168
168
|
return "enabled" in out
|
|
169
169
|
except Exception:
|
|
@@ -189,6 +189,17 @@ def _pci_writable() -> bool:
|
|
|
189
189
|
return False
|
|
190
190
|
|
|
191
191
|
|
|
192
|
+
def _ryzen_smu_writable() -> bool:
|
|
193
|
+
if not (os.path.isdir(DRIVER_PATH) and module_version_ok() and os.path.exists(SMN_PATH)):
|
|
194
|
+
return False
|
|
195
|
+
try:
|
|
196
|
+
fd = os.open(SMN_PATH, os.O_RDWR)
|
|
197
|
+
os.close(fd)
|
|
198
|
+
return True
|
|
199
|
+
except OSError:
|
|
200
|
+
return False
|
|
201
|
+
|
|
202
|
+
|
|
192
203
|
def init() -> str:
|
|
193
204
|
global _backend
|
|
194
205
|
|
|
@@ -219,6 +230,10 @@ def init() -> str:
|
|
|
219
230
|
_backend = "pci"
|
|
220
231
|
return _backend
|
|
221
232
|
|
|
233
|
+
if _ryzen_smu_writable():
|
|
234
|
+
_backend = "ryzen_smu"
|
|
235
|
+
return _backend
|
|
236
|
+
|
|
222
237
|
if os.path.exists(PCI_CONFIG):
|
|
223
238
|
raise BackendUnavailable(
|
|
224
239
|
"Secure Boot is off, so ZenMaster uses PCI direct access, but the PCI "
|
|
@@ -260,7 +275,7 @@ def _pci_read(fd: int, addr: int) -> int:
|
|
|
260
275
|
|
|
261
276
|
def _pci_write(fd: int, addr: int, value: int) -> None:
|
|
262
277
|
os.lseek(fd, NB_ADDR, os.SEEK_SET)
|
|
263
|
-
os.write(fd, struct.pack("<I", addr))
|
|
278
|
+
os.write(fd, struct.pack("<I", addr & ~3))
|
|
264
279
|
os.lseek(fd, NB_DATA, os.SEEK_SET)
|
|
265
280
|
os.write(fd, struct.pack("<I", value))
|
|
266
281
|
|
|
@@ -271,17 +286,7 @@ def _send_seq(write: Any, read: Any, fd: int, msg: int, rsp: int, args: int, op:
|
|
|
271
286
|
for i in range(1, NARGS):
|
|
272
287
|
write(fd, args + i * 4, 0)
|
|
273
288
|
write(fd, msg, op)
|
|
274
|
-
|
|
275
|
-
r = read(fd, rsp)
|
|
276
|
-
if r:
|
|
277
|
-
return r
|
|
278
|
-
deadline = time.monotonic() + _DEADLINE
|
|
279
|
-
while time.monotonic() < deadline:
|
|
280
|
-
time.sleep(_SLEEP_S)
|
|
281
|
-
r = read(fd, rsp)
|
|
282
|
-
if r:
|
|
283
|
-
return r
|
|
284
|
-
return SMU_FAILED
|
|
289
|
+
return poll_response(lambda a: read(fd, a), rsp, _POLL_N, _SLEEP_S, _DEADLINE) or SMU_FAILED
|
|
285
290
|
|
|
286
291
|
|
|
287
292
|
def _require_init() -> None:
|
|
@@ -413,6 +418,8 @@ def _read_devmem(phys: int, size: int) -> bytes | None:
|
|
|
413
418
|
|
|
414
419
|
def _read_pm_table_pci(family: str) -> tuple[bytes, int] | None:
|
|
415
420
|
global _cached_pm_ver
|
|
421
|
+
if _backend is None:
|
|
422
|
+
return None
|
|
416
423
|
cmds = PM_TABLE_CMDS.get(family)
|
|
417
424
|
if cmds is None:
|
|
418
425
|
return None
|
|
@@ -441,12 +448,14 @@ def _read_pm_table_pci(family: str) -> tuple[bytes, int] | None:
|
|
|
441
448
|
|
|
442
449
|
|
|
443
450
|
def get_smu_version(family: str = "") -> int:
|
|
444
|
-
if _backend
|
|
451
|
+
if _backend in ("ryzen_smu", None):
|
|
445
452
|
try:
|
|
446
453
|
with open(DRIVER_PATH + "/version", "r") as f:
|
|
447
454
|
return int(f.read().strip(), 16) & 0xFFFFFFFF
|
|
448
455
|
except (OSError, ValueError):
|
|
449
456
|
pass
|
|
457
|
+
if _backend is None:
|
|
458
|
+
return 0
|
|
450
459
|
status, out = query_mp1(family, 0x02, 1)
|
|
451
460
|
return (out[0] & 0xFFFFFFFF) if status == SMU_OK and out[0] else 0
|
|
452
461
|
|
|
@@ -488,7 +497,7 @@ def read_pm_table_version(family: str = "") -> int:
|
|
|
488
497
|
except OSError:
|
|
489
498
|
pass
|
|
490
499
|
|
|
491
|
-
if family in PM_TABLE_CMDS:
|
|
500
|
+
if _backend is not None and family in PM_TABLE_CMDS:
|
|
492
501
|
ver_op = PM_TABLE_CMDS[family][0]
|
|
493
502
|
status, out = query_rsmu(family, ver_op, 0)
|
|
494
503
|
if status == SMU_OK and out[0]:
|
|
@@ -12,7 +12,7 @@ from zenmaster.errors import BackendUnavailable, SMUNotInitialized
|
|
|
12
12
|
from zenmaster.pmtable import PM_TABLE_CMDS, TABLE_SIZES, DEFAULT_TABLE_SIZE
|
|
13
13
|
from zenmaster.mailbox import (
|
|
14
14
|
MP1, MP1_DEFAULT, RSMU, RSMU_DEFAULT, HSMP, HSMP_DEFAULT,
|
|
15
|
-
mailbox_send, mailbox_query, transfer_with_retry,
|
|
15
|
+
DEFAULT_TIMEOUT, mailbox_send, mailbox_query, transfer_with_retry,
|
|
16
16
|
)
|
|
17
17
|
from zenmaster.smu import SMU_OK, ModuleStatus
|
|
18
18
|
|
|
@@ -25,9 +25,9 @@ NB_DATA = 0xBC
|
|
|
25
25
|
PCI_ADDR = 0xCF8
|
|
26
26
|
PCI_DATA = 0xCFC
|
|
27
27
|
|
|
28
|
-
_POLL_N = 100
|
|
29
28
|
_FAST_POLL = 64
|
|
30
29
|
_POLL_SLEEP = 0.0005
|
|
30
|
+
_TIMEOUT = DEFAULT_TIMEOUT
|
|
31
31
|
_lock = threading.Lock()
|
|
32
32
|
_backend: str | None = None
|
|
33
33
|
_force: str | None = None
|
|
@@ -112,13 +112,17 @@ def module_version_ok() -> bool:
|
|
|
112
112
|
|
|
113
113
|
|
|
114
114
|
def module_status() -> ModuleStatus:
|
|
115
|
-
if
|
|
115
|
+
if _backend == "iopci":
|
|
116
|
+
return ModuleStatus(True, "loaded", "", None)
|
|
117
|
+
if not directhw.is_loaded():
|
|
118
|
+
if _debug_boot_arg_ok() and iopci.is_available():
|
|
119
|
+
return ModuleStatus(True, "loaded", "", None)
|
|
116
120
|
return ModuleStatus(False, "unknown", "", "not_loaded")
|
|
117
121
|
return ModuleStatus(True, "loaded", "", None)
|
|
118
122
|
|
|
119
123
|
|
|
120
124
|
def is_available() -> bool:
|
|
121
|
-
return directhw.is_loaded() or iopci.is_available()
|
|
125
|
+
return directhw.is_loaded() or (_debug_boot_arg_ok() and iopci.is_available())
|
|
122
126
|
|
|
123
127
|
|
|
124
128
|
def init() -> str:
|
|
@@ -200,12 +204,12 @@ def _smn_write(addr: int, value: int) -> None:
|
|
|
200
204
|
|
|
201
205
|
def _mailbox_send(msg: int, rsp: int, args_addr: int, op: int, arg0: int) -> int:
|
|
202
206
|
return mailbox_send(_smn_write, _smn_read, msg, rsp, args_addr, op, arg0,
|
|
203
|
-
|
|
207
|
+
_FAST_POLL, _POLL_SLEEP, _TIMEOUT)
|
|
204
208
|
|
|
205
209
|
|
|
206
210
|
def _mailbox_query(msg: int, rsp: int, args_base: int, op: int, arg0: int = 0) -> tuple[int, list[int]]:
|
|
207
211
|
return mailbox_query(_smn_write, _smn_read, msg, rsp, args_base, op, arg0,
|
|
208
|
-
|
|
212
|
+
_FAST_POLL, _POLL_SLEEP, _TIMEOUT)
|
|
209
213
|
|
|
210
214
|
|
|
211
215
|
def _require_init() -> None:
|
|
@@ -276,6 +280,8 @@ def smu_command(msg_id: int, arg: int = 0) -> int:
|
|
|
276
280
|
|
|
277
281
|
|
|
278
282
|
def get_smu_version(family: str = "") -> int:
|
|
283
|
+
if _backend is None:
|
|
284
|
+
return 0
|
|
279
285
|
status, out = query_mp1(family, 0x02, 1)
|
|
280
286
|
return (out[0] & 0xFFFFFFFF) if status == SMU_OK and out[0] else 0
|
|
281
287
|
|
|
@@ -329,6 +335,8 @@ def read_pm_table_full(family: str = "") -> tuple[bytes, int] | None:
|
|
|
329
335
|
|
|
330
336
|
def read_pm_table_version(family: str = "") -> int:
|
|
331
337
|
global _cached_pm_ver
|
|
338
|
+
if _backend in (None, "iopci"):
|
|
339
|
+
return 0
|
|
332
340
|
if _cached_pm_ver:
|
|
333
341
|
return _cached_pm_ver
|
|
334
342
|
|
|
@@ -354,8 +362,9 @@ def read_pm_table(family: str = "") -> bytes | None:
|
|
|
354
362
|
|
|
355
363
|
|
|
356
364
|
def close() -> None:
|
|
357
|
-
global _backend, _cached_pm_ver
|
|
365
|
+
global _backend, _cached_pm_ver, DRIVER_NAME
|
|
358
366
|
directhw.close()
|
|
359
367
|
iopci.close()
|
|
368
|
+
DRIVER_NAME = "DirectHW"
|
|
360
369
|
_backend = None
|
|
361
370
|
_cached_pm_ver = None
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
import time
|
|
3
|
+
from typing import Any
|
|
3
4
|
|
|
4
5
|
from zenmaster.smu import SMU_FAILED, SMU_REJECTED_PREREQ
|
|
5
6
|
|
|
6
7
|
NARGS = 6
|
|
8
|
+
DEFAULT_TIMEOUT: float = 5.0
|
|
7
9
|
|
|
8
10
|
MP1: dict[str, tuple[int, int, int]] = {
|
|
9
11
|
"SummitRidge": (0x3B10528, 0x3B10564, 0x3B10598),
|
|
@@ -49,35 +51,42 @@ HSMP: dict[str, tuple[int, int, int]] = {
|
|
|
49
51
|
HSMP_DEFAULT = (0x3B10A8C, 0x3B10A90, 0x3B10A94)
|
|
50
52
|
|
|
51
53
|
|
|
52
|
-
def poll_response(smn_read, rsp: int,
|
|
53
|
-
|
|
54
|
+
def poll_response(smn_read: Any, rsp: int, fast_poll: int = 64, poll_sleep: float = 0.0005,
|
|
55
|
+
timeout: float = DEFAULT_TIMEOUT) -> int:
|
|
56
|
+
for _ in range(fast_poll):
|
|
57
|
+
r = smn_read(rsp)
|
|
58
|
+
if r:
|
|
59
|
+
return r
|
|
60
|
+
deadline = time.monotonic() + timeout
|
|
61
|
+
while time.monotonic() < deadline:
|
|
62
|
+
time.sleep(poll_sleep)
|
|
54
63
|
r = smn_read(rsp)
|
|
55
64
|
if r:
|
|
56
65
|
return r
|
|
57
|
-
if i >= fast_poll:
|
|
58
|
-
time.sleep(poll_sleep)
|
|
59
66
|
return 0
|
|
60
67
|
|
|
61
68
|
|
|
62
|
-
def mailbox_send(smn_write, smn_read, msg: int, rsp: int, args_addr: int, op: int, arg0: int,
|
|
63
|
-
|
|
69
|
+
def mailbox_send(smn_write: Any, smn_read: Any, msg: int, rsp: int, args_addr: int, op: int, arg0: int,
|
|
70
|
+
fast_poll: int = 64, poll_sleep: float = 0.0005,
|
|
71
|
+
timeout: float = DEFAULT_TIMEOUT) -> int:
|
|
64
72
|
smn_write(rsp, 0)
|
|
65
73
|
smn_write(args_addr, arg0)
|
|
66
74
|
for i in range(1, NARGS):
|
|
67
75
|
smn_write(args_addr + i * 4, 0)
|
|
68
76
|
smn_write(msg, op)
|
|
69
|
-
return poll_response(smn_read, rsp,
|
|
77
|
+
return poll_response(smn_read, rsp, fast_poll, poll_sleep, timeout) or SMU_FAILED
|
|
70
78
|
|
|
71
79
|
|
|
72
|
-
def mailbox_query(smn_write, smn_read, msg: int, rsp: int, args_base: int, op: int, arg0: int,
|
|
73
|
-
|
|
80
|
+
def mailbox_query(smn_write: Any, smn_read: Any, msg: int, rsp: int, args_base: int, op: int, arg0: int,
|
|
81
|
+
fast_poll: int = 64, poll_sleep: float = 0.0005,
|
|
82
|
+
timeout: float = DEFAULT_TIMEOUT) -> tuple[int, list[int]]:
|
|
74
83
|
smn_write(rsp, 0)
|
|
75
84
|
for i in range(NARGS):
|
|
76
85
|
smn_write(args_base + i * 4, 0)
|
|
77
86
|
if arg0:
|
|
78
87
|
smn_write(args_base, arg0)
|
|
79
88
|
smn_write(msg, op)
|
|
80
|
-
r = poll_response(smn_read, rsp,
|
|
89
|
+
r = poll_response(smn_read, rsp, fast_poll, poll_sleep, timeout)
|
|
81
90
|
if r:
|
|
82
91
|
return r, [smn_read(args_base + i * 4) for i in range(NARGS)]
|
|
83
92
|
return SMU_FAILED, [0] * NARGS
|
|
@@ -58,10 +58,8 @@ def _backend() -> Any:
|
|
|
58
58
|
|
|
59
59
|
def smu_command(msg_id: int, arg: int = 0) -> int:
|
|
60
60
|
b = _backend() if callable(_backend) else _backend
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return fn(msg_id, arg)
|
|
64
|
-
ensure_backend()
|
|
61
|
+
if getattr(b, "active_backend", None) is not None and not ensure_backend():
|
|
62
|
+
return SMU_FAILED
|
|
65
63
|
b = _backend() if callable(_backend) else _backend
|
|
66
64
|
fn = getattr(b, "smu_command", None)
|
|
67
65
|
if fn is not None:
|
|
@@ -194,7 +192,9 @@ def send_arg(family: str, name: str, value: int) -> list[tuple[str, int, int]]:
|
|
|
194
192
|
from zenmaster.errors import UnsupportedCPU
|
|
195
193
|
if not runner.is_supported(family):
|
|
196
194
|
raise UnsupportedCPU(f"'{family}' is not a supported CPU family")
|
|
197
|
-
|
|
195
|
+
b = _backend() if callable(_backend) else _backend
|
|
196
|
+
if getattr(b, "active_backend", None) is not None and active_backend() is None:
|
|
197
|
+
init()
|
|
198
198
|
out: list[tuple[str, int, int]] = []
|
|
199
199
|
use_hsmp = runner.is_hsmp(family)
|
|
200
200
|
for is_mp1, op in runner.lookup(family, name):
|
|
@@ -228,25 +228,26 @@ def unavailable_reason() -> str | None:
|
|
|
228
228
|
|
|
229
229
|
|
|
230
230
|
def get_bios_if_ver(family: str) -> int:
|
|
231
|
-
ensure_backend()
|
|
231
|
+
if not ensure_backend():
|
|
232
|
+
return 0
|
|
232
233
|
status, out = query_mp1(family, 0x03, 0)
|
|
233
234
|
return out[0] if status == SMU_OK else 0
|
|
234
235
|
|
|
235
236
|
|
|
236
237
|
def get_smu_version(family: str) -> int:
|
|
237
|
-
ensure_backend()
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
238
|
+
if ensure_backend():
|
|
239
|
+
b = _backend()
|
|
240
|
+
fn = getattr(b, "get_smu_version", None)
|
|
241
|
+
if fn is not None:
|
|
242
|
+
try:
|
|
243
|
+
ver = fn(family)
|
|
244
|
+
if ver:
|
|
245
|
+
return ver
|
|
246
|
+
except Exception:
|
|
247
|
+
pass
|
|
248
|
+
status, out = query_mp1(family, 0x02, 1)
|
|
249
|
+
if status == SMU_OK and out[0]:
|
|
250
|
+
return out[0]
|
|
250
251
|
if platform.system() == "Linux":
|
|
251
252
|
for path in ("/sys/kernel/ryzen_smu_drv/version", "/sys/kernel/ryzen_smu_drv/drv_version"):
|
|
252
253
|
try:
|
|
@@ -11,7 +11,7 @@ from zenmaster.errors import BackendUnavailable, SMUNotInitialized
|
|
|
11
11
|
from zenmaster.pmtable import PM_TABLE_CMDS, TABLE_SIZES, DEFAULT_TABLE_SIZE
|
|
12
12
|
from zenmaster.mailbox import (
|
|
13
13
|
MP1, MP1_DEFAULT, RSMU, RSMU_DEFAULT, HSMP, HSMP_DEFAULT,
|
|
14
|
-
mailbox_send, mailbox_query, transfer_with_retry,
|
|
14
|
+
DEFAULT_TIMEOUT, mailbox_send, mailbox_query, transfer_with_retry,
|
|
15
15
|
)
|
|
16
16
|
from zenmaster.smu import SMU_OK, ModuleStatus
|
|
17
17
|
|
|
@@ -24,9 +24,9 @@ _DEVICE_PATHS = [
|
|
|
24
24
|
]
|
|
25
25
|
_IOCTL_LOAD = 0xA1B22084
|
|
26
26
|
_IOCTL_EXEC = 0xA1B22104
|
|
27
|
-
_POLL_N = 8192
|
|
28
27
|
_FAST_POLL = 64
|
|
29
28
|
_POLL_SLEEP = 0.0005
|
|
29
|
+
_TIMEOUT = DEFAULT_TIMEOUT
|
|
30
30
|
_lock = threading.Lock()
|
|
31
31
|
_handle = None
|
|
32
32
|
_k32 = None
|
|
@@ -56,6 +56,8 @@ def _query_pawnio_info() -> str | None:
|
|
|
56
56
|
return winreg.QueryValueEx(key, "DisplayVersion")[0]
|
|
57
57
|
except OSError:
|
|
58
58
|
return ""
|
|
59
|
+
finally:
|
|
60
|
+
winreg.CloseKey(key)
|
|
59
61
|
except OSError:
|
|
60
62
|
return None
|
|
61
63
|
|
|
@@ -81,7 +83,7 @@ def module_status() -> ModuleStatus:
|
|
|
81
83
|
|
|
82
84
|
|
|
83
85
|
def is_available() -> bool:
|
|
84
|
-
return _pawnio_info() is not None
|
|
86
|
+
return _handle is not None or _pawnio_info() is not None
|
|
85
87
|
|
|
86
88
|
|
|
87
89
|
def acquire_pci_mutex(timeout_ms: int = _PCI_MUTEX_TIMEOUT_MS) -> Any:
|
|
@@ -186,16 +188,18 @@ def init() -> str:
|
|
|
186
188
|
raise BackendUnavailable(f"PawnIO module not found: {module_path}")
|
|
187
189
|
|
|
188
190
|
ver = _pawnio_info()
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
"After installation, reboot and try again."
|
|
194
|
-
)
|
|
195
|
-
|
|
196
|
-
k32 = _make_k32()
|
|
191
|
+
try:
|
|
192
|
+
k32 = _make_k32()
|
|
193
|
+
except AttributeError as e:
|
|
194
|
+
raise BackendUnavailable("PawnIO driver is only supported on Windows.") from e
|
|
197
195
|
handle = _open_device(k32)
|
|
198
196
|
if handle is None:
|
|
197
|
+
if ver is None:
|
|
198
|
+
raise BackendUnavailable(
|
|
199
|
+
"PawnIO driver is not installed.\n"
|
|
200
|
+
f"Download and run the installer: {_PAWNIO_INSTALLER_URL}\n"
|
|
201
|
+
"After installation, reboot and try again."
|
|
202
|
+
)
|
|
199
203
|
raise BackendUnavailable(
|
|
200
204
|
"PawnIO device not found. The driver may need a reboot to activate.\n"
|
|
201
205
|
f"If not installed: {_PAWNIO_INSTALLER_URL}"
|
|
@@ -301,12 +305,12 @@ def _smn_write(addr: int, value: int) -> None:
|
|
|
301
305
|
|
|
302
306
|
def _mailbox_send(msg: int, rsp: int, args_addr: int, op: int, arg0: int) -> int:
|
|
303
307
|
return mailbox_send(_smn_write, _smn_read, msg, rsp, args_addr, op, arg0,
|
|
304
|
-
|
|
308
|
+
_FAST_POLL, _POLL_SLEEP, _TIMEOUT)
|
|
305
309
|
|
|
306
310
|
|
|
307
311
|
def _mailbox_query(msg: int, rsp: int, args_base: int, op: int, arg0: int = 0) -> tuple[int, list[int]]:
|
|
308
312
|
return mailbox_query(_smn_write, _smn_read, msg, rsp, args_base, op, arg0,
|
|
309
|
-
|
|
313
|
+
_FAST_POLL, _POLL_SLEEP, _TIMEOUT)
|
|
310
314
|
|
|
311
315
|
|
|
312
316
|
def _resolve_pm_table() -> tuple[int, int] | None:
|
|
@@ -426,7 +430,8 @@ def smu_command(msg_id: int, arg: int = 0) -> int:
|
|
|
426
430
|
|
|
427
431
|
|
|
428
432
|
def get_smu_version(family: str = "") -> int:
|
|
429
|
-
|
|
433
|
+
if _handle is None or _k32 is None:
|
|
434
|
+
return 0
|
|
430
435
|
with _lock:
|
|
431
436
|
with pci_mutex_guard():
|
|
432
437
|
out = _execute("ioctl_get_smu_version", [], 1)
|
|
@@ -445,29 +450,46 @@ def pm_table_supported(family: str = "") -> bool:
|
|
|
445
450
|
return family in PM_TABLE_CMDS
|
|
446
451
|
|
|
447
452
|
|
|
453
|
+
def _cache_pm_ver(ver: int) -> int:
|
|
454
|
+
global _cached_pm_ver, _cached_pm_size
|
|
455
|
+
_cached_pm_ver = ver & 0xFFFFFFFF
|
|
456
|
+
_cached_pm_size = TABLE_SIZES.get(_cached_pm_ver, DEFAULT_TABLE_SIZE)
|
|
457
|
+
return _cached_pm_ver
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
def _read_pm_ver_rsmu(family: str = "") -> int:
|
|
461
|
+
if _handle is None or _k32 is None or family not in PM_TABLE_CMDS:
|
|
462
|
+
return 0
|
|
463
|
+
ver_op = PM_TABLE_CMDS[family][0]
|
|
464
|
+
msg, rsp, args_base = RSMU.get(family, RSMU_DEFAULT)
|
|
465
|
+
with _lock:
|
|
466
|
+
with pci_mutex_guard():
|
|
467
|
+
status, out = _mailbox_query(msg, rsp, args_base, ver_op)
|
|
468
|
+
return (out[0] & 0xFFFFFFFF) if status == SMU_OK and out[0] else 0
|
|
469
|
+
|
|
470
|
+
|
|
448
471
|
def read_pm_table_full(family: str = "") -> tuple[bytes, int] | None:
|
|
449
|
-
|
|
450
|
-
if not _handle:
|
|
472
|
+
if _handle is None or _k32 is None:
|
|
451
473
|
return None
|
|
452
474
|
|
|
453
475
|
global _cached_pm_ver, _cached_pm_size
|
|
454
476
|
|
|
455
477
|
if _cached_pm_ver is None:
|
|
456
478
|
resolved = _resolve_pm_table()
|
|
457
|
-
if resolved is not None:
|
|
458
|
-
|
|
459
|
-
_cached_pm_size = TABLE_SIZES.get(_cached_pm_ver, DEFAULT_TABLE_SIZE)
|
|
479
|
+
if resolved is not None and resolved[0]:
|
|
480
|
+
_cache_pm_ver(resolved[0])
|
|
460
481
|
elif family in PM_TABLE_CMDS:
|
|
461
|
-
ver =
|
|
482
|
+
ver = _read_pm_ver_rsmu(family)
|
|
462
483
|
if ver:
|
|
463
|
-
|
|
464
|
-
_cached_pm_size = TABLE_SIZES.get(_cached_pm_ver, DEFAULT_TABLE_SIZE)
|
|
484
|
+
_cache_pm_ver(ver)
|
|
465
485
|
|
|
466
486
|
if _cached_pm_ver is None or not _cached_pm_ver:
|
|
467
487
|
return None
|
|
468
488
|
|
|
469
489
|
ver = _cached_pm_ver & 0xFFFFFFFF
|
|
470
|
-
|
|
490
|
+
if _cached_pm_size is None:
|
|
491
|
+
_cached_pm_size = TABLE_SIZES.get(ver, DEFAULT_TABLE_SIZE)
|
|
492
|
+
size = _cached_pm_size
|
|
471
493
|
|
|
472
494
|
_update_pm_table(family)
|
|
473
495
|
|
|
@@ -477,10 +499,8 @@ def read_pm_table_full(family: str = "") -> tuple[bytes, int] | None:
|
|
|
477
499
|
|
|
478
500
|
if not raw:
|
|
479
501
|
resolved = _resolve_pm_table()
|
|
480
|
-
if resolved is not None:
|
|
481
|
-
|
|
482
|
-
_cached_pm_size = TABLE_SIZES.get(_cached_pm_ver, DEFAULT_TABLE_SIZE)
|
|
483
|
-
ver = _cached_pm_ver
|
|
502
|
+
if resolved is not None and resolved[0]:
|
|
503
|
+
ver = _cache_pm_ver(resolved[0])
|
|
484
504
|
size = _cached_pm_size or DEFAULT_TABLE_SIZE
|
|
485
505
|
n = min((size + 7) // 8, 512)
|
|
486
506
|
_update_pm_table(family)
|
|
@@ -497,23 +517,16 @@ def read_pm_table_full(family: str = "") -> tuple[bytes, int] | None:
|
|
|
497
517
|
|
|
498
518
|
|
|
499
519
|
def read_pm_table_version(family: str = "") -> int:
|
|
500
|
-
global _cached_pm_ver
|
|
501
520
|
if _cached_pm_ver:
|
|
502
521
|
return _cached_pm_ver
|
|
503
|
-
if _handle:
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
with _lock:
|
|
512
|
-
with pci_mutex_guard():
|
|
513
|
-
status, out = _mailbox_query(msg, rsp, args_base, ver_op)
|
|
514
|
-
if status == SMU_OK and out[0]:
|
|
515
|
-
_cached_pm_ver = out[0] & 0xFFFFFFFF
|
|
516
|
-
return _cached_pm_ver
|
|
522
|
+
if _handle is None or _k32 is None:
|
|
523
|
+
return 0
|
|
524
|
+
resolved = _resolve_pm_table()
|
|
525
|
+
if resolved and resolved[0]:
|
|
526
|
+
return _cache_pm_ver(resolved[0])
|
|
527
|
+
ver = _read_pm_ver_rsmu(family)
|
|
528
|
+
if ver:
|
|
529
|
+
return _cache_pm_ver(ver)
|
|
517
530
|
return 0
|
|
518
531
|
|
|
519
532
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: zenmaster
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.2
|
|
4
4
|
Summary: Adjust power management settings for Ryzen CPUs on Linux, Windows, and macOS
|
|
5
5
|
Author-email: oxGorou <lekhanhbinh2901@gmail.com>
|
|
6
6
|
License-Expression: GPL-3.0-only
|
|
@@ -193,7 +193,7 @@ print(f"SMN 0x0005A380 = 0x{value:08X}")
|
|
|
193
193
|
|
|
194
194
|
## Technical Comparison: ZenMaster vs. RyzenAdj
|
|
195
195
|
|
|
196
|
-
| Feature | RyzenAdj | ZenMaster v1.2.
|
|
196
|
+
| Feature | RyzenAdj | ZenMaster v1.2.2 |
|
|
197
197
|
|---|---|---|
|
|
198
198
|
| **Installation** | Compilation from source (`cmake`, `make`, `libpci-dev`) | `pip install zenmaster` (pure Python package) |
|
|
199
199
|
| **Supported Families** | ~15 APU and desktop families | 44 families (Zen 1 to Zen 5/6, Desktop, Mobile, Threadripper, Server EPYC via HSMP) |
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|