Skip to content

Document timer behavior after cancellation - #294

Merged
dylandreimerink merged 1 commit into
isovalent:masterfrom
NAME-ASHWANIYADAV:docs/timer-cancel-restart
Sep 7, 2026
Merged

dylandreimerink merged 1 commit into
isovalent:masterfrom
NAME-ASHWANIYADAV:docs/timer-cancel-restart

Conversation

@NAME-ASHWANIYADAV

Copy link
Copy Markdown
Contributor

Fixes #262

What

Documents what bpf_timer_cancel actually does to a timer, and the resulting restart flow, across four pages:

  • bpf_timer_cancel.md: replaces the "Docs could be improved" placeholder with a Usage section: canceling detaches the callback and drops the program reference ([drop_prog_refcnt (https://elixir.bootlin.com/linux/v6.18/source/kernel/bpf/helpers.c#L1457)), the timer stays initialized, and a re-arm needs bpf_timer_set_callback before bpf_timer_start, with a short code sample.
  • bpf_timer_start.md: note that -EINVAL also covers the canceled-timer case.
  • bpf_timer_set_callback.md: note that it must be called again after a cancel, with no re-init.
  • concepts/timers.md: one paragraph on the cancel/restart cycle, next to the existing re-scheduling paragraph.

Verified against the kernel

kernel/bpf/helpers.c, checked on both v6.18 and v5.15 (the release that introduced timers) - the semantics are identical:

  • bpf_timer_cancel -> drop_prog_refcnt: sets prog = NULL and callback_fn = NULL, the bpf_hrtimer allocation is untouched
  • bpf_timer_start -> if (!t || !t->cb.prog) return -EINVAL - which is why a canceled timer cannot be started directly
  • bpf_timer_set_callback -> _bpf_async_set_callback only requires the timer to be initialized, and re-assigns the callback plus program reference
  • __bpf_async_init -> returns -EBUSY when the timer is already initialized, so re-initializing is not just unnecessary but impossible

bpf_timer_cancel detaches the callback from the timer via
drop_prog_refcnt, so a subsequent bpf_timer_start fails with -EINVAL
until bpf_timer_set_callback has assigned a new callback. The timer
stays initialized through all of this, and re-running bpf_timer_init
on it returns -EBUSY. None of this was documented.

Verified against kernel/bpf/helpers.c on v6.18 and v5.15; the
semantics are unchanged since timers were introduced.

Fixes isovalent#262

Signed-off-by: Ashwani Yadav <22ashwaniyadav@gmail.com>
@NAME-ASHWANIYADAV

Copy link
Copy Markdown
Contributor Author

@dylandreimerink, could you please review this PR when you have a moment?

@dylandreimerink
dylandreimerink merged commit e1f6c0a into isovalent:master Sep 7, 2026
2 checks passed
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.

Document timer behavior after cancelation.

2 participants