1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Sat, 16 Mar 2019 17:57:38 +0100
3 Subject: [PATCH] mac80211: calculate hash for fq without holding fq->lock
6 Reduces lock contention on enqueue/dequeue of iTXQ packets
8 Signed-off-by: Felix Fietkau <nbd@nbd.name>
11 --- a/include/net/fq_impl.h
12 +++ b/include/net/fq_impl.h
13 @@ -107,21 +107,23 @@ begin:
17 +static u32 fq_flow_idx(struct fq *fq, struct sk_buff *skb)
19 + u32 hash = skb_get_hash_perturb(skb, fq->perturbation);
21 + return reciprocal_scale(hash, fq->flows_cnt);
24 static struct fq_flow *fq_flow_classify(struct fq *fq,
26 + struct fq_tin *tin, u32 idx,
28 fq_flow_get_default_t get_default_func)
34 lockdep_assert_held(&fq->lock);
36 - hash = skb_get_hash_perturb(skb, fq->perturbation);
37 - idx = reciprocal_scale(hash, fq->flows_cnt);
38 flow = &fq->flows[idx];
40 if (flow->tin && flow->tin != tin) {
41 flow = get_default_func(fq, tin, idx, skb);
43 @@ -153,7 +155,7 @@ static void fq_recalc_backlog(struct fq
46 static void fq_tin_enqueue(struct fq *fq,
48 + struct fq_tin *tin, u32 idx,
50 fq_skb_free_t free_func,
51 fq_flow_get_default_t get_default_func)
52 @@ -163,7 +165,7 @@ static void fq_tin_enqueue(struct fq *fq
54 lockdep_assert_held(&fq->lock);
56 - flow = fq_flow_classify(fq, tin, skb, get_default_func);
57 + flow = fq_flow_classify(fq, tin, idx, skb, get_default_func);
60 flow->backlog += skb->len;
61 --- a/net/mac80211/tx.c
62 +++ b/net/mac80211/tx.c
63 @@ -1390,11 +1390,15 @@ static void ieee80211_txq_enqueue(struct
65 struct fq *fq = &local->fq;
66 struct fq_tin *tin = &txqi->tin;
67 + u32 flow_idx = fq_flow_idx(fq, skb);
69 ieee80211_set_skb_enqueue_time(skb);
70 - fq_tin_enqueue(fq, tin, skb,
72 + spin_lock_bh(&fq->lock);
73 + fq_tin_enqueue(fq, tin, flow_idx, skb,
75 fq_flow_get_default_func);
76 + spin_unlock_bh(&fq->lock);
79 static bool fq_vlan_filter_func(struct fq *fq, struct fq_tin *tin,
80 @@ -1564,7 +1568,6 @@ static bool ieee80211_queue_skb(struct i
84 - struct fq *fq = &local->fq;
85 struct ieee80211_vif *vif;
86 struct txq_info *txqi;
88 @@ -1582,9 +1585,7 @@ static bool ieee80211_queue_skb(struct i
92 - spin_lock_bh(&fq->lock);
93 ieee80211_txq_enqueue(local, txqi, skb);
94 - spin_unlock_bh(&fq->lock);
96 schedule_and_wake_txq(local, txqi);
98 @@ -3198,6 +3199,7 @@ static bool ieee80211_amsdu_aggregate(st
99 u8 max_subframes = sta->sta.max_amsdu_subframes;
100 int max_frags = local->hw.max_tx_fragments;
101 int max_amsdu_len = sta->sta.max_amsdu_len;
106 @@ -3220,6 +3222,8 @@ static bool ieee80211_amsdu_aggregate(st
107 max_amsdu_len = min_t(int, max_amsdu_len,
108 sta->sta.max_rc_amsdu_len);
110 + flow_idx = fq_flow_idx(fq, skb);
112 spin_lock_bh(&fq->lock);
114 /* TODO: Ideally aggregation should be done on dequeue to remain
115 @@ -3227,7 +3231,8 @@ static bool ieee80211_amsdu_aggregate(st
119 - flow = fq_flow_classify(fq, tin, skb, fq_flow_get_default_func);
120 + flow = fq_flow_classify(fq, tin, flow_idx, skb,
121 + fq_flow_get_default_func);
122 head = skb_peek_tail(&flow->queue);