Update the casting of the 'attr' parameter in pthread_cond_init to use
the correct variable name 'att'. Thanks clang for spotting the typo.
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Use the tp_diff() macro as a means of converting an absolute timeout
with respect to a specific clock to a relative timeout, in ms.
Clamp the result between 0 and UINT32_MAX.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Move somewhat useful (but private and internal functions) that deal
with struct timespec to posix_clock.h until there is a better API
available for dealing with operations on struct timespec.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Always require the clockid_t argument to timespec_to_timeoutms() and
remove the unused variant that accepts no clockid_t parameter.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Use CLOCK_REALTIME for the default clock source throughout
the POSIX implementation and tests so that we are
consistent with the specification.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Add a common private function timespec_is_valid() that
can be used to check if a timespec object is valid, and
use that consistently in lib/posix/options.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Add definitions for struct posix_condattr and struct posix_cond, which
are internal variants of the external pthread_condattr_t and
pthread_cond_t types.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Provide a private internal function timespec_to_clock_timeoutms() to
complement timespec_to_timeoutms(). This new variant accepts a clock_t
parameter that allows the caller to specify which clock to use.
The original timespec_to_timeoutms() then just becomes a static inline
wrapper around the original.
Note: timespec_to_clock_timeoutms() and timespec_to_timeoutms() might
have a limited lifespan, since it might make sense to create a
common timespec manipulation library.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Provide a single declaration of timespec_to_timeoutms() (which is
a private function), in the private header file posix_clock.h .
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
The implementation of POSIX_SEMAPHORES historically used heap allocation
and has not yet been transitioned to a pool allocator.
However, since 590258b381, the default heap-add with CONFIG_POSIX_API
has been reduced from 1 kiB which causes tests/posix/semaphores to fail
due to NULL being returned from a call to k_calloc().
Create a minimal heap-add for the POSIX_SEMAPHORES Option Group.
This can be removed at a future date if semaphores are changed to use
a pooled allocator and fixed-size name, rather than heap allocation.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
`pthread_setspecific` requires a stack in order to allocate the
`struct pthread_key_data` data structure. On 64 bit systems this data
structure is 32 bytes, resulting in 160 bytes usage for the default 5
supported threads.
Signed-off-by: Jordan Yates <jordan@embeint.com>
Don't `imply POSIX_MESSAGE_PASSING` when `POSIX_API=y` as this option
has a non-trivial RAM implication in `HEAP_MEM_POOL_ADD_SIZE_MQUEUE`.
The `mq_*` API is minimally used in-tree, with all users already
enabling the symbol directly.
Signed-off-by: Jordan Yates <jordan@embeint.com>
The signedness of the variable caused undefined behavior because the
sign bit is modified when it gets left-shifted.
This fixes that by changing it to an unsigned variable.
Signed-off-by: Daniel Hajjar <daniel.hajjar16@gmail.com>
If it is not possible to create a timer in timer_create(),
then the timer_obj associated with the timer must be freed.
However, the address of the pointer was mistakenly being
passed to k_mem_slab_free() rather than simply the
the pointer.
This caused a crash in tests which can easily be avoided
by passing the pointer rather than the address of the
pointer.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
This adds the best HD=4 CRC32 polynomial. The discovery
is the result of research by Philip Koopman of Carnegie
Mellon University, and is well documented at
https://users.ece.cmu.edu/~koopman/crc/.
The user is given the option of trading 1024B of RAM to
improve the execution speed. The unit tests are parameterized
with this KConfig option.
Signed-off-by: JP Hutchins <jp@intercreate.io>
Support parsing and serializing of struct fields that are defined as a
char array.
Use the token JSON_TOK_STRING_BUF to parse and serialize a string for a
char array, for example:
struct foo {
const char *str;
char str_buf[30];
};
struct json_obj_descr foo_descr[] = {
JSON_OBJ_DESCR_PRIM(struct foo, str, JSON_TOK_STRING),
JSON_OBJ_DESCR_PRIM(struct foo, str_buf, JSON_TOK_STRING_BUF),
};
The struct 'json_obj_descr' now has an additional union member 'field'
to store the size of the struct field, which is used with the token
'JSON_TOK_STRING_BUF' to determine the element size.
Fixes: #65200
Signed-off-by: Christoph Winklhofer <cj.winklhofer@gmail.com>
Up to now, the handling of type float was offloaded to the users of the
JSON utility, with the token JSON_TOK_FLOAT.
Improve handling of floating point types and support the types 'float'
and 'double' in a built-in way so that they can be directly parsed to
and serialized from variables (of type float or double).
The types are serialized in the shortest representation, either as a
decimal number or in scientific notation:
* float (with JSON_TOK_FLOAT_FP): encoded with maximal 9 digits
* double (with JSON_TOK_DOUBLE_FP): encoded with maximal 16 digits
* NaN, Infinity, -Infinity: encoded and decoded as:
{"nan_val":NaN,"inf_pos":Infinity,"inf_neg":-Infinity}
Enable the floating point functionality with the Kconfig option:
JSON_LIBRARY_FP_SUPPORT=y
It requires a libc implementation with support for floating point
functions: strtof(), strtod(), isnan() and isinf().
Fixes: #59412
Signed-off-by: Christoph Winklhofer <cj.winklhofer@gmail.com>
Add support to decode the special floating point values NaN, Infinity
and -Infinity. For example:
{"nan_val":NaN,"inf_pos":Infinity,"inf_neg":-Infinity}
Note that this commit is a preparation for the built-in support of
floating point values and these are only accepted when compiled with
the flag -DCONFIG_JSON_LIBRARY_FP_SUPPORT.
Signed-off-by: Christoph Winklhofer <cj.winklhofer@gmail.com>
Add support to decode floating point numbers in scientific notation,
e.g. 3.40282347e+38. Only the lower-case specifier 'e' is allowed.
Signed-off-by: Christoph Winklhofer <cj.winklhofer@gmail.com>
The calculation of the object size may be incorrect when the size of
a field is smaller than the struct alignment. When such a struct is
used in an array field, the decoded object contains wrong values.
The alignment influences the object size. For example the following
struct has a calculated object size of 8 bytes, however due to
alignment the real size of the struct is 12 bytes:
struct test_bool {
bool b1; /* offset 0, size 1 */
/* 3-byte padding */
int i1; /* offset 4, size 4 */
bool b2; /* offset 8, size 1 */
/* 3-byte padding */
};
This commit changes the object size calculation and computes the size
with the offset and size of the last field in the struct (rounded up
by the struct alignment).
Fixes: #85121
Signed-off-by: Christoph Winklhofer <cj.winklhofer@gmail.com>
When sys_heap_realloc() is expressed in terms of sys_heap_aligned_realloc()
it invokes a longer aligned allocation code path with an extra runtime
overhead even though no alignment is necessary.
Let's reference and invoke the aligned allocation code path only when an
actual aligned allocation is requested. This opens the possibility for
the linker to garbage-collect the aligning code otherwise.
Improve realloc documentation while at it.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
When k_malloc() is expressed in terms of k_aligned_alloc() it invokes a
longer aligned allocation code path with an extra runtime overhead even
though no alignment is necessary.
Let's reference and invoke the aligned allocation code path only when an
actual aligned allocation is requested. This opens the possibility for
the linker to garbage-collect the aligning code otherwise.
Also bypass k_heap_malloc() and friends given they're invoked with
K_NO_WAIT. Go directly to sys_heap_*() instead to cut some more unneeded
overhead.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
When k_heap_alloc() is expressed in terms of k_heap_aligned_alloc()
it invokes a longer aligned allocation code path with an extra runtime
overhead even though no alignment is necessary.
Let's reference and invoke the aligned allocation code path only when an
actual aligned allocation is requested. This opens the possibility for
the linker to garbage-collect the aligning code otherwise.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
Option OPENAMP_COPY_RSC_TABLE is added for cases where the placement of the
.resource_table section is not controlled by the remote. This option lets
zephyr do the copying of the .resource_table section to a specified memory
region.
Signed-off-by: Andre Heinemans <andre.heinemans@nxp.com>
Remove deprecated Kconfig options. These were given an extra
release cycle of soak time, but generally were OK to remove
after Zephyr v4.0.0 was released.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
MAX_PTHREAD_COUNT was deprecated in favour of
POSIX_THREAD_THREADS_MAX prior to v3.7.0.
Use CONFIG_POSIX_THREAD_THREADS_MAX going forward.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
This board does not exist anymore, so this is just dead code at this
point.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
Make struct ring_buf 12 bytes smaller by default. This comes with a 32KB
buffer size limit which covers almost all cases. The previous limit of
2GB can be restored with CONFIG_RING_BUFFER_LARGE=y.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
Make it more informative and useful.
Buffer sizes that are a power of 2 didn't provide any advantage since
commit 099850e916 ("ring_buffer: the great simplification").
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
When a queue has been unlinked but not removed the name pointer is set to
NULL. The queue is still in the list when adding new queues and the name
pointer is passed to strcmp.
Signed-off-by: Jari Tervonen <jari.tervonen@nordicsemi.no>
With MMU being converted to a non-user-configurable option, we can
rely on that exclusively to know whether arch_mem_map() and
arch_mem_unmap() are available and we can remove the workarounds
in POSIX at the Kconfig level.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Two public functions do not take the spinlock even though
they access mutable, non-atomic members of the buffer:
- mpsc_pbuf_get_utilization()
- mpsc_pbuf_get_max_utilization()
Take the spinlock to avoid possible data races.
Signed-off-by: Damian Krolik <damian.krolik@nordicsemi.no>
In order to make them functional for devices during init. Default
behavior is to keep late initialization, as before.
Signed-off-by: Luis Ubieda <luisf@croxel.com>
Switch to the common abort implementation so that we can use it
from the assert hooks to avoid undefined behavior.
Closes: 84824
Signed-off-by: Keith Packard <keithp@keithp.com>
Add an optional handler to the p4wq to give the submitting code
(e.g. rtio workq) a possibility execute code after the work was
succesfully executed.
Signed-off-by: Florian Weber <Florian.Weber@live.de>
Several downstream libraries need to specify that they work with c++ 17+
or 20+ and there's no easy way to do this without constantly updating
the Kconfig file and supporting different Kconfig versions for different
Zephyr versions (since I can't add a dependency on a new c++ standard
and have it backwards compatible.
Signed-off-by: Yuval Peress <peress@google.com>
Change the condition so that ESP32 SoCs are using `_heap_sentry` to
get actual run-time heap size.
Signed-off-by: Marek Matej <marek.matej@espressif.com>