Commit graph zephyr/kernel/Kconfig
Author SHA1 Message Date
Jordan Yates
4358001f10 random: use HAS_RANDOM_GENERATOR
Transition RNG dependencies to the new `HAS_RANDOM_GENERATOR` symbol.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2026-10-28 22:40:20 -04:00
Fin Maaß
864ea0ea3f kernel: default SYS_CLOCK_HW_CYCLES_PER_SEC from timebase-frequency
Default SYS_CLOCK_HW_CYCLES_PER_SEC to the timebase-frequency property
of the first CPU node when it is set, like DCACHE_LINE_SIZE does with
d-cache-line-size. The property describes exactly this value: the
frequency at which the CPU timebase (on RISC-V the mtime counter)
advances. edtlib falls back to /cpus for CPU properties, so this
covers the property placed on either /cpus or /cpus/cpu@0.

SoC and board Kconfig.defconfig defaults still take precedence.

Assisted-by: Claude:claude-opus-5.5
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2026-09-28 09:39:03 -04:00
Måns Ansgariusson
0bde5ccbeb lib: ring_buffer: drop select/depends on RING_BUFFER
The slim ring buffer API is now header-only and always available and the
tree has already migrated from the _claim/_finish API, so the RING_BUFFER
symbol no longer gates any code.
Remove the now-redundant "select RING_BUFFER" and CONFIG_RING_BUFFER=y
entries across drivers, subsystems, samples and tests.

Signed-off-by: Måns Ansgariusson <mansgariusson@gmail.com>
2026-09-16 07:29:22 +02:00
Brian Cain
5761d7d707 hexagon: add architecture port
Add Hexagon DSP architecture support to Zephyr RTOS, targeting the
Qualcomm Hexagon V67+ ISA running as a guest under the H2 hypervisor.

This includes:
- Architecture scaffolding (Kconfig, CMakeLists, arch selection)
- Public headers (arch.h, thread.h, exception.h, error.h)
- Core runtime: context switch, interrupt/exception handling, idle, TLS
- Memory management stubs for flat-memory H2 guest model
- SoC support for QEMU hexagon virt machine
- CMake/LLVM toolchain integration for hexagon cross-compilation

Hexagon uses H2's GEVB (Guest Event Vector Base) for interrupt dispatch
rather than a traditional function-pointer vector table, so
GEN_IRQ_VECTOR_TABLE is disabled by default.

Signed-off-by: Brian Cain <brian.cain@oss.qualcomm.com>
2026-09-12 07:52:39 -04:00
Dhruv Menon
5a0e1f9eb7 kernel: add Pugh skip list timeout backend
This commit introduces a new timeout backend using a
Pugh skip list, which allows for O(log N) insertion
and removal of timeouts. The skip list maintains
a same-tick firing order and has no capacity
limit, making it suitable for systems with many
concurrent timeouts. The implementation includes
necessary Kconfig options and updates to the timeout
management code to support this new backend.

Signed-off-by: Dhruv Menon <dhruvmenon1104@gmail.com>
2026-08-30 16:43:01 -04:00
Aaron Wisner
4d042d3103 kernel: add configurable striped semaphore locking
Replace the system-wide semaphore spinlock with a configurable array
of naturally aligned lock stripes. Hash each semaphore by its natural
alignment without changing the semaphore object ABI.

Default CONFIG_SEM_LOCK_STRIPES to one so SMP and uniprocessor builds
preserve existing global-lock behavior and static memory use. Use a
scalar lock unless SMP striping is explicitly enabled, so UP builds
retain zero-sized spinlocks and avoid non-portable empty-struct arrays.

Require a power-of-two stripe count so the compiler reduces stripe
selection to a bitmask. Divide by the alignment of struct k_sem before
hashing to discard redundant address bits.

Do not impose cache-line alignment or padding. Explain how spinlock
and cache-line sizes affect the stripe count needed to reduce cache
contention.

Validate upstream semaphore regressions with zero-sized uniprocessor
spinlocks and SMP configurations using one, 16, and 32 stripes.
Reject non-power-of-two stripe counts at compile time.

An internal throughput microbenchmark on a quad-core ARM Cortex-A53
SMP system observed an improvement of approximately 3.1%.

Assisted-by: Codex:GPT-5
Signed-off-by: Aaron Wisner <awiz@openai.com>
2026-08-27 22:11:20 -04:00
Mayur Salve
1b60add1ac kernel: mutex: fix priority inheritance with multiple held mutexes
The existing implementation unconditionally restores owner_orig_prio on
unlock, ignoring other held mutexes that still have high-priority waiters.
This causes incorrect priority restoration in nested mutex scenarios and
requires mutexes to be released in strict reverse acquisition order.

Additionally, priority boosts were not propagated through ownership chains
when the mutex owner was itself blocked on another mutex.

This change adds per-thread held_mutexes tracking and mutex_pended_on
pointer to enable:
- Correct priority recalculation on unlock by scanning all remaining held
  mutexes
- Chained priority inheritance through the full ownership chain
- Deadlock detection: assert on K_FOREVER circular ownership where
  every cycle member also waits forever; bounded chain walk prevents
  livelock on cycles not involving the current thread
- Per-thread orig_prio field records true pre-inheritance priority,
  fixing priority floor when mutexes are released in non-LIFO order

struct k_thread grows by three pointers plus a byte in default builds
(held_mutexes, mutex_pended_on, orig_prio).

Signed-off-by: Mayur Salve <msalve@qti.qualcomm.com>
2026-08-18 17:19:28 -04:00
Anas Nashif
f1521edd22 kernel: move USE_SWITCH out of the SMP options menu
USE_SWITCH and USE_SWITCH_SUPPORTED describe a general context-switch
primitive (_arch_switch) that is usable on uniprocessor systems, not
just SMP configurations. Having them under the "SMP Options" menu in
kernel/smp/Kconfig was misleading.

Move both symbols to kernel/Kconfig proper, just before the SMP menu is
sourced. SMP still depends on USE_SWITCH; the guarding and arch selects
are unchanged.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-07-12 20:02:52 -04:00
Nicolas Pitre
d33280510a kernel: timeout: add bucketed delta-list backend
Add a single-level bucketed delta list as a fourth selectable timeout
backend: a simpler relative of the timer wheel that keeps the wheel's
O(1) near-future insertion without its second tier, sift/defer
machinery, or tickless-idle penalty.

Timeouts expiring within the next CONFIG_TIMEOUT_BUCKET_LISTS ticks go
into a per-tick bucket list (O(1) insert and remove), tracked by an
occupancy bitmap so "ticks until next expiry" is O(1). Everything
beyond goes into one overflow list sorted by absolute expiry (O(n)
insert, O(1) remove, no delta fix-up). As curr_tick crosses the bucket
window, overflow entries that have come within range migrate into
buckets.

Like the other backends it is a single implementation header
(kernel/timeout_bucket.h) included only by timeout.c. Two properties
distinguish it from the other non-default backends, both confirmed by
running the full kernel timer/context/common suites with the backend
forced on (qemu_x86, x86_64, cortex_a53 SMP, riscv64):

  - It fits the generic next_gap/advance/pop_due announce loop -- no
    backend-owned announce. Migration is on demand against the actual
    next event, so an idle CPU with a distant timeout sleeps straight
    to it: it passes tests/kernel/context cpu_idle / timer_interrupts,
    which the wheel fails (the wheel wakes at least every 32 ticks).
  - Same-tick firing order stays FIFO (bucket and overflow inserts
    append; migration preserves order), so tests/kernel/common's
    timeout_order passes, unlike the min-heap.

The per-node representation is the delta list's node + dticks with no
extra field: a bucket entry stores its bucket index (< BUCKET_LISTS) in
dticks, an overflow entry its absolute expiry (>= BUCKET_LISTS); the
ranges never overlap, so it shares the dlist per-node helpers. Absolute
expiry needs 64-bit ticks, so the backend depends on TIMEOUT_64BIT. It
inherits the shared z_add_timeout round-up and the inflight_timeout
synchronization like the other backends. EXPERIMENTAL.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2026-07-09 18:02:12 -04:00
Nicolas Pitre
e0244d279b kernel: timeout: add timer-wheel backend
Add a hierarchical timer wheel as a third selectable timeout backend.
Timeouts are bucketed by expiry distance: one list per tick for the
next 32 ticks ("soon"), one list per 32-tick band for the next ~1024
("later"), and a sorted overflow list ("distant"). Insertion and
removal are O(1) for the common near-future case; every 32 ticks the
announce path sifts the current "later" band into "soon" and refills
it from "distant". This scales well when many short-lived timeouts are
pending.

