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

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

commit 03cdef8d5888eb6e5159c7f783f121350fae9820
Author: jingfei <[email protected]>
AuthorDate: Wed Oct 14 01:14:36 2026 +0800

    sched/spawn: skip policy handling on FIFO-only builds
    
    With CONFIG_RR_INTERVAL=0 and no CONFIG_SCHED_SPORADIC, SCHED_FIFO is
    the only scheduling policy and every task already runs with it. Still,
    posix_spawnattr_init() queries the caller's policy and
    spawn_execattrs() calls nxsched_set_scheduler(), which keeps the
    policy-switching code linked.
    
    In that configuration default the spawn policy to SCHED_FIFO and only
    set the priority. Other policies are still rejected with -EINVAL.
    
    stm32f103-minimum:nsh with RR_INTERVAL=0: text -176 bytes. Builds with
    round-robin or sporadic scheduling are unchanged.
    
    Signed-off-by: jingfei <[email protected]>
---
 libs/libc/spawn/lib_psa_init.c | 4 ++++
 sched/task/task_spawnparms.c   | 9 +++++++++
 2 files changed, 13 insertions(+)

diff --git a/libs/libc/spawn/lib_psa_init.c b/libs/libc/spawn/lib_psa_init.c
index 804d1561d81..3139803f7f2 100644
--- a/libs/libc/spawn/lib_psa_init.c
+++ b/libs/libc/spawn/lib_psa_init.c
@@ -82,6 +82,7 @@ int posix_spawnattr_init(posix_spawnattr_t *attr)
 
   /* Set the default scheduler policy to the policy of this task */
 
+#if CONFIG_RR_INTERVAL > 0 || defined(CONFIG_SCHED_SPORADIC)
   ret = _SCHED_GETSCHEDULER(0);
   if (ret < 0)
     {
@@ -89,6 +90,9 @@ int posix_spawnattr_init(posix_spawnattr_t *attr)
     }
 
   attr->policy              = ret;
+#else
+  attr->policy              = SCHED_FIFO;
+#endif
 
   /* Empty signal mask */
 
diff --git a/sched/task/task_spawnparms.c b/sched/task/task_spawnparms.c
index ca2d683479a..76f78da9309 100644
--- a/sched/task/task_spawnparms.c
+++ b/sched/task/task_spawnparms.c
@@ -227,7 +227,16 @@ int spawn_execattrs(pid_t pid, FAR const posix_spawnattr_t 
*attr)
       param.sched_ss_init_budget.tv_sec  = attr->budget.tv_sec;
       param.sched_ss_init_budget.tv_nsec = attr->budget.tv_nsec;
 #endif
+#if CONFIG_RR_INTERVAL > 0 || defined(CONFIG_SCHED_SPORADIC)
       ret = nxsched_set_scheduler(pid, attr->policy, &param);
+#else
+      /* SCHED_FIFO is the only policy and SCHED_OTHER maps to it, so only
+       * the priority can change.
+       */
+
+      ret = attr->policy == SCHED_FIFO || attr->policy == SCHED_OTHER ?
+            nxsched_set_param(pid, &param) : -EINVAL;
+#endif
     }
 
   return ret;

Reply via email to