Commit graph

299 commits

Author SHA1 Message Date
Daniel Apperloo 9fc26804fb linker: decouple KERNEL_WHOLE_ARCHIVE from LLEXT
Dynamic code execution applications not using LLEXT for "extension"
loading are subject to the same linker optimization symbol resolution
issue described in commit 321e395 (in summary, libkernel.a syscalls
not used directly by the application result in weak symbol resolution
of their z_mrsh_ wrapper).

To support usecases where an application is using alternative methods
to load and execute code calling syscalls (likely from userspace) or
is using a mechanism where the linker may not be aware, the configuration
option has been decoupled from CONFIG_LLEXT (who is now a selector) to
KERNEL_WHOLE_ARCHIVE.

Signed-off-by: Daniel Apperloo <daniel.apperloo@intel.com>
2024-05-13 14:23:38 +02:00
Alberto Escolar Piedras 2f5e93938b Revert "kernel: retrieve system timer clock frequency at runtime or static"
This reverts commit 7c03e5de7f.

https://github.com/zephyrproject-rtos/zephyr/pull/69705
Introduced a regression in main in which
tests/subsys/logging/log_timestamp
started failing. (See
https://github.com/zephyrproject-rtos/zephyr/issues/72344
for more info).
Let's revert the PR. It can be submitted after with the issue
fixed.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-05-06 14:52:29 +03:00
Najumon B.A 7c03e5de7f kernel: retrieve system timer clock frequency at runtime or static
update kernel timeout logic based on retrieve system timer clock
frequency at runtime or static way based on Kconfig
TIMER_READS_ITS_FREQUENCY_AT_RUNTIME

Signed-off-by: Najumon B.A <najumon.ba@intel.com>
2024-05-04 13:24:12 +03:00
Anas Nashif 297ad5186d kernel: increase main stack size for ztest on ARC
stack has been on the edge when using ztest, use 1024 for ARC as well.

Fixes #71797

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-04-24 10:49:05 +02:00
Daniel Leung d0a90a0b33 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>
2024-04-10 07:44:27 -04:00
Daniel Leung 378131c266 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>
2024-04-10 07:44:27 -04:00
TaiJu Wu 1f5f0cf838 sched: Remove multi-level queue priority limit
Modified bitmask to  bitmask array, it can make multilevel queue remove
32 bit prioriry limit.

We can scan bitmask array to find which queue have ready thread.

Only need the number of queues as priority because the priority
is checked on create_thread.

Signed-off-by: TaiJu Wu <tjwu1217@gmail.com>
2024-03-12 19:37:40 -04:00
Anas Nashif 9e83413542 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>
2024-03-06 19:27:28 -05:00
Anas Nashif 5e591c38f1 kernel: do not export z_thread_priority_set
This function is only being used by a test, so instead of reimplementing
a syscall in the test, provide a Kconfig option to provide the
functionality that only works with tests and remove some of the
duplication and extra code.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-03-06 19:27:28 -05:00
Anas Nashif a6ce422b10 kernel: remove cmsis-rtos layering violation
We shouldn't be calling hooks from optional and upper layer subsystems
in the kernel, instead, just call the hook to set thread status in the
API where it is needed.

This now clears related bit in cmsis thread status bitarray when
terminating a thread in the cmsis rtos v1 layer directly and not in the
kenrel code.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-03-06 19:27:28 -05:00
Anas Nashif 6e95bdeca6 kernel: reorg Kconfigs and split them
The kernel kconfig is becoming too big and unmanageable with too many
options scattered across the file. Move some areas out and reorg main
Kconfig slightly.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-03-06 19:27:28 -05:00
Daniel Leung 803e0e452f kernel: amend wording on CONFIG_SMP_BOOT_DELAY
This extends the wording so that not only architecture code can
start secondary CPUs at a later time. Also adds a missing 'to'.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2024-01-17 11:57:20 -05:00
Johan Hedberg 7bb16c779b posix: mqueue: Remove custom default for HEAP_MEM_POOL_SIZE
Use the new HEAP_MEM_POOL_ADD_SIZE_ prefix to construct a minimum
requirement for posix message queue usage. This way we can remove the
"special case" default values from the HEAP_MEM_POOL_SIZE Kconfig
definition.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2023-12-20 11:01:42 +01:00
Johan Hedberg 3fbf12487c kernel: Introduce a way to specify minimum system heap size
There are several subsystems and boards which require a relatively large
system heap (used by k_malloc()) to function properly. This became even
more notable with the recent introduction of the ACPICA library, which
causes ACPI-using boards to require a system heap of up to several
megabytes in size.

Until now, subsystems and boards have tried to solve this by having
Kconfig overlays which modify the default value of HEAP_MEM_POOL_SIZE.
This works ok, except when applications start explicitly setting values
in their prj.conf files:

$ git grep CONFIG_HEAP_MEM_POOL_SIZE= tests samples|wc -l
     157

The vast majority of values set by current sample or test applications
is much too small for subsystems like ACPI, which results in the
application not being able to run on such boards.

To solve this situation, we introduce support for subsystems to specify
their own custom system heap size requirement. Subsystems do
this by defining Kconfig options with the prefix HEAP_MEM_POOL_ADD_SIZE_.
The final value of the system heap is the sum of the custom
minimum requirements, or the value existing HEAP_MEM_POOL_SIZE option,
whichever is greater.

We also introduce a new HEAP_MEM_POOL_IGNORE_MIN Kconfig option which
applications can use to force a lower value than what subsystems have
specficied, however this behavior is disabled by default.

Whenever the minimum is greater than the requested value a CMake warning
will be issued in the build output.

This patch ends up modifying several places outside of kernel code,
since the presence of the system heap is no longer detected using a
non-zero CONFIG_HEAP_MEM_POOL_SIZE value, rather it's now detected using
a new K_HEAP_MEM_POOL_SIZE value that's evaluated at build.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2023-12-20 11:01:42 +01:00
Christopher Friedt afc59112a9 device: support for mutable devices
Add support for mutable devices. Mutable devices are those which
can be modified after declaration, in-place, in kernel mode.

In order for a device to be mutable, the following must be true

  * `CONFIG_DEVICE_MUTABLE` must be y-selected
  * the Devicetree bindings for the device must include
    `mutable.yaml`
  * the Devicetree node must include the `zephyr,mutable` property

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-11-28 15:35:39 +01:00
Flavio Ceolin 8679c58644 kernel: Option to not use tls to get current thread
Add a Kconfig option to tell whether or not using thread
local storage to store current thread.

The function using it can be called from ISR and using
TLS variables in this context may (should ???) not be
allowed

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2023-11-21 15:49:48 +01:00
Alexander Razinkov d2c101d466 kernel: init: conditional .bss section zeroing
Some platforms already have .bss section zeroed-out externally before the
Zephyr initialization and there is no sence to zero it out the second time
from the SW.
Such boot-time optimization could be critical e.g. for RTL Simulation.

Signed-off-by: Alexander Razinkov <alexander.razinkov@syntacore.com>
2023-11-08 10:07:26 +01:00
Alexander Razinkov 4664813a12 kernel: spinlock: Ticket spinlocks
Basic spinlock implementation is based on single
atomic variable and doesn't guarantee locking fairness
across multiple CPUs. It's even possible that single CPU
will win the contention every time which will result
in a live-lock.

Ticket spinlocks provide a FIFO order of lock aquisition
which resolves such unfairness issue at the cost of slightly
increased memory footprint.

