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

ng_pktbuf: new default packet buffer implementation #3496

Merged
merged 4 commits into from
Jul 29, 2015

Conversation

miri64
Copy link
Member

@miri64 miri64 commented Jul 25, 2015

Implements the API proposed in #3458. It also simplifies a lot in the packet buffer. It still isn't perfect (there is happening way to much copying for my taste), but I think it's a first step in a better direction.

@miri64 miri64 added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Process: API change Integration Process: PR contains or issue proposes an API change. Should be handled with care. NSTF labels Jul 25, 2015
@miri64 miri64 added this to the Release 2015.06 milestone Jul 25, 2015
@miri64 miri64 force-pushed the ng_pktbuf/enh/new_default branch 3 times, most recently from e655e98 to a442bd4 Compare July 25, 2015 20:02

static inline bool _too_small_hole(_unused_t *a, _unused_t *b)
{
return sizeof(_unused_t) > (size_t)(((uint8_t *)b) - (((uint8_t *)a) + a->size));
Copy link
Member

Choose a reason for hiding this comment

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

is it really necessary to add a->size here? I assumed that the address of b is already at least a->size bytes next to a

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. It's not about the size between pointer a and pointer b (which would just be the size of chunk a plaus anything in-between), but the size of the space between the chunks represented by a and b. To put this graphically:

(((uint8_t *)b) - ((uint8_t *)a)):
 |------------|
+---------+  +---------+
+---------+  +---------+
 a            b

vs.

(size_t)(((uint8_t *)b) - (((uint8_t *)a) + a->size));
           |--|
+---------+  +---------+
+---------+  +---------+
 a            b

This is correcting for the fact, that I size-up the chunk to the next word-aligned pointer and the next size that would fit an _unused_t struct in _pktbuf_alloc()

@miri64
Copy link
Member Author

miri64 commented Jul 26, 2015

Tested successfully with 6LoWPAN in the iot-lab testbed in the following configurations:

  • with IPHC with payloads 10, 120, 240, 320 (ping6 100 <ip> <payload> 10)
  • without IPHC with payloads 10, 120, 240, 320 (ping6 100 <ip> <payload> 10)

You need the following PRs for it (or just use the commit abeb852 in my repository):

@miri64 miri64 force-pushed the ng_pktbuf/enh/new_default branch from 1481534 to 74c8cf8 Compare July 27, 2015 10:48
@miri64
Copy link
Member Author

miri64 commented Jul 27, 2015

Rebased to current #3458. Please merge this one and ignore #3458, which is not able to be merged on its own (I don't care to fix the old packet buffer for the new API when this PR deletes it)

@haukepetersen
Copy link
Contributor

Just had to think about it: I think it would make sense to rename this new implementation to pktbuf_static (and of course make it the default packet buffer implicitly)

@miri64
Copy link
Member Author

miri64 commented Jul 28, 2015

Fine by me.

@miri64
Copy link
Member Author

miri64 commented Jul 28, 2015

Renamed and made unittests only available for ng_pktbuf_static

@@ -218,6 +218,12 @@ ifneq (,$(filter ng_pktdump,$(USEMODULE)))
USEMODULE += od
endif

ifneq (,$(filter ng_pktbuf, $(USEMODULE)))
ifeq (,$(filter ng_pktbuf_dynamic, $(USEMODULE)))
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can make this more general: ifeq(,$(filter ng_pktbuf_%, $(USEMODULE)))?!

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@OlegHahm OlegHahm added the Community: Hack'n'ACK candidate This PR is a candidate for review and discussion during one of RIOT's monthly Hack'n'ACK parties label Jul 28, 2015
*/
void ng_pktbuf_reset(void);
Copy link
Member

Choose a reason for hiding this comment

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

For me that was a nice function...

Copy link
Member Author

Choose a reason for hiding this comment

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

ng_pktbuf_init() does the same but is now mandatory on first start ;-)

Copy link
Member

Choose a reason for hiding this comment

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

Ahh, cool! You think it's reasonable to spend a small comment there?

