[Cryptech-Commits] [sw/stm32] 01/01: Merge branch 'profiling'

git at cryptech.is git at cryptech.is
Sat Apr 7 02:37:41 UTC 2018


This is an automated email from the git hooks/post-receive script.

paul at psgd.org pushed a commit to branch master
in repository sw/stm32.

commit 6c7bd80b4e7bc5af1659b14b7fb0038f3dc53989
Merge: b35b87e f508e24
Author: Paul Selkirk <paul at psgd.org>
AuthorDate: Fri Apr 6 16:14:43 2018 -0400

    Merge branch 'profiling'

 Makefile                                           |  26 ++
 libraries/libprof/Makefile                         |  20 ++
 libraries/libprof/README.md                        |  65 +++++
 libraries/libprof/gmon.c                           | 324 +++++++++++++++++++++
 libraries/libprof/gmon.h                           | 177 +++++++++++
 libraries/libprof/profil.c                         |  96 ++++++
 libraries/libprof/profil.h                         |  60 ++++
 libraries/libprof/profiler.S                       |  28 ++
 libraries/libtfm/Makefile                          |   5 +
 .../TARGET_CRYPTECH_ALPHA/stm32f4xx_it.c           |   7 +
 memfunc.c                                          | 101 +++++++
 projects/hsm/Makefile                              |  20 +-
 projects/hsm/hsm.c                                 |  10 +
 projects/hsm/mgmt-misc.c                           |  38 +++
 projects/hsm/mgmt-task.c                           |  44 +++
 syscalls.c                                         |   6 +
 task.c                                             |  62 ++++
 task.h                                             |  12 +
 18 files changed, 1097 insertions(+), 4 deletions(-)

diff --cc Makefile
index d04b4d4,2b421f5..a12f804
--- a/Makefile
+++ b/Makefile
@@@ -27,6 -27,6 +27,16 @@@
  # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
++# A couple features that can be enabled at build time, but are not turned on
++# by default:
++# DO_PROFILING: Enable gmon profiling. See libraries/libprof/README.md for
++# more details.
++# DO_TASK_METRICS: Enable task metrics - average/max time between yields. This
++# can be helpful when experimentally adding yields to improve responsiveness.
++#
++# To enable, run `make DO_PROFILING=1 DO_TASK_METRICS=1`
++# (or DO_PROFILING=xyzzy - `make` just cares that the symbol is defined)
++
  # export all variables to child processes by default
  .EXPORT_ALL_VARIABLES:
  
diff --cc libraries/libprof/README.md
index 0000000,f0bacc7..d464644
mode 000000,100644..100644
--- a/libraries/libprof/README.md
+++ b/libraries/libprof/README.md
@@@ -1,0 -1,67 +1,65 @@@
+ 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
++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"
++1. [Tutorial: Using GNU Profiling (gprof) with ARM Cortex-M](https://mcuoneclipse.com/2015/08/23/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"
++2. [Semihosting with ARM, GCC, and OpenOCD](http://bgamari.github.io/posts/2014-10-31-semihosting.html)
+ 
+ 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.
++I recommend executing the following in the `projects/hsm` directory, so that
++`gmon.out` ends up in the same directory as `hsm.elf`.
+ 
+ Start the debugger:
+ 
+     $ ../../bin/debug hsm
+ 
+ In another window, connect to OpenOCD:
+ 
+     $ telnet localhost 4444
+ 
+ In the OpenOCD console, enable semihosting:
+ 
+     > arm semihosting enable
+     > exit
+ 
+ Then connect to the Cryptech management console:
+ 
+     $ cryptech_console
+ 
+ In the Cryptech console, type `profile start`, then start the unit test or
+ whatever will be exercising the hsm. Afterwards, in the console, type
+ `profile stop`.
+ 
+ After invoking `profile stop`, it can take several minutes to write
 -gmon.out over OpenOCD to the host.
++`gmon.out` over OpenOCD to the host.
+ 
 -In the projects/hsm directory, run gprof to analyse the gmon.out file:
++In the `projects/hsm` directory, run `gprof` to analyse the `gmon.out` file:
+ 
+     $ gprof hsm.elf >gprof.txt
diff --cc projects/hsm/mgmt-misc.c
index b06003f,016d7cb..86f1be8
--- a/projects/hsm/mgmt-misc.c
+++ b/projects/hsm/mgmt-misc.c
@@@ -113,12 -113,27 +113,41 @@@ int cli_receive_data(struct cli_def *cl
      return CLI_ERROR;
  }
  
+ #ifdef DO_PROFILING
+ static int cmd_profile_start(struct cli_def *cli, const char *command, char *argv[], int argc)
+ {
++    cli = cli;
++    command = command;
++    argv = argv;
++    argc = argc;
++
+     extern uint32_t CRYPTECH_FIRMWARE_START;
+     extern char __etext; /* end of text/code symbol, defined by linker */
+     extern void monstartup (size_t lowpc, size_t highpc);
+     monstartup((size_t)&CRYPTECH_FIRMWARE_START, (size_t)&__etext);
+     return CLI_OK;
+ }
+ 
+ static int cmd_profile_stop(struct cli_def *cli, const char *command, char *argv[], int argc)
+ {
++    cli = cli;
++    command = command;
++    argv = argv;
++    argc = argc;
++
+     extern void _mcleanup(void);
+     _mcleanup();
+     return CLI_OK;
+ }
+ 
+ #endif
+ 
  static int cmd_reboot(struct cli_def *cli, const char *command, char *argv[], int argc)
  {
 +    command = command;
 +    argv = argv;
 +    argc = argc;
 +
      cli_print(cli, "\n\n\nRebooting\n\n\n");
      HAL_NVIC_SystemReset();
  
diff --cc projects/hsm/mgmt-task.c
index beffc32,4668585..c2a3d3f
--- a/projects/hsm/mgmt-task.c
+++ b/projects/hsm/mgmt-task.c
@@@ -77,6 -73,27 +77,36 @@@ static int cmd_task_show(struct cli_de
      return CLI_OK;
  }
  
+ #ifdef DO_TASK_METRICS
+ static int cmd_task_show_metrics(struct cli_def *cli, const char *command, char *argv[], int argc)
+ {
++    command = command;
++    argv = argv;
++    argc = argc;
++
+     struct task_metrics tm;
+ 
+     task_get_metrics(&tm);
+ 
+     cli_print(cli, "avg time between yields: %ld.%06ld sec", tm.avg.tv_sec, tm.avg.tv_usec);
+     cli_print(cli, "max time between yields: %ld.%06ld sec", tm.max.tv_sec, tm.max.tv_usec);
+ 
+     return CLI_OK;
+ }
+ 
+ static int cmd_task_reset_metrics(struct cli_def *cli, const char *command, char *argv[], int argc)
+ {
++    cli = cli;
++    command = command;
++    argv = argv;
++    argc = argc;
++
+     task_reset_metrics();
+ 
+     return CLI_OK;
+ }
+ #endif
+ 
  void configure_cli_task(struct cli_def *cli)
  {
      struct cli_command *c = cli_register_command(cli, NULL, "task", NULL, 0, 0, NULL);
diff --cc syscalls.c
index 2243d0b,1624454..fc842c0
--- a/syscalls.c
+++ b/syscalls.c
@@@ -101,11 -102,9 +102,12 @@@ int _write_r (struct _reent *r, int fil
  
  int _close_r (struct _reent *r, int file)
  {
 +  r = r;
 +  file = file;
 +
    return 0;
  }
+ #endif
  
  /***************************************************************************/
  



More information about the Commits mailing list