Unlike the dlist and min-heap backends, the wheel does not fit the
generic next_gap/advance/pop_due announce primitives: its per-tick
advance is a bitmap scan that jumps over empty ticks, and its sift is
a time-driven event tied to no single timeout. Rather than contort
that (already subtle) state machine, the wheel uses the backend-owned
announce escape hatch: it defines _TIMEOUT_BACKEND_OWNS_ANNOUNCE and
implements z_timeout_q_announce(), which sys_clock_announce_locked()
calls in place of the generic loop.

Like the other backends the wheel is a single implementation header
(kernel/timeout_wheel.h) included only by timeout.c, so its state, its
operations and that announce loop reach the shared state (curr_tick,
announce_remaining, inflight_timeout) directly; nothing extra needs
exposing. The SMP re-entry guard, announcing_cpu and the reprogram
remain in timeout.c. The wheel fires handlers through the same
inflight_timeout dance, so the post-#109977 abort/in-flight
synchronization works unchanged, and it carries no per-node
ANNOUNCING/ABORTED sentinels.

struct _timeout grows a wheel-only flags field (which wheel tier a
timeout occupies), gated by CONFIG_TIMEOUT_BACKEND_WHEEL so the dlist
and heap builds are unaffected.

The backend is EXPERIMENTAL. Two known limitations, inherent to the
wheel algorithm (not the abstraction):
  - No same-tick firing-order guarantee (sifted timeouts are
    prepended), so the timeout_order test does not apply.
  - next_timeout() never exceeds 32 ticks because a sift is always
    pending, so the wheel wakes a tickless-idle CPU at least every 32
    ticks. This fails tests that assert zero spurious idle wakeups
    (tests/kernel/context cpu_idle / timer_interrupts) and is a power
    regression versus the dlist and heap backends.
Verified the timeout-functional suites (timer_api, timeout,
timepoints, sleep, sched/deadline) pass with the wheel on qemu_x86,
x86_64, cortex_a53 SMP and riscv64; dlist and heap remain unaffected.

