NRF_MODEM_LIB_MEM_DIAG_ALLOC Kconfig setting needs log but increments the failed allocs (which is not only used for logging statistics but for diagnosis as well).

I am using the SDK v3.4.0 LTS

for modem error debugging I included:

prj.conf

CONFIG_NRF_MODEM_LIB_MEM_DIAG=y

# depends on CONFIG_LOG=y
CONFIG_NRF_MODEM_LIB_MEM_DIAG_ALLOC=y

I am mapping errors depending on wether memory allocations failed.

I am fetching the stats with nrf_modem_lib_diag_stats_get() and checking wether the stats.library.failed_allocs and stats.shmem.failed_allocs have incremented since last check. But these values are always passed as 0 when CONFIG_NRF_MODEM_LIB_MEM_DIAG_ALLOC is not set to =y as the internal counter is only incremented when it the Kconfig is set.

nrf_modem_os.c

void *nrf_modem_os_alloc(size_t bytes)
{
	extern uint32_t nrf_modem_lib_failed_allocs;
	void * const addr = k_heap_alloc(&nrf_modem_lib_heap, bytes, K_NO_WAIT);

	if (IS_ENABLED(CONFIG_NRF_MODEM_LIB_MEM_DIAG_ALLOC) && !addr) {
		nrf_modem_lib_failed_allocs++;
	}

	return addr;
}

void *nrf_modem_os_shm_tx_alloc(size_t bytes)
{
extern uint32_t nrf_modem_lib_shmem_failed_allocs;

#if (CONFIG_SOC_SERIES_NRF92 && CONFIG_DCACHE)
/* Allocate cache line aligned memory. */
void * const addr = k_heap_aligned_alloc(&nrf_modem_lib_shmem_heap, CONFIG_DCACHE_LINE_SIZE,
ROUND_UP(bytes, CONFIG_DCACHE_LINE_SIZE), K_NO_WAIT);
#else
void * const addr = k_heap_alloc(&nrf_modem_lib_shmem_heap, bytes, K_NO_WAIT);
#endif

if (IS_ENABLED(CONFIG_NRF_MODEM_LIB_MEM_DIAG_ALLOC) && !addr) {
nrf_modem_lib_shmem_failed_allocs++;
}

return addr;
}

I have now implemented a workaround so CONFIG_LOG does not have to be used for this to work correctly with a custom Kconfig definition like the following:

Kconfig

config NRF_MODEM_LIB_MEM_DIAG_ALLOC
bool
default y if NRF_MODEM_LIB_MEM_DIAG



I do not understand why NRF_MODEM_LIB_MEM_DIAG_ALLOC depends on LOG, as it not only adds log functionality but also a counts the failed allocations inside the library. It seems like a bug to me that would not report the correct values for failed allocations if NRF_MODEM_LIB_MEM_DIAG_ALLOC is not used (which depends on LOG if not set otherwise like in my workaroung).

Parents Reply Children
No Data
Related