Skip to content

[WIP] time: delay the cancellation of timers #7467

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

Draft
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

ADD-SP
Copy link
Member

@ADD-SP ADD-SP commented Jul 19, 2025

Status

There are something need to be polished, but before polishing something, I drafted this PR to get the CI error early.

Review guide

Rationale for some technical decisions

Please checkout the inline PR comments I wrote.

Benchmarks

Waiting for #7473.

@ADD-SP ADD-SP added A-tokio Area: The main tokio crate M-time Module: tokio/time T-performance Topic: performance and benchmarks R-loom-time-driver Run loom time driver tests on this PR R-loom-current-thread Run loom current-thread tests on this PR R-loom-multi-thread Run loom multi-thread tests on this PR labels Jul 19, 2025
@ADD-SP ADD-SP changed the title [WIP] [WIP] time: delayed cancellation of timers Jul 19, 2025
@ADD-SP ADD-SP force-pushed the add_sp/time-local-wheel branch 11 times, most recently from c2d5790 to d04c22f Compare July 19, 2025 13:19
@ADD-SP ADD-SP changed the title [WIP] time: delayed cancellation of timers [WIP] time: delay the cancellation of timers Jul 19, 2025
@@ -522,43 +514,6 @@ async fn insert_after_ready_poll() {
assert_eq!("3", res[2]);
}

#[tokio::test]
async fn reset_later_after_slot_starts() {
Copy link
Member Author

Choose a reason for hiding this comment

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

Note

This test was removed because it was testing the behavior of tokio::runtime::time::entry::reset, which is removed in this PR.

@@ -584,43 +539,6 @@ async fn reset_inserted_expired() {
assert_eq!(queue.len(), 0);
}

#[tokio::test]
async fn reset_earlier_after_slot_starts() {
Copy link
Member Author

Choose a reason for hiding this comment

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

Note

This test was removed because it was testing the behavior of tokio::runtime::time::entry::reset, which is removed in this PR.

@@ -221,7 +219,7 @@ async fn reset_much_later() {

sleep(ms(20)).await;

assert!(queue.is_woken());
assert_ready_some!(poll!(queue));
Copy link
Member Author

Choose a reason for hiding this comment

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

Note

Since previous queue.reset_at doesn't register the underlying timer, so the task won't be woken up, we have to poll the queue.

@@ -248,7 +246,7 @@ async fn reset_twice() {

sleep(ms(20)).await;

assert!(queue.is_woken());
assert_ready_some!(poll!(queue));
Copy link
Member Author

Choose a reason for hiding this comment

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

Note

Since previous queue.reset_at doesn't register the underlying timer, so the task won't be woken up, we have to poll the queue.

Comment on lines +771 to +779
// runtime is shutting down
// OR waking up expired timers

// Track that a task was scheduled from **outside** of the runtime.
self.shared.scheduler_metrics.inc_remote_schedule_count();

// Schedule the task
self.shared.inject.push(task);
self.driver.unpark();
Copy link
Member Author

@ADD-SP ADD-SP Jul 19, 2025

Choose a reason for hiding this comment

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

Note

Since the wheel is stored in the Core, the cx.core is None while waking up timers.

Although we can store Option<Wheel> in Core, it doubles the number of states of the local time subsystem.

@@ -41,7 +39,6 @@ mod wake_list;
feature = "fs",
feature = "rt",
feature = "signal",
feature = "time",
))]
pub(crate) use wake_list::WakeList;
Copy link
Member Author

Choose a reason for hiding this comment

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

Note

We no long use WakeList in the time subsystem.

Comment on lines +137 to +138
// #[cfg(test)]
// mod tests;
Copy link
Member Author

Choose a reason for hiding this comment

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

Note

Blocked by #7461

ADD-SP added 14 commits July 21, 2025 21:02
Signed-off-by: ADD-SP <qiqi.zhang@konghq.com>
Signed-off-by: ADD-SP <qiqi.zhang@konghq.com>
Signed-off-by: ADD-SP <qiqi.zhang@konghq.com>
Signed-off-by: ADD-SP <qiqi.zhang@konghq.com>
Signed-off-by: ADD-SP <qiqi.zhang@konghq.com>
Signed-off-by: ADD-SP <qiqi.zhang@konghq.com>
Signed-off-by: ADD-SP <qiqi.zhang@konghq.com>
Signed-off-by: ADD-SP <qiqi.zhang@konghq.com>
Signed-off-by: ADD-SP <qiqi.zhang@konghq.com>
Signed-off-by: ADD-SP <qiqi.zhang@konghq.com>
Signed-off-by: ADD-SP <qiqi.zhang@konghq.com>
Signed-off-by: ADD-SP <qiqi.zhang@konghq.com>
Signed-off-by: ADD-SP <qiqi.zhang@konghq.com>
Signed-off-by: ADD-SP <qiqi.zhang@konghq.com>
@ADD-SP ADD-SP force-pushed the add_sp/time-local-wheel branch from e9255ee to 64b138e Compare July 21, 2025 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate M-time Module: tokio/time R-loom-current-thread Run loom current-thread tests on this PR R-loom-multi-thread Run loom multi-thread tests on this PR R-loom-time-driver Run loom time driver tests on this PR T-performance Topic: performance and benchmarks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant