Skip to content

Commit 02b20f0

Browse files
VudentzGustavo F. Padovan
authored andcommitted
Bluetooth: recalculate priorities when channels are starving
To avoid starvation the priority is recalculated so that the starving channels are promoted to HCI_PRIO_MAX - 1 (6). HCI_PRIO_MAX (7) is considered special, because it requires CAP_NET_ADMIN capability which can be used to provide more guaranties, so it is not used when promoting. 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 ec1cce2 commit 02b20f0

1 file changed

Lines changed: 55 additions & 1 deletion

File tree

‎net/bluetooth/hci_core.c‎

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2170,6 +2170,53 @@ static inline struct hci_chan *hci_chan_sent(struct hci_dev *hdev, __u8 type,
21702170
return chan;
21712171
}
21722172

2173+
static void hci_prio_recalculate(struct hci_dev *hdev, __u8 type)
2174+
{
2175+
struct hci_conn_hash *h = &hdev->conn_hash;
2176+
struct hci_conn *conn;
2177+
int num = 0;
2178+
2179+
BT_DBG("%s", hdev->name);
2180+
2181+
list_for_each_entry(conn, &h->list, list) {
2182+
struct hci_chan_hash *ch;
2183+
struct hci_chan *chan;
2184+
2185+
if (conn->type != type)
2186+
continue;
2187+
2188+
if (conn->state != BT_CONNECTED && conn->state != BT_CONFIG)
2189+
continue;
2190+
2191+
num++;
2192+
2193+
ch = &conn->chan_hash;
2194+
list_for_each_entry(chan, &ch->list, list) {
2195+
struct sk_buff *skb;
2196+
2197+
if (chan->sent) {
2198+
chan->sent = 0;
2199+
continue;
2200+
}
2201+
2202+
if (skb_queue_empty(&chan->data_q))
2203+
continue;
2204+
2205+
skb = skb_peek(&chan->data_q);
2206+
if (skb->priority >= HCI_PRIO_MAX - 1)
2207+
continue;
2208+
2209+
skb->priority = HCI_PRIO_MAX - 1;
2210+
2211+
BT_DBG("chan %p skb %p promoted to %d", chan, skb,
2212+
skb->priority);
2213+
}
2214+
2215+
if (hci_conn_num(hdev, type) == num)
2216+
break;
2217+
}
2218+
}
2219+
21732220
static inline void hci_sched_acl(struct hci_dev *hdev)
21742221
{
21752222
struct hci_chan *chan;
@@ -2215,6 +2262,9 @@ static inline void hci_sched_acl(struct hci_dev *hdev)
22152262
chan->conn->sent++;
22162263
}
22172264
}
2265+
2266+
if (cnt != hdev->acl_cnt)
2267+
hci_prio_recalculate(hdev, ACL_LINK);
22182268
}
22192269

22202270
/* Schedule SCO */
@@ -2268,7 +2318,7 @@ static inline void hci_sched_le(struct hci_dev *hdev)
22682318
{
22692319
struct hci_chan *chan;
22702320
struct sk_buff *skb;
2271-
int quote, cnt;
2321+
int quote, cnt, tmp;
22722322

22732323
BT_DBG("%s", hdev->name);
22742324

@@ -2284,6 +2334,7 @@ static inline void hci_sched_le(struct hci_dev *hdev)
22842334
}
22852335

22862336
cnt = hdev->le_pkts ? hdev->le_cnt : hdev->acl_cnt;
2337+
tmp = cnt;
22872338
while (cnt && (chan = hci_chan_sent(hdev, LE_LINK, &quote))) {
22882339
u32 priority = (skb_peek(&chan->data_q))->priority;
22892340
while (quote-- && (skb = skb_peek(&chan->data_q))) {
@@ -2309,6 +2360,9 @@ static inline void hci_sched_le(struct hci_dev *hdev)
23092360
hdev->le_cnt = cnt;
23102361
else
23112362
hdev->acl_cnt = cnt;
2363+
2364+
if (cnt != tmp)
2365+
hci_prio_recalculate(hdev, LE_LINK);
23122366
}
23132367

23142368
static void hci_tx_task(unsigned long arg)

0 commit comments

Comments
 (0)