Signed-off-by: Alexander Razinkov <alexander.razinkov@syntacore.com>
2023-11-04 07:38:39 -04:00
Jukka Rissanen 83c875adab hostap: Move the relevant config options away from hostap
Moving the Zephyr specific config options from
modules/hostap/Kconfig to corresponding Kconfig where the
option is specified.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-10-26 09:48:47 +02:00
Daniel Leung 88b05b3b91 kernel: disable THREAD_USERSPACE_LOCAL_DATA if LIBC_ERRNO
Thread userspace local data is to be used with storing errno per
thread without thread local storage support. However, if the C
library has native errno support, there is no need to enable
thread userspace local data to store errno per thread. Therefore,
amend the default for CONFIG_THREAD_USERSPACE_LOCAL_DATA so that
it is not enabled if the C library has native errno support.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-10-24 20:23:11 -04:00
Keith Packard eb024b655f libc: Control Z_LIBC_PARTITION_EXISTS from Kconfig
Instead of adding every possible subsystem which places variables in the C
library memory partition in libc-hooks.h, place those conditions in the
related Kconfig files and simplify the libc-hooks.h to just looking at
CONFIG_NEED_LIBC_MEM_PARTITION.

Signed-off-by: Keith Packard <keithp@keithp.com>
2023-10-10 23:39:40 +03:00
Flavio Ceolin fee22dae40 kconfig: Deprecate CONFIG_MP_NUM_CPUS
Mark CONFIG_MP_NUM_CPUS deprecated and point to
CONFIG_MP_MAX_NUM_CPUS.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2023-10-03 17:45:53 +01:00
Flavio Ceolin 15aa3acaf6 kconfig: Remove MP_NUM_CPUS usage
Zephyr's code base uses MP_MAX_NUM_CPUS to
know how many cores exists in the target. It is
also expected that both symbols MP_MAX_NUM_CPUS
and MP_NUM_CPUS have the same value, so lets
just use MP_MAX_NUM_CPUS and simplify it.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2023-10-03 17:45:53 +01:00
Peter Mitsis e6f1090553 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>
2023-09-30 08:04:14 +03:00
Peter Mitsis 1d5d674e0d kernel: Add initial k_obj_core_stats infrastructure
Adds the infrastructure to integrate statistics into
the object core.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2023-09-30 08:04:14 +03:00
Peter Mitsis 6df8efe354 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>
2023-09-30 08:04:14 +03:00
Peter Mitsis 55db86e512 kernel: Add initial obj_core infrastructure
Adds the initial object core infrastructure.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2023-09-30 08:04:14 +03:00
Evgeniy Paltsev 54e0731666 kernel: SMP: allow more than 5 CPU cores
Previously we limit maximum number of CPU cores to 5, now be
bumping this restriction so we can use 12 cores.

Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
Signed-off-by: Evgeniy Paltsev <PaltsevEvgeniy@gmail.com>
2023-09-25 09:49:50 +02:00
Alberto Escolar Piedras 9eeb78d86d COVERAGE: Fix COVERAGE_GCOV dependencies
CONFIG_COVERAGE has been incorrectly used to
change other kconfig options (stack sizes, etc)
code defaults, as well as some samples behaviour,
which should not have dependend on it.

Instead those should have depended on COVERAGE_GCOV,
which, being the one which adds special code and
temporary RAM storage for embedded targets,
require changes to many features.

When building for the native targets, all this was
unnecessary.

=> Fix the dependency.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2023-08-24 15:36:31 +02:00
Flavio Ceolin d16c5b9048 kernel: canaries: Allow using TLS to store it
Add new option to use thread local storage for stack
canaries. This makes harder to find the canaries location
and value. This is made optional because there is
a performance and size penalty when using it.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2023-08-08 19:08:04 -04:00
Chaitanya Tata 5c7c099891 kernel: Add support to override banner
This is useful for Zephyr customers to put their custom banners.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-08-03 18:05:00 -04:00
Nicolas Pitre 13a6c45452 kernel: crude k_busy_wait() implementation
This allows for builds with CONFIG_SYS_CLOCK_EXISTS=n in which case
busy waits are achieved with a crude CPU loop. If ever accuracy is
needed even with such a configuration then implementing arch_busy_wait()
should be considered.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2023-07-19 21:42:41 -04:00
Christopher Friedt 7b1b2576ac kernel: support dynamic thread stack allocation
Add support for dynamic thread stack allocation

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-07-13 17:16:32 -04:00
Gerard Marull-Paretas 48b201cc53 device: make device dependencies optional
Device dependencies are not always required, so make them optional via
CONFIG_DEVICE_DEPS. When enabled, the gen_device_deps script will run so
that dependencies are collected and part of the final image. Related
APIs will be also made available. Since device dependencies are used in
just a few places (power domains), disable the feature by default. When
not enabled, a second linking pass will not be required.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-06-21 09:32:05 +02:00
Gerard Marull-Paretas 1ebd76ed51 pm: add prompt to DEVICE_DEPS_DYNAMIC
The option can now be set by projects. This change will also allow to
make it dependent on a future CONFIG_DEVICE_DEPS option.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-06-21 09:32:05 +02:00
Gerard Marull-Paretas 319fbe57e1 device: s/HAS_DYNAMIC_DEVICE_HANDLES/DEVICE_DEPS_DYMAMIC
Rename the Kconfig option to be in line with recent renamings in device
handles/dependencies.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-06-21 09:32:05 +02:00
Carlo Caione 74a942e673 barriers: Introduce barrier operations
Introduce a new API for barrier operations starting with a general
skeleton and the implementation for barrier_data_memory_fence_full().

Select a built-in or an arch-based implementation according to new
Kconfig symbols CONFIG_BARRIER_OPERATIONS_BUILTIN and
CONFIG_BARRIER_OPERATIONS_ARCH.

The built-in implementation falls back on the compiler built-in
function using __ATOMIC_SEQ_CST as it is done for the atomic APIs
already.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2023-05-24 13:13:57 -04:00
Nicolas Pitre c1afa5c85e kernel/atomic_c.c: prevent usage in SMP configs
The C version of atomic_cas() uses k_smp_lock() ... which uses
atomic_cas().

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2023-05-23 08:53:39 +02:00
Jaroslaw Stelter 9c0dd7e3be intel_adsp: ace20_lnl: Change LNL core count to 5
The ACE 2.0 LNL platform has 5 HIFI4 cores. Change number
of cores to enable 5th core on the platform.

Signed-off-by: Jaroslaw Stelter <Jaroslaw.Stelter@intel.com>
2023-05-15 08:00:11 -04:00
Jaxson Han bba9fc9853 kernel: Kconfig: Increase the main stack size for ARM when TEST
The following testcases fail with qemu_cortex_r5 caused by main stack
overflow.
tests/kernel/workq/work_queue/kernel.workqueue
tests/ztest/base/testing.ztest.base.verbose_0_userspace

The main stack size is 512 for qemu_cortex_r5(a Cortex-A/R aarch32
platform) with CONFIG_ZTEST=y. The Cortex-M platforms are already set to
1024. Likely 512 will fail for most aarch32 platforms soon.

Fix the issue by increasing the CONFIG_MAIN_STACK_SIZE to 1024.
Also, remove 'default 1024 if TEST_ARM_CORTEX_M' since Cortex-M is no
longer an exception of default 1024.

Signed-off-by: Jaxson Han <jaxson.han@arm.com>
2022-12-09 21:59:10 +09:00
Jordan Yates 635f8951e1 kernel: boot: add BOOT_DELAY dependency
The BOOT_DELAY option does nothing in code if MULTITHREADING is not
enabled. Move the dependency to Kconfig instead.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2022-10-28 18:38:06 -04:00
Kumar Gala 6393a7ce5c smp: Kconfig: Move to using MP_MAX_NUM_CPUS
Continue to phase out MP_NUM_CPUS, change Kconfig to be
MP_MAX_NUM_CPUS and make MP_MAX_NUM_CPUS the main Kconfig symbol.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2022-10-20 22:04:10 +09:00
Kumar Gala 2530ba5750 arch: smp: Allow for number of cpus to be determined at runtime
Introduce a Kconfig (MP_MAX_NUM_CPUS) and an api arch_num_cpus() to
allow for systems that might determine the number of CPUs available to
Zephyr at runtime.

