sycl: PCIe traffic on the Monitor, as an opt-in host permission

The Monitor's PCIe graph was flat at zero on an Intel Arc: xe's sysfs exposes the link (which
xe_telemetry already reports) but no traffic counters, and the reader answered None for both
rates. Level Zero sysman does keep them -- zesDevicePciGetStats, backed by Intel PMT -- and
refuses with INSUFFICIENT_PERMISSIONS unless the caller can read
/sys/class/intel_pmt/telem*/telem, which the kernel creates 0440 root:root.

  - xe_telemetry.py: rx/tx bytes from zesDevicePciGetStats, as a rate over the counter's own
    microsecond timestamp, the same shape as the power reading. A refused or absent call stays
    None (a dash), never a zero.
  - sycl/tools/99-intel-pmt-telemetry.rules and sycl/tools/intel-pmt-perms.sh hand those nodes
    to the render group; the install lines are in the rule's header. Nothing installs them by
    itself: without them the PCIe graph dashes and every other reading is unchanged.
  - A container must carry the group in. docker already documents that as
    --group-add $(getent group render | cut -d: -f3) (docs/DOCKER.md); rootless podman needs
    --group-add=keep-groups instead, because --userns=keep-id drops supplementary groups.
    Measured on one image, uid 10001 unchanged: rc 0x70010000 without the flag, rc 0 with it.
    Capabilities do not open the gate (cap_dac_read_search, cap_sys_admin and cap_sys_rawio all
    still return 0x70010000 under a rootless user namespace).

Measured on the B70 during a 400-token reply: 5192 MB/s rx and 1364 MB/s tx peak, with
gpu_util 98.7% and power 209.6 W in the same samples; 2037 MB/s rx for a peak taken on the
host in a separate run. Idle this reads a few hundredths of a MB/s, not zero.

Tests: serve.test_server -k "telemetry or gpu" 43 passed.

Refs: #5988 (PCIe graph). Builds on the commit before this one for the rest of the readings.
This commit is contained in:
Rob Riggs committed 2026-11-14 16:09:48 -08:00
1 parent 509d1a429f
commit 578b4146f7
4 files changed
+82 -3

No files matched your search

