Commit Graph

291 Commits

Author SHA1 Message Date
Pisit Sawangvonganan b8ca7d44c2 style: kernel: remove unnecessary `return` statements
For code clarity, remove unnecessary `return` statements
in functions with a void return type they don't affect control flow.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2026-04-20 17:44:15 +08:00
Rubin Gerritsen 3483b279b5 kernel: Define optional arch_thread_name_set()
The intention of this API is to allow setting the posix thread
name equal to the zephyr thread name.
By defining it as an arch interface, the implementation becomes
generic.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2026-04-20 17:38:00 +08:00
Jyri Sarha 89b41ce8cb kernel: thread: Add k_thread_runtime_stats_cpu_get()
Add k_thread_runtime_stats_cpu_get() to get runtime statistics of
the specified core.

Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
2026-04-20 17:32:38 +08:00
Hess Nathan b4f8e4a2ea kernel: corrected parameter names
- applied the exact parameter names of the interface to implementation

Signed-off-by: Hess Nathan <nhess@baumer.com>
2026-04-20 17:30:10 +08:00
Daniel Leung e108798156 kernel: mm: remove k_mem_phys_un/map()
These functions were introduced alongside with the memory mapped
stack feature, and are currently only being used there only.
To avoid potential confusion with k_mem_un/map(), remove them
and use k_mem_map/unmap_phys_guard() directly instead.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-04-20 17:24:59 +08:00
Yong Cong Sin 498f0db1a8 build: namespace the generated headers with `zephyr/`
Namespaced the generated headers with `zephyr` to prevent
potential conflict with other headers.

Introduce a temporary Kconfig `LEGACY_GENERATED_INCLUDE_PATH`
that is enabled by default. This allows the developers to
continue the use of the old include paths for the time being
until it is deprecated and eventually removed. The Kconfig will
generate a build-time warning message, similar to the
`CONFIG_TIMER_RANDOM_GENERATOR`.

Updated the includes path of in-tree sources accordingly.

Most of the changes here are scripted, check the PR for more
info.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2026-04-20 17:20:37 +08:00
Hess Nathan d70ba5284d coding guidelines: comply with MISRA Rule 12.1.
added parentheses verifying lack of ambiguities

Signed-off-by: Hess Nathan <nhess@baumer.com>
2026-04-20 17:16:15 +08:00
Hess Nathan de6edd5797 coding guidelines: comply with MISRA Rule 11.8
- modified parameter types to receive a const pointer when a
  non-const pointer is not needed

- avoided redundant casts

Signed-off-by: Hess Nathan <nhess@baumer.com>
2026-04-20 17:16:09 +08:00
Hess Nathan 4196aae76b coding guidelines: comply with MISRA Rule 20.9
- avoid to use undefined macros in #if expressions

Signed-off-by: Hess Nathan <nhess@baumer.com>
2026-04-20 17:14:33 +08:00
Daniel Leung e607f50596 kernel: add the ability to memory map thread stacks
This introduces support for memory mapped thread stacks,
where each thread stack is mapped into virtual memory
address space with two guard pages to catch
under-/over-flowing the stack. This is just on the kernel
side. Additional architecture code is required to fully
support this feature.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-04-20 17:11:29 +08:00
Daniel Leung 20dff5481d kernel: add options to cleanup after aborting current thread
This adds the mechanism to do cleanup after k_thread_abort()
is called with the current thread. This is mainly used for
cleaning up things when the thread cannot be running, e.g.,
cleanup the thread stack.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-04-20 17:11:29 +08:00
Anas Nashif 49f0a635dc kernel: move nothread support to own file
Do not build threading support when CONFIG_MULTITHREADING=n is set and
move needed calls to a new file with the changes needed instead of the
ifdef party in sched.c

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-04-20 17:10:46 +08:00
Anas Nashif d6c57ea8f2 kernel: thread: move thread states to header
Move state string defines into thread header.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-04-20 17:10:05 +08:00
Anas Nashif 0dbd32d87d kernel: thread: move k_thread_priority_get
Move to thread.c alongside all other thread calls.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-04-20 17:10:05 +08:00
Anas Nashif 4df581abcb kernel: thread: rename is_preempt
Trivila rename to thread_is_preempt.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-04-20 17:10:05 +08:00
Anas Nashif 34984cb33f kernel: thread: move k_is_preempt_thread to thread.c
This belongs in thread.c

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-04-20 17:10:05 +08:00
Daniel Leung 3918a77d5f kernel: align thread stack size declaration
When thread stack is defined as an array, K_THREAD_STACK_LEN()
is used to calculate the size for each stack in the array.
However, standalone thread stack has its size calculated by
Z_THREAD_STACK_SIZE_ADJUST() instead. Depending on the arch
alignment requirement, they may not be the same... which
could cause some confusions. So align them both to use
K_THREAD_STACK_LEN().

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-04-20 17:09:28 +08:00
Daniel Leung 65b887cf4d kernel: align kernel stack size declaration
When kernel stack is defined as an array, K_KERNEL_STACK_LEN()
is used to calculate the size for each stack in the array.
However, standalone kernel stack has its size calculated by
Z_KERNEL_STACK_SIZE_ADJUST() instead. Depending on the arch
alignment requirement, they may not be the same... which
could cause some confusions. So align them both to use
K_KERNEL_STACK_LEN().

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-04-20 17:09:27 +08:00
Daniel Leung 2dca565896 kernel: rename Z_THREAD_STACK_BUFFER to K_THREAD_STACK_BUFFER
Simple rename to align the kernel naming scheme. This is being
used throughout the tree, especially in the architecture code.
As this is not a private API internal to kernel, prefix it
appropriately with K_.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-04-20 17:09:27 +08:00
Daniel Leung e713e7672c kernel: rename Z_KERNEL_STACK_BUFFER to K_KERNEL_STACK_BUFFER
Simple rename to align the kernel naming scheme. This is being
used throughout the tree, especially in the architecture code.
As this is not a private API internal to kernel, prefix it
appropriately with K_.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-04-20 17:09:27 +08:00
Simon Hein 844ccf8267 kernel: add closing comments to config endifs
Add a closing comment to the endif with the configuration
information to which the endif belongs too.
To make the code more clearer if the configs need adaptions.

