-
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
ng_pktbuf: new default packet buffer implementation #3496
Conversation
e655e98
to
a442bd4
Compare
|
||
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)); |
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.
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
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.
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()
Tested successfully with 6LoWPAN in the iot-lab testbed in the following configurations:
You need the following PRs for it (or just use the commit abeb852 in my repository):
|
1481534
to
74c8cf8
Compare
Just had to think about it: I think it would make sense to rename this new implementation to |
Fine by me. |
Renamed and made unittests only available for |
@@ -218,6 +218,12 @@ ifneq (,$(filter ng_pktdump,$(USEMODULE))) | |||
USEMODULE += od | |||
endif | |||
|
|||
ifneq (,$(filter ng_pktbuf, $(USEMODULE))) | |||
ifeq (,$(filter ng_pktbuf_dynamic, $(USEMODULE))) |
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.
I think we can make this more general: ifeq(,$(filter ng_pktbuf_%, $(USEMODULE)))
?!
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.
done
*/ | ||
void ng_pktbuf_reset(void); |
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.
For me that was a nice function...
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.
ng_pktbuf_init()
does the same but is now mandatory on first start ;-)
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.
Ahh, cool! You think it's reasonable to spend a small comment there?
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.
Tell me what to write apart from "initializes the packet buffer" and I'll do it :>
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; |
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.
-ENOMEM
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 :-) |
04d7154
to
d85a7bf
Compare
and green lights, btw |
Cenk found some last minute erroros |
Hups, what did I see? There were no green lights, sry... |
No I just pushed something |
b32067e
to
cbc97a4
Compare
Added some last minute optimizations. :-) |
2ae9b11
to
1d3abfa
Compare
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)); |
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 assert only checks if at least one condition is met, but should check that all of them are met.
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.
Who coded this stuff? Certainly not me :D
3f4b39a
to
9578ab9
Compare
ACK |
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.
9578ab9
to
377f5cc
Compare
Some unittests were still failing… now everything should be alright (hopefully) |
Unittests succeeded \o/ |
ng_pktbuf: new default packet buffer implementation
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.