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

netdev ethernet: deal with too small packet buffer #5229

Merged
merged 2 commits into from
Apr 20, 2016

Conversation

OlegHahm
Copy link
Member

@OlegHahm OlegHahm commented Apr 1, 2016

Rationale: some drivers, e.g. the Ethernet drivers, require a minimum size for the packet buffer. This commit introduces an optional minimal size that can be overwritten from the application.

I reworked this PR to introduce a temporary buffer inside the Ethernet drivers themselves, instead of reallocating on the packet buffer. IMO that's a cleaner solution as it reduces the lines of code and makes it simpler. It introduces more statically allocated memory, but this memory is necessary with the current implementation anyway (it just moves from pktbuf to the driver), but at least fails at build time if not available.

Let the native port check for a too small pktbuf size and adjust it.

Additionally this PR removes the (now not longer needed) hack from gnrc_minimal_networking's Makefile and handle native the same as any other platform.

Without this PR the default example won't work on native (or other boards with an Ethernet device). Thanks for reporting, @LudwigKnuepfer.

@OlegHahm OlegHahm added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Area: network Area: Networking Discussion: RFC The issue/PR is used as a discussion starting point about the item of the issue/PR Area: drivers Area: Device drivers GNRC labels Apr 1, 2016
@OlegHahm OlegHahm added this to the Release 2016.04 milestone Apr 1, 2016
@kaspar030
Copy link
Contributor

This breaks if multiple modules define a minimum size.

@OlegHahm
Copy link
Member Author

OlegHahm commented Apr 1, 2016

Any better idea?

@kaspar030
Copy link
Contributor

Without this PR the default example won't work on native (or other boards with an Ethernet device).

Could you elaborate why?

Any better idea?

Define an ethernet pseudomodule, make all ethernet drivers depend on it (same with other network device types), then use those pseudomodules to fix minimum pktbuf size.

@OlegHahm
Copy link
Member Author

OlegHahm commented Apr 1, 2016

Without this PR the default example won't work on native (or other boards with an Ethernet device).

Could you elaborate why?

Because the Ethernet drivers always allocate a full Ethernet frame in the beginning and only reallocate later.

@kaspar030
Copy link
Contributor

kaspar030 commented Apr 1, 2016 via email

@OlegHahm
Copy link
Member Author

OlegHahm commented Apr 1, 2016

Define an ethernet pseudomodule, make all ethernet drivers depend on it (same with other network device types), then use those pseudomodules to fix minimum pktbuf size.

I don't see why I need a pseudomodule if we have already netdev2_eth, but the question is mostly: where would you put this minimum pktbuf size?

@kaspar030
Copy link
Contributor

I don't see why I need a pseudomodule if we have already netdev2_eth

yeah, just use that.

but the question is mostly: where would you put this minimum pktbuf size?

Why not exactly where you put with this PR?

@OlegHahm
Copy link
Member Author

OlegHahm commented Apr 1, 2016

So, then you propose to leave this PR as it is?

@kaspar030
Copy link
Contributor

So, then you propose to leave this PR as it is?

No, I meant instead of checking for "GNRC_PKTBUF_MIN_SIZE" in pktbuf.h, check for "MODULE_NETDEV2_ETH" and if true, set ethernet's minimum size.

@OlegHahm
Copy link
Member Author

OlegHahm commented Apr 1, 2016

Ah, but I was actually looking for a way to avoid more ifdefs and particular ifdefs checking for particular modules. Imagine we have hundred of network drivers with different requirements on the minimum packetbuffer size.

IMO the ideal solution would be to define this size somewhere in the device's header, but I don't know how to make sure that this headers gets included before pktbuf.h is parsed.

@kaspar030
Copy link
Contributor

Ah, but I was actually looking for a way to avoid more ifdefs and particular ifdefs checking for particular
modules. Imagine we have hundred of network drivers with different requirements on the minimum
packetbuffer size.

I imagine. Ugly. But currently we have one, and a handful would be manageable.
The solution of this PR only works for exactly one, and IMHO ifdefs within makefiles are even more ugly than ifdefs within C files.

IMO the ideal solution would be to define this size somewhere in the device's header, but I don't know
how to make sure that this headers gets included before pktbuf.h is parsed.

Reminds me of my snippets PR.

@kaspar030
Copy link
Contributor

Another solution would be to only allocate the maximum pktsnip size within the ethernet drivers (or a little bit less).

@OlegHahm
Copy link
Member Author

OlegHahm commented Apr 2, 2016

Instead of allocating it in the packet buffer, you mean? Might be somewhat cleaner and would allow us to get rid of this realloc-call.

On 2 April 2016 09:16:43 CEST, Kaspar Schleiser notifications@github.com wrote:

Another solution would be to only allocate the maximum pktsnip size
within the ethernet drivers (or a little bit less).


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub:
#5229 (comment)

Join the RIOT
http://www.riot-os.org

