Skip to content
This repository was archived by the owner on Apr 24, 2019. It is now read-only.

Memory optimizations #101

Closed
wants to merge 4 commits into from
Closed

Memory optimizations #101

wants to merge 4 commits into from

Conversation

TeroJaasko
Copy link
Contributor

No description provided.

@TeroJaasko
Copy link
Contributor Author

@anttiylitokola @kuggenhoffen @kjbracey-arm @karsev

otherwise block messages are passed to application */
unsigned mode:2; /**< STATIC etc.. */
bool free_on_delete:1; /**< 1 if struct is dynamic allocted --> to be freed */
} sn_nsdl_static_resource_parameters_s;

Choose a reason for hiding this comment

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

Verify the comments if they are valid.

unsigned access:4; /**< Allowed operation mode, GET, PUT, etc,
TODO! This should be in static struct but current
mbed-client implementation requires this to be changed at runtime */
unsigned registered:2; /**< Is resource registered or not */

Choose a reason for hiding this comment

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

Would be safer to use uint8_t.

Copy link
Contributor

Choose a reason for hiding this comment

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

see #100

@AnttiKauppila
Copy link

@artokin or @terhei Check from coap-service point of view

@@ -23,7 +23,7 @@
*/
#include <string.h>
#include <stdlib.h>

#include <assert.h>

Choose a reason for hiding this comment

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

Do not use assert for portability reasons in Mbed-client-c.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why not? Assert.h is part of C99 and we're already using it all over codebase without any problems so far.

Copy link
Contributor

@kjbracey kjbracey Dec 15, 2016

Choose a reason for hiding this comment

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

It's not used at all in any of the portable C/Nanomesh components. Is it getting used in the C++ bits?

We can't really assume we have a full "hosted" C99 library. But the minimum for a "freestanding" implementation is too tight, so we go a bit beyond that. So we take memcpy() and sprintf() from "hosted", but not fprintf(). I think assert() falls into the slightly-more-than-we-can assume fprintf() area.

My main concern is - does it actually do what you want on any given embedded platform, and do you end up accidentally pulling in a whole chunk of code to give you stderr for its output?

If you really want it, we can certainly create an NS_ASSERT in ns_types.h - it would map to MBED_ASSERT in mbedOS.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, some sort of tr_assert() extension to the trace library might make sense. You do really want the output going to the trace location, so that's presumably what a default ns_types.h implementation would do, in which case maybe it should just be in the trace to start with?

Don't forget the trace location isn't necessarily just a UART - it could be some sort of internal log-storage-for-later-extraction system. assert()'s default behaviour of "write to stderr" would not be helpful in that scenario.

Up to now, I've usually manually done tr_error() and return myself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought that the NDEBUG should get rid of any extra crap that assert() brings and that define should be anyway set on the release build versions.

That tr_assert() is a really good idea. Currently mbed-os' assert() is mostly visible only on debugger. If the assert fail or any other mbed os exception happens on tests, the test framework does not get any output and logs just "Dut1 timed out" or something equally useful.

Copy link
Contributor

Choose a reason for hiding this comment

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

True about NDEBUG, but if we were only thinking about NDEBUG, then there's never any issue.

The essence of the problem is "where does the output go", and so if we use tr_xxx rather than printf, we should use tr_error or a new tr_assert rather than assert. (Presumably a release build should also have the trace disabled?)

A secondary question to consider is "what happens after the output"? Standard assert() calls abort(), but what does that do in an embedded system? I believe MBED_ASSERT infinite loops, and a few of our own error handlers do the same.

That feels a bit more like a platform HAL thing, which isn't just covered by the existing trace. We do have a fairly-widely-implemented board reset call, but is halting better?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, removed asserts in #107.

