Skip to content

Commit

Permalink
drivers: wifi: Create dedicated mem pool for Wi-Fi driver
Browse files Browse the repository at this point in the history
Create dedicated memory pools for Wi-Fi management and
data operations (defaults: 20KB for management and 60KB for data).

Reduce the heap memory pool size since the Wi-Fi driver will
be allocating memory from a dedicated pool.

Signed-off-by: Ravi Dondaputi <[email protected]>
  • Loading branch information
rado17 committed Jul 24, 2024
1 parent 796c553 commit 11ebac8
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 6 deletions.
8 changes: 8 additions & 0 deletions drivers/wifi/nrf700x/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,14 @@ if NETWORKING
config HEAP_MEM_POOL_SIZE
default 153000

config NRF_WIFI_CONFIG_HEAP_MEM_POOL_SIZE
int "Dedicated memory pool for configuration"
default 20480

config NRF_WIFI_DATA_HEAP_MEM_POOL_SIZE
int "Dedicated memory pool for data plane"
default 61440

config SYSTEM_WORKQUEUE_STACK_SIZE
default 4096

Expand Down
69 changes: 66 additions & 3 deletions drivers/wifi/nrf700x/src/shim.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <zephyr/drivers/gpio.h>
#include <zephyr/logging/log.h>
#include <zephyr/sys/__assert.h>
#include <zephyr/sys/math_extras.h>

#include "rpu_hw_if.h"
#include "shim.h"
Expand All @@ -27,19 +28,79 @@
#include "qspi_if.h"

LOG_MODULE_REGISTER(wifi_nrf, CONFIG_WIFI_NRF700X_LOG_LEVEL);
#if defined(CONFIG_NOCACHE_MEMORY)
K_HEAP_DEFINE_NOCACHE(wifi_drv_ctrl_mem_pool, CONFIG_NRF_WIFI_CONFIG_HEAP_MEM_POOL_SIZE);
K_HEAP_DEFINE_NOCACHE(wifi_drv_data_mem_pool, CONFIG_NRF_WIFI_DATA_HEAP_MEM_POOL_SIZE);
#else
K_HEAP_DEFINE(wifi_drv_ctrl_mem_pool, CONFIG_NRF_WIFI_CONFIG_HEAP_MEM_POOL_SIZE);
K_HEAP_DEFINE(wifi_drv_data_mem_pool, CONFIG_NRF_WIFI_DATA_HEAP_MEM_POOL_SIZE);
#endif /* CONFIG_NOCACHE_MEMORY */
#define WORD_SIZE 4

struct zep_shim_intr_priv *intr_priv;

static void *zep_shim_mem_alloc(size_t size)
{
size = (size + 4) & 0xfffffffc;
return k_malloc(size);
return k_heap_aligned_alloc(&wifi_drv_ctrl_mem_pool, WORD_SIZE, size, K_FOREVER);
}

static void *zep_shim_data_mem_alloc(size_t size)
{
size = (size + 4) & 0xfffffffc;
return k_heap_aligned_alloc(&wifi_drv_data_mem_pool, WORD_SIZE, size, K_FOREVER);
}

static void *zep_shim_mem_zalloc(size_t size)
{
void *ret;
size_t bounds;

size = (size + 4) & 0xfffffffc;

if (size_mul_overflow(size, sizeof(char), &bounds)) {
return NULL;
}

ret = zep_shim_mem_alloc(bounds);
if (ret != NULL) {
(void)memset(ret, 0, bounds);
}

return ret;
}

static void *zep_shim_data_mem_zalloc(size_t size)
{
void *ret;
size_t bounds;

size = (size + 4) & 0xfffffffc;
return k_calloc(size, sizeof(char));

if (size_mul_overflow(size, sizeof(char), &bounds)) {
return NULL;
}

ret = zep_shim_data_mem_alloc(bounds);
if (ret != NULL) {
(void)memset(ret, 0, bounds);
}

return ret;
}

static void zep_shim_mem_free(void *buf)
{
if (buf) {
k_heap_free(&wifi_drv_ctrl_mem_pool, buf);
}
}

static void zep_shim_data_mem_free(void *buf)
{
if (buf) {
k_heap_free(&wifi_drv_data_mem_pool, buf);
}
}

static void *zep_shim_mem_cpy(void *dest, const void *src, size_t count)
Expand Down Expand Up @@ -884,7 +945,9 @@ static unsigned int zep_shim_strlen(const void *str)
static const struct nrf_wifi_osal_ops nrf_wifi_os_zep_ops = {
.mem_alloc = zep_shim_mem_alloc,
.mem_zalloc = zep_shim_mem_zalloc,
.mem_free = k_free,
.data_mem_zalloc = zep_shim_data_mem_zalloc,
.mem_free = zep_shim_mem_free,
.data_mem_free = zep_shim_data_mem_free,
.mem_cpy = zep_shim_mem_cpy,
.mem_set = zep_shim_mem_set,
.mem_cmp = zep_shim_mem_cmp,
Expand Down
2 changes: 1 addition & 1 deletion samples/wifi/shell/overlay-zperf.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ CONFIG_NET_PKT_RX_COUNT=30
CONFIG_NET_PKT_TX_COUNT=29
CONFIG_NET_BUF_RX_COUNT=30
CONFIG_NET_BUF_TX_COUNT=58
CONFIG_HEAP_MEM_POOL_SIZE=230000
#CONFIG_HEAP_MEM_POOL_SIZE=140000
CONFIG_NET_BUF_DATA_SIZE=1100
CONFIG_NRF700X_QSPI_LOW_POWER=n
# To enable optimization configuration options
Expand Down
4 changes: 2 additions & 2 deletions samples/wifi/shell/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ CONFIG_NET_PKT_TX_COUNT=8
# tuned for performance, but this will be revisited in the future.
CONFIG_NET_BUF_RX_COUNT=16
CONFIG_NET_BUF_TX_COUNT=16
CONFIG_NET_BUF_DATA_SIZE=128
CONFIG_NET_BUF_DATA_SIZE=1500
CONFIG_NRF700X_RX_NUM_BUFS=16
CONFIG_NRF700X_MAX_TX_AGGREGATION=4
# nRF700x is main consumer: (16 + 8) * 1600 = ~40KB + ~40KB control path (experimental)
CONFIG_HEAP_MEM_POOL_SIZE=80000
CONFIG_HEAP_MEM_POOL_SIZE=65000
CONFIG_NET_TC_TX_COUNT=1

CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=4
Expand Down

0 comments on commit 11ebac8

Please sign in to comment.