-
Notifications
You must be signed in to change notification settings - Fork 2.1k
sys: add evtimer WIP #5999
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
sys: add evtimer WIP #5999
Conversation
|
@kaspar030 what about kaspar030#19? |
|
Sorry wrong link. Corrected in edit. |
miri64
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.
Some changes I already introduced in kaspar030#19
sys/evtimer/evtimer.c
Outdated
| DEBUG("evtimer_add(): adding event with offset %"PRIu32"\n", event->offset); | ||
|
|
||
| _update_head_offset(evtimer); | ||
| _add_event_to_list((evtimer_event_t*)&evtimer->events, event); |
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.
Why the cast and why the address operator here?
sys/evtimer/evtimer.c
Outdated
| evtimer->events = NULL; | ||
| } | ||
|
|
||
| #if ENABLE_DEBUG == 1 |
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 requires any external caller to edit this file internally (which also causes printing of the messages above). The compile should optimize it away if it isn't called. Alternatively, put this function in another file (if you don't trust the compiler optimization).
| * @brief Integer divide val by 125 | ||
| * | ||
| * This function can be used to convert uint64_t microsecond times (or | ||
| * intervals) to miliseconds and store them in uint32_t variables, with up to |
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.
milliseconds
sys/evtimer/evtimer.c
Outdated
|
|
||
| evtimer_msg_event_t *mevent; | ||
| while ((mevent = (evtimer_msg_event_t *)_get_next(evtimer))) { | ||
| msg_send_int(&mevent->msg, mevent->msg.sender_pid); |
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.
Send to sender_pid? Also: isn't this value usually uninitialized by the user?
Easy fix: see here
|
By playing with it, I think I found a possible bug: Then, I checked and found that |
| { | ||
| uint32_t delta_sum = 0; | ||
|
|
||
| while (list->next) { |
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.
Maybe list-next is wrongly placed here.
when firstly add an event, i.e., the first element of evtimer->events, which is list here, is NULL. But list->next may not be NULL, and the following execution may lead to chaos...
In my test, when adding the first event, it goes into the while loop, which I think it is not as we expected. :-)
|
|
||
| static void _del_event_from_list(evtimer_event_t *list, evtimer_event_t *event) | ||
| { | ||
| while (list->next) { |
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.
Similar issue here.
sys/include/evtimer.h
Outdated
| struct evtimer_event { | ||
| evtimer_event_t *next; | ||
| uint32_t offset; | ||
| }; |
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.
Do you think we can add a expired bool value into the evtimer_event_t structure, which I think should be commonly used by users? :-)
@miri64 If not, I think I will add it (expired) into my gnrc_mac timeout module which will probably be the wrapper of evtimer module.
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.
@zhuoshuguo it's more RAM saving to implement expired as a function if you actually need it (though usually it is more advisable to just react via callback to an expired event ;-)): You could check the event list if the event is still contained.
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.
@miri64 I think you are right~ 😄 Thanks!
|
Add checking event running/scheduled functionality (see add_check_event_sched) which I think also enables checking event expired. Should be at least useful for me. 😄 |
Sorry, what was a too-quickly fix in the last commit. Both functions' logics required to get a pointer to pointer to the first list element in order to work, which I diffed out accidentaly. I've moved the pointer logic into the functions now. |
|
@kaspar030 Sorry for my impetuous action.. |
|
@kaspar030 Sorry for my impetuous action..
Don't be sorry, thanks for fixing my mess!
|
|
@kaspar030 can you provide [edit]documentation[/edit] (and maybe even tests)? I need to use this soon-ish for NDP. Let's merge this with #6000 later on (especially since we need to overhaul IPC to use thread flags for my use-case anyways to make it useful for my context anyways :-/). |
| * @return (val / 125) | ||
| */ | ||
| static inline uint32_t div_u64_by_125(uint64_t val) | ||
| { |
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.
Since when do we use two spaces?
|
Also, please consider kaspar030#22. This streamlines the message-based API a little bit. |
|
Also doesn't build atm... Will see, if I can provide a fix. |
|
Ah, the changes in #5608 were the problem. |
|
I guess we postpone then. |
|
I will be also thankful if this PR will get merged soon, since my |
|
@kaspar030 any news on this? What should be done in #6554 at this point concerning this PR? |
|
PING? |
|
Adopted in #6767 |
|
Closed in favour of 6767. Thanks for taking over! |
I have this timer module lying around. It's design goals are:
I ended up with using a single pointer and a 32bit value per timer, making it possible to have a timers that only use 8 bytes on a 32bit platform.