mirror of
https://github.com/espressif/esp-idf.git
synced 2026-04-27 19:13:21 +00:00
feat(ble_log): define multi-buffer transport types and Kconfig
Replace ping-pong (2-buffer) transport constants with configurable multi-buffer (4-buffer) types. Add buffer utilization reporting types, unified queue depth derivation macros, and compile-time guards. Rename Kconfig options to total-per-LBM semantics: - BLE_LOG_LBM_TRANS_SIZE (512) -> BLE_LOG_LBM_TRANS_BUF_SIZE (2048) - BLE_LOG_LBM_LL_TRANS_SIZE (1024) -> BLE_LOG_LBM_LL_TRANS_BUF_SIZE (2048) Key type changes: - ble_log_prph_trans_t: volatile bool -> plain bool (atomic ops used), add void *owner back-reference - ble_log_lbm_t: trans array sized to BLE_LOG_TRANS_BUF_CNT (4), add trans_inflight and trans_inflight_peak counters - BLE_LOG_TRANS_BUF_CNT replaces BLE_LOG_TRANS_PING_PONG_BUF_CNT - New ble_log_buf_util_t for buffer utilization telemetry - _Static_assert guards for divisibility, power-of-2, index limits
This commit is contained in:
@@ -13,15 +13,22 @@ if BLE_LOG_ENABLED
|
||||
help
|
||||
Stack size for BLE Log Task
|
||||
|
||||
config BLE_LOG_LBM_TRANS_SIZE
|
||||
int "Buffer size for each peripheral transport"
|
||||
default 512
|
||||
config BLE_LOG_LBM_TRANS_BUF_SIZE
|
||||
int "Total buffer memory per common LBM (bytes)"
|
||||
default 2048
|
||||
help
|
||||
There're 2 log buffer managers (LBMs) with compare-and-swap
|
||||
(CAS) protection, 1 LBM with FreeRTOS mutex protection, 1 LBM
|
||||
without protection for critical section. Each LBM is managing
|
||||
2 ping-pong buffers, which means there will be 4 * 2 *
|
||||
BLE_LOG_LBM_TRANS_SIZE bytes buffer allocated
|
||||
Total buffer memory allocated for each common pool log buffer
|
||||
manager (LBM). This memory is divided equally among internal
|
||||
transport buffers. Must be a multiple of BLE_LOG_TRANS_BUF_CNT
|
||||
(currently 4).
|
||||
|
||||
The common pool contains:
|
||||
- BLE_LOG_LBM_ATOMIC_LOCK_TASK_CNT atomic LBMs (task context)
|
||||
- BLE_LOG_LBM_ATOMIC_LOCK_ISR_CNT atomic LBMs (ISR context)
|
||||
- 2 spinlock-protected LBMs (one for task, one for ISR fallback)
|
||||
|
||||
Total common pool memory:
|
||||
(ATOMIC_TASK_CNT + ATOMIC_ISR_CNT + 2) * BLE_LOG_LBM_TRANS_BUF_SIZE
|
||||
|
||||
config BLE_LOG_LBM_ATOMIC_LOCK_TASK_CNT
|
||||
int "Count of log buffer managers with atomic lock protection for task context"
|
||||
@@ -70,14 +77,21 @@ if BLE_LOG_ENABLED
|
||||
Enable BLE Log for Link Layer
|
||||
|
||||
if BLE_LOG_LL_ENABLED
|
||||
config BLE_LOG_LBM_LL_TRANS_SIZE
|
||||
int "Buffer size for each peripheral transport of Link Layer LBM"
|
||||
default 1024
|
||||
config BLE_LOG_LBM_LL_TRANS_BUF_SIZE
|
||||
int "Total buffer memory per Link Layer LBM (bytes)"
|
||||
default 2048
|
||||
help
|
||||
There're 2 Link Layer dedicated log buffer managers (LBMs) with
|
||||
compare-and-swap (CAS) protection. Each LBM is managing 2 ping-
|
||||
pong buffers, which means there will be additional 2 * 2 *
|
||||
BLE_LOG_LBM_LL_TRANS_SIZE bytes buffer allocated
|
||||
Total buffer memory allocated for each Link Layer dedicated
|
||||
log buffer manager (LBM). This memory is divided equally among
|
||||
internal transport buffers. Must be a multiple of
|
||||
BLE_LOG_TRANS_BUF_CNT (currently 4).
|
||||
|
||||
There are 2 Link Layer LBMs without lock protection (each is
|
||||
accessed from a single context only):
|
||||
- LL task LBM (Link Layer task context logs)
|
||||
- LL HCI LBM (Link Layer HCI context logs)
|
||||
|
||||
Total LL pool memory: 2 * BLE_LOG_LBM_LL_TRANS_BUF_SIZE
|
||||
|
||||
config BLE_LOG_LL_HCI_LOG_PAYLOAD_LEN_LIMIT_ENABLED
|
||||
bool "Enable LL HCI Log Payload Length Limit"
|
||||
|
||||
@@ -49,7 +49,7 @@ typedef enum {
|
||||
|
||||
typedef struct {
|
||||
int trans_idx;
|
||||
ble_log_prph_trans_t *trans[BLE_LOG_TRANS_PING_PONG_BUF_CNT];
|
||||
ble_log_prph_trans_t *trans[BLE_LOG_TRANS_BUF_CNT];
|
||||
ble_log_lbm_lock_t lock_type;
|
||||
union {
|
||||
/* BLE_LOG_LBM_LOCK_NONE */
|
||||
@@ -61,6 +61,8 @@ typedef struct {
|
||||
/* BLE_LOG_LBM_LOCK_MUTEX */
|
||||
SemaphoreHandle_t mutex;
|
||||
};
|
||||
uint32_t trans_inflight;
|
||||
uint32_t trans_inflight_peak;
|
||||
} ble_log_lbm_t;
|
||||
|
||||
/* --------------------------------------- */
|
||||
@@ -86,7 +88,19 @@ enum {
|
||||
BLE_LOG_LBM_ATOMIC_ISR_CNT)
|
||||
#define BLE_LOG_LBM_COMMON_CNT (BLE_LOG_LBM_ATOMIC_CNT + BLE_LOG_LBM_SPIN_MAX)
|
||||
#define BLE_LOG_LBM_CNT (BLE_LOG_LBM_COMMON_CNT + BLE_LOG_LBM_LL_MAX)
|
||||
#define BLE_LOG_TRANS_CNT (BLE_LOG_LBM_CNT * BLE_LOG_TRANS_PING_PONG_BUF_CNT)
|
||||
|
||||
/* Derived per-buffer size from user-configured total-per-LBM budget */
|
||||
#define BLE_LOG_TRANS_SIZE (CONFIG_BLE_LOG_LBM_TRANS_BUF_SIZE / BLE_LOG_TRANS_BUF_CNT)
|
||||
#define BLE_LOG_TRANS_LL_SIZE (CONFIG_BLE_LOG_LBM_LL_TRANS_BUF_SIZE / BLE_LOG_TRANS_BUF_CNT)
|
||||
|
||||
/* Unified queue depth derivation */
|
||||
#define BLE_LOG_TRANS_POOL_CNT (BLE_LOG_LBM_CNT * BLE_LOG_TRANS_BUF_CNT)
|
||||
#if BLE_LOG_UART_REDIR_ENABLED
|
||||
#define BLE_LOG_TRANS_REDIR_CNT BLE_LOG_TRANS_BUF_CNT
|
||||
#else
|
||||
#define BLE_LOG_TRANS_REDIR_CNT (0)
|
||||
#endif
|
||||
#define BLE_LOG_TRANS_TOTAL_CNT (BLE_LOG_TRANS_POOL_CNT + BLE_LOG_TRANS_REDIR_CNT)
|
||||
|
||||
/* ------------------------------------------ */
|
||||
/* Log Buffer Manager Context Defines */
|
||||
@@ -127,6 +141,27 @@ typedef struct {
|
||||
};
|
||||
} ble_log_lbm_ctx_t;
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* Buffer Utilization Reporting Defines */
|
||||
/* -------------------------------------------- */
|
||||
typedef enum {
|
||||
BLE_LOG_BUF_UTIL_POOL_COMMON_TASK = 0,
|
||||
BLE_LOG_BUF_UTIL_POOL_COMMON_ISR = 1,
|
||||
BLE_LOG_BUF_UTIL_POOL_LL = 2,
|
||||
BLE_LOG_BUF_UTIL_POOL_REDIR = 3,
|
||||
} ble_log_buf_util_pool_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t int_src_code;
|
||||
uint8_t lbm_id;
|
||||
uint8_t trans_cnt;
|
||||
uint8_t inflight_peak;
|
||||
} __attribute__((packed)) ble_log_buf_util_t;
|
||||
|
||||
#define BLE_LOG_BUF_UTIL_MAKE_ID(pool, idx) (((pool) << 4) | ((idx) & 0x0F))
|
||||
#define BLE_LOG_BUF_UTIL_GET_POOL(id) (((id) >> 4) & 0x0F)
|
||||
#define BLE_LOG_BUF_UTIL_GET_INDEX(id) ((id) & 0x0F)
|
||||
|
||||
/* ---------------------------------------- */
|
||||
/* Enhanced Statistics Data Defines */
|
||||
/* ---------------------------------------- */
|
||||
@@ -174,6 +209,26 @@ enum {
|
||||
};
|
||||
#endif /* CONFIG_BLE_LOG_LL_ENABLED */
|
||||
|
||||
/* ------------------------------- */
|
||||
/* Compile-Time Guards */
|
||||
/* ------------------------------- */
|
||||
_Static_assert(CONFIG_BLE_LOG_LBM_TRANS_BUF_SIZE % BLE_LOG_TRANS_BUF_CNT == 0,
|
||||
"Common LBM total buffer size must be a multiple of BLE_LOG_TRANS_BUF_CNT (4)");
|
||||
#if CONFIG_BLE_LOG_LL_ENABLED
|
||||
_Static_assert(CONFIG_BLE_LOG_LBM_LL_TRANS_BUF_SIZE % BLE_LOG_TRANS_BUF_CNT == 0,
|
||||
"LL LBM total buffer size must be a multiple of BLE_LOG_TRANS_BUF_CNT (4)");
|
||||
#endif
|
||||
_Static_assert(CONFIG_BLE_LOG_LBM_TRANS_BUF_SIZE / BLE_LOG_TRANS_BUF_CNT >= BLE_LOG_FRAME_OVERHEAD,
|
||||
"Common LBM per-buffer size too small for a single frame");
|
||||
_Static_assert((BLE_LOG_TRANS_BUF_CNT & (BLE_LOG_TRANS_BUF_CNT - 1)) == 0,
|
||||
"BLE_LOG_TRANS_BUF_CNT must be a power of 2");
|
||||
_Static_assert(1 + BLE_LOG_LBM_ATOMIC_TASK_CNT <= 16,
|
||||
"Common task pool exceeds lbm_id 4-bit index limit (max 15)");
|
||||
_Static_assert(1 + BLE_LOG_LBM_ATOMIC_ISR_CNT <= 16,
|
||||
"Common ISR pool exceeds lbm_id 4-bit index limit (max 15)");
|
||||
_Static_assert(BLE_LOG_TRANS_BUF_CNT <= 255,
|
||||
"BLE_LOG_TRANS_BUF_CNT must fit in uint8_t for ble_log_buf_util_t");
|
||||
|
||||
/* --------------------------- */
|
||||
/* Internal Interfaces */
|
||||
/* --------------------------- */
|
||||
@@ -181,10 +236,12 @@ bool ble_log_lbm_init(void);
|
||||
void ble_log_lbm_deinit(void);
|
||||
void ble_log_lbm_enable(bool enable);
|
||||
void ble_log_write_enh_stat(void);
|
||||
void ble_log_write_buf_util(void);
|
||||
#if BLE_LOG_UART_REDIR_ENABLED
|
||||
void ble_log_lbm_stream_write(ble_log_lbm_t *lbm, ble_log_src_t src_code,
|
||||
const uint8_t *data, size_t len);
|
||||
void ble_log_lbm_stream_flush(ble_log_lbm_t *lbm, ble_log_src_t src_code);
|
||||
ble_log_lbm_t *ble_log_prph_get_redir_lbm(void);
|
||||
#endif
|
||||
|
||||
#endif /* __BLE_LOG_LBM_H__ */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -15,17 +15,20 @@
|
||||
|
||||
/* TYPEDEF */
|
||||
typedef struct {
|
||||
volatile bool prph_owned;
|
||||
bool prph_owned;
|
||||
uint8_t *buf;
|
||||
uint16_t size;
|
||||
uint16_t pos;
|
||||
|
||||
/* Peripheral implementation specific context */
|
||||
void *ctx;
|
||||
|
||||
/* Opaque back-reference to owning LBM, set once at init */
|
||||
void *owner;
|
||||
} ble_log_prph_trans_t;
|
||||
|
||||
#define BLE_LOG_TRANS_FREE_SPACE(trans) (trans->size - trans->pos)
|
||||
#define BLE_LOG_TRANS_PING_PONG_BUF_CNT (2)
|
||||
#define BLE_LOG_TRANS_BUF_CNT (4)
|
||||
|
||||
/* INTERFACE */
|
||||
bool ble_log_prph_init(size_t trans_cnt);
|
||||
@@ -33,5 +36,6 @@ void ble_log_prph_deinit(void);
|
||||
bool ble_log_prph_trans_init(ble_log_prph_trans_t **trans, size_t trans_size);
|
||||
void ble_log_prph_trans_deinit(ble_log_prph_trans_t **trans);
|
||||
void ble_log_prph_send_trans(ble_log_prph_trans_t *trans);
|
||||
void ble_log_prph_reset_util_counters(void);
|
||||
|
||||
#endif /* __BLE_LOG_PRPH_H__ */
|
||||
|
||||
@@ -139,6 +139,7 @@ typedef enum {
|
||||
BLE_LOG_INT_SRC_ENH_STAT,
|
||||
BLE_LOG_INT_SRC_INFO,
|
||||
BLE_LOG_INT_SRC_FLUSH,
|
||||
BLE_LOG_INT_SRC_BUF_UTIL,
|
||||
BLE_LOG_INT_SRC_MAX,
|
||||
} ble_log_int_src_t;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user