zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.61k stars 6.5k forks source link

Serial: Bluetooth: Increase Throughput by tracking run-time ATT MTU Size #72018

Closed ubieda closed 2 weeks ago

ubieda commented 5 months ago

Is your enhancement proposal related to a problem? Please describe. The UART over Bluetooth LE (NUS) currently fragments TX data in chunks of 20-bytes per Bluetooth notification. This is done since the maximum payload we can put through a single packet, assuming minimum ATT MTU size (MTU - 3). This, however, represents a throughput bottleneck and limits its usability (Simple but limited).

Describe the solution you'd like Split data in chunks of the maximum possible payload-per-packet (min_current_mtu - 3), where the min_current_mtu is the minimum MTU of all the peers currently connected. e.g:

        chunk_size = get_max_payload_packet_size();
        len = ring_buf_get_claim(dev_data->uart.tx_ringbuf, &data, chunk_size);
        if (len > 0) {
            err = bt_nus_inst_send(NULL, dev_data->bt.inst, data, len);
            if (err) {
                LOG_ERR("Failed to send data over BT: %d", err);
            }
        }

Describe alternatives you've considered No additional alternatives.

Additional context To achieve so, uart_bt.c needs to have run-time awareness of all connected peers and their MTU size at all times.

ubieda commented 5 months ago

@jori-nordic @alwa-nordic @jhedberg LMK if you have any inputs on this!

jhedberg commented 5 months ago

@ubieda sounds like a good potential improvement to me