Skip to content

[build]: support LoongArch host toolchains - #27

Merged
Naplesoul merged 4 commits into
XpuOS:mainfrom
guohuan78:codex/lg200-upstream-adapter
Jul 24, 2026
Merged

[build]: support LoongArch host toolchains#27
Naplesoul merged 4 commits into
XpuOS:mainfrom
guohuan78:codex/lg200-upstream-adapter

Conversation

@guohuan78

@guohuan78 guohuan78 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Summary

  • recognize LoongArch64 hosts in XSched's architecture utilities;
  • make the FIFO MCSLock use C++ atomics and acquire/release ordering so it is correct on weakly ordered CPUs;
  • allow the core runtime to build without the scheduler service and its unrelated third-party dependencies;
  • keep the Loongnix 20 / CMake 3.13 path usable while retaining the existing service requirement on CMake 3.14+;
  • use the repository's portable integer and PID formatting macros.

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 HwCommandCreateCallback and existing XSched interfaces.

LoongGPU work is split into independent follow-ups:

  1. LoongGPU device discovery/statistics;
  2. enforcement of the existing HwQueue::GetMaxSupportedLevel() contract in the core runtime;
  3. a hardware-specific Level-2 adapter backed by the LG200 KCD UPDATE_QUEUE UAPI 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 --parallel

BUILD_SERVICE=ON keeps the existing CMake 3.14+ requirement.

Validation

  • Loongnix 20 / LoongArch64: GCC 8.3 and CMake 3.13.4 core build validated on a Loongson 2K3000 board.
  • Ubuntu 24.04: preempt and halopencl build in an independent GitHub Actions run.
  • Windows MinGW: changed lock.cpp, scheduler, and executor translation units compile with -std=c++20 -Wall -Wextra -Werror.
  • git diff --check passes.

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

Copilot AI review requested due to automatic review settings July 16, 2026 18:46

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

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/lg200 HAL + 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.

Comment thread sched/src/scheduler/local.cpp Outdated
Comment thread preempt/src/sched/executor.cpp
Comment thread platforms/lg200/hal/src/lg200_command.cpp Outdated
@wuwen03

wuwen03 commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

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.
For the GPU part, apart from the device information retrieval module, which is closely related to Loongson GPUs, the remaining changes are mostly generic adaptations and do not yet provide a Loongson-GPU-specific implementation. This generic approach can already be implemented using existing XSched interfaces such as HwCommandCreateCallback and related APIs, without introducing a new platform-specific implementation.
We look forward to deeper integration of Loongson GPU capabilities, particularly its hardware-specific scheduling and preemption mechanisms, with XSched’s HAL abstractions.

@guohuan78
guohuan78 force-pushed the codex/lg200-upstream-adapter branch from c4fb83b to a6f2f21 Compare July 24, 2026 08:06
@guohuan78 guohuan78 changed the title [feat]: add Loongson LG200 Level-1 HAL [build]: support LoongArch host toolchains Jul 24, 2026
@guohuan78

Copy link
Copy Markdown
Contributor Author

Thank you for clarifying the expected boundary. I have reworked this contribution accordingly:

  • PR [build]: support LoongArch host toolchains #27 now contains only LoongArch CPU/toolchain support; the generic callback-backed LG200 queue/command implementation has been removed.
  • PR [feat]: add LG200 DRM device discovery #28 contains only LoongGPU DRM device discovery and optional statistics.
  • PR [fix]: enforce HwQueue preemption capability #29 is a platform-independent fix that makes HwQueue::GetMaxSupportedLevel() enforceable at XQueue creation and dynamic level changes.
  • The hardware-specific follow-up is implemented around the LG200 KCD UPDATE_QUEUE UAPI: an OpenCL HwQueue deactivates/reactivates the native KCD queue group through XSched's Level-2 HAL operations, while reusing the existing OpenCL command implementation. It does not introduce another generic callback command abstraction.

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.

@Naplesoul

Copy link
Copy Markdown
Collaborator

Thank you for your contribution! I believe this PR is ready to merge.

@Naplesoul
Naplesoul merged commit bd494cb into XpuOS:main Jul 24, 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