You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2024/09/09 11:45:34 UTC

(nuttx) branch master updated: sched/group/setuptask_file: duplicate idle task fd for kernel thread

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

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 4e24eec7b6 sched/group/setuptask_file: duplicate idle task fd for kernel thread
4e24eec7b6 is described below

commit 4e24eec7b607e4a6a7eca0fae9c58f02dc72e002
Author: dongjiuzhu1 <do...@xiaomi.com>
AuthorDate: Tue Jun 25 13:57:35 2024 +0800

    sched/group/setuptask_file: duplicate idle task fd for kernel thread
    
    The file descriptors of kernel threads should be clean and should
    not be generated based on user threads. Instead, an idle thread
    hould be chosen.
    
    Signed-off-by: dongjiuzhu1 <do...@xiaomi.com>
---
 sched/group/group_setuptaskfiles.c | 17 +++++++++++++++--
 sched/init/nx_start.c              |  2 +-
 sched/sched/sched.h                | 10 ++++++++++
 3 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/sched/group/group_setuptaskfiles.c b/sched/group/group_setuptaskfiles.c
index 26624e4ce6..8b4b07e49d 100644
--- a/sched/group/group_setuptaskfiles.c
+++ b/sched/group/group_setuptaskfiles.c
@@ -64,7 +64,7 @@ int group_setuptaskfiles(FAR struct task_tcb_s *tcb,
   FAR struct task_group_s *group = tcb->cmn.group;
   int ret = OK;
 #ifndef CONFIG_FDCLONE_DISABLE
-  FAR struct tcb_s *rtcb = this_task();
+  FAR struct tcb_s *rtcb;
 #endif
 
   sched_trace_begin();
@@ -75,7 +75,20 @@ int group_setuptaskfiles(FAR struct task_tcb_s *tcb,
 #endif
 
 #ifndef CONFIG_FDCLONE_DISABLE
-  DEBUGASSERT(rtcb->group);
+
+  /* The The file descriptors of kernel threads should be clean and
+   * should not be generated based on user threads. Instead, an idle
+   * thread should be chosen.
+   */
+
+  if ((tcb->cmn.flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_KERNEL)
+    {
+      rtcb = &g_idletcb[this_cpu()];
+    }
+  else
+    {
+      rtcb = this_task();
+    }
 
   /* Duplicate the parent task's file descriptors */
 
diff --git a/sched/init/nx_start.c b/sched/init/nx_start.c
index 997612739c..9e3c072067 100644
--- a/sched/init/nx_start.c
+++ b/sched/init/nx_start.c
@@ -206,7 +206,7 @@ uint8_t g_nx_initstate;  /* See enum nx_initstate_e */
  * bringing up the rest of the system.
  */
 
-static struct tcb_s g_idletcb[CONFIG_SMP_NCPUS];
+struct tcb_s g_idletcb[CONFIG_SMP_NCPUS];
 
 /* This is the name of the idle task */
 
diff --git a/sched/sched/sched.h b/sched/sched/sched.h
index b14c0d50b0..660a997fc6 100644
--- a/sched/sched/sched.h
+++ b/sched/sched/sched.h
@@ -194,6 +194,16 @@ extern dq_queue_t g_assignedtasks[CONFIG_SMP_NCPUS];
 
 extern FAR struct tcb_s *g_running_tasks[CONFIG_SMP_NCPUS];
 
+/* This is an array of task control block (TCB) for the IDLE thread of each
+ * CPU.  For the non-SMP case, this is a a single TCB; For the SMP case,
+ * there is one TCB per CPU.  NOTE: The system boots on CPU0 into the IDLE
+ * task.  The IDLE task later starts the other CPUs and spawns the user
+ * initialization task.  That user initialization task is responsible for
+ * bringing up the rest of the system.
+ */
+
+extern struct tcb_s g_idletcb[CONFIG_SMP_NCPUS];
+
 /* This is the list of all tasks that are ready-to-run, but cannot be placed
  * in the g_readytorun list because:  (1) They are higher priority than the
  * currently active task at the head of the g_readytorun list, and (2) the