if (temp_resource->resource_parameters_ptr) {
if (temp_resource->resource_parameters_ptr->registered == SN_NDSL_RESOURCE_REGISTERING) {
temp_resource->resource_parameters_ptr->registered = SN_NDSL_RESOURCE_REGISTERED;
if (temp_resource->static_resource_parameters) {

Choose a reason for hiding this comment

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

What is the reason for this check? (Only do what function name indicates if static resources are used?)
Is non-static resources handled elsewhere?

Copy link
Contributor

Choose a reason for hiding this comment

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

Fixed in #108

@@ -21,6 +21,7 @@
*/

#include <string.h>
#include <assert.h>

Choose a reason for hiding this comment

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

Don't use assert for portability reasons

Copy link

@AnttiKauppila AnttiKauppila left a comment

Choose a reason for hiding this comment

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

Remove assert calls from code, otherwise seemed to be ok.

@@ -583,7 +497,7 @@ extern int8_t set_NSP_address(struct nsdl_s *handle, uint8_t *NSP_address, uint1
* \return 0 Success
* \return -1 Failed to indicate that internal address pointer is not allocated (call nsdl_init() first).
*/
extern int8_t set_NSP_address_2(struct nsdl_s *handle, uint8_t *NSP_address, uint8_t address_length, uint16_t port, sn_nsdl_addr_type_e address_type);
extern int8_t set_NSP_address(struct nsdl_s *handle, uint8_t *NSP_address, uint8_t address_length, uint16_t port, sn_nsdl_addr_type_e address_type);
Copy link
Contributor

Choose a reason for hiding this comment

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

If you are changing API, can we also update this? set_DS_address( )?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, we added a IOTCLT-1322 task for this and the other cleanup items you suggested.

@terhei
Copy link
Contributor

terhei commented Dec 16, 2016

@peksaa01 - please check these modifications.

@yogpan01
Copy link
Contributor

@TeroJaasko Can you close this , now that you have this branch merged with the master ?

@mbed-ci
Copy link
Collaborator

mbed-ci commented Feb 24, 2017

Can't set status; build succeeded.

@mbed-ci
Copy link
Collaborator

mbed-ci commented Feb 24, 2017

Can't set status; build failed.

5 similar comments
@mbed-ci
Copy link
Collaborator

mbed-ci commented Feb 24, 2017

Can't set status; build failed.

@mbed-ci
Copy link
Collaborator

mbed-ci commented Feb 24, 2017

Can't set status; build failed.

@mbed-ci
Copy link
Collaborator

mbed-ci commented Feb 24, 2017

Can't set status; build failed.

@mbed-ci
Copy link
Collaborator

mbed-ci commented Feb 24, 2017

Can't set status; build failed.

@mbed-ci
Copy link
Collaborator

mbed-ci commented Feb 24, 2017

Can't set status; build failed.

@mbed-ci
Copy link
Collaborator

mbed-ci commented Feb 28, 2017

Can't set status; build succeeded.

@mbed-ci
Copy link
Collaborator

mbed-ci commented Feb 28, 2017

Can't set status; build failed.

5 similar comments
@mbed-ci
Copy link
Collaborator

mbed-ci commented Feb 28, 2017

Can't set status; build failed.

@mbed-ci
Copy link
Collaborator

mbed-ci commented Feb 28, 2017

Can't set status; build failed.

@mbed-ci
Copy link
Collaborator

mbed-ci commented Feb 28, 2017

Can't set status; build failed.

@mbed-ci
Copy link
Collaborator

mbed-ci commented Feb 28, 2017

Can't set status; build failed.

@mbed-ci
Copy link
Collaborator

mbed-ci commented Feb 28, 2017

Can't set status; build failed.

@mbed-ci
Copy link
Collaborator

mbed-ci commented Feb 28, 2017

Can't set status; build succeeded.

@mbed-ci
Copy link
Collaborator

mbed-ci commented Feb 28, 2017

Can't set status; build succeeded.

@mbed-ci
Copy link
Collaborator

mbed-ci commented Feb 28, 2017

Can't set status; build failed.

5 similar comments
@mbed-ci
Copy link
Collaborator

mbed-ci commented Feb 28, 2017

Can't set status; build failed.

@mbed-ci
Copy link
Collaborator

mbed-ci commented Feb 28, 2017

Can't set status; build failed.

@mbed-ci
Copy link
Collaborator

mbed-ci commented Feb 28, 2017

Can't set status; build failed.

@mbed-ci
Copy link
Collaborator

mbed-ci commented Feb 28, 2017

Can't set status; build failed.

@mbed-ci
Copy link
Collaborator

mbed-ci commented Feb 28, 2017

Can't set status; build failed.

@mbed-ci
Copy link
Collaborator

mbed-ci commented Feb 28, 2017

Can't set status; build succeeded.

@TeroJaasko TeroJaasko force-pushed the memory_optimizations branch from 61ba22a to 9d41fe2 Compare March 3, 2017 10:32
@TeroJaasko
Copy link
Contributor Author

Closing this PR as the content has been merged to master via separate PR.

@TeroJaasko TeroJaasko closed this Mar 3, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants