lib: move utilities into own folder

Move various utilities out of lib into own folder for better assignement
and management in the maintainer file. lib/os has become another dumping
ground for everything and it the Kconfig and contents in that folder
became difficult to manage, configure and test.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2023-12-20 08:07:43 -05:00 committed by Carles Cufí
parent e710c9ce9e
commit 0b999c0943
24 changed files with 112 additions and 78 deletions

View file

@ -2066,7 +2066,7 @@ JSON Web Token:
files: files:
- subsys/jwt/ - subsys/jwt/
- include/zephyr/data/ - include/zephyr/data/
- lib/os/json.c - lib/utils/json.c
- tests/subsys/jwt/ - tests/subsys/jwt/
- tests/lib/json/ - tests/lib/json/
labels: labels:
@ -2125,8 +2125,15 @@ Kernel:
Utilities: Utilities:
status: maintained status: maintained
maintainers:
- andyross
- nashif
collaborators:
- dcpleung
- peter-mitsis
files: files:
- lib/crc/ - lib/crc/
- lib/utils/
- tests/unit/timeutil/ - tests/unit/timeutil/
- tests/unit/time_units/ - tests/unit/time_units/
- tests/unit/rbtree/ - tests/unit/rbtree/
@ -2136,7 +2143,6 @@ Utilities:
- tests/unit/math_extras/ - tests/unit/math_extras/
- tests/unit/list/ - tests/unit/list/
- tests/unit/intmath/ - tests/unit/intmath/
- tests/misc/print_format/
- tests/unit/pot/ - tests/unit/pot/
- tests/lib/time/ - tests/lib/time/
- tests/lib/onoff/ - tests/lib/onoff/
@ -2147,6 +2153,10 @@ Utilities:
- tests/lib/linear_range/ - tests/lib/linear_range/
labels: labels:
- "area: Utilities" - "area: Utilities"
tests:
- utilities
- libraries.ring_buffer
- libraries.linear_range
Base OS: Base OS:
status: maintained status: maintained
@ -2159,6 +2169,9 @@ Base OS:
files: files:
- include/zephyr/sys/ - include/zephyr/sys/
- lib/os/ - lib/os/
- tests/misc/print_format/
- tests/lib/p4workq/
- tests/lib/fdtable/
files-exclude: files-exclude:
- include/zephyr/sys/cbprintf* - include/zephyr/sys/cbprintf*
- tests/unit/cbprintf/ - tests/unit/cbprintf/
@ -2171,6 +2184,8 @@ Base OS:
- lib/os/mpsc_pbuf.c - lib/os/mpsc_pbuf.c
labels: labels:
- "area: Base OS" - "area: Base OS"
tests:
- printk
Heap Management: Heap Management:
status: maintained status: maintained

View file

@ -13,6 +13,7 @@ add_subdirectory(hash)
add_subdirectory(heap) add_subdirectory(heap)
add_subdirectory(mem_blocks) add_subdirectory(mem_blocks)
add_subdirectory(os) add_subdirectory(os)
add_subdirectory(utils)
add_subdirectory_ifdef(CONFIG_SMF smf) add_subdirectory_ifdef(CONFIG_SMF smf)
add_subdirectory_ifdef(CONFIG_OPENAMP open-amp) add_subdirectory_ifdef(CONFIG_OPENAMP open-amp)
add_subdirectory_ifdef(CONFIG_ACPI acpi) add_subdirectory_ifdef(CONFIG_ACPI acpi)

View file

@ -26,4 +26,6 @@ source "lib/smf/Kconfig"
source "lib/acpi/Kconfig" source "lib/acpi/Kconfig"
source "lib/runtime/Kconfig" source "lib/runtime/Kconfig"
source "lib/utils/Kconfig"
endmenu endmenu

View file

