[Cryptech-Commits] [sw/stm32] 03/03: Add task_yield_maybe

git at cryptech.is git at cryptech.is
Tue May 30 14:03:40 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 5ff8c9512db48d128cf07904f68eb5139bebf952
Author: Paul Selkirk <paul at psgd.org>
AuthorDate: Wed May 24 18:03:19 2017 -0400

    Add task_yield_maybe
---
 projects/hsm/hsm.c |  5 +++++
 task.c             | 16 +++++++++++++++-
 task.h             |  1 +
 3 files changed, 21 insertions(+), 1 deletion(-)

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 };
diff --git a/task.c b/task.c
index b0028e7..36e8580 100644
--- a/task.c
+++ b/task.c
@@ -83,12 +83,16 @@ static tcb_t *cur_task = NULL;
 
 #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
 
+static uint32_t tick_prev  = 0;
+#ifndef TASK_YIELD_THRESHOLD
+#define TASK_YIELD_THRESHOLD 100
+#endif
+
 /* Add a task.
  */
 tcb_t *task_add(char *name, funcp_t func, void *cookie, void *stack, size_t stack_len)
@@ -221,6 +225,8 @@ void task_yield(void)
     }
     tick_prev = tick;
     ++nyield;
+#else
+    tick_prev = HAL_GetTick();
 #endif
 
     /* If there are no other runnable tasks (and cur_task is runnable),
@@ -256,6 +262,14 @@ void task_yield(void)
     }
 }
 
+/* Yield if it's been "too long" since the last yield.
+ */
+void task_yield_maybe(void)
+{
+    if (HAL_GetTick() - tick_prev >= TASK_YIELD_THRESHOLD)
+        task_yield();
+}
+
 /* Put the current task to sleep (make it non-runnable).
  */
 void task_sleep(void)
diff --git a/task.h b/task.h
index de3e275..47d62d6 100644
--- a/task.h
+++ b/task.h
@@ -55,6 +55,7 @@ extern tcb_t *task_add(char *name, funcp_t func, void *cookie, void *stack, size
 extern void task_set_idle_hook(funcp_t func);
 
 extern void task_yield(void);
+extern void task_yield_maybe(void);
 extern void task_sleep(void);
 extern void task_wake(tcb_t *t);
 



More information about the Commits mailing list