Skip to content

Batch and coalesce mass fiber wakeups#94

Merged
vadimskipin merged 3 commits into
mainfrom
vskipin/batch-schedule
Jun 29, 2026
Merged

Batch and coalesce mass fiber wakeups#94
vadimskipin merged 3 commits into
mainfrom
vskipin/batch-schedule

Conversation

@vadimskipin

Copy link
Copy Markdown
Collaborator

Add FiberFuture::setAll and FiberScheduler::scheduleAll to wake many parked fibers at once: enqueue each to its home ready queue, dedup the distinct target processors in a Bitmap, then ring each parked target's doorbell exactly once behind a single seq_cst fence and one submit - instead of a schedule/doorbell/submit per fiber.

Cross-ring doorbells post straight into the target's CQ via IORING_OP_MSG_RING; IOSQE_CQE_SKIP_SUCCESS drops the send-side completion and the carrier is tagged CQE_TAG_WAKEUP for the drain to skip. Gated on the new IORING_FEAT_CQE_SKIP feature check at init.

signal is split into extractWaitingFiber + schedule so setAll can reuse the extraction. enqueueReady now returns the processor whose doorbell the caller must ring (or null when it self-handled the wake), letting schedule and runFiber ring immediately while scheduleAll defers and coalesces.

FiberSequencer drains through setAll; its trivial wait/increment/advance move inline to the header. Adds setAll tests and a SetAllWake benchmark.

Non-owning view over a caller-owned bitmap of bits packed into 64-bit
words, with set/test/clear and findBit for in-order enumeration of set
or clear bits. Includes unit tests.
Add FiberFuture::setAll and FiberScheduler::scheduleAll to wake many
parked fibers at once: enqueue each to its home ready queue, dedup the
distinct target processors in a Bitmap, then ring each parked target's
doorbell exactly once behind a single seq_cst fence and one submit -
instead of a schedule/doorbell/submit per fiber.

Cross-ring doorbells post straight into the target's CQ via
IORING_OP_MSG_RING; IOSQE_CQE_SKIP_SUCCESS drops the send-side
completion and the carrier is tagged CQE_TAG_WAKEUP for the drain to
skip. Gated on the new IORING_FEAT_CQE_SKIP feature check at init.

signal is split into extractWaitingFiber + schedule so setAll can reuse
the extraction. enqueueReady now returns the processor whose doorbell
the caller must ring (or null when it self-handled the wake), letting
schedule and runFiber ring immediately while scheduleAll defers and
coalesces.

FiberSequencer drains through setAll; its trivial wait/increment/advance
move inline to the header. Adds setAll tests and a SetAllWake benchmark.
@praktika-gh

praktika-gh Bot commented Jun 29, 2026

Copy link
Copy Markdown

Workflow [PR], commit [d68a535]

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 introduces batched wakeups for parked fibers by adding FiberFuture::setAll() and FiberScheduler::scheduleAll(), aiming to coalesce cross-CPU doorbells and reduce per-fiber io_uring submissions during mass wakeups.

Changes:

  • Add FiberFuture::setAll() to set many futures and batch-schedule their waiting fibers.
  • Add FiberScheduler::scheduleAll() plus io_uring MSG_RING-based cross-ring doorbells to coalesce wakeups across target processors.
  • Introduce a small Bitmap utility (with tests) to deduplicate wake targets; add tests and a benchmark for setAll.

Reviewed changes

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

Show a summary per file
File Description
src/util/tests/bitmap-test.cpp Adds unit tests for the new Bitmap utility (bit ops + enumeration behavior).
src/util/bitmap.cpp Implements Bitmap::findBit() using word scanning + countr_zero.
include/silk/util/bitmap.h Adds the Bitmap non-owning view utility used for wake-target deduplication.
src/fibers/future.cpp Refactors waiter extraction and adds FiberFuture::setAll() batching logic.
include/silk/fibers/future.h Declares FiberFuture::setAll() and shared batching constant.
src/fibers/fiber.cpp Adds MSG_RING wakeup plumbing, scheduleAll(), and updated enqueue/wakeup flow.
include/silk/fibers/fiber.h Declares FiberScheduler::scheduleAll() and updates enqueueReady signature.
src/fibers/sequencer.cpp Switches drain wakeups to use batched FiberFuture::setAll().
include/silk/fibers/sequencer.h Inlines trivial sequencer methods and introduces batching helper declaration/constants.
src/fibers/tests/future-test.cpp Adds correctness tests for FiberFuture::setAll() (waiters/no-waiters/empty).
src/fibers/benchmarks/future-bench.cpp Adds a benchmark measuring batched wake performance (SetAllWake).
include/silk/util/bounded-queue.h Adds a documented convenience constructor for initialization-at-construction.

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

Comment thread src/fibers/fiber.cpp
Comment thread src/fibers/fiber.cpp
Comment thread src/fibers/fiber.cpp
@vadimskipin
vadimskipin merged commit 68e807d into main Jun 29, 2026
16 checks passed
@vadimskipin
vadimskipin deleted the vskipin/batch-schedule branch June 29, 2026 10:10
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