Skip to content

Add awakened_from_remote() to bypass remote_ready_queue#3

Open
Akatsukis wants to merge 15 commits into
categoryfrom
xiaojun/awakened_from_remote_v2
Open

Add awakened_from_remote() to bypass remote_ready_queue#3
Akatsukis wants to merge 15 commits into
categoryfrom
xiaojun/awakened_from_remote_v2

Conversation

@Akatsukis

Copy link
Copy Markdown
Collaborator

Depends on #2

jhunsaker and others added 13 commits March 27, 2026 18:05
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
These mutex types are unused by the top-level project. Removes source
files, headers, and references from CMakeLists.txt and all.hpp.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Unused by the top-level project. Removes source, header, examples,
and performance benchmarks.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Unused by the top-level project. Removes source, header, examples,
and performance benchmarks.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Unused by the top-level project. Removes header, example, and include
references from fiber.hpp and all.hpp.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Unused by the top-level project. Removes source, header, dedicated
test files, and dead do_wait() references in fiber tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Unused by the top-level project.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Unused by the top-level project. Removes fss.hpp, detail/fss.hpp, test
files, and cleans fss_data_ from context.hpp and context.cpp.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Unused by the top-level project. Removes header, test files, and
examples that solely used unbuffered_channel.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Unused by the top-level project.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Unused by the top-level project. Removes rtm.hpp, spinlock_rtm.hpp,
and strips BOOST_USE_TSX branches from spinlock.hpp.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Akatsukis Akatsukis changed the title Xiaojun/awakened from remote v2 Add awakened_from_remote() to bypass remote_ready_queue May 13, 2026
Akatsukis and others added 2 commits May 13, 2026 12:03
Drops all timed-wait APIs from boost.fiber. Affected interfaces:

  - boost::this_fiber::sleep_for / sleep_until
  - condition_variable::wait_for / wait_until (both _any and the
    mutex-bound variants)
  - future<T>::wait_for / wait_until, shared_future<T>::wait_for / wait_until
  - buffered_channel::push_wait_for / push_wait_until /
    pop_wait_for / pop_wait_until
  - context::wait_until, context::sleep_link / sleep_unlink /
    sleep_is_linked, plus the sleep_hook_, sleep_waker_, tp_ members
  - scheduler::wait_until, scheduler::sleep2ready_, sleep_queue_
  - wait_queue::suspend_and_wait_until

algorithm::suspend_until(time_point) is renamed to algorithm::suspend()
since the time_point has no meaning without a sleep queue.
round_robin::suspend uses condition_variable::wait(lk, pred) instead of
the timed variant.

Also removes upstream tests and examples that exercised the removed
APIs and would no longer build:

  - examples/priority.cpp, examples/wait_stuff.cpp
  - test/test_buffered_channel_{dispatch,post}.cpp
  - test/test_condition_variable_{,any_}{dispatch,post}.cpp
  - test/test_fiber_{dispatch,post}.cpp
  - test/test_future_{dispatch,post}.cpp
  - test/test_mutex_{dispatch,post}.cpp
  - test/test_shared_future_{dispatch,post}.cpp

The corresponding stanzas are stripped from examples/Jamfile.v2 and
test/Jamfile.v2. Untimed coverage of mutex/future/channel/fiber
behaviour remains in the MT variants (test_mutex_mt_*.cpp,
test_future_mt_*.cpp) and the unmodified barrier/promise/async/
packaged_task suites.

Intended for fiber pools where all synchronization is via untimed
waits + cross-thread wakeups; the sleep-queue scan in every dispatch
iteration is gone.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Introduces an optional algorithm hook, awakened_from_remote(context*),
that lets a scheduling algorithm with a thread-safe ready-queue (e.g.
a shared priority queue) take ownership of a remote wakeup directly,
bypassing the per-thread remote_ready_queue_ + spinlock indirection.

