Commit graph

81 commits

Author SHA1 Message Date
TOKITA Hiroshi 8eff4b6036 include: sys: util_macro: add IS_BIT_MASK()/IS_SHIFTED_BIT_MASK()
Add IS_BIT_MASK() macro for determining whether a value is set bits
continuously from the LSB.
This macro is not dependent on bit-width and works in contrast to
BIT_MASK() and BIT64_MASK().
IS_SHIFTED_BIT_MASK() is a version of IS_BIT_MASK() that allows setting
the start bit of continuous bits.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@fujitsu.com>
2023-01-10 09:23:14 +01:00
Krzysztof Chruscinski 235ee63233 lib: os: mpsc_pbuf: Use flag for buffer full indication
Use flag instead of word in the buffer. Using this method allows
to dedicate full buffer capacity for data.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-12-29 10:33:29 +01:00
Gerard Marull-Paretas adbd0603b6 lib: linear_range: fix count for ranges with step 0
Ranges with step 0, that is, multiple indices representing the same
value, need to report the count exclusively based on indices. This makes
it possible to later retrieve all values, e.g. in a group.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-12-27 13:12:55 +01:00
Erwan Gouriou 46fb043140 include: util_macro: Advise not to use IS_ENABLED in #if directives
Using #if IS_ENABLED(CONFIG_FOO) doesn't provide any benefit versus
#if defined(CONFIG_FOO).

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2022-12-21 10:09:23 +01:00
Rob Barnes de9e2fcd72 assert: Add no-op stub for __ASSERT_POST_ACTION
Add a no-op stub for __ASSERT_POST_ACTION.
This allows code to reference __ASSERT_POST_ACTION even when Zephyr
asserts are off.

Signed-off-by: Rob Barnes <robbarnes@google.com>
2022-12-05 12:36:58 +01:00
Gerard Marull-Paretas 55da0217da sys: linear_range: fix index calculation when spanning across groups
When dealing with groups, the specified window in
linear_range_group_get_win_index can span across multiple groups. In the
current implementation, if maximum value was not in the same sub-window
as the minimum value the function would return -EINVAL. This patch fixes
the problem and updates test cases to cover such scenario.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-12-02 11:29:35 +01:00
Carlo Caione 189cd1f4a2 cache: Rework cache API
The cache operations must be quick, optimized and possibly inlined. The
current API is clunky, functions are not inlined and passing parameters
around that are basically always known at compile time.

In this patch we rework the cache functions to allow us to get rid of
useless parameters and make inlining easier.

In particular this changeset is doing three things:

1. `CONFIG_HAS_ARCH_CACHE` is now `CONFIG_ARCH_CACHE` and
   `CONFIG_HAS_EXTERNAL_CACHE` is now `CONFIG_EXTERNAL_CACHE`

2. The cache API has been reworked.

3. Comments are added.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2022-12-01 13:40:56 -05:00
Chris Friedt 43fb41fff2 include: sys: crc: add crc_by_type inline dispatch function
Rather than hard-coding calls to each individual CRC function, it
may be more convenient to specify the crc algorithm to use
parametrically.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2022-11-29 09:32:28 +01:00
Gerard Marull-Paretas 01eb102719 sys: linear_range: initial API
This patch adds a new API to map values in a linear range to a range
index. This API is useful in the context of regulators, where it is
common that devices map regulator voltages to a set of indices with a
linear relationship.

The original idea is borrowed from Linux.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-11-24 10:16:03 +01:00
Gerard Marull-Paretas 7dc047406c include: util_macro: remove deprecated UTIL_LISTIFY
Macro was deprecated 2 releases ago, it is now time to remove it.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-11-11 11:00:26 +01:00
Christoph Schnetzler c364721796 net: sockets: Prevent compiler error if warnings being treated as errors
If gcc compiler option -Werror is used the warning,

declared inside parameter list will not be visible outside of this
definition or declaration [-Werror]

