Bluetooth: prioritizing data over HCI
Subsystems (2)
Luiz Augusto von Dentz
maintainerRFC v2 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 exclusive use of bandwidth but may starve other connections thus need to be used with care.
--- include/net/bluetooth/hci_core.h | 22 ++++- net/bluetooth/hci_conn.c | 8 +- net/bluetooth/hci_core.c | 200 +++++++++++++++++++++++++++++--------- net/bluetooth/rfcomm/sock.c | 8 ++ 4 files changed, 187 insertions(+), 51 deletions(-)
include/net/bluetooth/hci_core.h +21 -1
@@ -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;
@@ -395,6 +399,22 @@ static inline void hci_conn_hash_del(struct hci_dev *hdev, struct hci_conn *c) } } +static inline unsigned int hci_conn_num (struct hci_dev *hdev,__u8 type) +{ +struct hci_conn_hash *h = &hdev->conn_hash; +switch (type) { +case ACL_LINK : +return h->acl_num; +case LE_LINK : +return h->le_num; +case SCO_LINK : +case ESCO_LINK : +return h->sco_num; +default : +return 0 ; + } +} +static inline struct hci_conn *hci_conn_hash_lookup_handle (struct hci_dev *hdev,__u16 handle) {
net/bluetooth/hci_conn.c +6 -2
@@ -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 +152 -48
372 lines not on this page · raw message
net/bluetooth/rfcomm/sock.c +8 -0
@@ -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