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,29 +107,31 @@ begin:
17 -static struct fq_flow *fq_flow_classify(struct fq *fq,
19 - struct sk_buff *skb,
20 - fq_flow_get_default_t get_default_func)
21 +static u32 fq_flow_idx(struct fq *fq, struct sk_buff *skb)
23 - struct fq_flow *flow;
27 - lockdep_assert_held(&fq->lock);
29 #if LINUX_VERSION_IS_GEQ(5,3,10) || \
30 LINUX_VERSION_IN_RANGE(4,19,83, 4,20,0) || \
31 LINUX_VERSION_IN_RANGE(4,14,153, 4,15,0) || \
32 LINUX_VERSION_IN_RANGE(4,9,200, 4,10,0) || \
33 LINUX_VERSION_IN_RANGE(4,4,200, 4,5,0)
34 - hash = skb_get_hash_perturb(skb, &fq->perturbation);
35 + u32 hash = skb_get_hash_perturb(skb, &fq->perturbation);
37 - hash = skb_get_hash_perturb(skb, fq->perturbation);
38 + u32 hash = skb_get_hash_perturb(skb, fq->perturbation);
40 - idx = reciprocal_scale(hash, fq->flows_cnt);
41 - flow = &fq->flows[idx];
43 + return reciprocal_scale(hash, fq->flows_cnt);
46 +static struct fq_flow *fq_flow_classify(struct fq *fq,
47 + struct fq_tin *tin, u32 idx,
48 + struct sk_buff *skb,
49 + fq_flow_get_default_t get_default_func)
51 + struct fq_flow *flow;
53 + lockdep_assert_held(&fq->lock);
55 + flow = &fq->flows[idx];
56 if (flow->tin && flow->tin != tin) {
57 flow = get_default_func(fq, tin, idx, skb);
59 @@ -161,7 +163,7 @@ static void fq_recalc_backlog(struct fq
62 static void fq_tin_enqueue(struct fq *fq,
64 + struct fq_tin *tin, u32 idx,
66 fq_skb_free_t free_func,
67 fq_flow_get_default_t get_default_func)
68 @@ -171,7 +173,7 @@ static void fq_tin_enqueue(struct fq *fq
70 lockdep_assert_held(&fq->lock);
72 - flow = fq_flow_classify(fq, tin, skb, get_default_func);
73 + flow = fq_flow_classify(fq, tin, idx, skb, get_default_func);
76 flow->backlog += skb->len;
77 --- a/net/mac80211/tx.c
78 +++ b/net/mac80211/tx.c
79 @@ -1390,11 +1390,15 @@ static void ieee80211_txq_enqueue(struct
81 struct fq *fq = &local->fq;
82 struct fq_tin *tin = &txqi->tin;
83 + u32 flow_idx = fq_flow_idx(fq, skb);
85 ieee80211_set_skb_enqueue_time(skb);
86 - fq_tin_enqueue(fq, tin, skb,
88 + spin_lock_bh(&fq->lock);
89 + fq_tin_enqueue(fq, tin, flow_idx, skb,
91 fq_flow_get_default_func);
92 + spin_unlock_bh(&fq->lock);
95 static bool fq_vlan_filter_func(struct fq *fq, struct fq_tin *tin,
96 @@ -1564,7 +1568,6 @@ static bool ieee80211_queue_skb(struct i
100 - struct fq *fq = &local->fq;
101 struct ieee80211_vif *vif;
102 struct txq_info *txqi;
104 @@ -1582,9 +1585,7 @@ static bool ieee80211_queue_skb(struct i
108 - spin_lock_bh(&fq->lock);
109 ieee80211_txq_enqueue(local, txqi, skb);
110 - spin_unlock_bh(&fq->lock);
112 schedule_and_wake_txq(local, txqi);
114 @@ -3200,6 +3201,7 @@ static bool ieee80211_amsdu_aggregate(st
115 u8 max_subframes = sta->sta.max_amsdu_subframes;
116 int max_frags = local->hw.max_tx_fragments;
117 int max_amsdu_len = sta->sta.max_amsdu_len;
122 @@ -3222,6 +3224,8 @@ static bool ieee80211_amsdu_aggregate(st
123 max_amsdu_len = min_t(int, max_amsdu_len,
124 sta->sta.max_rc_amsdu_len);
126 + flow_idx = fq_flow_idx(fq, skb);
128 spin_lock_bh(&fq->lock);
130 /* TODO: Ideally aggregation should be done on dequeue to remain
131 @@ -3229,7 +3233,8 @@ static bool ieee80211_amsdu_aggregate(st
135 - flow = fq_flow_classify(fq, tin, skb, fq_flow_get_default_func);
136 + flow = fq_flow_classify(fq, tin, flow_idx, skb,
137 + fq_flow_get_default_func);
138 head = skb_peek_tail(&flow->queue);