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

DNM: Bluetooth: Host: Reproduce no avail acl bufs in ipc driver #84580

Closed
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
11 changes: 10 additions & 1 deletion drivers/bluetooth/hci/ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,22 @@ static struct net_buf *bt_ipc_acl_recv(const uint8_t *data, size_t remaining)
return NULL;
}

buf = bt_buf_get_rx(BT_BUF_ACL_IN, K_NO_WAIT);
k_timeout_t rx_timeout = K_NO_WAIT;
retry:
buf = bt_buf_get_rx(BT_BUF_ACL_IN, rx_timeout);
if (buf) {
memcpy((void *)&hdr, data, sizeof(hdr));
data += sizeof(hdr);
remaining -= sizeof(hdr);

net_buf_add_mem(buf, &hdr, sizeof(hdr));
} else {
if (K_TIMEOUT_EQ(rx_timeout, K_NO_WAIT)) {
LOG_WRN("No available ACL buffers! retrying...");
rx_timeout = K_FOREVER;
goto retry;
}

LOG_ERR("No available ACL buffers!");
return NULL;
}
Expand Down Expand Up @@ -273,6 +281,7 @@ static int bt_ipc_send(const struct device *dev, struct net_buf *buf)
err = ipc_service_send(&data->hci_ept, buf->data, buf->len);
if (err < 0) {
LOG_ERR("Failed to send (err %d)", err);
LOG_ERR("buf %p type %u len %u", buf, bt_buf_get_type(buf), buf->len);
}

done:
Expand Down
14 changes: 14 additions & 0 deletions tests/bsim/bluetooth/host/l2cap/stress/Kconfig.sysbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2023 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0

source "share/sysbuild/Kconfig"

config NET_CORE_BOARD
string
default "nrf5340bsim/nrf5340/cpunet" if $(BOARD_TARGET_STRING) = "NRF5340BSIM_NRF5340_CPUAPP"

config NATIVE_SIMULATOR_PRIMARY_MCU_INDEX
int
# Let's pass the test arguments to the application MCU test
# otherwise by default they would have gone to the net core.
default 0 if $(BOARD_TARGET_STRING) = "NRF5340BSIM_NRF5340_CPUAPP"
18 changes: 18 additions & 0 deletions tests/bsim/bluetooth/host/l2cap/stress/bt_mon.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// /dts-v1/;

// /delete-node/ &uart0;

/ {
chosen {
zephyr,bt-mon-uart = &uart0;
};

/*
uart0: uart {
status = "okay";
compatible = "zephyr,native-tty-uart";
current-speed = <115200>;
serial-port = "/dev/ttyUSB20";
};
*/
};
21 changes: 21 additions & 0 deletions tests/bsim/bluetooth/host/l2cap/stress/compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash
# Copyright 2025 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0

# Compile all the applications needed by the bsim tests in these subfolders

#set -x #uncomment this line for debugging
set -ue
: "${ZEPHYR_BASE:?ZEPHYR_BASE must be set to point to the zephyr root directory}"

export BOARD="nrf5340bsim/nrf5340/cpuapp"
#export BOARD="nrf52_bsim"

source ${ZEPHYR_BASE}/tests/bsim/compile.source

app=tests/bsim/bluetooth/host/l2cap/stress sysbuild=1 \
cmake_extra_args=-DEXTRA_DTC_OVERLAY_FILE=bt_mon.overlay compile
#app=tests/bsim/bluetooth/host/l2cap/stress conf_file=prj_nofrag.conf compile
#app=tests/bsim/bluetooth/host/l2cap/stress conf_file=prj_syswq.conf compile

wait_for_background_jobs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
CONFIG_IPC_SERVICE=y
CONFIG_MBOX=y

CONFIG_ISR_STACK_SIZE=1024
CONFIG_IDLE_STACK_SIZE=256
CONFIG_MAIN_STACK_SIZE=512
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=512
CONFIG_IPC_SERVICE_BACKEND_RPMSG_WQ_STACK_SIZE=512
CONFIG_HEAP_MEM_POOL_SIZE=8192
CONFIG_CBPRINTF_REDUCED_INTEGRAL=y

CONFIG_ISR_TABLES_LOCAL_DECLARATION=y
CONFIG_LTO=y

CONFIG_BT=y
CONFIG_BT_HCI_RAW=y
CONFIG_BT_MAX_CONN=1

# Workaround: Unable to allocate command buffer when using K_NO_WAIT since
# Host number of completed commands does not follow normal flow control.
CONFIG_BT_BUF_CMD_TX_COUNT=60

CONFIG_BT_BUF_ACL_RX_COUNT_EXTRA=60
CONFIG_BT_BUF_EVT_RX_COUNT=61

CONFIG_BT_BUF_ACL_RX_SIZE=255
CONFIG_BT_BUF_ACL_TX_COUNT=60
CONFIG_BT_BUF_ACL_TX_SIZE=255
CONFIG_BT_CTLR_DATA_LENGTH_MAX=251

#CONFIG_BT_BUF_ACL_RX_SIZE=81
#CONFIG_BT_BUF_ACL_TX_COUNT=60
#CONFIG_BT_BUF_ACL_TX_SIZE=27
#CONFIG_BT_CTLR_DATA_LENGTH_MAX=81
CONFIG_BT_CTLR_ADV_DATA_LEN_MAX=191

CONFIG_BT_CTLR_RX_BUFFERS=10

# Host features
CONFIG_BT_EXT_ADV=y

# Controller
CONFIG_BT_LL_SW_SPLIT=y
CONFIG_BT_CTLR_ASSERT_HANDLER=y
#CONFIG_BT_CTLR_DTM_HCI=y

# Advertising Sets and Extended Scanning
CONFIG_BT_CTLR_ADV_EXT=y
CONFIG_BT_CTLR_SCAN_DATA_LEN_MAX=1650

# Increase the below to receive interleaved advertising chains
CONFIG_BT_CTLR_SCAN_AUX_SET=1

CONFIG_BT_CTLR_LLCP_CONN=1

CONFIG_BT_CTLR_ADV_RESERVE_MAX=n
CONFIG_BT_CTLR_CENTRAL_RESERVE_MAX=n
CONFIG_BT_CTLR_SLOT_RESERVATION_UPDATE=n
CONFIG_BT_CTLR_SCAN_UNRESERVED=y

CONFIG_BT_CTLR_LLCP_REMOTE_PROC_CTX_BUF_NUM=1
CONFIG_BT_CTLR_FORCE_MD_COUNT=0
20 changes: 16 additions & 4 deletions tests/bsim/bluetooth/host/l2cap/stress/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ CONFIG_BT_L2CAP_TX_MTU=77
# CONFIG_BT_BUF_ACL_TX_SIZE=81

# L2CAP PDUs will be fragmented in 3 ACL packets.
CONFIG_BT_BUF_ACL_TX_SIZE=27
CONFIG_BT_BUF_ACL_TX_SIZE=255

CONFIG_BT_BUF_ACL_TX_COUNT=4
CONFIG_BT_BUF_ACL_TX_COUNT=60

# The minimum value for this is
# L2AP MPS + L2CAP header (4)
CONFIG_BT_BUF_ACL_RX_SIZE=81
CONFIG_BT_BUF_ACL_RX_SIZE=255

# Governs BT_CONN_TX_MAX, and so must be >= than the max number of
# peers, since we attempt to send one SDU per peer. The test execution
Expand All @@ -41,7 +41,7 @@ CONFIG_BT_L2CAP_TX_BUF_COUNT=6
CONFIG_BT_CTLR_DATA_LENGTH_MAX=27
CONFIG_BT_CTLR_RX_BUFFERS=10

CONFIG_BT_MAX_CONN=10
CONFIG_BT_MAX_CONN=1

CONFIG_LOG=y
CONFIG_ASSERT=y
Expand All @@ -53,3 +53,15 @@ CONFIG_LOG_THREAD_ID_PREFIX=y
CONFIG_THREAD_NAME=y

CONFIG_ARCH_POSIX_TRAP_ON_FATAL=y

CONFIG_BT_SMP_SC_PAIR_ONLY=n

CONFIG_BT_BUF_ACL_RX_COUNT_EXTRA=60

CONFIG_BT_DEBUG_MONITOR_UART=y
#CONFIG_CONSOLE=n
CONFIG_UART_CONSOLE=n
CONFIG_SERIAL=y
#CONFIG_UART_NATIVE_TTY=y
#CONFIG_UART_NATIVE_POSIX=y
CONFIG_NRFX_UARTE0=y
54 changes: 50 additions & 4 deletions tests/bsim/bluetooth/host/l2cap/stress/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,48 @@

