Skip to content

shim: gracefully skip optional telemetry queries when the ioctl is unsupported (#1447 follow-up)#1449

Closed
Scottcjn wants to merge 1 commit into
amd:mainfrom
Scottcjn:telemetry-graceful-degrade
Closed

shim: gracefully skip optional telemetry queries when the ioctl is unsupported (#1447 follow-up)#1449
Scottcjn wants to merge 1 commit into
amd:mainfrom
Scottcjn:telemetry-graceful-degrade

Conversation

@Scottcjn

Copy link
Copy Markdown
Contributor

Follow-up to #1447 (in-tree amdxdna ≤6.17 missing GET_ARRAY/AIE2 telemetry ioctls).

Problem. When the loaded kernel driver predates DRM_AMDXDNA_QUERY_TELEMETRY, the ioctl returns EOPNOTSUPP/EINVAL. The SHIM's telemetry query handlers call it unconditionally, so shim_err throws and the entire xrt-smi report aborts — even though basic BO/exec paths work fine on that driver.

Fix. A small helper (telemetry_handler::telemetry_query) wraps the optional telemetry ioctl: on EOPNOTSUPP/ENOTSUP/EINVAL/ENOTTY it logs a one-time warning and returns false, so the caller returns an empty result and the rest of the report continues. Any other (real) error is rethrown. Applied to all 9 optional telemetry query handlers (aie/misc/opcode/rtos/stream_buffer, incl. the aie4 overrides). Required paths are untouched.

This turns #1447 from "this ioctl is missing" into "the SHIM handles it safely on older drivers."

Testing.

  • Compiles cleanly under the repo's -Werror release build (cmake --build ... --target xrt_driver_xdna). The -Werror=maybe-uninitialized check caught that misc_telemetry's scalar result needed value-initialization on the new early-return path — fixed (result_type output{}).
  • Surgical/no-regression by construction: on a telemetry-capable driver the try succeeds and behavior is unchanged.
  • Disclosure: I could not live-reproduce the unsupported-ioctl path on my test box — the in-tree 6.17 driver had been replaced by the DKMS staging build, and the other installed in-tree modules are for different kernels (vermagic mismatch). The runtime degradation is straightforward (standard errno catch) but is best confirmed against an older in-tree driver / in CI. Happy to iterate.

Surfaced during an open-source XDNA1 (Phoenix) Linux bring-up.

…supported

Follow-up to amd#1447. An older in-tree amdxdna can return EOPNOTSUPP/EINVAL for
DRM_AMDXDNA_QUERY_TELEMETRY, and the SHIM currently throws shim_err, aborting the
whole xrt-smi report even though basic BO/exec works. Wrap the optional telemetry
query handlers so an unsupported ioctl degrades to an empty result plus a one-time
warning, while device use continues. Required paths are unchanged; any error other
than EOPNOTSUPP/ENOTSUP/EINVAL/ENOTTY is rethrown.
@maxzhen

maxzhen commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

ok to test

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the XDNA SHIM telemetry query path to gracefully handle older kernel drivers that don’t support DRM_AMDXDNA_QUERY_TELEMETRY, preventing xrt-smi from aborting the entire report when optional telemetry ioctls are unsupported.

Changes:

  • Add a telemetry_handler::telemetry_query() helper that treats EOPNOTSUPP/ENOTSUP/EINVAL/ENOTTY as “telemetry unsupported” and returns an empty telemetry result instead of throwing.
  • Apply the helper across the telemetry query handlers (AIE2 + AIE4), and value-initialize misc_telemetry outputs to support early returns safely.
  • Add required headers for errno handling, std::system_error, and one-time logging (std::once_flag).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/shim/device.cpp
Comment on lines +1071 to +1075
static std::once_flag warned;
std::call_once(warned, [] {
shim_debug("telemetry not supported by this driver version; skipping "
"(update amdxdna; see amd/xdna-driver#1447)");
});

@maxzhen maxzhen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that the fix should be in xrt-smi, not in SHIM. The SHIM should faithfully signaling the caller and return whatever error it sees. It is the caller to decide if this is optional or required.

@Scottcjn

Scottcjn commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

You're right, thanks. Moved it out of the shim.

The shim goes back to just returning whatever errno the ioctl gives, no swallowing. The optional decision now lives in the caller in XRT: Xilinx/XRT#9907.

It skips telemetry only when the driver reports it unsupported (EOPNOTSUPP, or ENOTTY if the ioctl is not registered), which is what aie2_get_info returns from its default case on an older driver. Everything else including EINVAL still surfaces so real errors are not hidden. I gave the preemption path the same handling since it hits the same rtos_telemetry query.

That leaves nothing in this shim PR, so closing it in favor of the XRT one.

@Scottcjn Scottcjn closed this Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants