-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Various Improvements and Fixes for etimer & timer #1265
base: master
Are you sure you want to change the base?
Various Improvements and Fixes for etimer & timer #1265
Conversation
The reason why the I haven't fully checked the code in this pull request, but I'd just like to check that the above reasoning still holds with the changes in this PR? |
Now that you mention it, there is one case where there would be a problem when calling I think I can fix this without adding next_to_expire back in. |
22c807b
to
7aa38b5
Compare
I just added the variable back in. Seems to be possible to get rid of |
@bkozak-scanimetrics I was about to propose a quick and dirty fix on how @adamdunkels how to detect that the value returned by |
249933b
to
bdabb08
Compare
Regarding the Travis failure, I just noticed it now. Not sure what's going on because the Travis build on my own account passed without any errors. Re-based to see if it fixes it. |
Yes actually I did notice this; I think I forgot to mention it in any commit message unfortunately. Thanks for pointing it out.
Just want to say that I completely agree with you here. Part of the motivation of this PR was to provide the |
Ok my own Travis build passed again. Hopefully we won't get the same problem on this build. |
bdabb08
to
4bc4b8b
Compare
I've performed a re-base. Although there were no merge conflicts, Travis is failing since one of the 6502 builds runs out of memory now. On the CC2650, this PR increases overall code size by about 90 bytes. As has been discussed on this page, this patch adds significant performance improvements, bug fixes and functionality so I think that a 90 byte flash cost is more than justified. I don't think that it makes sense for me to try and adjust this PR just to work around the limitations of the 6502 and its compiler. The 6502 build complains that it needs at least another 286 bytes of memory and I don't think that there is any reasonable way to make this change while still keeping all of the improvements from this PR unless separate conditionally compiled code is made just for the 6502. Furthermore, from what I have seen, attempts to optimize code for better memory consumption on the 6502 often result in worse code on other platforms; for example, one might manually inline a small (or once-called) function or make a local variable into a static variable in order to get a few extra bytes on the 6502. Finally, if anyone is going to optimize this code for the 6502 it won't be me since I have neither a machine to test on nor any interest in the platform. Considering all this, I request that the maintainers either find a way to reduce memory consumption for the 6502 in a different part of the code or consider dropping 6502 support altogether rather than drop this PR and all future PRs which affect the 6502 in a similar way. Otherwise, if anyone wants to try and modify this patch so that it will work with the 6502 once again, I'd appreciate it. |
} | ||
|
||
t_last->next = timer; | ||
timer->next = NULL; |
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.
The list is always sorted; and, it is searched linearly. Therefore, the first timer test is redundant; it stays true until after the second test has found the insertion point. Also, appending to the list is the same as inserting in front of the list's NULL
.
The above 10 lines can be replaced by this code:
if(etimer_lte(timer, t_this, now)) {
break;
}
t_last = t_this;
}
t_last->next = timer;
timer->next = t_this;
4bc4b8b
to
8ede3c6
Compare
@greg-king5 thanks for the review. I believe you're right and have added your suggested changes. I've already tested the code on my own Travis account and although everything else passes the 6502 build will still fail. |
8ede3c6
to
b5d3904
Compare
@greg-king5 has been kind enough to offer a patch to reduce the 6502's code usage. When testing on my own Travis account, this was enough for the 6502 test case to pass. I don't claim to understand exactly why this works so see the commit message of 30bf4d1 for details. |
I have a desire to allow for the complete elimination of sys tick interrupts. My primary motivation is to allow for a higher resolution of This can be done quite easily (I think) by adding support for an API call to set an RTC interrupt from the etimer module similar to how rtimer works. Since this PR contains some fairly major structural changes for etimer, however, I'd like to see this merged (or otherwise closed if there's a good reason to drop it) before I release any new work on etimer. Additionally I've been using this PR for months now with no issues so I think that it should me merged unless someone has a competing patch that does the job better. Could some maintainer who is responsible for |
I agree fully with your intent of getting rid of interrupt driven ticks. I will try to take some time within a few weeks and test and do a code review of this (if no one have done it before). |
Thanks @joakimeriksson I very much appreciate it. |
I tried the above patch since I was experiencing an issue with the CSMA where the queue was filled up and never emptied due to messed up timers. This happened randomly after hardware interrupts and I observed that the etimer_next_expiration_time is not updated after that. I added some debugging output to
After a while I see the following:
I'm not sure if this issue is just related to the JN516x platform since there was a big change in the clock module. However before and after this patch the issue still persists. |
Hi mguc,
the code is clearly wrong, as time_to_etimer is unsigned:
if(time_to_etimer < 0) {
Can you check changing the line to this helps?
if((int32_t)time_to_etimer < 0) {
Looks like this error was introduced when integer types were converted
to clock_time_t.
|
You are absolutely right. Your suggestion fixed the issue for me. I will make a PR for the JN516x platform concerning this problem. |
d1e64a7
to
5a2fd68
Compare
re-arranges some object modules, so that Contiki programs will fit into the fragmented memory maps of two 6502 platforms. This patch is local to those platforms; there are no side-effects.
Added the timer_cmp function so that we can compare two timers.
Replaced tabs with spaces and removed trailing whitespace.
the etimer module now uses a sorted list to track all of the etimers. Given that the etimer module would traverse the entire linked etimer list every time a timer was added or expired this can only improve performance. Now, we only need to traverse the entire list when adding, stopping, or adjusting an etimer. In addition, I have made various style improvements (to conform with the style guide) and other small changes to improve readability and performance. This commit optimized with help from github user greg-king5
Prep for the next commit. Add const to timer module params that don't change so that we don't have warnings when passing in const pointers.
Added the etimer_next_to_expire function as a superior version of etimer_next_expiration_time; the major benefits being: 1. We return NULL if no timers remaining 2. we can use the timer module functions to determine if the timer is expired, how long until it expires etc.
5a2fd68
to
8264260
Compare
Also updated code internal to timer to use timer_expired_at where appropriate. timer_expired_at computes whether some given timer will be expired at some given clock time (past, present or future).
I've made some changes to reduce code size on 6502 but Travis failed on the large-rpl build. Large RPL passed on my own account so it must be that same issue where the build randomly fails. Would someone be so kind as to restart it for me? |
⌛ |
Add LGTM config for native C extraction
This patch makes the following changes to the etimer and timer modules
etimer_next_expiration_time
. This will greatly cut down on the number of times that the linked list is fully traversed.*This is better than just returning the expiry time as does
etimer_next_expiration_time
because the timer structures carry more information than just the expiry time and because the existing timer module functions can be used to analyse the structure. For example, we might calltimer_expired
to find out if the time lies in the past.