Skip to content

Commit a8437e4

Browse files
committed
added clock and fixed try for API that doesnt exist in this version
1 parent 08ed3f0 commit a8437e4

File tree

2 files changed

+78
-10
lines changed

2 files changed

+78
-10
lines changed

nodescraper/plugins/inband/amdsmi/amdsmi_collector.py

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@
4949
StaticBoard,
5050
StaticBus,
5151
StaticCacheInfoItem,
52+
StaticClockData,
5253
StaticDriver,
54+
StaticFrequencyLevels,
5355
StaticNuma,
5456
StaticPolicy,
5557
StaticSocPstate,
@@ -111,7 +113,7 @@ def _get_amdsmi_data(self) -> AmdSmiDataModel | None:
111113
try:
112114
version = self._get_amdsmi_version()
113115
processes = self.get_process()
114-
partition = self.get_partition()
116+
partition = self._get_partition()
115117
firmware = self.get_firmware()
116118
gpu_list = self.get_gpu_list()
117119
statics = self.get_static()
@@ -296,7 +298,7 @@ def get_process(self) -> list[Processes] | None:
296298
)
297299
return out
298300

299-
def get_partition(self) -> Partition | None:
301+
def _get_partition(self) -> Partition | None:
300302
devices = self._get_handles()
301303
current: list[PartitionCurrent] = []
302304
memparts: list[PartitionMemory] = []
@@ -608,6 +610,7 @@ def _vu(val: object, unit: str) -> ValueUnit | None:
608610
soc_pstate_model = self._get_soc_pstate(h)
609611
xgmi_plpd_model = self._get_xgmi_plpd(h)
610612
cache_info_model = self._get_cache_info(h)
613+
clock_model = self._get_clock(h)
611614

612615
try:
613616
out.append(
@@ -626,10 +629,11 @@ def _vu(val: object, unit: str) -> ValueUnit | None:
626629
vram=vram_model,
627630
cache_info=cache_info_model,
628631
partition=None,
629-
clock=None, # TODO amdsmi_get_clk_freq??
632+
clock=clock_model,
630633
)
631634
)
632635
except ValidationError as e:
636+
self.logger.error(e)
633637
self._log_event(
634638
category=EventCategory.APPLICATION,
635639
description="Failed to build AmdSmiStatic",
@@ -640,7 +644,16 @@ def _vu(val: object, unit: str) -> ValueUnit | None:
640644
return out
641645

642646
def _get_soc_pstate(self, h) -> StaticSocPstate | None:
643-
data = self._smi_try(self._amdsmi.amdsmi_get_soc_pstate, h, default=None)
647+
fn = getattr(self._amdsmi, "amdsmi_get_soc_pstate", None)
648+
if not callable(fn):
649+
self._log_event(
650+
category=EventCategory.APPLICATION,
651+
description="amdsmi_get_soc_pstate not exposed by amdsmi build",
652+
priority=EventPriority.INFO,
653+
)
654+
return None
655+
656+
data = self._smi_try(fn, h, default=None)
644657
if not isinstance(data, dict):
645658
return None
646659

@@ -684,7 +697,16 @@ def _get_soc_pstate(self, h) -> StaticSocPstate | None:
684697
return None
685698

686699
def _get_xgmi_plpd(self, h) -> StaticXgmiPlpd | None:
687-
data = self._smi_try(self._amdsmi.amdsmi_get_xgmi_plpd, h, default=None)
700+
fn = getattr(self._amdsmi, "amdsmi_get_xgmi_plpd", None)
701+
if not callable(fn):
702+
self._log_event(
703+
category=EventCategory.APPLICATION,
704+
description="XGMI PLPD not exposed by this amdsmi build",
705+
priority=EventPriority.INFO,
706+
)
707+
return None
708+
709+
data = self._smi_try(fn, h, default=None)
688710
if not isinstance(data, dict):
689711
return None
690712

@@ -802,6 +824,52 @@ def _as_list_str(v) -> list[str]:
802824

803825
return out
804826

827+
828+
def _get_clock(self, h) -> StaticClockData | None:
829+
"""
830+
"""
831+
fn = getattr(self._amdsmi, "amdsmi_get_clk_freq", None)
832+
clk_type = getattr(self._amdsmi, "AmdSmiClkType", None)
833+
if not callable(fn) or clk_type is None or not hasattr(clk_type, "SYS"):
834+
return None
835+
836+
data = self._smi_try(fn, h, clk_type.SYS, default=None)
837+
if not isinstance(data, dict):
838+
return None
839+
840+
freqs_raw = data.get("frequency")
841+
if not isinstance(freqs_raw, list):
842+
return None
843+
844+
freqs_mhz: list[int] = []
845+
for v in freqs_raw:
846+
if isinstance(v, (int, float)):
847+
freqs_mhz.append(int(round(float(v) / 1_000_000.0)))
848+
849+
if not freqs_mhz:
850+
return None
851+
852+
def _fmt(n: int | None) -> str | None:
853+
return None if n is None else f"{n} MHz"
854+
855+
level0: str = _fmt(freqs_mhz[0]) or "0 MHz"
856+
level1: str | None = _fmt(freqs_mhz[1]) if len(freqs_mhz) > 1 else None
857+
level2: str | None = _fmt(freqs_mhz[2]) if len(freqs_mhz) > 2 else None
858+
859+
cur_raw = data.get("current")
860+
try:
861+
current: int | None = None if cur_raw in (None, "", "N/A") else int(cur_raw)
862+
except Exception:
863+
current = None
864+
865+
try:
866+
levels = StaticFrequencyLevels(Level_0=level0, Level_1=level1, Level_2=level2)
867+
return StaticClockData(frequency=levels, current=current)
868+
except ValidationError:
869+
return None
870+
871+
872+
805873
def collect_data(
806874
self,
807875
args=None,

nodescraper/plugins/inband/amdsmi/amdsmidata.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -460,10 +460,10 @@ class StaticClockData(BaseModel):
460460
model_config = ConfigDict(
461461
populate_by_name=True,
462462
)
463-
frequency_levels: StaticFrequencyLevels
463+
frequency: StaticFrequencyLevels
464464

465-
current_level: int | None = Field(..., alias="current level")
466-
na_validator = field_validator("current_level", mode="before")(na_to_none)
465+
current: int | None = Field(..., alias="current")
466+
na_validator = field_validator("current", mode="before")(na_to_none)
467467

468468

469469
class AmdSmiStatic(BaseModel):
@@ -481,8 +481,8 @@ class AmdSmiStatic(BaseModel):
481481
numa: StaticNuma
482482
vram: StaticVram
483483
cache_info: List[StaticCacheInfoItem]
484-
partition: StaticPartition | None = None # This has been removed in Amd-smi 26.0.0+d30a0afe+
485-
clock: dict[str, StaticClockData | None] | None = None
484+
partition: StaticPartition | None = None
485+
clock: StaticClockData | None = None
486486
na_validator_dict = field_validator("clock", mode="before")(na_to_none_dict)
487487
na_validator = field_validator("soc_pstate", "xgmi_plpd", "vbios", "limit", mode="before")(
488488
na_to_none

0 commit comments

Comments
 (0)