Skip to content

[fix]: enforce HwQueue preemption capability - #29

Open
guohuan78 wants to merge 1 commit into
XpuOS:mainfrom
guohuan78:codex/preempt-level-capability-check
Open

[fix]: enforce HwQueue preemption capability#29
guohuan78 wants to merge 1 commit into
XpuOS:mainfrom
guohuan78:codex/preempt-level-capability-check

Conversation

@guohuan78

Copy link
Copy Markdown
Contributor

Summary

  • enforce HwQueue::GetMaxSupportedLevel() when creating an XQueue;
  • apply the same capability check to dynamic preemption-level changes;
  • add a platform-independent Level-2 fake queue test covering creation, rejection of Level-3, suspend/resume dispatch, and dynamic upgrade rejection.

Motivation

GetMaxSupportedLevel() already expresses each HAL queue's preemption capability, but the core runtime previously treated it as advisory: callers could create or upgrade an XQueue to a level the HAL did not implement. A hardware queue that supports deactivation but not command interruption therefore had no reliable way to reject Level-3.

This change makes the existing HAL contract effective without adding any platform-specific behavior.

Scope

This PR contains only core preemption capability validation and its unit test. It does not add LoongGPU code, OpenCL wrappers, scheduler policy, benchmarks, or application artifacts.

Validation

  • Ubuntu 24.04: core preemption library and capability test build with -Wall -Wextra -Werror;
  • test verifies Level-3 rejection on a Level-2 HAL, valid Level-2 suspend/resume, and dynamic upgrade rejection;
  • git diff --check passes.

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

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

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 makes the HAL’s HwQueue::GetMaxSupportedLevel() contract effective by rejecting XQueue creation and dynamic preemption-level changes that exceed a hardware queue’s declared capability, and adds a core unit test to validate Level-2 vs Level-3 behavior in a platform-independent way.

Changes:

  • Enforce GetMaxSupportedLevel() during XQueueCreate to reject unsupported preemption levels.
  • Enforce the same capability check in XQueueSetPreemptLevel for dynamic level changes.
  • Add a new Level-2 fake-HwQueue test and wire it into the preempt module’s test build.

Reviewed changes

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

File Description
preempt/src/xqueue/xqueue.cpp Adds capability validation for queue creation and dynamic preemption-level changes.
preempt/test/preempt_level_capability_test.cpp New platform-independent test covering Level-3 rejection on a Level-2 HAL and suspend/resume behavior.
preempt/test/CMakeLists.txt Defines the new test executable, compile options, and registers it via add_test.
preempt/CMakeLists.txt Adds conditional inclusion of the new test subdirectory under BUILD_TEST.

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

Comment on lines +27 to +33
if (level > hwq_shptr->GetMaxSupportedLevel()) {
XWARN("preempt level %d is not supported by HwQueue 0x" FMT_64X
", max supported level is %d",
static_cast<int>(level), hwq_h,
hwq_shptr->GetMaxSupportedLevel());
return kXSchedErrorNotSupported;
}
Comment on lines +296 to +301
const auto hwq_shptr = xq_shptr->GetHwQueue();
if (hwq_shptr == nullptr || level > hwq_shptr->GetMaxSupportedLevel()) {
XWARN("preempt level %d is not supported by XQueue 0x" FMT_64X,
level, xq);
return kXSchedErrorNotSupported;
}
Comment thread preempt/CMakeLists.txt
Comment on lines +44 to +46
if(BUILD_TEST)
add_subdirectory(test)
endif()
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