[build]: support LoongArch host toolchains - #27
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new LG200 Level-1 HAL (Loongson 2K3000 integrated GPU) and updates the build system and core runtime interfaces to support callback-backed queues/work items, sysfs-based device discovery/stats, and older Loongnix toolchains.
Changes:
- Introduces
platforms/lg200HAL + tools/tests, including DRM/sysfs discovery and callback-backed queue/command integration. - Extends the preempt runtime with an
HwQueue::OnXQueueDestroy()hook and adds LG200 to platform enums/name mappings. - Improves portability for LoongArch/older toolchains (CMake 3.13 support, conditional service/3rdparty deps) and tightens lock/memory-ordering behavior.
Reviewed changes
Copilot reviewed 30 out of 30 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| utils/src/lock.cpp | Refactors MCS lock spinning to use atomics + per-arch CPU relax behavior. |
| utils/include/xsched/utils/lock.h | Updates MCSNode fields to std::atomic for correctness on weaker memory models. |
| utils/include/xsched/utils/common.h | Adds LoongArch64 arch detection and enforces supported-arch errors; defines format macros. |
| utils/include/xsched/utils/region.h | Fixes 64-bit formatting in an XASSERT message. |
| sched/src/scheduler/local.cpp | Updates operation-id formatting in scheduler logging/asserts. |
| preempt/src/sched/executor.cpp | Updates operation-id formatting in executor assertions. |
| preempt/src/xqueue/launch_worker.cpp | Calls new HwQueue::OnXQueueDestroy() before worker thread exits. |
| preempt/include/xsched/preempt/hal/hw_queue.h | Adds OnXQueueDestroy() lifecycle hook for launch-worker thread teardown. |
| protocol/src/names.cpp | Registers LG200 platform name mapping. |
| python/xsched/init.py | Adds kPlatformLG200 to Python enum. |
| include/xsched/types.h | Adds kPlatformLG200 to public C enum. |
| README.md | Documents LG200 platform and build target list update. |
| platforms/README.md | Adds LG200 to platforms index. |
| platforms/lg200/CMakeLists.txt | Adds LG200 HAL library, lg200_info, and platform tests; Loongnix/GCC8 stdc++fs link handling. |
| platforms/lg200/README.md | Documents LG200 scope, build, runtime integration, and error reporting expectations. |
| platforms/lg200/hal/include/xsched/lg200/hal.h | New public C HAL API for LG200 devices/queues/commands. |
| platforms/lg200/hal/include/xsched/lg200/hal/lg200_queue.h | New Lg200Queue HwQueue implementation header. |
| platforms/lg200/hal/include/xsched/lg200/hal/lg200_command.h | New Lg200Command HwCommand implementation header. |
| platforms/lg200/hal/include/xsched/lg200/hal/resource.h | Declares internal device-discovery helper for LG200. |
| platforms/lg200/hal/src/resource.cpp | Implements sysfs/DRM discovery + stats reading with env override for tests. |
| platforms/lg200/hal/src/lg200_queue.cpp | Implements callback-backed queue, worker enter/exit hooks, and sticky error state. |
| platforms/lg200/hal/src/lg200_command.cpp | Implements callback-backed command launch/sync/destroy behavior. |
| platforms/lg200/tools/lg200_info.cpp | Adds lg200_info utility to print discovered devices and stats. |
| platforms/lg200/test/CMakeLists.txt | Adds LG200 tests and platform-specific linking/timeout properties. |
| platforms/lg200/test/lg200_callback_test.cpp | Adds callback/lifecycle behavior validation for LG200 queue/command integration. |
| platforms/lg200/test/lg200_queue_error_test.cpp | Adds sticky error propagation test scenarios for enter/launch/sync/exit callbacks. |
| platforms/lg200/test/lg200_resource_test.cpp | Adds synthetic sysfs discovery/stat parsing test using temp dirs + symlinks. |
| Makefile | Adds BUILD_SERVICE and lg200 target to build core + LG200 without service. |
| CMakeLists.txt | Lowers minimum CMake to 3.13 and gates service + testing enablement. |
| 3rdparty/CMakeLists.txt | Makes service-related deps conditional; avoids enabling bundled googletest paths for older CMake. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Thank you for your work on supporting the Loongson platform. The changes related to Loongson CPUs meet the project’s requirements and are acceptable. We appreciate your contribution to Loongson CPU support. |
c4fb83b to
a6f2f21
Compare
|
Thank you for clarifying the expected boundary. I have reworked this contribution accordingly:
I am intentionally keeping that Level-2 branch out of this PR and will submit it after the two small prerequisites are reviewed, so each change can be evaluated independently. The Level-2 implementation claims queue deactivation/reactivation only; it does not claim Level-3 kernel interruption. |
|
Thank you for your contribution! I believe this PR is ready to merge. |
Summary
MCSLockuse C++ atomics and acquire/release ordering so it is correct on weakly ordered CPUs;Scope after review
This PR now contains only LoongArch CPU/toolchain support. The previous callback-backed LG200 queue/command wrapper has been removed in response to maintainer feedback because the same generic integration can use
HwCommandCreateCallbackand existing XSched interfaces.LoongGPU work is split into independent follow-ups:
HwQueue::GetMaxSupportedLevel()contract in the core runtime;UPDATE_QUEUEUAPI and XSched's existing OpenCL command implementation.Build
On Loongnix 20, the core-only configuration is:
cmake -S . -B build-loongarch \ -DBUILD_SERVICE=OFF \ -DBUILD_TEST=OFF cmake --build build-loongarch --parallelBUILD_SERVICE=ONkeeps the existing CMake 3.14+ requirement.Validation
preemptandhalopenclbuild in an independent GitHub Actions run.lock.cpp, scheduler, and executor translation units compile with-std=c++20 -Wall -Wextra -Werror.git diff --checkpasses.Validation run: https://github.com/guohuan78/xsched/actions/runs/30080993762