#define LOG_MODULE_NAME main
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(LOG_MODULE_NAME, LOG_LEVEL_INF);
LOG_MODULE_REGISTER(LOG_MODULE_NAME, LOG_LEVEL_DBG);

CREATE_FLAG(is_connected);
CREATE_FLAG(flag_l2cap_connected);

#define NUM_PERIPHERALS 6
#define NUM_PERIPHERALS 1
#define L2CAP_CHANS NUM_PERIPHERALS
#define SDU_NUM 20
#define SDU_LEN 3000
#define RESCHEDULE_DELAY K_MSEC(100)

struct bt_conn *default_conn;

static void tx_power_get(struct bt_conn *conn)
{
struct bt_conn_le_tx_power power_level = {0};
int err;

LOG_INF("Reading TX power");

err = bt_conn_le_get_tx_power_level(conn, &power_level);
if (err) {
FAIL("Failed to get tx power level (err %d)", err);
}

LOG_INF("Tx power level: %d", power_level.current_level);
}

static struct k_work_q dut_work_q;
static K_THREAD_STACK_DEFINE(dut_work_stack, 1024);

static void heavy_work_handler(struct k_work *work)
{
LOG_INF("Heavy work started");
k_busy_wait(100 * 1000);
LOG_INF("Heavy work done");

tx_power_get(default_conn);
}

static K_WORK_DEFINE(heavy_work, heavy_work_handler);