CONFIG_MP_MAX_NUM_CPUS is intented to be use for any array initialization
and such that need to occur at build time.  For most systems
arch_num_cpus() will just report the value of CONFIG_MP_MAX_NUM_CPUS.

The intent is to phase out CONFIG_NP_NUM_CPUS.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2022-10-13 16:02:19 +09:00
Peter Mitsis f86027ffb7 kernel: pipes: rewrite pipes implementation
This new implementation of pipes has a number of advantages over the
previous.
  1. The schedule locking is eliminated both making it safer for SMP
     and allowing for pipes to be used from ISR context.
  2. The code used to be structured to have separate code for copying
     to/from a wating thread's buffer and the pipe buffer. This had
     unnecessary duplication that has been replaced with a simpler
     scatter-gather copy model.
  3. The manner in which the "working list" is generated has also been
     simplified. It no longer tries to use the thread's queuing node.
     Instead, the k_pipe_desc structure (whose instances are on the
     part of the k_thread structure) has been extended to contain
     additional fields including a node for use with a linked list. As
     this impacts the k_thread structure, pipes are now configurable
     in the kernel via CONFIG_PIPES.

Fixes #47061

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2022-08-17 19:31:25 +02:00
Anas Nashif 13714a6742 kernel: clock: fix SYS_CLOCK_EXISTS help
SYS_CLOCK_EXISTS help was describing the 'do not exist' case and is
confusing.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-08-02 13:57:17 -04:00
Enjia Mai 89a9eab652 drivers: console: add a minimal EFI console driver to support printf
Add a minimal EFI console driver to support printf, this console driver
only supports console output. Otherwise the printf will not work.

Signed-off-by: Enjia Mai <enjia.mai@intel.com>
2022-07-05 16:52:32 -04:00
Keith Packard 275b40ef25 kernel: Allow non-zephyr toolchains to advertise TLS support
Use a new environment variable,
ZEPHYR_TOOLCHAIN_SUPPORTS_THREAD_LOCAL_STORAGE, to set the value for
TOOLCHAIN_SUPPORTS_THREAD_LOCAL_STORAGE instead of setting it to 'n' for
all non-Zephyr toolchains. In particular, the Debian arm-none-eabi
toolchain has TLS support and with this option, can be used to build
Zephyr with thread local variables.

Signed-off-by: Keith Packard <keithp@keithp.com>
2022-06-05 14:29:12 +02:00
Keith Packard 4fc00cae7a kernel: Allow Zephyr to use libc's internal errno
For a library which already provides a multi-thread aware errno, use
that instead of creating our own internal value.

Signed-off-by: Keith Packard <keithp@keithp.com>
2022-05-12 19:06:48 -04:00
Flavio Ceolin 551038e748 kernel: sched: Change cpu pin only for not executing threads
Do not allow changing the CPU which a thread is pinned when it is
already being executed. This allows further optimizations in some
platforms with incoherent memory since we can safely assume that the
thread will run in the same CPU and avoid invalidate / flush the
cache during context switches.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2022-05-04 13:46:48 -04:00
Flavio Ceolin 0b13b44a66 pm: device: Dynamically add a device to a power domain
Add API to add devices to a power domain in runtime. The number of
devices that can be added is defined in build time.

The script gen_handles.py will check the number defined in
`CONFIG_PM_DEVICE_POWER_DOMAIN_DYNAMIC` to resize the handles vector,
adding empty slots in the supported sector to be used later.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2022-04-18 17:25:01 -07:00