component/bt: add simple ADV flow control mechanism -- drop the packets when the adv report queues are considered full

pull/9485/head
wangmengyang 2022-07-18 15:53:08 +08:00
rodzic 9a5f854760
commit 0a1fa3e204
3 zmienionych plików z 23 dodań i 1 usunięć

Wyświetl plik

@ -51,6 +51,8 @@ static uint16_t btc_adv_list_count = 0;
#endif
#define BTC_GAP_BLE_ADV_RPT_QUEUE_IDX (1)
#define BTC_GAP_BLE_ADV_RPT_BATCH_SIZE (10)
#define BTC_GAP_BLE_ADV_RPT_QUEUE_LEN_MAX (200)
#if (BLE_42_FEATURE_SUPPORT == TRUE)
typedef struct {
@ -565,6 +567,9 @@ static void btc_gap_ble_adv_pkt_handler(void *arg)
{
btc_gap_ble_env_t *p_env = &btc_gap_ble_env;
size_t pkts_to_process = pkt_queue_length(p_env->adv_rpt_queue);
if (pkts_to_process > BTC_GAP_BLE_ADV_RPT_BATCH_SIZE) {
pkts_to_process = BTC_GAP_BLE_ADV_RPT_BATCH_SIZE;
}
for (size_t i = 0; i < pkts_to_process; i++) {
pkt_linked_item_t *linked_pkt = pkt_queue_dequeue(p_env->adv_rpt_queue);
@ -596,6 +601,12 @@ static void btc_process_adv_rpt_pkt(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_
btc_adv_list_count ++;
#endif
// drop ADV packets if data queue length goes above threshold
btc_gap_ble_env_t *p_env = &btc_gap_ble_env;
if (pkt_queue_length(p_env->adv_rpt_queue) >= BTC_GAP_BLE_ADV_RPT_QUEUE_LEN_MAX) {
return;
}
pkt_linked_item_t *linked_pkt = osi_calloc(BT_PKT_LINKED_HDR_SIZE + sizeof(esp_ble_gap_cb_param_t));
if (linked_pkt == NULL) {
return;
@ -617,7 +628,6 @@ static void btc_process_adv_rpt_pkt(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_
memcpy(scan_rst->ble_adv, p_data->inq_res.p_eir, sizeof(scan_rst->ble_adv));
} while (0);
btc_gap_ble_env_t *p_env = &btc_gap_ble_env;
pkt_queue_enqueue(p_env->adv_rpt_queue, linked_pkt);
osi_thread_post_event(p_env->adv_rpt_ready, OSI_THREAD_MAX_TIMEOUT);
}

Wyświetl plik

@ -40,6 +40,7 @@
#define PACKET_TYPE_TO_INBOUND_INDEX(type) ((type) - 2)
#define PACKET_TYPE_TO_INDEX(type) ((type) - 1)
#define HCI_UPSTREAM_DATA_QUEUE_IDX (1)
#define HCI_HAL_BLE_ADV_RPT_QUEUE_LEN_MAX (200)
extern bool BTU_check_queue_is_congest(void);
@ -407,6 +408,12 @@ static int host_recv_pkt_cb(uint8_t *data, uint16_t len)
memcpy(pkt->data, data, len);
fixed_queue_enqueue(hci_hal_env.rx_q, pkt, FIXED_QUEUE_MAX_TIMEOUT);
} else {
#if !BLE_ADV_REPORT_FLOW_CONTROL
// drop the packets if pkt_queue length goes beyond upper limit
if (pkt_queue_length(hci_hal_env.adv_rpt_q) > HCI_HAL_BLE_ADV_RPT_QUEUE_LEN_MAX) {
return 0;
}
#endif
pkt_size = BT_PKT_LINKED_HDR_SIZE + BT_HDR_SIZE + len;
linked_pkt = (pkt_linked_item_t *) osi_calloc(pkt_size);
if (!linked_pkt) {

Wyświetl plik

@ -57,6 +57,8 @@
#define MIN_ADV_LENGTH 2
#define BTM_VSC_CHIP_CAPABILITY_RSP_LEN_L_RELEASE 9
#define BTM_BLE_GAP_ADV_RPT_BATCH_SIZE (10)
#if BTM_DYNAMIC_MEMORY == FALSE
static tBTM_BLE_VSC_CB cmn_ble_gap_vsc_cb;
#else
@ -3463,6 +3465,9 @@ static void btm_adv_pkt_handler(void *arg)
tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
size_t pkts_to_process = pkt_queue_length(p_cb->adv_rpt_queue);
if (pkts_to_process > BTM_BLE_GAP_ADV_RPT_BATCH_SIZE) {
pkts_to_process = BTM_BLE_GAP_ADV_RPT_BATCH_SIZE;
}
for (size_t i = 0; i < pkts_to_process; i++) {
pkt_linked_item_t *linked_pkt = pkt_queue_dequeue(p_cb->adv_rpt_queue);