Skip to content

Commit 035fcdc

Browse files
Sebastian Andrzej SiewiorPaolo Abeni
Sebastian Andrzej Siewior
authored and
Paolo Abeni
committed
openvswitch: Merge three per-CPU structures into one
exec_actions_level is a per-CPU integer allocated at compile time. action_fifos and flow_keys are per-CPU pointer and have their data allocated at module init time. There is no gain in splitting it, once the module is allocated, the structures are allocated. Merge the three per-CPU variables into ovs_pcpu_storage, adapt callers. Cc: Aaron Conole <aconole@redhat.com> Cc: Eelco Chaudron <echaudro@redhat.com> Cc: Ilya Maximets <i.maximets@ovn.org> Cc: dev@openvswitch.org Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Reviewed-by: Aaron Conole <aconole@redhat.com> Link: https://patch.msgid.link/20250512092736.229935-8-bigeasy@linutronix.de Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent 9c607d4 commit 035fcdc

File tree

3 files changed

+17
-44
lines changed

3 files changed

+17
-44
lines changed

net/openvswitch/actions.c

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,22 @@ struct action_flow_keys {
7878
struct sw_flow_key key[OVS_DEFERRED_ACTION_THRESHOLD];
7979
};
8080

81-
static struct action_fifo __percpu *action_fifos;
82-
static struct action_flow_keys __percpu *flow_keys;
83-
static DEFINE_PER_CPU(int, exec_actions_level);
81+
struct ovs_pcpu_storage {
82+
struct action_fifo action_fifos;
83+
struct action_flow_keys flow_keys;
84+
int exec_level;
85+
};
86+
87+
static DEFINE_PER_CPU(struct ovs_pcpu_storage, ovs_pcpu_storage);
8488

