Commit Graph

3067 Commits

Author SHA1 Message Date
Chris Friedt 9504034733 sys: util: use BITS_PER_BYTE macro instead of the magic number 8
Obviously, everyone knows that there are 8 bits per byte, so
there isn't a lot of magic happening, per se, but it's also
helpful to clearly denote where the magic number 8 is referring
to the number of bits in a byte.

Occasionally, 8 will refer to a field size or offset in a
structure, MMR, or word. Occasionally, the number 8 will refer
to the number of bytes in a 64-bit value (which should probably
be replaced with `sizeof(uint64_t)`).

For converting bits to bytes, or vice-versa, let's use
`BITS_PER_BYTE` for clarity (or other appropriate `BITS_PER_*`
macros).

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-11-16 15:22:35 -05:00
Tom Burdick 2b5012a5d9 kernel: Move run queue initialization
Move the initialization of the priority q for running out of sched.c to
remove one more ifdef from sched.c. No change in functionality but
better matches the rest of sched.c and priority_q.h such that the
ifdefry needed is done in in priority_q.h.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2024-11-16 15:20:15 -05:00
Mikhail Kushnerov a995d9d76f kernel: fix k_sleep in no multi-threading mode
Fix k_sleep implementation for no multi-threading mode.

Absolute value of timeout expiration was fed to the k_busy_wait()
function instead of delta value. That caused bug like incrementing of
sleep time in geometric progression (while actual function argument is
constant) during program running.

Signed-off-by: Mikhail Kushnerov <m.kushnerov@yadro.com>
2024-11-16 14:07:41 -05:00
Yong Cong Sin de347a4e07 init: support per-core init hook
Allow SoC to implement their custom per-core initialization function by
selecting `CONFIG_SOC_PER_CORE_INIT_HOOK` and implement
`soc_per_core_init_hook()`.

Signed-off-by: Maxim Adelman <imax@meta.com>
Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2024-11-16 14:04:25 -05:00
Daniel DeGrasse 6023d6a142 arch: common: fix copy for ramfunc region during XIP init
ramfunc region is copied into RAM from FLASH region during XIP init. We
copy from the loadaddr of the region, and were previously loading to the
symbol __ramfunc_start. This is incorrect when using an MPU with
alignment requirements, as the __ramfunc_start symbol may have padding
placed before it in the region. The __ramfunc_start symbol still needs
to be aligned in order to be used by the MPU though, so define a new
symbol __ramfunc_region_start, and use that symbol when copying the
__ramfunc region from FLASH to RAM.

Fixes #75296

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2024-11-06 10:19:08 -08:00
Anas Nashif 6261e2a673 Revert "kernel: banner: Expose tainted builds"
This reverts commit 6d4031f96c.

Those makes majority of builds og platforms with blobs tainted although
the blob were not used or compiled in. So it is very misleading.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-10-29 14:17:21 -05:00
Peter Mitsis cedd36106b kernel: Begin abstracting out _sched_spinlock
In a uniprocessor system, _sched_spinlock may not need to be
held in all the same cases that it does in a multiprocessor
system. Removing those unnecessary usages can lead to better
performance on UP systems. In the case of uncontested taking
and giving of a semaphore, this can be as much as a +14%
performance gain.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2024-10-21 18:38:00 -05:00
Peter Mitsis f6a76c32b7 kernel: inline z_unpend_first_thread()
Inlining z_unpend_first_thread() has been observed to give a
+8% and +16% performance boost to the thread_metric benchmark's
message processing and synchronization tests respectively.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2024-10-21 18:38:00 -05:00
Peter Mitsis 0bf44f2352 kernel: Re-order should_preempt() checks
Re-orders the checks in should_preempt() tests so that the
z_is_thread_timeout_active() check is done last.

This change has been observed to give a +7% performance boost on
the thread_metric benchmark's preemptive scheduling test.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2024-10-21 18:38:00 -05:00
Reto Schneider 6d4031f96c kernel: banner: Expose tainted builds
Due to the (potentially) hard to understand effects of blobs, it seems
prudent to make their presence more noticeable.

With this change, whenever blobs are present in the Zephyr work space,
the hello world sample output looks like this:

> *** Booting Zephyr OS build (tainted) v3.7.0-4569-gd4f8765ef20e ***
> Hello World! esp32c3_devkitm/esp32c3

Before, it looked like this:

> *** Booting Zephyr OS build v3.7.0-4568-g69c47471d187 ***
> Hello World! esp32c3_devkitm/esp32c3

Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
2024-10-21 15:58:27 +02:00
Peter Mitsis c70a619a2f kernel: Remove unused z_ready_thread_locked()
Removing the routine z_ready_thread_locked() as it is not
used anywhere. It was a leftover artefact from development
that previously escaped cleanup.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2024-10-15 19:08:30 -04:00
Peter Mitsis cc415bc139 kernel: Apply 'unlikely' attribute
Applies the 'unlikely' attribute to various kernel objects that
use z_unpend_first_thread() to optimize for the non-blocking path.

This boosts the thread_metric synchronization benchmark numbers
on the frdm_k64f board by about 10%.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2024-10-15 04:06:32 -04:00
Anas Nashif 121cb49a46 kernel: sched: inline update_cache
This improves context switching by 7% when measured using the
thread_metric benchmark.

Before:
**** Thread-Metric Preemptive Scheduling Test **** Relative Time: 120
Time Period Total:  5451879

After:
**** Thread-Metric Preemptive Scheduling Test **** Relative Time: 30
Time Period Total:  5853535

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-10-10 20:21:04 -04:00
Peter Mitsis 318b49570a tests: scheduler queue benchmarks
Implements a set of tests designed to show how the performance of the
three scheduler queue implementations (DUMB, SCALABLE and MULTIQ)
varies with respect to the number of threads in the ready queue.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2024-10-07 20:16:20 -04:00
Chris Friedt b6aed5c505 kernel: dynamic: use 4k stack size for x86
x86 architectures require a dynamic stack size that is a multiple
of 4096 bytes due to mmu restrictions.

For example, this test would previously fail when using the
default dynamic stack size of 1024 bytes for 32-bit
platforms.

```
west build -p auto -b qemu_x86/atom/nopae -t run \
  tests/posix/common/ -- -DCONFIG_USERSPACE=y
```

It would pass with an additional argument
```
west build -p auto -b qemu_x86/atom/nopae -t run \
  tests/posix/common/ -- -DCONFIG_USERSPACE=y \
  -DCONFIG_DYNAMIC_THREAD_STACK_SIZE=4096
```

Add a special default for x86 when using dynamic thread stacks.

The x86 default removes the need for `boards/qemu_x86*.conf`,
with the exception of `qemu_x86_tiny`.

qemu_x86_tiny did not have sufficient memory (or configuration)
to run the non-userspace tests, so bump up the available ram
from 256k to 512k for this test and clone the .conf from the
demand paging tests.

Eventually, the common posix test should be split into more
concise functional categories.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-10-05 14:13:18 -04:00
Yong Cong Sin 52a202309b zephyr: bulk update to DT_NODE_HAS_STATUS_OKAY
Change instances of:

DT_NODE_HAS_STATUS(<node_id>, okay)

to

DT_NODE_HAS_STATUS_OKAY(<node_id>)

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2024-10-03 17:06:52 +01:00
Daniel Flodin 746c59c82a arch: kernel: lib: toolchain: Standardize TLS keyword
Up until now, the `__thread` keyword has been used for declaring
variables as Thread local storage. However, `__thread` is a GNU
specific keyword which thus limits compatibility with other
toolchains (for instance IAR).

This PR intoduces a new macro `Z_THREAD_LOCAL` which expands to the
corresponding C11, C23 or C++11 standard keyword based on the standard
that is specified during compilation, else it uses the old `__thread`
keyword.

Signed-off-by: Daniel Flodin <daniel.flodin@iar.com>
2024-09-23 10:01:48 +02:00
Daniel Leung f5163d8940 arch: add interface to dump privileged stack in coredump
This adds a interface to allow coredump to dump privileged
stack which is defined in architecture specific way.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2024-09-21 11:29:39 +02:00
Anas Nashif e9474302da init: enhance kconfig docs for custom hooks
Improve docs for custom soc/board hooks.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-09-20 13:15:31 +02:00
Pisit Sawangvonganan 5c8a2c0dbf 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>
2024-09-20 11:06:55 +02:00
Peter Mitsis eda5814dbc kernel: Simplify k_thread_cpu_pin()
Simplifies the k_thread_cpu_pin() implementation to leverage the
existing cpu_mask_mod() infrastructure.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2024-09-20 09:02:38 +02:00
Yong Cong Sin b55f3c1c4f kernel: remove `CONFIG_MP_NUM_CPUS`
`CONFIG_MP_NUM_CPUS` has been deprecated for more than 2
releases, it's time to remove it.

Updated all usage of `CONFIG_MP_NUM_CPUS` to
`CONFIG_MP_MAX_NUM_CPUS`

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2024-09-19 18:28:37 +01:00
Anas Nashif 7e225efab7 arch: initialize irq_offload during boot, do not use SYS_INIT
Do not use SYS_INIT for initializing irq_offload when enabled, instead
using a new interface that is called during the boot process for all
architectures.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-09-17 20:05:22 -04:00
Anas Nashif ca09a4b91c doc: kernel/arch: fix some wrong doxygen references
Remove non-existing references and document parameters.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-09-17 05:24:09 -04:00
Yong Cong Sin 035c822253 arch: riscv: fill all IRQ stacks with 0xAA
Fill the memory of all CPU's IRQ stack with 0xAA on init, so
that `z_stack_space_get` can calculate the remaining space
correctly.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2024-09-13 09:17:34 +02:00
Pisit Sawangvonganan 1e58b53d2a style: kernel: comply with MISRA C:2012 Rule 15.6
Add missing braces to comply with MISRA C:2012 Rule 15.6 and
also following Zephyr's style guideline.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-09-11 07:40:35 -04:00
Nicolas Pitre 1e4fd23e58 kernel: mmu: install demand mappings for the on-demand linker sections
This sets initial unpaged mappings for __ondemand_func code and
__ondemand_rodata variables. To achieve this, we have to augment the
backing store API.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2024-09-10 17:17:30 -04:00
Nicolas Pitre 6b3fff3a2f kernel: mmu: make demand paging work on SMP
This is the minimum for demand paging to work on SMP systems.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2024-09-10 11:44:16 +02:00
Anas Nashif e260d03686 init: introduce soc and board hooks
Introduce soc and board hooks to replace arch specific code
and replace usages of SYS_INIT for platform initialization.

include/zephyr/platform/hooks.h introduces the hooks to be implemented
by boards and SoCs.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-09-09 10:07:33 +02:00
Nicolas Pitre c692136f21 mmu: introduce k_mem_update_flags()
It is sometimes necessary to modify/update memory permissions on some
pages, especially with LLEXT where some allocated segments have to be
executable.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2024-09-06 11:25:54 -04:00
Jakub Michalski f568e2d3ca zefi: add bootargs support
Add bootargs support to zefi. This implements
get_bootargs() when both efi and bootargs are
selected in config.

Signed-off-by: Jakub Michalski <jmichalski@internships.antmicro.com>
Signed-off-by: Filip Kokosinski <fkokosinski@antmicro.com>
2024-09-05 12:30:39 -05:00
Jakub Michalski 0cf726b8ef arch/x86: multiboot: add bootargs support
Add bootargs support for multiboot. This
implements get_bootargs() when multiboot and
bootargs are selected in config.

Signed-off-by: Jakub Michalski <jmichalski@internships.antmicro.com>
Signed-off-by: Filip Kokosinski <fkokosinski@antmicro.com>
2024-09-05 12:30:39 -05:00
Jakub Michalski 49fc106c60 kernel: add bootargs support
Add support for passing args to main(). The
content of bootargs is taken from get_bootargs()
which should be implemented for each loader and
then its split into args and passed to main.

Signed-off-by: Jakub Michalski <jmichalski@internships.antmicro.com>
Signed-off-by: Filip Kokosinski <fkokosinski@antmicro.com>
2024-09-05 12:30:39 -05:00
Rick Tsao e9ff0dc35e kernel: userspace: Fix dynamic thread stack allocation for RISC-V
RISC-V use the same logic for dynamic thread stacks allocation as ARM.
This fixup reuses ARM code.

Signed-off-by: Rick Tsao <rick592@andestech.com>
2024-09-04 21:28:36 +02:00
Daniel Leung b4c455c754 arch: add interface to get stack space of privileged stack
This adds a new arch_thread_priv_stack_space_get() interface for
each architecture to report privileged stack space usage. Each
architecture will need to implement this function as each arch
has their own way of defining privileged stacks.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2024-08-28 06:50:30 -04:00
Nicolas Pitre c9aa98ebc0 kernel: mmu: support for on-demand mappings
This provides memory mappings with the ability to be initialized in their
paged-out state and be paged in on demand. This is especially nice for
anonymous memory mappings as they no longer have to allocate all memory
at mem_map time. This also allows for file mappings to be implemented by
simply providing backing store location tokens.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2024-08-26 17:25:41 -04:00
Rubin Gerritsen 98a16b424a 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>
2024-08-23 08:01:33 -04:00
Pisit Sawangvonganan ef639efb38 style: kernel: comply with MISRA C:2012 Rule 15.6
Add missing braces to comply with MISRA C:2012 Rule 15.6 and
also following Zephyr's style guideline.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-08-20 10:33:51 +02:00
Nicolas Pitre 2a41d85709 k_mem_map: move some assertions to unconditional checks
Dynamic memory allocation depends on various factors and many are
only known at runtime depending on application inputs.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2024-08-19 15:17:48 -04:00
Jan Peters b8bef42add device_dt_metadata: handle dt_meta being NULL
Using  DEVICE_DEFINE, a device without a corresponding DT node can be
defined (for example CRYPTO_MTLS), Z_DEVICE_INIT() does not initialize
dt_meta for such devices, leaving the field as NULL.
device_get_dt_nodelabels() and functions calling it have to handle
dev->dt_meta == NULL to prevent fatal errors.

Signed-off-by: Jan Peters <peters@kt-elektronik.de>
2024-08-12 15:54:22 +02:00
Anas Nashif f53d5d5712 arch: move custom arch call Kconfigs
Move from kernel/ to arch/ and have all those Kconfigs in one place.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-08-12 12:43:36 +02:00
Krzysztof Chruściński 28b4bab01c kernel: fatal: Fix NO_OPTIMIZATIONS build
When logging is on and optimization and multithreading is off then
build fails to link because unoptimized compiler/linker seems to not
look beyond the function and it fails trying to link k_thread_name_get.
Reworking the code to make it known to the compiler without optimization
that k_thread_name_get is not needed and not logging current thread
name in that case.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2024-08-07 19:03:40 -04:00
Peter Mitsis 8c48665868 kernel: Remove k_thread_priority_set() restriction
Removes the ISR restriction from k_thread_priority_set().
Since the first commit, the routine k_thread_priority_set() has
had a restriction preventing it from being called from within
the context of an ISR. As there does not (any longer) appear to
be a reason why the restriction exists, it is being removed.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2024-08-02 03:29:55 -04:00
Jyri Sarha 28215fc788 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>
2024-07-30 18:25:40 +01:00
Jyri Sarha b8a1a62048 kernel: thread: Add k_thread_foreach_filter_by_cpu() and unlocked version
Add functions k_thread_foreach_unlocked_filter_by_cpu() and
k_thread_foreach_filter_by_cpu() to loop through the threads on the
specified cpu only.

Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
2024-07-30 18:25:40 +01:00
Pieter De Gendt ad63ca284e kconfig: replace known integer constants with variables
Make the intent of the value clear and avoid invalid ranges with typos.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2024-07-27 20:49:15 +03:00
Pisit Sawangvonganan 2e0e9b1a18 kernel: reduce `k_spin_unlock` calls using `if-else if-else` structure
Reduce `k_spin_unlock` calls in `k_obj_core_stats_xxx` functions by
consolidating error handling into an `if-else if-else` structure and
using a single return variable `rv`.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-07-27 20:48:07 +03:00
Anas Nashif 2a39132645 device: remove const qualifier from node label copy
k_usermode_string_copy does not accept const in its arguements.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-07-27 15:09:10 +03:00
Peter Mitsis 20dee1a6e9 kernel: Tweak z_unpend_thread_no_timeout() API
Removes the ALWAYS_INLINE attribute from the definition of the
routine z_unpend_thread_no_timeout() to fix an unresolved symbol
error that was occurring with some compilers.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2024-07-27 10:47:41 +03:00
Peter Mitsis 9efb8fde61 kernel: Remove z_sched_abort() prototype
The routine z_sched_abort() no longer exists.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2024-07-27 10:47:41 +03:00