|
| 1 | +"""Guest-VF (virtualized amdgpu) Pydantic models for amd-smi data. |
| 2 | +
|
| 3 | +A guest VM sees a single amdgpu virtual function (VF). Its amd-smi build shares |
| 4 | +the bare-metal amdgpu JSON schema EXCEPT that a VF does not expose physical / |
| 5 | +host-owned fields: fan control, SoC power state, power/thermal limits, NUMA |
| 6 | +topology, XGMI power-down policy, and energy/throttle/voltage-curve/perf-level |
| 7 | +counters. The bare-metal ``AmdSmi*`` models mark those fields as required, so a |
| 8 | +guest payload fails to build against them; these subclasses relax exactly those |
| 9 | +fields to optional and inherit all other structure unchanged. |
| 10 | +
|
| 11 | +amd-smi was not exercised on the guest before the host/guest driver-flavor work, |
| 12 | +so the base ``AmdSmi*`` models had implicitly assumed bare-metal amdgpu. |
| 13 | +""" |
| 14 | + |
| 15 | +from __future__ import annotations |
| 16 | + |
| 17 | +from typing import Optional, Union |
| 18 | + |
| 19 | +from pydantic import ConfigDict |
| 20 | + |
| 21 | +from nodescraper.plugins.inband.amdsmi.amdsmidata import ( |
| 22 | + AmdSmiMetric, |
| 23 | + AmdSmiStatic, |
| 24 | + MetricEnergy, |
| 25 | + MetricFan, |
| 26 | + MetricMemUsage, |
| 27 | + MetricThrottle, |
| 28 | + MetricVoltageCurve, |
| 29 | + StaticBus, |
| 30 | + StaticLimit, |
| 31 | + StaticNuma, |
| 32 | + StaticSocPstate, |
| 33 | + StaticVbios, |
| 34 | + StaticXgmiPlpd, |
| 35 | +) |
| 36 | + |
| 37 | + |
| 38 | +class GuestStaticBus(StaticBus): |
| 39 | + """Guest amd-smi (ROCm 7.14+) adds a per-link ``pcie_levels`` block to the bus |
| 40 | + section that the base ``StaticBus`` (``extra="forbid"``) rejects. Ignore unknown |
| 41 | + bus fields so a new field doesn't drop the whole static payload, matching the |
| 42 | + host models' schema-drift resilience.""" |
| 43 | + |
| 44 | + model_config = ConfigDict(extra="ignore") |
| 45 | + |
| 46 | + |
| 47 | +class GuestAmdSmiStatic(AmdSmiStatic): |
| 48 | + """Bare-metal static schema minus the physical fields a guest VF omits.""" |
| 49 | + |
| 50 | + # Base bus (StaticBus) forbids extras; the guest build adds pcie_levels. |
| 51 | + bus: GuestStaticBus # type: ignore[assignment] |
| 52 | + soc_pstate: Optional[StaticSocPstate] = None |
| 53 | + xgmi_plpd: Optional[StaticXgmiPlpd] = None |
| 54 | + numa: Optional[StaticNuma] = None # type: ignore[assignment] |
| 55 | + limit: Optional[StaticLimit] = None |
| 56 | + # A guest VF's static payload carries an ``ifwi`` firmware block (name, |
| 57 | + # build_date, part_number, version) that the bare-metal schema omits; its |
| 58 | + # shape matches StaticVbios. |
| 59 | + ifwi: Optional[StaticVbios] = None |
| 60 | + |
| 61 | + |
| 62 | +class GuestAmdSmiMetric(AmdSmiMetric): |
| 63 | + """Bare-metal metric schema minus the physical fields a guest VF omits.""" |
| 64 | + |
| 65 | + # These physical fields are required on the bare-metal base model; a guest VF |
| 66 | + # omits them, so relax to Optional (intentional LSP-widening override). |
| 67 | + fan: Optional[MetricFan] = None # type: ignore[assignment] |
| 68 | + voltage_curve: Optional[MetricVoltageCurve] = None |
| 69 | + perf_level: Optional[Union[str, dict]] = None |
| 70 | + xgmi_err: Optional[Union[str, dict]] = None |
| 71 | + energy: Optional[MetricEnergy] = None |
| 72 | + throttle: Optional[MetricThrottle] = None # type: ignore[assignment] |
| 73 | + mem_usage: Optional[MetricMemUsage] = None # type: ignore[assignment] |
0 commit comments