8589
/* Make a clone of the 'key', using the pre-allocated percpu 'flow_keys'
8690
* space. Return NULL if out of key spaces.
8791
*/
8892
static struct sw_flow_key *clone_key(const struct sw_flow_key *key_)
8993
{
90-
struct action_flow_keys *keys = this_cpu_ptr(flow_keys);
91-
int level = this_cpu_read(exec_actions_level);
94+
struct ovs_pcpu_storage *ovs_pcpu = this_cpu_ptr(&ovs_pcpu_storage);
95+
struct action_flow_keys *keys = &ovs_pcpu->flow_keys;
96+
int level = ovs_pcpu->exec_level;
9297
struct sw_flow_key *key = NULL;
9398

9499
if (level <= OVS_DEFERRED_ACTION_THRESHOLD) {
@@ -132,10 +137,9 @@ static struct deferred_action *add_deferred_actions(struct sk_buff *skb,
132137
const struct nlattr *actions,
133138
const int actions_len)
134139
{
135-
struct action_fifo *fifo;
140+
struct action_fifo *fifo = this_cpu_ptr(&ovs_pcpu_storage.action_fifos);
136141
struct deferred_action *da;
137142

138-
fifo = this_cpu_ptr(action_fifos);
139143
da = action_fifo_put(fifo);
140144
if (da) {
141145
da->skb = skb;
@@ -1608,13 +1612,13 @@ static int clone_execute(struct datapath *dp, struct sk_buff *skb,
16081612

16091613
if (actions) { /* Sample action */
16101614
if (clone_flow_key)
1611-
__this_cpu_inc(exec_actions_level);
1615+
__this_cpu_inc(ovs_pcpu_storage.exec_level);
16121616

16131617
err = do_execute_actions(dp, skb, clone,
16141618
actions, len);
16151619

16161620
if (clone_flow_key)
1617-
__this_cpu_dec(exec_actions_level);
1621+
__this_cpu_dec(ovs_pcpu_storage.exec_level);
16181622
} else { /* Recirc action */
16191623
clone->recirc_id = recirc_id;
16201624
ovs_dp_process_packet(skb, clone);
@@ -1650,7 +1654,7 @@ static int clone_execute(struct datapath *dp, struct sk_buff *skb,
16501654

16511655
static void process_deferred_actions(struct datapath *dp)
16521656
{
1653-
struct action_fifo *fifo = this_cpu_ptr(action_fifos);
1657+
struct action_fifo *fifo = this_cpu_ptr(&ovs_pcpu_storage.action_fifos);
16541658

16551659
/* Do not touch the FIFO in case there is no deferred actions. */
16561660
if (action_fifo_is_empty(fifo))
@@ -1681,7 +1685,7 @@ int ovs_execute_actions(struct datapath *dp, struct sk_buff *skb,
16811685
{
16821686
int err, level;
16831687

1684-
level = __this_cpu_inc_return(exec_actions_level);
1688+
level = __this_cpu_inc_return(ovs_pcpu_storage.exec_level);
16851689
if (unlikely(level > OVS_RECURSION_LIMIT)) {
16861690
net_crit_ratelimited("ovs: recursion limit reached on datapath %s, probable configuration error\n",
16871691
ovs_dp_name(dp));
@@ -1698,27 +1702,6 @@ int ovs_execute_actions(struct datapath *dp, struct sk_buff *skb,
16981702
process_deferred_actions(dp);
16991703

17001704
out:
1701-
__this_cpu_dec(exec_actions_level);
1705+
__this_cpu_dec(ovs_pcpu_storage.exec_level);
17021706
return err;
17031707
}
1704-
1705-
int action_fifos_init(void)
1706-
{
1707-
action_fifos = alloc_percpu(struct action_fifo);
1708-
if (!action_fifos)
1709-
return -ENOMEM;
1710-
1711-
flow_keys = alloc_percpu(struct action_flow_keys);
1712-
if (!flow_keys) {
1713-
free_percpu(action_fifos);
1714-
return -ENOMEM;
1715-
}
1716-
1717-
return 0;
1718-
}
1719-
1720-
void action_fifos_exit(void)
1721-
{
1722-
free_percpu(action_fifos);
1723-
free_percpu(flow_keys);
1724-
}

net/openvswitch/datapath.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2729,13 +2729,9 @@ static int __init dp_init(void)
27292729

27302730
pr_info("Open vSwitch switching datapath\n");
27312731

2732-
err = action_fifos_init();
2733-
if (err)
2734-
goto error;
2735-
27362732
err = ovs_internal_dev_rtnl_link_register();
27372733
if (err)
2738-
goto error_action_fifos_exit;
2734+
goto error;
27392735

27402736
err = ovs_flow_init();
27412737
if (err)
@@ -2778,8 +2774,6 @@ static int __init dp_init(void)
27782774
ovs_flow_exit();
27792775
error_unreg_rtnl_link:
27802776
ovs_internal_dev_rtnl_link_unregister();
2781-
error_action_fifos_exit:
2782-
action_fifos_exit();
27832777
error:
27842778
return err;
27852779
}
@@ -2795,7 +2789,6 @@ static void dp_cleanup(void)
27952789
ovs_vport_exit();
27962790
ovs_flow_exit();
27972791
ovs_internal_dev_rtnl_link_unregister();
2798-
action_fifos_exit();
27992792
}
28002793

28012794
module_init(dp_init);

net/openvswitch/datapath.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,6 @@ int ovs_execute_actions(struct datapath *dp, struct sk_buff *skb,
281281

282282
void ovs_dp_notify_wq(struct work_struct *work);
283283

284-
int action_fifos_init(void);
285-
void action_fifos_exit(void);
286-
287284
/* 'KEY' must not have any bits set outside of the 'MASK' */
288285
#define OVS_MASKED(OLD, KEY, MASK) ((KEY) | ((OLD) & ~(MASK)))
289286
#define OVS_SET_MASKED(OLD, KEY, MASK) ((OLD) = OVS_MASKED(OLD, KEY, MASK))

0 commit comments

Comments
 (0)