Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isrthread: add configuring the stack of an isrthread as static #50

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/nuttx/wqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ int work_usrstart(void);
* Input Parameters:
* name - Name of the new task
* priority - Priority of the new task
* stack_addr - Stack buffer of the new task
* stack_size - size (in bytes) of the stack needed
* nthreads - Number of work thread should be created
*
Expand All @@ -359,6 +360,7 @@ int work_usrstart(void);

FAR struct kwork_wqueue_s *work_queue_create(FAR const char *name,
int priority,
FAR void *stack_addr,
int stack_size, int nthreads);

/****************************************************************************
Expand Down
5 changes: 5 additions & 0 deletions sched/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,11 @@ config IRQ_NWORKS
---help---
The max num of active irq wqueue.

config IRQ_WORK_SECTION
string "The section where irq stack is located"
---help---
The section where irq stack is located.

config IRQ_WORK_STACKSIZE
int "The default stack size for isr wqueue"
default DEFAULT_TASK_STACKSIZE
Expand Down
5 changes: 5 additions & 0 deletions sched/irq/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@ if(CONFIG_IRQCHAIN)
list(APPEND SRCS irq_chain.c)
endif()

if(CONFIG_IRQ_WORK_SECTION)
target_compile_definitions(
sched PRIVATE -DIRQ_WORK_SECTION="${CONFIG_IRQ_WORK_SECTION}")
endif()

target_sources(sched PRIVATE ${SRCS})
4 changes: 4 additions & 0 deletions sched/irq/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ ifeq ($(CONFIG_IRQCHAIN),y)
CSRCS += irq_chain.c
endif

ifneq ($(CONFIG_IRQ_WORK_SECTION),"")
CFLAGS += ${DEFINE_PREFIX}IRQ_WORK_SECTION=CONFIG_IRQ_WORK_SECTION
endif

# Include irq build support

DEPPATH += --dep-path irq
Expand Down
10 changes: 9 additions & 1 deletion sched/irq/irq_attach_wqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ static struct irq_work_info_s g_irq_work_vector[NR_IRQS];
static mutex_t g_irq_wqueue_lock = NXMUTEX_INITIALIZER;
static FAR struct kwork_wqueue_s *g_irq_wqueue[CONFIG_IRQ_NWORKS];

#ifdef IRQ_WORK_SECTION
static uint8_t g_irq_work_stack[CONFIG_IRQ_NWORKS][CONFIG_IRQ_WORK_STACKSIZE]
locate_data(IRQ_WORK_SECTION);
#else
static uint8_t g_irq_work_stack[CONFIG_IRQ_NWORKS]
[CONFIG_IRQ_WORK_STACKSIZE];
#endif

/****************************************************************************
* Private Functions
****************************************************************************/
Expand Down Expand Up @@ -98,7 +106,7 @@ inline_function FAR struct kwork_wqueue_s *irq_get_wqueue(int priority)

DEBUGASSERT(i < CONFIG_IRQ_NWORKS);

queue = work_queue_create("isrwork", priority,
queue = work_queue_create("isrwork", priority, g_irq_work_stack[i],
CONFIG_IRQ_WORK_STACKSIZE, 1);

g_irq_wqueue[i] = queue;
Expand Down
17 changes: 10 additions & 7 deletions sched/wqueue/kwork_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ static int work_thread(int argc, FAR char *argv[])
* Input Parameters:
* name - Name of the new task
* priority - Priority of the new task
* stack_addr - Stack buffer of the new task
* stack_size - size (in bytes) of the stack needed
* wqueue - Work queue instance
*
Expand All @@ -239,7 +240,7 @@ static int work_thread(int argc, FAR char *argv[])
****************************************************************************/

static int work_thread_create(FAR const char *name, int priority,
int stack_size,
FAR void *stack_addr, int stack_size,
FAR struct kwork_wqueue_s *wqueue)
{
FAR char *argv[3];
Expand All @@ -264,8 +265,8 @@ static int work_thread_create(FAR const char *name, int priority,
argv[1] = arg1;
argv[2] = NULL;

pid = kthread_create(name, priority, stack_size,
work_thread, argv);
pid = kthread_create_with_stack(name, priority, stack_addr, stack_size,
work_thread, argv);

DEBUGASSERT(pid > 0);
if (pid < 0)
Expand Down Expand Up @@ -299,8 +300,9 @@ static int work_thread_create(FAR const char *name, int priority,
* Input Parameters:
* name - Name of the new task
* priority - Priority of the new task
* stack_addr - Stack buffer of the new task
* stack_size - size (in bytes) of the stack needed
* nthreads - Number of work thread should be created
* nthreads - Number of work thread should be created
*
* Returned Value:
* The work queue handle returned on success. Otherwise, NULL
Expand All @@ -309,6 +311,7 @@ static int work_thread_create(FAR const char *name, int priority,

FAR struct kwork_wqueue_s *work_queue_create(FAR const char *name,
int priority,
FAR void *stack_addr,
int stack_size, int nthreads)
{
FAR struct kwork_wqueue_s *wqueue;
Expand Down Expand Up @@ -337,7 +340,7 @@ FAR struct kwork_wqueue_s *work_queue_create(FAR const char *name,

/* Create the work queue thread pool */

ret = work_thread_create(name, priority, stack_size, wqueue);
ret = work_thread_create(name, priority, stack_addr, stack_size, wqueue);
if (ret < 0)
{
kmm_free(wqueue);
Expand Down Expand Up @@ -457,7 +460,7 @@ int work_start_highpri(void)

sinfo("Starting high-priority kernel worker thread(s)\n");

return work_thread_create(HPWORKNAME, CONFIG_SCHED_HPWORKPRIORITY,
return work_thread_create(HPWORKNAME, CONFIG_SCHED_HPWORKPRIORITY, NULL,
CONFIG_SCHED_HPWORKSTACKSIZE,
(FAR struct kwork_wqueue_s *)&g_hpwork);
}
Expand Down Expand Up @@ -485,7 +488,7 @@ int work_start_lowpri(void)

sinfo("Starting low-priority kernel worker thread(s)\n");

return work_thread_create(LPWORKNAME, CONFIG_SCHED_LPWORKPRIORITY,
return work_thread_create(LPWORKNAME, CONFIG_SCHED_LPWORKPRIORITY, NULL,
CONFIG_SCHED_LPWORKSTACKSIZE,
(FAR struct kwork_wqueue_s *)&g_lpwork);
}
Expand Down
Loading