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 d483364481b sched/wqueue: add configuring the stack of an 
hpwork/lpwork as static
d483364481b is described below

commit d483364481b39a6251e442ae4dc297828903349f
Author: pangzhen1 <[email protected]>
AuthorDate: Fri Feb 21 20:13:35 2025 +0800

    sched/wqueue: add configuring the stack of an hpwork/lpwork as static
    
    Allows configuring a static stack for hpwork/lpwork.
    
    Signed-off-by: pangzhen1 <[email protected]>
---
 sched/Kconfig               | 12 ++++++++++++
 sched/wqueue/CMakeLists.txt | 12 ++++++++++++
 sched/wqueue/Make.defs      |  8 ++++++++
 sched/wqueue/kwork_thread.c | 39 ++++++++++++++++++++++++++++++++++++---
 4 files changed, 68 insertions(+), 3 deletions(-)

diff --git a/sched/Kconfig b/sched/Kconfig
index 0e833d15864..34db4e5d92e 100644
--- a/sched/Kconfig
+++ b/sched/Kconfig
@@ -1855,6 +1855,12 @@ config SCHED_HPWORKSTACKSIZE
        ---help---
                The stack size allocated for the worker thread.  Default: 2K.
 
+config SCHED_HPWORKSTACKSECTION
+       string "The section where hpwork stack is located"
+       default ""
+       ---help---
+               The section where hpwork stack is located.
+
 endif # SCHED_HPWORK
 
 config SCHED_LPWORK
@@ -1954,6 +1960,12 @@ config SCHED_LPWORKSTACKSIZE
        ---help---
                The stack size allocated for the lower priority worker thread.  
Default: 2K.
 
+config SCHED_LPWORKSTACKSECTION
+       string "The section where lpwork stack is located"
+       default ""
+       ---help---
+               The section where lpwork stack is located.
+
 endif # SCHED_LPWORK
 endmenu # Work Queue Support
 
diff --git a/sched/wqueue/CMakeLists.txt b/sched/wqueue/CMakeLists.txt
index 7b325beae46..90e012b098e 100644
--- a/sched/wqueue/CMakeLists.txt
+++ b/sched/wqueue/CMakeLists.txt
@@ -38,6 +38,18 @@ if(CONFIG_SCHED_WORKQUEUE)
     list(APPEND SRCS kwork_notifier.c)
   endif()
 
+  if(CONFIG_SCHED_HPWORKSTACKSECTION)
+    target_compile_definitions(
+      sched
+      PRIVATE -DSCHED_HPWORKSTACKSECTION="${CONFIG_SCHED_HPWORKSTACKSECTION}")
+  endif()
+
+  if(CONFIG_SCHED_LPWORKSTACKSECTION)
+    target_compile_definitions(
+      sched
+      PRIVATE -DSCHED_LPWORKSTACKSECTION="${CONFIG_SCHED_LPWORKSTACKSECTION}")
+  endif()
+
   target_sources(sched PRIVATE ${SRCS})
 
 endif()
diff --git a/sched/wqueue/Make.defs b/sched/wqueue/Make.defs
index baa93f72e6f..04e735dae92 100644
--- a/sched/wqueue/Make.defs
+++ b/sched/wqueue/Make.defs
@@ -36,6 +36,14 @@ ifeq ($(CONFIG_WQUEUE_NOTIFIER),y)
 CSRCS += kwork_notifier.c
 endif
 
+ifneq ($(CONFIG_SCHED_HPWORKSTACKSECTION),"")
+  CFLAGS += 
${DEFINE_PREFIX}SCHED_HPWORKSTACKSECTION=CONFIG_SCHED_HPWORKSTACKSECTION
+endif
+
+ifneq ($(CONFIG_SCHED_LPWORKSTACKSECTION),"")
+  CFLAGS += 
${DEFINE_PREFIX}SCHED_LPWORKSTACKSECTION=CONFIG_SCHED_LPWORKSTACKSECTION
+endif
+
 # Include wqueue build support
 
 DEPPATH += --dep-path wqueue
diff --git a/sched/wqueue/kwork_thread.c b/sched/wqueue/kwork_thread.c
index 725461d76d2..7461ccdc8d7 100644
--- a/sched/wqueue/kwork_thread.c
+++ b/sched/wqueue/kwork_thread.c
@@ -308,6 +308,7 @@ static int work_thread_create(FAR const char *name, int 
priority,
   char arg1[32];
   int wndx;
   int pid;
+  FAR void *stack = NULL;
 
   /* Don't permit any of the threads to run until we have fully initialized
    * all of them.
@@ -325,8 +326,15 @@ static int work_thread_create(FAR const char *name, int 
priority,
       argv[1] = arg1;
       argv[2] = NULL;
 
-      pid = kthread_create_with_stack(name, priority, stack_addr, stack_size,
-                                      work_thread, argv);
+      /* In case of the stack_addr is NULL */
+
+      if (stack_addr)
+        {
+          stack = (FAR void *)((uintptr_t)stack_addr + wndx * stack_size);
+        }
+
+      pid = kthread_create_with_stack(name, priority, stack,
+                                      stack_size, work_thread, argv);
 
       DEBUGASSERT(pid > 0);
       if (pid < 0)
@@ -550,9 +558,21 @@ int work_start_highpri(void)
 
   sinfo("Starting high-priority kernel worker thread(s)\n");
 
+#ifdef SCHED_HPWORKSTACKSECTION
+  static uint8_t hp_work_stack[CONFIG_SCHED_HPNTHREADS]
+                              [CONFIG_SCHED_HPWORKSTACKSIZE]
+  locate_data(CONFIG_SCHED_HPWORKSTACKSECTION);
+
+  return work_thread_create(HPWORKNAME,
+                            CONFIG_SCHED_HPWORKPRIORITY,
+                            hp_work_stack,
+                            CONFIG_SCHED_HPWORKSTACKSIZE,
+                            (FAR struct kwork_wqueue_s *)&g_hpwork);
+#else
   return work_thread_create(HPWORKNAME, CONFIG_SCHED_HPWORKPRIORITY, NULL,
                             CONFIG_SCHED_HPWORKSTACKSIZE,
                             (FAR struct kwork_wqueue_s *)&g_hpwork);
+#endif
 }
 #endif /* CONFIG_SCHED_HPWORK */
 
@@ -578,9 +598,22 @@ int work_start_lowpri(void)
 
   sinfo("Starting low-priority kernel worker thread(s)\n");
 
-  return work_thread_create(LPWORKNAME, CONFIG_SCHED_LPWORKPRIORITY, NULL,
+#ifdef SCHED_LPWORKSTACKSECTION
+  static uint8_t lp_work_stack[CONFIG_SCHED_LPNTHREADS]
+                              [CONFIG_SCHED_LPWORKSTACKSIZE]
+  locate_data(CONFIG_SCHED_LPWORKSTACKSECTION);
+
+  return work_thread_create(LPWORKNAME,
+                            CONFIG_SCHED_LPWORKPRIORITY,
+                            lp_work_stack,
                             CONFIG_SCHED_LPWORKSTACKSIZE,
                             (FAR struct kwork_wqueue_s *)&g_lpwork);
+#else
+  return work_thread_create(LPWORKNAME,
+                            CONFIG_SCHED_LPWORKPRIORITY, NULL,
+                            CONFIG_SCHED_LPWORKSTACKSIZE,
+                            (FAR struct kwork_wqueue_s *)&g_lpwork);
+#endif
 }
 #endif /* CONFIG_SCHED_LPWORK */
 

Reply via email to