Skip to content

Conversation

@Fix-Point
Copy link
Contributor

@Fix-Point Fix-Point commented Jan 19, 2026

Summary

This series of commits refactors and simplifies the tickless scheduler's timer expiration code.

The key changes are:

  1. Removal of Redundant State (g_timer_interval): The global atomic variable g_timer_interval, which tracked the currently active timer interval, has been eliminated. The next expiration time is now calculated directly from the active watchdog list.
  2. Centralized Timer Adjustment Logic: The logic for adjusting the next timer tick (handling CONFIG_SCHED_TICKLESS_LIMIT_MAX_SLEEP and CONFIG_TIMER_ADJUST_USEC) has been moved from sched_timerexpiration.c into the watchdog module as a new inline function wd_adjust_next_tick(). This simplifies the scheduler's nxsched_timer_start() function.
  3. Elimination of Redundant Time Reads: A new global variable g_wdexpired is introduced to store the tick count at which the watchdog timer actually expired. This allows the scheduler event handler (nxsched_process_event) to use this pre-fetched value, avoiding a redundant call to up_timer_gettick() during timer expiration processing. The tick is only fetched again when reassessing the timer via nxsched_reassess_timer().
  4. Simplified Timer Start Abstraction: Helper functions (up_timer_tick_start, up_alarm_tick_start) are consolidated and the wd_timer_start() function is significantly simplified by using wd_adjust_next_tick().
  5. SCHED_RR Workaround: A workaround is added within nxsched_process_timer() to trigger the scheduler on every timer expiration when CONFIG_RR_INTERVAL > 0. This mitigates an existing issue where a preempted round-robin task's timeslice counter may not decrement correctly. This is temporary until the core SCHED_RR behavior is fixed.
  6. Utility Function: A new function wd_get_next_expire() is added to provide a safe way to get the next watchdog expiration time relative to the current time, returning 0 if it's in the past.

These changes improve code maintainability by reducing state duplication, centralizing configuration-dependent logic, and clarifying the flow of time information through the tickless scheduler and watchdog subsystem.

Impact

  • Users: No direct impact on the API. The internal behavior of the tickless scheduler is modified, which could theoretically affect timing precision and power consumption characteristics, but the functional interface remains the same.
  • Hardware: No impact on hardware support. The changes are at the OS scheduler level and rely on the existing up_timer_gettick(), up_timer_start(), and up_alarm_start() architecture interfaces.
  • Documentation: No documentation changes are required as this is an internal refactor.
  • Compatibility: The changes are intended to be fully compatible with existing use cases.

Testing

Internal CT passed. Tested on rv-virt:smp,ostest passed.

@github-actions github-actions bot added Area: OS Components OS Components issues Size: M The size of the change in this PR is medium labels Jan 19, 2026
jerpelea
jerpelea previously approved these changes Jan 19, 2026
@xiaoxiang781216
Copy link
Contributor

please fix the conflict @Fix-Point

This commit added wd_adjust_next_tick to simplify the scheduler.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
This commit simplified the sched_timerexpiration by removing the
interval.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
During the expiration, the g_wdexpired has already updated, so only nxsched_reassess_timer requires getting current tick again.
This commit avoided getting tick again in the nxsched_process_event.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
This commit simplified the wd_timer_start.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
@Donny9 Donny9 merged commit 702e1d9 into apache:master Jan 22, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: OS Components OS Components issues Size: M The size of the change in this PR is medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants