diff options
author | Paul Selkirk <paul@psgd.org> | 2017-09-07 18:17:12 -0400 |
---|---|---|
committer | Paul Selkirk <paul@psgd.org> | 2017-09-07 18:20:55 -0400 |
commit | 72227852729ed3125af58cff3f593340b3247fed (patch) | |
tree | 234d45ae587ce51bfbbce6d8c059a121a44bf1e6 | |
parent | 2e1f88062c7ec6cd12688ce7522e802bbf09bba1 (diff) | |
parent | 5ff8c9512db48d128cf07904f68eb5139bebf952 (diff) |
Rebase branch 'profiling' from master
-rw-r--r-- | Makefile | 10 | ||||
-rw-r--r-- | libraries/libprof/README.txt | 2 | ||||
-rw-r--r-- | libraries/libprof/profil.c | 17 | ||||
-rw-r--r-- | libraries/libtfm/Makefile | 5 | ||||
-rw-r--r-- | projects/hsm/Makefile | 6 | ||||
-rw-r--r-- | projects/hsm/hsm.c | 5 | ||||
-rw-r--r-- | projects/hsm/mgmt-task.c | 9 | ||||
-rw-r--r-- | task.c | 8 | ||||
-rw-r--r-- | task.h | 2 |
9 files changed, 43 insertions, 21 deletions
@@ -117,6 +117,9 @@ CFLAGS += -I$(MBED_DIR)/targets/cmsis/TARGET_STM/TARGET_STM32F4 CFLAGS += -I$(MBED_DIR)/targets/cmsis/TARGET_STM/TARGET_STM32F4/$(BOARD) CFLAGS += -I$(MBED_DIR)/targets/hal/TARGET_STM/TARGET_STM32F4 CFLAGS += -I$(MBED_DIR)/targets/hal/TARGET_STM/TARGET_STM32F4/$(BOARD) +ifdef DO_TASK_METRICS +CFLAGS += -DDO_TASK_METRICS +endif %.o : %.c $(CC) $(CFLAGS) -c -o $@ $< @@ -124,7 +127,11 @@ CFLAGS += -I$(MBED_DIR)/targets/hal/TARGET_STM/TARGET_STM32F4/$(BOARD) %.o : %.S $(CC) $(CFLAGS) -c -o $@ $< +ifdef DO_PROFILING +all: hsm +else all: board-test cli-test libhal-test hsm bootloader +endif $(MBED_DIR)/libstmf4.a: .FORCE $(MAKE) -C $(MBED_DIR) @@ -152,9 +159,6 @@ libhal-test: $(BOARD_OBJS) $(LIBS) $(LIBHAL_BLD)/libhal.a .FORCE ifdef DO_PROFILING CFLAGS += -pg -DDO_PROFILING -endif -ifdef DO_TASK_METRICS -CFLAGS += -DDO_TASK_METRICS hsm: $(BOARD_OBJS) $(LIBS) $(LIBHAL_BLD)/libhal.a $(LIBCLI_BLD)/libcli.a $(LIBPROF_BLD)/libprof.a .FORCE $(MAKE) -C projects/hsm else diff --git a/libraries/libprof/README.txt b/libraries/libprof/README.txt index 1fe378c..f0b8ee8 100644 --- a/libraries/libprof/README.txt +++ b/libraries/libprof/README.txt @@ -52,7 +52,7 @@ In the OpenOCD console, enable semihosting: In another window, start the debugger: - $ sw/stm32/bin/debug projects/hsm/hsm + $ ../../bin/debug 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`. diff --git a/libraries/libprof/profil.c b/libraries/libprof/profil.c index 0654879..b0d8d55 100644 --- a/libraries/libprof/profil.c +++ b/libraries/libprof/profil.c @@ -25,27 +25,30 @@ static struct profinfo prof = { PROFILE_NOT_INIT, 0, 0, 0, 0 }; -extern void set_SysTick_hook(void (*hook)(void)); - /* sample the current program counter */ -static void SysTick_hook(void) { - size_t pc = (size_t)((uint32_t *)__get_MSP())[8]; - if (pc >= prof.lowpc && pc < prof.highpc) { +void profil_callback(void) { + if (prof.state == PROFILE_ON) { + /* The interrupt mechanism pushes xPSR, PC, LR, R12, and R3-R0 onto the + * stack, so PC is the 6th word from the top at that point. However, the + * normal function entry code pushes registers as well, so the stack + * offset right now depends on the call tree that got us here. + */ + size_t pc = (size_t)((uint32_t *)__get_MSP())[6 + 6]; + if (pc >= prof.lowpc && pc < prof.highpc) { size_t idx = PROFIDX (pc, prof.lowpc, prof.scale); prof.counter[idx]++; + } } } /* Stop profiling to the profiling buffer pointed to by p. */ static int profile_off (struct profinfo *p) { - set_SysTick_hook(NULL); p->state = PROFILE_OFF; return 0; } /* Create a timer thread and pass it a pointer P to the profiling buffer. */ static int profile_on (struct profinfo *p) { - set_SysTick_hook(SysTick_hook); p->state = PROFILE_ON; return 0; /* ok */ } diff --git a/libraries/libtfm/Makefile b/libraries/libtfm/Makefile index ceb8541..5be45f4 100644 --- a/libraries/libtfm/Makefile +++ b/libraries/libtfm/Makefile @@ -30,7 +30,12 @@ LIB := tomsfastmath/libtfm.a # for now, at least until we confirm that it hasn't already been fixed # in a newer version of libtfm. +ifdef DO_PROFILING +# arm-none-eabi-gcc: error: -pg and -fomit-frame-pointer are incompatible +STM32_LIBTFM_CFLAGS_OPTIMIZATION := -O3 -funroll-loops +else STM32_LIBTFM_CFLAGS_OPTIMIZATION := -O3 -funroll-loops -fomit-frame-pointer +endif CFLAGS := $(subst ${STM32_CFLAGS_OPTIMIZATION},${STM32_LIBTFM_CFLAGS_OPTIMIZATION},${CFLAGS}) CFLAGS += -DTFM_ARM -Dasm=__asm__ -Wa,-mimplicit-it=thumb diff --git a/projects/hsm/Makefile b/projects/hsm/Makefile index 429069d..9a75b92 100644 --- a/projects/hsm/Makefile +++ b/projects/hsm/Makefile @@ -12,8 +12,6 @@ OBJS = mgmt-cli.o \ log.o \ $(TOPLEVEL)/task.o -CFLAGS += -DTASK_METRICS - CFLAGS += -DNUM_RPC_TASK=4 CFLAGS += -I$(LIBHAL_SRC) @@ -32,6 +30,10 @@ LIBS += $(LIBPROF_BLD)/libprof.a LDFLAGS += --specs=rdimon.specs -lc -lrdimon endif +ifdef DO_TASK_METRICS +CFLAGS += -DDO_TASK_METRICS +endif + all: $(PROJ:=.elf) %.elf: %.o $(BOARD_OBJS) $(OBJS) $(LIBS) diff --git a/projects/hsm/hsm.c b/projects/hsm/hsm.c index b6b8820..5ef2ccc 100644 --- a/projects/hsm/hsm.c +++ b/projects/hsm/hsm.c @@ -268,6 +268,11 @@ size_t uart_rx_max = 0; void HAL_SYSTICK_Callback(void) { +#ifdef DO_PROFILING + extern void profil_callback(void); + profil_callback(); +#endif + size_t count = RINGBUF_COUNT(uart_ringbuf); if (uart_rx_max < count) uart_rx_max = count; diff --git a/projects/hsm/mgmt-task.c b/projects/hsm/mgmt-task.c index 9f6a908..4668585 100644 --- a/projects/hsm/mgmt-task.c +++ b/projects/hsm/mgmt-task.c @@ -73,7 +73,7 @@ static int cmd_task_show(struct cli_def *cli, const char *command, char *argv[], return CLI_OK; } -#ifdef TASK_METRICS +#ifdef DO_TASK_METRICS static int cmd_task_show_metrics(struct cli_def *cli, const char *command, char *argv[], int argc) { struct task_metrics tm; @@ -99,9 +99,12 @@ void configure_cli_task(struct cli_def *cli) struct cli_command *c = cli_register_command(cli, NULL, "task", NULL, 0, 0, NULL); /* task show */ - struct cli_command *c_show = cli_register_command(cli, c, "show", cmd_task_show, 0, 0, "Show the active tasks"); +#ifdef DO_TASK_METRICS + struct cli_command *c_show = +#endif + cli_register_command(cli, c, "show", cmd_task_show, 0, 0, "Show the active tasks"); -#ifdef TASK_METRICS +#ifdef DO_TASK_METRICS /* task show metrics */ cli_register_command(cli, c_show, "metrics", cmd_task_show_metrics, 0, 0, "Show task metrics"); @@ -81,7 +81,7 @@ static tcb_t *cur_task = NULL; #define STACK_GUARD_WORD 0x55AA5A5A -#ifdef TASK_METRICS +#ifdef DO_TASK_METRICS static uint32_t tick_start = 0; static uint32_t tick_idle = 0; static uint32_t tick_max = 0; @@ -192,7 +192,7 @@ void task_yield(void) if (tail == NULL) return; -#ifdef TASK_METRICS +#ifdef DO_TASK_METRICS uint32_t tick0 = HAL_GetTick(); #endif @@ -213,7 +213,7 @@ void task_yield(void) * } while (next == NULL); */ -#ifdef TASK_METRICS +#ifdef DO_TASK_METRICS uint32_t tick = HAL_GetTick(); tick_idle += (tick - tick0); if (tick_start == 0) @@ -395,7 +395,7 @@ void task_mutex_unlock(task_mutex_t *mutex) mutex->locked = 0; } -#ifdef TASK_METRICS +#ifdef DO_TASK_METRICS void task_get_metrics(struct task_metrics *tm) { if (tm != NULL) { @@ -74,7 +74,7 @@ extern void task_delay(uint32_t delay); extern void task_mutex_lock(task_mutex_t *mutex); extern void task_mutex_unlock(task_mutex_t *mutex); -#ifdef TASK_METRICS +#ifdef DO_TASK_METRICS #include <sys/time.h> struct task_metrics { |