Skip to content

[feat]: add LG200 DRM device discovery - #28

Open
guohuan78 wants to merge 1 commit into
XpuOS:mainfrom
guohuan78:codex/lg200-device-info
Open

[feat]: add LG200 DRM device discovery#28
guohuan78 wants to merge 1 commit into
XpuOS:mainfrom
guohuan78:codex/lg200-device-info

Conversation

@guohuan78

Copy link
Copy Markdown
Contributor

Summary

  • discover LG200 DRM devices under /sys/class/drm using the loonggpu driver identity;
  • expose a small C API for device enumeration and optional utilization/memory statistics;
  • add lg200_info for runtime inspection;
  • add a synthetic sysfs test that does not require Loongson hardware.

Scope

This PR contains device information retrieval only. It intentionally does not add an LG200 HwQueue, HwCommand, callback wrapper, scheduler policy, benchmark, model, or application demo.

Generic application work can continue to use XSched's existing HwCommandCreateCallback API. Hardware-specific KCD queue deactivation is being prepared as a separate Level-2 follow-up after this discovery layer is reviewed.

Build and test

cmake -S . -B build-lg200 \
  -DPLATFORM_LG200=ON \
  -DPLATFORM_OPENCL=ON \
  -DBUILD_TEST=ON
cmake --build build-lg200 --target lg200_info lg200_resource_test
./build-lg200/platforms/lg200/test/lg200_resource_test

Validation

  • Ubuntu 24.04: hallg200, lg200_info, and lg200_resource_test build with -Wall -Wextra -Werror;
  • synthetic DRM/sysfs enumeration test passes;
  • public hal.h compiles as C11;
  • git diff --check passes.

Validation run: https://github.com/guohuan78/xsched/actions/runs/30079872796

Runtime behavior

Lg200DeviceEnumerate() accepts the loonggpu driver name (or an explicit LG200 product identity) rather than treating the Loongson PCI vendor id alone as proof of a GPU. Statistics are optional: unavailable utilization is returned as -1.0, and unavailable memory counters as zero.

Copilot AI review requested due to automatic review settings July 24, 2026 08:44

Copilot AI left a comment

Copy link
Copy Markdown

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 introduces an LG200 “discovery-only” layer that enumerates Loongson LG200 DRM devices via sysfs and exposes a small C API for device listing and optional utilization/memory stats, plus a CLI/tool and a synthetic sysfs test to validate discovery without hardware.

Changes:

  • Add Lg200DeviceEnumerate() / Lg200DeviceReadStats() C API and Linux sysfs-backed implementation.
  • Add lg200_info tool for runtime inspection of discovered devices and optional stats.
  • Add a synthetic /sys/class/drm-like test harness (lg200_resource_test) and wire up LG200 platform/test CMake.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
platforms/lg200/hal/src/resource.cpp Implements sysfs-based DRM discovery and optional stats reads for LG200.
platforms/lg200/hal/include/xsched/lg200/hal.h Defines the public LG200 C API structs and function declarations.
platforms/lg200/hal/include/xsched/lg200/hal/resource.h Declares internal C++ discovery helper returning a std::vector.
platforms/lg200/tools/lg200_info.cpp Adds a CLI utility to enumerate devices and print optional stats.
platforms/lg200/test/lg200_resource_test.cpp Adds a synthetic sysfs/DRM layout test for discovery + stats behavior.
platforms/lg200/test/CMakeLists.txt Builds and links the LG200 synthetic resource test on Linux.
platforms/lg200/CMakeLists.txt Adds the LG200 HAL library, CLI tool, install rules, and test subdir hook.
platforms/lg200/README.md Documents build steps and the LG200 discovery/statistics API behavior.

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

Comment on lines +175 to +179
const std::string vendor = ReadTextFile(device_path / "vendor");
const std::string driver = ReadUeventValue(device_path, "DRIVER");
const std::string pci_id = ReadUeventValue(device_path, "PCI_ID");
const std::string model = pci_id.empty() ? card_name : pci_id;
if (!IsLg200Candidate(vendor, driver, model)) continue;
Comment on lines +31 to +33
// Enumerate DRM cards owned by the loonggpu kernel driver. Passing devices as
// NULL queries the required count. If the supplied array is too small, count
// is updated to the required size and kXSchedErrorInvalidValue is returned.
Comment thread platforms/lg200/README.md
Comment on lines +26 to +27
- `Lg200DeviceEnumerate()` enumerates `cardN` nodes whose driver name starts
with `loonggpu` or whose product identity contains `LG200`.
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.

2 participants