zephyr/lib/os/Kconfig

66 lines
2.1 KiB
Plaintext
Raw Normal View History

# Copyright (c) 2016 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
menu "OS Support 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 "Enable 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 BASE64
bool "Enable base64 encoding and decoding"
help
Enable base64 encoding and decoding functionality
lib/os: Add sys_heap, a new/simpler/faster memory allocator The existing mem_pool implementation has been an endless source of frustration. It's had alignment bugs, it's had racy behavior. It's never been particularly fast. It's outrageously complicated to configure statically. And while its fragmentation resistance and overhead on small blocks is good, it's space efficiencey has always been very poor due to the four-way buddy scheme. This patch introduces sys_heap. It's a more or less conventional segregated fit allocator with power-of-two buckets. It doesn't expose its level structure to the user at all, simply taking an arbitrarily aligned pointer to memory. It stores all metadata inside the heap region. It allocates and frees by simple pointer and not block ID. Static initialization is trivial, and runtime initialization is only a few cycles to format and add one block to a list header. It has excellent space efficiency. Chunks can be split arbitrarily in 8 byte units. Overhead is only four bytes per allocated chunk (eight bytes for heaps >256kb or on 64 bit systems), plus a log2-sized array of 2-word bucket headers. No coarse alignment restrictions on blocks, they can be split and merged (in units of 8 bytes) arbitrarily. It has good fragmentation resistance. Freed blocks are always immediately merged with adjacent free blocks. Allocations are attempted from a sample of the smallest bucket that might fit, falling back rapidly to the smallest block guaranteed to fit. Split memory remaining in the chunk is always returned immediately to the heap for other allocation. It has excellent performance with firmly bounded runtime. All operations are constant time (though there is a search of the smallest bucket that has a compile-time-configurable upper bound, setting this to extreme values results in an effectively linear search of the list), objectively fast (about a hundred instructions) and amenable to locked operation. No more need for fragile lock relaxation trickery. It also contains an extensive validation and stress test framework, something that was sorely lacking in the previous implementation. Note that sys_heap is not a compatible API with sys_mem_pool and k_mem_pool. Partial wrappers for those (now-) legacy APIs will appear later and a deprecation strategy needs to be chosen. Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-07-18 00:58:25 +08:00
config SYS_HEAP_VALIDATE
bool "Enable internal heap validity checking"
help
The sys_heap implementation is instrumented for extensive
internal validation. Leave this off by default, unless
modifying the heap code or (maybe) when running in
environments that require sensitive detection of memory
corruption.
config SYS_HEAP_ALLOC_LOOPS
int "Number of tries in the inner heap allocation loop"
default 3
help
The sys_heap allocator bounds the number of tries from the
smallest chunk level (the one that might not fit the
requested allocation) to maintain constant time performance.
Setting this to a high level will cause the heap to return
more successful allocations in situations of high
fragmentation, at the cost of potentially significant
(linear time) searching of the free list. The default is
three, which results in an allocator with good statistical
properties ("most" allocations that fit will succeed) but
keeps the maximum runtime at a tight bound so that the heap
is useful in locked or ISR contexts.
lib/os: Rework/shrink printk conversions, add 64 bit support Add support for 64 bit conversions in a uniformly expressable way by printing values backwards into a buffer on the stack first. This allows all operations to work on the low bits of the value and so the code doesn't need to care (beyond the size of that buffer) about the word size. This trick also doesn't care about the specifics of the base value, so in the process this unifies the decimal and hex printk conversion code to a single function. This comes at a mild cost in CPU cycles to the decimal converter and somewhat higher cost to hex (because it's now doing a full div/mod operation instead of shifting and masking). And stack usage has grown by a few words to hold the temporary. But the benefits in code size are substantial (e.g. ~250 bytes of .text on arm32). Note that this also contains a change to tests/kernel/common to address what appears to have been a bug in the original converters. The printk test uses a format string that looks like "%-4x%-2p" and feeds it the literal arguments "0xABCDEF" and "(char *)42". Now... clearly both those results are going to overflow the 4 and 2-byte field sizes, so there shouldn't be any whitespace between these fields. But the test was written to expect two spaces, inexplicably (yes, I checked: POSIX-compatible printf implementations don't have those spaces either). The new code is definitely doing the right thing, so fix the test instead. Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-06-23 06:54:23 +08:00
config PRINTK64
bool "Enable 64 bit printk conversions (DEPRECATED)"
lib/os: Rework/shrink printk conversions, add 64 bit support Add support for 64 bit conversions in a uniformly expressable way by printing values backwards into a buffer on the stack first. This allows all operations to work on the low bits of the value and so the code doesn't need to care (beyond the size of that buffer) about the word size. This trick also doesn't care about the specifics of the base value, so in the process this unifies the decimal and hex printk conversion code to a single function. This comes at a mild cost in CPU cycles to the decimal converter and somewhat higher cost to hex (because it's now doing a full div/mod operation instead of shifting and masking). And stack usage has grown by a few words to hold the temporary. But the benefits in code size are substantial (e.g. ~250 bytes of .text on arm32). Note that this also contains a change to tests/kernel/common to address what appears to have been a bug in the original converters. The printk test uses a format string that looks like "%-4x%-2p" and feeds it the literal arguments "0xABCDEF" and "(char *)42". Now... clearly both those results are going to overflow the 4 and 2-byte field sizes, so there shouldn't be any whitespace between these fields. But the test was written to expect two spaces, inexplicably (yes, I checked: POSIX-compatible printf implementations don't have those spaces either). The new code is definitely doing the right thing, so fix the test instead. Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-06-23 06:54:23 +08:00
help
Replace with CBPRINTF_FULL_INTEGRAL.
lib/os: Rework/shrink printk conversions, add 64 bit support Add support for 64 bit conversions in a uniformly expressable way by printing values backwards into a buffer on the stack first. This allows all operations to work on the low bits of the value and so the code doesn't need to care (beyond the size of that buffer) about the word size. This trick also doesn't care about the specifics of the base value, so in the process this unifies the decimal and hex printk conversion code to a single function. This comes at a mild cost in CPU cycles to the decimal converter and somewhat higher cost to hex (because it's now doing a full div/mod operation instead of shifting and masking). And stack usage has grown by a few words to hold the temporary. But the benefits in code size are substantial (e.g. ~250 bytes of .text on arm32). Note that this also contains a change to tests/kernel/common to address what appears to have been a bug in the original converters. The printk test uses a format string that looks like "%-4x%-2p" and feeds it the literal arguments "0xABCDEF" and "(char *)42". Now... clearly both those results are going to overflow the 4 and 2-byte field sizes, so there shouldn't be any whitespace between these fields. But the test was written to expect two spaces, inexplicably (yes, I checked: POSIX-compatible printf implementations don't have those spaces either). The new code is definitely doing the right thing, so fix the test instead. Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-06-23 06:54:23 +08:00
config PRINTK_SYNC
bool "Serialize printk() calls"
default y if SMP && MP_NUM_CPUS > 1
help
When true, a spinlock will be taken around the output from a
single printk() call, preventing the output data from
interleaving with concurrent usage from another CPU or an
preempting interrupt.
rsource "Kconfig.cbprintf"
endmenu