Skip to content

Commit 78e8311

Browse files
committed
Merge branch 'net-rps-lockless'
Jason Xing says: ==================== locklessly protect left members in struct rps_dev_flow From: Jason Xing <kernelxing@tencent.com> Since Eric did a more complicated locklessly change to last_qtail member[1] in struct rps_dev_flow, the left members are easier to change as the same. One thing important I would like to share by qooting Eric: "rflow is located in rxqueue->rps_flow_table, it is thus private to current thread. Only one cpu can service an RX queue at a time." So we only pay attention to the reader in the rps_may_expire_flow() and writer in the set_rps_cpu(). They are in the two different contexts. [1]: https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit/?id=3b4cf29bdab v3 Link: https://lore.kernel.org/all/20240417062721.45652-1-kerneljasonxing@gmail.com/ 1. adjust the protection in a right way (Eric) v2 1. fix passing wrong type qtail. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 00ac0dc + f7b60cc commit 78e8311

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

net/core/dev.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4507,7 +4507,7 @@ set_rps_cpu(struct net_device *dev, struct sk_buff *skb,
45074507
struct netdev_rx_queue *rxqueue;
45084508
struct rps_dev_flow_table *flow_table;
45094509
struct rps_dev_flow *old_rflow;
4510-
u32 flow_id;
4510+
u32 flow_id, head;
45114511
u16 rxq_index;
45124512
int rc;
45134513

@@ -4530,16 +4530,16 @@ set_rps_cpu(struct net_device *dev, struct sk_buff *skb,
45304530
goto out;
45314531
old_rflow = rflow;
45324532
rflow = &flow_table->flows[flow_id];
4533-
rflow->filter = rc;
4534-
if (old_rflow->filter == rflow->filter)
4535-
old_rflow->filter = RPS_NO_FILTER;
4533+
WRITE_ONCE(rflow->filter, rc);
4534+
if (old_rflow->filter == rc)
4535+
WRITE_ONCE(old_rflow->filter, RPS_NO_FILTER);
45364536
out:
45374537
#endif
4538-
rflow->last_qtail =
4539-
READ_ONCE(per_cpu(softnet_data, next_cpu).input_queue_head);
4538+
head = READ_ONCE(per_cpu(softnet_data, next_cpu).input_queue_head);
4539+
rps_input_queue_tail_save(&rflow->last_qtail, head);
45404540
}
45414541

4542-
rflow->cpu = next_cpu;
4542+
WRITE_ONCE(rflow->cpu, next_cpu);
45434543
return rflow;
45444544
}
45454545

@@ -4619,7 +4619,7 @@ static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb,
46194619
if (unlikely(tcpu != next_cpu) &&
46204620
(tcpu >= nr_cpu_ids || !cpu_online(tcpu) ||
46214621
((int)(READ_ONCE(per_cpu(softnet_data, tcpu).input_queue_head) -
4622-
READ_ONCE(rflow->last_qtail))) >= 0)) {
4622+
rflow->last_qtail)) >= 0)) {
46234623
tcpu = next_cpu;
46244624
rflow = set_rps_cpu(dev, skb, rflow, next_cpu);
46254625
}
@@ -4672,7 +4672,7 @@ bool rps_may_expire_flow(struct net_device *dev, u16 rxq_index,
46724672
if (flow_table && flow_id <= flow_table->mask) {
46734673
rflow = &flow_table->flows[flow_id];
46744674
cpu = READ_ONCE(rflow->cpu);
4675-
if (rflow->filter == filter_id && cpu < nr_cpu_ids &&
4675+
if (READ_ONCE(rflow->filter) == filter_id && cpu < nr_cpu_ids &&
46764676
((int)(READ_ONCE(per_cpu(softnet_data, cpu).input_queue_head) -
46774677
READ_ONCE(rflow->last_qtail)) <
46784678
(int)(10 * flow_table->mask)))

0 commit comments

Comments
 (0)