Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Contribution description
This PR adds an abstraction for allocating packets from a network stack or static buffer.
The motivation behind this is:
At the same time if we want to have MAC and PHY layers that are independent to the network stack, we need an interface for allocation.
dev->driver->recv
(see [RFC] netdev: change receive mechanism #11652)If CONFIG_NETBUF_DISABLE_STACK_ALLOC==0, it's necessary to define a
netbuf_stack_alloc
function for every stack.How to use
Let's assume there's a radio API for reading data from the framebuffer:
Depending on how the netbuf is initialized, it's possible to either get a buffer from the stack allocator or from a static buffer.
Let's assume GNRC has the following
netbuf_stack_alloc
function:Some examples:
Considerations about the RX procedure
I wrote this patch that overloads the "recv" function of netdev to receive a
netbuf
instead of a buffer, and removed the "drop" and "get packet length" logic.The "recv" function will read the pkt_len, try to get a buffer from the netbuf and write directly to that buffer. The frame buffer is read once and the logic is simpler now.
It also makes the binary smaller from:
to
And calling
netif->ops->recv()
is 6-8% faster with this method.Testing procedure
make doc
Issues/PRs references
It's related to the PHY/MAC rework proposed in #11483
#11652