Copy link
Member Author

Choose a reason for hiding this comment

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

Tell me what to write apart from "initializes the packet buffer" and I'll do it :>

@PeterKietzmann
Copy link
Member

For the protocol: I'm running a test-application on the iot-lab_M3 node which sends 1000 UDP packets for payloads from 10:1:330 bytes/packet without a pause. No faults and the result looks valid.

if (size == 0) {
DEBUG("pktbuf: size == 0\n");
mutex_unlock(&_mutex);
return ENOMEM;
Copy link
Member

Choose a reason for hiding this comment

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

-ENOMEM

@PeterKietzmann
Copy link
Member

And again, to finish my protocol: I'm running a test-application on the iot-lab_M3 node which "virtually" receives 1000 UDP packets for payloads from 10:1:330 bytes/packet without a pause. No faults and the result looks valid. Of course, IPHC and fragmentation are enabled. Note: That was not possible with the old implementation. Häppi to see that :-)

@miri64 miri64 force-pushed the ng_pktbuf/enh/new_default branch from 04d7154 to d85a7bf Compare July 28, 2015 18:51
@PeterKietzmann
Copy link
Member

and green lights, btw

@miri64
Copy link
Member Author

miri64 commented Jul 28, 2015

Cenk found some last minute erroros

@PeterKietzmann
Copy link
Member

Hups, what did I see? There were no green lights, sry...

@miri64
Copy link
Member Author

miri64 commented Jul 28, 2015

No I just pushed something

@miri64 miri64 force-pushed the ng_pktbuf/enh/new_default branch 2 times, most recently from b32067e to cbc97a4 Compare July 28, 2015 19:31
@miri64
Copy link
Member Author

miri64 commented Jul 28, 2015

Added some last minute optimizations. :-)

@miri64 miri64 force-pushed the ng_pktbuf/enh/new_default branch 2 times, most recently from 2ae9b11 to 1d3abfa Compare July 28, 2015 19:46
size_t aligned_size = (size < sizeof(_unused_t)) ?
_align(sizeof(_unused_t)) : _align(size);
mutex_lock(&_mutex);
assert((pkt == NULL) || (pkt->data == NULL) || _pktbuf_contains(pkt->data));
Copy link
Member

Choose a reason for hiding this comment

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

This assert only checks if at least one condition is met, but should check that all of them are met.

Copy link
Member Author

Choose a reason for hiding this comment

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

Who coded this stuff? Certainly not me :D

@miri64 miri64 force-pushed the ng_pktbuf/enh/new_default branch 4 times, most recently from 3f4b39a to 9578ab9 Compare July 28, 2015 20:42
@OlegHahm
Copy link
Member

ACK

miri64 and others added 4 commits July 29, 2015 00:47
This simplifies the `ng_pktbuf` API by adding a new function
`ng_pktbuf_mark()` which takes over some functionality of
`ng_pktbuf_add()`. `size == 0` for `ng_pktbuf_add()` is now illegal.
@miri64 miri64 force-pushed the ng_pktbuf/enh/new_default branch from 9578ab9 to 377f5cc Compare July 28, 2015 22:48
@miri64
Copy link
Member Author

miri64 commented Jul 28, 2015

Some unittests were still failing… now everything should be alright (hopefully)

@miri64
Copy link
Member Author

miri64 commented Jul 28, 2015

Unittests succeeded \o/

miri64 added a commit that referenced this pull request Jul 29, 2015
ng_pktbuf: new default packet buffer implementation
@miri64 miri64 merged commit 3d99456 into RIOT-OS:master Jul 29, 2015
@miri64 miri64 deleted the ng_pktbuf/enh/new_default branch July 29, 2015 00:08
@miri64 miri64 added the Area: network Area: Networking label Sep 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: network Area: Networking CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Community: Hack'n'ACK candidate This PR is a candidate for review and discussion during one of RIOT's monthly Hack'n'ACK parties Process: API change Integration Process: PR contains or issue proposes an API change. Should be handled with care. Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants