Skip to contentSkip to conversation

RFC: prioritizing data over HCI

PATCH Superseded Luiz Augusto von Dentz 5 participants 26 messages Aug 3, 2011 – Aug 11, 2011

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

cover RFC: prioritizing data over HCI

From: Luiz Augusto von Dentz <[email protected]>

This set of patches uses the priority of the socket, set via SO_PRIORITY, to prioritized data over HCI. Current priority range is from 0-7, where 0-6 priority can be set without any exatra capability which is according to SO_PRIORITY documentation (socket(7)):

SO_PRIORITY

Set the protocol-defined priority for all packets to be sent on this socket. Linux uses this value to order the networking
queues: packets with a higher priority may be processed first depending on the selected device queueing discipline.... Setting a priority outside the range 0 to 6 requires the CAP_NET_ADMIN capability.

This also enables in the future the use of guaranteed channels as it is necessary to prioritized them over best effort (default) channels, Bluetooth V4.0 spec (page 1497):

7.9 PRIORITIZING DATA OVER HCI

In order for guaranteed channels to meet their guarantees, L2CAP should prioritize traffic over the HCI transport in devices that support HCI. Packets for Guaranteed channels should receive higher priority than packets for Best Effort channels.

Note: to be able to use guaranteed channels we need to negotiate QoS parameters both in L2CAP and HCI, this is outside of the scope of this patches since it probably requires new socket options to L2CAP sockets.

The main use case for this is A2DP, many people complained that when they are using their HID devices (mouses) together with headset the mouse has higher priority, which btw is not true since currently there is no priority and connections receives the same quote.

With this changes it may reduce the problem since PulseAudio already sets A2DP socket as low latency (priority 6), which means audio packets will be processed before the HID packets, but this only affects tx and there still exist the problem of some HID not letting us being master.

Ive been testing this using A2DP and HID connected simultaneusly without a problem, though connecting/paging still makes audio skips, and also tried OBEX transfers together to see if audio skips, indeed it does when HID is active but it works better than having no priority (skips less frequent) and in case of using priority 7 the audio doesn't skip anymore but it eventually stall the OBEX transfer (this is maybe because OpenOBEX loop while trying to write to socket and don't wait for POLLOUT).

Luiz Augusto von Dentz (3):
Bluetooth: prioritizing data over HCI
Bluetooth: set skbuffer priority based on L2CAP socket priority
Bluetooth: make use sk_priority to priritize RFCOMM packets

 include/net/bluetooth/hci_core.h |    6 ++-
 include/net/bluetooth/l2cap.h    |    3 +-
 net/bluetooth/hci_conn.c         |    8 ++-
 net/bluetooth/hci_core.c         |  141 +++++++++++++++++++++++++++----------
 net/bluetooth/l2cap_core.c       |   47 +++++++++----
 net/bluetooth/l2cap_sock.c       |    2 +-
 net/bluetooth/rfcomm/core.c      |   51 +++++++++----
 net/bluetooth/rfcomm/sock.c      |    8 ++
 8 files changed, 194 insertions(+), 72 deletions(-)
Signature · 1 line
1.7.6
author maintainer
#1 lore raw

RFC 1/3 Bluetooth: prioritizing data over HCI

From: Luiz Augusto von Dentz <[email protected]>

This implement priority based scheduler using skbuffer priority set via SO_PRIORITY socket option.

It reuses the quote calculation from old scheduler, but the difference is that the number of connections used to calculate the quote is by priority, so the quote may not be devided equally per connection if their priorities are different.

To avoid starvation the priority is recalculated in a round robin fashion so that the remaining queues are upgraded by 1 in priority until HCI_PRIO_MAX - 1 (6).

HCI_PRIO_MAX (7) is considered special, it requires CAP_NET_ADMIN capability and is used to send time critical command/respose for L2CAP and RFCOMM to avoid timeouts, in addition to that it can be used to provide more guaranteed channels but may starve other connections thus need to be used with care.

---
 include/net/bluetooth/hci_core.h |    6 ++-
 net/bluetooth/hci_conn.c         |    8 ++-
 net/bluetooth/hci_core.c         |  141 +++++++++++++++++++++++++++----------
 net/bluetooth/rfcomm/sock.c      |    8 ++
 4 files changed, 122 insertions(+), 41 deletions(-)
include/net/bluetooth/hci_core.h +5 -1
index 8f441b8..be226b0 100644
@@ -32,6 +32,10 @@
 #define HCI_PROTO_L2CAP	0
 #define HCI_PROTO_SCO	1
 
+/* HCI priority queues */
+#define HCI_PRIO_QUEUES	8
+#define HCI_PRIO_MAX	HCI_PRIO_QUEUES - 1
+
 /* HCI Core structures */
 struct inquiry_data {
 	bdaddr_t	bdaddr;
@@ -274,7 +278,7 @@ struct hci_conn {
 
 	unsigned int	sent;
 
-	struct sk_buff_head data_q;
+	struct sk_buff_head data_q[HCI_PRIO_QUEUES];
 
 	struct timer_list disc_timer;
 	struct timer_list idle_timer;
net/bluetooth/hci_conn.c +6 -2
index ea7f031..4c09738 100644
@@ -336,6 +336,7 @@ static void hci_conn_auto_accept(unsigned long arg)
 struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst)
 {
 	struct hci_conn *conn;
+	int i;
 
 	BT_DBG("%s dst %s", hdev->name, batostr(dst));
 
@@ -372,7 +373,8 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst)
 		break;
 	}
 
-	skb_queue_head_init(&conn->data_q);
+	for (i = 0; i < HCI_PRIO_QUEUES; i++)
+		skb_queue_head_init(&conn->data_q[i]);
 
 	setup_timer(&conn->disc_timer, hci_conn_timeout, (unsigned long)conn);
 	setup_timer(&conn->idle_timer, hci_conn_idle, (unsigned long)conn);
@@ -401,6 +403,7 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst)
 int hci_conn_del(struct hci_conn *conn)
 {
 	struct hci_dev *hdev = conn->hdev;
+	int i;
 
 	BT_DBG("%s conn %p handle %d", hdev->name, conn, conn->handle);
 
@@ -438,7 +441,8 @@ int hci_conn_del(struct hci_conn *conn)
 
 	tasklet_enable(&hdev->tx_task);
 
-	skb_queue_purge(&conn->data_q);
+	for (i = 0; i < HCI_PRIO_QUEUES; i++)
+		skb_queue_purge(&conn->data_q[i]);
 
 	hci_conn_put_device(conn);
 
net/bluetooth/hci_core.c +103 -38

270 lines not on this page · raw message

net/bluetooth/rfcomm/sock.c +8 -0
index 8f01e6b..0228e1f 100644
@@ -561,6 +561,7 @@ static int rfcomm_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
 	struct sock *sk = sock->sk;
 	struct rfcomm_dlc *d = rfcomm_pi(sk)->dlc;
 	struct sk_buff *skb;
+	u32 priority;
 	int sent = 0;
 
 	if (test_bit(RFCOMM_DEFER_SETUP, &d->flags))
@@ -572,6 +573,11 @@ static int rfcomm_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
 	if (sk->sk_shutdown & SEND_SHUTDOWN)
 		return -EPIPE;
 
+	if (msg->msg_flags & MSG_TRYHARD)
+		priority = HCI_PRIO_MAX;
+	else
+		priority = sk->sk_priority;
+
 	BT_DBG("sock %p, sk %p", sock, sk);
 
 	lock_sock(sk);
@@ -597,6 +603,8 @@ static int rfcomm_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
 			break;
 		}
 
+		skb->priority = priority;
+
 		err = rfcomm_dlc_send(d, skb);
 		if (err < 0) {
 			kfree_skb(skb);
Signature · 1 line
1.7.6
author maintainer
#7 lore raw

RFC 2/3 Bluetooth: set skbuffer priority based on L2CAP socket priority

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This uses SO_PRIORITY to set the skbuffer priority field

---
 include/net/bluetooth/l2cap.h |    3 +-
 net/bluetooth/l2cap_core.c    |   47 +++++++++++++++++++++++++++++-----------
 net/bluetooth/l2cap_sock.c    |    2 +-
 3 files changed, 37 insertions(+), 15 deletions(-)
include/net/bluetooth/l2cap.h +2 -1
index 4f34ad2..f018e5d 100644
@@ -511,7 +511,8 @@ struct l2cap_chan *l2cap_chan_create(struct sock *sk);
 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);
+int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len,
+								u32 priority);
 void l2cap_chan_busy(struct l2cap_chan *chan, int busy);
 
 #endif /* __L2CAP_H */
net/bluetooth/l2cap_core.c +34 -13

149 lines not on this page · raw message

net/bluetooth/l2cap_sock.c +1 -1
index 5c36b3e..abe302b 100644
@@ -706,7 +706,7 @@ static int l2cap_sock_sendmsg(struct kiocb *iocb, struct socket *sock, struct ms
 		return -ENOTCONN;
 	}
 
-	err = l2cap_chan_send(chan, msg, len);
+	err = l2cap_chan_send(chan, msg, len, sk->sk_priority);
 
 	release_sock(sk);
 	return err;
Signature · 1 line
1.7.6
author maintainer
#8 lore raw

RFC 3/3 Bluetooth: make use sk_priority to priritize RFCOMM packets

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

---
 net/bluetooth/rfcomm/core.c |   51 +++++++++++++++++++++++++++++-------------
 1 files changed, 35 insertions(+), 16 deletions(-)
net/bluetooth/rfcomm/core.c +35 -16
index 5759bb7..3ec98bd 100644
@@ -66,7 +66,8 @@ static unsigned long rfcomm_event;
 
 static LIST_HEAD(session_list);
 
-static int rfcomm_send_frame(struct rfcomm_session *s, u8 *data, int len);
+static int rfcomm_send_frame(struct rfcomm_session *s, u8 *data, int len,
+							u32 priority);
 static int rfcomm_send_sabm(struct rfcomm_session *s, u8 dlci);
 static int rfcomm_send_disc(struct rfcomm_session *s, u8 dlci);
 static int rfcomm_queue_disc(struct rfcomm_dlc *d);
@@ -751,19 +752,34 @@ void rfcomm_session_getaddr(struct rfcomm_session *s, bdaddr_t *src, bdaddr_t *d
 }
 
 /* ---- RFCOMM frame sending ---- */
-static int rfcomm_send_frame(struct rfcomm_session *s, u8 *data, int len)
+static int rfcomm_send_frame(struct rfcomm_session *s, u8 *data, int len,
+							u32 priority)
 {
 	struct socket *sock = s->sock;
+	struct sock *sk = sock->sk;
 	struct kvec iv = { data, len };
 	struct msghdr msg;
 
-	BT_DBG("session %p len %d", s, len);
+	BT_DBG("session %p len %d priority %u", s, len, priority);
+
+	if (sk->sk_priority != priority) {
+		lock_sock(sk);
+		sk->sk_priority = priority;
+		release_sock(sk);
+	}
 
 	memset(&msg, 0, sizeof(msg));
 
 	return kernel_sendmsg(sock, &msg, &iv, 1, len);
 }
 
+static int rfcomm_send_cmd(struct rfcomm_session *s, struct rfcomm_cmd *cmd)
+{
+	BT_DBG("%p cmd %u", s, cmd->ctrl);
+
+	return rfcomm_send_frame(s, (void *) cmd, sizeof(*cmd), HCI_PRIO_MAX);
+}
+
 static int rfcomm_send_sabm(struct rfcomm_session *s, u8 dlci)
 {
 	struct rfcomm_cmd cmd;
@@ -775,7 +791,7 @@ static int rfcomm_send_sabm(struct rfcomm_session *s, u8 dlci)
 	cmd.len  = __len8(0);
 	cmd.fcs  = __fcs2((u8 *) &cmd);
 
-	return rfcomm_send_frame(s, (void *) &cmd, sizeof(cmd));
+	return rfcomm_send_cmd(s, &cmd);
 }
 
 static int rfcomm_send_ua(struct rfcomm_session *s, u8 dlci)
@@ -789,7 +805,7 @@ static int rfcomm_send_ua(struct rfcomm_session *s, u8 dlci)
 	cmd.len  = __len8(0);
 	cmd.fcs  = __fcs2((u8 *) &cmd);
 
-	return rfcomm_send_frame(s, (void *) &cmd, sizeof(cmd));
+	return rfcomm_send_cmd(s, &cmd);
 }
 
 static int rfcomm_send_disc(struct rfcomm_session *s, u8 dlci)
@@ -803,7 +819,7 @@ static int rfcomm_send_disc(struct rfcomm_session *s, u8 dlci)
 	cmd.len  = __len8(0);
 	cmd.fcs  = __fcs2((u8 *) &cmd);
 
-	return rfcomm_send_frame(s, (void *) &cmd, sizeof(cmd));
+	return rfcomm_send_cmd(s, &cmd);
 }
 
 static int rfcomm_queue_disc(struct rfcomm_dlc *d)
@@ -817,6 +833,8 @@ static int rfcomm_queue_disc(struct rfcomm_dlc *d)
 	if (!skb)
 		return -ENOMEM;
 
+	skb->priority = HCI_PRIO_MAX;
+
 	cmd = (void *) __skb_put(skb, sizeof(*cmd));
 	cmd->addr = d->addr;
 	cmd->ctrl = __ctrl(RFCOMM_DISC, 1);
@@ -839,7 +857,7 @@ static int rfcomm_send_dm(struct rfcomm_session *s, u8 dlci)
 	cmd.len  = __len8(0);
 	cmd.fcs  = __fcs2((u8 *) &cmd);
 
-	return rfcomm_send_frame(s, (void *) &cmd, sizeof(cmd));
+	return rfcomm_send_cmd(s, &cmd);
 }
 
 static int rfcomm_send_nsc(struct rfcomm_session *s, int cr, u8 type)
@@ -864,7 +882,7 @@ static int rfcomm_send_nsc(struct rfcomm_session *s, int cr, u8 type)
 
 	*ptr = __fcs(buf); ptr++;
 
-	return rfcomm_send_frame(s, buf, ptr - buf);
+	return rfcomm_send_frame(s, buf, ptr - buf, HCI_PRIO_MAX);
 }
 
 static int rfcomm_send_pn(struct rfcomm_session *s, int cr, struct rfcomm_dlc *d)
@@ -906,7 +924,7 @@ static int rfcomm_send_pn(struct rfcomm_session *s, int cr, struct rfcomm_dlc *d
 
 	*ptr = __fcs(buf); ptr++;
 
-	return rfcomm_send_frame(s, buf, ptr - buf);
+	return rfcomm_send_frame(s, buf, ptr - buf, HCI_PRIO_MAX);
 }
 
 int rfcomm_send_rpn(struct rfcomm_session *s, int cr, u8 dlci,
@@ -944,7 +962,7 @@ int rfcomm_send_rpn(struct rfcomm_session *s, int cr, u8 dlci,
 
 	*ptr = __fcs(buf); ptr++;
 
-	return rfcomm_send_frame(s, buf, ptr - buf);
+	return rfcomm_send_frame(s, buf, ptr - buf, HCI_PRIO_MAX);
 }
 
 static int rfcomm_send_rls(struct rfcomm_session *s, int cr, u8 dlci, u8 status)
@@ -971,7 +989,7 @@ static int rfcomm_send_rls(struct rfcomm_session *s, int cr, u8 dlci, u8 status)
 
 	*ptr = __fcs(buf); ptr++;
 
-	return rfcomm_send_frame(s, buf, ptr - buf);
+	return rfcomm_send_frame(s, buf, ptr - buf, HCI_PRIO_MAX);
 }
 
 static int rfcomm_send_msc(struct rfcomm_session *s, int cr, u8 dlci, u8 v24_sig)
@@ -998,7 +1016,7 @@ static int rfcomm_send_msc(struct rfcomm_session *s, int cr, u8 dlci, u8 v24_sig
 
 	*ptr = __fcs(buf); ptr++;
 
-	return rfcomm_send_frame(s, buf, ptr - buf);
+	return rfcomm_send_frame(s, buf, ptr - buf, HCI_PRIO_MAX);
 }
 
 static int rfcomm_send_fcoff(struct rfcomm_session *s, int cr)
@@ -1020,7 +1038,7 @@ static int rfcomm_send_fcoff(struct rfcomm_session *s, int cr)
 
 	*ptr = __fcs(buf); ptr++;
 
-	return rfcomm_send_frame(s, buf, ptr - buf);
+	return rfcomm_send_frame(s, buf, ptr - buf, HCI_PRIO_MAX);
 }
 
 static int rfcomm_send_fcon(struct rfcomm_session *s, int cr)
@@ -1042,7 +1060,7 @@ static int rfcomm_send_fcon(struct rfcomm_session *s, int cr)
 
 	*ptr = __fcs(buf); ptr++;
 
-	return rfcomm_send_frame(s, buf, ptr - buf);
+	return rfcomm_send_frame(s, buf, ptr - buf, HCI_PRIO_MAX);
 }
 
 static int rfcomm_send_test(struct rfcomm_session *s, int cr, u8 *pattern, int len)
@@ -1093,7 +1111,7 @@ static int rfcomm_send_credits(struct rfcomm_session *s, u8 addr, u8 credits)
 
 	*ptr = __fcs(buf); ptr++;
 
-	return rfcomm_send_frame(s, buf, ptr - buf);
+	return rfcomm_send_frame(s, buf, ptr - buf, HCI_PRIO_MAX);
 }
 
 static void rfcomm_make_uih(struct sk_buff *skb, u8 addr)
@@ -1771,7 +1789,8 @@ static inline int rfcomm_process_tx(struct rfcomm_dlc *d)
 		return skb_queue_len(&d->tx_queue);
 
 	while (d->tx_credits && (skb = skb_dequeue(&d->tx_queue))) {
-		err = rfcomm_send_frame(d->session, skb->data, skb->len);
+		err = rfcomm_send_frame(d->session, skb->data, skb->len,
+							skb->priority);
 		if (err < 0) {
 			skb_queue_head(&d->tx_queue, skb);
 			break;
Signature · 1 line
1.7.6
#2 lore raw

Re: [RFC 1/3] Bluetooth: prioritizing data over HCI

In reply to Luiz Augusto von Dentz

SGkgTHVpeiwNCg0KT24gV2VkLCAyMDExLTA4LTAzIGF0IDA5OjExIC0wNDAwLCBMdWl6IEF1Z3Vz dG8gdm9uIERlbnR6IHdyb3RlOg0KPiBGcm9tOiBMdWl6IEF1Z3VzdG8gdm9uIERlbnR6IDxsdWl6 LnZvbi5kZW50ekBpbnRlbC5jb20+DQo+DQo+IFRoaXMgaW1wbGVtZW50IHByaW9yaXR5IGJhc2Vk IHNjaGVkdWxlciB1c2luZyBza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c3RydWN0IGxpc3RfaGVhZCAqcDsNCj4g KyAgICAgICBpbnQgaTsNCj4NCj4gICAgICAgICAvKiBXZSBkb24ndCBoYXZlIHRvIGxvY2sgZGV2 aWNlIGhlcmUuIENvbm5lY3Rpb25zIGFyZSBhbHdheXMNCj4gICAgICAgICAgKiBhZGRlZCBhbmQg cmVtb3ZlZCB3aXRoIFRYIHRhc2sgZGlzYWJsZWQuICovDQo+IC0gICAgICAgbGlzdF9mb3JfZWFj aChwLCAmaC0+bGlzdCkgew0KPiAtICAgICAgICAgICAgICAgc3RydWN0IGhjaV9jb25uICpjOw0K PiAtICAgICAgICAgICAgICAgYyA9IGxpc3RfZW50cnkocCwgc3RydWN0IGhjaV9jb25uLCBsaXN0 KTsNCj4gKyAgICAgICBmb3IgKGkgPSBIQ0lfUFJJT19NQVg7IGkgPj0gMDsgaS0tKSB7DQo+ICsg ICAgICAgICAgICAgICBpbnQgbnVtID0gMCwgbWluID0gfjA7DQo+ICsgICAgICAgICAgICAgICBz dHJ1Y3QgbGlzdF9oZWFkICpwOw0KPiArICAgICAgICAgICAgICAgaW50IGNudCwgcTsNCj4NCj4g LSAgICAgICAgICAgICAgIGlmIChjLT50eXBlICE9IHR5cGUgfHwgc2tiX3F1ZXVlX2VtcHR5KCZj LT5kYXRhX3EpKQ0KPiAtICAgICAgICAgICAgICAgICAgICAgICBjb250aW51ZTsNCj4gKyAgICAg ICAgICAgICAgIGxpc3RfZm9yX2VhY2gocCwgJmgtPmxpc3QpIHsNCj4gKyAgICAgICAgICAgICAg ICAgICAgICAgc3RydWN0IGhjaV9jb25uICpjOw0KPiArICAgICAgICAgICAgICAgICAgICAgICBj ID0gbGlzdF9lbnRyeShwLCBzdHJ1Y3QgaGNpX2Nvbm4sIGxpc3QpOw0KPg0KPiAtICAgICAgICAg ICAgICAgaWYgKGMtPnN0YXRlICE9IEJUX0NPTk5FQ1RFRCAmJiBjLT5zdGF0ZSAhPSBCVF9DT05G SUcpDQo+IC0gICAgICAgICA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ICAgNyBwcmkgbGV2ZWxzIHggNCBjb25u ZWN0aW9ucyA9PiBubyBMRSB0eCBwYWNrZXRzDQogICAgICAgIDcgcHJpIGxldmVscyB4IDQgY29u bmVjdGlvbnMgPT4gcmVjYWxjIHByaW9yaXR5DQoNCklmIHRoZSBjb25uZWN0aW9uIHR5cGUgZG9l c24ndCBtYXRjaCwgaXQncyBub3QgZ29pbmcgdG8gbWF0Y2ggYXQgYW55DQpwcmlvcml0eSBsZXZl bC4NCg0KPiArDQo+ICsgICAgICAgICAgICAgICAgICAgICAgIGlmIChjLT5zdGF0ZSAhPSBCVF9D T05ORUNURUQgJiYgYy0+c3RhdGUgIT0gQlRfQ09ORklHKQ0KPiArICAgICAgICAgICAgICAgICAg ICAgICAgICAgICAgIGNvbnRpbnVlOw0KPg0KPiAtICAgICAgICAgICAgICAgbnVtKys7DQo+ICsg ICAgICAgICAgICAgICAgICAgICAgIG51bSsrOw0KPg0KPiAtICAgICAgICAgICAgICAgaWYgKGMt PnNlbnQgPCBtaW4pIHsNCj4gLSAgICAgICAgICAgICAgICAgICAgICAgbWluICA9IGMtPnNlbnQ7 DQo+IC0gICAgICAgICAgICAgICAgICAgICAgIGNvbm4gPSBjOw0KPiArICAgICAgICAgICAgICAg ICAgICAgICBpZiAoYy0+c2VudCA8IG1pbikgew0KPiArICAgICAgICAgICAgICAgICAgICAgICAg ICAgICAgIG1pbiAgPSBjLT5zZW50Ow0KPiArICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg IGNvbm4gPSBjOw0KPiArICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICpxdWV1ZSA9ICZj LT5kYXRhX3FbaV07DQo+ICsgICAgICAgICAgICAgICAgICAgICAgIH0NCg0KV2h5IHByZXNlcnZl IHRoZSBmYWlybmVzcyBsb2dpYz8NCg0KPiAgICAgICAgICAgICAgICAgfQ0KPiAtICAgICAgIH0N Cj4NCj4gLSAgICAgICBpZiAoY29ubikgew0KPiAtICAgICAgICAgICAgICAgaW50IGNudCwgcTsN Cj4gKyAgICAgICAgICAgICAgIGlmICghY29ubikNCj4gKyAgICAgICAgICAgICAgICAgICAgICAg Y29udGludWU7DQo+DQo+ICAgICAgICAgICAgICAgICBzd2l0Y2ggKGNvbm4tPnR5cGUpIHsNCj4g ICAgICAgICAgICAgICAgIGNhc2UgQUNMX0xJTks6DQo+IEBAIC0yMDk4LDEwICsyMTE5LDEzIEBA IHN0YXRpYyBpbmxpbmUgc3RydWN0IGhjaV9jb25uICpoY2lfbG93X3NlbnQoc3RydWN0IGhjaV9k ZXYgKmhkZXYsIF9fdTggdHlwZSwgaW50DQo+DQo+ICAgICAgICAgICAgICAgICBxID0gY250IC8g bnVtOw0KPiAgICAgICAgICAgICAgICAgKnF1b3RlID0gcSA/IHEgOiAxOw0KPiAtICAgICAgIH0g ZWxzZQ0KPiAtICAgICAgICAgICAgICAgKnF1b3RlID0gMDsNCj4gKyAgICAgICAgICAgICAgIEJU X0RCRygiY29ubiAlcCBpbmRleCAlZCBxdW90ZSAlZCIsIGNvbm4sIGksICpxdW90ZSk7DQo+ICsg ICAgICAgICAgICAgICByZXR1cm4gY29ubjsNCj4gKyAgICAgICB9DQo+DQo+IC0gICAgICAgQlRf REJHKCJjb25uICVwIHF1b3RlICVkIiwgY29ubiwgKnF1b3RlKTsNCj4gKyAgICAgICAqcXVvdGUg PSAwOw0KPiArICAgICAgICpxdWV1ZSA9IE5VTEw7DQo+ICsgICAgICAgQlRfREJHKCJjb25uICVw IHF1ZXVlICVwIHF1b3RlICVkIiwgY29ubiwgcXVldWUsICpxdW90ZSk7DQo+ICAgICAgICAgcmV0 dXJuIGNvbm47DQo+ICB9DQo+DQo+IEBAIC0yMTI4LDYgKzIxNTIsNyBAQCBzdGF0aWMgaW5saW5l IHZvaWQgaGNpX3NjaGVkX2FjbChzdHJ1Y3QgaGNpX2RldiAqaGRldikNCj4gIHsNCj4gICAgICAg ICBzdHJ1Y3QgaGNpX2Nvbm4gKmNvbm47DQo+ICAgICAgICAgc3RydWN0IHNrX2J1ZmYgKnNrYjsN Cj4gKyAgICAgICBzdHJ1Y3Qgc2tfYnVmZl9oZWFkICpxdWV1ZSA9IE5VTEw7DQo+ICAgICAgICAg aW50IHF1b3RlOw0KPg0KPiAgICAgICAgIEJUX0RCRygiJXMiLCBoZGV2LT5uYW1lKTsNCj4gQEAg LTIxMzksOSArMjE2NCwxMSBAQCBzdGF0aWMgaW5saW5lIHZvaWQgaGNpX3NjaGVkX2FjbChzdHJ1 Y3QgaGNpX2RldiAqaGRldikNCj4gICAgICAgICAgICAgICAgICAgICAgICAgaGNpX2xpbmtfdHhf dG8oaGRldiwgQUNMX0xJTkspOw0KPiAgICAgICAgIH0NCj4NCj4gLSAgICAgICB3aGlsZSAoaGRl di0+YWNsX2NudCAmJiAoY29ubiA9IGhjaV9sb3dfc2VudChoZGV2LCBBQ0xfTElOSywgJnF1b3Rl KSkpIHsNCj4gLSAgICAgICAgICAgICAgIHdoaWxlIChxdW90ZS0tICYmIChza2IgPSBza2JfZGVx dWV1ZSgmY29ubi0+ZGF0YV9xKSkpIHsNCj4gLSAgICAgICAgICAgICAgICAgICAgICAgQlRfREJH KCJza2IgJXAgbGVuICVkIiwgc2tiLCBza2ItPmxlbik7DQo+ICsgICAgICAgd2hpbGUgKGhkZXYt PmFjbF9jbnQgJiYNCj4gKyAgICAgICAgICAgICAgICAgICAgICAgKGNvbm4gPSBoY2lfcHJpb19z ZW50KGhkZXYsIEFDTF9MSU5LLCAmcXVldWUsICZxdW90ZSkpKSB7DQo+ICsgICAgICAgICAgICAg ICB3aGlsZSAocXVvdGUtLSAmJiAoc2tiID0gc2tiX2RlcXVldWUocXVldWUpKSkgew0KPiArICAg ICAgICAgICAgICAgICAgICAgICBCVF9EQkcoInNrYiAlcCBsZW4gJWQgcHJpb3JpdHkgJXUiLCBz a2IsIHNrYi0+bGVuLA0KPiArICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgIHNrYi0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ICVwIGxl biAlZCBwcmlvcml0eSAldSIsIGNvbm4sIHNrYiwNCj4gKyAgICAgICAgICAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgc2tiLT5sZW4sIHNrYi0+cHJpb3JpdHkpOw0KPiAgICAg ICAgICAgICAgICAgICAgICAgICBoY2lfc2VuZF9mcmFtZShza2IpOw0KPg0KPiAgICAgICAgICAg ICAgICAgICAgICAgICBjb25uLT5zZW50Kys7DQo+IEBAIC0yMTc5LDEzICsyMjA5LDE2IEBAIHN0 YXRpYyBpbmxpbmUgdm9pZCBoY2lfc2NoZWRfZXNjbyhzdHJ1Y3QgaGNpX2RldiAqaGRldikNCj4g IHsNCj4gICAgICAgICBzdHJ1Y3QgaGNpX2Nvbm4gKmNvbm47DQo+ICAgICAgICAgc3RydWN0IHNr X2J1ZmYgKnNrYjsNCj4gKyAgICAgICBzdHJ1Y3Qgc2tfYnVmZl9oZWFkICpxdWV1ZSA9IE5VTEw7 DQo+ICAgICAgICAgaW50IHF1b3RlOw0KPg0KPiAgICAgICAgIEJUX0RCRygiJXMiLCBoZGV2LT5u YW1lKTsNCj4NCj4gLSAgICAgICB3aGlsZSAoaGRldi0+c2NvX2NudCAmJiAoY29ubiA9IGhjaV9s b3dfc2VudChoZGV2LCBFU0NPX0xJTkssICZxdW90ZSkpKSB7DQo+IC0gICAgICAgICAgICAgICB3 aGlsZSAocXVvdGUtLSAmJiAoc2tiID0gc2tiX2RlcXVldWUoJmNvbm4tPmRhdGFfcSkpKSB7DQo+ IC0gICAgICAgICAgICAgICAgICAgICAgIEJUX0RCRygic2tiICVwIGxlbiAlZCIsIHNrYiwgc2ti LT5sZW4pOw0KPiArICAgICAgIHdoaWxlIChoZGV2LT5zY29fY250ICYmDQo+ICsgICAgICAgICAg ICAgICAgICAgICAgIChjb25uID0gaGNpX3ByaW9fc2VudChoZGV2LCBFU0NPX0xJTkssICZxdWV1 ZSwgJnF1b3RlKSkpIHsNCj4gKyAgICAgICAgICAgICAgIHdoaWxlIChxdW90ZS0tICYmIChza2Ig PSBza2JfZGVxdWV1ZShxdWV1ZSkpKSB7DQo+ICsgICAgICAgICAgICAgICAgICAgICAgIEJUX0RC RygiY29ubiAlcCBza2IgJXAgbGVuICVkIHByaW9yaXR5ICV1IiwgY29ubiwgc2tiLA0KPiArICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBza2ItPmxlbiwgc2ti LT5wcmlvcml0eSk7DQo+ICAgICAgICAgICAgICAgICAgICAgICAgIGhjaV9zZW5kX2ZyYW1lKHNr Yik7DQo+DQo+ICAgICAgICAgICAgICAgICAgICAgICAgIGNvbm4tPnNlbnQrKzsNCj4gQEAgLTIx OTksNiArMjIzMiw3IEBAIHN0YXRpYyBpbmxpbmUgdm9pZCBoY2lfc2NoZWRfbGUoc3RydWN0IGhj aV9kZXYgKmhkZXYpDQo+ICB7DQo+ICAgICAgICAgc3RydWN0IGhjaV9jb25uICpjb25uOw0KPiAg ICAgICAgIHN0cnVjdCBza19idWZmICpza2I7DQo+ICsgICAgICAgc3RydWN0IHNrX2J1ZmZfaGVh ZCAqcXVldWUgPSBOVUxMOw0KPiAgICAgICAgIGludCBxdW90ZSwgY250Ow0KPg0KPiAgICAgICAg IEJUX0RCRygiJXMiLCBoZGV2LT5uYW1lKTsNCj4gQEAgLTIyMTIsOSArMjI0NiwxMCBAQCBzdGF0 aWMgaW5saW5lIHZvaWQgaGNpX3NjaGVkX2xlKHN0cnVjdCBoY2lfZGV2ICpoZGV2KQ0KPiAgICAg ICAgIH0NCj4NCj4gICAgICAgICBjbnQgPSBoZGV2LT5sZV9wa3RzID8gaGRldi0+bGVfY250IDog aGRldi0+YWNsX2NudDsNCj4gLSAgICAgICB3aGlsZSAoY250ICYmIChjb25uID0gaGNpX2xvd19z ZW50KGhkZXYsIExFX0xJTkssICZxdW90ZSkpKSB7DQo+IC0gICAgICAgICAgICAgICB3aGlsZSAo cXVvdGUtLSAmJiAoc2tiID0gc2tiX2RlcXVldWUoJmNvbm4tPmRhdGFfcSkpKSB7DQo+IC0gICAg ICAgICAgICAgICAgICAgICAgIEJUX0RCRygic2tiICVwIGxlbiAlZCIsIHNrYiwgc2tiLT5sZW4p Ow0KPiArICAgICAgIHdoaWxlIChjbnQgJiYgKGNvbm4gPSBoY2lfcHJpb19zZW50KGhkZXYsIExF X0xJTkssICZxdWV1ZSwgJnF1b3RlKSkpIHsNCj4gKyAgICAgICAgICAgICAgIHdoaWxlIChxdW90 ZS0tICYmIChza2IgPSBza2JfZGVxdWV1ZShxdWV1ZSkpKSB7DQo+ICsgICAgICAgICAgICAgICAg ICAgICAgIEJUX0RCRygiY29ubiAlcCBza2IgJXAgbGVuICVkIHByaW9yaXR5ICV1IiwgY29ubiwg c2tiLA0KPiArICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBz a2ItPmxlbiwgc2tiLT5wcmlvcml0eSk7DQo+DQo+ICAgICAgICAgICAgICAgICAgICAgICAgIGhj aV9zZW5kX2ZyYW1lKHNrYik7DQo+ICAgICAgICAgICAgICAgICAgICAgICAgIGhkZXYtPmxlX2xh c3RfdHggPSBqaWZmaWVzOw0KPiBAQCAtMjIyOSw2ICsyMjY0LDM0IEBAIHN0YXRpYyBpbmxpbmUg dm9pZCBoY2lfc2NoZWRfbGUoc3RydWN0IGhjaV9kZXYgKmhkZXYpDQo+ICAgICAgICAgICAgICAg ICBoZGV2LT5hY2xfY250ID0gY250Ow0KPiAgfQ0KPg0KPiArc3RhdGljIHZvaWQgaGNpX3ByaW9f cmVjYWxjdWxhdGUoc3RydWN0IGhjaV9kZXYgKmhkZXYpDQo+ICt7DQo+ICsgICAgICAgc3RydWN0 IGhjaV9jb25uX2hhc2ggKmggPSAmaGRldi0+Y29ubl9oYXNoOw0KPiArICAgICAgIGludCBpOw0K PiArDQo+ICsgICAgICAgQlRfREJHKCIlcyIsIGhkZXYtPm5hbWUpOw0KPiArDQo+ICsgICAgICAg Zm9yICh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jay0+c2s7DQo+ ICAgICAgICAgc3RydWN0IHJmY29tbV9kbGMgKmQgPSByZmNvbW1fcGkoc2spLT5kbGM7DQo+ICAg ICAgICAgc3RydWN0IHNrX2J1ZmYgKnNrYjsNCj4gKyAgICAgICB1MzIgcHJpb3JpdHk7DQo+ICAg ICAgICAgaW50IHNlbnQgPSAwOw0KPg0KPiAgICAgICAgIGlmICh0ZXN0X2JpdChSRkNPTU1fREVG RVJfU0VUVVAsICZkLT5mbGFncykpDQo+IEBAIC01NzIsNiArNTczLDExIEBAIHN0YXRpYyBpbnQg cmZjb21tX3NvY2tfc2VuZG1zZyhzdHJ1Y3Qga2lvY2IgKmlvY2IsIHN0cnVjdCBzb2NrZXQgKnNv Y2ssDQo+ICAgICAgICAgaWYgKHNrLT5za19zaHV0ZG93biAmIFNFTkRfU0hVVERPV04pDQo+ICAg ICAgICAgICAgICAgICByZXR1cm4gLUVQSVBFOw0KPg0KPiArICAgICAgIGlmIChtc2ctPm1zZ19m bGFncyAmIE1TR19UUllIQVJEKQ0KPiArICAgICAgICAgICAgICAgcHJpb3JpdHkgPSBIQ0lfUFJJ T19NQVg7DQo+ICsgICAgICAgZWxzZQ0KPiArICAgICAgICAgICAgICAgcHJpb3JpdHkgPSBzay0+ c2tfcHJpb3JpdHk7DQo+ICsNCj4gICAgICAgICBCVF9EQkcoInNvY2sgJXAsIHNrICVwIiwgc29j aywgc2spOw0KPg0KPiAgICAgICAgIGxvY2tfc29jayhzayk7DQo+IEBAIC01OTcsNiArNjAzLDgg QEAgc3RhdGljIGludCByZmNvbW1fc29ja19zZW5kbXNnKHN0cnVjdCBraW9jYiAqaW9jYiwgc3Ry dWN0IHNvY2tldCAqc29jaywNCj4gICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7DQo+ICAg ICAgICAgICAgICAgICB9DQo+DQo+ICsgICAgICAgICAgICAgICBza2ItPnByaW9yaXR5ID0gcHJp b3JpdHk7DQo+ICsNCj4gICAgICAgICAgICAgICAgIGVyciA9IHJmY29tbV9kbGNfc2VuZChkLCBz a2IpOw0KPiAgICAgICAgICAgICAgICAgaWYgKGVyciA8IDApIHsNCj4gICAgICAgICAgICAgICAg ICAgICAgICAga2ZyZWVfc2tiKHNrYik7DQo+IC0tDQo+IDEuNy42DQo+DQo+IC0tDQo+IFRvIHVu c3Vic2NyaWJlIGZyb20gdGhpcyBsaXN0OiBzZW5kIHRoZSBsaW5lICJ1bnN1YnNjcmliZSBsaW51 eC1ibHVldG9vdGgiIGluDQo+IHRoZSBib2R5IG9mIGEgbWVzc2FnZSB0byBtYWpvcmRvbW9Admdl ci5rZXJuZWwub3JnDQo+IE1vcmUgbWFqb3Jkb21vIGluZm8gYXQgIGh0dHA6Ly92Z2VyLmtlcm5l bC5vcmcvbWFqb3Jkb21vLWluZm8uaHRtbA0KDQo=

author maintainer
#3 lore raw

Re: [RFC 1/3] Bluetooth: prioritizing data over HCI

Hi Peter,

Quoted 17 lines · Peter Hurley

I believe that the existing tx scheduler is already inefficient and that this approach significantly compounds that inefficiency.

Consider the following scenarios with 4 ACL connections (keyboard, mouse, phone, headset):

For *one* scheduled ACL tx packet, the connection list will be searched 35~42 times -- that's 140~168 connection list node visits to find one packet! Here's the math:
       (7 - priority of tx packet) x 4 connections => found the packet 7 pri levels x 4 connections => no more ACL tx packets 7 pri levels x 4 connections => no SCO tx packets
       7 pri levels x 4 connections => no ESCO tx packets
       7 pri levels x 4 connections => no LE tx packets
       7 pri levels x 4 connections => recalc priority

Quoted 2 lines

If the connection type doesn't match, it's not going to match at any priority level.

Obviously there are a few things that we might change to not traverse the list of connection over and over, remember this is an RFC, besides it 8 priorities (0-7), but we can skip much earlier if connection doesn't match as you said. Also I guess for SCO/ESCO/LE e doesn't make much sense to have many queues/priorities, it is basically ACL only, that simplify a lot already.

Quoted 16 lines
Quoted 7 lines

+
+                       if (c->state != BT_CONNECTED && c->state != BT_CONFIG)
+                               continue;

-               num++;
+                       num++;

Quoted 8 lines

-               if (c->sent < min) {
-                       min  = c->sent;
-                       conn = c;
+                       if (c->sent < min) {
+                               min  = c->sent;
+                               conn = c;
+                               *queue = &c->data_q[i];
+                       }

Quoted 1 line

Why preserve the fairness logic?

It does need to fair if there is 2 or more sockets with the same priority, otherwise the first connection in the list might get all the quote and even if we promote the starving queues it may still happen to top most priority since there it cannot be promoted anymore.

Quoted 13 lines
Quoted 13 lines
net/bluetooth/hci_core.c +13 -0
+static void hci_prio_recalculate(struct hci_dev *hdev)
+{
+       struct hci_conn_hash *h = &hdev->conn_hash;
+       int i;
+
+       BT_DBG("%s", hdev->name);
+
+       for (i = HCI_PRIO_MAX - 1; i > 0; i--) {
+               struct list_head *p;
+
+               list_for_each(p, &h->list) {
+                       struct hci_conn *c;
+                       c = list_entry(p, struct hci_conn, list);
Quoted 8 lines
Quoted 3 lines

+
+                       if (c->sent || skb_queue_empty(&c->data_q[i - 1]))
+                               continue;

The test for unacked packets does not allow the priority to advance if the unacked packets are from a previously executed hci_tx_task (ie., a connection transmitted packets on an earlier scheduled tx_task but those packets haven't been acked yet).

IMO it does, why should it be promoted to a higher priority if it still is pending from the last time, this is specifically to throttle lower priority in favor of higher, if throughput is important the application should request be able to sets its priority according, and it can do it at any time.

Quoted 6 lines

This would allow a higher priority connection to almost monopolize transmission when the controller is near max load. A higher priority link will receive a tx quota of all available tx buffers, whereas a lower priority link will not advance until it's previous tx packets are acked. Worst-case scheduling could take a long time to schedule a lower priority packet.

You probably have never run this code did you? Only priority 7 can really monopolize the connection, and that is on purpose, and yes lower priority are throttled so higher priority can get lower latency, what is wrong with that?

Quoted 7 lines
Quoted 7 lines

 static void hci_tx_task(unsigned long arg)
 {
        struct hci_dev *hdev = (struct hci_dev *) arg;

net/bluetooth/hci_core.c +0 -0
@@ -2253,6 +2316,8 @@ static void hci_tx_task(unsigned long arg)
         while ((skb = skb_dequeue(&hdev->raw_q)))
                 hci_send_frame(skb);
 
Quoted 5 lines

net/bluetooth/hci_core.c static void hci_tx_task(unsigned long arg) · line 2319

Quoted 1 line
net/bluetooth/hci_core.c +1 -0
+       hci_prio_recalculate(hdev);

The priority recalculation should only be performed if one of the hci_sched_* functions was unable to schedule all outstanding packets (ie., a tx buffer count dropped to zero).

Yep, gonna fix that too.

Quoted 3 lines

How does this scheduler + priority recalc behave if *no* packets could be scheduled at all? For example, if acl_cnt == 0 when the tx_task is scheduled?

Right now it promotes starving queues, all of them, but maybe it shouldn't so that we simplify the complexity a little bit.

Signature · 1 line
Luiz Augusto von Dentz
#4 lore raw

Re: [RFC 1/3] Bluetooth: prioritizing data over HCI

Hi Luiz,

Quoted 23 lines · Luiz Augusto von Dentz

Hi Peter,

Quoted 17 lines · Peter Hurley

I believe that the existing tx scheduler is already inefficient and that this approach significantly compounds that inefficiency.

Consider the following scenarios with 4 ACL connections (keyboard, mouse, phone, headset):

For *one* scheduled ACL tx packet, the connection list will be searched 35~42 times -- that's 140~168 connection list node visits to find one packet! Here's the math:
       (7 - priority of tx packet) x 4 connections => found the packet 7 pri levels x 4 connections => no more ACL tx packets 7 pri levels x 4 connections => no SCO tx packets
       7 pri levels x 4 connections => no ESCO tx packets
       7 pri levels x 4 connections => no LE tx packets
       7 pri levels x 4 connections => recalc priority

Quoted 2 lines

If the connection type doesn't match, it's not going to match at any priority level.

Quoted 6 lines

Obviously there are a few things that we might change to not traverse the list of connection over and over, remember this is an RFC, besides it 8 priorities (0-7), but we can skip much earlier if connection doesn't match as you said. Also I guess for SCO/ESCO/LE e doesn't make much sense to have many queues/priorities, it is basically ACL only, that simplify a lot already.

Maybe 8 is too much, I think it could work with 4. We keep the high priority queue 7 and more 3. A2DP and SCO could have the 6, HID the queue 5, Obex transfers, PAN, AVRCP, etc goes queue 4. Queueing in 3, 2, 1 and 0 could actually queue on 4.

Gustavo

#5 lore raw

Re: [RFC 1/3] Bluetooth: prioritizing data over HCI

In reply to Luiz Augusto von Dentz

SGkgTHVpeiwNCg0KT24gV2VkLCAyMDExLTA4LTAzIGF0IDEzOjQ5IC0wNDAwLCBMdWl6IEF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JsZW0sIHRob3VnaCBjb25uZWN0aW5n L3BhZ2luZyBzdGlsbCBtYWtlcyBhdWRpbyBza2lwcywgYW5kIGFsc28gdHJpZWQNCj4gT0JFWCB0 cmFuc2ZlcnMgdG9nZXRoZXIgdG8gc2VlIGlmIGF1ZGlvIHNraXBzLCBpbmRlZWQgaXQgZG9lcyB3 aGVuIEhJRCBpcw0KPiBhY3RpdmUgYnV0IGl0IHdvcmtzIGJldHRlciB0aGFuIGhhdmluZyBubyBw cmlvcml0eSAoc2tpcHMgbGVzcyBmcmVxdWVudCkNCj4gYW5kIGluIGNhc2Ugb2YgdXNpbmcgcHJp b3JpdHkgNyB0aGUgYXVkaW8gZG9lc24ndCBza2lwIGFueW1vcmUgYnV0IGl0DQo+IGV2ZW50dWFs bHkgc3RhbGwgdGhlIE9CRVggdHJhbnNmZXIgKHRoaXMgaXMgbWF5YmUgYmVjYXVzZSBPcGVuT0JF WCBsb29wDQo+IHdoaWxlIHRyeWluZyB0byB3cml0ZSB0byBzb2NrZXQgYW5kIGRvbid0IHdhaXQg Zm9yIFBPTExPVVQpLg0KDQpJbnRlcmVzdGluZy4uLg0KDQpSZWdhcmRzLA0KUGV0ZXIgSHVybGV5 DQoNCg==

author maintainer
#10 lore raw

Hi Peter,

Quoted 14 lines · Peter Hurley

Hi Luiz,

On Wed, 2011-08-03 at 09:11 -0400, Luiz Augusto von Dentz wrote:
....

Quoted 9 lines

The main use case for this is A2DP, many people complained that when they are using their HID devices (mouses) together with headset the mouse has higher priority, which btw is not true since currently there is no priority and connections receives the same quote.

With this changes it may reduce the problem since PulseAudio already sets A2DP socket as low latency (priority 6), which means audio packets will be processed before the HID packets, but this only affects tx and there still exist the problem of some HID not letting us being master.

Quoted 4 lines

What packets are being transmitted _to_ the HID devices during audio streaming?  In all my captures of A2DP crackle/skips, there's not a single HID packet being transmitted out. Of course, I was carefully not to press any of the led-transition keys during the capture :).

Well with HID you will probably be only receiving, but that doesn't change anything does it? I mean you still got less bandwidth to use and we probably want low latency packets to be prioritized in any case, besides there is probably some use case where HID transmit too, see net/bluetooth/hidp/core.c:666(hidp_process_transmit).

Quoted 3 lines

It's my belief that the incredibly complicated way that PulseAudio handles the stream indices and computed latency is really the issue (at least with A2DP).

Really, so you have a fix for that? I would be happy to see your proposal and discussion on PulseAudio mailing list.

Quoted 5 lines

For example, in several configuration I have, PulseAudio is rendering *too fast*. This is evidenced by the remote device sending STOP packets (which can flood the syslog as 0-length L2CAP packets) because its recv buffers are full! (Of course, these DM1 packets are eating up air time too -- which is slowing legitimate rx packets from the HID devices!)

But why the kernel is not stopping PulseAudio? I mean PA does use POLLOUT to check if the socket is writable, it then writes as much as possible and sleep, but without using guaranteed channels with proper QoS support I don't this changing anytime soon.

Quoted 5 lines

You should hear the 'skipping' when the sleep timer which delays the next block render is IFDEF'd out of the module-bluetooth-device.c/threadfn(). With other subsystems but not with Bluez, PulseAudio uses a 'smoother' to fine-tune when to render the next block.

This can be fixed, the source already uses the smoother anyway, but Im afraid this can cause bad effects like much frequent wakeups and even auto of sync with some headsets.

Quoted 2 lines

My point here is I think it's premature to conclude that PulseAudio doesn't have a part to play.

It probably does, but it doesn't change the fact the prioritization is pretty much needed, actually it will probably make such problems more visible than ever.

Signature · 1 line
Luiz Augusto von Dentz
author maintainer
#6 lore raw

Re: [RFC 1/3] Bluetooth: prioritizing data over HCI

In reply to Peter Hurley

Hi Peter,

Quoted 4 lines · Peter Hurley

My point here (besides pointing out the massive iteration) was to suggest that perhaps some scheduler state should be preserved such that already-visited priority levels are not revisited more than once per tx tasklet schedule.

That is a valid point, Im gonna try to come up with something that address that.

Quoted 9 lines
Quoted 3 lines

 Also I guess for SCO/ESCO/LE e doesn't make
much sense to have many queues/priorities, it is basically ACL only, that simplify a lot already.

LE should still have priorities. In fact, in a private test we've been running here, we've merged the scheduler so that LE conns that share ACL buffers are scheduled alongside other ACL conns (because they share the same resource -- namely, the acl_cnt. We also merged SCO/ESCO scheduling together as well).

Well I guess it would make sense, specially for SCO/ESCO, now LE Im not sure, it is not always the case the it uses acl_cnt, but in case it does it should be prioritized according.

Quoted 24 lines
Quoted 17 lines
Quoted 17 lines
Quoted 16 lines

+
+                       if (c->state != BT_CONNECTED && c->state != BT_CONFIG)
+                               continue;

-               num++;
+                       num++;

-               if (c->sent < min) {
-                       min  = c->sent;
-                       conn = c;
+                       if (c->sent < min) {
+                               min  = c->sent;
+                               conn = c;
+                               *queue = &c->data_q[i];
+                       }

Quoted 6 lines
Quoted 1 line

Why preserve the fairness logic?

It does need to fair if there is 2 or more sockets with the same priority, otherwise the first connection in the list might get all the quote and even if we promote the starving queues it may still happen to top most priority since there it cannot be promoted anymore.

Quoted 9 lines

Right. What I meant here was this: if the tx scheduler is re-made as priority-based, then it seems logical to discard the fairness logic and design the priority scheme such that starvation is not possible. For example, the pri levels could be like this:
       0 ~ 5   socket-programmable priorities
       6       special CAP_NET_ADMIN priority
       7       only possible via promotion
(Not that I'm suggesting that's the only or even best way to make starvation not possible).

I would like to stick with current approach with bigger than 6 needing CAP_NET_ADMIN which is aligned with with SO_PRIORITY current does, otherwise it would immediately break the current application that uses priority 6. Besides I don't think having one possible promotion index is a good idea, it would completely ignore priorities in starvation case, but there is exactly where it is most needed to throttle lower priorities in favor of higher.

Quoted 9 lines
Quoted 4 lines

You probably have never run this code did you? Only priority 7 can really monopolize the connection, and that is on purpose, and yes lower priority are throttled so higher priority can get lower latency, what is wrong with that?

With no offense meant, simply running this code would be insufficient to qualify it's appropriateness as a replacement scheduler. A bare-minimum test matrix would ascertain comparative values for minimum/mean/maximum latency and throughput for best-case/nominal/worst-case tx loads.

But it would give a hint if your assumption are correct or not.

Quoted 2 lines

My main concern here is that app-level socket settings can have dramatic effects on tx scheduling behavior, especially at near max tx loads.

An that is ultimately what is needed for guaranteed channels (priority 7), best effort is nearly unchanged because there is no guarantees of latency or throughput.

Quoted 5 lines

What I meant about near monopolization is this:  a priority 6 link that retires 2 packets every 55 ms would mean that priority 0 links could only xmit every 330 ms (1/3 sec.), assuming the controller was already saturated by the priority 6 link. Even priority 3 links are only going to be able to xmit every 165ms under these conditions.

So what? the application can and should be set its priority according to not get throttled, it should only be fair with the same priority, the other are left behind. Im gonna be repeating this over and over, best effort channel as we have today have no guarantees (latency, throughput), so it is perfectly ok to throttle them.

Quoted 3 lines

What if, instead, links that are being promoted because the controller is saturated, are promoted to the same (or maybe, higher) priority level than was last successful?

Ive tried that, it breaks the prioritization when it is most needed because it returns the schedulers to its fairness state and complete ignores the priorities.

Quoted 7 lines
Quoted 2 lines

Right now it promotes starving queues, all of them, but maybe it shouldn't so that we simplify the complexity a little bit.

My thinking here is that the tx tasklet shouldn't be scheduled at all if no work can be performed. Of course, the existing code suffers from the same defect. Really, the only reason the tx tasklet *needs* to be scheduled when the relevant buffer counter is 0 is to catch tx timeouts.

Yep, that can indeed be fixed but then we need to find some other place to detect tx timeouts.

Signature · 1 line
Luiz Augusto von Dentz
#11 lore raw
In reply to Luiz Augusto von Dentz

SGkgTHVpeiwNCg0KT24gVGh1LCAyMDExLTA4LTA0IGF0IDA0OjIwIC0wNDAwLCBMdWl6IEF1Z3Vz dG8gdm9uIERlbnR6IHdyb3RlOg0KPiBIaSBQZXRlciwNCj4gDQo+IE9uIFRodSwgQXVnIDQsIDIw MTEgYXQgMTI6MTQgQU0sIFBldGVyIEh1cmxleSA8cGV0ZXJAaHVybGV5c29mdHdhcmUuY29tPiB3 cm90ZToNCj4gPiBIaSBMdWl6LA0KPiA+DQo+ID4gLi4uLi4NCj4gPg0KPiA+IEl0J3MgbXkgYmVs aWVmIHRoYXQgdGhlIGluY3JlZGlibHkgY29tcGxpY2F0ZWQgd2F5IHRoYXQgUHVsc2VBdWRpbw0K PiA+IGhhbmRsZXMgdGhlIHN0cmVhbSBpbmRpY2VzIGFuZCBjb21wdXRlZCBsYXRlbmN5IGlzIHJl YWxseSB0aGUgaXNzdWUgKGF0DQo+ID4gbGVhc3Qgd2l0aCBBMkRQKS4NCj4gDQo+IFJlYWxseSwg c28geW91IG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GF5Lg0KPiANCj4gSXQgcHJvYmFibHkgZG9lcywgYnV0 IGl0IGRvZXNuJ3QgY2hhbmdlIHRoZSBmYWN0IHRoZSBwcmlvcml0aXphdGlvbiBpcw0KPiBwcmV0 dHkgbXVjaCBuZWVkZWQsIGFjdHVhbGx5IGl0IHdpbGwgcHJvYmFibHkgbWFrZSBzdWNoIHByb2Js ZW1zIG1vcmUNCj4gdmlzaWJsZSB0aGFuIGV2ZXIuDQoNCkFncmVlZC4gQXMgSSB3cm90ZSBpbiB0 aGUgb3RoZXIgcG9zdCwgSSB0aGluayBwcmlvcml0eS1iYXNlZCB0eA0Kc2NoZWR1bGluZyBpcyBh biBleGNlbGxlbnQgaWRlYS4NCg0KUmVnYXJkcywNClBldGVyDQoNCg==

#12 lore raw
In reply to Luiz Augusto von Dentz
Quoted 54 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This set of patches uses the priority of the socket, set via SO_PRIORITY, to prioritized data over HCI. Current priority range is from 0-7, where 0-6 priority can be set without any exatra capability which is according to SO_PRIORITY documentation (socket(7)):

SO_PRIORITY

Set the protocol-defined priority for all packets to be sent on this socket. Linux uses this value to order the networking
queues: packets with a higher priority may be processed first depending on the selected device queueing discipline.... Setting a priority outside the range 0 to 6 requires the CAP_NET_ADMIN capability.

This also enables in the future the use of guaranteed channels as it is necessary to prioritized them over best effort (default) channels, Bluetooth V4.0 spec (page 1497):

7.9 PRIORITIZING DATA OVER HCI

In order for guaranteed channels to meet their guarantees, L2CAP should prioritize traffic over the HCI transport in devices that support HCI. Packets for Guaranteed channels should receive higher priority than packets for Best Effort channels.

Note: to be able to use guaranteed channels we need to negotiate QoS parameters both in L2CAP and HCI, this is outside of the scope of this patches since it probably requires new socket options to L2CAP sockets.

The main use case for this is A2DP, many people complained that when they are using their HID devices (mouses) together with headset the mouse has higher priority, which btw is not true since currently there is no priority and connections receives the same quote.

With this changes it may reduce the problem since PulseAudio already sets A2DP socket as low latency (priority 6), which means audio packets will be processed before the HID packets, but this only affects tx and there still exist the problem of some HID not letting us being master.

Ive been testing this using A2DP and HID connected simultaneusly without a problem, though connecting/paging still makes audio skips, and also tried OBEX transfers together to see if audio skips, indeed it does when HID is active but it works better than having no priority (skips less frequent) and in case of using priority 7 the audio doesn't skip anymore but it eventually stall the OBEX transfer (this is maybe because OpenOBEX loop while trying to write to socket and don't wait for POLLOUT).

Luiz Augusto von Dentz (3):
Bluetooth: prioritizing data over HCI
Bluetooth: set skbuffer priority based on L2CAP socket priority
Bluetooth: make use sk_priority to priritize RFCOMM packets

Quoted 12 lines
include/net/bluetooth/hci_core.h |    6 ++-
include/net/bluetooth/l2cap.h    |    3 +-
net/bluetooth/hci_conn.c         |    8 ++-
net/bluetooth/hci_core.c         |  141 +++++++++++++++++++++++++++----------
net/bluetooth/l2cap_core.c       |   47 +++++++++----
net/bluetooth/l2cap_sock.c       |    2 +-
net/bluetooth/rfcomm/core.c      |   51 +++++++++----
net/bluetooth/rfcomm/sock.c      |    8 ++
8 files changed, 194 insertions(+), 72 deletions(-)
Signature · 1 line
1.7.6

Luiz -

Thanks for making the effort to improve the scheduler! The AMP code I'm upstreaming has some more building blocks for QoS, so we are getting closer to QoS support.

One concern I have is that an application that changes sk_priority while it has data in the HCI tx queue could have its frames delivered out of order. While we can't control when sk_priority is set, it is possible to make a choice when setting the priority of each skb. Does it make sense to detect an sk_priority change and only apply the new value when there are no skbs for the channel in the HCI tx queue?

I had a recent discussion with Gustavo about HCI queuing issues with ERTM:

http://www.spinics.net/lists/linux-bluetooth/msg13774.html

My proposal is to move tx queuing up to L2CAP, and have the HCI tx task only handle scheduling. Senders would tell HCI they have data to send, and HCI would call back to pull data. I've been focused on L2CAP - it would be possible to make a similar queuing change to SCO/eSCO/LE, but not strictly necessary.

This is different from the problem you're solving, but as long as we're talking about big changes to HCI tx, I think we could make some changes that help out with prioritization and queuing across all channels (whether they're going to the same remote device or different remote devices).

It could be more efficient to schedule this way since HCI wouldn't have to iterate over all of the connections and queues - it would only have to review the prioritized list of pending sends. Might be a more fitting structure for QoS too.

Since HCI wouldn't have a bunch of queued-up skbs, it would also eliminate the sk_priority change problem I noted above.

Your thoughts?

--
Mat Martineau
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum

#13 lore raw

SGkgTWF0LA0KDQpPbiBUaHUsIDIwMTEtMDgtMDQgYXQgMTM6MzcgLTA0MDAsIE1hdCBNYXJ0aW5l YXUgd3JvdGU6DQoNCj4gSSBoYWQgYSByZWNlbnQgZGlzY3Vzc2lvbiB3aXRoIEd1c3Rhdm8gYWJv dXQgSENJIHF1ZXVpbmcgaXNzdWVzIHdpdGggDQo+IEVSVE06DQo+IA0KPiBodHRwOi8vd3d3LnNw aW5pY3MubmV0L2xpc3RzL2xpbnV4LWJsdWV0b290aC9tc2cxMzc3NC5odG1sDQo+IA0KPiBNeSBw cm9wb3NhbCBpcyB0byBtb3ZlIHR4IHF1ZXVpbmcgdXAgdG8gTDJDQVAsIGFuZCBoYXZlIHRoZSBI Q0kgdHggDQo+IHRhc2sgb25seSBoYW5kbGUgc2NoZWR1bGluZy4gIFNlbmRlcnMgd291bGQgdGVs bCBIQ0kgdGhleSBoYXZlIGRhdGEgdG8gDQo+IHNlbmQsIGFuZCBIQ0kgd291bGQgY2FsbCBiYWNr IHRvIHB1bGwgZGF0YS4gIEkndmUgYmVlbiBmb2N1c2VkIG9uIA0KPiBMMkNBUCAtIGl0IHdvdWxk IGJlIHBvc3NpYmxlIHRvIG1ha2UgYSBzaW1pbGFyIHF1ZXVpbmcgY2hhbmdlIHRvIA0KPiBTQ08v ZVNDTy9MRSwgYnV0IG5vdCBzdHJpY3RseSBuZWNlc3NhcnkuDQoNCldvdWxkIHlvdSBwbGVhc2Ug Y2xhcmlmeSB0aGlzIGFwcHJvYWNoIChwZXJoYXBzIGluIGEgc2VwYXJhdGUgdGhyZWFkKT8NCg0K Rm9yIGV4YW1wbGUsIGhvdyBkb2VzIGhhdmluZyB0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C0gaXQgd291bGQgb25seSANCj4gaGF2ZSB0byByZXZpZXcgdGhlIHByaW9yaXRp emVkIGxpc3Qgb2YgcGVuZGluZyBzZW5kcy4gTWlnaHQgYmUgYSBtb3JlIA0KPiBmaXR0aW5nIHN0 cnVjdHVyZSBmb3IgUW9TIHRvby4NCg0KV291bGRuJ3QgdGhpcyAncHJpb3JpdGl6ZWQgbGlzdCBv ZiBwZW5kaW5nIHNlbmRzJyBuZWVkIHRvIGJlIGxvY2tlZCB0bw0KcHJldmVudCB1cGRhdGUgd2hp bGUgcmVhZGluZz8gSVNUTSB0aGF0IGNvbnRlbnRpb24gbWlnaHQgYmUgZmFpcmx5IGhpZ2gNCmZv ciBhIHNpbmdsZSwgc2hhcmVkIHJlc291cmNlIGxpa2UgdGhhdC4NCg0KDQpSZWdhcmRzLA0KUGV0 ZXIgSHVybGV5DQoNCg==

author maintainer
#22 lore raw
In reply to Mat Martineau

Hi Mat,

Quoted 6 lines · Mat Martineau

One concern I have is that an application that changes sk_priority while it has data in the HCI tx queue could have its frames delivered out of order. While we can't control when sk_priority is set, it is possible to make a choice when setting the priority of each skb.  Does it make sense to detect an sk_priority change and only apply the new value when there are no skbs for the channel in the HCI tx queue?

Yep, if we need to maintain the order I guess this would make sense, the problem is that this could be a bit expensive.

Quoted 20 lines

I had a recent discussion with Gustavo about HCI queuing issues with ERTM:

http://www.spinics.net/lists/linux-bluetooth/msg13774.html

My proposal is to move tx queuing up to L2CAP, and have the HCI tx task only handle scheduling.  Senders would tell HCI they have data to send, and HCI would call back to pull data.  I've been focused on L2CAP - it would be possible to make a similar queuing change to SCO/eSCO/LE, but not strictly necessary.

This is different from the problem you're solving, but as long as we're talking about big changes to HCI tx, I think we could make some changes that help out with prioritization and queuing across all channels (whether they're going to the same remote device or different remote devices).

It could be more efficient to schedule this way since HCI wouldn't have to iterate over all of the connections and queues - it would only have to review the prioritized list of pending sends. Might be a more fitting structure for QoS too.

Quoted 4 lines

Since HCI wouldn't have a bunch of queued-up skbs, it would also eliminate the sk_priority change problem I noted above.

Your thoughts?

If the idea is to have a list of chan/sockets and each having its own queue, I guess that would make sense and we could possible preserve the packet order in that case, but we still have to maintain the fairness when dealing with the same priority so I would still have to iterate to each connection and then to each channel evaluating their priority. This way we don't have to defined any arbitrary number of queues which is probably less items to visit on tx task, but the locking may be a lot more complicated.

Signature · 1 line
Luiz Augusto von Dentz
#14 lore raw
In reply to Peter Hurley
Quoted 15 lines · Peter Hurley

Hi Mat,

Quoted 10 lines · Mat Martineau

I had a recent discussion with Gustavo about HCI queuing issues with ERTM:

http://www.spinics.net/lists/linux-bluetooth/msg13774.html

My proposal is to move tx queuing up to L2CAP, and have the HCI tx task only handle scheduling. Senders would tell HCI they have data to send, and HCI would call back to pull data. I've been focused on L2CAP - it would be possible to make a similar queuing change to SCO/eSCO/LE, but not strictly necessary.

Quoted 8 lines

Would you please clarify this approach (perhaps in a separate thread)?

For example, how does having tx queues in l2cap_chan (instead of the hci_conn) solve the latency problems in ERTM when replying to REJ/SREJ/poll? Won't there potentially be just as much data already queued up? Is the plan to move the reply to the front of the tx queue because reqseq won't need to be assigned until the frame is actually pulled off the queue?

Exactly. ERTM connections can get dropped if the too much data is buffered and we need to send final bit for example.

Quoted 12 lines
Quoted 11 lines

This is different from the problem you're solving, but as long as we're talking about big changes to HCI tx, I think we could make some changes that help out with prioritization and queuing across all channels (whether they're going to the same remote device or different remote devices).

It could be more efficient to schedule this way since HCI wouldn't have to iterate over all of the connections and queues - it would only have to review the prioritized list of pending sends. Might be a more fitting structure for QoS too.

Quoted 8 lines

Wouldn't this 'prioritized list of pending sends' need to be locked to prevent update while reading? ISTM that contention might be fairly high for a single, shared resource like that.

Regards,
Peter Hurley

Gustavo

#23 lore raw
In reply to Luiz Augusto von Dentz
Quoted 38 lines · Luiz Augusto von Dentz

Hi Mat,

Quoted 6 lines · Mat Martineau

One concern I have is that an application that changes sk_priority while it has data in the HCI tx queue could have its frames delivered out of order. While we can't control when sk_priority is set, it is possible to make a choice when setting the priority of each skb.  Does it make sense to detect an sk_priority change and only apply the new value when there are no skbs for the channel in the HCI tx queue?

Yep, if we need to maintain the order I guess this would make sense, the problem is that this could be a bit expensive.

Quoted 20 lines

I had a recent discussion with Gustavo about HCI queuing issues with ERTM:

http://www.spinics.net/lists/linux-bluetooth/msg13774.html

My proposal is to move tx queuing up to L2CAP, and have the HCI tx task only handle scheduling.  Senders would tell HCI they have data to send, and HCI would call back to pull data.  I've been focused on L2CAP - it would be possible to make a similar queuing change to SCO/eSCO/LE, but not strictly necessary.

This is different from the problem you're solving, but as long as we're talking about big changes to HCI tx, I think we could make some changes that help out with prioritization and queuing across all channels (whether they're going to the same remote device or different remote devices).

It could be more efficient to schedule this way since HCI wouldn't have to iterate over all of the connections and queues - it would only have to review the prioritized list of pending sends. Might be a more fitting structure for QoS too.

Quoted 4 lines

Since HCI wouldn't have a bunch of queued-up skbs, it would also eliminate the sk_priority change problem I noted above.

Your thoughts?

Quoted 8 lines

If the idea is to have a list of chan/sockets and each having its own queue, I guess that would make sense and we could possible preserve the packet order in that case, but we still have to maintain the fairness when dealing with the same priority so I would still have to iterate to each connection and then to each channel evaluating their priority. This way we don't have to defined any arbitrary number of queues which is probably less items to visit on tx task, but the locking may be a lot more complicated.

Only ERTM needs to have its own queue, Basic and Streaming mode doesn't need to change, they can use the same queue they are using now.

Gustavo

author maintainer
#24 lore raw

Hi Gustavo,

Quoted 3 lines · Gustavo Padovan

Only ERTM needs to have its own queue, Basic and Streaming mode doesn't need to change, they can use the same queue they are using now.

The guaranteed channels also seems to need separated queue, actually even best effort channels could use QoS (see page 1442 :5.3 QUALITY OF SERVICE (QOS) OPTION). Note this is a general option which is then negotiated also on HCI level, it seems completely independent of ERTM.

The per channel queuing is almost a must have if we really want to be able to implement any QoS, because then we can track exactly what channels are sending, calculate if we can attend the QoS needs and so on. But I don't think doing this on L2CAP level is a good idea, because it create a circular dependency with HCI and the pull mode might create a locking nightmare, not to mention L2CAP is already quite big.

One of the solution Ive been thinking is to have an HCI Channel (e.g. struct hci_chan) abstraction, which would be responsible for queueing and storing necessary information for scheduling. This could be implemented directly in HCI level (hci_conn.c) so L2CAP can still push data to HCI by using the HCI Channel (l2cap_chan->hci_chan). How about that?

Signature · 1 line
Luiz Augusto von Dentz
#25 lore raw

Hi Luiz,

Quoted 11 lines · Luiz Augusto von Dentz

Hi Gustavo,

Quoted 3 lines · Gustavo Padovan

Only ERTM needs to have its own queue, Basic and Streaming mode doesn't need to change, they can use the same queue they are using now.

The guaranteed channels also seems to need separated queue, actually even best effort channels could use QoS (see page 1442 :5.3 QUALITY OF SERVICE (QOS) OPTION). Note this is a general option which is then negotiated also on HCI level, it seems completely independent of ERTM.

What I tried to say is that ERTM needs to prioritize some frames (SREJ, REJ, poll and final bits, resends) to improve the throughput. This is independent of the QoS of the channel. So we need to postpone the queueing into conn->data_q until the last moment before send it to the hci_dev.

Quoted 9 lines

The per channel queuing is almost a must have if we really want to be able to implement any QoS, because then we can track exactly what channels are sending, calculate if we can attend the QoS needs and so on. But I don't think doing this on L2CAP level is a good idea, because it create a circular dependency with HCI and the pull mode might create a locking nightmare, not to mention L2CAP is already quite big.

Quoted 6 lines

One of the solution Ive been thinking is to have an HCI Channel (e.g. struct hci_chan) abstraction, which would be responsible for queueing and storing necessary information for scheduling. This could be implemented directly in HCI level (hci_conn.c) so L2CAP can still push data to HCI by using the HCI Channel (l2cap_chan->hci_chan). How about that?

This doesn't work ERTM. I've been thinking on keep both the normal ERTM queue and the prio qeue inside L2CAP and the create some callbacks, then HCI can ask L2CAP channel to deliver the frames it have queued. ERTM would first clear it prio queue and then the normal queue, and before send each of packets to HCI ERTM have to set packet header properly.

You approach can work for the other L2CAP modes.

Gustavo

#15 lore raw
In reply to Gustavo Padovan
Quoted 26 lines · Gustavo Padovan
Quoted 15 lines · Peter Hurley

Hi Mat,

Quoted 10 lines · Mat Martineau

I had a recent discussion with Gustavo about HCI queuing issues with ERTM:

http://www.spinics.net/lists/linux-bluetooth/msg13774.html

My proposal is to move tx queuing up to L2CAP, and have the HCI tx task only handle scheduling. Senders would tell HCI they have data to send, and HCI would call back to pull data. I've been focused on L2CAP - it would be possible to make a similar queuing change to SCO/eSCO/LE, but not strictly necessary.

Quoted 8 lines

Would you please clarify this approach (perhaps in a separate thread)?

For example, how does having tx queues in l2cap_chan (instead of the hci_conn) solve the latency problems in ERTM when replying to REJ/SREJ/poll? Won't there potentially be just as much data already queued up? Is the plan to move the reply to the front of the tx queue because reqseq won't need to be assigned until the frame is actually pulled off the queue?

Quoted 2 lines

Exactly. ERTM connections can get dropped if the too much data is buffered and we need to send final bit for example.

Right now, an outgoing ERTM frame goes through two queues: a channel-specific ERTM tx queue and the HCI ACL data_q. The ERTM control field is not constructed until a frame is removed from the ERTM tx queue and pushed to the HCI data_q, so the s-frame latency problem comes in when the the HCI data_q gets deep. S-frames are already pushed directly in to the HCI data_q, bypassing the data tx queue.

Quoted 1 line

From an ERTM perspective, the goal is to defer assignment of reqseq

and f-bit values as late as possible, so the remote device gets the most recent information on data frames and polls that have been received. The optimal thing to do (by this measurement, anyway) is to build the ERTM control field as data is sent to the baseband -- in other words, to eliminate the HCI data_q altogether.

(Yeah, without the data_q, ERTM would need additional queues for s-frames and retransmitted i-frames)

So, without a data_q, what makes sense? If there are ACL buffers available and no pending L2CAP senders, it would be great to push data straight out to the baseband. If we're blocked waiting for num_completed_packets, then receipt of num_completed_packets is the natural time to pull data from the tx queues that now happen to be up in the L2CAP layer.

There are certainly locking, task scheduling, data scheduling, QoS, and efficiency issues to consider. This is just a general description for now, and I'm trying to see if there's enough interest (or few enough obvious gotchas) to put some serious effort in to moving forward.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

This is different from the problem you're solving, but as long as we're talking about big changes to HCI tx, I think we could make some changes that help out with prioritization and queuing across all channels (whether they're going to the same remote device or different remote devices).

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

It could be more efficient to schedule this way since HCI wouldn't have to iterate over all of the connections and queues - it would only have to review the prioritized list of pending sends. Might be a more fitting structure for QoS too.

Wouldn't this 'prioritized list of pending sends' need to be locked to prevent update while reading? ISTM that contention might be fairly high for a single, shared resource like that.

If there was a prioritized list that was manipulated on multiple threads, then a lock certainly would be required. Maybe it would work to keep the information sent between threads pretty simple (just an "I have data" bit), then any complex lists could be manipulated in a more controlled HCI-only context. The prioritization code could run only when processing num_completed_packets.

Thanks for the great feedback so far! Seeing any major flaws at this high level?

Regards,

--
Mat Martineau
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum

#16 lore raw
Quoted 57 lines · Mat Martineau
Quoted 26 lines · Gustavo Padovan
Quoted 15 lines · Peter Hurley

Hi Mat,

Quoted 10 lines · Mat Martineau

I had a recent discussion with Gustavo about HCI queuing issues with ERTM:

http://www.spinics.net/lists/linux-bluetooth/msg13774.html

My proposal is to move tx queuing up to L2CAP, and have the HCI tx task only handle scheduling. Senders would tell HCI they have data to send, and HCI would call back to pull data. I've been focused on L2CAP - it would be possible to make a similar queuing change to SCO/eSCO/LE, but not strictly necessary.

Quoted 8 lines

Would you please clarify this approach (perhaps in a separate thread)?

For example, how does having tx queues in l2cap_chan (instead of the hci_conn) solve the latency problems in ERTM when replying to REJ/SREJ/poll? Won't there potentially be just as much data already queued up? Is the plan to move the reply to the front of the tx queue because reqseq won't need to be assigned until the frame is actually pulled off the queue?

Quoted 2 lines

Exactly. ERTM connections can get dropped if the too much data is buffered and we need to send final bit for example.

Right now, an outgoing ERTM frame goes through two queues: a channel-specific ERTM tx queue and the HCI ACL data_q. The ERTM control field is not constructed until a frame is removed from the ERTM tx queue and pushed to the HCI data_q, so the s-frame latency problem comes in when the the HCI data_q gets deep. S-frames are already pushed directly in to the HCI data_q, bypassing the data tx queue.

From an ERTM perspective, the goal is to defer assignment of reqseq and f-bit values as late as possible, so the remote device gets the most recent information on data frames and polls that have been received. The optimal thing to do (by this measurement, anyway) is to build the ERTM control field as data is sent to the baseband -- in other words, to eliminate the HCI data_q altogether.

(Yeah, without the data_q, ERTM would need additional queues for s-frames and retransmitted i-frames)

So, without a data_q, what makes sense? If there are ACL buffers available and no pending L2CAP senders, it would be great to push data straight out to the baseband. If we're blocked waiting for num_completed_packets, then receipt of num_completed_packets is the natural time to pull data from the tx queues that now happen to be up in the L2CAP layer.

Quoted 5 lines

There are certainly locking, task scheduling, data scheduling, QoS, and efficiency issues to consider. This is just a general description for now, and I'm trying to see if there's enough interest (or few enough obvious gotchas) to put some serious effort in to moving forward.

Getting rid of conn->data_q makes sense. I started a patch to create the struct hci_chan that Luiz proposed. It would be one HCI channel per L2CAP connection. The buffer (acl_cnt) would be now divided by the number of channels and not the number of connections. This is a first step to support QoS and priority inside ERTM. QoS then would just need new scheduler rules.

+struct hci_chan {

+       struct list_head list;
+       struct hci_conn *conn;
+       struct sk_buff_head data_q;
+       unsigned int    sent;

+}

So in the next step for ERTM we move the queue to L2CAP and create a callback to call from HCI at the moment of push data to the baseband. The function in L2CAP would set the last control bits in the first packet of the queue and sent it through.

Then the queue can be split in two by adding a pointer that will mark which element divides the queue between prio and normal. New prio skbs would just be queued after this element and before the rest.

I still need to think on locking here. (and also finish my patches that move all the bluetooth to workqueue)

Gustavo

#17 lore raw
Quoted 71 lines · Gustavo Padovan
Quoted 57 lines · Mat Martineau
Quoted 26 lines · Gustavo Padovan
Quoted 15 lines · Peter Hurley

Hi Mat,

Quoted 10 lines · Mat Martineau

I had a recent discussion with Gustavo about HCI queuing issues with ERTM:

http://www.spinics.net/lists/linux-bluetooth/msg13774.html

My proposal is to move tx queuing up to L2CAP, and have the HCI tx task only handle scheduling. Senders would tell HCI they have data to send, and HCI would call back to pull data. I've been focused on L2CAP - it would be possible to make a similar queuing change to SCO/eSCO/LE, but not strictly necessary.

Quoted 8 lines

Would you please clarify this approach (perhaps in a separate thread)?

For example, how does having tx queues in l2cap_chan (instead of the hci_conn) solve the latency problems in ERTM when replying to REJ/SREJ/poll? Won't there potentially be just as much data already queued up? Is the plan to move the reply to the front of the tx queue because reqseq won't need to be assigned until the frame is actually pulled off the queue?

Quoted 2 lines

Exactly. ERTM connections can get dropped if the too much data is buffered and we need to send final bit for example.

Right now, an outgoing ERTM frame goes through two queues: a channel-specific ERTM tx queue and the HCI ACL data_q. The ERTM control field is not constructed until a frame is removed from the ERTM tx queue and pushed to the HCI data_q, so the s-frame latency problem comes in when the the HCI data_q gets deep. S-frames are already pushed directly in to the HCI data_q, bypassing the data tx queue.

From an ERTM perspective, the goal is to defer assignment of reqseq and f-bit values as late as possible, so the remote device gets the most recent information on data frames and polls that have been received. The optimal thing to do (by this measurement, anyway) is to build the ERTM control field as data is sent to the baseband -- in other words, to eliminate the HCI data_q altogether.

(Yeah, without the data_q, ERTM would need additional queues for s-frames and retransmitted i-frames)

So, without a data_q, what makes sense? If there are ACL buffers available and no pending L2CAP senders, it would be great to push data straight out to the baseband. If we're blocked waiting for num_completed_packets, then receipt of num_completed_packets is the natural time to pull data from the tx queues that now happen to be up in the L2CAP layer.

Quoted 5 lines

There are certainly locking, task scheduling, data scheduling, QoS, and efficiency issues to consider. This is just a general description for now, and I'm trying to see if there's enough interest (or few enough obvious gotchas) to put some serious effort in to moving forward.

Getting rid of conn->data_q makes sense. I started a patch to create the struct hci_chan that Luiz proposed. It would be one HCI channel per L2CAP connection. The buffer (acl_cnt) would be now divided by the number of channels and not the number of connections. This is a first step to support QoS and priority inside ERTM. QoS then would just need new scheduler rules.

Review

Quoted 6 lines
(quoted diff) +6 -0
+struct hci_chan {
+       struct list_head list;
+       struct hci_conn *conn;
+       struct sk_buff_head data_q;
+       unsigned int    sent;
+}

At the BlueZ summit last year, the group settled on using an "HCI channel" as an abstraction for AMP logical links. We have a hci_chan struct already that you could add to. Before making changes to HCI data structures, could we first work on upstreaming the AMP HCI changes (which also include some QoS-related code)?

Quoted 4 lines

So in the next step for ERTM we move the queue to L2CAP and create a callback to call from HCI at the moment of push data to the baseband. The function in L2CAP would set the last control bits in the first packet of the queue and sent it through.

This actually causes some problems for ERTM, since skbs are cloned before they are pushed to HCI. skb data is not supposed to be modified after cloning.

If there's a callback to L2CAP anyway, why not have L2CAP provide the skb at that time instead of modifying data it provided earlier?

Quoted 3 lines

Then the queue can be split in two by adding a pointer that will mark which element divides the queue between prio and normal. New prio skbs would just be queued after this element and before the rest.

I think it's simpler and less bug-prone to just have two queues. Either way, it's one more pointer.

However, I'm still not sure we want any queues in hci_chan. It's not very complicated to have the queue in the L2CAP layer, and gives ERTM the control it needs.

Quoted 1 line

I still need to think on locking here. (and also finish my patches that move all the bluetooth to workqueue)

Keep in mind that skb_queue() and skb_dequeue() have their own locking. Non-ERTM modes shouldn't need locking when HCI calls back for skbs.

For ERTM, we need to figure out a good way to protect ERTM state (like buffer_seq and next_tx_seq) without using the socket lock.

--
Mat Martineau
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum

author maintainer
#18 lore raw

Hi Mat,

Quoted 4 lines · Mat Martineau
Quoted 4 lines

+struct hci_chan {
+       struct list_head list;
+       struct hci_conn *conn;
+       struct sk_buff_head data_q;

Quoted 8 lines
Quoted 2 lines

+       unsigned int    sent;
+}

At the BlueZ summit last year, the group settled on using an "HCI channel" as an abstraction for AMP logical links.  We have a hci_chan struct already that you could add to.  Before making changes to HCI data structures, could we first work on upstreaming the AMP HCI changes (which also include some QoS-related code)?

If just you told us this before I would have not spend time implementing it, so could you please sent this patches ASAP, otherwise I will just send mine that just address the prioritization

Btw, the thread intent is perhaps becoming too broad, we should focus in small steps lets say first HCI Channel, then we continue from there.

Signature · 1 line
Luiz Augusto von Dentz
#20 lore raw
In reply to Mat Martineau

T24gV2VkLCAyMDExLTA4LTEwIGF0IDEzOjM4IC0wNDAwLCBNYXQgTWFydGluZWF1IHdyb3RlOg0K PiANCj4gT24gVHVlLCA5IEF1ZyAyMDExLCBHdXN0YXZvIFBhZG92YW4gd3JvdGU6DQo+IA0KPiA+ ICogTWF0IE1hcnRpbmVhdSA8bWF0aGV3bUBjb2RlY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dCByaWdo dCBub3cgdGhlIEVSVE0gdHhfcSBpcyBhIHByaXZhdGUgcXVldWUuIFdoZW4gdGhpcw0KYmVjb21l cyBzaGFyZWQsIHdlIG5lZWQgdG8gaGF2ZSBhbHJlYWR5IHdvcmtlZCBvdXQgaG93IHRvIGF2b2lk IHRoZQ0Kc2l0dWF0aW9uIHdoZXJlIHRoZSBzY2hlZHVsZXIgaXMgaGVsZCB1cCB3YWl0aW5nIGZv ciBhbiBFUlRNIGNoYW5uZWwgdG8NCmRyb3BwZWQgaXRzIGFja2VkIGZyYW1lcywgZm9yIGV4YW1w bGUuDQoNCj4gRm9yIEVSVE0sIHdlIG5lZWQgdG8gZmlndXJlIG91dCBhIGdvb2Qgd2F5IHRvIHBy b3RlY3QgRVJUTSBzdGF0ZSAobGlrZSANCj4gYnVmZmVyX3NlcSBhbmQgbmV4dF90eF9zZXEpIHdp dGhvdXQgdXNpbmcgdGhlIHNvY2tldCBsb2NrLg0KDQpBbmQgdGhpcy4NCg0KVGhhbmtzIGFnYWlu IGFuZCByZWdhcmRzLA0KUGV0ZXIgSHVybGV5DQoNCg==

#19 lore raw
In reply to Luiz Augusto von Dentz

Hi Luiz -

Quoted 16 lines · Luiz Augusto von Dentz

Hi Mat,

Quoted 4 lines · Mat Martineau
Quoted 4 lines

+struct hci_chan {
+       struct list_head list;
+       struct hci_conn *conn;
+       struct sk_buff_head data_q;

Quoted 8 lines
Quoted 2 lines

+       unsigned int    sent;
+}

At the BlueZ summit last year, the group settled on using an "HCI channel" as an abstraction for AMP logical links.  We have a hci_chan struct already that you could add to.  Before making changes to HCI data structures, could we first work on upstreaming the AMP HCI changes (which also include some QoS-related code)?

Quoted 3 lines

If just you told us this before I would have not spend time implementing it, so could you please sent this patches ASAP, otherwise I will just send mine that just address the prioritization

Your RFC patches for prioritized HCI queues are not in conflict with the AMP code. It's just the proposed hci_chan structure that came up in this email thread.

My recent patches are the beginning of AMP upstreaming. I was trying to get the generic L2CAP improvements in place first. One of my coworkers is starting to work in parallel on upstreaming the HCI changes, but we need to create a suitable patch series for bluetooth-next.

Quoted 3 lines

Btw, the thread intent is perhaps becoming too broad, we should focus in small steps lets say first HCI Channel, then we continue from there.

I agree, it's hard to keep track of the various sub-threads at this point. The HCI channel is a good place to start.

--
Mat Martineau
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum

maintainer
#21 lore raw
In reply to Mat Martineau

Hi Mat,

<snip>

Quoted 17 lines
Quoted 4 lines

So in the next step for ERTM we move the queue to L2CAP and create a callback to call from HCI at the moment of push data to the baseband. The function in L2CAP would set the last control bits in the first packet of the queue and sent it through.

This actually causes some problems for ERTM, since skbs are cloned before they are pushed to HCI. skb data is not supposed to be modified after cloning.

If there's a callback to L2CAP anyway, why not have L2CAP provide the skb at that time instead of modifying data it provided earlier?

Quoted 3 lines

Then the queue can be split in two by adding a pointer that will mark which element divides the queue between prio and normal. New prio skbs would just be queued after this element and before the rest.

Quoted 6 lines

I think it's simpler and less bug-prone to just have two queues. Either way, it's one more pointer.

However, I'm still not sure we want any queues in hci_chan. It's not very complicated to have the queue in the L2CAP layer, and gives ERTM the control it needs.

I am fine if we just queue in L2CAP actually. Since nobody should send ACL packets directly (besides the crazy people that wanna abuse BlueZ's support for HCI_RAW for 3rd party stacks) anyway.

In a real fully integrated stack only L2CAP will send ACL data packets and we can just rely on that fact if want to.

Regards

Marcel