Commit bf4c6325 authored by Gustavo F. Padovan's avatar Gustavo F. Padovan

Bluetooth: convert conn hash to RCU

Handling hci_conn_hash with RCU make us avoid some locking and disable
tasklets.
Acked-by: default avatarMarcel Holtmann <marcel@holtmann.org>
Signed-off-by: default avatarGustavo F. Padovan <padovan@profusion.mobi>
parent 8192edef
...@@ -392,7 +392,7 @@ static inline void hci_conn_hash_init(struct hci_dev *hdev) ...@@ -392,7 +392,7 @@ static inline void hci_conn_hash_init(struct hci_dev *hdev)
static inline void hci_conn_hash_add(struct hci_dev *hdev, struct hci_conn *c) static inline void hci_conn_hash_add(struct hci_dev *hdev, struct hci_conn *c)
{ {
struct hci_conn_hash *h = &hdev->conn_hash; struct hci_conn_hash *h = &hdev->conn_hash;
list_add(&c->list, &h->list); list_add_rcu(&c->list, &h->list);
switch (c->type) { switch (c->type) {
case ACL_LINK: case ACL_LINK:
h->acl_num++; h->acl_num++;
...@@ -410,7 +410,10 @@ static inline void hci_conn_hash_add(struct hci_dev *hdev, struct hci_conn *c) ...@@ -410,7 +410,10 @@ static inline void hci_conn_hash_add(struct hci_dev *hdev, struct hci_conn *c)
static inline void hci_conn_hash_del(struct hci_dev *hdev, struct hci_conn *c) static inline void hci_conn_hash_del(struct hci_dev *hdev, struct hci_conn *c)
{ {
struct hci_conn_hash *h = &hdev->conn_hash; struct hci_conn_hash *h = &hdev->conn_hash;
list_del(&c->list);
list_del_rcu(&c->list);
synchronize_rcu();
switch (c->type) { switch (c->type) {
case ACL_LINK: case ACL_LINK:
h->acl_num--; h->acl_num--;
...@@ -445,14 +448,18 @@ static inline struct hci_conn *hci_conn_hash_lookup_handle(struct hci_dev *hdev, ...@@ -445,14 +448,18 @@ static inline struct hci_conn *hci_conn_hash_lookup_handle(struct hci_dev *hdev,
__u16 handle) __u16 handle)
{ {
struct hci_conn_hash *h = &hdev->conn_hash; struct hci_conn_hash *h = &hdev->conn_hash;
struct list_head *p;
struct hci_conn *c; struct hci_conn *c;
list_for_each(p, &h->list) { rcu_read_lock();
c = list_entry(p, struct hci_conn, list);
if (c->handle == handle) list_for_each_entry_rcu(c, &h->list, list) {
if (c->handle == handle) {
rcu_read_unlock();
return c; return c;
}
} }
rcu_read_unlock();
return NULL; return NULL;
} }
...@@ -460,14 +467,19 @@ static inline struct hci_conn *hci_conn_hash_lookup_ba(struct hci_dev *hdev, ...@@ -460,14 +467,19 @@ static inline struct hci_conn *hci_conn_hash_lookup_ba(struct hci_dev *hdev,
__u8 type, bdaddr_t *ba) __u8 type, bdaddr_t *ba)
{ {
struct hci_conn_hash *h = &hdev->conn_hash; struct hci_conn_hash *h = &hdev->conn_hash;
struct list_head *p;
struct hci_conn *c; struct hci_conn *c;
list_for_each(p, &h->list) { rcu_read_lock();
c = list_entry(p, struct hci_conn, list);
if (c->type == type && !bacmp(&c->dst, ba)) list_for_each_entry_rcu(c, &h->list, list) {
if (c->type == type && !bacmp(&c->dst, ba)) {
rcu_read_unlock();
return c; return c;
}
} }
rcu_read_unlock();
return NULL; return NULL;
} }
...@@ -475,14 +487,19 @@ static inline struct hci_conn *hci_conn_hash_lookup_state(struct hci_dev *hdev, ...@@ -475,14 +487,19 @@ static inline struct hci_conn *hci_conn_hash_lookup_state(struct hci_dev *hdev,
__u8 type, __u16 state) __u8 type, __u16 state)
{ {
struct hci_conn_hash *h = &hdev->conn_hash; struct hci_conn_hash *h = &hdev->conn_hash;
struct list_head *p;
struct hci_conn *c; struct hci_conn *c;
list_for_each(p, &h->list) { rcu_read_lock();
c = list_entry(p, struct hci_conn, list);
if (c->type == type && c->state == state) list_for_each_entry_rcu(c, &h->list, list) {
if (c->type == type && c->state == state) {
rcu_read_unlock();
return c; return c;
}
} }
rcu_read_unlock();
return NULL; return NULL;
} }
......
...@@ -418,18 +418,17 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst) ...@@ -418,18 +418,17 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst)
hci_dev_hold(hdev); hci_dev_hold(hdev);
tasklet_disable(&hdev->tx_task);
hci_conn_hash_add(hdev, conn); hci_conn_hash_add(hdev, conn);
if (hdev->notify) if (hdev->notify) {
tasklet_disable(&hdev->tx_task);
hdev->notify(hdev, HCI_NOTIFY_CONN_ADD); hdev->notify(hdev, HCI_NOTIFY_CONN_ADD);
tasklet_enable(&hdev->tx_task);
}
atomic_set(&conn->devref, 0); atomic_set(&conn->devref, 0);
hci_conn_init_sysfs(conn); hci_conn_init_sysfs(conn);
tasklet_enable(&hdev->tx_task);
return conn; return conn;
} }
...@@ -465,15 +464,15 @@ int hci_conn_del(struct hci_conn *conn) ...@@ -465,15 +464,15 @@ int hci_conn_del(struct hci_conn *conn)
} }
} }
tasklet_disable(&hdev->tx_task);
hci_chan_list_flush(conn); hci_chan_list_flush(conn);
hci_conn_hash_del(hdev, conn); hci_conn_hash_del(hdev, conn);
if (hdev->notify) if (hdev->notify) {
tasklet_disable(&hdev->tx_task);
hdev->notify(hdev, HCI_NOTIFY_CONN_DEL); hdev->notify(hdev, HCI_NOTIFY_CONN_DEL);
tasklet_enable(&hdev->tx_task);
tasklet_enable(&hdev->tx_task); }
skb_queue_purge(&conn->data_q); skb_queue_purge(&conn->data_q);
...@@ -808,7 +807,7 @@ void hci_conn_hash_flush(struct hci_dev *hdev) ...@@ -808,7 +807,7 @@ void hci_conn_hash_flush(struct hci_dev *hdev)
BT_DBG("hdev %s", hdev->name); BT_DBG("hdev %s", hdev->name);
list_for_each_entry(c, &h->list, list) { list_for_each_entry_rcu(c, &h->list, list) {
c->state = BT_CLOSED; c->state = BT_CLOSED;
hci_proto_disconn_cfm(c, HCI_ERROR_LOCAL_HOST_TERM); hci_proto_disconn_cfm(c, HCI_ERROR_LOCAL_HOST_TERM);
......
...@@ -2050,7 +2050,10 @@ static inline struct hci_conn *hci_low_sent(struct hci_dev *hdev, __u8 type, int ...@@ -2050,7 +2050,10 @@ static inline struct hci_conn *hci_low_sent(struct hci_dev *hdev, __u8 type, int
/* We don't have to lock device here. Connections are always /* We don't have to lock device here. Connections are always
* added and removed with TX task disabled. */ * added and removed with TX task disabled. */
list_for_each_entry(c, &h->list, list) {
rcu_read_lock();
list_for_each_entry_rcu(c, &h->list, list) {
if (c->type != type || skb_queue_empty(&c->data_q)) if (c->type != type || skb_queue_empty(&c->data_q))
continue; continue;
...@@ -2068,6 +2071,8 @@ static inline struct hci_conn *hci_low_sent(struct hci_dev *hdev, __u8 type, int ...@@ -2068,6 +2071,8 @@ static inline struct hci_conn *hci_low_sent(struct hci_dev *hdev, __u8 type, int
break; break;
} }
rcu_read_unlock();
if (conn) { if (conn) {
int cnt, q; int cnt, q;
...@@ -2103,14 +2108,18 @@ static inline void hci_link_tx_to(struct hci_dev *hdev, __u8 type) ...@@ -2103,14 +2108,18 @@ static inline void hci_link_tx_to(struct hci_dev *hdev, __u8 type)
BT_ERR("%s link tx timeout", hdev->name); BT_ERR("%s link tx timeout", hdev->name);
rcu_read_lock();
/* Kill stalled connections */ /* Kill stalled connections */
list_for_each_entry(c, &h->list, list) { list_for_each_entry_rcu(c, &h->list, list) {
if (c->type == type && c->sent) { if (c->type == type && c->sent) {
BT_ERR("%s killing stalled connection %s", BT_ERR("%s killing stalled connection %s",
hdev->name, batostr(&c->dst)); hdev->name, batostr(&c->dst));
hci_acl_disconn(c, 0x13); hci_acl_disconn(c, 0x13);
} }
} }
rcu_read_unlock();
} }
static inline struct hci_chan *hci_chan_sent(struct hci_dev *hdev, __u8 type, static inline struct hci_chan *hci_chan_sent(struct hci_dev *hdev, __u8 type,
...@@ -2124,7 +2133,9 @@ static inline struct hci_chan *hci_chan_sent(struct hci_dev *hdev, __u8 type, ...@@ -2124,7 +2133,9 @@ static inline struct hci_chan *hci_chan_sent(struct hci_dev *hdev, __u8 type,
BT_DBG("%s", hdev->name); BT_DBG("%s", hdev->name);
list_for_each_entry(conn, &h->list, list) { rcu_read_lock();
list_for_each_entry_rcu(conn, &h->list, list) {
struct hci_chan *tmp; struct hci_chan *tmp;
if (conn->type != type) if (conn->type != type)
...@@ -2135,8 +2146,6 @@ static inline struct hci_chan *hci_chan_sent(struct hci_dev *hdev, __u8 type, ...@@ -2135,8 +2146,6 @@ static inline struct hci_chan *hci_chan_sent(struct hci_dev *hdev, __u8 type,
conn_num++; conn_num++;
rcu_read_lock();
list_for_each_entry_rcu(tmp, &conn->chan_list, list) { list_for_each_entry_rcu(tmp, &conn->chan_list, list) {
struct sk_buff *skb; struct sk_buff *skb;
...@@ -2161,12 +2170,12 @@ static inline struct hci_chan *hci_chan_sent(struct hci_dev *hdev, __u8 type, ...@@ -2161,12 +2170,12 @@ static inline struct hci_chan *hci_chan_sent(struct hci_dev *hdev, __u8 type,
} }
} }
rcu_read_unlock();
if (hci_conn_num(hdev, type) == conn_num) if (hci_conn_num(hdev, type) == conn_num)
break; break;
} }
rcu_read_unlock();
if (!chan) if (!chan)
return NULL; return NULL;
...@@ -2200,7 +2209,9 @@ static void hci_prio_recalculate(struct hci_dev *hdev, __u8 type) ...@@ -2200,7 +2209,9 @@ static void hci_prio_recalculate(struct hci_dev *hdev, __u8 type)
BT_DBG("%s", hdev->name); BT_DBG("%s", hdev->name);
list_for_each_entry(conn, &h->list, list) { rcu_read_lock();
list_for_each_entry_rcu(conn, &h->list, list) {
struct hci_chan *chan; struct hci_chan *chan;
if (conn->type != type) if (conn->type != type)
...@@ -2211,8 +2222,6 @@ static void hci_prio_recalculate(struct hci_dev *hdev, __u8 type) ...@@ -2211,8 +2222,6 @@ static void hci_prio_recalculate(struct hci_dev *hdev, __u8 type)
num++; num++;
rcu_read_lock();
list_for_each_entry_rcu(chan, &conn->chan_list, list) { list_for_each_entry_rcu(chan, &conn->chan_list, list) {
struct sk_buff *skb; struct sk_buff *skb;
...@@ -2234,11 +2243,12 @@ static void hci_prio_recalculate(struct hci_dev *hdev, __u8 type) ...@@ -2234,11 +2243,12 @@ static void hci_prio_recalculate(struct hci_dev *hdev, __u8 type)
skb->priority); skb->priority);
} }
rcu_read_unlock();
if (hci_conn_num(hdev, type) == num) if (hci_conn_num(hdev, type) == num)
break; break;
} }
rcu_read_unlock();
} }
static inline void hci_sched_acl(struct hci_dev *hdev) static inline void hci_sched_acl(struct hci_dev *hdev)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment