Skip to content

Commit 73d80de

Browse files
VudentzGustavo F. Padovan
authored andcommitted
Bluetooth: prioritizing data over HCI
This implement priority based scheduler using skbuffer priority set via SO_PRIORITY socket option. It introduces hci_chan_hash (list of HCI Channel/hci_chan) per connection, each item in this list refer to a L2CAP connection and it is used to queue the data for transmission. Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com> Acked-by: Marcel Holtmann <marcel@holtmann.org> Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
1 parent 3c32fa9 commit 73d80de

6 files changed

Lines changed: 251 additions & 55 deletions

File tree

‎include/net/bluetooth/hci_core.h‎

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ struct hci_conn_hash {
6767
unsigned int le_num;
6868
};
6969

70+
struct hci_chan_hash {
71+
struct list_head list;
72+
spinlock_t lock;
73+
unsigned int num;
74+
};
75+
7076
struct bdaddr_list {
7177
struct list_head list;
7278
bdaddr_t bdaddr;
@@ -287,6 +293,7 @@ struct hci_conn {
287293
unsigned int sent;
288294

289295
struct sk_buff_head data_q;
296+
struct hci_chan_hash chan_hash;
290297

291298
struct timer_list disc_timer;
292299
struct timer_list idle_timer;
@@ -309,6 +316,14 @@ struct hci_conn {
309316
void (*disconn_cfm_cb) (struct hci_conn *conn, u8 reason);
310317
};
311318

319+
struct hci_chan {
320+
struct list_head list;
321+
322+
struct hci_conn *conn;
323+
struct sk_buff_head data_q;
324+
unsigned int sent;
325+
};
326+
312327
extern struct hci_proto *hci_proto[];
313328
extern struct list_head hci_dev_list;
314329
extern struct list_head hci_cb_list;
@@ -469,6 +484,28 @@ static inline struct hci_conn *hci_conn_hash_lookup_state(struct hci_dev *hdev,
469484
return NULL;
470485
}
471486

487+
static inline void hci_chan_hash_init(struct hci_conn *c)
488+
{
489+
struct hci_chan_hash *h = &c->chan_hash;
490+
INIT_LIST_HEAD(&h->list);
491+
spin_lock_init(&h->lock);
492+
h->num = 0;
493+
}
494+
495+
static inline void hci_chan_hash_add(struct hci_conn *c, struct hci_chan *chan)
496+
{
497+
struct hci_chan_hash *h = &c->chan_hash;
498+
list_add(&chan->list, &h->list);
499+
h->num++;
500+
}
501+
502+
static inline void hci_chan_hash_del(struct hci_conn *c, struct hci_chan *chan)
503+
{
504+
struct hci_chan_hash *h = &c->chan_hash;
505+
list_del(&chan->list);
506+
h->num--;
507+
}
508+
472509
void hci_acl_connect(struct hci_conn *conn);
473510
void hci_acl_disconn(struct hci_conn *conn, __u8 reason);
474511
void hci_add_sco(struct hci_conn *conn, __u16 handle);
@@ -480,6 +517,10 @@ int hci_conn_del(struct hci_conn *conn);
480517
void hci_conn_hash_flush(struct hci_dev *hdev);
481518
void hci_conn_check_pending(struct hci_dev *hdev);
482519

520+
struct hci_chan *hci_chan_create(struct hci_conn *conn);
521+
int hci_chan_del(struct hci_chan *chan);
522+
void hci_chan_hash_flush(struct hci_conn *conn);
523+
483524
struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst,
484525
__u8 sec_level, __u8 auth_type);
485526
int hci_conn_check_link_mode(struct hci_conn *conn);
@@ -849,7 +890,7 @@ int hci_register_notifier(struct notifier_block *nb);
849890
int hci_unregister_notifier(struct notifier_block *nb);
850891

851892
int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen, void *param);
852-
void hci_send_acl(struct hci_conn *conn, struct sk_buff *skb, __u16 flags);
893+
void hci_send_acl(struct hci_chan *chan, struct sk_buff *skb, __u16 flags);
853894
void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb);
854895

855896
void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode);

‎include/net/bluetooth/l2cap.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ struct l2cap_ops {
451451

452452
struct l2cap_conn {
453453
struct hci_conn *hcon;
454+
struct hci_chan *hchan;
454455

455456
bdaddr_t *dst;
456457
bdaddr_t *src;

‎net/bluetooth/hci_conn.c‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,8 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst)
374374

375375
skb_queue_head_init(&conn->data_q);
376376

377+
hci_chan_hash_init(conn);
378+
377379
setup_timer(&conn->disc_timer, hci_conn_timeout, (unsigned long)conn);
378380
setup_timer(&conn->idle_timer, hci_conn_idle, (unsigned long)conn);
379381
setup_timer(&conn->auto_accept_timer, hci_conn_auto_accept,
@@ -432,6 +434,8 @@ int hci_conn_del(struct hci_conn *conn)
432434

433435
tasklet_disable(&hdev->tx_task);
434436

437+
hci_chan_hash_flush(conn);
438+
435439
hci_conn_hash_del(hdev, conn);
436440
if (hdev->notify)
437441
hdev->notify(hdev, HCI_NOTIFY_CONN_DEL);
@@ -950,3 +954,52 @@ int hci_get_auth_info(struct hci_dev *hdev, void __user *arg)
950954

951955
return copy_to_user(arg, &req, sizeof(req)) ? -EFAULT : 0;
952956
}
957+
958+
struct hci_chan *hci_chan_create(struct hci_conn *conn)
959+
{
960+
struct hci_dev *hdev = conn->hdev;
961+
struct hci_chan *chan;
962+
963+
BT_DBG("%s conn %p", hdev->name, conn);
964+
965+
chan = kzalloc(sizeof(struct hci_chan), GFP_ATOMIC);
966+
if (!chan)
967+
return NULL;
968+
969+
chan->conn = conn;
970+
skb_queue_head_init(&chan->data_q);
971+
972+
tasklet_disable(&hdev->tx_task);
973+
hci_chan_hash_add(conn, chan);
974+
tasklet_enable(&hdev->tx_task);
975+
976+
return chan;
977+
}
978+
979+
int hci_chan_del(struct hci_chan *chan)
980+
{
981+
struct hci_conn *conn = chan->conn;
982+
struct hci_dev *hdev = conn->hdev;
983+
984+
BT_DBG("%s conn %p chan %p", hdev->name, conn, chan);
985+
986+
tasklet_disable(&hdev->tx_task);
987+
hci_chan_hash_del(conn, chan);
988+
tasklet_enable(&hdev->tx_task);
989+
990+
skb_queue_purge(&chan->data_q);
991+
kfree(chan);
992+
993+
return 0;
994+
}
995+
996+
void hci_chan_hash_flush(struct hci_conn *conn)
997+
{
998+
struct hci_chan_hash *h = &conn->chan_hash;
999+
struct hci_chan *chan, *tmp;
1000+
1001+
BT_DBG("conn %p", conn);
1002+
1003+
list_for_each_entry_safe(chan, tmp, &h->list, list)
1004+
hci_chan_del(chan);
1005+
}

‎net/bluetooth/hci_core.c‎

Lines changed: 120 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,33 +1937,28 @@ static void hci_add_acl_hdr(struct sk_buff *skb, __u16 handle, __u16 flags)
19371937
hdr->dlen = cpu_to_le16(len);
19381938
}
19391939