When BOOST_FIBERS_AWAKENED_FROM_REMOTE is defined:
  - schedule_from_remote() offers non-pinned contexts to the algorithm
    first; on a true return the wake is claimed and the algorithm is
    notified. Falls back to remote_ready_queue_ for pinned contexts or
    when the algorithm declines.
  - A new worker_splk_ serializes attach_worker_context() and
    detach_worker_context() against each other and against
    worker_queue_ traversal in dispatch()/terminate(), so a remote
    thread that calls ctx->detach() inside awakened_from_remote()
    cannot race the owning thread attaching another fiber.
  - A compile-time guard rejects builds that combine the new hook
    with BOOST_FIBERS_NO_ATOMICS (single-thread mode).

Invariant asserts in schedule_from_remote() are hoisted above the
fast-path so the debug-time contract still applies when the hook
claims the wake.

Default awakened_from_remote() returns false, so algorithms that
don't override it behave exactly as before.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Akatsukis Akatsukis force-pushed the xiaojun/awakened_from_remote_v2 branch from c81895e to 0f0d947 Compare May 13, 2026 16:12
@Akatsukis Akatsukis requested a review from Copilot May 13, 2026 16:16

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 adds an optional awakened_from_remote() hook on algorithm so that schedulers with thread-safe ready-queues can bypass the per-thread remote_ready_queue_ when schedule_from_remote() is invoked. It also (apparently inheriting from a dependent PR) removes the sleep-queue mechanism and all timed-wait/sleep public API along with associated tests and examples, and replaces algorithm::suspend_until with a parameterless suspend().

Changes:

  • Add algorithm::awakened_from_remote() virtual hook (default returns false) and integrate fast-path in scheduler::schedule_from_remote, plus a new worker_splk_ to serialize attach/detach of worker contexts across threads.
  • Remove the sleep queue and all wait_until/wait_for/sleep_for/sleep_until API surface from scheduler, context, condition_variable[_any], future/shared_future, buffered_channel, operations, and wait_queue.
  • Delete the corresponding _post/_dispatch test files and the priority/wait_stuff examples, with matching removals in test/Jamfile.v2 and examples/Jamfile.v2.

Reviewed changes

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

Show a summary per file
File Description
include/boost/fiber/algo/algorithm.hpp Replace suspend_until with suspend; add awakened_from_remote default hook.
include/boost/fiber/algo/round_robin.hpp Override suspend() instead of suspend_until.
src/algo/round_robin.cpp Implementation now waits unconditionally on the cv.
include/boost/fiber/scheduler.hpp Remove sleep-queue type/state and wait_until; add worker_splk_ and AWAKENED_FROM_REMOTE guards.
src/scheduler.cpp Remove sleep2ready_/wait_until; integrate awakened_from_remote fast path; lock worker_splk_ in attach/detach/terminate/dispatch.
include/boost/fiber/context.hpp Drop sleep_hook, sleep_waker_, tp_, sleep_*/wait_until members.
src/context.cpp Remove wait_until and sleep_* definitions/asserts.
include/boost/fiber/waker.hpp, src/waker.cpp Remove suspend_and_wait_until.
include/boost/fiber/condition_variable.hpp Remove wait_for/wait_until overloads on cv and cv_any.
include/boost/fiber/buffered_channel.hpp Remove push_wait_for/until and pop_wait_for/until.
include/boost/fiber/future/future.hpp, .../shared_state.hpp Remove wait_for/wait_until.
include/boost/fiber/operations.hpp Remove sleep_for/sleep_until.
test/Jamfile.v2 Drop test entries for the removed _post/_dispatch test files.
test/test_fiber_{post,dispatch}.cpp, test/test_mutex_, test/test_condition_variable*, test/test_future, test/test_shared_future_, test/test_buffered_channel_* Deleted.
examples/Jamfile.v2, examples/priority.cpp Remove priority and wait_stuff examples.

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

@Akatsukis Akatsukis requested review from jhunsaker and magedm May 13, 2026 16:19
@jhunsaker jhunsaker force-pushed the category branch 2 times, most recently from 133ac78 to a7c0273 Compare May 29, 2026 05:45
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.

3 participants