Bugfix: bthread_worker_usage could exceed bthread_worker_count#3009
Merged
Conversation
65e1b6e to
11497b0
Compare
gitccl
reviewed
Jun 28, 2025
6ceff12 to
eba4d84
Compare
eba4d84 to
6aa0286
Compare
Contributor
Author
|
@wwbmmm @yanglimingcn Please take a look. |
Contributor
Author
|
@wwbmmm @yanglimingcn Friendly ping! |
wwbmmm
reviewed
Jul 14, 2025
Contributor
Author
b7bfdb3 to
7d4ce67
Compare
7d4ce67 to
bd1683b
Compare
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a bug where bthread_worker_usage could exceed bthread_worker_count by refactoring how CPU time statistics are tracked for bthread workers. The fix ensures that worker usage calculations properly account for both cumulated CPU time and the current running task's elapsed time.
- Introduces atomic 128-bit operations for thread-safe CPU time tracking
- Refactors CPU time statistics to include both scheduling time and task type information
- Consolidates prime offset generation into a shared utility function
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
src/bthread/task_group.h |
Adds AtomicInteger128 and CPUTimeStat classes, refactors TaskGroup member variables with default initialization |
src/bthread/task_group.cpp |
Implements atomic operations and updates CPU time tracking logic in scheduling functions |
src/bthread/task_control.h |
Renames method from get_cumulated_worker_time_with_tag to get_cumulated_worker_time |
src/bthread/task_control.cpp |
Updates method calls and simplifies cumulated time calculation logic |
src/bthread/prime_offset.h |
New utility header providing centralized prime offset generation functions |
| Load balancer files | Updates to use the new centralized prime_offset() function instead of GenRandomStride() |
src/brpc/load_balancer.h |
Removes deprecated GenRandomStride() function |
Comments suppressed due to low confidence (1)
src/bthread/task_group.h:91
- Misspelled word: 'Supress' should be 'Suppress'.
bthread_t* __restrict tid,
bd1683b to
9ca6a4b
Compare
wwbmmm
reviewed
Jul 20, 2025
Contributor
|
LGTM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What problem does this PR solve?
Issue Number: resolve #1231 , resolve #2640 , resolve #2972
Problem Summary:
What is changed and the side effects?
Changed:
bthread_worker_usageshould consist of_cumulated_cputime_nsand the CPU time of the task currently run by the worker.Side effects:
Performance effects:
Breaking backward compatibility:
Check List: