[Cryptech-Commits] [sw/stm32] 01/03: Merge branch 'task_metrics' into profiling
git at cryptech.is
git at cryptech.is
Tue May 30 14:03:38 UTC 2017
This is an automated email from the git hooks/post-receive script.
paul at psgd.org pushed a commit to branch profiling
in repository sw/stm32.
commit a7ee9a7b76a4ec90d9f864adfc4342f13f8bd499
Merge: 65b94ef 7ef51e8
Author: Paul Selkirk <paul at psgd.org>
AuthorDate: Sat May 13 13:14:56 2017 -0400
Merge branch 'task_metrics' into profiling
projects/hsm/Makefile | 4 ++++
projects/hsm/mgmt-task.c | 34 +++++++++++++++++++++++++++++++++-
task.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
task.h | 11 +++++++++++
4 files changed, 96 insertions(+), 1 deletion(-)
diff --cc projects/hsm/Makefile
index 4df60d7,ecd1a5d..9a75b92
--- a/projects/hsm/Makefile
+++ b/projects/hsm/Makefile
@@@ -20,16 -23,6 +20,20 @@@ 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
+OBJS += $(TOPLEVEL)/memfunc.o
+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 --cc projects/hsm/mgmt-task.c
index a1ae7e6,12ce2b8..1658a80
--- a/projects/hsm/mgmt-task.c
+++ b/projects/hsm/mgmt-task.c
@@@ -69,10 -69,42 +69,42 @@@ static int cmd_task_show(struct cli_de
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;
+
+ 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
++#ifdef DO_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
}
diff --cc task.c
index 2e2ddec,e156940..b0028e7
--- a/task.c
+++ b/task.c
@@@ -81,6 -81,14 +81,14 @@@ 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_prev = 0;
+ static uint32_t tick_idle = 0;
+ static uint32_t tick_max = 0;
+ static uint32_t nyield = 0;
+ #endif
+
/* Add a task.
*/
tcb_t *task_add(char *name, funcp_t func, void *cookie, void *stack, size_t stack_len)
@@@ -180,6 -188,10 +188,10 @@@ void task_yield(void
if (tail == NULL)
return;
-#ifdef TASK_METRICS
++#ifdef DO_TASK_METRICS
+ uint32_t tick0 = HAL_GetTick();
+ #endif
+
/* Find the next runnable task. Loop if every task is waiting. */
while (1) {
next = next_task();
@@@ -197,6 -209,20 +209,20 @@@
* } while (next == NULL);
*/
-#ifdef TASK_METRICS
++#ifdef DO_TASK_METRICS
+ uint32_t tick = HAL_GetTick();
+ tick_idle += (tick - tick0);
+ if (tick_start == 0)
+ tick_start = tick;
+ if (tick_prev != 0) {
+ uint32_t duration = tick0 - tick_prev;
+ if (duration > tick_max)
+ tick_max = duration;
+ }
+ tick_prev = tick;
+ ++nyield;
+ #endif
+
/* If there are no other runnable tasks (and cur_task is runnable),
* we don't need to context-switch.
*/
@@@ -354,3 -380,25 +380,25 @@@ void task_mutex_unlock(task_mutex_t *mu
if (mutex != NULL)
mutex->locked = 0;
}
+
-#ifdef TASK_METRICS
++#ifdef DO_TASK_METRICS
+ void task_get_metrics(struct task_metrics *tm)
+ {
+ if (tm != NULL) {
+ tm->avg.tv_sec = 0;
+ tm->avg.tv_usec = (HAL_GetTick() - tick_start - tick_idle) * 1000 / nyield;
+ if (tm->avg.tv_usec > 1000000) {
+ tm->avg.tv_sec = tm->avg.tv_usec / 1000000;
+ tm->avg.tv_usec = tm->avg.tv_usec % 1000000;
+ }
+ tm->max.tv_sec = tick_max / 1000;
+ tm->max.tv_usec = (tick_max % 1000) * 1000;
+ }
+ }
+
+ void task_reset_metrics(void)
+ {
+ tick_start = HAL_GetTick();
+ tick_prev = tick_idle = tick_max = nyield = 0;
+ }
+ #endif
diff --cc task.h
index 6b45db8,24f87ce..de3e275
--- a/task.h
+++ b/task.h
@@@ -73,4 -73,15 +73,15 @@@ 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 {
+ struct timeval avg, max;
+ };
+
+ void task_get_metrics(struct task_metrics *tm);
+ void task_reset_metrics(void);
+ #endif
+
#endif /* _TASK_H_ */
More information about the Commits
mailing list