You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ja...@apache.org on 2019/11/28 10:29:08 UTC

[mynewt-core] branch master updated: kernel/os: Add os_task_info_get function

This is an automated email from the ASF dual-hosted git repository.

janc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 28c926d  kernel/os: Add os_task_info_get function
28c926d is described below

commit 28c926d02e7c9a741af14e1de936485e1b1a8f9f
Author: Szymon Janc <sz...@codecoup.pl>
AuthorDate: Tue Nov 26 16:57:55 2019 +0100

    kernel/os: Add os_task_info_get function
    
    This allows to get info about specified task.
---
 kernel/os/include/os/os_task.h | 17 ++++++++++++
 kernel/os/src/os_task.c        | 63 +++++++++++++++++++++---------------------
 2 files changed, 49 insertions(+), 31 deletions(-)

diff --git a/kernel/os/include/os/os_task.h b/kernel/os/include/os/os_task.h
index 503501b..2955a6a 100644
--- a/kernel/os/include/os/os_task.h
+++ b/kernel/os/include/os/os_task.h
@@ -232,6 +232,23 @@ struct os_task_info {
 struct os_task *os_task_info_get_next(const struct os_task *,
         struct os_task_info *);
 
+/**
+ * Get following info about specified task
+ * - Priority
+ * - Task ID
+ * - State (READY, SLEEP)
+ * - Total Stack Usage
+ * - Stack Size
+ * - Context Switch Count
+ * - Runtime
+ * - Last & Next Sanity checkin
+ * - Task Name
+ *
+ *  @param task The task to get info about
+ *  @param oti  The OS task info structure to fill out.
+ */
+void os_task_info_get(const struct os_task *task, struct os_task_info *oti);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/kernel/os/src/os_task.c b/kernel/os/src/os_task.c
index 02f64be..fbdd8b3 100644
--- a/kernel/os/src/os_task.c
+++ b/kernel/os/src/os_task.c
@@ -168,13 +168,40 @@ os_task_remove(struct os_task *t)
     return rc;
 }
 
+void
+os_task_info_get(const struct os_task *task, struct os_task_info *oti)
+{
+    os_stack_t *bottom;
+    os_stack_t *top;
+
+    oti->oti_prio = task->t_prio;
+    oti->oti_taskid = task->t_taskid;
+    oti->oti_state = task->t_state;
+
+    top = task->t_stacktop;
+    bottom = task->t_stacktop - task->t_stacksize;
+    while (bottom < top) {
+        if (*bottom != OS_STACK_PATTERN) {
+            break;
+        }
+        ++bottom;
+    }
+
+    oti->oti_stkusage = (uint16_t) (task->t_stacktop - bottom);
+    oti->oti_stksize = task->t_stacksize;
+    oti->oti_cswcnt = task->t_ctx_sw_cnt;
+    oti->oti_runtime = task->t_run_time;
+    oti->oti_last_checkin = task->t_sanity_check.sc_checkin_last;
+    oti->oti_next_checkin = task->t_sanity_check.sc_checkin_last +
+                            task->t_sanity_check.sc_checkin_itvl;
+    oti->oti_name[0] = '\0';
+    strncat(oti->oti_name, task->t_name, sizeof(oti->oti_name) - 1);
+}
 
 struct os_task *
 os_task_info_get_next(const struct os_task *prev, struct os_task_info *oti)
 {
     struct os_task *next;
-    os_stack_t *top;
-    os_stack_t *bottom;
 
     if (prev != NULL) {
         next = STAILQ_NEXT(prev, t_os_task_list);
@@ -182,36 +209,10 @@ os_task_info_get_next(const struct os_task *prev, struct os_task_info *oti)
         next = STAILQ_FIRST(&g_os_task_list);
     }
 
-    if (next == NULL) {
-        return (NULL);
+    if (next) {
+        os_task_info_get(next, oti);
     }
 
-    /* Otherwise, copy OS task information into the OTI structure, and
-     * return 1, which means continue
-     */
-    oti->oti_prio = next->t_prio;
-    oti->oti_taskid = next->t_taskid;
-    oti->oti_state = next->t_state;
-
-    top = next->t_stacktop;
-    bottom = next->t_stacktop - next->t_stacksize;
-    while (bottom < top) {
-        if (*bottom != OS_STACK_PATTERN) {
-            break;
-        }
-        ++bottom;
-    }
-
-    oti->oti_stkusage = (uint16_t) (next->t_stacktop - bottom);
-    oti->oti_stksize = next->t_stacksize;
-    oti->oti_cswcnt = next->t_ctx_sw_cnt;
-    oti->oti_runtime = next->t_run_time;
-    oti->oti_last_checkin = next->t_sanity_check.sc_checkin_last;
-    oti->oti_next_checkin = next->t_sanity_check.sc_checkin_last +
-        next->t_sanity_check.sc_checkin_itvl;
-    oti->oti_name[0] = '\0';
-    strncat(oti->oti_name, next->t_name, sizeof(oti->oti_name) - 1);
-
-    return (next);
+    return next;
 }