-
Notifications
You must be signed in to change notification settings - Fork 8.5k
kernel: timer: Add timer observer hooks for extensibility #101462
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
base: main
Are you sure you want to change the base?
Conversation
|
Hello @VijsharQC, and thank you very much for your first pull request to the Zephyr project! |
4ecbb2f to
134c694
Compare
pdgendt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't comment on the usefulness of the feature, but I do have some implementation suggestions.
134c694 to
a854bfe
Compare
|
Hi @pdgendt, Thank you for the suggestions. Made changes as per those. |
a854bfe to
58046ee
Compare
pdgendt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs tests.
83c5b1b to
4b649fe
Compare
|
Can you provide examples of what this is useful for? |
|
There are few cases where timers may need to operate only in specific modes. This approach allows vendors to add custom functionality to manage those timers without making significant changes to Zephyr’s core timer implementation. |
4b649fe to
51227a3
Compare
pdgendt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still missing some sample/test, it's currently not being built in CI.
Ideally a sample is added with a use case to prove the usefulness of the feature.
51227a3 to
3b5d7ce
Compare
100b8bc to
0c9c1cd
Compare
c6ebddd to
d04c8c1
Compare
|
After adding the test code, I see that it is failing with below error. The failure is specific to the qemu_x86 board. INFO - 962/962 qemu_x86_tiny/atom kernel.timer.timer_observer FAILED Timeout (qemu 119.955s ) |
d04c8c1 to
85c0f72
Compare
| k_busy_wait(10 * 1000); | ||
|
|
||
| /* Verify timer on_init was called once */ | ||
| zassert_equal(obs.init_cnt, 1, "obs init count mismatch"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test assumes that there will only be a single timer in the system--an assumption that is unlikely to hold for all boards. A quick grep in the drivers/ directory shows that there are many drivers that use k_timer; without delving deep into their use cases, it seems reasonable that they may interfere with the expected counts. I'm not sure what the best way to resolve that would be. (It might be to just document it as a comment here noting that those boards should be excluded from the test as they show up).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or only increment the counters if the timer instance matches the test timer
static void obs_on_expiry(struct k_timer *timer)
{
if (timer == &test_periodic_timer) {
obs.expiry_cnt++;
}
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @pdgendt , @peter-mitsis - thank you for the suggestions.
I did try updating the observer callbacks so that they only increment counts when the timer instance matches test_periodic_timer. Unfortunately, the tests are still failing with the same issue.
As mentioned by @peter-mitsis, I’ve excluded qemu_x86_tiny for this test.
85c0f72 to
2ad224e
Compare
Introduce lifecycle observer callbacks (init, start, stop, expiry) for k_timer using Zephyr's iterable sections pattern. This enables external modules to extend timer functionality without modifying kernel internals. Signed-off-by: Vijay Sharma <[email protected]>
2ad224e to
2433cbf
Compare
|



Introduce lifecycle observer callbacks (init, start, stop, expiry) for k_timer using Zephyr's iterable sections pattern. This enables external modules to extend timer functionality without modifying kernel internals.