Skip to content

Conversation

@jukkar
Copy link
Member

@jukkar jukkar commented Apr 16, 2020

Instead of allocating an endpoint union and then freeing it almost immediately, allocate the ep from stack instead of heap.
This contains also Ravi's SRC/DST rename patch from the TCP2 unit test PR #24346

Copy link
Contributor

@ozhuraki ozhuraki left a comment

Choose a reason for hiding this comment

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

@jukkar

I would suggest a following approach here, i.e.:

  1. Externalize the memory management from tcp_endpoint_new()
  2. tcp_endpoint_new() -> tcp_endpoint_set()

What do you think?

@jukkar
Copy link
Member Author

jukkar commented Apr 16, 2020

What do you think?

Agreed, the allocation and setting are not needed in the same function. I can look into it.

@jukkar jukkar added the DNM This PR should not be merged (Do Not Merge) label Apr 16, 2020
jukkar added 2 commits April 17, 2020 15:54
In tcp_endpoint_cmd() we allocate and then almost immediately
destroy the allocated endpoint. This is quite inefficient so
use a endpoint from stack in the compare.

Separate endpoint allocation from value setting so the caller
can decide how the endpoint union values are set.

Signed-off-by: Jukka Rissanen <[email protected]>
It is useful to know which test fails to semaphore timeout so
add line number of the failing test to assert print.

Signed-off-by: Jukka Rissanen <[email protected]>
@jukkar jukkar force-pushed the tcp2-endpoint-cmp branch from 0f4b7b6 to 3bc67f0 Compare April 17, 2020 12:56
@jukkar jukkar removed the DNM This PR should not be merged (Do Not Merge) label Apr 17, 2020
@jukkar
Copy link
Member Author

jukkar commented Apr 17, 2020

Separated the allocation and setup of endpoint union.

@zephyrbot zephyrbot added the area: Tests Issues related to a particular existing or missing test label Apr 17, 2020
Copy link
Contributor

@ozhuraki ozhuraki left a comment

Choose a reason for hiding this comment

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

LGTM.

A few improvements per your judgement.

}

ep->sin.sin_port = src ? th->th_sport : th->th_dport;
static union tcp_endpoint *tcp_endpoint_set(union tcp_endpoint *ep,
Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest to change the return type to bool. This way it would be easier to do the error handling more clear and intuitive inside this function and in places of its usage.

Copy link
Member Author

Choose a reason for hiding this comment

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

I did not want to change the current behaviour too much. So new tcp_endpoint_set() can be put to same place where tcp_endpoint_new() was earlier. Actually we do not seem to handle the out-of-mem case very well in current code either. Hmm, I will send another PR that adds more error checks, will check also would it be better to change the return type.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, this can be done later. These (handling out or memory and more explicit/clear error handling) were my points.

Alternative approach to consider later is just to embed endpoints into struct tcp and to drop the heap allocations.

Copy link
Member Author

Choose a reason for hiding this comment

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

Alternative approach to consider later is just to embed endpoints into struct tcp and to drop the heap allocations.

Yes, that would be better way indeed.

union tcp_endpoint *ep_new = tcp_endpoint_new(pkt, which);
bool is_equal = memcmp(ep, ep_new, tcp_endpoint_len(ep->sa.sa_family)) ?
false : true;
union tcp_endpoint ep_tmp = { 0 }, *ep_ptr;
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps, ep_ptr is extra here, &ep_tmp can be passed right to memcmp().


conn->dst = tcp_endpoint_new(pkt, TCP_EP_SRC);
conn->src = tcp_endpoint_new(pkt, TCP_EP_DST);
conn->dst = tcp_endpoint_set(tcp_endpoint_new(pkt), pkt, TCP_EP_SRC);
Copy link
Contributor

Choose a reason for hiding this comment

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

Per your judgement, consider the first comment (tcp_enpoint_set() -> bool), might make the error/reporting handling more clear.

@jukkar jukkar merged commit cb4c09d into zephyrproject-rtos:master Apr 19, 2020
@jukkar jukkar deleted the tcp2-endpoint-cmp branch April 19, 2020 08:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Networking area: Tests Issues related to a particular existing or missing test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants