-
Notifications
You must be signed in to change notification settings - Fork 82
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
Some 64-bit milliseconds tick values were not migrated to 32-bit #209
Comments
Agreed: I was aware of this but it is kind of a ticklish thing to change, need to check each one to make sure we're not introducing a new problem. Thanks for the ones you've spotted here, what I will do is search the codebase for I had wondered if there is an argument for creating a macro which performs the compare "safely", and which would fall-through if the tick wraps, though the macro would need to be named very well in order that the person writing the code knows how it will behave, since the macro is now hiding the truth. Anyway, maybe we can discuss this later. |
As discussed, I have created a branch which integrates your proposed fixes here and in #207/#208, and also introduces a pair of macros, You can find a preview of the branch here: https://github.com/u-blox/ubxlib/tree/preview_fix_tick_wrap_rmea Note that this has NOT BEEN tested properly yet, since a key part of our test system is down. The test system should be fixed on Monday, at which point I can begin running proper tests. Obviously with such a wide change I'm concerned that I've typed in something wrong, maybe got the sense of a check upside-down: please, if you have the time, give it a thorough review. All feedback welcomed. |
If I may ask - why use a macro for the tick comparison functions instead of a |
Hi: only because |
But I could go either way of course, just seems a bit more "embedded" to use a macro, which guarantees a specific behaviour irrespective of toolchain. |
This is largely true. The nuance is complicated but I'm so used to always having optimization turned on. For the three primary arm targeting c compilers (gcc, clang, and armcc), with any level of optimization All three compilers do support the I generally live on -O1, -Og, or -Os. In my experience with gcc, all of them will pick up the hint correctly and avoid emitting an out-of-line version when unnecessary. I also find that an attached debugger will better follow the code path of the inline function, allowing easier line steps through it, while a macro can only be stepped over or instruction stepped. I'm just being an evangelist for header delcared |
OK, I can be persuaded to go for |
You're welcome to name it whatever you want; it's not my codebase after all. I have a different perspective on things again so I'll share for posterity. Wrapping SchmappingThe thing is, it's not that it returns If there's any caveats to list, it would be that this is only valid within the range What's in a MillisecondThis can be nice to have in the signature, but truthfully it doesn't matter what unit the On a different evangelism note, |
We make My concern remains that I have got a comparison the wrong way around somewhere in this relatively broad change; I will merge the change when you have confirmed when you are happy that has not happened. |
Branch is now updated with the new form, do let me know when you are happy with it and I will merge it to |
Been looking at this again trying to resolve issues running ubxlib past INT32_MAX rollover. Had the following comments:
Unfortunately, I don't really have a great way of pulling this down and testing it at the moment. Our fork diverged way back at 1.2.0; not sure what the executive decision will be on updating. |
Ooo, well spotted, will fix.
Understood, will modify in next revision.
Interesting, hadn't appreciated that but it does seem to be the case that relying on the linker is not so wise. Will modify.
Well I guess you could apply the changes manually to places you know/care about; with the exception of the one you spotted above they were reasonably easy to search for. Either way the result will require a careful review. |
Changes now applied to the preview branch, see here: https://github.com/u-blox/ubxlib/tree/preview_fix_tick_wrap_rmea Thanks again for the feedback. I'm not going to merge this change into |
So we've made progress on handling the Lines 1243 to 1248 in 3cf5348
What if it's been more than There are a couple of different approaches to solving this sort of problem. The first is to explicitly check for values in that range. With the current code that would look like a timeout implementation below: static U_INLINE bool uPortTickTimeExpiredMs(int32_t startTimeMs,
int32_t timeoutMs)
{
int32_t delta = uPortGetTickTimeMs() - startTimeMs;
return (delta > timeoutMs) || (delta < 0);
} The second way this is often resolved is to just used unsigned math for expiration values, since the negative values we had to explicitly check for before are simply large values which will always exceed the timeout. Both of these approaches map only the yellow area above and below as within the timeout value. This more tightly bounds the potential waiting time to the potential timeout window anyways, so worst case the check will result in the timeout to be observed in code. If that's not sufficient, the only way is to maintain these timeout values, essentially checking that they are within the expected value and bringing them within range or invalidating them every 2^31 ticks. This is a lot of complexity and overhead and generally it's acceptable to have the application wait up to the specified timeout anyways in the exceedingly rare case this occurs. Note that a similar relationship is true with the current state of the comparisons for "stop" values instead of "start" values with a timeout. These map I'm curious if there was a reason the portable layer chose An additional spot we have identified this style of is issue is below: Lines 2003 to 2006 in a2d986e
Another potential source of issues worth revisiting is the use of Lines 751 to 755 in 3cf5348
This check has to be removed to prevent immediate timeout in these cases. The good news on this one is that, currently, there does not seem to be a code path which calls this without first setting |
All good stuff, give me a little time to process... |
@warasilapm: have been discussing with Michael today, hope to have next revision tomorrow. |
Branch is now updated. This is the "Michael edition": a This new API is used in all cases where time calculations are performed, aside from one case in BLE and the lock timer in the AT Client (which has been pretty darned thoroughly tested and doesn't quite fit the pattern). Just about every file in |
@mazgch has made initial comments on the branch (thanks Michael). I have addressed these, I think, but it was getting quite difficult for Michael to view (the baseline for the current preview branch is also pretty old now) so I have (a) deleted the old preview branch, (b) created a new branch preview_fix_tick_wrap_2_rmea and (c), in order to make commenting hopefully easier, I have made this branch a PR #225 to this repo (rather than our internal development repo). I won't merge this PR, it will only be for comments. |
@warasilapm: in the hope that it will enable you to comment directly on #225 I have sent you an invitation to this repo as a read-only collaborator. Or you can also just comment here of course. |
@RobMeades As far as I know, I can comment on PRs and submit code review on PRs in public repositories. I just can't be used as an "approving" review for the purposes of code review requirements, etc. As such, I have declined the invitation for now; if there are other features you need me to have access for in the future I'll let you know. I'll still take a look at the changes in #225 as I am able. |
@RobMeades If memory serves, you should even be able to request review from me on the PR without me as a collaborator. |
@warasilapm: I understand from separate e-mail communication that you cannot use a new release of Please advise. |
@RobMeades Did you develop a test case where the tick value is initialized close to the 2^31 and 2^32 rollover values? |
Yes, we do this on test instance 23 (where EDIT: for context, the complete test run on that instance takes just under one hour. |
Okay sounds good! Just wanted to make sure that was being covered explicitly since that's the main advantage I could provide with testing on our application. I may be able to find some time to review the PR you put up in the next couple of days but you are correct in that the takeaway in the email from our side today is a) our version is not synchronized with latest ubxlib so it's challenging for me to work with, b) we aren't updating to latest ubxlib on this release cycle, and c) there are other immediate priorities for me during the work day over reviewing your PR. |
Got it: in that case I will wait until late Friday evening UK time before I go ahead with things on our side; there are reasons for me not to upset the applecart before then. |
FYI, #225 is about to enter our internal review process; once it has passed that it should appear on |
@warasilapm: the change has now passed testing, review, and is pushed to |
I'm good to close the issues for now. |
It would appear at some time in the past (I believe here), the portable API was changed from 64-bit millisecond ticks to 32-bit milliseconds ticks. In general, this was migrated successfully. However, there are still a number of 64-bit millisecond time values which would more correctly be 32-bit values, since that matches the portable API's type. None of these included here strictly cause issues, but they are confusing and their use could conceivably lead to issues with misuse in the future. See attached patch.
I may have missed some uses; perhaps a more thorough review is in order.
The text was updated successfully, but these errors were encountered: