Skip to content

Commit

Permalink
dpif-netdev: Add command line and function pointer for miniflow extract
Browse files Browse the repository at this point in the history
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 allow 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>
Signed-off-by: Ian Stokes <ian.stokes@intel.com>
  • Loading branch information
2 people authored and istokes committed Jun 22, 2021
1 parent 7106a3c commit 803d4aa
Show file tree
Hide file tree
Showing 6 changed files with 337 additions and 7 deletions.
2 changes: 2 additions & 0 deletions lib/automake.mk
Expand Up @@ -118,6 +118,8 @@ lib_libopenvswitch_la_SOURCES = \
lib/dpif-netdev-private-dpcls.h \
lib/dpif-netdev-private-dpif.c \
lib/dpif-netdev-private-dpif.h \
lib/dpif-netdev-private-extract.c \
lib/dpif-netdev-private-extract.h \
lib/dpif-netdev-private-flow.h \
lib/dpif-netdev-private-hwol.h \
lib/dpif-netdev-private-thread.h \
Expand Down
32 changes: 27 additions & 5 deletions lib/dpif-netdev-avx512.c
Expand Up @@ -148,6 +148,15 @@ dp_netdev_input_outer_avx512(struct dp_netdev_pmd_thread *pmd,
* // do all processing (HWOL->MFEX->EMC->SMC)
* }
*/

/* Do a batch minfilow extract into keys. */
uint32_t mf_mask = 0;
if (pmd->miniflow_extract_opt) {
mf_mask = pmd->miniflow_extract_opt(packets, keys,
batch_size, in_port,
(void *) pmd);
}
/* Perform first packet interation */
uint32_t lookup_pkts_bitmask = (1ULL << batch_size) - 1;
uint32_t iter = lookup_pkts_bitmask;
while (iter) {
Expand All @@ -159,26 +168,39 @@ dp_netdev_input_outer_avx512(struct dp_netdev_pmd_thread *pmd,
pkt_metadata_init(&packet->md, in_port);

struct dp_netdev_flow *f = NULL;
struct netdev_flow_key *key = &keys[i];

/* Check the minfiflow mask to see if the packet was correctly
* classifed by vector mfex else do a scalar miniflow extract
* for that packet. */
uint32_t mfex_hit = (mf_mask & (1 << i));

/* Check for partial hardware offload mark. */
uint32_t mark;
if (dp_packet_has_flow_mark(packet, &mark)) {
f = mark_to_flow_find(pmd, mark);
if (f) {
rules[i] = &f->cr;
pkt_meta[i].tcp_flags = parse_tcp_flags(packet);
/* If AVX512 MFEX already classified the packet, use it. */
if (mfex_hit) {
pkt_meta[i].tcp_flags = miniflow_get_tcp_flags(&key->mf);
} else {
pkt_meta[i].tcp_flags = parse_tcp_flags(packet);
}

pkt_meta[i].bytes = dp_packet_size(packet);
phwol_hits++;
hwol_emc_smc_hitmask |= (1 << i);
continue;
}
}

/* Do miniflow extract into keys. */
struct netdev_flow_key *key = &keys[i];
miniflow_extract(packet, &key->mf);
if (!mfex_hit) {
/* Do a scalar miniflow extract into keys */
miniflow_extract(packet, &key->mf);
}

/* Cache TCP and byte values for all packets. */
/* Cache TCP and byte values for all packets */
pkt_meta[i].bytes = dp_packet_size(packet);
pkt_meta[i].tcp_flags = miniflow_get_tcp_flags(&key->mf);

Expand Down
86 changes: 86 additions & 0 deletions lib/dpif-netdev-private-extract.c
@@ -0,0 +1,86 @@
/*
* 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);

/* Implementations of available extract options. */
static struct dpif_miniflow_extract_impl mfex_impls[] = {
{
.probe = NULL,
.extract_func = NULL,
.name = "disable",
},
};

BUILD_ASSERT_DECL(MFEX_IMPLS_MAX_SIZE > ARRAY_SIZE(mfex_impls));

int32_t
dpif_miniflow_extract_opt_get(const char *name,
struct dpif_miniflow_extract_impl **opt)
{
ovs_assert(opt);
ovs_assert(name);

uint32_t i;
for (i = 0; i < ARRAY_SIZE(mfex_impls); i++) {
if (strcmp(name, mfex_impls[i].name) == 0) {
*opt = &mfex_impls[i];
return 0;
}
}
return -ENOTSUP;
}

void
dpif_miniflow_extract_init(void)
{
/* Call probe on each impl, and cache the result. */
uint32_t i;
for (i = 0; i < ARRAY_SIZE(mfex_impls); i++) {
int avail = 1;
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 ? "True" : "False");
mfex_impls[i].available = avail;
}
}

int32_t
dpif_miniflow_extract_info_get(struct dpif_miniflow_extract_impl **out_ptr)
{
if (out_ptr == NULL) {
return -EINVAL;
}
*out_ptr = mfex_impls;
return ARRAY_SIZE(mfex_impls);
}
94 changes: 94 additions & 0 deletions lib/dpif-netdev-private-extract.h
@@ -0,0 +1,94 @@
/*
* 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 DPIF_NETDEV_AVX512_EXTRACT
#define DPIF_NETDEV_AVX512_EXTRACT 1

#include <sys/types.h>

#include "openvswitch/types.h"

/* Max size of dpif_miniflow_extract_impl array. */
#define MFEX_IMPLS_MAX_SIZE (16)

/* 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,
void *pmd_handle);

/* 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 zero on failure.
*/
typedef int32_t (*miniflow_extract_probe)(void);

/* Structure representing the attributes of an optimized implementation. */
struct dpif_miniflow_extract_impl {
/* When non-zero, this impl has passed the probe() checks. */
uint8_t available;

/* Probe function is used to detect if this CPU has the ISA required
* to run the optimized miniflow implementation.
*/
miniflow_extract_probe probe;

/* Function to call to extract miniflows for a burst of packets. */
miniflow_extract_func extract_func;

/* Name of the optimized implementation. */
char *name;
};

/* Retrieve the opt structure for the requested implementation by name.
* Returns zero on success, and opt points to a valid struct, or
* returns a negative failure status.
* -ENOTSUP : invalid name requested
*/
int32_t
dpif_miniflow_extract_opt_get(const char *name,
struct dpif_miniflow_extract_impl **opt);

/* 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);

/* Retrieve the array of miniflow implementations for iteration.
* On error, returns a negative number.
* On success, returns the size of the arrays pointed to by the out parameter.
*/
int32_t
dpif_miniflow_extract_info_get(struct dpif_miniflow_extract_impl **out_ptr);


#endif /* DPIF_NETDEV_AVX512_EXTRACT */
4 changes: 4 additions & 0 deletions lib/dpif-netdev-private-thread.h
Expand Up @@ -28,6 +28,7 @@
#include "dpif-netdev-private-dpif.h"
#include "dpif-netdev-perf.h"
#include "openvswitch/thread.h"
#include "dpif-netdev-private-extract.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -110,6 +111,9 @@ struct dp_netdev_pmd_thread {
/* Pointer for per-DPIF implementation scratch space. */
void *netdev_input_func_userdata;

/* Function pointer to call for miniflow_extract() functionality. */
miniflow_extract_func miniflow_extract_opt;

struct seq *reload_seq;
uint64_t last_reload_seq;

Expand Down

0 comments on commit 803d4aa

Please sign in to comment.