-
Notifications
You must be signed in to change notification settings - Fork 2k
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 new timer subsystem #2926
Conversation
Hm, didn't we talk about that relying on a 1MHz timer is not a good idea? |
Just a (maybe not so tiny) issue: the current timer system revealed a lot of bugs particularly on the 16-bit (aka MSP430) platforms. So, I think it is required to test this on these boards. Caveat: so far, we don't have periph/timer there. |
Uh, I thought that we agreed that we could get a timer close (small factor) to that and then integrate this factor. |
I did some tests with both 24bit and 16bit timers, so they should work with this, but yeah, please break it. ;) |
A question came up when developing: Currently, removal of a timer would be O(n) with n being the number of active timers. It is possible to get this to O(1) by using doubly linked lists, but that would increase the timer struct by 4 byte (from 20 to 24), and increase the codesize because of the handling of that pointer. Opinions? |
I think O(n) is perfectly fine for timer removal as long as this is not called internally for whatever reasons. Calling Edit: For me this is a obvious case for memory efficiency over speed performance as long as it is not required to call this function from a critical context (e.g. ISR). |
Actually I use it in the Neighbor Discovery (though I don't know if my usage is correct): Neighbor Discovery messages are not really periodical but have random resend times, as soon as a new message is send out. So what I currently do is e.g. vtimer_remove(&iface->rtr_adv_timer);
vtimer_set_msg(&iface->rtr_adv_timer, interval, thread_getpid(), NG_NDP_SEND_RTR_ADV, pkt); |
The current usage of |
@OlegHahm What bug is that? Thinking about it, O(n) in this case will be a couple of instructions per timer. IMHO that would be acceptable, considering that everywhere else the additional instructions for filling the second pointer in the lists are saved. Currently, at each short timer overflow (e.g., every 71,6 minutes for 1mhz 32bit timers, more often for 16bitters), the ISR does a copy of long timers into the short timer list. This is also O(n) with n being the number of timers that have to be copied. I don't know how to make this O(1) without using a lot more lists... |
@kaspar030, to be honest, I don't remember. That was more than a year ago. I think we realized a race condition if the timer fires while it's getting deleting or something like this. So to be on the safe side we prepended every timer_set with a timer_delete. However, it might be that the bug has been fixed in the mean time. |
Ah, so people set timers that are already set, with a different target time? I need to check for that. |
KISS: vtimer2. |
What about ttimer (pronounced like tea timer)? 🍵 |
Yes, I think I remember again what the problem was: if you set the same timer twice, it's added to the queue again and creates a circle. |
I'm wondering too if this is not a too limiting decision. Can really every platform so far provide a 1 MHz timer? Because it looks like Freescale's Freedom boards are set up so that the low power timer could only use the 32 kHz clock as source in the low power modes (but I have to recheck that in detail). |
The low-power timer in Kinetis processors can only run at 1 kHz or 32.768 kHz, at least on K60. All other timers stop when entering the power saving modes, so they are not suitable for using as a wakeup source. |
the plan is to use a two-timer system, one with higher resolution and a fall-back to the lower resulution low power timer. |
I don't understand the Travis failures.
but timer_periodic_wakeup was never built for any platform during the compile test.
|
@gebart I've moved up timer_periodic_wakeup one but forgot to change the Makefile's $RIOTBASE setting. |
Maybe I should remove the example until all platforms support periph/timer, or the test can depend on FEATURE_PERIPH_TIMER... What do you think? |
I think the example itself is useful. I think using FEATURES_PERIPH_TIMER would be the proper way to filter out the unsupported platforms. |
|
||
kernel_pid_t me = thread_getpid(); | ||
|
||
xtimer_set_wakeup(&xtimer, 1<<31, me); |
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.
fails on avr8,
change to 1ul<<31
or some variant of ((uint32_t)1 << 31)
Apart from squashing, travis seems happy. |
|
Feel free to review and ACK this during tonight's session, I will not be participating however. I feel like this PR has become quite mature now. |
ACK once Travis is happy |
kicked Travis, errors seemed to be unrelated. |
Travis is happy, GO! |
sys: add new timer subsystem
Everybody, thanks a lot for reviewing! |
This is my work-in-progress new timer implementation.
Please take a look...
The working title is "wtimer", but as that is hard to pronounce in english, I'm very open to suggestions.It's now called xtimer, leaving room for two more tries! ;)
In order to actually try the code, I've adapted vtimer_msg to this API, the test is in test/wtimer_msg.
(PR depends on #2870 so it can be tested on native).To do:
use slow low power timer or RTC if available(let's get this in first)Optional: