ERTM local busy enhancement
Subsystems (2)
v3 cover ERTM local busy enhancement
These patches change receiver-side handling of flow control. This new approach will not keep very much incoming data beyond what fits in the socket receive buffer, so memory use is more tightly controlled. When incoming data does not immediately fit in the socket buffer, the L2CAP socket layer will now only check for available space when the socket is read from instead of polling on a workqueue thread.
Mat Martineau (3):
Bluetooth: Move code for ERTM local busy state to separate functions
Bluetooth: Use event-driven approach for handling ERTM receive buffer
Bluetooth: Remove L2CAP busy queue
include/net/bluetooth/l2cap.h | 6 +- net/bluetooth/l2cap_core.c | 174 +++++++++++------------------------------ net/bluetooth/l2cap_sock.c | 65 ++++++++++++++- 3 files changed, 108 insertions(+), 137 deletions(-)
Signature · 6 lines
1.7.6 -- Mat Martineau Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum
PATCH v3 1/3 Bluetooth: Move code for ERTM local busy state to separate functions
The local busy state is entered and exited based on buffer status in the socket layer (or other upper layer). This change is in preparation for general buffer status reports from the socket layer, which will then be used to change the local busy status.
--- net/bluetooth/l2cap_core.c | 62 +++++++++++++++++++++++++++----------------- 1 files changed, 38 insertions(+), 24 deletions(-)
net/bluetooth/l2cap_core.c +38 -24
@@ -3227,22 +3227,26 @@ disconnect:return 0 ; } -static int l2cap_try_push_rx_skb (struct l2cap_chan *chan) +static void l2cap_ertm_enter_local_busy (struct l2cap_chan *chan) { -struct sk_buff *skb;u16 control; -int err; -while ((skb =skb_dequeue (&chan->busy_q))) { - control =bt_cb (skb)->sar <<L2CAP_CTRL_SAR_SHIFT ; - err =l2cap_ertm_reassembly_sdu (chan, skb, control); -if (err <0 ) { -skb_queue_head (&chan->busy_q, skb); -return -EBUSY ; - } +BT_DBG ("chan %p, Enter local busy" , chan); - chan->buffer_seq = (chan->buffer_seq +1 ) %64 ; - } +set_bit (CONN_LOCAL_BUSY , &chan->conn_state); + + control = chan->buffer_seq <<L2CAP_CTRL_REQSEQ_SHIFT ; + control |=L2CAP_SUPER_RCV_NOT_READY ; +l2cap_send_sframe (chan, control); + +set_bit (CONN_RNR_SENT , &chan->conn_state); + +__clear_ack_timer (chan); +} + +static void l2cap_ertm_exit_local_busy (struct l2cap_chan *chan) +{ +u16 control;if (!test_bit (CONN_RNR_SENT , &chan->conn_state)) goto done;
@@ -3262,6 +3266,26 @@ done:clear_bit (CONN_RNR_SENT , &chan->conn_state);BT_DBG ("chan %p, Exit local busy" , chan); +} + +static int l2cap_try_push_rx_skb (struct l2cap_chan *chan) +{ +struct sk_buff *skb; +u16 control; +int err; + +while ((skb =skb_dequeue (&chan->busy_q))) { + control =bt_cb (skb)->sar <<L2CAP_CTRL_SAR_SHIFT ; + err =l2cap_ertm_reassembly_sdu (chan, skb, control); +if (err <0 ) { +skb_queue_head (&chan->busy_q, skb); +return -EBUSY ; + } + + chan->buffer_seq = (chan->buffer_seq +1 ) %64 ; + } + +l2cap_ertm_exit_local_busy (chan);return 0 ; }
@@ -3315,7 +3339,7 @@ static void l2cap_busy_work(struct work_struct *work)static int l2cap_push_rx_skb (struct l2cap_chan *chan,struct sk_buff *skb,u16 control) { -int sctrl, err; +int err;if (test_bit (CONN_LOCAL_BUSY , &chan->conn_state)) {bt_cb (skb)->sar = control >>L2CAP_CTRL_SAR_SHIFT ;
@@ -3331,21 +3355,11 @@ static int l2cap_push_rx_skb(struct l2cap_chan *chan, struct sk_buff *skb, u16 creturn err; } -/* Busy Condition */ -BT_DBG ("chan %p, Enter local busy" , chan); +l2cap_ertm_enter_local_busy (chan); -set_bit (CONN_LOCAL_BUSY , &chan->conn_state);bt_cb (skb)->sar = control >>L2CAP_CTRL_SAR_SHIFT ;__skb_queue_tail (&chan->busy_q, skb); - sctrl = chan->buffer_seq <<L2CAP_CTRL_REQSEQ_SHIFT ; - sctrl |=L2CAP_SUPER_RCV_NOT_READY ; -l2cap_send_sframe (chan, sctrl); - -set_bit (CONN_RNR_SENT , &chan->conn_state); - -__clear_ack_timer (chan); -queue_work (_busy_wq, &chan->busy_work);return err;
Signature · 6 lines
1.7.6 -- Mat Martineau Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum
PATCH v3 2/3 Bluetooth: Use event-driven approach for handling ERTM receive buffer
In reply to Mat MartineauThis change moves most L2CAP ERTM receive buffer handling out of the L2CAP core and in to the socket code. It's up to the higher layer (the socket code, in this case) to tell the core when its buffer is full or has space available. The recv op should always accept incoming ERTM data or else the connection will go down.
Within the socket layer, an skb that does not fit in the socket receive buffer will be temporarily stored. When the socket is read from, that skb will be placed in the receive buffer if possible. Once adequate buffer space becomes available, the L2CAP core is informed and the ERTM local busy state is cleared.
Receive buffer management for non-ERTM modes is unchanged.
--- include/net/bluetooth/l2cap.h | 2 + net/bluetooth/l2cap_core.c | 41 ++++++++++++++++--------- net/bluetooth/l2cap_sock.c | 65 ++++++++++++++++++++++++++++++++++++++-- 3 files changed, 89 insertions(+), 19 deletions(-)
include/net/bluetooth/l2cap.h +2 -0
@@ -422,6 +422,7 @@ struct l2cap_conn {struct l2cap_pinfo {struct bt_sock bt;struct l2cap_chan *chan; +struct sk_buff *rx_busy_skb; };enum {
@@ -498,5 +499,6 @@ void l2cap_chan_close(struct l2cap_chan *chan, int reason);void l2cap_chan_destroy (struct l2cap_chan *chan);int l2cap_chan_connect (struct l2cap_chan *chan);int l2cap_chan_send (struct l2cap_chan *chan,struct msghdr *msg,size_t len); +void l2cap_chan_busy (struct l2cap_chan *chan,int busy);#endif /* __L2CAP_H */
net/bluetooth/l2cap_core.c +26 -15
68 lines not on this page · raw message
net/bluetooth/l2cap_sock.c +61 -4
98 lines not on this page · raw message
Signature · 6 lines
1.7.6 -- Mat Martineau Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum
PATCH v3 3/3 Bluetooth: Remove L2CAP busy queue
In reply to Mat MartineauThe ERTM receive buffer is now handled in a way that does not require the busy queue and the associated polling code.
--- include/net/bluetooth/l2cap.h | 4 - net/bluetooth/l2cap_core.c | 125 +++-------------------------------------- 2 files changed, 8 insertions(+), 121 deletions(-)
include/net/bluetooth/l2cap.h +0 -4
@@ -37,7 +37,6 @@#define L2CAP_DEFAULT_MONITOR_TO 12000/* 12 seconds */ #define L2CAP_DEFAULT_MAX_PDU_SIZE 1009/* Sized for 3-DH5 packet */ #define L2CAP_DEFAULT_ACK_TO 200 -#define L2CAP_LOCAL_BUSY_TRIES 12#define L2CAP_LE_DEFAULT_MTU 23#define L2CAP_CONN_TIMEOUT (40000)/* 40 seconds */
@@ -352,8 +351,6 @@ struct l2cap_chan {struct sk_buff *tx_send_head;struct sk_buff_head tx_q;struct sk_buff_head srej_q; -struct sk_buff_head busy_q; -struct work_struct busy_work;struct list_head srej_l;struct list_head list;
@@ -450,7 +447,6 @@ enum {CONN_REJ_ACT ,CONN_SEND_FBIT , CONN_RNR_SENT, - CONN_SAR_RETRY, };#define __set_chan_timer (c, t) l2cap_set_timer(c, &c->chan_timer, (t))
net/bluetooth/l2cap_core.c +8 -117
206 lines not on this page · raw message
Signature · 6 lines
1.7.6 -- Mat Martineau Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum
Re: [PATCH v3 3/3] Bluetooth: Remove L2CAP busy queue
Quoted 8 lines · Mat Martineau
The ERTM receive buffer is now handled in a way that does not require the busy queue and the associated polling code.
Signed-off-by Mat Martineau <[email protected]>--- include/net/bluetooth/l2cap.h | 4 - net/bluetooth/l2cap_core.c | 125 +++-------------------------------------- 2 files changed, 8 insertions(+), 121 deletions(-)
All 3 patches applied, thanks.
Gustavo