Skip to content

Commit 81bb231

Browse files
doki-nordicnashif
authored andcommitted
ipc: icbmsg: Reduce block alignment to 32-bits
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]>
1 parent 4fe6d47 commit 81bb231

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

subsys/ipc/ipc_service/backends/ipc_icbmsg.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,11 @@ const static struct ipc_service_backend backend_ops = {
12961296
.release_rx_buffer = release_rx_buffer,
12971297
};
12981298

1299+
/**
1300+
* Required block alignment.
1301+
*/
1302+
#define BLOCK_ALIGNMENT sizeof(uint32_t)
1303+
12991304
/**
13001305
* Number of bytes per each ICMsg message. It is used to calculate size of ICMsg area.
13011306
*/
@@ -1309,28 +1314,28 @@ const static struct ipc_service_backend backend_ops = {
13091314
(PBUF_HEADER_OVERHEAD(GET_CACHE_ALIGNMENT(i)) + 2 * BYTES_PER_ICMSG_MESSAGE)
13101315

13111316
/**
1312-
* Returns required block alignment for instance "i".
1317+
* Returns required data cache alignment for instance "i".
13131318
*/
13141319
#define GET_CACHE_ALIGNMENT(i) \
1315-
MAX(sizeof(uint32_t), DT_INST_PROP_OR(i, dcache_alignment, 0))
1320+
MAX(BLOCK_ALIGNMENT, DT_INST_PROP_OR(i, dcache_alignment, 0))
13161321

13171322
/**
13181323
* Calculates minimum size required for ICMsg region for specific number of local
13191324
* and remote blocks. The minimum size ensures that ICMsg queue is will never overflow
13201325
* because it can hold data message for each local block and release message
13211326
* for each remote block.
13221327
*/
1323-
#define GET_ICMSG_MIN_SIZE(i, local_blocks, remote_blocks) \
1328+
#define GET_ICMSG_MIN_SIZE(i, local_blocks, remote_blocks) ROUND_UP( \
13241329
(ICMSG_BUFFER_OVERHEAD(i) + BYTES_PER_ICMSG_MESSAGE * \
1325-
(local_blocks + remote_blocks))
1330+
(local_blocks + remote_blocks)), GET_CACHE_ALIGNMENT(i))
13261331

13271332
/**
13281333
* Calculate aligned block size by evenly dividing remaining space after removing
13291334
* the space for ICMsg.
13301335
*/
13311336
#define GET_BLOCK_SIZE(i, total_size, local_blocks, remote_blocks) ROUND_DOWN( \
13321337
((total_size) - GET_ICMSG_MIN_SIZE(i, (local_blocks), (remote_blocks))) / \
1333-
(local_blocks), GET_CACHE_ALIGNMENT(i))
1338+
(local_blocks), BLOCK_ALIGNMENT)
13341339

13351340
/**
13361341
* Calculate offset where area for blocks starts which is just after the ICMsg.
@@ -1435,11 +1440,11 @@ const static struct ipc_service_backend backend_ops = {
14351440
}; \
14361441
BUILD_ASSERT(IS_POWER_OF_TWO(GET_CACHE_ALIGNMENT(i)), \
14371442
"This module supports only power of two cache alignment"); \
1438-
BUILD_ASSERT((GET_BLOCK_SIZE_INST(i, tx, rx) >= GET_CACHE_ALIGNMENT(i)) && \
1443+
BUILD_ASSERT((GET_BLOCK_SIZE_INST(i, tx, rx) >= BLOCK_ALIGNMENT) && \
14391444
(GET_BLOCK_SIZE_INST(i, tx, rx) < \
14401445
GET_MEM_SIZE_INST(i, tx)), \
14411446
"TX region is too small for provided number of blocks"); \
1442-
BUILD_ASSERT((GET_BLOCK_SIZE_INST(i, rx, tx) >= GET_CACHE_ALIGNMENT(i)) && \
1447+
BUILD_ASSERT((GET_BLOCK_SIZE_INST(i, rx, tx) >= BLOCK_ALIGNMENT) && \
14431448
(GET_BLOCK_SIZE_INST(i, rx, tx) < \
14441449
GET_MEM_SIZE_INST(i, rx)), \
14451450
"RX region is too small for provided number of blocks"); \

0 commit comments

Comments
 (0)