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

Creating dedicated memory pools for data and control traffic #78588

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions drivers/wifi/nrfwifi/Kconfig.nrfwifi
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,15 @@ config NRF70_RSSI_STALE_TIMEOUT_MS

if NETWORKING
# Finetune defaults for certain system components used by the driver

config NRF_WIFI_CTRL_HEAP_SIZE
Copy link
Collaborator

@krish2718 krish2718 Sep 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in order to leverage the newly added per-module HEAP hints, may be we should use HEAP_MEM_POOL_ADD_SIZE_NRF70_CTRL and HEAP_MEM_POOL_ADD_SIZE_NRF70_DATA, this way there won't be any changes to the samples/applications. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are creating a separate pool for each of the control path and data path, and not allocating from system heap. Since HEAP_MEM_POOL_ADD_SIZE_* is used just as a hint to verify the available system heap, using this name convention here may not be appropriate.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, then existing HEAP_MEM_POOL_ADD_SIZE_ have to be removed or reduced, no? And then for NRF_WIFI_DATA_HEAP_SIZE needs to be adjusted per-sample as per the network buffer configuration?

int "Dedicated memory pool for control path"
default 20480

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

config SYSTEM_WORKQUEUE_STACK_SIZE
default 4096

Expand Down
71 changes: 66 additions & 5 deletions drivers/wifi/nrfwifi/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,21 +28,79 @@
#include "qspi_if.h"

LOG_MODULE_REGISTER(wifi_nrf, CONFIG_WIFI_NRF70_LOG_LEVEL);
#if defined(CONFIG_NOCACHE_MEMORY)
K_HEAP_DEFINE_NOCACHE(wifi_drv_ctrl_mem_pool, CONFIG_NRF_WIFI_CTRL_HEAP_SIZE);
K_HEAP_DEFINE_NOCACHE(wifi_drv_data_mem_pool, CONFIG_NRF_WIFI_DATA_HEAP_SIZE);
#else
K_HEAP_DEFINE(wifi_drv_ctrl_mem_pool, CONFIG_NRF_WIFI_CTRL_HEAP_SIZE);
K_HEAP_DEFINE(wifi_drv_data_mem_pool, CONFIG_NRF_WIFI_DATA_HEAP_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_t size_aligned = ROUND_UP(size, 4);
size = (size + 4) & 0xfffffffc;
return k_heap_aligned_alloc(&wifi_drv_ctrl_mem_pool, WORD_SIZE, size, K_FOREVER);
}

return k_malloc(size_aligned);
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)
{
size_t size_aligned = ROUND_UP(size, 4);
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;

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);
}
}

return k_calloc(size_aligned, sizeof(char));
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 @@ -877,7 +936,9 @@ static unsigned int zep_shim_strlen(const void *str)
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 west.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ manifest:
groups:
- hal
- name: hal_nordic
revision: af7b21c4f875bea26689307daa8e52e9a8e8323c
revision: pull/213/head
path: modules/hal/nordic
groups:
- hal
Expand Down
Loading