Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dpif-netdev: Add command line and function pointer for miniflow extract
This patch introduces the MFEX function pointers which allows the user to switch between different miniflow extract implementations which are provided by the OVS based on optimized ISA CPU. The user can query for the available minflow extract variants available for that CPU by following commands: $ovs-appctl dpif-netdev/miniflow-parser-get Similarly an user can set the miniflow implementation by the following command : $ ovs-appctl dpif-netdev/miniflow-parser-set name This allows for more performance and flexibility to the user to choose the miniflow implementation according to the needs. Signed-off-by: Kumar Amber <kumar.amber@intel.com> Co-authored-by: Harry van Haaren <harry.van.haaren@intel.com> Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com> Acked-by: Eelco Chaudron <echaudro@redhat.com> Acked-by: Flavio Leitner <fbl@sysclose.org> Signed-off-by: Ian Stokes <ian.stokes@intel.com>
- Loading branch information
Showing
7 changed files
with
419 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
/* | ||
* Copyright (c) 2021 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 <stdint.h> | ||
#include <string.h> | ||
|
||
#include "dp-packet.h" | ||
#include "dpif-netdev-private-dpcls.h" | ||
#include "dpif-netdev-private-extract.h" | ||
#include "dpif-netdev-private-thread.h" | ||
#include "flow.h" | ||
#include "openvswitch/vlog.h" | ||
#include "ovs-thread.h" | ||
#include "util.h" | ||
|
||
VLOG_DEFINE_THIS_MODULE(dpif_netdev_extract); | ||
|
||
/* Variable to hold the default MFEX implementation. */ | ||
static ATOMIC(miniflow_extract_func) default_mfex_func; | ||
|
||
/* Implementations of available extract options and | ||
* the implementations are always in order of preference. | ||
*/ | ||
static struct dpif_miniflow_extract_impl mfex_impls[] = { | ||
|
||
[MFEX_IMPL_SCALAR] = { | ||
.probe = NULL, | ||
.extract_func = NULL, | ||
.name = "scalar", }, | ||
}; | ||
|
||
BUILD_ASSERT_DECL(MFEX_IMPL_MAX == ARRAY_SIZE(mfex_impls)); | ||
|
||
void | ||
dpif_miniflow_extract_init(void) | ||
{ | ||
atomic_uintptr_t *mfex_func = (void *)&default_mfex_func; | ||
int mfex_idx = MFEX_IMPL_SCALAR; | ||
|
||
/* Call probe on each impl, and cache the result. */ | ||
for (int i = 0; i < MFEX_IMPL_MAX; i++) { | ||
bool avail = true; | ||
if (mfex_impls[i].probe) { | ||
/* Return zero is success, non-zero means error. */ | ||
avail = (mfex_impls[i].probe() == 0); | ||
} | ||
VLOG_INFO("Miniflow Extract implementation %s (available: %s)\n", | ||
mfex_impls[i].name, avail ? "available" : "not available"); | ||
mfex_impls[i].available = avail; | ||
} | ||
|
||
/* For the first call, this will be choosen based on the | ||
* compile time flag. | ||
*/ | ||
VLOG_INFO("Default MFEX Extract implementation is %s.\n", | ||
mfex_impls[mfex_idx].name); | ||
atomic_store_relaxed(mfex_func, (uintptr_t) mfex_impls | ||
[mfex_idx].extract_func); | ||
} | ||
|
||
miniflow_extract_func | ||
dp_mfex_impl_get_default(void) | ||
{ | ||
miniflow_extract_func return_func; | ||
atomic_uintptr_t *mfex_func = (void *)&default_mfex_func; | ||
|
||
atomic_read_relaxed(mfex_func, (uintptr_t *) &return_func); | ||
|
||
return return_func; | ||
} | ||
|
||
int | ||
dp_mfex_impl_set_default_by_name(const char *name) | ||
{ | ||
miniflow_extract_func new_default; | ||
atomic_uintptr_t *mfex_func = (void *)&default_mfex_func; | ||
|
||
int err = dp_mfex_impl_get_by_name(name, &new_default); | ||
|
||
if (!err) { | ||
atomic_store_relaxed(mfex_func, (uintptr_t) new_default); | ||
} | ||
|
||
return err; | ||
|
||
} | ||
|
||
void | ||
dp_mfex_impl_get(struct ds *reply, struct dp_netdev_pmd_thread **pmd_list, | ||
size_t pmd_list_size) | ||
{ | ||
/* Add all MFEX functions to reply string. */ | ||
ds_put_cstr(reply, "Available MFEX implementations:\n"); | ||
|
||
for (int i = 0; i < MFEX_IMPL_MAX; i++) { | ||
ds_put_format(reply, " %s (available: %s pmds: ", | ||
mfex_impls[i].name, mfex_impls[i].available ? | ||
"True" : "False"); | ||
|
||
for (size_t j = 0; j < pmd_list_size; j++) { | ||
struct dp_netdev_pmd_thread *pmd = pmd_list[j]; | ||
if (pmd->core_id == NON_PMD_CORE_ID) { | ||
continue; | ||
} | ||
|
||
if (pmd->miniflow_extract_opt == mfex_impls[i].extract_func) { | ||
ds_put_format(reply, "%u,", pmd->core_id); | ||
} | ||
} | ||
|
||
ds_chomp(reply, ','); | ||
|
||
if (ds_last(reply) == ' ') { | ||
ds_put_cstr(reply, "none"); | ||
} | ||
|
||
ds_put_cstr(reply, ")\n"); | ||
} | ||
|
||
} | ||
|
||
/* This function checks all available MFEX implementations, and selects and | ||
* returns the function pointer to the one requested by "name". If nothing | ||
* is found it returns error. | ||
*/ | ||
int | ||
dp_mfex_impl_get_by_name(const char *name, miniflow_extract_func *out_func) | ||
{ | ||
if (!name || !out_func) { | ||
return -EINVAL; | ||
} | ||
|
||
for (int i = 0; i < MFEX_IMPL_MAX; i++) { | ||
if (strcmp(mfex_impls[i].name, name) == 0) { | ||
/* Check available is set before exec. */ | ||
if (!mfex_impls[i].available) { | ||
*out_func = NULL; | ||
return -ENODEV; | ||
} | ||
|
||
*out_func = mfex_impls[i].extract_func; | ||
return 0; | ||
} | ||
} | ||
|
||
return -ENOENT; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
* Copyright (c) 2021 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. | ||
*/ | ||
|
||
#ifndef MFEX_AVX512_EXTRACT | ||
#define MFEX_AVX512_EXTRACT 1 | ||
|
||
#include <sys/types.h> | ||
|
||
/* Forward declarations. */ | ||
struct dp_packet; | ||
struct miniflow; | ||
struct dp_netdev_pmd_thread; | ||
struct dp_packet_batch; | ||
struct netdev_flow_key; | ||
|
||
/* Function pointer prototype to be implemented in the optimized miniflow | ||
* extract code. | ||
* returns the hitmask of the processed packets on success. | ||
* returns zero on failure. | ||
*/ | ||
typedef uint32_t (*miniflow_extract_func)(struct dp_packet_batch *batch, | ||
struct netdev_flow_key *keys, | ||
uint32_t keys_size, | ||
odp_port_t in_port, | ||
struct dp_netdev_pmd_thread | ||
*pmd_handle); | ||
|
||
|
||
/* The function pointer miniflow_extract_func depends on batch size. */ | ||
BUILD_ASSERT_DECL(NETDEV_MAX_BURST == 32); | ||
|
||
/* Probe function is used to detect if this CPU has the ISA required | ||
* to run the optimized miniflow implementation. | ||
* returns one on successful probe. | ||
* returns negative errno on failure. | ||
*/ | ||
typedef int (*miniflow_extract_probe)(void); | ||
|
||
/* Structure representing the attributes of an optimized implementation. */ | ||
struct dpif_miniflow_extract_impl { | ||
/* When it is true, this impl has passed the probe() checks. */ | ||
bool available; | ||
|
||
/* Probe function is used to detect if this CPU has the ISA required | ||
* to run the optimized miniflow implementation. It is optional and | ||
* if it is not used, then it must be null. | ||
*/ | ||
miniflow_extract_probe probe; | ||
|
||
/* Optional function to call to extract miniflows for a burst of packets. | ||
* If it is not used must be set to NULL; | ||
*/ | ||
miniflow_extract_func extract_func; | ||
|
||
/* Name of the optimized implementation. */ | ||
char *name; | ||
}; | ||
|
||
|
||
/* Enum to hold implementation indexes. The list is traversed | ||
* linearly as from the ISA perspective, the VBMI version | ||
* should always come before the generic AVX512-F version. | ||
*/ | ||
enum dpif_miniflow_extract_impl_idx { | ||
MFEX_IMPL_SCALAR, | ||
MFEX_IMPL_MAX | ||
}; | ||
|
||
extern struct ovs_mutex dp_netdev_mutex; | ||
|
||
/* This function returns all available implementations to the caller. The | ||
* quantity of implementations is returned by the int return value. | ||
*/ | ||
void | ||
dp_mfex_impl_get(struct ds *reply, struct dp_netdev_pmd_thread **pmd_list, | ||
size_t pmd_list_size) OVS_REQUIRES(dp_netdev_mutex); | ||
|
||
/* This function checks all available MFEX implementations, and selects the | ||
* returns the function pointer to the one requested by "name". | ||
*/ | ||
int | ||
dp_mfex_impl_get_by_name(const char *name, miniflow_extract_func *out_func); | ||
|
||
/* Returns the default MFEX which is first ./configure selected, but can be | ||
* overridden at runtime. */ | ||
miniflow_extract_func dp_mfex_impl_get_default(void); | ||
|
||
/* Overrides the default MFEX with the user set MFEX. */ | ||
int dp_mfex_impl_set_default_by_name(const char *name); | ||
|
||
|
||
/* Initializes the available miniflow extract implementations by probing for | ||
* the CPU ISA requirements. As the runtime available CPU ISA does not change | ||
* and the required ISA of the implementation also does not change, it is safe | ||
* to cache the probe() results, and not call probe() at runtime. | ||
*/ | ||
void | ||
dpif_miniflow_extract_init(void); | ||
|
||
#endif /* MFEX_AVX512_EXTRACT */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.