Skip to content
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

MAJOR CHANGE: uTimeout API. #225

Closed
wants to merge 2 commits into from
Closed

Conversation

RobMeades
Copy link
Contributor

@RobMeades RobMeades commented Apr 4, 2024

A new common API, uTimeout, is added and all timeouts are routed through it. This API performs time comparisons correctly with unsigned 32 bit arithmetic to ensure that timeouts are not affected if they happen to cross the 32-bit wrap point, which will occur every 50 days for a millisecond tick; otherwise there were instances where a timeout could potentially get "stuck" for 25 days (the unsigned 32-bit wrap length for a millisecond tick).

The implementation of the API includes the ability to speed up the apparent wrap-rate of the underlying tick; this is used on test instance 23 (which includes cellular, GNSS and short-range module types) to give it a good thrashing.

Our thanks to warasilapm for raising this issue and my thanks to mazgch for providing the solution.

NOTE: this PR will not be merged it is simply posted here to make it possible for warasilapm to comment on it directly and for him to be able to see any comments made by mazgch.

A new common API, uTimeout, is added and all timeouts are routed through it.  This API performs time comparisons correctly with unsigned 32 bit arithmetic to ensure that timeouts expire correctly if they happen to cross the 32-bit wrap point, which will occur every 50 days for a millisecond tick; otherwise there were instances where a timeout could potentially get "stuck" for 25 days (the unsigned 32-bit wrap length for a millisecond tick).

The implementation of the API includes the ability to speed up the apparent wrap-rate of the underlying tick; this is used on test instance 23 (which includes cellular, GNSS and short-range module types) to give it a good thrashing.

Our thanks to warasilapm for raising this issue and _my_ thanks to mazgch for providing the solution.
Copy link
Contributor

@mazgch mazgch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RobMeades Added several small comments and suggestions, but it looks really good and in my view cleaner.

ble/src/u_ble_sps_intmod.c Outdated Show resolved Hide resolved
ble/src/u_ble_sps_intmod.c Outdated Show resolved Hide resolved
ble/src/u_ble_sps_intmod.c Outdated Show resolved Hide resolved
common/at_client/src/u_at_client.c Outdated Show resolved Hide resolved
common/at_client/test/u_at_client_test_data.c Show resolved Hide resolved
x = send(sock, (const void *) pData, sizeBytes - sentSizeBytes, 0);
if (x > 0) {
sentSizeBytes += x;
pData += x;
U_TEST_PRINT_LINE("sent %d byte(s) of TCP data @%d ms.",
sentSizeBytes, (int32_t) uPortGetTickTimeMs());
sentSizeBytes, uPortGetTickTimeMs());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so me need absolute ms here ?

@@ -254,7 +256,7 @@ static void rxTask(void *pParameter)
pTestConfig->bytesReceived, 0);
if (sizeBytes > 0) {
U_TEST_PRINT_LINE("received %d byte(s) of data @%d ms.",
sizeBytes, (int32_t) uPortGetTickTimeMs());
sizeBytes, uPortGetTickTimeMs());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ms remove ?

x = zsock_send(sock, (const void *) pData, sizeBytes - sentSizeBytes, 0);
if (x > 0) {
sentSizeBytes += x;
pData += x;
U_TEST_PRINT_LINE("sent %d byte(s) of TCP data @%d ms.",
sentSizeBytes, (int32_t) uPortGetTickTimeMs());
sentSizeBytes, uPortGetTickTimeMs());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remoive @ms or make it relative ?

@@ -1511,7 +1514,7 @@ U_PORT_TEST_FUNCTION("[port]", "portOs")
U_PORT_TEST_ASSERT(errorCode == 0);
U_PORT_TEST_ASSERT(gTaskHandle != NULL);

U_TEST_PRINT_LINE("time now %d ms.", (int32_t) uPortGetTickTimeMs());
U_TEST_PRINT_LINE("time now %d ms.", uPortGetTickTimeMs());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this all have relative times to the start ? use uTimeoutStart and elapsed ?
Just consistency not anything wrong here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found it useful to have the timestamps in front of me when initially debugging this, kind of easier to visualise.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, you want to see how the packet timing when the go out, and at the same time wouldn't an elapsed ms time since start be even more useful, so it keeps the numbers less random and small ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe; I think it probably depends how you want to look at things. Given a set of times I can write them on a line and get a feeling for the pattern; provided one isn't running ubxlib on Windows or Linux, the MCU we are running on will have been booted just a short time before and so the numbers will be small. I know I could do the same with time differences, just that I recall finding this clearer to stuff into my tiny brain :-).

wifi/test/u_wifi_captive_portal_test.c Outdated Show resolved Hide resolved
Test: 1 2 4.1 4.2 4.3.0 4.3.1 4.4.0 4.4.1 5.1.0 5.1.1 5.2.0 5.2.1 5.3 5.4 6.1.0 6.1.1 6.2.0 6.2.1 7 8
@mazgch
Copy link
Contributor

mazgch commented Apr 6, 2024

@RobMeades in the latest commit where you removed the durationMs in at client test aroud lines 950-970 you are once using utimeoutStop.timeoutStart and in the timeoutStart to replace the similar durationMs timeoutCheck

@RobMeades
Copy link
Contributor Author

RobMeades commented Apr 6, 2024

@mazgch: yes, well spotted, the subset of tests I ran on that commit didn't include ones that ran that particular AT Client test, when I ran a more complete test that one failed; fixed on my local branch, didn't bother pushing it back here.

@RobMeades RobMeades closed this Apr 24, 2024
@RobMeades RobMeades deleted the preview_fix_tick_wrap_2_rmea branch April 24, 2024 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants