From 7ef51e89d5a1d7d75cb0b8d3832327beb46319dd Mon Sep 17 00:00:00 2001 From: Paul Selkirk Date: Wed, 3 May 2017 16:38:09 -0400 Subject: Add some task metrics. --- projects/hsm/Makefile | 2 ++ projects/hsm/mgmt-task.c | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) (limited to 'projects') diff --git a/projects/hsm/Makefile b/projects/hsm/Makefile index 927c9f1..ecd1a5d 100644 --- a/projects/hsm/Makefile +++ b/projects/hsm/Makefile @@ -13,6 +13,8 @@ OBJS = mgmt-cli.o \ BOARD_OBJS += $(TOPLEVEL)/task.o +CFLAGS += -DTASK_METRICS + CFLAGS += -DNUM_RPC_TASK=4 CFLAGS += -I$(LIBHAL_SRC) diff --git a/projects/hsm/mgmt-task.c b/projects/hsm/mgmt-task.c index a1ae7e6..12ce2b8 100644 --- a/projects/hsm/mgmt-task.c +++ b/projects/hsm/mgmt-task.c @@ -69,10 +69,42 @@ static int cmd_task_show(struct cli_def *cli, const char *command, char *argv[], return CLI_OK; } +#ifdef TASK_METRICS +static int cmd_task_show_metrics(struct cli_def *cli, const char *command, char *argv[], int 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) +{ + 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); /* task show */ - cli_register_command(cli, c, "show", cmd_task_show, 0, 0, "Show the active tasks"); + struct cli_command *c_show = cli_register_command(cli, c, "show", cmd_task_show, 0, 0, "Show the active tasks"); + +#ifdef TASK_METRICS + /* task show metrics */ + cli_register_command(cli, c_show, "metrics", cmd_task_show_metrics, 0, 0, "Show task metrics"); + + /* task reset */ + struct cli_command *c_reset = cli_register_command(cli, c, "reset", NULL, 0, 0, NULL); + + /* task reset metrics */ + cli_register_command(cli, c_reset, "metrics", cmd_task_reset_metrics, 0, 0, "Reset task metrics"); +#endif } -- 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. --- projects/hsm/Makefile | 11 ++++++++++- projects/hsm/mgmt-misc.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) (limited to 'projects') diff --git a/projects/hsm/Makefile b/projects/hsm/Makefile index 927c9f1..6add6a8 100644 --- a/projects/hsm/Makefile +++ b/projects/hsm/Makefile @@ -21,10 +21,19 @@ CFLAGS += -I$(LIBCLI_SRC) LIBS += $(LIBHAL_BLD)/libhal.a $(LIBTFM_BLD)/libtfm.a LIBS += $(LIBCLI_BLD)/libcli.a +LDFLAGS += -mcpu=cortex-m4 -mthumb -mlittle-endian -mthumb-interwork +LDFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 +LDFLAGS += -Wl,--gc-sections + +ifdef DO_PROFILING +LIBS += $(LIBPROF_BLD)/libprof.a +LDFLAGS += --specs=rdimon.specs -lc -lrdimon +endif + all: $(PROJ:=.elf) %.elf: %.o $(BOARD_OBJS) $(OBJS) $(LIBS) - $(CC) $(CFLAGS) $^ -o $@ -T$(LDSCRIPT) -g -Wl,-Map=$*.map + $(CC) $(LDFLAGS) $^ -o $@ -T$(LDSCRIPT) -g -Wl,-Map=$*.map $(OBJCOPY) -O binary $*.elf $*.bin $(SIZE) $*.elf diff --git a/projects/hsm/mgmt-misc.c b/projects/hsm/mgmt-misc.c index ccd032b..016d7cb 100644 --- a/projects/hsm/mgmt-misc.c +++ b/projects/hsm/mgmt-misc.c @@ -113,6 +113,25 @@ int cli_receive_data(struct cli_def *cli, uint8_t *buf, size_t len, cli_data_cal return CLI_ERROR; } +#ifdef DO_PROFILING +static int cmd_profile_start(struct cli_def *cli, const char *command, char *argv[], int 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) +{ + extern void _mcleanup(void); + _mcleanup(); + return CLI_OK; +} + +#endif + static int cmd_reboot(struct cli_def *cli, const char *command, char *argv[], int argc) { cli_print(cli, "\n\n\nRebooting\n\n\n"); @@ -124,6 +143,15 @@ static int cmd_reboot(struct cli_def *cli, const char *command, char *argv[], in void configure_cli_misc(struct cli_def *cli) { +#ifdef DO_PROFILING + struct cli_command *c_profile = cli_register_command(cli, NULL, "profile", NULL, 0, 0, NULL); + + /* profile start */ + cli_register_command(cli, c_profile, "start", cmd_profile_start, 0, 0, "Start collecting profiling data"); + + /* profile stop */ + cli_register_command(cli, c_profile, "stop", cmd_profile_stop, 0, 0, "Stop collecting profiling data"); +#endif /* reboot */ cli_register_command(cli, NULL, "reboot", cmd_reboot, 0, 0, "Reboot the STM32"); } -- 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. --- projects/hsm/Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'projects') diff --git a/projects/hsm/Makefile b/projects/hsm/Makefile index 6add6a8..4df60d7 100644 --- a/projects/hsm/Makefile +++ b/projects/hsm/Makefile @@ -9,9 +9,8 @@ OBJS = mgmt-cli.o \ mgmt-masterkey.o \ mgmt-misc.o \ mgmt-task.o \ - log.o - -BOARD_OBJS += $(TOPLEVEL)/task.o + log.o \ + $(TOPLEVEL)/task.o CFLAGS += -DNUM_RPC_TASK=4 @@ -26,6 +25,7 @@ LDFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 LDFLAGS += -Wl,--gc-sections ifdef DO_PROFILING +OBJS += $(TOPLEVEL)/memfunc.o LIBS += $(LIBPROF_BLD)/libprof.a LDFLAGS += --specs=rdimon.specs -lc -lrdimon endif @@ -33,7 +33,7 @@ endif all: $(PROJ:=.elf) %.elf: %.o $(BOARD_OBJS) $(OBJS) $(LIBS) - $(CC) $(LDFLAGS) $^ -o $@ -T$(LDSCRIPT) -g -Wl,-Map=$*.map + $(CC) $^ -o $@ -T$(LDSCRIPT) -g -Wl,-Map=$*.map $(LDFLAGS) $(OBJCOPY) -O binary $*.elf $*.bin $(SIZE) $*.elf -- cgit v1.2.3 From 5ff8c9512db48d128cf07904f68eb5139bebf952 Mon Sep 17 00:00:00 2001 From: Paul Selkirk Date: Wed, 24 May 2017 18:03:19 -0400 Subject: Add task_yield_maybe --- projects/hsm/hsm.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'projects') diff --git a/projects/hsm/hsm.c b/projects/hsm/hsm.c index 8a8f441..33342c0 100644 --- a/projects/hsm/hsm.c +++ b/projects/hsm/hsm.c @@ -380,6 +380,11 @@ void hal_task_yield(void) task_yield(); } +void hal_task_yield_maybe(void) +{ + task_yield_maybe(); +} + /* A mutex to arbitrate concurrent access to the keystore. */ task_mutex_t ks_mutex = { 0 }; -- cgit v1.2.3 From 12585a41bbf124ff8204fc1b538b9796812db747 Mon Sep 17 00:00:00 2001 From: Paul Selkirk Date: Wed, 3 May 2017 16:38:09 -0400 Subject: Add some task metrics. --- projects/hsm/Makefile | 2 ++ projects/hsm/mgmt-task.c | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) (limited to 'projects') diff --git a/projects/hsm/Makefile b/projects/hsm/Makefile index 927c9f1..ecd1a5d 100644 --- a/projects/hsm/Makefile +++ b/projects/hsm/Makefile @@ -13,6 +13,8 @@ OBJS = mgmt-cli.o \ BOARD_OBJS += $(TOPLEVEL)/task.o +CFLAGS += -DTASK_METRICS + CFLAGS += -DNUM_RPC_TASK=4 CFLAGS += -I$(LIBHAL_SRC) diff --git a/projects/hsm/mgmt-task.c b/projects/hsm/mgmt-task.c index ac1a737..9f6a908 100644 --- a/projects/hsm/mgmt-task.c +++ b/projects/hsm/mgmt-task.c @@ -73,10 +73,42 @@ static int cmd_task_show(struct cli_def *cli, const char *command, char *argv[], return CLI_OK; } +#ifdef TASK_METRICS +static int cmd_task_show_metrics(struct cli_def *cli, const char *command, char *argv[], int 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) +{ + 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); /* task show */ - cli_register_command(cli, c, "show", cmd_task_show, 0, 0, "Show the active tasks"); + struct cli_command *c_show = cli_register_command(cli, c, "show", cmd_task_show, 0, 0, "Show the active tasks"); + +#ifdef TASK_METRICS + /* task show metrics */ + cli_register_command(cli, c_show, "metrics", cmd_task_show_metrics, 0, 0, "Show task metrics"); + + /* task reset */ + struct cli_command *c_reset = cli_register_command(cli, c, "reset", NULL, 0, 0, NULL); + + /* task reset metrics */ + cli_register_command(cli, c_reset, "metrics", cmd_task_reset_metrics, 0, 0, "Reset task metrics"); +#endif } -- cgit v1.2.3 From 358d038067b10330011ef4e6596ae37842d516fe 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. --- projects/hsm/Makefile | 11 ++++++++++- projects/hsm/mgmt-misc.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) (limited to 'projects') diff --git a/projects/hsm/Makefile b/projects/hsm/Makefile index ecd1a5d..7efd41d 100644 --- a/projects/hsm/Makefile +++ b/projects/hsm/Makefile @@ -23,10 +23,19 @@ CFLAGS += -I$(LIBCLI_SRC) LIBS += $(LIBHAL_BLD)/libhal.a $(LIBTFM_BLD)/libtfm.a LIBS += $(LIBCLI_BLD)/libcli.a +LDFLAGS += -mcpu=cortex-m4 -mthumb -mlittle-endian -mthumb-interwork +LDFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 +LDFLAGS += -Wl,--gc-sections + +ifdef DO_PROFILING +LIBS += $(LIBPROF_BLD)/libprof.a +LDFLAGS += --specs=rdimon.specs -lc -lrdimon +endif + all: $(PROJ:=.elf) %.elf: %.o $(BOARD_OBJS) $(OBJS) $(LIBS) - $(CC) $(CFLAGS) $^ -o $@ -T$(LDSCRIPT) -g -Wl,-Map=$*.map + $(CC) $(LDFLAGS) $^ -o $@ -T$(LDSCRIPT) -g -Wl,-Map=$*.map $(OBJCOPY) -O binary $*.elf $*.bin $(SIZE) $*.elf diff --git a/projects/hsm/mgmt-misc.c b/projects/hsm/mgmt-misc.c index ccd032b..016d7cb 100644 --- a/projects/hsm/mgmt-misc.c +++ b/projects/hsm/mgmt-misc.c @@ -113,6 +113,25 @@ int cli_receive_data(struct cli_def *cli, uint8_t *buf, size_t len, cli_data_cal return CLI_ERROR; } +#ifdef DO_PROFILING +static int cmd_profile_start(struct cli_def *cli, const char *command, char *argv[], int 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) +{ + extern void _mcleanup(void); + _mcleanup(); + return CLI_OK; +} + +#endif + static int cmd_reboot(struct cli_def *cli, const char *command, char *argv[], int argc) { cli_print(cli, "\n\n\nRebooting\n\n\n"); @@ -124,6 +143,15 @@ static int cmd_reboot(struct cli_def *cli, const char *command, char *argv[], in void configure_cli_misc(struct cli_def *cli) { +#ifdef DO_PROFILING + struct cli_command *c_profile = cli_register_command(cli, NULL, "profile", NULL, 0, 0, NULL); + + /* profile start */ + cli_register_command(cli, c_profile, "start", cmd_profile_start, 0, 0, "Start collecting profiling data"); + + /* profile stop */ + cli_register_command(cli, c_profile, "stop", cmd_profile_stop, 0, 0, "Stop collecting profiling data"); +#endif /* reboot */ cli_register_command(cli, NULL, "reboot", cmd_reboot, 0, 0, "Reboot the STM32"); } -- cgit v1.2.3 From 03d7fa26a89d44349df86e29ac782d075856c570 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. --- projects/hsm/Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'projects') diff --git a/projects/hsm/Makefile b/projects/hsm/Makefile index 7efd41d..429069d 100644 --- a/projects/hsm/Makefile +++ b/projects/hsm/Makefile @@ -9,9 +9,8 @@ OBJS = mgmt-cli.o \ mgmt-masterkey.o \ mgmt-misc.o \ mgmt-task.o \ - log.o - -BOARD_OBJS += $(TOPLEVEL)/task.o + log.o \ + $(TOPLEVEL)/task.o CFLAGS += -DTASK_METRICS @@ -28,6 +27,7 @@ LDFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 LDFLAGS += -Wl,--gc-sections ifdef DO_PROFILING +OBJS += $(TOPLEVEL)/memfunc.o LIBS += $(LIBPROF_BLD)/libprof.a LDFLAGS += --specs=rdimon.specs -lc -lrdimon endif @@ -35,7 +35,7 @@ endif all: $(PROJ:=.elf) %.elf: %.o $(BOARD_OBJS) $(OBJS) $(LIBS) - $(CC) $(LDFLAGS) $^ -o $@ -T$(LDSCRIPT) -g -Wl,-Map=$*.map + $(CC) $^ -o $@ -T$(LDSCRIPT) -g -Wl,-Map=$*.map $(LDFLAGS) $(OBJCOPY) -O binary $*.elf $*.bin $(SIZE) $*.elf -- cgit v1.2.3 From 2e1f88062c7ec6cd12688ce7522e802bbf09bba1 Mon Sep 17 00:00:00 2001 From: Paul Selkirk Date: Wed, 24 May 2017 18:03:19 -0400 Subject: Add task_yield_maybe --- projects/hsm/hsm.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'projects') diff --git a/projects/hsm/hsm.c b/projects/hsm/hsm.c index 800edcc..b6b8820 100644 --- a/projects/hsm/hsm.c +++ b/projects/hsm/hsm.c @@ -393,6 +393,11 @@ void hal_task_yield(void) task_yield(); } +void hal_task_yield_maybe(void) +{ + task_yield_maybe(); +} + /* A mutex to arbitrate concurrent access to the keystore. */ task_mutex_t ks_mutex = { 0 }; -- cgit v1.2.3 From f508e24f5b872a8f7d642eb4fb2217dd1497de96 Mon Sep 17 00:00:00 2001 From: Paul Selkirk Date: Thu, 21 Sep 2017 11:24:02 -0400 Subject: cleanup --- projects/hsm/Makefile | 1 - 1 file changed, 1 deletion(-) (limited to 'projects') diff --git a/projects/hsm/Makefile b/projects/hsm/Makefile index 9a75b92..3430e14 100644 --- a/projects/hsm/Makefile +++ b/projects/hsm/Makefile @@ -26,7 +26,6 @@ LDFLAGS += -Wl,--gc-sections ifdef DO_PROFILING OBJS += $(TOPLEVEL)/memfunc.o -LIBS += $(LIBPROF_BLD)/libprof.a LDFLAGS += --specs=rdimon.specs -lc -lrdimon endif -- cgit v1.2.3