mirror of
https://github.com/openvswitch/ovs
synced 2025-08-31 06:15:47 +00:00
odp-execute: Add function pointers to odp-execute for different action implementations.
This commit introduces the initial infrastructure required to allow different implementations for OvS actions. The patch introduces action function pointers which allows user to switch between different action implementations available. This will allow for more performance and flexibility so the user can choose the action implementation to best suite their use case. Signed-off-by: Emma Finn <emma.finn@intel.com> Acked-by: Harry van Haaren <harry.van.haaren@intel.com> Acked-by: Sunil Pai G <sunil.pai.g@intel.com> Acked-by: Eelco Chaudron <echaudro@redhat.com> Signed-off-by: Ian Stokes <ian.stokes@intel.com>
This commit is contained in:
91
lib/odp-execute-private.c
Normal file
91
lib/odp-execute-private.c
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Intel.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "dpdk.h"
|
||||
#include "dp-packet.h"
|
||||
#include "odp-execute-private.h"
|
||||
#include "odp-netlink.h"
|
||||
#include "odp-util.h"
|
||||
#include "openvswitch/vlog.h"
|
||||
|
||||
VLOG_DEFINE_THIS_MODULE(odp_execute_impl);
|
||||
static int active_action_impl_index;
|
||||
|
||||
static struct odp_execute_action_impl action_impls[] = {
|
||||
[ACTION_IMPL_SCALAR] = {
|
||||
.available = false,
|
||||
.name = "scalar",
|
||||
.init_func = NULL,
|
||||
},
|
||||
};
|
||||
|
||||
static void
|
||||
action_impl_copy_funcs(struct odp_execute_action_impl *dest,
|
||||
const struct odp_execute_action_impl *src)
|
||||
{
|
||||
for (int i = 0; i < __OVS_ACTION_ATTR_MAX; i++) {
|
||||
atomic_store_relaxed(&dest->funcs[i], src->funcs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
struct odp_execute_action_impl *
|
||||
odp_execute_action_set(const char *name)
|
||||
{
|
||||
for (int i = 0; i < ACTION_IMPL_MAX; i++) {
|
||||
/* String compare, and set ptrs atomically. */
|
||||
if (!strcmp(action_impls[i].name, name)) {
|
||||
active_action_impl_index = i;
|
||||
|
||||
VLOG_INFO("Action implementation set to %s", name);
|
||||
return &action_impls[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
odp_execute_action_init(void)
|
||||
{
|
||||
/* Each impl's function array is initialized to reflect the scalar
|
||||
* implementation. This simplifies adding optimized implementations,
|
||||
* as the autovalidator can always compare all actions.
|
||||
*
|
||||
* Below will check if impl is available and copies the scalar functions
|
||||
* to all other implementations. */
|
||||
for (int i = 0; i < ACTION_IMPL_MAX; i++) {
|
||||
bool avail = true;
|
||||
|
||||
if (i != ACTION_IMPL_SCALAR) {
|
||||
action_impl_copy_funcs(&action_impls[i],
|
||||
&action_impls[ACTION_IMPL_SCALAR]);
|
||||
}
|
||||
|
||||
if (action_impls[i].init_func) {
|
||||
/* Return zero is success, non-zero means error. */
|
||||
avail = (action_impls[i].init_func(&action_impls[i]) == 0);
|
||||
}
|
||||
|
||||
action_impls[i].available = avail;
|
||||
|
||||
VLOG_INFO("Action implementation %s (available: %s)",
|
||||
action_impls[i].name, avail ? "Yes" : "No");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user