| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
Please merge or rebase master branch which fixed CI failure. |
Sorry, something went wrong.
There was a problem hiding this comment.
This PR introduces an experimental Active Task mechanism for bthread workers to run non-blocking maintenance hooks (e.g. harvesting io_uring completions) and adds a local pin + within-worker wake path so waiters can reliably resume on the same worker without cross-thread routing.
Changes:
Copilot reviewed 15 out of 16 changed files in this pull request and generated 5 comments.
Show a summary per file| File | Description |
|---|---|
| test/bthread_active_task_unittest.cpp | Adds end-to-end tests for local wait/wake, strict invariants, pinned/no-steal behavior, and competition cases. |
| src/bthread/unstable.h | Defines the experimental Active Task API surface and callback/context structs. |
| src/bthread/task_meta.h | Extends task metadata with local pin state (home group/control/tag, depth, enabled flag). |
| src/bthread/task_group_inl.h | Adds pinned runqueue push and flushes pinned remote nosignal tasks. |
| src/bthread/task_group.h | Declares active-task worker lifecycle/harvest plumbing and pin-aware routing helpers/queues. |
| src/bthread/task_group.cpp | Implements active-task init/destroy/harvest, worker-loop polling/idle integration, and pin-aware ready-to-run routing. |
| src/bthread/task_control.h | Stores an active-task type snapshot on init; exposes internal snapshot helper. |
| src/bthread/task_control.cpp | Captures active-task registry snapshot during init; initializes/destroys per-worker active tasks; extends signal counting. |
| src/bthread/parking_lot.h | Adds timed wait support (relative timeout) used by active-task idle waiting. |
| src/bthread/butex.h | Documents strict pinned-waiter behavior and exposes butex_wake_to_task_group helper. |
| src/bthread/butex.cpp | Adds within-worker wake helper, strict rejection for pinned waiters, and pin-aware wake routing adjustments. |
| src/bthread/bthread.cpp | Adds active-task type registry + registration API and implements bthread_butex_wait_local/wake_within. |
| docs/cn/bthread_active_task.md | New documentation describing the Active Task model, constraints, and recommended usage pattern. |
| README_cn.md | Links the new Active Task documentation from the Chinese README. |
| README.md | Links the new Active Task documentation from the main README. |
| .gitignore | Adds .cache to ignored paths. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong.
| // wake_within() runs on target_group's owner worker. For pinned waiters, | ||
| // if owner-local pinned runqueue is already full, report EAGAIN and | ||
| // keep waiter on butex list for next harvest retry, instead of | ||
| // blocking/spinning here. | ||
| if (is_pinned_waiter(bw) && target_group->pinned_rq_full()) { | ||
| errno = EAGAIN; | ||
| return -1; | ||
| } | ||
| bw->RemoveFromList(); | ||
| bw->container.store(NULL, butil::memory_order_relaxed); | ||
| } | ||
|
|
||
| unsleep_if_necessary(bbw, get_global_timer_thread()); | ||
| target_group->ready_to_run(bbw->task_meta, true); | ||
| return 1; |
There was a problem hiding this comment.
butex_wake_to_task_group tries to avoid blocking in active-task hooks by checking pinned_rq_full() and returning EAGAIN, but the check isn't atomic with the subsequent enqueue (target_group->ready_to_run(...)). If the pinned runqueue becomes full between the check and ready_to_run, push_pinned_rq may spin/sleep inside the hook, violating the non-blocking intent. Consider adding a non-blocking/try-enqueue path for within-wake (or re-check/return EAGAIN on enqueue failure) so hooks never block.
Sorry, something went wrong.
There was a problem hiding this comment.
in this code path, pinned_rq_full() and the following enqueue are executed by the same owner worker, so the TOCTOU case you mentioned does not occur here.
butex_wake_within_active_task() is only allowed from the active-task hook of the current TaskGroup (validated in validate_active_task_hook_ctx). For pinned waiters, ready_to_run() routes to ready_to_run_pinned_local() on the same home worker. Also, _pinned_rq is owner-local (not used by steal path, and remote routing for pinned tasks goes to _pinned_remote_rq), so there is no concurrent producer that can make _pinned_rq become full between the check and enqueue.
so this check is intended as a fast fail (EAGAIN) when already full, not as a cross-thread non-blocking CAS gate.
Sorry, something went wrong.
| bthread::TaskControl& GetSharedSingleWorkerTaskControl() { | ||
| return GetSharedTaskControl(); | ||
| } | ||
|
|
||
| bthread::TaskControl& GetSharedTwoWorkerTaskControl() { | ||
| return GetSharedTaskControl(); | ||
| } |
There was a problem hiding this comment.
These helpers are named as if they return different TaskControl configurations, but both currently return the same shared TaskControl initialized with concurrency=2. This is misleading for readers and can cause incorrect assumptions in future edits; please either rename them to reflect the shared 2-worker instance, or actually initialize distinct single-worker vs two-worker TaskControls (if feasible).
Sorry, something went wrong.
…ou/add_active_task
Sorry, something went wrong.
Sorry, something went wrong.
|
the ideas were borrowed from : https://github.com/eloqdata/brpc |
Sorry, something went wrong.
|
The testing and usage project is located at: https://github.com/MalikHou/brpc-iouring |
Sorry, something went wrong.
Happy to see the io_uring improvement in brpc . Do you have some benchmark number to share? |
Sorry, something went wrong.
the test plan compared the results of io_uring and pread requests. I will demonstrate the workload from low to high pressure with only 5 threads on the server:
|
Sorry, something went wrong.
|
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
What problem does this PR solve?
Issue Number: resolve #3212
Problem Summary:
What is changed and the side effects?
Changed:
Side effects:
Performance effects:
Breaking backward compatibility:
Check List: