-
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
net/gcoap: use sock_async and events #13386
Conversation
Rework from earlier custom event/msg handling.
Any idea where this increase is coming from specifically? If it is coming from |
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.
Codewise this looks good. Code is mostly just moved around and usages of msg
replaced with event
. Will do some testing after lunch break.
static void _on_resp_timeout(void *arg) { | ||
gcoap_request_memo_t *memo = (gcoap_request_memo_t *)arg; | ||
|
||
/* no retries remaining */ | ||
if ((memo->send_limit == GCOAP_SEND_LIMIT_NON) || (memo->send_limit == 0)) { | ||
_expire_request(memo); | ||
} | ||
/* reduce retries remaining, double timeout and resend */ | ||
else { | ||
memo->send_limit--; | ||
#ifdef CONFIG_GCOAP_NO_RETRANS_BACKOFF | ||
unsigned i = 0; | ||
#else | ||
unsigned i = COAP_MAX_RETRANSMIT - memo->send_limit; | ||
#endif | ||
uint32_t timeout = ((uint32_t)COAP_ACK_TIMEOUT << i) * US_PER_SEC; | ||
#if COAP_RANDOM_FACTOR_1000 > 1000 | ||
uint32_t end = ((uint32_t)TIMEOUT_RANGE_END << i) * US_PER_SEC; | ||
timeout = random_uint32_range(timeout, end); | ||
#endif | ||
event_timeout_set(&memo->resp_evt_tmout, timeout); | ||
|
||
ssize_t bytes = sock_udp_send(&_sock, memo->msg.data.pdu_buf, | ||
memo->msg.data.pdu_len, &memo->remote_ep); | ||
if (bytes <= 0) { | ||
DEBUG("gcoap: sock resend failed: %d\n", (int)bytes); | ||
_expire_request(memo); |
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.
Note to self: This was adapted from _event_loop
's GCOAP_MSG_TYPE_TIMEOUT
case.
Tested as proposed in Testing Procedures:
Timings between messages still look correct, however there are now 6 tries (as posed to just 5 in master).
(that the address changes is I think unrelated and due to #13362 being merged in the meantime ;-)) |
Are you sure this difference happens consistently? I tested several times on native and samr21-xpro and could not reproduce. In my tests, gcoap would send messages via tap to libcoap running on my workstation. I used ethos over USB for the samr21-xpro test. I set up libcoap's coap-server example to drop responses like this:
I have not tested between two samr21-xpro using the radio as it looks like you did. I wonder if you are seeing a spurious multipath reception on the sniffer rather than an extra send -- which is the basis for my question above. |
Thanks for analyzing this, so the major part seems to come from the
I'm using link-local addresses on the nodes, so multipath side-effects would be odd. It isn't a link-layer retransmission either, as can be seen in my screenshot. And yes, the 6 sends were reproducible. I'll test with your proposed setup to reconfirm. |
A question to your ethos setup: Do you have an application for this? Just replacing |
Between two |
I retried it for several times now but wasn't able to reproduce yesterdays results.. so maybe it was a fluke after all. |
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.
ACK from my side.
My answer is going to drift off topic, but I'm glad you asked. I have some extra build scripts and make files to help with alternative builds like this. Rather than post them for gcoap, I have added similar ones to the gcoap native LwM2M client I'm working on. Most of the files are in the client directory for that project. Start with To get to your question, I also have running.md documentation to help me remember how to do the setup. For ULA, see the section Single board client via USB. Notice the routing setup for both the board and the workstation. I don't know if the setup is logical, but it works. ;-) I originally created the ULA version when testing Wakaama, so it would fit on a samr21-xpro. I created the lwIP versions for use in environments required by my employer. The larger point i wanted to make is that I think we need two things to help with these variations:
|
Murdock has a couple of issues I need to address. |
This might be of tangential interest to you: #13427 |
@@ -185,7 +185,7 @@ static void _on_sock_evt(sock_udp_t *sock, sock_async_flags_t type) | |||
switch (coap_get_type(&pdu)) { | |||
case COAP_TYPE_NON: | |||
case COAP_TYPE_ACK: | |||
if (&memo->resp_evt_tmout.queue) { | |||
if (memo->resp_evt_tmout.queue) { |
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.
llvm found this even on native, and is absolutely right. The queue member in the timeout struct already is an address.
The conditional is false when CONFIG_GCOAP_NON_TIMEOUT
to 0 and sending a NON message type. I did test this configuration earlier, but didn't verify that the conditional was false. :-/
@@ -139,7 +139,7 @@ static void _on_sock_evt(sock_udp_t *sock, sock_async_flags_t type) | |||
ssize_t res = sock_udp_recv(sock, _listen_buf, sizeof(_listen_buf), | |||
0, &remote); | |||
if (res <= 0) { | |||
DEBUG("gcoap: udp recv failure: %d\n", res); | |||
DEBUG("gcoap: udp recv failure: %d\n", (int)res); |
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 issue is the usual problem with an ssize_t
type on pic32. You can see a similar cast just below.
Previously, this DEBUG statement was within #if macro that was always false in the CI. In other words, it's a bug fix. :-)
Addressed Murdock issues. @miri64, please confirm you're OK with these changes. |
Yepp. Just make sure you keep them in a separate commit if unrelated to the main change when squashing (which: please do! ;-)) |
There are also some vera++ warnings in the static tests you might want to address (you can ignore the line-length warnings for now, see #13400). |
The cast issue is a bug, so I'll make a new commit. The invalid address-of is just a faulty implementation in aba6873, which already is a bug fix commit in the PR, so I'll squash that in.
I saw those and was about to create a commit for them before I saw your message. But then I heard the little Martine voice in my head, and she said, "No, these changes are totally unrelated. Make another PR." I'll do that; should be quick and easy to review. |
Do I really come across as that strict? 🤔 😅 |
I'm sure she said it in a nice way. :-) |
Fixes bug found during rework for sock_async implementation.
Fixes bug found during rework for sock_async implementation.
89e350d
to
9b63abb
Compare
Squashed and added commit as discussed. I'll try this out with #13427 after the merge. |
Contribution description
From its inception gcoap has implemented asynchronous message processing. However, this implementation has included a custom
msg_t
queue handler for timeouts, as well as stack specific handling to break out of a blocking call tosock_udp_recv()
. The new sock_async and event queue modules implement generic message queue processing and timeout events that can supplant gcoap's custom solutions. This PR performs that replacement with no change in gcoap's feature set.Abstraction has a cost, and we measured the increase in size of the executable and RAM use. For the gcoap example built for a samr21-xpro:
We also saw RAM increase by 32 bytes via
ps
command.Testing procedure
Run the gcoap example or your favorite app. There should not be any change in functionality for client request handling or server response handling.
Issues/PRs references
N/A