Skip to content

Signal workers for priority tasks - #3423

Open
chenBright wants to merge 1 commit into
apache:masterfrom
chenBright:fix_priority_to_run
Open

Signal workers for priority tasks#3423
chenBright wants to merge 1 commit into
apache:masterfrom
chenBright:fix_priority_to_run

Conversation

@chenBright

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: resolve N/A

Problem Summary:

Tasks placed into a global priority queue did not signal worker threads after being enqueued. If all eligible workers were sleeping, these tasks could remain pending until another event woke a worker.

What is changed and the side effects?

Changed:

Signal one worker after adding a task to the global priority queue. The signal uses the task's tag so that a worker associated with the correct tag is notified.

Side effects:

  • Performance effects:

  • Breaking backward compatibility:


Check List:

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 addresses a scheduling gap in bthread’s global priority queue path: after enqueuing a task into the global per-tag priority queue, no worker was explicitly signaled, so eligible workers could remain asleep and leave priority work pending until another wake-up event occurred.

Changes:

  • Enqueueing into the global ED priority queue now additionally signals one worker for the task’s tag.
  • The priority-queue unit test now keeps track of started urgent children and joins them to ensure completion.

Reviewed changes

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

File Description
src/bthread/task_group.cpp Signals a worker after pushing a task into the global per-tag priority queue to avoid stalled priority work.
test/bthread_priority_queue_unittest.cpp Joins urgent child bthreads in a priority-queue test to ensure spawned tasks complete before returning.

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

Comment thread test/bthread_priority_queue_unittest.cpp
Comment thread src/bthread/task_group.cpp

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Suppressed comments (2)

src/bthread/task_group.cpp:1026

  • The new wakeup in priority_to_run() always calls signal_task() even when the BTHREAD_NOSIGNAL flag was set on the newly created bthread (passed through args->nosignal). That changes the documented NOSIGNAL behavior (“worker pthreads are not notified”) and can defeat batching/flush semantics.
    g->control()->push_ed_priority_queue(
        args->tag, args->meta->priority_index, args->meta->tid);

    ++g->_nsignaled;
    g->control()->signal_task(1, args->tag);

src/bthread/task_group.cpp:1025

  • There isn’t a regression test that specifically exercises the original failure mode described in the PR (all eligible workers parked, then an ED is enqueued into the global priority queue and must wake a worker). The current unit tests create/execute priority work, but they don’t assert the wakeup behavior from the ED priority queue under idle-worker conditions, so this change could regress without being caught.
    ++g->_nsignaled;
    g->control()->signal_task(1, args->tag);

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