Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linker: do not force keep common kernel objects #28486

Merged
merged 4 commits into from
Sep 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions include/linker/common-ram.ld
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,17 @@
_static_kernel_objects_begin = .;
#endif /* CONFIG_USERSPACE */

Z_ITERABLE_SECTION_RAM(k_timer, 4)
Z_ITERABLE_SECTION_RAM(k_mem_slab, 4)
Z_ITERABLE_SECTION_RAM(k_mem_pool, 4)
Z_ITERABLE_SECTION_RAM(k_heap, 4)
Z_ITERABLE_SECTION_RAM(k_mutex, 4)
Z_ITERABLE_SECTION_RAM(k_stack, 4)
Z_ITERABLE_SECTION_RAM(k_msgq, 4)
Z_ITERABLE_SECTION_RAM(k_mbox, 4)
Z_ITERABLE_SECTION_RAM(k_pipe, 4)
Z_ITERABLE_SECTION_RAM(k_sem, 4)
Z_ITERABLE_SECTION_RAM(k_queue, 4)
Z_ITERABLE_SECTION_RAM_GC_ALLOWED(k_timer, 4)
Z_ITERABLE_SECTION_RAM_GC_ALLOWED(k_mem_slab, 4)
Z_ITERABLE_SECTION_RAM_GC_ALLOWED(k_mem_pool, 4)
Z_ITERABLE_SECTION_RAM_GC_ALLOWED(k_heap, 4)
Z_ITERABLE_SECTION_RAM_GC_ALLOWED(k_mutex, 4)
Z_ITERABLE_SECTION_RAM_GC_ALLOWED(k_stack, 4)
Z_ITERABLE_SECTION_RAM_GC_ALLOWED(k_msgq, 4)
Z_ITERABLE_SECTION_RAM_GC_ALLOWED(k_mbox, 4)
Z_ITERABLE_SECTION_RAM_GC_ALLOWED(k_pipe, 4)
Z_ITERABLE_SECTION_RAM_GC_ALLOWED(k_sem, 4)
Z_ITERABLE_SECTION_RAM_GC_ALLOWED(k_queue, 4)

SECTION_DATA_PROLOGUE(_net_buf_pool_area,,SUBALIGN(4))
{
Expand Down
42 changes: 42 additions & 0 deletions include/linker/linker-defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,72 @@
KEEP(*(SORT_BY_NAME(._##struct_type.static.*))); \
_CONCAT(_##struct_type, _list_end) = .

#define Z_LINK_ITERABLE_GC_ALLOWED(struct_type) \
_CONCAT(_##struct_type, _list_start) = .; \
*(SORT_BY_NAME(._##struct_type.static.*)); \
_CONCAT(_##struct_type, _list_end) = .

/* Define an output section which will set up an iterable area
* of equally-sized data structures. For use with Z_STRUCT_SECTION_ITERABLE.
* Input sections will be sorted by name, per ld's SORT_BY_NAME.
*
* This macro should be used for read-only data.
*
* Note that this keeps the symbols in the image even though
* they are not being directly referenced. Use this when symbols
* are indirectly referenced by iterating through the section.
*/
#define Z_ITERABLE_SECTION_ROM(struct_type, subalign) \
SECTION_PROLOGUE(struct_type##_area,,SUBALIGN(subalign)) \
{ \
Z_LINK_ITERABLE(struct_type); \
} GROUP_LINK_IN(ROMABLE_REGION)

/* Define an output section which will set up an iterable area
* of equally-sized data structures. For use with Z_STRUCT_SECTION_ITERABLE.
* Input sections will be sorted by name, per ld's SORT_BY_NAME.
*
* This macro should be used for read-only data.
*
* Note that the symbols within the section can be garbage collected.
*/
#define Z_ITERABLE_SECTION_ROM_GC_ALLOWED(struct_type, subalign) \
SECTION_PROLOGUE(struct_type##_area,,SUBALIGN(subalign)) \
{ \
Z_LINK_ITERABLE_GC_ALLOWED(struct_type); \
} GROUP_LINK_IN(ROMABLE_REGION)

/* Define an output section which will set up an iterable area
* of equally-sized data structures. For use with Z_STRUCT_SECTION_ITERABLE.
* Input sections will be sorted by name, per ld's SORT_BY_NAME.
*
* This macro should be used for read-write data that is modified at runtime.
*
* Note that this keeps the symbols in the image even though
* they are not being directly referenced. Use this when symbols
* are indirectly referenced by iterating through the section.
*/
#define Z_ITERABLE_SECTION_RAM(struct_type, subalign) \
SECTION_DATA_PROLOGUE(struct_type##_area,,SUBALIGN(subalign)) \
{ \
Z_LINK_ITERABLE(struct_type); \
} GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)


/* Define an output section which will set up an iterable area
* of equally-sized data structures. For use with Z_STRUCT_SECTION_ITERABLE.
* Input sections will be sorted by name, per ld's SORT_BY_NAME.
*
* This macro should be used for read-write data that is modified at runtime.
*
* Note that the symbols within the section can be garbage collected.
*/
#define Z_ITERABLE_SECTION_RAM_GC_ALLOWED(struct_type, subalign) \
SECTION_DATA_PROLOGUE(struct_type##_area,,SUBALIGN(subalign)) \
{ \
Z_LINK_ITERABLE_GC_ALLOWED(struct_type); \
} GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)

/*
* generate a symbol to mark the start of the objects array for
* the specified object and level, then link all of those objects
Expand Down
11 changes: 7 additions & 4 deletions kernel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ add_library(kernel
kheap.c
mailbox.c
mem_slab.c
mempool.c
msg_q.c
mutex.c
pipes.c
Expand Down Expand Up @@ -42,9 +41,13 @@ target_sources_ifdef(CONFIG_ATOMIC_OPERATIONS_C kernel PRIVATE atomic_c.c)
target_sources_ifdef(CONFIG_MMU kernel PRIVATE mmu.c)
target_sources_ifdef(CONFIG_POLL kernel PRIVATE poll.c)

if(${CONFIG_MEM_POOL_HEAP_BACKEND})
else()
target_sources(kernel PRIVATE mempool_sys.c)
if(${CONFIG_KERNEL_MEM_POOL})
target_sources(kernel PRIVATE mempool.c)

if(${CONFIG_MEM_POOL_HEAP_BACKEND})
else()
target_sources(kernel PRIVATE mempool_sys.c)
endif()
endif()

# The last 2 files inside the target_sources_ifdef should be
Expand Down
13 changes: 13 additions & 0 deletions kernel/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,16 @@ config NUM_PIPE_ASYNC_MSGS
Setting this option to 0 disables support for asynchronous
pipe messages.

config KERNEL_MEM_POOL
bool "Use Kernel Memory Pool"
default y
help
Enable the use of kernel memory pool.

Say y if unsure.

if KERNEL_MEM_POOL

config MEM_POOL_HEAP_BACKEND
bool "Use k_heap as the backend for k_mem_pool"
default y
Expand Down Expand Up @@ -472,6 +482,9 @@ config HEAP_MEM_POOL_MIN_SIZE
This option specifies the size of the smallest block in the pool.
Option must be a power of 2 and lower than or equal to the size
of the entire pool.

endif # KERNEL_MEM_POOL

endmenu

config ARCH_HAS_CUSTOM_SWAP_TO_MAIN
Expand Down
1 change: 1 addition & 0 deletions samples/basic/minimal/no-mt.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Single-threaded, no timer support in the kernel

CONFIG_MULTITHREADING=n
CONFIG_KERNEL_MEM_POOL=n