is treated as error, for

sockets_internal.h:18:28: ‘struct net_context’
sockets_internal.h:19:32: ‘struct zsock_pollfd’
fdtable.h:108:17: ‘struct k_mutex’

Signed-off-by: Christoph Schnetzler <christoph.schnetzler@husqvarnagroup.com>
2022-11-09 09:15:32 +00:00
Tom Burdick dbc366918d tests: Enable qemu_xtensa logging tests
Enables logging testing for qemu_xtensa along with the fixes needed to
correctly run the tests.

Several tests in log_api rely on being able to calculate the size of
the message in the mpsc_pbuf to know when an overflow occurs. The
size being calculated assumed a ROUND_UP size alignment to sizeof(long
long). On xtensa this is actually 16 bytes as defined by
CBPRINTF_PACKAGE_ALIGNMENT.

Changes the size calculation for SIMPLE_MSG_LEN to account for this.

The second issue was a misaligned package that would cause reading
from the incorrect memory when going to format the package with cbpprintf.

Fixes the padding used to align the package in cbprintf.h and adds a build
assert ensuring correct alignment when building against xtensa in both
cbprintf.h and log_msg.h.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2022-11-04 11:02:27 -04:00
Evgeniy Paltsev ead4d2bc02 ARC: cbprintf: enforce proper alignment
ARC ABI requires stack to be 32 / 64 bit aligned for 32bit and
64 bit architecture variant.

Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
Signed-off-by: Evgeniy Paltsev <PaltsevEvgeniy@gmail.com>
2022-10-31 11:22:12 +01:00
Keith Packard cb5c440525 picolibc: Fix a couple of printfcb wrapper macros
Picolibc aliases the printfcb functions directly to printf
equivalents. There were a couple of these macros that were broken.