+6 -1
View File
@@ -161,7 +161,12 @@ with Coder IQ1_M 1,024 MiB fits all 12,288 experts with 2 GB of VRAM free.
`libze_loader.so.1`, through ctypes), and load from the DRM clients the process can see in `/proc/<pid>/fdinfo` (xe counts
engine cycles per client). None of it needs root and none of it needs a helper service: `xpu-smi stats` reads the same
sysman API as a normal user. The load is the engine's own, not the card's share across other users' processes, which would
need root to read; a reading no source can give shows as a dash rather than a zero. A run config may name
need root to read; a reading no source can give shows as a dash rather than a zero. PCIe traffic is the one reading with a
precondition: sysman reports the counters only when the caller can read `/sys/class/intel_pmt/telem*/telem`, which the kernel
creates 0440 root:root. `sycl/tools/99-intel-pmt-telemetry.rules` hands those nodes to the `render` group (install lines are
in the file); a container must then carry that group in, which docker does with
`--group-add $(getent group render | cut -d: -f3)` and rootless podman needs `--group-add=keep-groups` for, because
`--userns=keep-id` drops supplementary groups. Without it the graph dashes and nothing else changes. A run config may name
a `model_switcher`; the web app's header then gets a Model menu.
- **Logprobs.** `/v1/chat/completions` takes `"logprobs": true` and `"top_logprobs": 0..20` through `server_intel.py`, streamed
or not. Not on `/v1/completions` or the Anthropic endpoint.
+40 -2
View File
@@ -11,6 +11,10 @@ helper service running outside it:
keeps one fdinfo entry per client, so a container sees the engine it runs and nothing else. The card-wide load
across other users' processes would need root; this reading says so in the Monitor instead of guessing.
- Temperature, power and the PCIe link: sysfs (hwmon and the PCI path), which everyone can read.
- PCIe traffic: sysman's PCIe counters, which Intel PMT backs with /sys/class/intel_pmt/telem*/telem. That node
ships 0440, so the reading needs a udev rule granting it to a group the caller is in (`render`), and a container
needs --group-add=keep-groups to carry that group across the user namespace. Without it sysman answers
INSUFFICIENT_PERMISSIONS and this reports None, never a zero.
A reading that no source can give is None, never a zero: the Monitor shows a dash rather than a made-up number.
"""
@@ -48,6 +52,15 @@ class _ZesMemState(ctypes.Structure): # zes_mem_state_t
("free", ctypes.c_uint64), ("size", ctypes.c_uint64)]
class _ZesSpeed(ctypes.Structure): # zes_pci_speed_t
_fields_ = [("gen", ctypes.c_int32), ("width", ctypes.c_int32), ("maxBandwidth", ctypes.c_int64)]
class _ZesPciStats(ctypes.Structure): # zes_pci_stats_t: monotonic counters, timestamp in microseconds
_fields_ = [("timestamp", ctypes.c_uint64), ("replayCounter", ctypes.c_uint64), ("packetCounter", ctypes.c_uint64),
("rxCounter", ctypes.c_uint64), ("txCounter", ctypes.c_uint64), ("speed", _ZesSpeed)]
class _Zes:
"""The card's VRAM through Level Zero's management API (sysman), matched to the card by its PCI address, so a
machine with two Intel cards reports the one this reader was asked for. Runs as the calling user."""
@@ -55,7 +68,7 @@ class _Zes:
STYPE_PCI_PROPERTIES, STYPE_MEM_STATE = 0x2, 0x1E
def __init__(self, pci):
self.lib, self.mems = None, []
self.lib, self.mems, self.dev = None, [], None
try:
self.lib = ctypes.CDLL("libze_loader.so.1")
if self.lib.zesInit(ctypes.c_uint32(0)) != 0:
@@ -78,6 +91,7 @@ class _Zes:
a = props.address
if f"{a.domain:04x}:{a.bus:02x}:{a.device:02x}.{a.function:x}" != pci:
continue
self.dev = ctypes.c_void_p(dev)
k = ctypes.c_uint32(0)
if self.lib.zesDeviceEnumMemoryModules(ctypes.c_void_p(dev), ctypes.byref(k), None) != 0:
continue
@@ -103,6 +117,23 @@ class _Zes:
total += st.size
return (total - free, total) if total else (None, None)
def pci_stats(self):
"""(rx bytes, tx bytes, timestamp us) of the card's PCIe link, or None.
The counters come from Intel PMT telemetry, which ships /sys/class/intel_pmt/telem*/telem as 0440; when that
file is group-readable by the caller (a udev rule granting it to `render`, plus --group-add=keep-groups in
the container) sysman returns them, and otherwise the call fails with INSUFFICIENT_PERMISSIONS and this
returns None, so the Monitor shows a dash instead of a flat zero."""
if self.lib is None or self.dev is None:
return None
st = _ZesPciStats()
try:
if self.lib.zesDevicePciGetStats(self.dev, ctypes.byref(st)) != 0:
return None
except (OSError, AttributeError):
return None
return st.rxCounter, st.txCounter, st.timestamp
class _XeGpu:
"""The Intel Arc readings in NVML's shape: VRAM from sysman, load from the DRM clients this process can see,
@@ -127,6 +158,7 @@ class _XeGpu:
self.zes = _Zes(self.pci)
self._cycles = {} # client id -> (busy cycles, total cycles) of the last read
self._e = None # (t, card energy uJ) for power
self._pci = None # (rx bytes, tx bytes, ts us) of the last read, for the traffic rate
def ok(self):
return self.dev is not None and sys.platform.startswith("linux")
@@ -233,5 +265,11 @@ class _XeGpu:
cap = self._rd(f"{self.hwmon}/power1_cap")
out["power_limit"] = int(cap) / 1e6 if cap and cap.isdigit() and int(cap) > 0 else None
out["pcie_gen"], out["pcie_gen_max"], out["pcie_width"] = self._link()
out["pcie_rx_mb"] = out["pcie_tx_mb"] = None # no PCIe traffic counters without the PMT permission
out["pcie_rx_mb"] = out["pcie_tx_mb"] = None
st = self.zes.pci_stats() if self.zes else None
prev, self._pci = self._pci, st
if st and prev and st[2] > prev[2] and st[0] >= prev[0] and st[1] >= prev[1]:
dt = (st[2] - prev[2]) / 1e6
out["pcie_rx_mb"] = (st[0] - prev[0]) / dt / 2**20
out["pcie_tx_mb"] = (st[1] - prev[1]) / dt / 2**20
return out
+17
View File
@@ -0,0 +1,17 @@
# Intel PMT telemetry: let the render group read /sys/class/intel_pmt/telemN/telem, which the kernel creates
# 0440 root:root. Level Zero sysman takes the card's PCIe traffic counters from those nodes, so without this
# Strata's Monitor shows a dash for PCIe traffic. Load, VRAM, temperature, power and the link need none of it.
#
# Install (root, once):
# sudo install -m 755 sycl/tools/intel-pmt-perms.sh /usr/local/sbin/
# sudo install -m 644 sycl/tools/99-intel-pmt-telemetry.rules /etc/udev/rules.d/
# sudo udevadm control --reload && sudo udevadm trigger --subsystem-match=intel_pmt
#
# The helper exists because udev cannot set the owner or mode of a sysfs attribute itself (GROUP=/MODE= are
# ignored on sysfs), and the node appears after device_add, so the write has to wait for it. Crashlog blobs
# under the same subsystem are left alone on purpose: they can contain GPU state dumps.
#
# The group must exist (`render` on Debian, Ubuntu, Fedora and Arch). Set PMT_GROUP=... in the helper if your
# system names it differently, and pass that group into a container (`--group-add=keep-groups` with rootless
# podman, `--group-add $(getent group render | cut -d: -f3)` with docker).
SUBSYSTEM=="intel_pmt", KERNEL=="telem[0-9]*", ACTION=="add|change", RUN+="/usr/local/sbin/intel-pmt-perms.sh %k"
+19
View File
@@ -0,0 +1,19 @@
#!/bin/sh
# Hand an Intel PMT telemetry blob to the render group, called from 99-intel-pmt-telemetry.rules.
#
# The kernel's pmt_class creates these attributes 0440 root:root and after device_add, so the uevent can arrive
# before the file exists: wait for it, then chgrp. Crashlog blobs under the same subsystem stay root-only.
set -eu
name="${1:-}"
[ -n "$name" ] || exit 0
file="/sys/class/intel_pmt/$name/telem"
group="${PMT_GROUP:-render}"
i=0
while [ ! -e "$file" ] && [ "$i" -lt 60 ]; do
sleep 0.05
i=$((i + 1))
done
[ -e "$file" ] || exit 0 # a blob the kernel never created is not an error
chgrp "$group" "$file" 2>/dev/null || exit 0 # no such group: leave the node as it was
chmod 0440 "$file" 2>/dev/null || true # sysfs may refuse the mode; the group is what sysman needs
exit 0