Skip to content

Commit

Permalink
ipc: icbmsg: Reduce block alignment to 32-bits
Browse files Browse the repository at this point in the history
The ICBMsg backend divides its memory into
blocks. Each block is aligned to data cache
alignment. Is it not required, since adjacent
blocks has the same data flow direction (either
read-only or write-only). This commit changes
it to 32-bits making wasted memory significantly
reduced.

Signed-off-by: Dominik Kilian <[email protected]>
  • Loading branch information
doki-nordic committed Oct 23, 2024
1 parent bd932d1 commit 73fd121
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions subsys/ipc/ipc_service/backends/ipc_icbmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,11 @@ const static struct ipc_service_backend backend_ops = {
.release_rx_buffer = release_rx_buffer,
};

/**
* Required block alignment.
*/
#define BLOCK_ALIGNMENT sizeof(uint32_t)

/**
* Number of bytes per each ICMsg message. It is used to calculate size of ICMsg area.
*/
Expand All @@ -1308,28 +1313,28 @@ const static struct ipc_service_backend backend_ops = {
(PBUF_HEADER_OVERHEAD(GET_CACHE_ALIGNMENT(i)) + 2 * BYTES_PER_ICMSG_MESSAGE)

/**
* Returns required block alignment for instance "i".
* Returns required data cache alignment for instance "i".
*/
#define GET_CACHE_ALIGNMENT(i) \
MAX(sizeof(uint32_t), DT_INST_PROP_OR(i, dcache_alignment, 0))
MAX(BLOCK_ALIGNMENT, DT_INST_PROP_OR(i, dcache_alignment, 0))

Check notice on line 1320 in subsys/ipc/ipc_service/backends/ipc_icbmsg.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/ipc/ipc_service/backends/ipc_icbmsg.c:1320 -#define GET_CACHE_ALIGNMENT(i) \ - MAX(BLOCK_ALIGNMENT, DT_INST_PROP_OR(i, dcache_alignment, 0)) +#define GET_CACHE_ALIGNMENT(i) MAX(BLOCK_ALIGNMENT, DT_INST_PROP_OR(i, dcache_alignment, 0))
/**
* Calculates minimum size required for ICMsg region for specific number of local
* and remote blocks. The minimum size ensures that ICMsg queue is will never overflow
* because it can hold data message for each local block and release message
* for each remote block.
*/
#define GET_ICMSG_MIN_SIZE(i, local_blocks, remote_blocks) \
#define GET_ICMSG_MIN_SIZE(i, local_blocks, remote_blocks) ROUND_UP( \
(ICMSG_BUFFER_OVERHEAD(i) + BYTES_PER_ICMSG_MESSAGE * \
(local_blocks + remote_blocks))
(local_blocks + remote_blocks)), GET_CACHE_ALIGNMENT(i))

/**
* Calculate aligned block size by evenly dividing remaining space after removing
* the space for ICMsg.
*/
#define GET_BLOCK_SIZE(i, total_size, local_blocks, remote_blocks) ROUND_DOWN( \
((total_size) - GET_ICMSG_MIN_SIZE(i, (local_blocks), (remote_blocks))) / \
(local_blocks), GET_CACHE_ALIGNMENT(i))
(local_blocks), BLOCK_ALIGNMENT)

Check notice on line 1338 in subsys/ipc/ipc_service/backends/ipc_icbmsg.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/ipc/ipc_service/backends/ipc_icbmsg.c:1338 -#define GET_ICMSG_MIN_SIZE(i, local_blocks, remote_blocks) ROUND_UP( \ - (ICMSG_BUFFER_OVERHEAD(i) + BYTES_PER_ICMSG_MESSAGE * \ - (local_blocks + remote_blocks)), GET_CACHE_ALIGNMENT(i)) +#define GET_ICMSG_MIN_SIZE(i, local_blocks, remote_blocks) \ + ROUND_UP((ICMSG_BUFFER_OVERHEAD(i) + \ + BYTES_PER_ICMSG_MESSAGE * (local_blocks + remote_blocks)), \ + GET_CACHE_ALIGNMENT(i)) /** * Calculate aligned block size by evenly dividing remaining space after removing * the space for ICMsg. */ -#define GET_BLOCK_SIZE(i, total_size, local_blocks, remote_blocks) ROUND_DOWN( \ - ((total_size) - GET_ICMSG_MIN_SIZE(i, (local_blocks), (remote_blocks))) / \ - (local_blocks), BLOCK_ALIGNMENT) +#define GET_BLOCK_SIZE(i, total_size, local_blocks, remote_blocks) \ + ROUND_DOWN(((total_size) - GET_ICMSG_MIN_SIZE(i, (local_blocks), (remote_blocks))) / \ + (local_blocks), \ + BLOCK_ALIGNMENT)
/**
* Calculate offset where area for blocks starts which is just after the ICMsg.
Expand Down Expand Up @@ -1434,11 +1439,11 @@ const static struct ipc_service_backend backend_ops = {
}; \
BUILD_ASSERT(IS_POWER_OF_TWO(GET_CACHE_ALIGNMENT(i)), \
"This module supports only power of two cache alignment"); \
BUILD_ASSERT((GET_BLOCK_SIZE_INST(i, tx, rx) >= GET_CACHE_ALIGNMENT(i)) && \
BUILD_ASSERT((GET_BLOCK_SIZE_INST(i, tx, rx) >= BLOCK_ALIGNMENT) && \
(GET_BLOCK_SIZE_INST(i, tx, rx) < \
GET_MEM_SIZE_INST(i, tx)), \
"TX region is too small for provided number of blocks"); \
BUILD_ASSERT((GET_BLOCK_SIZE_INST(i, rx, tx) >= GET_CACHE_ALIGNMENT(i)) && \
BUILD_ASSERT((GET_BLOCK_SIZE_INST(i, rx, tx) >= BLOCK_ALIGNMENT) && \
(GET_BLOCK_SIZE_INST(i, rx, tx) < \
GET_MEM_SIZE_INST(i, rx)), \
"RX region is too small for provided number of blocks"); \
Expand Down

0 comments on commit 73fd121

Please sign in to comment.