Signed-off-by: Simon Hein <Shein@baumer.com>
2026-04-20 17:08:35 +08:00
Anas Nashif a504ccf3ff kernel: thread: use consistent thread parameter
Use thread wherever it makes sense, using 't' in some places can get
confused with 't' used for timeouts for example.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-04-20 17:04:57 +08:00
Anas Nashif 9b62cc2c74 kernel: move float operations out of thread.c
Move float operation out and add missing vrfy hook for enabling float.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-04-20 17:04:57 +08:00
Anas Nashif 58ba62698d kernel: split thread monitor
Move thread monitor related functions, not enabled in most cases outside
of thread.c and cleanup headers.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-04-20 17:04:57 +08:00
Anas Nashif 79d739f939 kernel: move z_init_static_threads to where it is being used
Move out of thread and put directly in init.c where it is being used.
Also remove definition from kernel.h, this is an internal function and
should not be in a public header.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-04-20 17:04:56 +08:00
Anas Nashif 3eeb070d52 kernel: move essential flag related routines out
The functions to manipulate the essential flag indeed operate on
threads, but they are misplaced in the thread implementation file. Put
them alongside other routines setting other thread flags and cleanup
headers a bit.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-04-20 17:04:56 +08:00
Anas Nashif 2a000d5ecf kernel: split irq_offload ccode into own file
Move irq_offload code out of thread.c into own file. This code is not
related to threads.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-04-20 17:04:55 +08:00
Anas Nashif f0dc8fdb60 kernel: move spinlock validation to own file
Move spin_lock validation outside of thread.c into own file. This code
really has nothing to do with the thread code.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-04-20 17:04:55 +08:00
Flavio Ceolin fb19dba2b7 kernel: thread: Allow stack in coherent memory
When allowing dynamic thread stack allocation the stack may come from
the heap in coherent memory, trying to use cached memory is over
complicated because of heap meta data and cache line sizes.
Also when userspace is enabled, stacks have to be page aligned and the
address of the stack is used to track kernel objects.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2026-04-20 17:02:18 +08:00
Andy Ross 532c6311ef kernel/thread: Detect in-kernel "reserved" stack overflow
Traditionally, k_thread_create() has required that the application
size the stack correctly.  Zephyr doesn't detect or return errors and
treats stack overflow as an application bug (though obviously some
architectures have runtime features to trap on overflows).

At this one spot though, it's possible for the kernel to adjust the
stack for K_THREAD_STACK_RESERVED in such a way that the arch layer's
own stack initialization overflows.  That failure can be seen by
static analysis, so we can't just sweep it under the rug as an
application failure.

Unfortunately there aren't any good options for handling it here (no
way to return failure, can't be a build assert as the size is a
runtime argument).  A panic will have to do.

Fixes: #67106
Fixes: #65584