1940-
void hci_send_acl(struct hci_conn *conn, struct sk_buff *skb, __u16 flags)
1940+
static void hci_queue_acl(struct hci_conn *conn, struct sk_buff_head *queue,
1941+
struct sk_buff *skb, __u16 flags)
19411942
{
19421943
struct hci_dev *hdev = conn->hdev;
19431944
struct sk_buff *list;
19441945

1945-
BT_DBG("%s conn %p flags 0x%x", hdev->name, conn, flags);
1946-
1947-
skb->dev = (void *) hdev;
1948-
bt_cb(skb)->pkt_type = HCI_ACLDATA_PKT;
1949-
hci_add_acl_hdr(skb, conn->handle, flags);
1950-
19511946
list = skb_shinfo(skb)->frag_list;
19521947
if (!list) {
19531948
/* Non fragmented */
19541949
BT_DBG("%s nonfrag skb %p len %d", hdev->name, skb, skb->len);
19551950

1956-
skb_queue_tail(&conn->data_q, skb);
1951+
skb_queue_tail(queue, skb);
19571952
} else {
19581953
/* Fragmented */
19591954
BT_DBG("%s frag %p len %d", hdev->name, skb, skb->len);
19601955

19611956
skb_shinfo(skb)->frag_list = NULL;
19621957

19631958
/* Queue all fragments atomically */
1964-
spin_lock_bh(&conn->data_q.lock);
1959+
spin_lock_bh(&queue->lock);
19651960

1966-
__skb_queue_tail(&conn->data_q, skb);
1961+
__skb_queue_tail(queue, skb);
19671962

19681963
flags &= ~ACL_START;
19691964
flags |= ACL_CONT;
@@ -1976,11 +1971,25 @@ void hci_send_acl(struct hci_conn *conn, struct sk_buff *skb, __u16 flags)
19761971

19771972
BT_DBG("%s frag %p len %d", hdev->name, skb, skb->len);
19781973

1979-
__skb_queue_tail(&conn->data_q, skb);
1974+
__skb_queue_tail(queue, skb);
19801975
} while (list);
19811976

1982-
spin_unlock_bh(&conn->data_q.lock);
1977+
spin_unlock_bh(&queue->lock);
19831978
}
1979+
}
1980+
1981+
void hci_send_acl(struct hci_chan *chan, struct sk_buff *skb, __u16 flags)
1982+
{
1983+
struct hci_conn *conn = chan->conn;
1984+
struct hci_dev *hdev = conn->hdev;
1985+
1986+
BT_DBG("%s chan %p flags 0x%x", hdev->name, chan, flags);
1987+
1988+
skb->dev = (void *) hdev;
1989+
bt_cb(skb)->pkt_type = HCI_ACLDATA_PKT;
1990+
hci_add_acl_hdr(skb, conn->handle, flags);
1991+
1992+
hci_queue_acl(conn, &chan->data_q, skb, flags);
19841993

19851994
tasklet_schedule(&hdev->tx_task);
19861995
}
@@ -2083,11 +2092,90 @@ static inline void hci_link_tx_to(struct hci_dev *hdev, __u8 type)
20832092
}
20842093
}
20852094

2086-
static inline void hci_sched_acl(struct hci_dev *hdev)
2095+
static inline struct hci_chan *hci_chan_sent(struct hci_dev *hdev, __u8 type,
2096+
int *quote)
20872097
{
2098+
struct hci_conn_hash *h = &hdev->conn_hash;
2099+
struct hci_chan *chan = NULL;
2100+
int num = 0, min = ~0, cur_prio = 0;
20882101
struct hci_conn *conn;
2102+
int cnt, q, conn_num = 0;
2103+
2104+
BT_DBG("%s", hdev->name);
2105+
2106+
list_for_each_entry(conn, &h->list, list) {
2107+
struct hci_chan_hash *ch;
2108+
struct hci_chan *tmp;
2109+
2110+
if (conn->type != type)
2111+
continue;
2112+
2113+
if (conn->state != BT_CONNECTED && conn->state != BT_CONFIG)
2114+
continue;
2115+
2116+
conn_num++;
2117+
2118+
ch = &conn->chan_hash;
2119+
2120+
list_for_each_entry(tmp, &ch->list, list) {
2121+
struct sk_buff *skb;
2122+
2123+
if (skb_queue_empty(&tmp->data_q))
2124+
continue;
2125+
2126+
skb = skb_peek(&tmp->data_q);
2127+
if (skb->priority < cur_prio)
2128+
continue;
2129+
2130+
if (skb->priority > cur_prio) {
2131+
num = 0;
2132+
min = ~0;
2133+
cur_prio = skb->priority;
2134+
}
2135+
2136+
num++;
2137+
2138+
if (conn->sent < min) {
2139+
min = conn->sent;
2140+
chan = tmp;
2141+
}
2142+
}
2143+
2144+
if (hci_conn_num(hdev, type) == conn_num)
2145+
break;
2146+
}
2147+
2148+
if (!chan)
2149+
return NULL;
2150+
2151+
switch (chan->conn->type) {
2152+
case ACL_LINK:
2153+
cnt = hdev->acl_cnt;
2154+
break;
2155+
case SCO_LINK:
2156+
case ESCO_LINK:
2157+
cnt = hdev->sco_cnt;
2158+
break;
2159+
case LE_LINK:
2160+
cnt = hdev->le_mtu ? hdev->le_cnt : hdev->acl_cnt;
2161+
break;
2162+
default:
2163+
cnt = 0;
2164+
BT_ERR("Unknown link type");
2165+
}
2166+
2167+
q = cnt / num;
2168+
*quote = q ? q : 1;
2169+
BT_DBG("chan %p quote %d", chan, *quote);
2170+
return chan;
2171+
}
2172+
2173+
static inline void hci_sched_acl(struct hci_dev *hdev)
2174+
{
2175+
struct hci_chan *chan;
20892176
struct sk_buff *skb;
20902177
int quote;
2178+
unsigned int cnt;
20912179

20922180
BT_DBG("%s", hdev->name);
20932181

@@ -2101,17 +2189,23 @@ static inline void hci_sched_acl(struct hci_dev *hdev)
21012189
hci_link_tx_to(hdev, ACL_LINK);
21022190
}
21032191