Signed-off-by: Keith Packard <keithp@keithp.com>
2022-10-31 17:17:42 +09:00
Carles Cufi 8e4d499fa0 treewide: Use CONFIG_*_ENDIAN instead of __BYTE_ORDER__
In order to avoid using multiple sources of truth for the platfom's
endianness, convert the in-tree code to use the (BIG|LITTLE)_ENDIAN
Kconfig variables exclusively, instead of the compiler's
__BYTE_ORDER__.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2022-10-28 19:23:46 +09:00
Kumar Gala 77dcf91f50 smp: define arch_num_cpus always
Move arch_num_cpus outside of CONFIG_SMP in sys/arch_interface.h and
add define arch_num_cpus on all platforms (added arch_inlines.h on
those platforms that didn't have it before).

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2022-10-21 13:14:58 +02:00
Tom Burdick 872e3553f9 kernel: Option to assert on spin lock time
Spin locks held for any lengthy duration prevent interrupts and
in a real time system where interrupts drive tasks this can be
problematic. Add an option to assert if a spin lock is held for
a duration longer than the configurable number of microseconds.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2022-10-18 14:14:12 +02: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
Tomasz Moń 0b32870838 doc: Use Markdown syntax instead of html tt blocks
Doxygen comment containing <tt>__VA_ARGS__</tt> does not render
correctly, i.e. __VA_ARGS__ is completely missing from the html
output. The Markdown syntax `__VA_ARGS__` renders as expected.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2022-10-11 16:22:35 +02:00
Peter Tönz 387d84e452 includes: prevent warnings (Z_CBPRINTF_ARG_SIZE shadows variables)
We compile with the gcc compiler flags -Werror and -Wshadow. So
the mentioned macro rasies a warning (and with the flags the
warning becoms to an error). It uses the same variable names
as on of its caller. Add an addidional underscore to the
affected variables to prevent this warning.

Signed-off-by: Peter Tönz <peter.tonz@husqvarnagroup.com>
2022-09-26 09:43:28 -05:00
Henri Xavier 1a276d0ac6 ring_buffer: Introduce RING_BUF_ITEM_SIZEOF
Currently, to compute the 'item' size in a ring buffer, we have
`SIZE32_OF`.

Several issues with this:
- `SIZE32_OF` only works on variables, not types, due to an extra
 parenthesis pair. Indeed, `sizeof((int))` is not valid C, whereas
 `sizeof((my_var))` is.
- `SIZE32_OF` is not a proper public API
- `SIZE32_OF` rounds down if the argument size is not a multiple
 of 4 bytes.

Thus, we introduce a proper `RING_BUF_ITEM_SIZEOF`, fixing the
aforementioned issues.

Signed-off-by: Henri Xavier <datacomos@huawei.com>
2022-09-20 09:08:14 +00:00
Krzysztof Chruscinski a7224830ce lib: os: cbprintf: Mechanism for detecting %p in static package
Static packaging is using only argument types to build a package. There
is one case where analysing argument type only is not enough to
determine package content. That is %p with (unsigned) char pointer vs
%s. In case of %s a string might need to be appended to the package
and in case of %p it must be avoided. Format string analysis is required
to distinguish those two cases.
In order to speed up the runtime inspection, additional information is
added to a static package. That is index of the string argument (where
first argument has index 0). This information allows quick format string
inspection where nth format specifier is found and checked if it is a
pointer format specifier.
Inspection algorithm is added to cbprintf_package_convert() and if %p
is found then data for that argument is discarded. Additionally, log
warning is printed with suggestion to cast pointer argument to void *
to avoid confusion. It is desired to get rid of this ambiguity because
there are going to be logging configurations where strings are stripped
from a binary and runtime inspection cannot be performed.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-09-19 10:14:23 +00:00
Krzysztof Chruscinski bd51d0ed20 lib: os: cbprintf: Interpret unsigned char pointer as string
Static packaging is analyzing string argument type and based
on that builds a package. The most tricky one are pointers
which can be used for %s or %p. %s are strings which may be
transient and must be appended to the package to allow string
formatting from that package when original transient string
location is lost.
It is allowed (gcc printflike extension does not complain) to
using unsigned char for %s. So far static packaging allowed
only char or wchar_t pointers. Extending detection to unsigned
char as well.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-09-19 10:14:23 +00:00
Christopher Friedt cda7e31de1 util: provide IS_ARRAY_ELEMENT, ARRAY_INDEX, ARRAY_INDEX_FLOOR
`IS_ARRAY_ELEMENT(array, ptr)` behaves like `PART_OF_ARRAY()`
except that it checks that `ptr` is aligned to an array-element
boundary.

`ARRAY_INDEX(array, ptr)` returns the index of `ptr`, where
`ptr` is aligned to an array-element boundary.

`ARRAY_INDEX_FLOOR(array, ptr)` returns the index of `ptr`,
where `ptr` does not need to be aligned to an array-element
boundary.

If `CONFIG_ASSERT=y`, then `ARRAY_INDEX()` and
`ARRAY_INDEX_FLOOR()` will trigger an assertion for invalid
`ptr`.

Signed-off-by: Christopher Friedt <cfriedt@fb.com>
2022-09-09 13:20:12 -05:00
Henrik Brix Andersen 86de6b71a4 sys: util: fix WAIT_FOR() timeout calculation
Use k_us_to_cyc_ceil32() for calculating the number of hardware cycles for
the given timeout value instead of using a custom calculation.

Fixes: #50032

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-09-09 15:28:41 +00:00
Anas Nashif 78d8ea4a62 doc: doxygen: group heap APIs
Group heap APIs under heap management.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-09-07 10:45:55 -04:00
Anas Nashif 163b99e755 doc: doxyegen: readd data structure api group
Re-add parent groups for data-structures.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-09-07 10:36:25 +02:00
Anas Nashif d7f2f97fe9 doc: doxygen: add memory management group
Add new group for all memory management APIs.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-09-07 10:36:25 +02:00
Anas Nashif 5a60fd5397 doc: doxygen: restructure device model APIs
add doxygen groups for device model under one parent group.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-09-07 10:36:25 +02:00
Anas Nashif 4530268e79 doc: group demand paging APIs in doxygne
add doxygen groups for demand paging under one parent group.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-09-07 10:36:25 +02:00
Daniel Leung 203c4c2e13 lib: os: cbprintf: move padding for xtensa from hdr_ext to hdr
This moves padding needed for Xtensa in the cbprintf package header
from the extended header to the simple header. This is due to
the cbprintf packaging function uses the simple header to calculate
offset. This results in the padding not being there in the package,
and the printing function reading incorrect data in the package.

This was discovered while looking into #49016. Without the padding
in the simple header, turning on tagged argument on cbprintf would
crash on qemu_xtensa.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2022-09-05 10:16:07 +02:00
Rob Barnes f3375af4b6 cbprintf: Remove unnecessary downcast
Downcast from const void* to void* is unnecessary since the signature of
memcpy expects a const in second param. This downcast will raise a
compile error when -Werror=cast-qual is on.

Signed-off-by: Rob Barnes <robbarnes@google.com>
2022-08-31 10:21:42 +00:00
Flavio Ceolin 30e2b8049f mm: Remove deprecated definition
K_MEM_MAP_GUARD was deprecated before 2.6 release. Just removing it.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2022-08-27 16:18:06 -04:00
Krzysztof Chruscinski bb74b4f028 lib: os: cbprintf: Renamed flags used for conversion function
At some point, package copy function was extended and renamed
to cbprintf_package_convert. However, flags used by this
function were not renamed and used contained COPY idiom.
Deprecating flags with COPY and replacing them with flags
with CONVERT idiom to match function which is utilizing them.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-08-26 12:52:08 +02:00
Carlo Caione ae82071ae4 arch: Rework cache-related Kconfig symbols
We have now:

- CPU_HAS_{D,I}CACHE: when the CPU has support for d-cache and i-cache

- {D,I}CACHE: to enable / disable d-cache and i-cache

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2022-08-18 11:30:49 +00:00
Daniel Leung 7dc20978e3 lib: os: cbprintf: fix typo exteral -> external
The cbprintf formatter cbvprintf_exteral_formatter_func has a typo
in it with a missing 'n'. So add it.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2022-08-17 08:08:46 +00:00
Stephanos Ioannidis 230ddd9a7f lib: os: assert: Add unreachable path hint for assertion failure
This commit adds the `CODE_UNREACHABLE` hint at the end of the
assertion failure branch so that the compiler takes note of the assert
function not returning when an assertion fails.

This prevents the compiler from generating misguided warnings assuming
the asserted execution paths.

It also introduces the `ASSERT_TEST` Kconfig symbol, which indicates
that the "assert test mode" is enabled. This symbol may be selected by
the tests that require the assert post action function to return
without aborting so that the test can proceed.

Note that the `CODE_UNREACHABLE` hint is specified only when the assert
test mode is disabled in order to prevent the tests from crashing when
the assert post action function returns.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2022-08-10 14:32:36 +02:00
Gerard Marull-Paretas a7c3e7e84a doxygen: remove redundant usages of def
The def command Indicates that a comment block contains documentation
for a #define macro. This is useful if the comment block documents a
macro not adjacent to it, e.g.

```c
/**
 * @def MAX(x,y)
 * @brief Computes the maximum of @a x and @a y.
 */
 #ifdef XXX
 #define MAX(x,y) ...
 #endif
```

However, it is not necessary if the comment is adjacent to the
definition, e.g.

```c
/**
 * @brief Computes the maximum of @a x and @a y.
 */
 #define MAX(x,y) ...
```

This patch removes all unnecessary def entries in-tree.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-09 12:29:28 +02:00
Aurelien Jarno d98a75a4cb sys: util: export Z_IS_EQ macro as IS_EQ
And also add the corresponding documentation.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2022-08-04 17:35:39 +01:00
Kumar Gala 9341b98821 sys: util: add a Z_IS_EQ macro to compare integers
This macro compares two integers from 0 to 255 at compile time, using
the preprocessor.

Signed-off-by: Kumar Gala <galak@kernel.org>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2022-08-04 17:35:39 +01:00
Fabio Baltieri 24d09d363c include: fix the remaining legacy #include paths
Add the "zephyr/" prefix to various #include statements that are
preventing the CI form running with LEGACY_INCLUDE_PATH=n.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2022-08-02 16:41:41 +01:00
Corey Wharton f78726124f arch: fix typos for arch_icache_disable
arch_dcache_disable was declared twice and function comments were wrong.

Signed-off-by: Corey Wharton <xodus7@cwharton.com>
2022-07-30 07:11:35 -04:00
Simon Hein c1288208ce include: zephyr: comply to coding guidelines MISRA C:2012 Rule 14.4
MISRA C:2012 Rule 14.4 (The controlling expression of an if statement
and the controlling expression of an iteration-statement shall have
essentially Boolean type.)

Use comparisons with NULL instead of implicitly testing pointers.
Use `do { ... } while (false)' instead of `do { ... } while (0)'.
Use comparisons with zero instead of implicitly testing integers.

The commit is a subset of the original auditable-branch commit:
5d02614e34a86b549c7707d3d9f0984bc3a5f22a

Signed-off-by: Simon Hein <SHein@baumer.com>
2022-07-26 15:30:11 -04:00
Yuval Peress 82caf98dde cbprintf: fix missing field initializer warning
When compiling with '-Werror=missing-field-initializers', the cbprintf
header causes an error since 'off' isn't initialized.

Signed-off-by: Yuval Peress <peress@google.com>
2022-07-19 10:29:53 +02:00
Krzysztof Chruscinski b6dcdb17f9 lib: os: spsc_pbuf: Improve data cache configuration
Use CONFIG_DCACHE_LINE_SIZE to determine distance between
fields modified by different cores.
Add option which specifies what is the data cache line
of the remote core. Maximum from local and remote cache
line sizes is used as distance and alignement.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-07-18 12:21:16 -04:00
Tomislav Milkovic 0fe2c1fe90 everywhere: Fix legacy include paths
Any project with Kconfig option CONFIG_LEGACY_INCLUDE_PATH set to n
couldn't be built because some files were missing zephyr/ prefix in
includes
Re-run the migrate_includes.py script to fix all legacy include paths

Signed-off-by: Tomislav Milkovic <milkovic@byte-lab.com>
2022-07-18 16:16:47 +00:00
Marcin Szkudlinski e4d11fe177 lib: mem_blocks: add a usage test for a block
add a sys_mem_blocks_is_region_free procedure to test
if the block in question is free or taken

Signed-off-by: Marcin Szkudlinski <marcin.szkudlinski@intel.com>
Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
2022-07-14 10:44:18 +02:00
Peter Mitsis 3b7818b2d2 lib/os: use generic mem stats structure for heap
Since the retrieved heap memory statistics are identical to those of
the retrieved mem_block statistics, it makes sense to use a single
generic-named structure for both instead of two identical structures
with different names.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2022-07-12 13:59:26 +00:00
Peter Mitsis d061366f54 lib/os: add statistics tracking to mem_blocks
Both the current and maximum number of allocations in a given memory
blocked are tracked (and can be queried) when the
CONFIG_SYS_MEM_BLOCKS_RUNTIME_STATS Kconfig option is selected.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2022-07-12 13:59:26 +00:00
Anas Nashif efbadbb677 scripts: move gen_kobject_list.py to scripts/build/gen_kobject_list.py
Move scripts needed by the build system and not designed to be run
individually or standalone into the build subfolder.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-07-12 10:03:45 +02:00