Signed-off-by: Andy Ross <andyross@google.com>
2026-04-20 17:01:54 +08:00
Guennadi Liakhovetski 15e597ff7b llext: export some symbols
Export some symbols for loadable modules. Also add an
EXPORT_SYSCALL() helper macro for exporting system calls by their
official names.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
2026-04-20 16:51:58 +08:00
Peter Mitsis c077b6f672 kernel: Update k_thread_state_str()
Updates k_thread_state_str() to interpret the halting bits
correctly.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2026-04-20 16:47:12 +08:00
Peter Mitsis b4e2c77885 kernel: Add halt_queue field to k_thread
The halt queue will be used to identify threads that are waiting
for a thread on another CPU to finish suspending.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2026-04-20 16:47:11 +08:00
Anas Nashif 763910485c syscall: rename Z_OOPS -> K_OOPS
Rename internal API to not use z_/Z_.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-04-20 16:46:53 +08:00
Anas Nashif 9e51940168 syscall: rename Z_SYSCALL_VERIFY -> K_SYSCALL_VERIFY
Rename internal API to not use z_/Z_.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-04-20 16:46:52 +08:00
Anas Nashif f4074c1a66 syscall: rename Z_SYSCALL_ to K_SYSCALL_
Rename internal API to not use z_/Z_.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-04-20 16:46:52 +08:00
Anas Nashif 98c55be4b1 syscall: rename z_user_ to k_usermode_
Rename internal API to not use z_/Z_.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-04-20 16:46:52 +08:00
Anas Nashif c0c858c157 syscall: rename z_object_find -> k_object_find
Rename internal API to not use z_/Z_.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-04-20 16:46:51 +08:00
Anas Nashif 27525407fe syscall: rename z_thread_perms_inherit -> k_thread_perms_inherit
Rename internal API to not use z_/Z_.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-04-20 16:46:51 +08:00
Anas Nashif f027469ce2 syscall: z_obj_validation_check -> k_object_validation_check
Rename z_obj_validation_check  and do not use z_ for internal APIs.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-04-20 16:46:50 +08:00
Anas Nashif 0881e3d5d6 syscall: Z_SYSCALL_VERIFY_MSG -> K_SYSCALL_VERIFY_MSG
Rename macros and do not use Z_ for internal APIs.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-04-20 16:46:49 +08:00
Anas Nashif 4b6c58a9dc kernel: move syscall_handler.h to internal include directory
Move the syscall_handler.h header, used internally only to a dedicated
internal folder that should not be used outside of Zephyr.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-04-20 16:46:49 +08:00
Anas Nashif 5b09d243f3 kernel: object: rename z_object -> k_object
Do not use z_ for internal structures and rename to k_object instead.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-04-20 16:46:48 +08:00
Anas Nashif a0c11242e2 kernel: object: rename z_object_init to k_object_init
Do not use z_ for internal API and rename to k_object_init.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-04-20 16:46:48 +08:00
Flavio Ceolin ad33f71c65 kernel: Fix k_thread_name_get signature
k_thread_name_get has inconsistent signature. In the function
declaration it uses k_tid_t but in the implementation it is using
struct k_thread *. Change the implementation to use k_tid_t.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2026-04-20 16:46:07 +08:00
Flavio Ceolin eb4164dfba kernel: random: Rename early random get function
Rename z_early_boot_rand_get with z_early_rand_get to get consistent
with other early functions.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2026-04-20 16:43:36 +08:00
Keith Packard 0c8dc9ba32 kernel: Support platforms with runtime timer freq for thread init_delay
Platforms that determine their basic timer frequency at runtime instead of
build time cannot compute thread initialization timeouts during
compilation.

Switch back to storing the init_delay value in milliseconds and perform the
conversion to a k_timeout_t at runtime.

Signed-off-by: Keith Packard <keithp@keithp.com>
2026-04-20 16:43:34 +08:00
Flavio Ceolin 3d6841c21f random: Rename random header
rand32.h does not make much sense, since the random subsystem
provides more APIs than just getting a random 32 bits value.

Rename it to random.h and get consistently with other
subsystems.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2026-04-20 16:43:01 +08:00
Peter Mitsis 37466daed1 kernel: Integrate object core statistics
Integrates object core statistics framework into the following
kernel objects:
  sys_mem_blocks, k_mem_slab
  threads, _cpu, z_kernel

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2026-04-20 16:42:07 +08:00
Peter Mitsis 79db1a93ce kernel: Integrate object cores into kernel
Integrates object cores into the following kernel structures
   sys_mem_blocks, k_mem_slab
   _cpu, z_kernel
   k_thread, k_timer
   k_condvar, k_event, k_mutex, k_sem
   k_mbox, k_msgq, k_pipe, k_fifo, k_lifo, k_stack

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2026-04-20 16:42:06 +08:00