Skip to content
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
12 changes: 12 additions & 0 deletions sched/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1855,6 +1855,12 @@ config SCHED_HPWORKSTACKSIZE
---help---
The stack size allocated for the worker thread. Default: 2K.

config SCHED_HPWORKSTACKSECTION

@linguini1 linguini1 Feb 4, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is causing a failing build for RPi4B.

Usage of this definition is guarded by

#ifdef SCHED_HPWORKSTACKSECTION
...

In kwork_thread.c l561, but ifdef does not evaluate to false with the default value "" (empty string). There needs to be a boolean condition guarding this.

Create version.h
LN: platform/board to /home/linguini/coding/nuttx-space/apps/platform/dummy
Register: getprime
Register: dd
Register: ostest
Register: nsh
Register: sh
Register: sdstress
In file included from /home/linguini/coding/nuttx-space/nuttx/include/sys/types.h:31,
                 from /home/linguini/coding/nuttx-space/nuttx/include/unistd.h:30,
                 from wqueue/kwork_thread.c:29:
wqueue/kwork_thread.c: In function 'work_start_highpri':
wqueue/kwork_thread.c:564:15: error: 'CONFIG_SCHED_HPWORKSTACKSECTION' undeclared (first use in this function); did you mean 'CONFIG_SCHED_HPWORKSTACKSIZE'?
  564 |   locate_data(CONFIG_SCHED_HPWORKSTACKSECTION);
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
wqueue/kwork_thread.c:564:15: note: each undeclared identifier is reported only once for each function it appears in
wqueue/kwork_thread.c:564:3: error: section attribute argument not a string constant
  564 |   locate_data(CONFIG_SCHED_HPWORKSTACKSECTION);
      |   ^~~~~~~~~~~
make[1]: *** [Makefile:65: kwork_thread.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [tools/LibTargets.mk:71: sched/libsched.a] Error 2
make: *** Waiting for unfinished jobs....

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is causing a failing build for RPi4B.

Usage of this definition is guarded by

#ifdef SCHED_HPWORKSTACKSECTION
...

In kwork_thread.c l561, but ifdef does not evaluate to false with the default value "" (empty string). There needs to be a boolean condition guarding this.

Create version.h
LN: platform/board to /home/linguini/coding/nuttx-space/apps/platform/dummy
Register: getprime
Register: dd
Register: ostest
Register: nsh
Register: sh
Register: sdstress
In file included from /home/linguini/coding/nuttx-space/nuttx/include/sys/types.h:31,
                 from /home/linguini/coding/nuttx-space/nuttx/include/unistd.h:30,
                 from wqueue/kwork_thread.c:29:
wqueue/kwork_thread.c: In function 'work_start_highpri':
wqueue/kwork_thread.c:564:15: error: 'CONFIG_SCHED_HPWORKSTACKSECTION' undeclared (first use in this function); did you mean 'CONFIG_SCHED_HPWORKSTACKSIZE'?
  564 |   locate_data(CONFIG_SCHED_HPWORKSTACKSECTION);
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
wqueue/kwork_thread.c:564:15: note: each undeclared identifier is reported only once for each function it appears in
wqueue/kwork_thread.c:564:3: error: section attribute argument not a string constant
  564 |   locate_data(CONFIG_SCHED_HPWORKSTACKSECTION);
      |   ^~~~~~~~~~~
make[1]: *** [Makefile:65: kwork_thread.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [tools/LibTargets.mk:71: sched/libsched.a] Error 2
make: *** Waiting for unfinished jobs....

Hi:
I think I've identified the root cause of the issue. It's a bug in the makefile:
You might have SCHED_HPWORK disabled. Could you please try enabling SCHED_HPWORK and test again? Alternatively, could you let me know which configuration you used for compilation? I'll try to reproduce it locally.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick response! I was testing the patch in #18333 using the raspberrypi-4b:sd configuration. I faced this error after rebasing the patch onto main, but I tested again on mainline afterwards and did not have this issue. It may not be relevant and instead due to some build artifacts being out of sync.

Don't worry about this issue. If I encounter it on mainline again I'll let you know but I think it was just due to some out of sync build stuff. Thank you again!

string "The section where hpwork stack is located"
default ""
---help---
The section where hpwork stack is located.

endif # SCHED_HPWORK

config SCHED_LPWORK
Expand Down Expand Up @@ -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

Expand Down
12 changes: 12 additions & 0 deletions sched/wqueue/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 8 additions & 0 deletions sched/wqueue/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 36 additions & 3 deletions sched/wqueue/kwork_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down Expand Up @@ -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 */

Expand All @@ -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);
Comment on lines +602 to +604

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static uint8_t lp_work_stack[CONFIG_SCHED_LPNTHREADS]
[CONFIG_SCHED_LPWORKSTACKSIZE]
locate_data(CONFIG_SCHED_LPWORKSTACKSECTION);
static uint32_t lp_work_stack[CONFIG_SCHED_LPNTHREADS
* STACK_ALIGN_UP(CONFIG_SCHED_LPWORKSTACKSIZE) / sizeof(uint32_t)]
locate_data(CONFIG_SCHED_LPWORKSTACKSECTION);

emm... stack align should set the data type to uint32_t or other arch requirement ...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emm... stack align should set the data type to uint32_t or other arch requirement ...

Thanks for the correction. I think it can be revised as follows:
static aligned_data(STACK_ALIGNMENT) uint8_t
lp_work_stack[CONFIG_SCHED_LPNTHREADS][CONFIG_SCHED_LPWORKSTACKSIZE]
locate_data(CONFIG_SCHED_LPWORKSTACKSECTION);
I'll submit another PR to fix it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aligned_data just aligned the first stack, we should consider CONFIG_SCHED_LPWORKSTACKSIZE also must align with arch requirement

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aligned_data just aligned the first stack, we should consider CONFIG_SCHED_LPWORKSTACKSIZE also must align with arch requirement

Alright, the modifications below should be appropriate. Please check them. Thank you.

#define LP_WORK_STACK_SIZE STACK_ALIGN_UP(CONFIG_SCHED_LPWORKSTACKSIZE)

static aligned_data(STACK_ALIGNMENT) uint8_t
lp_work_stack[CONFIG_SCHED_LPNTHREADS][LP_WORK_STACK_SIZE]
locate_data(CONFIG_SCHED_LPWORKSTACKSECTION);

return work_thread_create(LPWORKNAME,
CONFIG_SCHED_LPWORKPRIORITY,
lp_work_stack,
LP_WORK_STACK_SIZE,
(FAR struct kwork_wqueue_s *)&g_lpwork);


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 */

Expand Down
Loading