@ -4,23 +4,14 @@ zephyr_syscall_header(
${ZEPHYR_BASE}/include/zephyr/sys/mutex.h ${ZEPHYR_BASE}/include/zephyr/sys/mutex.h
) )
zephyr_sources_ifdef(CONFIG_BASE64 base64.c)
zephyr_sources( zephyr_sources(
cbprintf_packaged.c cbprintf_packaged.c
dec.c
hex.c
printk.c printk.c
rb.c
sem.c sem.c
thread_entry.c thread_entry.c
timeutil.c
bitarray.c
) )
zephyr_sources_ifdef(CONFIG_FDTABLE fdtable.c) zephyr_sources_ifdef(CONFIG_FDTABLE fdtable.c)
zephyr_sources_ifdef(CONFIG_ONOFF onoff.c)
zephyr_sources_ifdef(CONFIG_NOTIFY notify.c)
zephyr_sources_ifdef(CONFIG_CBPRINTF_COMPLETE cbprintf_complete.c) zephyr_sources_ifdef(CONFIG_CBPRINTF_COMPLETE cbprintf_complete.c)
zephyr_sources_ifdef(CONFIG_CBPRINTF_NANO cbprintf_nano.c) zephyr_sources_ifdef(CONFIG_CBPRINTF_NANO cbprintf_nano.c)
@ -29,10 +20,6 @@ if(NOT CONFIG_PICOLIBC)
zephyr_sources(cbprintf.c) zephyr_sources(cbprintf.c)
endif() endif()
zephyr_sources_ifdef(CONFIG_JSON_LIBRARY json.c)
zephyr_sources_ifdef(CONFIG_RING_BUFFER ring_buffer.c)
if (CONFIG_ASSERT OR CONFIG_ASSERT_VERBOSE) if (CONFIG_ASSERT OR CONFIG_ASSERT_VERBOSE)
zephyr_sources(assert.c) zephyr_sources(assert.c)
endif() endif()
@ -47,10 +34,6 @@ zephyr_sources_ifdef(CONFIG_SCHED_DEADLINE p4wq.c)
zephyr_sources_ifdef(CONFIG_REBOOT reboot.c) zephyr_sources_ifdef(CONFIG_REBOOT reboot.c)
zephyr_sources_ifdef(CONFIG_UTF8 utf8.c)
zephyr_sources_ifdef(CONFIG_WINSTREAM winstream.c)
zephyr_sources_ifdef(CONFIG_POWEROFF poweroff.c) zephyr_sources_ifdef(CONFIG_POWEROFF poweroff.c)
zephyr_library_include_directories( zephyr_library_include_directories(

View file

@ -10,29 +10,6 @@ config FDTABLE
for any I/O object implementing POSIX I/O semantics (i.e. read/write + for any I/O object implementing POSIX I/O semantics (i.e. read/write +
aux operations). aux operations).
config JSON_LIBRARY
bool "Build JSON library"
help
Build a minimal JSON parsing/encoding library. Used by sample
applications such as the NATS client.
config RING_BUFFER
bool "Ring buffers"
help
Enable usage of ring buffers. This is similar to kernel FIFOs but ring
buffers manage their own buffer memory and can store arbitrary data.
For optimal performance, use buffer sizes that are a power of 2.
config NOTIFY
bool "Asynchronous Notifications"
help
Use this API to support async transactions.
config BASE64
bool "Base64 encoding and decoding"
help
Enable base64 encoding and decoding functionality
config PRINTK_SYNC config PRINTK_SYNC
bool "Serialize printk() calls" bool "Serialize printk() calls"
default y if SMP && MP_MAX_NUM_CPUS > 1 && !(EFI_CONSOLE && LOG) default y if SMP && MP_MAX_NUM_CPUS > 1 && !(EFI_CONSOLE && LOG)
@ -50,14 +27,6 @@ config MPSC_PBUF
storing variable length packets in a circular way and operate directly storing variable length packets in a circular way and operate directly
on the buffer memory. on the buffer memory.
config ONOFF
bool "On-Off Manager"
select NOTIFY
help
An on-off manager supports an arbitrary number of clients of a
service which has a binary state. Example applications are power
rails, clocks, and binary device power management.
config SPSC_PBUF config SPSC_PBUF
bool "Single producer, single consumer packet buffer" bool "Single producer, single consumer packet buffer"
help help
@ -119,23 +88,6 @@ config SPSC_PBUF_UTILIZATION
endif # SPSC_PBUF endif # SPSC_PBUF
config WINSTREAM
bool "Lockless shared memory window byte stream"
help
Winstream is a byte stream IPC for use in shared memory
"windows", generally for transmit to non-Zephyr contexts that
can't share Zephyr APIs or data structures.
if WINSTREAM
config WINSTREAM_STDLIB_MEMCOPY
bool "Use standard memcpy() in winstream"
help
The sys_winstream utility is sometimes used in early boot
environments before the standard library is usable. By
default it uses a simple internal bytewise memcpy(). Set
this to use the one from the standard library.
endif
if MPSC_PBUF if MPSC_PBUF
config MPSC_CLEAR_ALLOCATED config MPSC_CLEAR_ALLOCATED
bool "Clear allocated packet" bool "Clear allocated packet"
@ -161,12 +113,6 @@ config POWEROFF
help help
Enable support for system power off. Enable support for system power off.
config UTF8
bool "UTF-8 string operation supported"
help
Enable the utf8 API. The API implements functions to specifically
handle UTF-8 encoded strings.
rsource "Kconfig.cbprintf" rsource "Kconfig.cbprintf"
endmenu endmenu

27
lib/utils/CMakeLists.txt Normal file
View file

@ -0,0 +1,27 @@
# SPDX-License-Identifier: Apache-2.0
zephyr_sources_ifdef(CONFIG_BASE64 base64.c)
zephyr_sources(
dec.c
hex.c
rb.c
timeutil.c
bitarray.c
)
zephyr_sources_ifdef(CONFIG_ONOFF onoff.c)
zephyr_sources_ifdef(CONFIG_NOTIFY notify.c)
zephyr_sources_ifdef(CONFIG_JSON_LIBRARY json.c)
zephyr_sources_ifdef(CONFIG_RING_BUFFER ring_buffer.c)
zephyr_sources_ifdef(CONFIG_UTF8 utf8.c)
zephyr_sources_ifdef(CONFIG_WINSTREAM winstream.c)
zephyr_library_include_directories(
${ZEPHYR_BASE}/kernel/include
${ZEPHYR_BASE}/arch/${ARCH}/include
)

60
lib/utils/Kconfig Normal file
View file

@ -0,0 +1,60 @@
# Copyright (c) 2016 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
menu "Utility Library"
config JSON_LIBRARY
bool "Build JSON library"
help
Build a minimal JSON parsing/encoding library. Used by sample
applications such as the NATS client.
config RING_BUFFER
bool "Ring buffers"
help
Enable usage of ring buffers. This is similar to kernel FIFOs but ring
buffers manage their own buffer memory and can store arbitrary data.
For optimal performance, use buffer sizes that are a power of 2.
config NOTIFY
bool "Asynchronous Notifications"
help
Use this API to support async transactions.
config BASE64
bool "Base64 encoding and decoding"
help
Enable base64 encoding and decoding functionality
config ONOFF
bool "On-Off Manager"
select NOTIFY
help
An on-off manager supports an arbitrary number of clients of a
service which has a binary state. Example applications are power
rails, clocks, and binary device power management.
config WINSTREAM
bool "Lockless shared memory window byte stream"
help
Winstream is a byte stream IPC for use in shared memory
"windows", generally for transmit to non-Zephyr contexts that
can't share Zephyr APIs or data structures.
if WINSTREAM
config WINSTREAM_STDLIB_MEMCOPY
bool "Use standard memcpy() in winstream"
help
The sys_winstream utility is sometimes used in early boot
environments before the standard library is usable. By
default it uses a simple internal bytewise memcpy(). Set
this to use the one from the standard library.
endif
config UTF8
bool "UTF-8 string operation supported"
help
Enable the utf8 API. The API implements functions to specifically
handle UTF-8 encoded strings.
endmenu

View file

@ -27,7 +27,7 @@
#include <zephyr/sys/base64.h> #include <zephyr/sys/base64.h>
#include <zephyr/ztest.h> #include <zephyr/ztest.h>
#include "../../../lib/os/base64.c" #include "../../../lib/utils/base64.c"
static const unsigned char base64_test_dec[64] = { static const unsigned char base64_test_dec[64] = {
0x24, 0x48, 0x6E, 0x56, 0x87, 0x62, 0x5A, 0xBD, 0x24, 0x48, 0x6E, 0x56, 0x87, 0x62, 0x5A, 0xBD,

View file

@ -6,7 +6,7 @@
#include <zephyr/ztest.h> #include <zephyr/ztest.h>
#include <zephyr/sys/rb.h> #include <zephyr/sys/rb.h>
#include "../../../lib/os/rb.c" #include "../../../lib/utils/rb.c"
#define _CHECK(n) \ #define _CHECK(n) \
zassert_true(!!(n), "Tree check failed: [ " #n " ] @%d", __LINE__) zassert_true(!!(n), "Tree check failed: [ " #n " ] @%d", __LINE__)

View file

@ -6,7 +6,7 @@
#include <zephyr/ztest.h> #include <zephyr/ztest.h>
#include "timeutil_test.h" #include "timeutil_test.h"
#include "../../../lib/os/timeutil.c" #include "../../../lib/utils/timeutil.c"
void timeutil_check(const struct timeutil_test_data *tp, void timeutil_check(const struct timeutil_test_data *tp,
size_t count) size_t count)

View file

@ -4,4 +4,4 @@ cmake_minimum_required(VERSION 3.20.0)
project(util) project(util)
find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE})
target_sources(testbinary PRIVATE main.c maincxx.cxx ${ZEPHYR_BASE}/lib/os/dec.c) target_sources(testbinary PRIVATE main.c maincxx.cxx ${ZEPHYR_BASE}/lib/utils/dec.c)

View file

@ -8,7 +8,7 @@
/* This, uh, seems to be the standard way to unit test library code. /* This, uh, seems to be the standard way to unit test library code.
* Or so I gather from tests/unit/rbtree ... * Or so I gather from tests/unit/rbtree ...
*/ */
#include "../../../lib/os/winstream.c" #include "../../../lib/utils/winstream.c"
#define BUFLEN 64 #define BUFLEN 64