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

Code Size: Add the TFM Medium Profile config files and the option to track code size changes #7426

Conversation

aditya-deshpande-arm
Copy link
Contributor

Description

This PR:

  1. Adds slightly modified versions of both regular and PSA-style config header files from TFM under configs/.
  2. Modifies code_size_compare.py so that it separates the sizes of crypto, x509, and tls in the csv report and allows for the use of alternative configurations (like the TFM Baremetal one).

Should resolve #7360. Will also lay the foundations for addressing #7361 and #7359.

Gatekeeper checklist

  • changelog not required: scripts only (unless we feel adding a new configuration warrants one)
  • backport not required: scripts only
  • tests not required: scripts only

@aditya-deshpande-arm
Copy link
Contributor Author

aditya-deshpande-arm commented Apr 13, 2023

@adeaarm please confirm you're happy for us to update our copies of the three files updated by 86fc300 in Mbed TLS.

@tom-daubney-arm tom-daubney-arm self-requested a review April 13, 2023 14:52
@adeaarm
Copy link
Contributor

adeaarm commented Apr 13, 2023

@adeaarm please confirm you're happy for us to update our copies of the three files updated by 86fc300 in Mbed TLS.

would it be possible to have the relicensing only in its own PR?

@aditya-deshpande-arm
Copy link
Contributor Author

@adeaarm please confirm you're happy for us to update our copies of the three files updated by 86fc300 in Mbed TLS.

would it be possible to have the relicensing only in its own PR?

Sure, I'll remove the re-licensing commit from this PR and open a separate PR as soon as this one is merged.

@aditya-deshpande-arm aditya-deshpande-arm force-pushed the code-size-tracking branch 4 times, most recently from 7132f5c to dc057df Compare April 17, 2023 15:00
@aditya-deshpande-arm aditya-deshpande-arm added needs-review Every commit must be reviewed by at least two team members, needs-ci Needs to pass CI tests size-optimisation labels Apr 17, 2023
@yanrayw yanrayw self-requested a review April 23, 2023 07:38
@yanrayw
Copy link

yanrayw commented Apr 24, 2023

@aditya-deshpande-arm Is this ready for review? CI still reports a coding style error. It looks easy to fix.

@tom-daubney-arm
Copy link
Contributor

@yanrayw I have already begun my review because I believe it is ready but it would be nice to get the CI to go green to be sure

@tom-daubney-arm
Copy link
Contributor

@aditya-deshpande-arm
When looking at the configs you rbought over from tf-m, tfm_mbedcrypto_config_profile_medium.h has an extra config option in it compared to what I see in the tf-m version. The config option is MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER. Have you added this in yourself? I am trying to establish why it is in one and not the other when the otherwise all the config files are identical.

Copy link
Contributor

@tom-daubney-arm tom-daubney-arm left a comment

Choose a reason for hiding this comment

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

Generally speaking this PR does look good. The python is nice and it does work; I have tested it and used it. I have requested changes for the following reasons (note I have left comments on most of these things but will summarise here):

  • When bringing the configs across I see a slightly different version of tfm_mbedcrypto_config_profile_medium.h which does not include the config option MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODE_OWNER. I would like to know if this has been added in manually and if so it should probably be mentioned why.
  • Several commit messages contain the word "also" which shows the commit is doing more than one thing. We try to stick to granular commits that do one thing, and one thing only, where possible. I think these commits should be broken up.
  • In the larger commits, for example the 3rd commit, if it is not possible or practical to split them up a bit more then a more detailed commit message would be appreciated.
  • Commits that apply corrections in response to CI failures should really have those changes applied in their original commits as this leads to a cleaner commit history.
  • There are some small gramatical nits (see comments) that are not a big deal on their own but would make sense to clean them up since other changes are being made.

Please write on here for any clarifications and I will help you get this over the line.

@@ -290,6 +303,11 @@ def main():
help="new revision for comparison, default is the current work \
directory, including uncommitted changes."
)
parser.add_argument(
"-c", "--config", type=str, default="default",
help="optional configuration for Mbed TLS. Default uses current \
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Capital "O" on optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The existing help messages in the file start with lowercase letters too so I've just replicated that style for consistency. If we change this to a capital O then we should change the messages for all options..

@@ -262,13 +266,15 @@ def _gen_code_size_csv(self, revision, git_worktree_path):
sizes_dict = self._gen_code_size_report(revision, git_worktree_path)

def write_dict_to_csv(d):
for (f,s) in d.items():
csv_file.write(f'{f}, {s.text}, {s.data}, {s.bss}, {s.total}\n')
for (f, s) in d.items():
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the reviews had not started at the time these changes were made, it would be better to fix them via an interactive rebase so that the commit history is cleaner, i.e. fixing this in the original commit rather than applying a commit at the end which fixes the problem.

x509_text = result.decode()
# Size for libmbedtls.a
try:
result = subprocess.check_output(
["size -t library/libmbedtls.a"], cwd=git_worktree_path, shell=True
)
except subprocess.CalledProcessError as e:
self._handle_CalledProcessError(e,git_worktree_path)
self._handle_called_process_error(e, git_worktree_path)
Copy link
Contributor

Choose a reason for hiding this comment

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

Fixing pylint should ideally be done in a separate commit. This commit was primarily about removing f-strings so really it should only do this one thing.

As is the case with my comment around the f-strings, it would be better to fix the pylint related errors in their original commit, via an interactive rebase, rather than applying a fix-up commit to the end since this will generate a cleaner git history.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, ideally that would be in a separate commit, but at this point, let's not use Aditya's limited time rewriting the commit history

@aditya-deshpande-arm
Copy link
Contributor Author

aditya-deshpande-arm commented Apr 24, 2023

I looked into this - it looks like in between me cloning TFM and your review this option has been removed from the config. I'll rebase and take the latest config from TFM.

@gilles-peskine-arm
Copy link
Contributor

When looking at the configs you rbought over from tf-m, tfm_mbedcrypto_config_profile_medium.h has an extra config option in it compared to what I see in the tf-m version. The config option is MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER

The TF-M configs are at https://git.trustedfirmware.org/TF-M/trusted-firmware-m.git/tree/lib/ext/mbedcrypto/mbedcrypto_config . All of them enable MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER. Since https://git.trustedfirmware.org/TF-M/trusted-firmware-m.git/commit/?id=34a0ffd0d14bf98c8dc517e3982c4ed8cec9f56f this is done via CMakeLists.txt.

@aditya-deshpande-arm aditya-deshpande-arm added needs-work and removed needs-review Every commit must be reviewed by at least two team members, labels Apr 25, 2023
* you wish to support.
*
* Note that this option is meant for internal use only and may be removed
* without notice.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe make a comment here that TF-M does it in CMakeLists.txt?

Copy link
Contributor

@adeaarm adeaarm Apr 25, 2023

Choose a reason for hiding this comment

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

Just to add some more on this point, the problem in TF-M is that we want to use the same config file without duplicating the file between the client view of the API (NS or other partitions) and the server view of the API (the crypto service and the crypto_platform_keys components). For this reason we have removed that define from the config so that the file can be shared, but we enforce it on the crypto service and crypto_platform_keys components via a CMakelists.txt option. This is basically the consequence of TF-M keeping a different view of the key encodings between clients and server, i.e. the service.

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've added a comment here explaining that TF-M enables this option using CMake instead of in the config. I've also pointed to this discussion for reference.

@aditya-deshpande-arm aditya-deshpande-arm force-pushed the code-size-tracking branch 3 times, most recently from 800dc05 to 67b1258 Compare April 25, 2023 19:18
@tom-daubney-arm tom-daubney-arm added needs-review Every commit must be reviewed by at least two team members, enhancement and removed needs-work needs-ci Needs to pass CI tests labels Apr 26, 2023
@yanrayw yanrayw added the needs-review Every commit must be reviewed by at least two team members, label May 12, 2023
@daverodgman daverodgman added needs-reviewer This PR needs someone to pick it up for review priority-high High priority - will be reviewed soon size-s Estimated task size: small (~2d) labels May 16, 2023
Copy link
Contributor

@tom-daubney-arm tom-daubney-arm left a comment

Choose a reason for hiding this comment

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

Thanks for the changes @yanrayw. I have checked all the different options for the script and they are working now. I think this is ready to go.

LGTM.

@daverodgman
Copy link
Contributor

I've just tested this on #7578 with ./scripts/code_size_compare.py -o 04059d2e60f1c65f14c19a36d2 -n c5205a311acf5e3 -c tfm-medium -a aarch32 and it crashed:

The following command: make -j lib CC=armclang                   CFLAGS='--target=arm-arm-none-eabi -mcpu=cortex-m33 -Os             -DMBEDTLS_CONFIG_FILE=\"../configs/tfm_mbedcrypto_config_profile_medium.h\"             -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE=\"../configs/crypto_config_profile_medium.h\" '  failed and exited with code 2
Process output:
 b'make[1]: Entering directory \'/home/davrod01/code/mbedtls/temp-04059d2e60f1c65f14c19a36d208110fea6fd7ef/library\'\n  CC    aes.c\n  CC    aesni.c\n  CC    aesce.c\n  CC    aria.c\n  CC    asn1parse.c\n  CC    asn1write.c\n  CC    base64.c\n  CC    bignum.c\n  CC    bignum_core.c\nIn file included from aria.c:26:\nIn file included from ./common.h:26:\nIn file included from ../include/mbedtls/build_info.h:193:\n../include/mbedtls/check_config.h:453:2: error: "MBEDTLS_PK_C defined, but not all prerequisites"\n#error "MBEDTLS_PK_C defined, but not all prerequisites"\n ^\nIn file included from aesce.c:43:\nIn file included from ./common.h:26:\nIn file included from ../include/mbedtls/build_info.h:193:\n../include/mbedtls/check_config.h:453:2: error: "MBEDTLS_PK_C defined, but not all prerequisites"\n#error "MBEDTLS_PK_C defined, but not all prerequisites"\n ^\nIn file included from aesni.c:25:\nIn file included from ./common.h:26:\nIn file included from ../include/mbedtls/build_info.h:193:\n../include/mbedtls/check_config.h:453:2: error: "MBEDTLS_PK_C defined, but not all prerequisites"\n#error "MBEDTLS_PK_C defined, but not all prerequisites"\n ^\nIn file included from aes.c:26:\nIn file included from ./common.h:26:\nIn file included from ../include/mbedtls/build_info.h:193:\n../include/mbedtls/check_config.h:453:2: error: "MBEDTLS_PK_C defined, but not all prerequisites"\n#error "MBEDTLS_PK_C defined, but not all prerequisites"\n ^\nIn file included from asn1parse.c:20:\nIn file included from ./common.h:26:\nIn file included from ../include/mbedtls/build_info.h:193:\n../include/mbedtls/check_config.h:453:2: error: "MBEDTLS_PK_C defined, but not all prerequisites"\n#error "MBEDTLS_PK_C defined, but not all prerequisites"\n ^\nIn file included from asn1write.c:20:\nIn file included from ./common.h:26:\nIn file included from ../include/mbedtls/build_info.h:193:\n../include/mbedtls/check_config.h:453:2: error: "MBEDTLS_PK_C defined, but not all prerequisites"\n#error "MBEDTLS_PK_C defined, but not all prerequisites"\n ^\n1 error generated.\n1 error generated.\n1 error generated.\nmake[1]: *** [Makefile:306: aesce.o] Error 1\nmake[1]: *** Waiting for unfinished jobs....\nmake[1]: *** [Makefile:306: aria.o] Error 1\n  CC    bignum_mod.c\nmake[1]: *** [Makefile:307: aesni.o] Error 1\n1 error generated.\nIn file included from bignum.c:36:\nIn file included from ./common.h:26:\nIn file included from ../include/mbedtls/build_info.h:193:\n../include/mbedtls/check_config.h:453:2: error: "MBEDTLS_PK_C defined, but not all prerequisites"\nmake[1]: *** [Makefile:307: asn1parse.o] Error 1\n#error "MBEDTLS_PK_C defined, but not all prerequisites"\n ^\n1 error generated.\n1 error generated.\nIn file included from base64.c:20:\nIn file included from ./common.h:26:\nIn file included from ../include/mbedtls/build_info.h:193:\n../include/mbedtls/check_config.h:453:2: error: "MBEDTLS_PK_C defined, but not all prerequisites"\n#error "MBEDTLS_PK_C defined, but not all prerequisites"\n ^\nmake[1]: *** [Makefile:307: asn1write.o] Error 1\nmake[1]: *** [Makefile:307: aes.o] Error 1\n1 error generated.\nmake[1]: *** [Makefile:307: base64.o] Error 1\nIn file included from bignum_core.c:20:\nIn file included from ./common.h:26:\nIn file included from ../include/mbedtls/build_info.h:193:\n../include/mbedtls/check_config.h:453:2: error: "MBEDTLS_PK_C defined, but not all prerequisites"\n#error "MBEDTLS_PK_C defined, but not all prerequisites"\n ^\nIn file included from bignum_mod.c:20:\nIn file included from ./common.h:26:\nIn file included from ../include/mbedtls/build_info.h:193:\n../include/mbedtls/check_config.h:453:2: error: "MBEDTLS_PK_C defined, but not all prerequisites"\n#error "MBEDTLS_PK_C defined, but not all prerequisites"\n ^\n1 error generated.\nmake[1]: *** [Makefile:307: bignum.o] Error 1\n1 error generated.\n1 error generated.\nmake[1]: *** [Makefile:307: bignum_mod.o] Error 1\nmake[1]: *** [Makefile:307: bignum_core.o] Error 1\nmake[1]: Leaving directory \'/home/davrod01/code/mbedtls/temp-04059d2e60f1c65f14c19a36d208110fea6fd7ef/library\'\nmake: *** [Makefile:18: lib] Error 2\n'
Removing temporary worktree ./temp-04059d2e60f1c65f14c19a36d208110fea6fd7ef```

@tom-daubney-arm
Copy link
Contributor

I've just tested this on #7578 with ./scripts/code_size_compare.py -o 04059d2e60f1c65f14c19a36d2 -n c5205a311acf5e3 -c tfm-medium -a aarch32 and it crashed:

The following command: make -j lib CC=armclang                   CFLAGS='--target=arm-arm-none-eabi -mcpu=cortex-m33 -Os             -DMBEDTLS_CONFIG_FILE=\"../configs/tfm_mbedcrypto_config_profile_medium.h\"             -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE=\"../configs/crypto_config_profile_medium.h\" '  failed and exited with code 2
Process output:
 b'make[1]: Entering directory \'/home/davrod01/code/mbedtls/temp-04059d2e60f1c65f14c19a36d208110fea6fd7ef/library\'\n  CC    aes.c\n  CC    aesni.c\n  CC    aesce.c\n  CC    aria.c\n  CC    asn1parse.c\n  CC    asn1write.c\n  CC    base64.c\n  CC    bignum.c\n  CC    bignum_core.c\nIn file included from aria.c:26:\nIn file included from ./common.h:26:\nIn file included from ../include/mbedtls/build_info.h:193:\n../include/mbedtls/check_config.h:453:2: error: "MBEDTLS_PK_C defined, but not all prerequisites"\n#error "MBEDTLS_PK_C defined, but not all prerequisites"\n ^\nIn file included from aesce.c:43:\nIn file included from ./common.h:26:\nIn file included from ../include/mbedtls/build_info.h:193:\n../include/mbedtls/check_config.h:453:2: error: "MBEDTLS_PK_C defined, but not all prerequisites"\n#error "MBEDTLS_PK_C defined, but not all prerequisites"\n ^\nIn file included from aesni.c:25:\nIn file included from ./common.h:26:\nIn file included from ../include/mbedtls/build_info.h:193:\n../include/mbedtls/check_config.h:453:2: error: "MBEDTLS_PK_C defined, but not all prerequisites"\n#error "MBEDTLS_PK_C defined, but not all prerequisites"\n ^\nIn file included from aes.c:26:\nIn file included from ./common.h:26:\nIn file included from ../include/mbedtls/build_info.h:193:\n../include/mbedtls/check_config.h:453:2: error: "MBEDTLS_PK_C defined, but not all prerequisites"\n#error "MBEDTLS_PK_C defined, but not all prerequisites"\n ^\nIn file included from asn1parse.c:20:\nIn file included from ./common.h:26:\nIn file included from ../include/mbedtls/build_info.h:193:\n../include/mbedtls/check_config.h:453:2: error: "MBEDTLS_PK_C defined, but not all prerequisites"\n#error "MBEDTLS_PK_C defined, but not all prerequisites"\n ^\nIn file included from asn1write.c:20:\nIn file included from ./common.h:26:\nIn file included from ../include/mbedtls/build_info.h:193:\n../include/mbedtls/check_config.h:453:2: error: "MBEDTLS_PK_C defined, but not all prerequisites"\n#error "MBEDTLS_PK_C defined, but not all prerequisites"\n ^\n1 error generated.\n1 error generated.\n1 error generated.\nmake[1]: *** [Makefile:306: aesce.o] Error 1\nmake[1]: *** Waiting for unfinished jobs....\nmake[1]: *** [Makefile:306: aria.o] Error 1\n  CC    bignum_mod.c\nmake[1]: *** [Makefile:307: aesni.o] Error 1\n1 error generated.\nIn file included from bignum.c:36:\nIn file included from ./common.h:26:\nIn file included from ../include/mbedtls/build_info.h:193:\n../include/mbedtls/check_config.h:453:2: error: "MBEDTLS_PK_C defined, but not all prerequisites"\nmake[1]: *** [Makefile:307: asn1parse.o] Error 1\n#error "MBEDTLS_PK_C defined, but not all prerequisites"\n ^\n1 error generated.\n1 error generated.\nIn file included from base64.c:20:\nIn file included from ./common.h:26:\nIn file included from ../include/mbedtls/build_info.h:193:\n../include/mbedtls/check_config.h:453:2: error: "MBEDTLS_PK_C defined, but not all prerequisites"\n#error "MBEDTLS_PK_C defined, but not all prerequisites"\n ^\nmake[1]: *** [Makefile:307: asn1write.o] Error 1\nmake[1]: *** [Makefile:307: aes.o] Error 1\n1 error generated.\nmake[1]: *** [Makefile:307: base64.o] Error 1\nIn file included from bignum_core.c:20:\nIn file included from ./common.h:26:\nIn file included from ../include/mbedtls/build_info.h:193:\n../include/mbedtls/check_config.h:453:2: error: "MBEDTLS_PK_C defined, but not all prerequisites"\n#error "MBEDTLS_PK_C defined, but not all prerequisites"\n ^\nIn file included from bignum_mod.c:20:\nIn file included from ./common.h:26:\nIn file included from ../include/mbedtls/build_info.h:193:\n../include/mbedtls/check_config.h:453:2: error: "MBEDTLS_PK_C defined, but not all prerequisites"\n#error "MBEDTLS_PK_C defined, but not all prerequisites"\n ^\n1 error generated.\nmake[1]: *** [Makefile:307: bignum.o] Error 1\n1 error generated.\n1 error generated.\nmake[1]: *** [Makefile:307: bignum_mod.o] Error 1\nmake[1]: *** [Makefile:307: bignum_core.o] Error 1\nmake[1]: Leaving directory \'/home/davrod01/code/mbedtls/temp-04059d2e60f1c65f14c19a36d208110fea6fd7ef/library\'\nmake: *** [Makefile:18: lib] Error 2\n'
Removing temporary worktree ./temp-04059d2e60f1c65f14c19a36d208110fea6fd7ef```

That's interesting, I have just seen this error myself. I was not using this script but just compiling something for TF-M on another PR I am reviewing. I am wondering if the TF-M configs that were brought across don't work for all cases because I was running a near idential command to what the script produces, and this error appeared for me. I can chat with @yanrayw and see if we can get to the bottom of this.

@tom-daubney-arm
Copy link
Contributor

tom-daubney-arm commented May 16, 2023

@yanrayw in order to get around the error that @daverodgman reported, I had to turn off the following config options from tfm_mbedcrypto_config_profile_medium.h: MBEDTLS_PK_C, MBEDTLS_PK_PARSE_C and MBEDTLS_PK_WRITE_C.
I also had to add MBEDTLS_ECP_LIGHT to tfm_mbedcrypto_config_profile_medium.h to get the build working. I am not sure if it is reasonable to have to modify the config in this way yet though.

This is a bit confusing because I did not encounter this error when I was playing around with testing the PR earlier today, but I did get this same build error when testing another PR which I was building with the TF-M configs. Have you got any ideas as to why this might be happening? I can chat with you about this tomorrow.

@gilles-peskine-arm
Copy link
Contributor

@tom-daubney-arm The problem is that chains of dependencies between build_info.h and config_psa.h are not handled automatically and not always implemented correctly manually. You're seeing one instance of the problem which is caused by the recent merge of ECP-light.

@tom-daubney-arm
Copy link
Contributor

@tom-daubney-arm The problem is that chains of dependencies between build_info.h and config_psa.h are not handled automatically and not always implemented correctly manually. You're seeing one instance of the problem which is caused by the recent merge of ECP-light.

Thank you, @gilles-peskine-arm!

@yanrayw
Copy link

yanrayw commented May 17, 2023

Look into the build error, I think this error could be fixed by tweaking the location which we include mbedtls/config_psa.h. So I created a PR #7611 to fix build error mentioned by #7426 (comment) in order to merge this PR without further modifications.
Although an alternative solution is we add #define MBEDTLS_MD_LIGHT in tfm_mbedcrypto_config_profile_medium.h, I prefer to fixing it by #7611 .

@tom-daubney-arm
Copy link
Contributor

Look into the build error, I think this error could be fixed by tweaking the location which we include mbedtls/config_psa.h. So I created a PR #7611 to fix build error mentioned by #7426 (comment) in order to merge this PR without further modifications. Although an alternative solution is we add #define MBEDTLS_MD_LIGHT in tfm_mbedcrypto_config_profile_medium.h, I prefer to fixing it by #7611 .

Thanks @yanrayw. I think these are both reasonable options. Can I ask @daverodgman to weigh in since Tom C is away at the moment. Which solution do you want to see?

@yanrayw
Copy link

yanrayw commented May 23, 2023

Know Limitations:

  1. If we measure code size for aarch32 and aarch64, include/mbedtls/mbedtls_config.h in not checked out to initial state.
  2. We can't pass AR=armar and CC=armclang as arguments.

Those limitations will be added in a follow-up PR. (It's also up to what kind of code size measurement script we want) We can add extra functionalities if needed.

@tom-daubney-arm
Copy link
Contributor

Following up on a test I have done which is around point the script at commits which are not in its current branch. I confirm that the script cannot handle this. My steps to preproduce were as follows:

  • Checkout out this Code Size: Add the TFM Medium Profile config files and the option to track code size changes #7426 (this PR) to a local branch.
  • Rebase it onto latest development to get changes brought in by build_info.h: fix mutual implications with config_psa.h temporarily  #7611.
  • Run the following command which points the script at two local commits from my local copy of the development branch:
    ./scripts/code_size_compare.py -n 399fa48e95 -o 9a11f8a122 -a aarch32 -c tfm-medium Creating git worktree for 9a11f8a12236594382ef4eec4b818b9519ad31b1 The following command: make -j lib CC=armclang CFLAGS='--target=arm-arm-none-eabi -mcpu=cortex-m33 -Os -DMBEDTLS_CONFIG_FILE=\"../configs/tfm_mbedcrypto_config_profile_medium.h\" -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE=\"../configs/crypto_config_profile_medium.h\" ' failed and exited with code 2 Process output: b' CC aes.c\n CC aesni.c\n CC aesce.c\n CC aria.c\nIn file included from aesni.c:25:\nIn file included from ./common.h:26:\n../include/mbedtls/build_info.h:65:10: fatal error: \'../configs/tfm_mbedcrypto_config_profile_medium.h\' file not found\n#include MBEDTLS_CONFIG_FILE\n ^~~~~~~~~~~~~~~~~~~\n<command line>:2:29: note: expanded from here\n#define MBEDTLS_CONFIG_FILE "../configs/tfm_mbedcrypto_config_profile_medium.h"\n ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nIn file included from aes.c:26:\nIn file included from ./common.h:26:\n../include/mbedtls/build_info.h:65:10: fatal error: \'../configs/tfm_mbedcrypto_config_profile_medium.h\' file not found\n#include MBEDTLS_CONFIG_FILE\n ^~~~~~~~~~~~~~~~~~~\n<command line>:2:29: note: expanded from here\n#define MBEDTLS_CONFIG_FILE "../configs/tfm_mbedcrypto_config_profile_medium.h"\n ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n1 error generated.\n1 error generated.\nIn file included from aesce.c:43:\nIn file included from ./common.h:26:\n../include/mbedtls/build_info.h:65:10: fatal error: \'../configs/tfm_mbedcrypto_config_profile_medium.h\' file not found\n#include MBEDTLS_CONFIG_FILE\n ^~~~~~~~~~~~~~~~~~~\n<command line>:2:29: note: expanded from here\n#define MBEDTLS_CONFIG_FILE "../configs/tfm_mbedcrypto_config_profile_medium.h"\n ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nmake[1]: *** [Makefile:307: aes.o] Error 1\n1 error generated.\nmake[1]: *** Waiting for unfinished jobs....\nmake[1]: *** [Makefile:307: aesni.o] Error 1\nmake[1]: *** [Makefile:307: aesce.o] Error 1\nIn file included from aria.c:26:\nIn file included from ./common.h:26:\n../include/mbedtls/build_info.h:65:10: fatal error: \'../configs/tfm_mbedcrypto_config_profile_medium.h\' file not found\n#include MBEDTLS_CONFIG_FILE\n ^~~~~~~~~~~~~~~~~~~\n<command line>:2:29: note: expanded from here\n#define MBEDTLS_CONFIG_FILE "../configs/tfm_mbedcrypto_config_profile_medium.h"\n ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n1 error generated.\nmake[1]: *** [Makefile:307: aria.o] Error 1\nmake: *** [Makefile:18: lib] Error 2\n' Removing temporary worktree ./temp-9a11f8a12236594382ef4eec4b818b9519ad31b1

So we are seeing an error here around not finding the config file.

Copy link
Contributor

@davidhorstmann-arm davidhorstmann-arm left a comment

Choose a reason for hiding this comment

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

Mostly small comments

None are blocking except the build error in the tfm-medium config. I'm happy for all except that one to be addressed in a followup.

No blocking comments, I'm happy for them to be addressed in a followup if preferred.

return 'make -j lib'

if self.config == 'default':
if self.arch == 'aarch32':
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: aarch32 is an execution state of Armv8-A, whereas this is compiling for M-class (M33). Changing aarch32 to armv8-m would correct this.

Comment on lines +38 to +41
self.text = text
self.data = data
self.bss = bss
self.total = total
Copy link
Contributor

Choose a reason for hiding this comment

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

Non-blocker: Is total just text + data + bss? If so, why not calculate it on the fly by replacing it with a method so that we can never have an inconsistent object?

Or does alignment/padding mean that total might be different from the sum of the other 3?

Comment on lines +158 to +161
'make -j lib CC=armclang \
CFLAGS=\'--target=arm-arm-none-eabi -mcpu=cortex-m33 -Os \
-DMBEDTLS_CONFIG_FILE=\\\"../configs/tfm_mbedcrypto_config_profile_medium.h\\\" \
-DMBEDTLS_PSA_CRYPTO_CONFIG_FILE=\\\"../configs/crypto_config_profile_medium.h\\\" \' '
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Indentation here is a bit funky.


def _gen_code_size_csv(self, revision, git_worktree_path):
"""Generate code size csv file."""

csv_fname = revision + ".csv"
csv_fname = revision + "-" + self.config + ".csv"
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we use self.arch here to avoid a name clash if used on the same revisions over different architectures?

# Tell the user what went wrong
print("The following command: {} failed and exited with code {}"\
.format(e.cmd, e.returncode))
print("Process output:\n {}".format(e.output))
Copy link
Contributor

Choose a reason for hiding this comment

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

Formatting nit: The output is a bytes b'xyz' object so is printed as this not as a string. This means that for example newlines are escaped not actually printed. This should be converted to a string before outputting to make it easier to read.

Suggested change
print("Process output:\n {}".format(e.output))
print("Process output:\n {}".format(str(e.output, "utf-8")))

@yanrayw
Copy link

yanrayw commented May 24, 2023

Thanks @tom-daubney-arm for providing feedback.

In #7426 (comment), there are logs about file not found. Actually this error is expected, I would say this is a limitation if we want to measure code size for older commits for tfm-medium config.

To compare two commits by this script, firstly it creates a worktree for that commit. The issue here is, regarding 399fa48, we haven't created crypto_config_profile_medium.h and tfm_mbedcrypto_config_profile_medium.h under 399fa48. Therefore, there is no those two configs for worktree of 399fa48. Then error is reported that XXX file not found.

@tom-daubney-arm
Copy link
Contributor

Thanks @tom-daubney-arm for providing feedback.

In #7426 (comment), there are logs about file not found. Actually this error is expected, I would say this is a limitation if we want to measure code size for older commits for tfm-medium config.

To compare two commits by this script, firstly it creates a worktree for that commit. The issue here is, regarding 399fa48, we haven't created crypto_config_profile_medium.h and tfm_mbedcrypto_config_profile_medium.h under 399fa48. Therefore, there is no those two configs for worktree of 399fa48. Then error is reported that XXX file not found.

Thanks @yanrayw. I agree with this analysis here; I thought this is what was happening. I personally think it is ok to have this as a limitation of the script.

In my understanding, the main use case of this script is for measuing the impact that a new piece of work has (whether that is adding or removing code from the lib) on the code size of the library. In order to do this, a developer would make their measurement after adding some commits and then call the script, pointing it at the current HEAD and the last commit that existed when they started their work. The script in its current form does indeed handle this use case without error and as such I think it can be merged (subject to the review comments from @davidhorstmann-arm being addressed).

I know there are some additional features that might be nice to have in the script, such as architecture detection etc, however I feel like these could be brought in with a follow up PR.

What do people think? @daverodgman in particular as I know you have some issues you want followed up on but also @yanrayw, @davidhorstmann-arm

@yanrayw
Copy link

yanrayw commented May 24, 2023

This PR is not in a good shape. I'll split this PR into smaller pieces and upload smaller PRs.
#7650 only adds code size measurement for tfm-medium in order to be merged soon.

@yanrayw
Copy link

yanrayw commented Jun 1, 2023

This PR is superseded by #7650 and its follow-up PRs.

@yanrayw yanrayw closed this Jun 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement needs-review Every commit must be reviewed by at least two team members, needs-reviewer This PR needs someone to pick it up for review priority-high High priority - will be reviewed soon size-optimisation size-s Estimated task size: small (~2d)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Code Size: Code Size Tracking: Configurations
8 participants