Skip to content

Commit 0f1bf69

Browse files
krikkkuNipaLocal
authored andcommitted
net: Cache hash and flow_id to avoid recalculation
get_rps_cpu() can cache flow_id and hash as both are required by set_rps_cpu() instead of recalculating them twice. Signed-off-by: Krishna Kumar <krikku@gmail.com> Signed-off-by: NipaLocal <nipa@local>
1 parent 1d8ce41 commit 0f1bf69

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

net/core/dev.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4869,7 +4869,8 @@ static bool rps_flow_is_active(struct rps_dev_flow *rflow,
48694869

48704870
static struct rps_dev_flow *
48714871
set_rps_cpu(struct net_device *dev, struct sk_buff *skb,
4872-
struct rps_dev_flow *rflow, u16 next_cpu)
4872+
struct rps_dev_flow *rflow, u16 next_cpu, u32 hash,
4873+
u32 flow_id)
48734874
{
48744875
if (next_cpu < nr_cpu_ids) {
48754876
u32 head;
@@ -4880,8 +4881,6 @@ set_rps_cpu(struct net_device *dev, struct sk_buff *skb,
48804881
struct rps_dev_flow *tmp_rflow;
48814882
unsigned int tmp_cpu;
48824883
u16 rxq_index;
4883-
u32 flow_id;
4884-
u32 hash;
48854884
int rc;
48864885

48874886
/* Should we steer this flow to a different hardware queue? */
@@ -4897,9 +4896,6 @@ set_rps_cpu(struct net_device *dev, struct sk_buff *skb,
48974896
if (!flow_table)
48984897
goto out;
48994898

4900-
hash = skb_get_hash(skb);
4901-
flow_id = rfs_slot(hash, flow_table);
4902-
49034899
tmp_rflow = &flow_table->flows[flow_id];
49044900
tmp_cpu = READ_ONCE(tmp_rflow->cpu);
49054901

@@ -4947,6 +4943,7 @@ static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb,
49474943
struct rps_dev_flow_table *flow_table;
49484944
struct rps_map *map;
49494945
int cpu = -1;
4946+
u32 flow_id;
49504947
u32 tcpu;
49514948
u32 hash;
49524949

@@ -4993,7 +4990,8 @@ static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb,
49934990
/* OK, now we know there is a match,
49944991
* we can look at the local (per receive queue) flow table
49954992
*/
4996-
rflow = &flow_table->flows[rfs_slot(hash, flow_table)];
4993+
flow_id = rfs_slot(hash, flow_table);
4994+
rflow = &flow_table->flows[flow_id];
49974995
tcpu = rflow->cpu;
49984996

49994997
/*
@@ -5012,7 +5010,8 @@ static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb,
50125010
((int)(READ_ONCE(per_cpu(softnet_data, tcpu).input_queue_head) -
50135011
rflow->last_qtail)) >= 0)) {
50145012
tcpu = next_cpu;
5015-
rflow = set_rps_cpu(dev, skb, rflow, next_cpu);
5013+
rflow = set_rps_cpu(dev, skb, rflow, next_cpu, hash,
5014+
flow_id);
50165015
}
50175016

50185017
if (tcpu < nr_cpu_ids && cpu_online(tcpu)) {

0 commit comments

Comments
 (0)