2104-
while (hdev->acl_cnt && (conn = hci_low_sent(hdev, ACL_LINK, &quote))) {
2105-
while (quote-- && (skb = skb_dequeue(&conn->data_q))) {
2106-
BT_DBG("skb %p len %d", skb, skb->len);
2192+
cnt = hdev->acl_cnt;
21072193

2108-
hci_conn_enter_active_mode(conn, bt_cb(skb)->force_active);
2194+
while (hdev->acl_cnt &&
2195+
(chan = hci_chan_sent(hdev, ACL_LINK, &quote))) {
2196+
while (quote-- && (skb = skb_dequeue(&chan->data_q))) {
2197+
BT_DBG("chan %p skb %p len %d priority %u", chan, skb,
2198+
skb->len, skb->priority);
2199+
2200+
hci_conn_enter_active_mode(chan->conn,
2201+
bt_cb(skb)->force_active);
21092202

21102203
hci_send_frame(skb);
21112204
hdev->acl_last_tx = jiffies;
21122205

21132206
hdev->acl_cnt--;
2114-
conn->sent++;
2207+
chan->sent++;
2208+
chan->conn->sent++;
21152209
}
21162210
}
21172211
}
@@ -2165,7 +2259,7 @@ static inline void hci_sched_esco(struct hci_dev *hdev)
21652259

21662260
static inline void hci_sched_le(struct hci_dev *hdev)
21672261
{
2168-
struct hci_conn *conn;
2262+
struct hci_chan *chan;
21692263
struct sk_buff *skb;
21702264
int quote, cnt;
21712265

@@ -2183,17 +2277,20 @@ static inline void hci_sched_le(struct hci_dev *hdev)
21832277
}
21842278

21852279
cnt = hdev->le_pkts ? hdev->le_cnt : hdev->acl_cnt;
2186-
while (cnt && (conn = hci_low_sent(hdev, LE_LINK, &quote))) {
2187-
while (quote-- && (skb = skb_dequeue(&conn->data_q))) {
2188-
BT_DBG("skb %p len %d", skb, skb->len);
2280+
while (cnt && (chan = hci_chan_sent(hdev, LE_LINK, &quote))) {
2281+
while (quote-- && (skb = skb_dequeue(&chan->data_q))) {
2282+
BT_DBG("chan %p skb %p len %d priority %u", chan, skb,
2283+
skb->len, skb->priority);
21892284

21902285
hci_send_frame(skb);
21912286
hdev->le_last_tx = jiffies;
21922287

21932288
cnt--;
2194-
conn->sent++;
2289+
chan->sent++;
2290+
chan->conn->sent++;
21952291
}
21962292
}
2293+
21972294
if (hdev->le_pkts)
21982295
hdev->le_cnt = cnt;
21992296
else

0 commit comments

Comments
 (0)