-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
[Baremetal] Various minor changes to improve RAM measurements #2850
[Baremetal] Various minor changes to improve RAM measurements #2850
Conversation
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.
Thanks for making those changes! I found an issue with the size of a buffer, and the CI found another with the type/allocation of a variable - actually I stopped at the first issue in the CI, so perhaps it found others as well.
programs/ssl/ssl_client2.c
Outdated
@@ -75,8 +75,8 @@ int main( void ) | |||
#include <stdlib.h> | |||
#include <string.h> | |||
|
|||
#define MAX_REQUEST_SIZE 20000 | |||
#define MAX_REQUEST_SIZE_STR "20000" | |||
#define MAX_REQUEST_SIZE 100 |
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 don't think this is going to work well with ssl-opt.sh
. We have multiple tests with request_size=123
(arguably for no good reason, so this could be changed to a lower value), and some with request_size=$(( MAX_CONTENT_LEN + 1 ))
. However those test are skipped when MAX_CONTENT_LEN < 4096
, so perhaps here we could define MAX_REQUEST_SIZE
as either MAX_CONTENT_LEN + 1
or a lower value depending on the value of MAX_REQUEST_SIZE
(and leave appropriate comments here and in ssl-opt.sh
.
Alternatively, we could allow MAX_REQUEST_SIZE
to be defined on on the compiler's command line, providing only a default here, and defined a low enough value in baremetal.sh
. Perhaps that would be a bit cleaner than having non-trivial logic tying this file to ssl-opt.sh
.
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.
Oh yes, of course... thank you for spotting. I have reverted this change for now.
808f9f0
to
03e3751
Compare
Thank you @mpg for your review - I have reverted the change of |
/test |
This commit modifies the example programs ssl_client2 and ssl_server2 to allocate various structures on the heap instead of the stack. This allows more fine-grained memory usage tracking via valgrind massif.
03e3751
to
ead3aae
Compare
…t way when giving to functions.
0d0cfe9
to
9697401
Compare
Allocations are now done after command line parsing. Added more checks if allocations are needed and fixed baremetal tests with these defines.
9697401
to
52c9ecb
Compare
/test |
287f493
to
d2a63ed
Compare
/test |
d2a63ed
to
efba673
Compare
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.
One requested change, otherwise LGTM.
Override define MBEDTLS_ENTROPY_MAX_SOURCES from 1 to 3 in baremetal_test.h mbedtls_entropy_init adds 2 sources already so max must be 3 so that one source can be added with mbedtls_entropy_add_source.
66b39c9
to
99082ae
Compare
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.
Thank you for making the change, LGTM
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 is generally looking good! However, I found a possible memory error, and left a suggestion for an improvement.
Note: CI only failed in API-ABI check in pr-head job, while the same test passed in the pr-merge job. This is an artifact of the checking script, and not an indication that the PR breaks anything (actually the test passing in the pr-merge job confirms that the PR did not break the API or ABI), so can be ignored. |
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.
Thanks for fixing the issue and implementing the suggested improvement. Looks good to me!
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.
LGTM
CI passed, except for the API/ABI check which failed in pr-head and succeeded in pr-merge. As with other PRs, this only reflect a design issue versions picked by the API/ABI checker in the CI, not a problem in the PR: the fact the the check passed in pr-merge means the PR did not break the API or ABI. Therefore removing label "needs: CI". |
This has two approval, a passing CI (except for the known-questionable API/ABI checker in pr-head only, see above), and no conflict or prerequisite, so it's ready for merge. |
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.
LGTM
#endif | ||
|
||
#if defined(MBEDTLS_TIMING_C) | ||
#if !defined(MBEDTLS_SSL_CONF_SET_TIMER) && \ | ||
!defined(MBEDTLS_SSL_CONF_GET_TIMER) | ||
mbedtls_ssl_set_timer_cb( &ssl, &timer, mbedtls_timing_set_delay, | ||
mbedtls_ssl_set_timer_cb( ssl, &timer, mbedtls_timing_set_delay, |
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.
Trivial - Alignment is out on the next line, but it's not important.
This PR aims at making RAM measurements with
scripts/baremetal.sh --ram
more useful.Specifically, this PR:
ssl_client2
andssl_server2
to allocate various larger structures on the heap instead of the stack, in order to ease memory usage tracking with massif.ssl_client2
andssl_server2
to use a smaller request buffer in order to not inflate heap usage statistics with something not related to Mbed TLS' actual usage.ssl_client2
andssl_server2
to make use of the existing copyless CRT parsing APImbedtls_x509_crt_parse_der_nocopy()
.baremetal.h
config to allow only a single entropy source, which is likely enough for constrained environments, and significantly reduces the size ofmbedtls_entropy_context
.Changes to RAM measurements
Before: Max heap usage: 30832 (heap 7283+165, stack 23384)
After: Max heap usage: 11944 (heap 9437+259, stack 2248)
This does not reflect changes in actual RAM usage of the library, only in RAM usage of the test client used for the measurements by the script. The following effects can be observed:
main()
function, which was previously huge and has now been made much smaller, in part by moving the larger parts to the heap. Measured stack usage is now closer to that of the library.