The timer-wheel data structure, bucketing scheme and sift algorithm
are the work of Peter Mitsis (PR #108339), re-homed here behind the
timeout backend interface.

Co-authored-by: Peter Mitsis <peter.mitsis@intel.com>
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2026-07-09 18:02:12 -04:00
Nicolas Pitre
5188d5009b kernel: timeout: add min-heap backend
Add a binary min-heap as a selectable timeout backend alongside the
sorted delta list, plugging into the backend abstraction rather than
forking timeout.c. Pending timeouts are kept in a min-heap keyed on
absolute expiry tick; insertion and arbitrary removal are O(log n),
which scales better than the delta list's O(n) insertion when many
timeouts are pending.

The backend is a new kernel/timeout_minheap.h: the heap instance (a
min_heap_ref from the previous commit), its comparator and the
z_timeout_q_*() operations, included only by timeout.c (after curr_tick)
so the whole backend stays private to that translation unit. struct
_timeout gains the abs_ticks + heap_handle representation, selected by
Kconfig (the delta list's node + dticks is the #else), with the common
fn pointer kept as a shared trailing member; the per-node helpers in
timeout_q.h grow a matching min-heap variant. The kernel shell thread
dump prints the backend's raw scheduling field (dticks or abs_ticks)
under #ifdef.

Because the shared z_add_timeout() already applies the post-#107452
conditional tick round-up, the heap inherits it: the backend's insert
simply stores abs_ticks = curr_tick + dticks. Likewise in-flight
handler synchronization (PR #109977) lives in timeout.c, so the heap
node carries no ANNOUNCING/ABORTED sentinels -- "not queued" is just
heap_handle.idx == 0.

The backend is EXPERIMENTAL, depends on TIMEOUT_64BIT (absolute ticks
need 64-bit precision), and uses a fixed-capacity heap
(CONFIG_TIMEOUT_HEAP_MAX_ENTRIES) whose overflow is a fatal error.

The min-heap algorithm, struct fields, Kconfig and capacity model are
derived from Sayooj K Karun's min-heap timeout subsystem (#106013),
reworked here to fit the pluggable backend and the current in-tree
in-flight-handler synchronization.

Co-authored-by: Sayooj K Karun <sayooj@aerlync.com>
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2026-07-09 18:02:12 -04:00
Anas Nashif
dc61457251 kernel: stack canaries: disable TLS canaries for Clang on RISC-V
Clang's RISC-V backend rejects the -mstack-protector-guard=tls family of
flags used to anchor the stack canary to the TLS base register. With those
flags stripped, Clang falls back to an absolute reference to the
thread-local __stack_chk_guard symbol, which resolves to address 0. The
build compiles cleanly but the resulting image faults in the prologue of
the first canary-instrumented function (vprintk during early boot, before
the console is up), then re-faults forever in the trap handler, producing
no output at all.

Guard STACK_CANARIES_TLS so it cannot be selected for Clang on RISC-V,
falling back to the global canary which Clang handles correctly, and
exclude the kernel.memory_protection.stackprot_tls test from zephyr/llvm.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-06-23 17:40:13 -04:00
Christoph Busold
9828037e91 arch: riscv: Detach DEP config from EXECUTE_XOR_WRITE
Move EXECUTE_XOR_WRITE back into userspace and update the comment
to reflect that it only applies to memory partitions.

PMP_DATA_EXECUTION_PREVENTION is now independent from it and no
longer a requirement.

For full protection both options should be enabled. Otherwise,
some data areas my be left executable and writable at the same
time.

Signed-off-by: Christoph Busold <cbusold@qti.qualcomm.com>
2026-06-19 22:37:17 +02:00
Christoph Busold
70df4ac429 arch: riscv: Add CONFIG_EXECUTE_XOR_WRITE support using PMP
CONFIG_EXECUTE_XOR_WRITE is a basic countermeasure to prevent code
injection attacks by making data non-executable. This can be done
on RISC-V with PMP by removing the executable permission.

Since PMP slots are statically prioritized, we can add a region
covering the whole address space into the last register giving
only read-write access. This will be overridden by any other
configured register with lower index so that the code region
remains executable.

In order to make this register apply to kernel threads in M mode,
it needs to be locked, but this means we cannot remove it anymore.
For CONFIG_USERSPACE we therefore need to reserve another register
so that we can add another address space-wide region with higher
priority without any permission to override the last one and limit
user threads to their assigned regions. This needs to be removed
when switching from user to kernel threads, which is done in the
new function z_riscv_pmp_usermode_disable.

This feature simplifies CONFIG_PMP_KERNEL_MODE_DYNAMIC because we
already have a catch-all register for kernel threads.

Does not work with CONFIG_CODE_DATA_RELOCATION for now and requires
PMP region locking.

Signed-off-by: Christoph Busold <cbusold@qti.qualcomm.com>
2026-06-19 22:37:17 +02:00
Anas Nashif
50f4e51efb kernel: smp: update SCHED_CPU_MASK for multi-scheduler support
Now SCHED_CPU_MASK is no longer restricted to SCHED_SIMPLE. Dropped
dependency on SCHED_SIMPLE and made SCHED_CPU_MASK work on all scheduler
types by implementing z_priq_rb_mask_best and z_priq_mq_mask_best for
both scalable and multiq schedulers.

Update the help text and remove the stale claim that the feature only
works with the simple scheduler and document the mask-aware best-thread
search algorithm and its performance characteristics for each of the
three supported backends:

  SCHED_SIMPLE:   O(N) sorted-list scan; terminates at the first
                  priority-eligible thread, so cost is proportional to
                  the number of higher-priority threads pinned away from
                  the current CPU.

  SCHED_SCALABLE: O(N) in-order rbtree walk; benefits from priority
                  ordering so the walk usually terminates early.

  SCHED_MULTIQ:   O(P) bitmap iteration over non-empty priority levels
                  plus an inner O(N) per-level list scan; fast when
                  affinity-constrained threads are sparse, degrades when
                  many same-priority threads are pinned away.

Assisted-by: GitHub Copilot:claude-sonnet-4.6
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-06-09 19:57:09 +02:00
Fabio Baltieri
63732a6fb5 device: make DEVICE_API_GET assert optionals
Asserts on DEVICE_API_GET can take a significant amount of flash, to the
point of making an imagine not fit the flash anymore, add an option to
disable them.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2026-06-04 14:05:26 +02:00
Daniel Leung
c91e5e1390 kernel: move atomic_c.c to lib/os
This moves the atomic_c.c from kernel to lib/os as atomic
functions are not exactly kernel features.

This also moves all the atomic kconfigs from kernel to lib/os
as the atomic headers are already under include/zephyr/sys/.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-05-01 11:17:27 -05:00
Daniel Leung
cc61366283 kernel: move errno from kernel to lib/libc/common
errno is not exactly a kernel functionality but more of C
library feature. So move errno from kernel into lib/libc/common.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-05-01 11:16:31 -05:00
Daniel Leung
db7a5e80a4 kernel: move bootargs out of kernel into lib/os.
This moves boot arguments from kernel into the lib/os.
This is not strictly a kernel function so this change provides
a separation between core kernel functionalities and others.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-04-29 06:23:14 -05:00
Daniel Leung
9fe4cc20a2 kernel: move boot banner into lib/os
Boot banner is not exactly a kernel feature. It is more like
an OS feature so moving it into lib/os.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-04-29 06:23:14 -05:00
Anas Nashif
85ca9bb992 kernel: move smp code into smp/
Isolate SMP code into own folder.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-04-14 22:31:16 -04:00
Anas Nashif
974dbbf2c0 kernel: move userspace kconfigs into own file
Move userspace Kconfig under userspace/.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-04-14 22:31:16 -04:00
Anas Nashif
d8a1960c8b kernel: reorg mem domain kconfig
Reorganize memory domain Kconfig and move it under userspace/.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-04-14 22:31:16 -04:00
Joel Holdsworth
76def70bed arch: Added initial OpenRISC architecture port
This patch adds support for the OpenRISC 1000 (or1k) architecture: a
MIPS-like open hardware ISA which was first introduced in 2000.

The thread switching implementation uses the modern Zephyr thread "switch"
architecture.

Signed-off-by: Joel Holdsworth <jholdsworth@nvidia.com>
2026-03-21 07:50:57 -05:00
Anas Nashif
b84319c460 kernel: drop deprecated options SCHED_DUMB and WAITQ_DUMB
Those kconfig options were deprecated in 4.2. Now they are removed.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-03-09 15:09:04 -05:00
Peter Mitsis
ec2e20530c kernel: Disable k_mutex priority inheritance
There is no need to include the k_mutex priority inheritance code
when CONFIG_PRIORITY_CEILING is set to a priority level that is at
or below that of the idle thread.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2026-02-16 00:13:23 +00:00
Peter Mitsis
73cf293de6 kernel: Add NONZERO_SPINLOCK_SIZE Kconfig option
Embeds both an anonymous union and an anonymous structure within the
k_spinlock structure to ensure that the structure can easily have a
non-zero size.

This new option provides a cleaner way to specify that the
spinlock structure must have a non-zero size. A non-zero size
is necessary when C++ support is enabled, or when a library
or application wants to create an array of spinlocks.

Fixes #59922

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2026-02-09 11:16:03 +01:00
Tim Lin
2edece9d58 kernel: Add Kconfig option to disable LTO for kernel sources
Some SoCs require kernel code to be placed in RAM, which makes
link-time optimization (LTO) unsuitable for these files.
Disabling LTO allows the affected code to be linked as separate
objects and placed in specific memory regions.

Running kernel code from RAM can improve execution performance,
especially for timing-critical routines or context switch paths.

Signed-off-by: Tim Lin <tim2.lin@ite.corp-partner.google.com>
2026-01-21 17:04:50 +01:00
Vijay Sharma
83f1b8ba49 kernel: timer: Add timer observer hooks for extensibility
Introduce lifecycle observer callbacks (init, start, stop, expiry)
for k_timer using Zephyr's iterable sections pattern. This enables
external modules to extend timer functionality without modifying
kernel internals.

Signed-off-by: Vijay Sharma <vijshar@qti.qualcomm.com>
2026-01-09 14:25:31 -06:00
Peter Mitsis
c08905ecc9 kernel: Add thread runtime stack safety
Adds support for thread runtime stack safety. This kernel feature
allows a developer to run enhanced stack usage checks on threads
such that if the amount of unused stack space drops below a thread's
configured threshold, it will invoke a custom handler/callback.

This can be used by monitoring software to log warnings, suspend
or abort threads, or even reboot the system.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2025-11-25 19:25:44 +00:00
Carles Cufi
cd8e773b32 kernel: events: Depend on multithreading
Kernel events depend on multithreading being enabled, and mixing them
with a non-multithreaded build gives linker failures internal to
events.c. To avoid this, make events depend on multithreading.

```
libkernel.a(events.c.obj): in function `k_event_post_internal':
175: undefined reference to `z_sched_waitq_walk'
events.c:183: undefined reference to `z_sched_wake_thread'
events.c:191: undefined reference to `z_reschedule'
libkernel.a(events.c.obj): in function `k_sched_current_thread_query':
kernel.h:216: undefined reference to `z_impl_k_sched_current_thread_query'
libkernel.a(events.c.obj): in function `k_event_wait_internal':
events.c:312: undefined reference to `z_pend_curr'
```

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2025-10-30 15:13:38 +02:00
Anas Nashif
6240b0ddb9 kernel: set DYNAMIC_THREAD_STACK_SIZE to 4096 for coverage
Increase stack sizes to allow coverage to complete.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-10-14 17:32:46 -04:00
Anas Nashif
7aa3269a3f kernel: boot args kconfig cleanup
Cleanup kconfig of bootargs and put everything in one menuconfig.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-09-08 15:51:07 -04:00
Anas Nashif
cf6db903e1 kernel: move xip into arch/common
Not really a kernel feature, more for architecture, which is reflected
in how XIP is enabled and tested. Move it to architecture code to keep
which much of the 'implementation' and usage is.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-09-08 15:51:07 -04:00
Anas Nashif
0c84cc5bc6 kernel: drop deprecated pipe API
This API was deprecated in 4.1, so drop it for the 4.3 release. Use new
PIPE API instead.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-09-05 17:13:05 +02:00
Ederson de Souza
cdaca274a5 kernel: Automatically set up HW shadow stack for thread stacks
This patch modifies thread stack macros (such as K_KERNEL_STACK_DECLARE
or K_KERNEL_STACK_ARRAY_DECLARE) to also create a HW shadow stack (when
CONFIG_HW_SHADOW_STACK=y), as well as define a pairing between the
thread stack (or thread stack array) and the shadow stack (or shadow
stack array).

This pairing, which currently is simply an array of pairs (stack,
shadow_stack) is searched during thread setup to find the corresponding
shadow stack and attach it to the thread. If linear search on this array
proves to be a performance issue, the actual structure can be revisited.

To define the size of the shadow stack for a given stack, the stack size
is used. A new Kconfig, CONFIG_HW_SHADOW_STACK_PERCENTAGE_SIZE is used
to define how big the shadow stack is compared to the stack. Note that
this size is in *addition* to the stack size. To avoid some shadow
stacks becoming too small, CONFIG_HW_SHADOW_STACK_MIN_SIZE is used to
define a minimum size. Note that after this size is defined, platform
restrictions on the size of the shadow stack are still applied.

Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
2025-09-02 07:56:48 +02:00
Ederson de Souza
10d6ef0ea5 kernel: Option to allow shadow stack to be reused
It seems that, at least on tests, it's common to call k_thread_create()
on a thread multiple times. This trips a check for the CET shadow stack
- namely, set a shadow stack on a thread which already has a shadow
stack.

This patch adds a Kconfig option to allow that, iff the base address and
size of the new shadow stack are the same as before. This will trigger a
reset of the shadow stack, so it can be reused.

It may be the case that this behaviour (reusing threads) is more common
than only for tests, in which case it could make sense to change the
default - in this patch, is only true if ZTEST.

Even if being enabled by default becomes the reality, it would still
make sense to keep this option - more conscious apps could avoid the
need for the shadow stack reset code altogether.

Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
2025-09-02 07:56:48 +02:00
Ederson de Souza
016eaf2959 kernel: Add interface for hardware shadow stack usage
In order to allow kernel created threads (such as main and idle threads)
to make use of hardware shadow stack implementation, add an interface
for them.

This patch basically provides an infra that architectures need to
implement to provide hardware shadow stack.

Also, main and idle threads are updated to make use of this interface
(if hardware shadow stacks are enabled).

Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
2025-09-02 07:56:48 +02:00
Jamie McCrae
db8f991c77 kconfig: Use $(...) instead of ${...} for getting variables
Updates this to comply with the Zephyr Kconfig recommendations

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2025-08-20 12:05:41 +02:00
Chaitanya Tata
4bd1d39c67 wifi: nrf70: Fix system work queue stack size override
Defaults cannot be overidden (even with configdefault extension), they
only work if the original symbol is defined after the override e.g.,
"drivers and then subsys/net" but for kernel symbols,the default value
overrides don't work due "kernel and drivers" order, the kernel defines
the original symbol with the default and then it cannot be overridden.

Move the kernel symbol override to the original definition to make it
affect. Else any sample that uses nRF70 but doesn't enable WPA
supplicant ends up with 1024 and crashes.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2025-07-01 19:04:00 -05:00
Pisit Sawangvonganan
a163f9db61 kconfig: fix typo in (arch, boards, kernel, modules, samples, share)
Utilize a code spell-checking tool to scan for and correct spelling errors
in `Kconfig` files within the `arch`, `boards`, `kernel`, `modules`,
`samples`, and `share` directory.
Additionally, incorporates a fix recommended by the reviewer.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2025-07-01 10:58:54 -10:00
Carles Cufi
61cdcb3383 kernel: Guard SYS_CLOCK_HW_CYCLES_PER_SEC to avoid spurious empty macro
If SYS_CLOCK_EXISTS is not enabled, then the SYS_CLOCK_HW_CYCLES_PER_SEC
still gets created, but with no value. This causes the code generation
in misc/generated/CMakeLists.txt to create an empty assembly macro:

`.equ  CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC,`

which then causes a build error.

Disable SYS_CLOCK_HW_CYCLES_PER_SEC entirely when SYS_CLOCK_EXISTS is
disabled to fix this.

This is a follow-up to 03f46db859.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2025-06-06 15:01:34 +01:00
Bjarki Arge Andreasen
8f9eae25c9 kernel: workq: introduce work timeout:
Introduce work timeout, which is an optional workqueue configuration
which enables monitoring for work items which take longer than
expected. This could be due to long running or deadlocked handlers.

Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
2025-06-06 08:42:53 +02:00
Daniel Mangum
e337b7b65d kernel: sched: default TIMESLICE_SIZE to 20
Sets the default for CONFIG_TIMESLICE_SIZE to 20 to approximate the
historical clamping behavior that was removed in 405611d.

Signed-off-by: Daniel Mangum <georgedanielmangum@gmail.com>
2025-05-16 22:55:49 +02:00
Anas Nashif
5fe84d5b69 arch: nios2: remove arch
Remove architecture and dependencies.
Remove altera HAL supporting nios2

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-05-15 20:01:05 -04:00
Keith Packard
9398174340 kernel: Unify .ctors and .init_array handling
Handle both of these sections in a single chunk of code instead of
separately. We don't need to use the legacy .ctors ABI as both
the constructors array and startup logic are managed within a single
link result.

This can now also be used with ARC MWDT which had been using the .ctors
sections but with .init_array semantics. For ARC MWDT, we now always
discard .dtors and .fini sections as Zephyr will never cause global
destructors to execute. Stop discarding .eh_frame sections so that
exception handling works as expected.

When building a NATIVE_APPLICATION, we ask the native C library to run all
of the constructors to ensure any non-Zephyr constructors are run before
main is invoked. It might be "nice" to split the constructors so that the
Zephyr constructors were executed by the Zephyr code while the non-Zephyr
ones were executed by the native C library. I think that could be done if
we knew the pathnames of either the Zephyr or non-Zephyr files. That might
make a good future enhancement.

Signed-off-by: Keith Packard <keithp@keithp.com>
2025-04-16 20:36:27 +02:00
Peter Mitsis
4bc5498399 kconfig: Remove stale references to _Swap()
_Swap() is obsolete and has since been replaced with z_swap().

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2025-04-16 01:10:15 +02:00
Anas Nashif
f29ae72d79 kernel: rename 'dumb' scheduler and simply call it 'simple'
Improve naming of the scheduler and call it what it is: simple. Using
'dumb' for the default scheduler algorithm in Zephyr is a bad idea.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-03-15 00:34:58 +01:00
William Tambe
15fa9a8ed8 arch: x86: remove arch specific dependencies from DYNAMIC_BOOTARGS
CONFIG_DYNAMIC_BOOTARGS currently depends on CONFIG_MULTIBOOT_INFO
and CONFIG_BUILD_OUTPUT_EFI which are x86 specific.

This change removes those dependencies so that another architecture
can use CONFIG_DYNAMIC_BOOTARGS without the x86 specifc features.

Signed-off-by: William Tambe <williamt@cadence.com>
2025-03-13 07:22:53 +01:00
Henrik Brix Andersen
110cd6b806 kernel: fix compilation with CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME
Fix compilation with CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME=y and
CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC unset at the board/SoC level.

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
2025-03-11 18:53:40 +01:00