static void sdu_destroy(struct net_buf *buf)
{
LOG_DBG("%p", buf);
Expand All @@ -38,12 +69,12 @@ static void rx_destroy(struct net_buf *buf)

/* Only one SDU per link will be transmitted at a time */
NET_BUF_POOL_DEFINE(sdu_tx_pool,
CONFIG_BT_MAX_CONN, BT_L2CAP_SDU_BUF_SIZE(SDU_LEN),
120, BT_L2CAP_SDU_BUF_SIZE(SDU_LEN),
CONFIG_BT_CONN_TX_USER_DATA_SIZE, sdu_destroy);

/* Only one SDU per link will be received at a time */
NET_BUF_POOL_DEFINE(sdu_rx_pool,
CONFIG_BT_MAX_CONN, BT_L2CAP_SDU_BUF_SIZE(SDU_LEN),
120, BT_L2CAP_SDU_BUF_SIZE(SDU_LEN),
8, rx_destroy);

static uint8_t tx_data[SDU_LEN];
Expand Down Expand Up @@ -251,6 +282,8 @@ static void connected(struct bt_conn *conn, uint8_t conn_err)
{
char addr[BT_ADDR_LE_STR_LEN];

default_conn = conn;

bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

if (conn_err) {
Expand Down Expand Up @@ -303,6 +336,11 @@ static void test_peripheral_main(void)
tx_data[i] = (uint8_t)i;
}

k_work_queue_start(&dut_work_q, dut_work_stack,
K_THREAD_STACK_SIZEOF(dut_work_stack),
K_PRIO_COOP(CONFIG_BT_RX_PRIO + 1), NULL);
k_thread_name_set(&dut_work_q.thread, "DUT workq");

err = bt_enable(NULL);
if (err) {
FAIL("Can't enable Bluetooth (err %d)", err);
Expand All @@ -326,6 +364,14 @@ static void test_peripheral_main(void)

LOG_DBG("Registered server PSM %x", psm);

#if 0
k_work_submit_to_queue(&dut_work_q, &heavy_work);
#else
(void)dut_work_q;
k_sleep(K_SECONDS(2));
k_work_submit(&heavy_work);
#endif

LOG_DBG("Peripheral waiting for transfer completion");
while (rx_cnt < SDU_NUM) {
k_msleep(100);
Expand Down
24 changes: 24 additions & 0 deletions tests/bsim/bluetooth/host/l2cap/stress/sysbuild.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (c) 2025 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0

if(NOT("${SB_CONFIG_NET_CORE_BOARD}" STREQUAL ""))
set(NET_APP hci_ipc)
set(NET_APP_SRC_DIR ${ZEPHYR_BASE}/samples/bluetooth/${NET_APP})

ExternalZephyrProject_Add(
APPLICATION ${NET_APP}
SOURCE_DIR ${NET_APP_SRC_DIR}
BOARD ${SB_CONFIG_NET_CORE_BOARD}
)

set(${NET_APP}_CONF_FILE
${ZEPHYR_BASE}/tests/bsim/bluetooth/host/l2cap/stress/nrf5340_cpunet-bt_ll_sw_split.conf
CACHE INTERNAL ""
)

native_simulator_set_primary_mcu_index(${DEFAULT_IMAGE} ${NET_APP})

native_simulator_set_child_images(${DEFAULT_IMAGE} ${NET_APP})
endif()

native_simulator_set_final_executable(${DEFAULT_IMAGE})
12 changes: 1 addition & 11 deletions tests/bsim/bluetooth/host/l2cap/stress/testcase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,10 @@ common:
tags:
- bluetooth
platform_allow:
- nrf52_bsim/native
- nrf5340bsim/nrf5340/cpuapp
harness: bsim

tests:
bluetooth.host.l2cap.stress:
harness_config:
bsim_exe_name: tests_bsim_bluetooth_host_l2cap_stress_prj_conf
bluetooth.host.l2cap.stress_nofrag:
harness_config:
bsim_exe_name: tests_bsim_bluetooth_host_l2cap_stress_prj_nofrag_conf
extra_args:
CONF_FILE=prj_nofrag.conf
bluetooth.host.l2cap.stress_syswq:
harness_config:
bsim_exe_name: tests_bsim_bluetooth_host_l2cap_stress_prj_syswq_conf
extra_args:
CONF_FILE=prj_syswq.conf
24 changes: 16 additions & 8 deletions tests/bsim/bluetooth/host/l2cap/stress/tests_scripts/l2cap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
# Copyright (c) 2022 Nordic Semiconductor
# SPDX-License-Identifier: Apache-2.0

set -x

BOARD="nrf5340bsim/nrf5340/cpuapp"
#BOARD="nrf52_bsim"
source ${ZEPHYR_BASE}/tests/bsim/sh_common.source

# EATT test
Expand All @@ -13,15 +17,19 @@ bsim_exe=./bs_${BOARD_TS}_tests_bsim_bluetooth_host_l2cap_stress_prj_conf

cd ${BSIM_OUT_PATH}/bin

Execute "${bsim_exe}" -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central -rs=43
#ATTACH_CMD=("btmon" "--tty" "%s" "--tty-speed" "115200" "&")
ATTACH_CMD="xterm -e btmon --tty %s --tty-speed 115200 &"

Execute "${bsim_exe}" -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central -rs=43 \
-uart0_pty_attach_cmd="${ATTACH_CMD}" -uart_pty_wait

Execute "${bsim_exe}" -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral -rs=42
Execute "${bsim_exe}" -v=${verbosity_level} -s=${simulation_id} -d=2 -testid=peripheral -rs=10
Execute "${bsim_exe}" -v=${verbosity_level} -s=${simulation_id} -d=3 -testid=peripheral -rs=23
Execute "${bsim_exe}" -v=${verbosity_level} -s=${simulation_id} -d=4 -testid=peripheral -rs=7884
Execute "${bsim_exe}" -v=${verbosity_level} -s=${simulation_id} -d=5 -testid=peripheral -rs=230
Execute "${bsim_exe}" -v=${verbosity_level} -s=${simulation_id} -d=6 -testid=peripheral -rs=9
Execute "${bsim_exe}" -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral -rs=42 #--uart0_pty --uart_pty_wait
#Execute "${bsim_exe}" -v=${verbosity_level} -s=${simulation_id} -d=2 -testid=peripheral -rs=10
#Execute "${bsim_exe}" -v=${verbosity_level} -s=${simulation_id} -d=3 -testid=peripheral -rs=23
#Execute "${bsim_exe}" -v=${verbosity_level} -s=${simulation_id} -d=4 -testid=peripheral -rs=7884
#Execute "${bsim_exe}" -v=${verbosity_level} -s=${simulation_id} -d=5 -testid=peripheral -rs=230
#Execute "${bsim_exe}" -v=${verbosity_level} -s=${simulation_id} -d=6 -testid=peripheral -rs=9

Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} -D=7 -sim_length=400e6 $@
Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} -D=2 -sim_length=400e6 $@

wait_for_background_jobs
Loading
Loading