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

net/coap: Block optimizations #11057

Merged
merged 7 commits into from
Oct 4, 2019
Merged

Conversation

kb2ma
Copy link
Member

@kb2ma kb2ma commented Feb 24, 2019

Contribution description

While working on the Block implementation (#10732) we found several opportunities for optimization. However, we decided to wait until the implementation was complete before implementing them. This PR includes the improvements listed below.

This PR also completes the Block implementation!

Commit Notes
c02872f Adds coap_opt_put_uint() to write a generic uint-based option for the Buffer API. The Packet API already includes coap_opt_add_uint(). This function allows the implementation of simple options, like Content-Format, to inline this function. It also allows a user to easily add an option to a message for which there is not a specific implementation presently, like Max-Age or Size1.
1420c8e Reimplements coap_opt_put_blockN(), coap_put_option_ct(), and coap_put_option_block1() to inline coap_opt_put_uint(). Removes implementations of those functions.
d90f022 Reworks the static _slicer_blknum() into the more useful _slicer2blkopt(). The former function only calculated the block number from a slicer struct. The latter adds a more parameter to completely calculate the uint for the block option from a slicer struct. Also replaces three uses of _slicer_blknum() with _slicer2blkopt(), which also removes the duplicate calculation of the block option uint value.
d8ccda5 The previous commit removed the only use of coap_opt_put_block_object(), which was added during recent development for completion of block. This commit removes coap_opt_put_block_object().
0ff2856 The coap_get_blockN() functions were implemented separately. Only the defintiion of coap_get_block1() calculated the offset attribute for the coap_block1_t struct. This commit reworks the implementation to a single definition that calculates the offset, with inlines for the specific "blockN" functions.
789646e Fixes coap_block_object_init() to also calculate the offset attribute for coap_block1_t struct.

Testing procedure

Verify no regression by rerunning the test procedure in #11024 and #11056.

Issues/PRs references

Completes #10732.

@kb2ma kb2ma added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Area: CoAP Area: Constrained Application Protocol implementations labels Feb 24, 2019
@kb2ma kb2ma added this to the Release 2019.04 milestone Feb 24, 2019
@kb2ma kb2ma mentioned this pull request Feb 24, 2019
6 tasks
@kb2ma kb2ma force-pushed the coap/block_optimization branch from 789646e to b2c9080 Compare July 25, 2019 13:41
@kb2ma
Copy link
Member Author

kb2ma commented Jul 25, 2019

Rebased, including replacement of functionality in #11802 with the implementation here.

@benpicco
Copy link
Contributor

This one needs a rebase.

@kb2ma kb2ma force-pushed the coap/block_optimization branch from b2c9080 to c1aa872 Compare September 28, 2019 15:06
Copy link
Contributor

@fjmolinas fjmolinas left a comment

Choose a reason for hiding this comment

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

Some comments, otherwise I ran the functional tests and there seems to be no regression

sudo -E pytest block1_server_test.py 
========================================================= test session starts ==========================================================
platform linux -- Python 3.6.8, pytest-5.1.3, py-1.8.0, pluggy-0.12.0
rootdir: /home/francisco/workspace/riot-coap-pytest, inifile: pytest.ini
collected 6 items                                                                                                                      

block1_server_test.py ......                                                                                                     [100%]

========================================================== 6 passed in 25.57s ==========================================================

sudo -E pytest block2_server_test.py
========================================================= test session starts ==========================================================
platform linux -- Python 3.6.8, pytest-5.1.3, py-1.8.0, pluggy-0.12.0
rootdir: /home/francisco/workspace/riot-coap-pytest, inifile: pytest.ini
collected 4 items

block2_server_test.py .... [100%]

========================================================== 4 passed in 16.94s ==========================================================


sudo -E pytest block1_client_test.py 
========================================================= test session starts ==========================================================
platform linux -- Python 3.6.8, pytest-5.1.3, py-1.8.0, pluggy-0.12.0
rootdir: /home/francisco/workspace/riot-coap-pytest, inifile: pytest.ini
collected 1 item                                                                                                                       

block1_client_test.py .                                                                                                          [100%]

========================================================== 1 passed in 0.84s ===========================================================
sudo -E pytest block2_client_test.py 
========================================================= test session starts ==========================================================
platform linux -- Python 3.6.8, pytest-5.1.3, py-1.8.0, pluggy-0.12.0
rootdir: /home/francisco/workspace/riot-coap-pytest, inifile: pytest.ini
collected 3 items                                                                                                                      

block2_client_test.py ...                                                                                                        [100%]

========================================================== 3 passed in 2.62s ===========================================================

sys/net/application_layer/nanocoap/nanocoap.c Outdated Show resolved Hide resolved
@@ -1216,7 +1245,12 @@ size_t coap_put_option(uint8_t *buf, uint16_t lastonum, uint16_t onum, const uin
*
* @returns amount of bytes written to @p buf
*/
size_t coap_put_option_block1(uint8_t *buf, uint16_t lastonum, unsigned blknum, unsigned szx, int more);
static inline size_t coap_put_option_block1(uint8_t *buf, uint16_t lastonum,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we change this to coap_put_option_block()? and add option as a parameter?

Copy link
Member Author

Choose a reason for hiding this comment

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

How about actually deprecating this function in favor of using coap_opt_put_block1_control(), which already is used in the nanocoap_server example? One of my goals with this sequence of PRs was consistent names for block functions.

Either way, I would like to put the deprecation in a separate PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

@fjmolinas
Copy link
Contributor

@kb2ma once the final two comments are addressed feel free to squash :) and trigger the ci build

@kb2ma kb2ma force-pushed the coap/block_optimization branch from 12518ae to 5018e2c Compare October 2, 2019 09:58
@kb2ma kb2ma added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Oct 2, 2019
Copy link
Member Author

@kb2ma kb2ma left a comment

Choose a reason for hiding this comment

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

Blocking until I get a fix in for _size2szx().

/* Size exponent + 1 */
assert(szx >= 5);
return szx - 5;
return bitarithm_lsb(size) - 4;
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 think I was too aggressive by returning here. I'd like to restore the assert on the szx value. I'll add in a fix.

Apologies for the churn.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok!

Copy link
Member Author

Choose a reason for hiding this comment

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

Just pushed the fixup. Also added a comment to explain the sequencing of the offset subtraction.

@fjmolinas
Copy link
Contributor

@kb2ma Tests are still passing, please squash.

@kb2ma kb2ma force-pushed the coap/block_optimization branch from c49c8f4 to 2dc4209 Compare October 3, 2019 17:19
Copy link
Contributor

@fjmolinas fjmolinas left a comment

Choose a reason for hiding this comment

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

There are no new changes since last I tested. Some of my comments are still pending, but will be addressed in follow-up PR's, namely consistency across block function names.

There is no regression regarding #11024 and #11056. ACK!

@fjmolinas fjmolinas merged commit 7d7596e into RIOT-OS:master Oct 4, 2019
@fjmolinas
Copy link
Contributor

@kb2ma I would add some doc cleanup to the list #10732 to complete it :)

@kb2ma
Copy link
Member Author

kb2ma commented Oct 4, 2019

Thanks for all the testing and feedback with these PRs, @fjmolinas!

size_t coap_opt_put_block_object(uint8_t *buf, uint16_t lastonum,
coap_block1_t *block, uint16_t option);
size_t coap_opt_put_uint(uint8_t *buf, uint16_t lastonum, uint16_t onum,
uint32_t value);
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this also pass the remaining space available in buf so we don't silently overflow?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: CoAP Area: Constrained Application Protocol implementations CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR 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