2b6d8ab52525dcbdb0f8cec14732a624cec99672
[openwrt/staging/xback.git] /
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
4 in itxq enqueue
5
6 Reduces lock contention on enqueue/dequeue of iTXQ packets
7
8 Signed-off-by: Felix Fietkau <nbd@nbd.name>
9 ---
10
11 --- a/include/net/fq_impl.h
12 +++ b/include/net/fq_impl.h
13 @@ -107,21 +107,23 @@ begin:
14 return skb;
15 }
16
17 +static u32 fq_flow_idx(struct fq *fq, struct sk_buff *skb)
18 +{
19 + u32 hash = skb_get_hash_perturb(skb, fq->perturbation);
20 +
21 + return reciprocal_scale(hash, fq->flows_cnt);
22 +}
23 +
24 static struct fq_flow *fq_flow_classify(struct fq *fq,
25 - struct fq_tin *tin,
26 + struct fq_tin *tin, u32 idx,
27 struct sk_buff *skb,
28 fq_flow_get_default_t get_default_func)
29 {
30 struct fq_flow *flow;
31 - u32 hash;
32 - u32 idx;
33
34 lockdep_assert_held(&fq->lock);
35
36 - hash = skb_get_hash_perturb(skb, fq->perturbation);
37 - idx = reciprocal_scale(hash, fq->flows_cnt);
38 flow = &fq->flows[idx];
39 -
40 if (flow->tin && flow->tin != tin) {
41 flow = get_default_func(fq, tin, idx, skb);
42 tin->collisions++;
43 @@ -153,7 +155,7 @@ static void fq_recalc_backlog(struct fq
44 }
45
46 static void fq_tin_enqueue(struct fq *fq,
47 - struct fq_tin *tin,
48 + struct fq_tin *tin, u32 idx,
49 struct sk_buff *skb,
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
53
54 lockdep_assert_held(&fq->lock);
55
56 - flow = fq_flow_classify(fq, tin, skb, get_default_func);
57 + flow = fq_flow_classify(fq, tin, idx, skb, get_default_func);
58
59 flow->tin = tin;
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
64 {
65 struct fq *fq = &local->fq;
66 struct fq_tin *tin = &txqi->tin;
67 + u32 flow_idx = fq_flow_idx(fq, skb);
68
69 ieee80211_set_skb_enqueue_time(skb);
70 - fq_tin_enqueue(fq, tin, skb,
71 +
72 + spin_lock_bh(&fq->lock);
73 + fq_tin_enqueue(fq, tin, flow_idx, skb,
74 fq_skb_free_func,
75 fq_flow_get_default_func);
76 + spin_unlock_bh(&fq->lock);
77 }
78
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
81 struct sta_info *sta,
82 struct sk_buff *skb)
83 {
84 - struct fq *fq = &local->fq;
85 struct ieee80211_vif *vif;
86 struct txq_info *txqi;
87
88 @@ -1582,9 +1585,7 @@ static bool ieee80211_queue_skb(struct i
89 if (!txqi)
90 return false;
91
92 - spin_lock_bh(&fq->lock);
93 ieee80211_txq_enqueue(local, txqi, skb);
94 - spin_unlock_bh(&fq->lock);
95
96 schedule_and_wake_txq(local, txqi);
97
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;
102 + u32 flow_idx;
103 int orig_truesize;
104 __be16 len;
105 void *data;
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);
109
110 + flow_idx = fq_flow_idx(fq, skb);
111 +
112 spin_lock_bh(&fq->lock);
113
114 /* TODO: Ideally aggregation should be done on dequeue to remain
115 @@ -3227,7 +3231,8 @@ static bool ieee80211_amsdu_aggregate(st
116 */
117
118 tin = &txqi->tin;
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);
123 if (!head)
124 goto unlock;