Skip to content

sched: Add max delay tick limitation for wdog/wqueue. #16394

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

Merged
merged 2 commits into from
May 27, 2025

Conversation

Fix-Point
Copy link
Contributor

@Fix-Point Fix-Point commented May 16, 2025

Summary

This PR fixes bugs in the wqueue and wdog modules. When delay is the maximum ticks (CLOCK_MAX >> 1) or SCLOCK_MAX, If there are expired wdog timer in the wdog queue, clock_compare might be incorrect.

E.g. Current tick is 123, and there is an expired wdog timer with the expired ticks 100. If we insert a wdog timer with delay CLOCK_MAX >> 1, where the absolute ticks is 123 + CLOCK_MAX >> 1, then clock_compare(100, 123 + CLOCK_MAX >> 1) will return false, leading to the new wdog timer queued before the expired wdog timer.

So we limited the delay ticks to CLOCK_MAX >> 2, which is 2 30 1 or 2 62 1 . Assume all expired wdog timer can be processed within WDOG_MAX_DELAY ticks after the expiration, this ensure the correct enqueue of the wdog timer.

Besides, this PR changed the semantic of the wd_start. So we should also change the wdog_test. See apache/nuttx-apps#3076.

Impact

This PR affects the wqueue and wdog modules, especially the semantic of the wd_start.

Testing

Tested on QEMU/x86_64, sim and QEMU/riscv32.

@github-actions github-actions bot added Area: Documentation Improvements or additions to documentation Area: OS Components OS Components issues Size: S The size of the change in this PR is small labels May 16, 2025
acassis
acassis previously approved these changes May 20, 2025
@jlaitine
Copy link
Contributor

jlaitine commented May 22, 2025

Hm. I am experiencing an assertion in the test on rv-virt:smp, with updated nuttx-apps and this PR still:

[CPU1] Assertion failed : at file: wdog.c:312 task(CPU1): ostest process: ostest 0x80011b46

Perhaps check what happens in the test when interval -1 is passed as an argument to wd_start... ?

@Fix-Point
Copy link
Contributor Author

Hm. I am experiencing an assertion in the test on rv-virt:smp, with updated nuttx-apps and this PR still:

[CPU1] Assertion failed : at file: wdog.c:312 task(CPU1): ostest process: ostest 0x80011b46

Perhaps check what happens in the test when interval -1 is passed as an argument to wd_start... ?

Rebased the PR and tested with the latest nuttx-apps(a5709532577ff0b3276a78bc8d278e8bf8a1b037). It works fine for me.

This commit added max delay tick limitation for the workqueue.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
@jlaitine
Copy link
Contributor

Yes, I can confirm that it now works, I had a messed-up environment myself.

@xiaoxiang781216
Copy link
Contributor

@Fix-Point why ci still fail?

This commit changed the type of the delay ticks to the unsigned, which can reduce the useless branch conditions
Besides, this commit added max delay tick limitation to fix incorrect timing behavior if we delay SCLOCK_MAX in the SMP build.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
@jerpelea jerpelea merged commit 947856e into apache:master May 27, 2025
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Documentation Improvements or additions to documentation Area: OS Components OS Components issues Size: S The size of the change in this PR is small
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants