From 9cec66f9200cb573353928bd3292fb1f710e4b3c Mon Sep 17 00:00:00 2001 From: Paul Selkirk Date: Thu, 4 May 2017 15:23:10 -0400 Subject: Copy profiling code from MCUOnEclipse. --- libraries/libprof/README.txt | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 libraries/libprof/README.txt (limited to 'libraries/libprof/README.txt') diff --git a/libraries/libprof/README.txt b/libraries/libprof/README.txt new file mode 100644 index 0000000..2df8b96 --- /dev/null +++ b/libraries/libprof/README.txt @@ -0,0 +1,6 @@ +Copied from https://github.com/ErichStyger/mcuoneclipse.git, +directory Examples/KDS/FRDM-K64F120M/FRDM-K64F_Profiling/Profiling, +commit 9b7eedddd8b24968128582aedc63be95b61f782c, +dated Mon Jan 9 16:56:17 2017 +0100. +(This is in turn adapted from Cygwin, and can be found in newlib distributions.) + -- cgit v1.2.3 From 1815f1b2aa0a3ff0654f4eb65fdd0a5bdfe8c7b7 Mon Sep 17 00:00:00 2001 From: Paul Selkirk Date: Fri, 5 May 2017 22:58:34 -0400 Subject: Port profiling code, using a new SysTick hook and new CLI commands. --- libraries/libprof/README.txt | 65 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 5 deletions(-) (limited to 'libraries/libprof/README.txt') diff --git a/libraries/libprof/README.txt b/libraries/libprof/README.txt index 2df8b96..da138c2 100644 --- a/libraries/libprof/README.txt +++ b/libraries/libprof/README.txt @@ -1,6 +1,61 @@ -Copied from https://github.com/ErichStyger/mcuoneclipse.git, -directory Examples/KDS/FRDM-K64F120M/FRDM-K64F_Profiling/Profiling, -commit 9b7eedddd8b24968128582aedc63be95b61f782c, -dated Mon Jan 9 16:56:17 2017 +0100. -(This is in turn adapted from Cygwin, and can be found in newlib distributions.) +Profiling the Cryptech Alpha +============================ +Origin +------ + +This code was copied from https://github.com/ErichStyger/mcuoneclipse.git, +directory Examples/KDS/FRDM-K64F120M/FRDM-K64F_Profiling/Profiling, commit +9b7eedddd8b24968128582aedc63be95b61f782c, dated Mon Jan 9 16:56:17 2017 +0100. + +References +---------- + +I recommend reading both of these to understand how the profiling code works. + +[1]: https://mcuoneclipse.com/2015/08/23/tutorial-using-gnu-profiling-gprof-with-arm-cortex-m/ +"Tutorial: Using GNU Profiling (gprof) with ARM Cortex-M" + +[2]: http://bgamari.github.io/posts/2014-10-31-semihosting.html +"Semihosting with ARM, GCC, and OpenOCD" + +How to build +------------ + +From the top level, run + + make DO_PROFILING=1 hsm + +By default, all code is profiled, *except* the profiling code itself, +because that would cause fatal recursion. + +How to run +---------- + +You need to start OpenOCD on the host, and enable semihosting, at least +before you try to use it as a remote file system. + +I recommend executing the following in the projects/hsm directory, so that +gmon.out ends up in the same directory as hsm.elf. + +Start OpenOCD: + + $ openocd -f /usr/share/openocd/scripts/board/stm32f4discovery.cfg & + +Connect to OpenOCD: + + $ telnet localhost 4444 + +In the OpenOCD console, enable semihosting: + + > arm semihosting enable + +In the CLI, type `profile start`, then start the unit test or whatever +will be exercising the hsm. Afterwards, in the CLI, type `profile stop`. + +After invoking `profile stop`, it takes almost 2 minutes to write gmon.out +over OpenOCD to the host. + +In the projects/hsm directory, run gprof to analyse the gmon.out file: + + $ gprof hsm.elf >gprof.txt -- cgit v1.2.3 From 4d69f1a0ef2ef3aa23b0ac9f1b9cbc84582136a7 Mon Sep 17 00:00:00 2001 From: Paul Selkirk Date: Sat, 6 May 2017 13:07:59 -0400 Subject: Correct offset to get the PC. A previous version of this code ran over the RTOS, where threads used the Process Stack, while the SysTick interrupt used the Main Stack. Now everything's on the main stack, so we need to account for 2 extra words that SysTick_Handler pushes on the stack at entry. --- libraries/libprof/README.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libraries/libprof/README.txt') diff --git a/libraries/libprof/README.txt b/libraries/libprof/README.txt index da138c2..9db27a6 100644 --- a/libraries/libprof/README.txt +++ b/libraries/libprof/README.txt @@ -53,8 +53,8 @@ In the OpenOCD console, enable semihosting: In the CLI, type `profile start`, then start the unit test or whatever will be exercising the hsm. Afterwards, in the CLI, type `profile stop`. -After invoking `profile stop`, it takes almost 2 minutes to write gmon.out -over OpenOCD to the host. +After invoking `profile stop`, it can take several minutes to write +gmon.out over OpenOCD to the host. In the projects/hsm directory, run gprof to analyse the gmon.out file: -- cgit v1.2.3 From 65b94ef5ba1981c74a99cb43ee768fbf480c698b Mon Sep 17 00:00:00 2001 From: Paul Selkirk Date: Wed, 10 May 2017 00:00:04 -0400 Subject: Sigh, right offset for the wrong register. Get the PC (the address we interrupted) rather than LR (the return address from the function we interrupted). Also, change u_short and u_int to unsigned short and unsigned int, since gcc recently decided that those aren't part of the C99 standard. Finally, add profilable versions of memcpy, memset, and friends, because they get called a lot in the course of unit testing, and it would be nice to know who's calling them. --- libraries/libprof/README.txt | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'libraries/libprof/README.txt') diff --git a/libraries/libprof/README.txt b/libraries/libprof/README.txt index 9db27a6..1fe378c 100644 --- a/libraries/libprof/README.txt +++ b/libraries/libprof/README.txt @@ -50,6 +50,10 @@ In the OpenOCD console, enable semihosting: > arm semihosting enable +In another window, start the debugger: + + $ sw/stm32/bin/debug projects/hsm/hsm + In the CLI, type `profile start`, then start the unit test or whatever will be exercising the hsm. Afterwards, in the CLI, type `profile stop`. -- cgit v1.2.3