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 eebe998662fd7490708e012cde5a89bd8fd2e85d
Author: jingfei <[email protected]>
AuthorDate: Wed Oct 14 00:57:26 2026 +0800

    sched/wqueue: move g_hpwork/g_lpwork to .bss
    
    The static initializers put both kernel work queues in .data, so their
    initial image is kept in flash although only the self-referencing list
    heads and the thread count are non-zero.
    
    Leave the queues in .bss and set those fields in work_initialize(),
    called at the start of nx_start() before anything can queue work. The
    semaphores, spinlock and timer were zero-initialized before as well.
    
    stm32f103-minimum:nsh: flash -96 bytes (-192 with SCHED_LPWORK), RAM
    unchanged.
    
    Signed-off-by: jingfei <[email protected]>
---
 sched/init/nx_start.c       |  5 +++++
 sched/wqueue/kwork_thread.c | 49 +++++++++++++++++++++++++--------------------
 sched/wqueue/wqueue.h       | 11 ++++++++++
 3 files changed, 43 insertions(+), 22 deletions(-)

diff --git a/sched/init/nx_start.c b/sched/init/nx_start.c
index 7dc7d1a918a..777e0174950 100644
--- a/sched/init/nx_start.c
+++ b/sched/init/nx_start.c
@@ -51,6 +51,7 @@
 
 #include "task/task.h"
 #include "sched/sched.h"
+#include "wqueue/wqueue.h"
 #include "signal/signal.h"
 #include "semaphore/semaphore.h"
 #include "mqueue/mqueue.h"
@@ -479,6 +480,10 @@ void nx_start(void)
   g_nx_initstate = OSINIT_BOOT;
   sched_trace_mark("BOOT");
 
+#ifdef CONFIG_SCHED_WORKQUEUE
+  work_initialize();
+#endif
+
   /* Initialize the IDLE task TCB *******************************************/
 
   idle_task_initialize();
diff --git a/sched/wqueue/kwork_thread.c b/sched/wqueue/kwork_thread.c
index ace0c393fb5..65652886032 100644
--- a/sched/wqueue/kwork_thread.c
+++ b/sched/wqueue/kwork_thread.c
@@ -82,34 +82,14 @@
 #if defined(CONFIG_SCHED_HPWORK)
 /* The state of the kernel mode, high priority work queue(s). */
 
-struct hp_wqueue_s g_hpwork =
-{
-  {
-    LIST_INITIAL_VALUE(g_hpwork.wq.expired),
-    LIST_INITIAL_VALUE(g_hpwork.wq.pending),
-    SEM_INITIALIZER(0),
-    SEM_INITIALIZER(0),
-    SP_UNLOCKED,
-    CONFIG_SCHED_HPNTHREADS,
-  }
-};
+struct hp_wqueue_s g_hpwork;
 
 #endif /* CONFIG_SCHED_HPWORK */
 
 #if defined(CONFIG_SCHED_LPWORK)
 /* The state of the kernel mode, low priority work queue(s). */
 
-struct lp_wqueue_s g_lpwork =
-{
-  {
-    LIST_INITIAL_VALUE(g_lpwork.wq.expired),
-    LIST_INITIAL_VALUE(g_lpwork.wq.pending),
-    SEM_INITIALIZER(0),
-    SEM_INITIALIZER(0),
-    SP_UNLOCKED,
-    CONFIG_SCHED_LPNTHREADS,
-  }
-};
+struct lp_wqueue_s g_lpwork;
 
 #endif /* CONFIG_SCHED_LPWORK */
 
@@ -751,6 +731,31 @@ int work_queue_setpriority(int qid, int priority)
   return work_queue_setpriority_wq(work_qid2wq(qid), priority);
 }
 
+/****************************************************************************
+ * Name: work_initialize
+ *
+ * Description:
+ *   Set up the kernel work queues before any work can be queued.  The
+ *   queues live in .bss; only the self-referencing list heads and the
+ *   thread count differ from the zero state.
+ *
+ ****************************************************************************/
+
+void work_initialize(void)
+{
+#ifdef CONFIG_SCHED_HPWORK
+  list_initialize(&g_hpwork.wq.expired);
+  list_initialize(&g_hpwork.wq.pending);
+  g_hpwork.wq.nthreads = CONFIG_SCHED_HPNTHREADS;
+#endif
+
+#ifdef CONFIG_SCHED_LPWORK
+  list_initialize(&g_lpwork.wq.expired);
+  list_initialize(&g_lpwork.wq.pending);
+  g_lpwork.wq.nthreads = CONFIG_SCHED_LPNTHREADS;
+#endif
+}
+
 /****************************************************************************
  * Name: work_start_highpri
  *
diff --git a/sched/wqueue/wqueue.h b/sched/wqueue/wqueue.h
index 9e621da2b94..fe8f64bbecc 100644
--- a/sched/wqueue/wqueue.h
+++ b/sched/wqueue/wqueue.h
@@ -316,6 +316,17 @@ void work_timer_reset(FAR struct kwork_wqueue_s *wqueue)
     }
 }
 
+/****************************************************************************
+ * Name: work_initialize
+ *
+ * Description:
+ *   Initialize the kernel work queue state.  Must run before the first
+ *   work_queue() call.
+ *
+ ****************************************************************************/
+
+void work_initialize(void);
+
 /****************************************************************************
  * Name: work_start_highpri
  *

Reply via email to