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

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

commit 1c2a2f98413d6745ebf36182d8c421e74912474e
Author: jingfei <[email protected]>
AuthorDate: Tue Oct 13 18:09:17 2026 +0800

    sched: optional inline for nxsched_add_prioritized
    
    nxsched_add_prioritized() is inlined into all 18 call sites across
    the scheduler, semaphores, message queues and events.
    
    Add SCHED_INLINE_ADDPRIORITIZED, default !DEFAULT_SMALL. Small builds
    now use one shared copy; default builds are unchanged.
    
    stm32f103-minimum:nsh (DEFAULT_SMALL=y): text -200 bytes.
    
    Signed-off-by: jingfei <[email protected]>
---
 sched/Kconfig                      |  8 +++++++
 sched/sched/CMakeLists.txt         |  4 ++++
 sched/sched/Make.defs              |  4 ++++
 sched/sched/sched.h                | 15 +++++++++++--
 sched/sched/sched_addprioritized.c | 43 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 72 insertions(+), 2 deletions(-)

diff --git a/sched/Kconfig b/sched/Kconfig
index 4fb39a2ea40..12b5f91802b 100644
--- a/sched/Kconfig
+++ b/sched/Kconfig
@@ -614,6 +614,14 @@ config ETC_FATMOUNTPT
 
 endif # ETC_ROMFS
 
+config SCHED_INLINE_ADDPRIORITIZED
+       bool "Inline nxsched_add_prioritized()"
+       default !DEFAULT_SMALL
+       ---help---
+               Inline nxsched_add_prioritized() into every scheduler, 
semaphore and
+               message queue caller for speed.  Disable to emit one shared copy
+               instead and save code space.
+
 config RR_INTERVAL
        int "Round robin timeslice (MSEC)"
        default 0
diff --git a/sched/sched/CMakeLists.txt b/sched/sched/CMakeLists.txt
index be709a4ecb0..9c2cb617da4 100644
--- a/sched/sched/CMakeLists.txt
+++ b/sched/sched/CMakeLists.txt
@@ -50,6 +50,10 @@ set(SRCS
     sched_switchcontext.c
     sched_sleep.c)
 
+if(NOT CONFIG_SCHED_INLINE_ADDPRIORITIZED)
+  list(APPEND SRCS sched_addprioritized.c)
+endif()
+
 if(DEFINED CONFIG_STACKCHECK_MARGIN)
   if(NOT CONFIG_STACKCHECK_MARGIN EQUAL -1)
     list(APPEND SRCS nxsched_checkstackoverflow.c)
diff --git a/sched/sched/Make.defs b/sched/sched/Make.defs
index 1aae136ecec..a612b244b0d 100644
--- a/sched/sched/Make.defs
+++ b/sched/sched/Make.defs
@@ -32,6 +32,10 @@ CSRCS += sched_idletask.c sched_self.c sched_get_stackinfo.c 
sched_get_tls.c
 CSRCS += sched_sysinfo.c sched_get_stateinfo.c sched_getcpu.c
 CSRCS += sched_switchcontext.c sched_sleep.c
 
+ifneq ($(CONFIG_SCHED_INLINE_ADDPRIORITIZED),y)
+CSRCS += sched_addprioritized.c
+endif
+
 ifneq ($(CONFIG_STACKCHECK_MARGIN),)
   ifneq ($(CONFIG_STACKCHECK_MARGIN),-1)
     CSRCS += nxsched_checkstackoverflow.c
diff --git a/sched/sched/sched.h b/sched/sched/sched.h
index 1d45d5b6da6..bd595f55d1b 100644
--- a/sched/sched/sched.h
+++ b/sched/sched/sched.h
@@ -474,8 +474,16 @@ FAR char **nxsched_get_stackargs(FAR struct tcb_s *tcb);
  * Inline functions
  ****************************************************************************/
 
-static inline_function bool nxsched_add_prioritized(FAR struct tcb_s *tcb,
-                                                    DSEG dq_queue_t *list)
+/* Single body for both forms: inline in every caller, or emitted once by
+ * sched_addprioritized.c (which defines SCHED_ADDPRIORITIZED_IMPL).
+ */
+
+#if defined(CONFIG_SCHED_INLINE_ADDPRIORITIZED) || \
+    defined(SCHED_ADDPRIORITIZED_IMPL)
+#  ifdef CONFIG_SCHED_INLINE_ADDPRIORITIZED
+static inline_function
+#  endif
+bool nxsched_add_prioritized(FAR struct tcb_s *tcb, DSEG dq_queue_t *list)
 {
   FAR struct tcb_s *next;
   FAR struct tcb_s *prev;
@@ -552,6 +560,9 @@ static inline_function bool nxsched_add_prioritized(FAR 
struct tcb_s *tcb,
 
   return ret;
 }
+#else
+bool nxsched_add_prioritized(FAR struct tcb_s *tcb, DSEG dq_queue_t *list);
+#endif
 
 #  ifdef CONFIG_SMP
 
diff --git a/sched/sched/sched_addprioritized.c 
b/sched/sched/sched_addprioritized.c
new file mode 100644
index 00000000000..509dcd9e574
--- /dev/null
+++ b/sched/sched/sched_addprioritized.c
@@ -0,0 +1,43 @@
+/****************************************************************************
+ * sched/sched/sched_addprioritized.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <assert.h>
+
+#include <nuttx/queue.h>
+
+/* Emit the out-of-line definition of nxsched_add_prioritized() from
+ * sched.h.
+ */
+#define SCHED_ADDPRIORITIZED_IMPL
+#include "sched/sched.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/* nxsched_add_prioritized() is defined in sched/sched.h. */

Reply via email to