]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
openvswitch: Merge three per-CPU structures into one
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>
Mon, 12 May 2025 09:27:28 +0000 (11:27 +0200)
committerPaolo Abeni <pabeni@redhat.com>
Thu, 15 May 2025 13:23:31 +0000 (15:23 +0200)
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>
net/openvswitch/actions.c
net/openvswitch/datapath.c
net/openvswitch/datapath.h

index 2f22ca59586f2545c3394057d9fd048eb516fd0d..7e4a8d41b9ed6fcdaa3262a4b50634a1d68db5d5 100644 (file)
@@ -78,17 +78,22 @@ struct action_flow_keys {
        struct sw_flow_key key[OVS_DEFERRED_ACTION_THRESHOLD];
 };
 
-static struct action_fifo __percpu *action_fifos;
-static struct action_flow_keys __percpu *flow_keys;
-static DEFINE_PER_CPU(int, exec_actions_level);
+struct ovs_pcpu_storage {
+       struct action_fifo action_fifos;
+       struct action_flow_keys flow_keys;
+       int exec_level;
+};
+
+static DEFINE_PER_CPU(struct ovs_pcpu_storage, ovs_pcpu_storage);
 
 /* Make a clone of the 'key', using the pre-allocated percpu 'flow_keys'
  * space. Return NULL if out of key spaces.
  */
 static struct sw_flow_key *clone_key(const struct sw_flow_key *key_)
 {
-       struct action_flow_keys *keys = this_cpu_ptr(flow_keys);
-       int level = this_cpu_read(exec_actions_level);
+       struct ovs_pcpu_storage *ovs_pcpu = this_cpu_ptr(&ovs_pcpu_storage);
+       struct action_flow_keys *keys = &ovs_pcpu->flow_keys;
+       int level = ovs_pcpu->exec_level;
        struct sw_flow_key *key = NULL;
 
        if (level <= OVS_DEFERRED_ACTION_THRESHOLD) {
@@ -132,10 +137,9 @@ static struct deferred_action *add_deferred_actions(struct sk_buff *skb,
                                    const struct nlattr *actions,
                                    const int actions_len)
 {
-       struct action_fifo *fifo;
+       struct action_fifo *fifo = this_cpu_ptr(&ovs_pcpu_storage.action_fifos);
        struct deferred_action *da;
 
-       fifo = this_cpu_ptr(action_fifos);
        da = action_fifo_put(fifo);
        if (da) {
                da->skb = skb;
@@ -1608,13 +1612,13 @@ static int clone_execute(struct datapath *dp, struct sk_buff *skb,
 
                if (actions) { /* Sample action */
                        if (clone_flow_key)
-                               __this_cpu_inc(exec_actions_level);
+                               __this_cpu_inc(ovs_pcpu_storage.exec_level);
 
                        err = do_execute_actions(dp, skb, clone,
                                                 actions, len);
 
                        if (clone_flow_key)
-                               __this_cpu_dec(exec_actions_level);
+                               __this_cpu_dec(ovs_pcpu_storage.exec_level);
                } else { /* Recirc action */
                        clone->recirc_id = recirc_id;
                        ovs_dp_process_packet(skb, clone);
@@ -1650,7 +1654,7 @@ static int clone_execute(struct datapath *dp, struct sk_buff *skb,
 
 static void process_deferred_actions(struct datapath *dp)
 {
-       struct action_fifo *fifo = this_cpu_ptr(action_fifos);
+       struct action_fifo *fifo = this_cpu_ptr(&ovs_pcpu_storage.action_fifos);
 
        /* Do not touch the FIFO in case there is no deferred actions. */
        if (action_fifo_is_empty(fifo))
@@ -1681,7 +1685,7 @@ int ovs_execute_actions(struct datapath *dp, struct sk_buff *skb,
 {
        int err, level;
 
-       level = __this_cpu_inc_return(exec_actions_level);
+       level = __this_cpu_inc_return(ovs_pcpu_storage.exec_level);
        if (unlikely(level > OVS_RECURSION_LIMIT)) {
                net_crit_ratelimited("ovs: recursion limit reached on datapath %s, probable configuration error\n",
                                     ovs_dp_name(dp));
@@ -1698,27 +1702,6 @@ int ovs_execute_actions(struct datapath *dp, struct sk_buff *skb,
                process_deferred_actions(dp);
 
 out:
-       __this_cpu_dec(exec_actions_level);
+       __this_cpu_dec(ovs_pcpu_storage.exec_level);
        return err;
 }
-
-int action_fifos_init(void)
-{
-       action_fifos = alloc_percpu(struct action_fifo);
-       if (!action_fifos)
-               return -ENOMEM;
-
-       flow_keys = alloc_percpu(struct action_flow_keys);
-       if (!flow_keys) {
-               free_percpu(action_fifos);
-               return -ENOMEM;
-       }
-
-       return 0;
-}
-
-void action_fifos_exit(void)
-{
-       free_percpu(action_fifos);
-       free_percpu(flow_keys);
-}
index 5d548eda742dfc43fcd3d07458704ee9b7e9ed64..aaa6277bb49c2506f848b9c83c3b34e68ec55986 100644 (file)
@@ -2729,13 +2729,9 @@ static int __init dp_init(void)
 
        pr_info("Open vSwitch switching datapath\n");
 
-       err = action_fifos_init();
-       if (err)
-               goto error;
-
        err = ovs_internal_dev_rtnl_link_register();
        if (err)
-               goto error_action_fifos_exit;
+               goto error;
 
        err = ovs_flow_init();
        if (err)
@@ -2778,8 +2774,6 @@ error_flow_exit:
        ovs_flow_exit();
 error_unreg_rtnl_link:
        ovs_internal_dev_rtnl_link_unregister();
-error_action_fifos_exit:
-       action_fifos_exit();
 error:
        return err;
 }
@@ -2795,7 +2789,6 @@ static void dp_cleanup(void)
        ovs_vport_exit();
        ovs_flow_exit();
        ovs_internal_dev_rtnl_link_unregister();
-       action_fifos_exit();
 }
 
 module_init(dp_init);
index 384ca77f4e794ce91c371932dd8dff59a914d127..a12640792605858ab41b3a1f0aa264f21760efec 100644 (file)
@@ -281,9 +281,6 @@ int ovs_execute_actions(struct datapath *dp, struct sk_buff *skb,
 
 void ovs_dp_notify_wq(struct work_struct *work);
 
-int action_fifos_init(void);
-void action_fifos_exit(void);
-
 /* 'KEY' must not have any bits set outside of the 'MASK' */
 #define OVS_MASKED(OLD, KEY, MASK) ((KEY) | ((OLD) & ~(MASK)))
 #define OVS_SET_MASKED(OLD, KEY, MASK) ((OLD) = OVS_MASKED(OLD, KEY, MASK))