@kaspar030
Copy link
Contributor

kaspar030 commented Apr 2, 2016 via email

@OlegHahm
Copy link
Member Author

OlegHahm commented Apr 2, 2016

Hm, why not simply using a temporary static buffer inside the driver? Would simplify the code and fail at bukd time if not enough memory is available.

MTU is not a fixed value in GNRC.

On 2 April 2016 10:14:23 CEST, Kaspar Schleiser notifications@github.com wrote:

Instead of allocating it in the packet buffer, you mean? Might be
somewhat cleaner and would allow us to get rid of this realloc-call.

No, I meant something like setting an MTU dependent on pktbuf size, or
checking the minimum pktbuffer size before allocating, or sth like
that.


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub:
#5229 (comment)

Join the RIOT
http://www.riot-os.org

@OlegHahm
Copy link
Member Author

OlegHahm commented Apr 2, 2016

How about this solution?

@OlegHahm OlegHahm changed the title gnrc pktbuf: introduce minimum size for pktbuf netdev ethernet: deal with too small packet buffer Apr 3, 2016
@OlegHahm
Copy link
Member Author

OlegHahm commented Apr 3, 2016

Hm, just realized that this won't work.

@OlegHahm
Copy link
Member Author

OlegHahm commented Apr 3, 2016

Ah, no, my mistake. It should work. Forget the previous comment.

@kaspar030
Copy link
Contributor

How about this solution?

But this allocates the needed space again in the pktbuf, right? Then it essentially doubles the needed space.

@kaspar030
Copy link
Contributor

If it just wraps the buffer, it needs to be locked, and only one ethernet packet can be in flight at one time.

@OlegHahm
Copy link
Member Author

OlegHahm commented Apr 3, 2016

But this allocates the needed space again in the pktbuf, right? Then it essentially doubles the needed space.

It allocates the spaced that is actual need in the pktbuffer, yes. I think if we waste 1.5kB in the driver anyway, that doesn't make things much worse.

Can you explain (once again) why this alloc-realloc mechanism is required for the Ethernet driver but not for other radio drivers? Maybe we can get completely rid of this hack?

@kaspar030
Copy link
Contributor

What was the rationale again of lowering the default pktbuf size? IMHO we should just up it again, all our MCU's have that memory.

@miri64
Copy link
Member

miri64 commented Apr 8, 2016

Just another idea: Since this is a native related issue, how about fixing it there: We are on native, so why not use a temporary buffer that we can malloc() in the netdev2_tap driver where we copy the data from instead of the file buffer of the TAP interface? Then recv() could return the actual length of the packet instead of the maximum length.

@OlegHahm
Copy link
Member Author

OlegHahm commented Apr 8, 2016

@kaspar030 was against this.

else
CFLAGS += -DGNRC_PKTBUF_SIZE=512 -DGNRC_IPV6_NC_SIZE=0
endif
CFLAGS += -DGNRC_IPV6_NETIF_ADDR_NUMOF=4 -DGNRC_IPV6_NC_SIZE=1
Copy link
Contributor

Choose a reason for hiding this comment

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

the NC_SIZE is different than before, is that a problem?

Copy link
Contributor

Choose a reason for hiding this comment

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

solved offline

@kaspar030
Copy link
Contributor

pls squash

@OlegHahm OlegHahm added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable labels Apr 18, 2016
@OlegHahm
Copy link
Member Author

Removed reverted (and reverting) commits.

@OlegHahm OlegHahm added the CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable label Apr 18, 2016
@OlegHahm
Copy link
Member Author

There were two small glitches revealed by the CI. Can I squash directly?

@haukepetersen
Copy link
Contributor

yes, please

Rationale: the netdev2_tap Ethernet driver for native requires to temporarily store at least a maximum sized Ethernet frame.
The workaround for the pktbuf size is not longer needed, since native itself assures a big enough buffer.
Using a neighbor cache size of 1 is mandatory for all platforms when compiling pedantically.
@OlegHahm OlegHahm added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Apr 20, 2016
@OlegHahm
Copy link
Member Author

Squashed.

@haukepetersen haukepetersen added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Apr 20, 2016
@haukepetersen
Copy link
Contributor

restarted Murdock

@haukepetersen
Copy link
Contributor

ACK once Murdock agrees.

@miri64 miri64 merged commit c24e91d into RIOT-OS:master Apr 20, 2016
@miri64 miri64 added the Process: needs backport Integration Process: The PR is required to be backported to a release or feature branch label Apr 20, 2016
@miri64
Copy link
Member

miri64 commented Apr 20, 2016

Please provide a backport.

@miri64 miri64 removed the Process: needs backport Integration Process: The PR is required to be backported to a release or feature branch label Apr 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: drivers Area: Device drivers Area: network Area: Networking CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Discussion: RFC The issue/PR is used as a discussion starting point about the item of the issue/PR Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants