Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove busy wait completely in TaskScheduler #2573

Merged
merged 8 commits into from
Dec 12, 2023
Merged

Remove busy wait completely in TaskScheduler #2573

merged 8 commits into from
Dec 12, 2023

Conversation

mewim
Copy link
Member

@mewim mewim commented Dec 12, 2023

No description provided.

@mewim mewim linked an issue Dec 12, 2023 that may be closed by this pull request
Copy link

codecov bot commented Dec 12, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (00d8dda) 93.16% compared to head (2dc5139) 93.16%.

❗ Current head 2dc5139 differs from pull request most recent head d27c431. Consider uploading reports for the commit d27c431 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2573      +/-   ##
==========================================
- Coverage   93.16%   93.16%   -0.01%     
==========================================
  Files        1027     1027              
  Lines       38418    38416       -2     
==========================================
- Hits        35791    35789       -2     
  Misses       2627     2627              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -22,6 +22,10 @@ void Task::deRegisterThreadAndFinalizeTaskIfNecessary() {
finalizeIfNecessary();
} catch (std::exception& e) { setExceptionNoLock(std::current_exception()); }
}
if (isCompletedNoLock()) {
mtx.unlock();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait shouldn't this be lck.unlock().

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Via #2574, seems like this is the issue.

Comment on lines 58 to 61
inline uint64_t getTimeoutRemainingInMS() {
if (!isTimeOutEnabled()) {
return UINT64_MAX;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could change this into a KU_ASSERT()... not sure if that makes more sense. I.e., make it an error to call this method when a timeout is not set.

Comment on lines +51 to +56
if (timedWait) {
task->cv.wait_for(taskLck, std::chrono::milliseconds(timeout));
} else {
task->cv.wait(taskLck);
}
taskLck.unlock();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing we should note in the code as a comment is that completed tasks may sit around in the queue for a bit.

@mewim mewim marked this pull request as ready for review December 12, 2023 15:28
@Riolku
Copy link
Contributor

Riolku commented Dec 12, 2023

image

I'm pretty sure we actually didn't fix the busy wait. In runWorkerThread(), we continue if there is no schedulable task. That means we unlock, re-lock, check if the queue is empty (it's not) and then play the same game.

Basically, the issue is that we don't remove tasks from the queue once they have been scheduled on enough threads, I think.

@mewim mewim merged commit 60ebb05 into master Dec 12, 2023
12 checks passed
@mewim mewim deleted the kill-busy-loop branch December 12, 2023 16:21
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.

Remove busy wait completely in TaskScheduler
2 participants