Skip to content

sys/evtimer: fix 0 offset events#22026

Open
fabian18 wants to merge 2 commits intoRIOT-OS:masterfrom
fabian18:pr/evtimer_0_offset_fix
Open

sys/evtimer: fix 0 offset events#22026
fabian18 wants to merge 2 commits intoRIOT-OS:masterfrom
fabian18:pr/evtimer_0_offset_fix

Conversation

@fabian18
Copy link
Contributor

Contribution description

Something is weird in the evtimer. When a 0 offset event is added it seems like the timer IRQ does not fire.
I got the fix from AI actually 😅.
But I noticed in development that sometimes an event with 0 offset is stuck in the _nib_evtimer which prevents any further events.

This is not the case on native, but on same54-xpro.

Testing procedure

Added a test in tests/sys/evtimer Without the fix the 0 offset event does not trigger.
Try to run it with the fix and it triggers.

Issues/PRs references

@github-actions github-actions bot added Area: tests Area: tests and testing framework Area: timers Area: timer subsystems Area: sys Area: System labels Jan 29, 2026
@fabian18 fabian18 added the Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) label Jan 29, 2026
@crasbe crasbe added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jan 29, 2026
@riot-ci
Copy link

riot-ci commented Jan 29, 2026

Murdock results

✔️ PASSED

f892984 tests/sys/evtimer_msg: add test for 0 offset events

Success Failures Total Runtime
11004 0 11004 09m:01s

Artifacts

_update_head_offset(evtimer);
_add_event_to_list(evtimer, event);
/* drain zero-offset head immediately */
if (evtimer->events && evtimer->events->offset == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't want this to execute here (in calling context) without debate. It breaks the (maybe implicit) assumption that evtimer handlers are executed in the timer isr.

@fabian18
Copy link
Contributor Author

fabian18 commented Feb 1, 2026

More investigation shows that it works with increasing:

/**
 * @def     RTT_MIN_OFFSET
 *
 * @brief   The minimum offset to correctly set an rtt callback.
 *
 * If the callback is taking into account rtt_get_counter() then the rtt
 * might advance right between the call to rtt_get_counter() and
 * rtt_set_alarm(). If that happens with val==1, the alarm would be
 * set to the current time, which would then underflow. To avoid this,
 * the alarm should be set at least two ticks in the future.
 *
 * This value can vary depending on the platform.
 *
 */
#ifndef RTT_MIN_OFFSET
#define RTT_MIN_OFFSET (2U)
#endif

Confusing to me is that a timer offset of 1 works, but is also smaller than the default value of RTT_MIN_OFFSET.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: sys Area: System Area: tests Area: tests and testing framework Area: timers Area: timer subsystems CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants