sched/wqueue: add configuring the stack of an hpwork/lpwork as static

Allows configuring a static stack for hpwork/lpwork.

Signed-off-by: pangzhen1 <pangzhen1@xiaomi.com>
This commit is contained in:
pangzhen1
2025-02-21 20:13:35 +08:00
committed by Xiang Xiao
parent ec41f30f9a
commit d483364481
4 changed files with 68 additions and 3 deletions
+12
View File
@@ -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
+12
View File
@@ -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()
+8
View File
@@ -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
+36 -3
View File
@@ -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 */