From patchwork Wed Jan 12 09:42:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Finn, Emma" X-Patchwork-Id: 1578951 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=FtJ9uFV1; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JYjL82Y9Sz9sXM for ; Wed, 12 Jan 2022 20:43:28 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 8311783F99; Wed, 12 Jan 2022 09:43:23 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Nljf088oclEv; Wed, 12 Jan 2022 09:43:22 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp1.osuosl.org (Postfix) with ESMTPS id E536983F2E; Wed, 12 Jan 2022 09:43:20 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 2A24DC0074; Wed, 12 Jan 2022 09:43:19 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 1C013C002F for ; Wed, 12 Jan 2022 09:43:17 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 33C7883F7B for ; Wed, 12 Jan 2022 09:43:16 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DC-gnz5rPDWB for ; Wed, 12 Jan 2022 09:43:15 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by smtp1.osuosl.org (Postfix) with ESMTPS id 0DA3883F7C for ; Wed, 12 Jan 2022 09:43:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641980595; x=1673516595; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pDHKtTnfGJ9NrSr+CGvU12zvEwYMu5mWgYRphq+ZTdQ=; b=FtJ9uFV1KQsziSrOeAHDDya30tWHn7iz0cyQVhB2rdcnwolwNR3S16CX tVa3Aez6s9FoV6IohbsE9XVLUm2mVZRrIRbeJXwosW4/mNomPGpJCu1ai 9P7PdNlYdoRNy1WFy+T7dik2VdkoltxcavonUyvoH489G4BUsbt4BjgoP N5gjlda8h+0hcOpHS1OpdswLnld3FJ9CpNwtw5h6LP5MZqOHgqTPTCxqA TDinDHwDqoHccPCr8M9aw49VATDyneWrVwphA7o6jXMg9VdRAJaeTDfLZ IpeCYSNPYzGXYm7OgEy3RBZotX6TcMXWAwk5e/9nKgKD/ZNIS+shiUc8y w==; X-IronPort-AV: E=McAfee;i="6200,9189,10224"; a="224394744" X-IronPort-AV: E=Sophos;i="5.88,282,1635231600"; d="scan'208";a="224394744" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2022 01:43:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,282,1635231600"; d="scan'208";a="490688267" Received: from silpixa00400899.ir.intel.com ([10.243.23.110]) by orsmga002.jf.intel.com with ESMTP; 12 Jan 2022 01:43:07 -0800 From: Emma Finn To: dev@openvswitch.org, harry.van.haaren@intel.com, kumar.amber@intel.com, ian.stokes@intel.com, i.maximets@ovn.org Date: Wed, 12 Jan 2022 09:42:37 +0000 Message-Id: <20220112094244.81402-2-emma.finn@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220112094244.81402-1-emma.finn@intel.com> References: <20220105165349.3447695-1-emma.finn@intel.com> <20220112094244.81402-1-emma.finn@intel.com> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH v5 1/8] odp-execute: Add function pointers to odp-execute for different action implementations. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" 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 Acked-by: Harry van Haaren --- lib/automake.mk | 2 + lib/dpif-netdev.c | 2 + lib/odp-execute-private.c | 84 +++++++++++++++++++++++++++++++++ lib/odp-execute-private.h | 98 +++++++++++++++++++++++++++++++++++++++ lib/odp-execute.c | 39 ++++++++++++++-- lib/odp-execute.h | 4 ++ 6 files changed, 224 insertions(+), 5 deletions(-) create mode 100644 lib/odp-execute-private.c create mode 100644 lib/odp-execute-private.h diff --git a/lib/automake.mk b/lib/automake.mk index 5224e0856..1bc855a6b 100644 --- a/lib/automake.mk +++ b/lib/automake.mk @@ -203,6 +203,8 @@ lib_libopenvswitch_la_SOURCES = \ lib/nx-match.h \ lib/object-collection.c \ lib/object-collection.h \ + lib/odp-execute-private.c \ + lib/odp-execute-private.h \ lib/odp-execute.c \ lib/odp-execute.h \ lib/odp-util.c \ diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 649c700cb..eada4fcd7 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -1618,6 +1618,8 @@ create_dpif_netdev(struct dp_netdev *dp) dpif->dp = dp; dpif->last_port_seq = seq_read(dp->port_seq); + odp_execute_init(); + return &dpif->dpif; } diff --git a/lib/odp-execute-private.c b/lib/odp-execute-private.c new file mode 100644 index 000000000..6441c491c --- /dev/null +++ b/lib/odp-execute-private.c @@ -0,0 +1,84 @@ +/* + * 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 +#include +#include +#include +#include "dpdk.h" + +#include "openvswitch/vlog.h" +#include "odp-execute-private.h" +#include "odp-netlink.h" +#include "dp-packet.h" +#include "odp-util.h" + + +int32_t action_autoval_init(struct odp_execute_action_impl *self); +VLOG_DEFINE_THIS_MODULE(odp_execute_private); + +static struct odp_execute_action_impl action_impls[] = { + [ACTION_IMPL_SCALAR] = { + .available = 1, + .name = "scalar", + .probe = NULL, + .init_func = NULL, + }, +}; + +static void +action_impl_copy_funcs(struct odp_execute_action_impl *to, + const struct odp_execute_action_impl *from) +{ + for (uint32_t i = 0; i < __OVS_KEY_ATTR_MAX; i++) { + atomic_uintptr_t *func = (void *) &to->funcs[i]; + atomic_store_relaxed(func, (uintptr_t) from->funcs[i]); + } +} + +void +odp_execute_action_init(void) +{ + /* Call probe on each impl, and cache the result. */ + for (int i = 0; i < ACTION_IMPL_MAX; i++) { + bool avail = true; + if (action_impls[i].probe) { + /* Return zero is success, non-zero means error. */ + avail = (action_impls[i].probe() == 0); + } + VLOG_INFO("Action implementation %s (available: %s)\n", + action_impls[i].name, avail ? "available" : "not available"); + action_impls[i].available = avail; + } + + uint32_t i; + for (i = 0; i < ACTION_IMPL_MAX; i++) { + /* 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 copies the scalar functions to all other implementations. + */ + if (i != ACTION_IMPL_SCALAR) { + action_impl_copy_funcs(&action_impls[i], + &action_impls[ACTION_IMPL_SCALAR]); + } + + if (action_impls[i].init_func) { + action_impls[i].init_func(&action_impls[i]); + } + } +} diff --git a/lib/odp-execute-private.h b/lib/odp-execute-private.h new file mode 100644 index 000000000..c2e86bbee --- /dev/null +++ b/lib/odp-execute-private.h @@ -0,0 +1,98 @@ +/* + * 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 ODP_EXTRACT_PRIVATE +#define ODP_EXTRACT_PRIVATE 1 + +#include "odp-execute.h" + +/* For __OVS_KEY_ATTR_MAX. */ +#include "odp-netlink.h" +#include "dp-packet.h" +#include "ovs-atomic.h" + +/* Forward declaration for typedef. */ +struct odp_execute_action_impl; + +/* Typedef for an initialization function that can initialize each + * implementation, checking requirements such as CPU ISA. + */ +typedef int32_t (*odp_execute_action_init_func) + (struct odp_execute_action_impl *self); + +/* Probe function is used to detect if this CPU has the ISA required + * to run the optimized action implementation. + * returns one on successful probe. + * returns negative errno on failure. + */ +typedef int (*odp_execute_action_probe)(void); + +/* Structure represents an implementation of the odp actions. */ +struct odp_execute_action_impl { + /* When set, the CPU ISA required for this implementation is available + * and the implementation can be used. + */ + bool available; + + /* Name of the implementation. */ + const char *name; + + /* 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. + */ + odp_execute_action_probe probe; + + /* Called to check requirements and if usable, initializes the + * implementation for use. + */ + odp_execute_action_init_func init_func; + + /* An array of callback functions, one for each action. */ + ATOMIC(odp_execute_cb) funcs[__OVS_KEY_ATTR_MAX]; +}; + +/* Order of Actions implementations. */ +enum odp_execute_action_impl_idx { + ACTION_IMPL_SCALAR, + /* See ACTION_IMPL_BEGIN below, for "first to-be-validated" impl. + * Do not change the autovalidator position in this list without updating + * the define below. + */ + + ACTION_IMPL_MAX, +}; + +/* Index to start verifying implementations from. */ +BUILD_ASSERT_DECL(ACTION_IMPL_SCALAR == 0); + +/* Odp execute init handles setting up the state of the actions functions at + * initialization time. It cannot return errors, as it must always succeed in + * initializing the scalar/generic codepath. + */ +void odp_execute_action_init(void); + +/* Update the current active functions to those requested in name. */ +void odp_execute_action_get(struct ds *name); +int32_t odp_execute_action_set(const char *name, + struct odp_execute_action_impl *active); + +/* Init function for the scalar implementation. Calls into the odp-execute.c + * file, and initializes the function pointers for optimized action types. + */ +int32_t odp_action_scalar_init(struct odp_execute_action_impl *self); + +#endif /* ODP_EXTRACT_PRIVATE */ diff --git a/lib/odp-execute.c b/lib/odp-execute.c index 6eeda2a61..49dfa2a74 100644 --- a/lib/odp-execute.c +++ b/lib/odp-execute.c @@ -17,6 +17,7 @@ #include #include "odp-execute.h" +#include "odp-execute-private.h" #include #include #include @@ -830,6 +831,23 @@ requires_datapath_assistance(const struct nlattr *a) return false; } +/* The active function pointers on the datapath. ISA optimized implementations + * are enabled by plugging them into this static arary, which is consulted when + * applying actions on the datapath. + */ +static struct odp_execute_action_impl actions_active_impl; + +void +odp_execute_init(void) +{ + static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER; + if (ovsthread_once_start(&once)) { + odp_execute_action_init(); + ovsthread_once_done(&once); + } +} + + /* Executes all of the 'actions_len' bytes of datapath actions in 'actions' on * the packets in 'batch'. If 'steal' is true, possibly modifies and * definitely free the packets in 'batch', otherwise leaves 'batch' unchanged. @@ -855,13 +873,12 @@ odp_execute_actions(void *dp, struct dp_packet_batch *batch, bool steal, NL_ATTR_FOR_EACH_UNSAFE (a, left, actions, actions_len) { int type = nl_attr_type(a); bool last_action = (left <= NLA_ALIGN(a->nla_len)); + /* Allow 'dp_execute_action' to steal the packet data if we do + * not need it any more. */ + bool should_steal = steal && last_action; if (requires_datapath_assistance(a)) { if (dp_execute_action) { - /* Allow 'dp_execute_action' to steal the packet data if we do - * not need it any more. */ - bool should_steal = steal && last_action; - dp_execute_action(dp, batch, a, should_steal); if (last_action || dp_packet_batch_is_empty(batch)) { @@ -876,8 +893,20 @@ odp_execute_actions(void *dp, struct dp_packet_batch *batch, bool steal, continue; } - switch ((enum ovs_action_attr) type) { + /* If type is set in the active actions implementation, call the + * function-pointer and an continue to the next action. + */ + enum ovs_action_attr attr_type = (enum ovs_action_attr) type; + if (actions_active_impl.funcs[attr_type]) { + actions_active_impl.funcs[attr_type](NULL, batch, a, should_steal); + continue; + } + + /* If the action was not handled by the active function pointers above, + * process them by switching on the type below. + */ + switch (attr_type) { case OVS_ACTION_ATTR_HASH: { const struct ovs_action_hash *hash_act = nl_attr_get(a); diff --git a/lib/odp-execute.h b/lib/odp-execute.h index a3578a575..c4f5303e7 100644 --- a/lib/odp-execute.h +++ b/lib/odp-execute.h @@ -28,6 +28,10 @@ struct dp_packet; struct pkt_metadata; struct dp_packet_batch; + +/* Called once at initialization time. */ +void odp_execute_init(void); + typedef void (*odp_execute_cb)(void *dp, struct dp_packet_batch *batch, const struct nlattr *action, bool should_steal); From patchwork Wed Jan 12 09:42:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Finn, Emma" X-Patchwork-Id: 1578949 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=TkbZ6Evd; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JYjL26TQlz9s0r for ; Wed, 12 Jan 2022 20:43:22 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 54F9D428C5; Wed, 12 Jan 2022 09:43:20 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id IdS_a5x_LFEU; Wed, 12 Jan 2022 09:43:19 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id 8F214428D3; Wed, 12 Jan 2022 09:43:18 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 5D30BC002F; Wed, 12 Jan 2022 09:43:18 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 55C86C0038 for ; Wed, 12 Jan 2022 09:43:16 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id CFA2383F2E for ; Wed, 12 Jan 2022 09:43:15 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp1.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=intel.com Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id UR1f8NFh4kP3 for ; Wed, 12 Jan 2022 09:43:15 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by smtp1.osuosl.org (Postfix) with ESMTPS id 2926383F7B for ; Wed, 12 Jan 2022 09:43:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641980595; x=1673516595; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qvTTh6phWTlU+kuxOPwRss2urrB6f9UDBil2DHqlV/c=; b=TkbZ6Evdd6hZs90j8ooFZEBWXZ57WYmDAzmyziy/xR7ysAy6zwREwbM/ epl+jlV5fDyZ0tYtaDApL9BIHIz2e1YAGQOEeUERTCKnCTW0FQw03C9GX jddklrvGDt8sZv/C9zi43Pu3eVSF1AEH/HbFL848OpaTGIpDwOe0SBZJr hjnbuB/tLXWNVfQGepOphiR7yu8ckt5vXZanjlQxr9xDvt8x0fX1Rquk9 93Lj9k7Ifv7ZAE+KKSSwP6AdTQ2B2xqR4Alkfuc7cD6R/Hdj1SH1cUdUq Gztg1nflGCaCnms6gkmUJ5Qq7DsS4hgcMKYJNXAK/yiPPjMacr+7qfun2 Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10224"; a="224394749" X-IronPort-AV: E=Sophos;i="5.88,282,1635231600"; d="scan'208";a="224394749" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2022 01:43:13 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,282,1635231600"; d="scan'208";a="490688280" Received: from silpixa00400899.ir.intel.com ([10.243.23.110]) by orsmga002.jf.intel.com with ESMTP; 12 Jan 2022 01:43:11 -0800 From: Emma Finn To: dev@openvswitch.org, harry.van.haaren@intel.com, kumar.amber@intel.com, ian.stokes@intel.com, i.maximets@ovn.org Date: Wed, 12 Jan 2022 09:42:38 +0000 Message-Id: <20220112094244.81402-3-emma.finn@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220112094244.81402-1-emma.finn@intel.com> References: <20220105165349.3447695-1-emma.finn@intel.com> <20220112094244.81402-1-emma.finn@intel.com> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH v5 2/8] odp-execute: Add function pointer for pop_vlan action. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" This commit removes the pop_vlan action from the large switch and creates a separate function for batched processing. A function pointer is also added to call the new batched function for the pop_vlan action. Signed-off-by: Emma Finn Acked-by: Harry van Haaren --- lib/odp-execute-private.c | 19 +++++++++++++++++- lib/odp-execute.c | 41 +++++++++++++++++++++++++++++++++------ lib/odp-execute.h | 2 ++ 3 files changed, 55 insertions(+), 7 deletions(-) diff --git a/lib/odp-execute-private.c b/lib/odp-execute-private.c index 6441c491c..d88ff4921 100644 --- a/lib/odp-execute-private.c +++ b/lib/odp-execute-private.c @@ -29,13 +29,14 @@ int32_t action_autoval_init(struct odp_execute_action_impl *self); VLOG_DEFINE_THIS_MODULE(odp_execute_private); +static uint32_t active_action_impl_index; static struct odp_execute_action_impl action_impls[] = { [ACTION_IMPL_SCALAR] = { .available = 1, .name = "scalar", .probe = NULL, - .init_func = NULL, + .init_func = odp_action_scalar_init, }, }; @@ -49,6 +50,22 @@ action_impl_copy_funcs(struct odp_execute_action_impl *to, } } +int32_t +odp_execute_action_set(const char *name, + struct odp_execute_action_impl *active) +{ + uint32_t i; + for (i = 0; i < ACTION_IMPL_MAX; i++) { + /* string compare, and set ptrs *atomically*. */ + if (strcmp(action_impls[i].name, name) == 0) { + action_impl_copy_funcs(active, &action_impls[i]); + active_action_impl_index = i; + return 0; + } + } + return -1; +} + void odp_execute_action_init(void) { diff --git a/lib/odp-execute.c b/lib/odp-execute.c index 49dfa2a74..ab051aecc 100644 --- a/lib/odp-execute.c +++ b/lib/odp-execute.c @@ -831,6 +831,28 @@ requires_datapath_assistance(const struct nlattr *a) return false; } +static void +action_pop_vlan(void *dp OVS_UNUSED, struct dp_packet_batch *batch, + const struct nlattr *a OVS_UNUSED, + bool should_steal OVS_UNUSED) +{ + struct dp_packet *packet; + DP_PACKET_BATCH_FOR_EACH (i, packet, batch) { + eth_pop_vlan(packet); + } +} + +/* Implementation of the scalar actions impl init function. Build up the + * array of func ptrs here. + */ +int32_t +odp_action_scalar_init(struct odp_execute_action_impl *self) +{ + self->funcs[OVS_ACTION_ATTR_POP_VLAN] = action_pop_vlan; + + return 0; +} + /* The active function pointers on the datapath. ISA optimized implementations * are enabled by plugging them into this static arary, which is consulted when * applying actions on the datapath. @@ -843,10 +865,22 @@ odp_execute_init(void) static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER; if (ovsthread_once_start(&once)) { odp_execute_action_init(); + odp_actions_impl_set("scalar"); ovsthread_once_done(&once); } } +int32_t +odp_actions_impl_set(const char *name) +{ + + int err = odp_execute_action_set(name, &actions_active_impl); + if (err) { + VLOG_ERR("error %d from action set to %s\n", err, name); + return -1; + } + return 0; +} /* Executes all of the 'actions_len' bytes of datapath actions in 'actions' on * the packets in 'batch'. If 'steal' is true, possibly modifies and @@ -962,12 +996,6 @@ odp_execute_actions(void *dp, struct dp_packet_batch *batch, bool steal, break; } - case OVS_ACTION_ATTR_POP_VLAN: - DP_PACKET_BATCH_FOR_EACH (i, packet, batch) { - eth_pop_vlan(packet); - } - break; - case OVS_ACTION_ATTR_PUSH_MPLS: { const struct ovs_action_push_mpls *mpls = nl_attr_get(a); @@ -1100,6 +1128,7 @@ odp_execute_actions(void *dp, struct dp_packet_batch *batch, bool steal, } case OVS_ACTION_ATTR_OUTPUT: case OVS_ACTION_ATTR_LB_OUTPUT: + case OVS_ACTION_ATTR_POP_VLAN: case OVS_ACTION_ATTR_TUNNEL_PUSH: case OVS_ACTION_ATTR_TUNNEL_POP: case OVS_ACTION_ATTR_USERSPACE: diff --git a/lib/odp-execute.h b/lib/odp-execute.h index c4f5303e7..6441392b9 100644 --- a/lib/odp-execute.h +++ b/lib/odp-execute.h @@ -32,6 +32,8 @@ struct dp_packet_batch; /* Called once at initialization time. */ void odp_execute_init(void); +int32_t odp_actions_impl_set(const char *name); + typedef void (*odp_execute_cb)(void *dp, struct dp_packet_batch *batch, const struct nlattr *action, bool should_steal); From patchwork Wed Jan 12 09:42:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Finn, Emma" X-Patchwork-Id: 1578950 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=Nr3XZ+wi; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JYjL80sHDz9s0r for ; Wed, 12 Jan 2022 20:43:28 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id B81D9428E1; Wed, 12 Jan 2022 09:43:25 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id sxDri8lKofJ0; Wed, 12 Jan 2022 09:43:24 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id 936FB428E6; Wed, 12 Jan 2022 09:43:22 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 02321C0077; Wed, 12 Jan 2022 09:43:20 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 34AA6C0075 for ; Wed, 12 Jan 2022 09:43:19 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id B5EB183F7A for ; Wed, 12 Jan 2022 09:43:17 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp1.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=intel.com Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PSnFpWhDkc1H for ; Wed, 12 Jan 2022 09:43:17 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by smtp1.osuosl.org (Postfix) with ESMTPS id 02B9B83F2E for ; Wed, 12 Jan 2022 09:43:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641980597; x=1673516597; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+ZMhXyoTgawI0zXjxat+6SGh3rxPu9GJE51Ke5ZvJww=; b=Nr3XZ+wiz8wZ8g0aGL869tRd0ga39CD7Rwdy4puKZpDpI0rFoXOQLnfa pEJdXPPBFGYgdpGh5hnsD2r9haEhXpmptb4F1FZQwWjbwDFYATZGv/KDx cuNpNeLJo9PaWWO1GTZVnMtNrTe4MLo1p6tizicRJjGa6jXg8WQQbpnQ+ fkIHCgqmOBtzmvIYSkep8VnkP8goJT8W7lHCrhOLeyOHQB48EhRFj8mzB z9lKyfbfWigLJZ9abs5F8G65H8y+I5b3LPrxUUF82J32OPvka5WnHAXmd Bfm45c9V/h/DSgybhC7bXLrbN3GGBECoEN9O8YRTjOUhbrpa/WuOOSe3N w==; X-IronPort-AV: E=McAfee;i="6200,9189,10224"; a="224394758" X-IronPort-AV: E=Sophos;i="5.88,282,1635231600"; d="scan'208";a="224394758" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2022 01:43:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,282,1635231600"; d="scan'208";a="490688294" Received: from silpixa00400899.ir.intel.com ([10.243.23.110]) by orsmga002.jf.intel.com with ESMTP; 12 Jan 2022 01:43:15 -0800 From: Emma Finn To: dev@openvswitch.org, harry.van.haaren@intel.com, kumar.amber@intel.com, ian.stokes@intel.com, i.maximets@ovn.org Date: Wed, 12 Jan 2022 09:42:39 +0000 Message-Id: <20220112094244.81402-4-emma.finn@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220112094244.81402-1-emma.finn@intel.com> References: <20220105165349.3447695-1-emma.finn@intel.com> <20220112094244.81402-1-emma.finn@intel.com> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH v5 3/8] odp-execute: Add auto validation function for actions. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" This commit introduced the auto-validation function which allows users to compare the batch of packets obtained from different action implementations against the linear action implementation. The autovalidator function can be triggered at runtime using the following command: $ ovs-appctl dpif-netdev/action-impl-set autovalidator Signed-off-by: Emma Finn Acked-by: Harry van Haaren --- NEWS | 2 + lib/dp-packet.c | 23 +++++++++ lib/dp-packet.h | 5 ++ lib/odp-execute-private.c | 99 +++++++++++++++++++++++++++++++++++++++ lib/odp-execute-private.h | 3 ++ 5 files changed, 132 insertions(+) diff --git a/NEWS b/NEWS index afef81b40..26be454df 100644 --- a/NEWS +++ b/NEWS @@ -19,6 +19,8 @@ Post-v2.16.0 * Add support for DPDK 21.11. * Forbid use of DPDK multiprocess feature. * Add support for running threads on cores >= RTE_MAX_LCORE. + * Add actions auto-validator function to compare different actions + implementations against default implementation. - Python: * For SSL support, the use of the pyOpenSSL library has been replaced with the native 'ssl' module. diff --git a/lib/dp-packet.c b/lib/dp-packet.c index 72f6d09ac..1e4ff35ef 100644 --- a/lib/dp-packet.c +++ b/lib/dp-packet.c @@ -506,3 +506,26 @@ dp_packet_resize_l2(struct dp_packet *b, int increment) dp_packet_adjust_layer_offset(&b->l2_5_ofs, increment); return dp_packet_data(b); } + +bool +dp_packet_compare_and_log(struct dp_packet *good, struct dp_packet *test, + struct ds *err_str) +{ + if ((good->l2_pad_size != test->l2_pad_size) || + (good->l2_5_ofs != test->l2_5_ofs) || + (good->l3_ofs != test->l3_ofs) || + (good->l4_ofs != test->l4_ofs)) { + ds_put_format(err_str, "Autovalidation packet offsets failed" + "\n"); + ds_put_format(err_str, "Good offsets: l2_pad_size %u," + " l2_5_ofs : %u l3_ofs %u, l4_ofs %u\n", + good->l2_pad_size, good->l2_5_ofs, + good->l3_ofs, good->l4_ofs); + ds_put_format(err_str, "Test offsets: l2_pad_size %u," + " l2_5_ofs : %u l3_ofs %u, l4_ofs %u\n", + test->l2_pad_size, test->l2_5_ofs, + test->l3_ofs, test->l4_ofs); + return false; + } + return true; +} diff --git a/lib/dp-packet.h b/lib/dp-packet.h index ee0805ae6..723215add 100644 --- a/lib/dp-packet.h +++ b/lib/dp-packet.h @@ -236,6 +236,11 @@ void *dp_packet_steal_data(struct dp_packet *); static inline bool dp_packet_equal(const struct dp_packet *, const struct dp_packet *); + +bool dp_packet_compare_and_log(struct dp_packet *good, + struct dp_packet *test, + struct ds *err_str); + /* Frees memory that 'b' points to, as well as 'b' itself. */ static inline void diff --git a/lib/odp-execute-private.c b/lib/odp-execute-private.c index d88ff4921..a4155b5df 100644 --- a/lib/odp-execute-private.c +++ b/lib/odp-execute-private.c @@ -30,8 +30,16 @@ int32_t action_autoval_init(struct odp_execute_action_impl *self); VLOG_DEFINE_THIS_MODULE(odp_execute_private); static uint32_t active_action_impl_index; +static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1); static struct odp_execute_action_impl action_impls[] = { + [ACTION_IMPL_AUTOVALIDATOR] = { + .available = 1, + .name = "autovalidator", + .probe = NULL, + .init_func = action_autoval_init, + }, + [ACTION_IMPL_SCALAR] = { .available = 1, .name = "scalar", @@ -99,3 +107,94 @@ odp_execute_action_init(void) } } } + +/* Init sequence required to be scalar first to pick up the default scalar +* implementations, allowing over-riding of the optimized functions later. +*/ +BUILD_ASSERT_DECL(ACTION_IMPL_SCALAR == 0); +BUILD_ASSERT_DECL(ACTION_IMPL_AUTOVALIDATOR == 1); + +/* Loop over packets, and validate each one for the given action. */ +static void +action_autoval_generic(void *dp OVS_UNUSED, struct dp_packet_batch *batch, + const struct nlattr *a, bool should_steal) +{ + uint32_t failed = 0; + + int type = nl_attr_type(a); + enum ovs_action_attr attr_type = (enum ovs_action_attr) type; + + struct odp_execute_action_impl *scalar = &action_impls[ACTION_IMPL_SCALAR]; + + struct dp_packet_batch good_batch; + dp_packet_batch_clone(&good_batch, batch); + + scalar->funcs[attr_type](NULL, &good_batch, a, should_steal); + + for (uint32_t impl = ACTION_IMPL_BEGIN; impl < ACTION_IMPL_MAX; impl++) { + /* Clone original batch and execute implementation under test. */ + struct dp_packet_batch test_batch; + dp_packet_batch_clone(&test_batch, batch); + action_impls[impl].funcs[attr_type](NULL, &test_batch, a, + should_steal); + + /* Loop over implementations, checking each one. */ + for (uint32_t pidx = 0; pidx < batch->count; pidx++) { + struct dp_packet *good_pkt = good_batch.packets[pidx]; + struct dp_packet *test_pkt = test_batch.packets[pidx]; + + struct ds log_msg = DS_EMPTY_INITIALIZER; + + /* Compare packet length and payload contents. */ + bool eq = dp_packet_equal(good_pkt, test_pkt); + + if (!eq) { + ds_put_format(&log_msg, "Packet: %d\nAction : ", pidx); + format_odp_actions(&log_msg, a, a->nla_len, NULL); + ds_put_format(&log_msg, "\nGood hex:\n"); + ds_put_hex_dump(&log_msg, dp_packet_data(good_pkt), + dp_packet_size(good_pkt), 0, false); + ds_put_format(&log_msg, "Test hex:\n"); + ds_put_hex_dump(&log_msg, dp_packet_data(test_pkt), + dp_packet_size(test_pkt), 0, false); + + failed = 1; + } + + /* Compare offsets and RSS */ + if (!dp_packet_compare_and_log(good_pkt, test_pkt, &log_msg)) { + failed = 1; + } + + uint32_t good_hash = dp_packet_get_rss_hash(good_pkt); + uint32_t test_hash = dp_packet_get_rss_hash(test_pkt); + + if (good_hash != test_hash) { + ds_put_format(&log_msg, "Autovalidation rss hash failed" + "\n"); + ds_put_format(&log_msg, "Good RSS hash : %u\n", good_hash); + ds_put_format(&log_msg, "Test RSS hash : %u\n", test_hash); + + failed = 1; + } + + if (failed) { + VLOG_ERR_RL(&rl, "\nAutovalidation failed details:\n%s", + ds_cstr(&log_msg)); + } + } + dp_packet_delete_batch(&test_batch, 1); + } + dp_packet_delete_batch(&good_batch, 1); + + /* Apply the action to the original batch for continued processing. */ + scalar->funcs[attr_type](NULL, batch, a, should_steal); +} + +int32_t +action_autoval_init(struct odp_execute_action_impl *self) +{ + self->funcs[OVS_ACTION_ATTR_POP_VLAN] = action_autoval_generic; + + return 0; +} diff --git a/lib/odp-execute-private.h b/lib/odp-execute-private.h index c2e86bbee..d49714bd2 100644 --- a/lib/odp-execute-private.h +++ b/lib/odp-execute-private.h @@ -68,6 +68,7 @@ struct odp_execute_action_impl { /* Order of Actions implementations. */ enum odp_execute_action_impl_idx { ACTION_IMPL_SCALAR, + ACTION_IMPL_AUTOVALIDATOR, /* See ACTION_IMPL_BEGIN below, for "first to-be-validated" impl. * Do not change the autovalidator position in this list without updating * the define below. @@ -78,6 +79,8 @@ enum odp_execute_action_impl_idx { /* Index to start verifying implementations from. */ BUILD_ASSERT_DECL(ACTION_IMPL_SCALAR == 0); +BUILD_ASSERT_DECL(ACTION_IMPL_AUTOVALIDATOR == 1); +#define ACTION_IMPL_BEGIN (ACTION_IMPL_AUTOVALIDATOR + 1) /* Odp execute init handles setting up the state of the actions functions at * initialization time. It cannot return errors, as it must always succeed in From patchwork Wed Jan 12 09:42:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Finn, Emma" X-Patchwork-Id: 1578952 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=FW/HizAA; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JYjLB5JPpz9s0r for ; Wed, 12 Jan 2022 20:43:30 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id DDF9B428C9; Wed, 12 Jan 2022 09:43:27 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zFnh3JpYEILv; Wed, 12 Jan 2022 09:43:26 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id 7FB25428F5; Wed, 12 Jan 2022 09:43:24 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 01C7BC0070; Wed, 12 Jan 2022 09:43:22 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 43F8AC0070 for ; Wed, 12 Jan 2022 09:43:21 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 236D083F84 for ; Wed, 12 Jan 2022 09:43:21 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp1.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=intel.com Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Eg2gZB2Zvw_6 for ; Wed, 12 Jan 2022 09:43:20 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by smtp1.osuosl.org (Postfix) with ESMTPS id 5AA7983F7D for ; Wed, 12 Jan 2022 09:43:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641980600; x=1673516600; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qd2qwdHPFnplsCE4aSh4/VAqxka3wdjBI2y+yW98ef4=; b=FW/HizAAZSXDdhS0qvv/yb9hy+QG5ErU2CMXlxWPNRAiv9adrI9HMcG3 l14Bx8PXODbJg4sPA3NYC1KSE/ANfpjzPfHK3pT8jGTQ0oj4LjfFLSj6L X+QppsG44V5dIB6qv0fs6LwYSAvg7r1z7Fo3cUW9/WmEsEGX7+CpfY2pr ZoreEmwci31TOtmkR2gvWUXwUxkpu4WiFIZjKNRf3NqrOPtsJ4jvsyLkx QSFWPN+UNKAFgD092kdFMyoNWgC9u5M4kQoD0LElWWQFYZ8PyCrXRWNNM MMcrOwf1Bc2uaL0TyRnOsRqiSxoKSo+Wayui1ccPOy4VcoO6hsWePoW+W Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10224"; a="224394766" X-IronPort-AV: E=Sophos;i="5.88,282,1635231600"; d="scan'208";a="224394766" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2022 01:43:20 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,282,1635231600"; d="scan'208";a="490688322" Received: from silpixa00400899.ir.intel.com ([10.243.23.110]) by orsmga002.jf.intel.com with ESMTP; 12 Jan 2022 01:43:18 -0800 From: Emma Finn To: dev@openvswitch.org, harry.van.haaren@intel.com, kumar.amber@intel.com, ian.stokes@intel.com, i.maximets@ovn.org Date: Wed, 12 Jan 2022 09:42:40 +0000 Message-Id: <20220112094244.81402-5-emma.finn@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220112094244.81402-1-emma.finn@intel.com> References: <20220105165349.3447695-1-emma.finn@intel.com> <20220112094244.81402-1-emma.finn@intel.com> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH v5 4/8] odp-execute: Add command to switch action implementation. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" This commit adds a new command to allow the user to switch the active action implementation at runtime. A probe function is executed before switching the implementation, to ensure the CPU is capable of running the ISA required. Usage: $ ovs-appctl dpif-netdev/action-impl-set scalar This commit also adds a new command to retrieve the list of available action implementations. This can be used by to check what implementations of actions are available and what implementation is active during runtime. Usage: $ ovs-appctl dpif-netdev/action-impl-get Added separate test-case for ovs-actions get/set commands: 1023: PMD - ovs-actions configuration Signed-off-by: Emma Finn Co-authored-by: Kumar Amber Signed-off-by: Kumar Amber Acked-by: Harry van Haaren --- NEWS | 2 ++ lib/dpif-netdev-unixctl.man | 6 ++++++ lib/dpif-netdev.c | 39 +++++++++++++++++++++++++++++++++++++ lib/odp-execute-private.c | 14 +++++++++++++ lib/odp-execute.h | 3 +++ tests/pmd.at | 21 ++++++++++++++++++++ 6 files changed, 85 insertions(+) diff --git a/NEWS b/NEWS index 26be454df..42bb876da 100644 --- a/NEWS +++ b/NEWS @@ -21,6 +21,8 @@ Post-v2.16.0 * Add support for running threads on cores >= RTE_MAX_LCORE. * Add actions auto-validator function to compare different actions implementations against default implementation. + * Add command line option to switch between different actions + implementations available at run time. - Python: * For SSL support, the use of the pyOpenSSL library has been replaced with the native 'ssl' module. diff --git a/lib/dpif-netdev-unixctl.man b/lib/dpif-netdev-unixctl.man index 8cd847416..500daf4de 100644 --- a/lib/dpif-netdev-unixctl.man +++ b/lib/dpif-netdev-unixctl.man @@ -262,3 +262,9 @@ PMDs in the case where no value is specified. By default "scalar" is used. \fIstudy_cnt\fR defaults to 128 and indicates the number of packets that the "study" miniflow implementation must parse before choosing an optimal implementation. + +.IP "\fBdpif-netdev/action-impl-get\fR +Lists the actions implementations that are available. +. +.IP "\fBdpif-netdev/action-impl-set\fR \fIaction_impl\fR" +Sets the action to be used to \fIaction_impl\fR. By default "scalar" is used. diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index eada4fcd7..f6cc779ef 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -60,6 +60,7 @@ #include "netdev-vport.h" #include "netlink.h" #include "odp-execute.h" +#include "odp-execute-private.h" #include "odp-util.h" #include "openvswitch/dynamic-string.h" #include "openvswitch/list.h" @@ -1330,6 +1331,38 @@ error: ds_destroy(&reply); } +static void +action_impl_set(struct unixctl_conn *conn, int argc OVS_UNUSED, + const char *argv[] OVS_UNUSED, void *aux OVS_UNUSED) +{ + struct ds reply = DS_EMPTY_INITIALIZER; + + int32_t err = odp_actions_impl_set(argv[1]); + if (err) { + ds_put_format(&reply, "action implementation %s not found.\n", + argv[1]); + const char *reply_str = ds_cstr(&reply); + unixctl_command_reply_error(conn, reply_str); + VLOG_ERR("%s", reply_str); + ds_destroy(&reply); + return; + } + + ds_put_format(&reply, "action implementation set to %s.\n", argv[1]); + unixctl_command_reply(conn, ds_cstr(&reply)); + ds_destroy(&reply); +} + +static void +action_impl_get(struct unixctl_conn *conn, int argc OVS_UNUSED, + const char *argv[] OVS_UNUSED, void *aux OVS_UNUSED) +{ + struct ds reply = DS_EMPTY_INITIALIZER; + odp_execute_action_get(&reply); + unixctl_command_reply(conn, ds_cstr(&reply)); + ds_destroy(&reply); +} + static void dpif_netdev_pmd_rebalance(struct unixctl_conn *conn, int argc, const char *argv[], void *aux OVS_UNUSED) @@ -1567,6 +1600,12 @@ dpif_netdev_init(void) unixctl_command_register("dpif-netdev/miniflow-parser-get", "", 0, 0, dpif_miniflow_extract_impl_get, NULL); + unixctl_command_register("dpif-netdev/action-impl-set", "name", + 1, 1, action_impl_set, + NULL); + unixctl_command_register("dpif-netdev/action-impl-get", "", + 0, 0, action_impl_get, + NULL); return 0; } diff --git a/lib/odp-execute-private.c b/lib/odp-execute-private.c index a4155b5df..c17882a33 100644 --- a/lib/odp-execute-private.c +++ b/lib/odp-execute-private.c @@ -74,6 +74,20 @@ odp_execute_action_set(const char *name, return -1; } +void +odp_execute_action_get(struct ds *string) +{ + uint32_t i; + + ds_put_cstr(string, "Available Actions implementations:\n"); + for (i = 0; i < ACTION_IMPL_MAX; i++) { + ds_put_format(string, " %s (available: %s, active: %s)\n", + action_impls[i].name, + action_impls[i].available ? "True" : "False", + i == active_action_impl_index ? "True" : "False"); + } +} + void odp_execute_action_init(void) { diff --git a/lib/odp-execute.h b/lib/odp-execute.h index 6441392b9..4f4cdc4ac 100644 --- a/lib/odp-execute.h +++ b/lib/odp-execute.h @@ -23,6 +23,7 @@ #include #include "openvswitch/types.h" +struct ds; struct nlattr; struct dp_packet; struct pkt_metadata; @@ -32,6 +33,8 @@ struct dp_packet_batch; /* Called once at initialization time. */ void odp_execute_init(void); +/* Runtime update get/set functionality. */ +int32_t odp_actions_impl_get(struct ds *name); int32_t odp_actions_impl_set(const char *name); typedef void (*odp_execute_cb)(void *dp, struct dp_packet_batch *batch, diff --git a/tests/pmd.at b/tests/pmd.at index a2f9d34a2..df0b3b54c 100644 --- a/tests/pmd.at +++ b/tests/pmd.at @@ -1162,3 +1162,24 @@ ovs-appctl: ovs-vswitchd: server returned an error OVS_VSWITCHD_STOP AT_CLEANUP + +AT_SETUP([PMD - ovs-actions configuration]) +OVS_VSWITCHD_START([], [], [], [--dummy-numa 0,0]) +AT_CHECK([ovs-vsctl add-port br0 p1 -- set Interface p1 type=dummy-pmd]) + +dnl Set the scalar first, so we always have the scalar impl as Active. +AT_CHECK([ovs-appctl dpif-netdev/action-impl-set scalar], [0], [dnl +action implementation set to scalar. +]) + +AT_CHECK([ovs-vsctl show], [], [stdout]) +AT_CHECK([ovs-appctl dpif-netdev/action-impl-get | grep "scalar"], [], [dnl + scalar (available: True, active: True) +]) + +AT_CHECK([ovs-appctl dpif-netdev/action-impl-get | grep "autovalidator"], [], [dnl + autovalidator (available: True, active: False) +]) + +OVS_VSWITCHD_STOP +AT_CLEANUP \ No newline at end of file From patchwork Wed Jan 12 09:42:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Finn, Emma" X-Patchwork-Id: 1578953 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=jitrMJQB; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JYjLJ4QRxz9s0r for ; Wed, 12 Jan 2022 20:43:36 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id CF1D66FBB4; Wed, 12 Jan 2022 09:43:33 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id mmVESg1e4rIP; Wed, 12 Jan 2022 09:43:32 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp3.osuosl.org (Postfix) with ESMTPS id 955916FBBA; Wed, 12 Jan 2022 09:43:30 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 56D70C001E; Wed, 12 Jan 2022 09:43:30 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 1B062C0038 for ; Wed, 12 Jan 2022 09:43:29 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id E0EFE83FA1 for ; Wed, 12 Jan 2022 09:43:24 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp1.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=intel.com Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ijYQzNxYnrBF for ; Wed, 12 Jan 2022 09:43:23 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by smtp1.osuosl.org (Postfix) with ESMTPS id 473C783F98 for ; Wed, 12 Jan 2022 09:43:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641980603; x=1673516603; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=MIf14mr3bh6ye1Av+G05lDzgD6+GZgMSr0ElmJfFh6o=; b=jitrMJQBOui6vKLkjACOvwJIF6onBVd+qYQCJEXkS800qIbddFQHP/4A OCjs6kjc/Be/oDr8MLVNbGnlCmlgaFupDMa4akWaHLHhJ+XYkuftJ693c wnYSgbzPIwhdRQsFHJ/e+LZ9LJaNXfPfJ3E0JVjJ7uDtAv/lkwTs6MMa+ 3egBl6eeZ8hA5rjVClJQ1zcp8ah2lO0C/w2tZqZHVxhf80El8O4bkaHNJ my5nsuniIKF7qFvpZm9dyki6b5zvPxerJxIlZyvEb9HmrfNTHDCqJ/Lsa 0cw1YvkcJksxjpv7FYDC8tpRdpT3u+4ja7eYw+qLSeQNs49c/ESYC04Vb g==; X-IronPort-AV: E=McAfee;i="6200,9189,10224"; a="224394773" X-IronPort-AV: E=Sophos;i="5.88,282,1635231600"; d="scan'208";a="224394773" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2022 01:43:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,282,1635231600"; d="scan'208";a="490688345" Received: from silpixa00400899.ir.intel.com ([10.243.23.110]) by orsmga002.jf.intel.com with ESMTP; 12 Jan 2022 01:43:21 -0800 From: Emma Finn To: dev@openvswitch.org, harry.van.haaren@intel.com, kumar.amber@intel.com, ian.stokes@intel.com, i.maximets@ovn.org Date: Wed, 12 Jan 2022 09:42:41 +0000 Message-Id: <20220112094244.81402-6-emma.finn@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220112094244.81402-1-emma.finn@intel.com> References: <20220105165349.3447695-1-emma.finn@intel.com> <20220112094244.81402-1-emma.finn@intel.com> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH v5 5/8] dpif-netdev: Add configure option to enable actions autovalidator at build time. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Kumar Amber This commit adds a new command to allow the user to enable the actions autovalidator by default at build time thus allowing for running unit test by default. $ ./configure --enable-actions-default-autovalidator Signed-off-by: Kumar Amber Acked-by: Harry van Haaren --- NEWS | 2 ++ acinclude.m4 | 17 +++++++++++++++++ configure.ac | 1 + lib/odp-execute.c | 4 ++++ 4 files changed, 24 insertions(+) diff --git a/NEWS b/NEWS index 42bb876da..1fd2f7375 100644 --- a/NEWS +++ b/NEWS @@ -23,6 +23,8 @@ Post-v2.16.0 implementations against default implementation. * Add command line option to switch between different actions implementations available at run time. + * Add build time configure command to enable auto-validator as default + actions implementation at build time. - Python: * For SSL support, the use of the pyOpenSSL library has been replaced with the native 'ssl' module. diff --git a/acinclude.m4 b/acinclude.m4 index 23cd6df44..6514f2bd7 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -14,6 +14,23 @@ # See the License for the specific language governing permissions and # limitations under the License. +dnl Set OVS Actions Autovalidator as default action at compile time? +dnl This enables automatically running all unit tests with all actions +dnl implementations. +AC_DEFUN([OVS_CHECK_ACTIONS_AUTOVALIDATOR], [ + AC_ARG_ENABLE([actions-default-autovalidator], + [AC_HELP_STRING([--enable-actions-default-autovalidator], [Enable actions autovalidator as default ovs actions implementation.])], + [autovalidator=yes],[autovalidator=no]) + AC_MSG_CHECKING([whether actions Autovalidator is default implementation]) + if test "$autovalidator" != yes; then + AC_MSG_RESULT([no]) + else + OVS_CFLAGS="$OVS_CFLAGS -DACTIONS_AUTOVALIDATOR_DEFAULT" + AC_MSG_RESULT([yes]) + fi +]) + + dnl Set OVS MFEX Autovalidator as default miniflow extract at compile time? dnl This enables automatically running all unit tests with all MFEX dnl implementations. diff --git a/configure.ac b/configure.ac index eaa9bf7ee..bfd0a9aff 100644 --- a/configure.ac +++ b/configure.ac @@ -185,6 +185,7 @@ OVS_CTAGS_IDENTIFIERS OVS_CHECK_DPCLS_AUTOVALIDATOR OVS_CHECK_DPIF_AVX512_DEFAULT OVS_CHECK_MFEX_AUTOVALIDATOR +OVS_CHECK_ACTIONS_AUTOVALIDATOR OVS_CHECK_AVX512 AC_ARG_VAR(KARCH, [Kernel Architecture String]) diff --git a/lib/odp-execute.c b/lib/odp-execute.c index ab051aecc..1bc9fae09 100644 --- a/lib/odp-execute.c +++ b/lib/odp-execute.c @@ -865,7 +865,11 @@ odp_execute_init(void) static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER; if (ovsthread_once_start(&once)) { odp_execute_action_init(); +#ifdef ACTIONS_AUTOVALIDATOR_DEFAULT + odp_actions_impl_set("autovalidator"); +#else odp_actions_impl_set("scalar"); +#endif ovsthread_once_done(&once); } } From patchwork Wed Jan 12 09:42:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Finn, Emma" X-Patchwork-Id: 1578955 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=CxjtzMs6; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JYjLn4zVKz9s0r for ; Wed, 12 Jan 2022 20:44:01 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id E633D6FBE4; Wed, 12 Jan 2022 09:43:59 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ZoRAFnZ-r0pB; Wed, 12 Jan 2022 09:43:58 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp3.osuosl.org (Postfix) with ESMTPS id B7B636FB92; Wed, 12 Jan 2022 09:43:57 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 7F13DC0038; Wed, 12 Jan 2022 09:43:57 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 116A9C001E for ; Wed, 12 Jan 2022 09:43:56 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id B526F83F98 for ; Wed, 12 Jan 2022 09:43:31 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp1.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=intel.com Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ljd1xxny7eKM for ; Wed, 12 Jan 2022 09:43:30 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by smtp1.osuosl.org (Postfix) with ESMTPS id 5189983F9D for ; Wed, 12 Jan 2022 09:43:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641980610; x=1673516610; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KCrVOoakpEmfNhbLaTasbi0qUx8eigP/s/cBsC+gvxI=; b=CxjtzMs6pDySm8Wq08etMTBGpFcBIoRvuw9mjUsPWjMT+11XP8OTvzGV KtNKff3AAg2lmzLGqto7xlJum3wSiziMDyNu6RdTAMZPPi2K2PEAG0iKd d2D05ZGXSNOpniPOiLPoyilctL+JULIdoyOSTQE/1Udh5Q07oXwXbb9EG 4TqZqSmlNM2lLgfWtV3K762u1T3yDQL7SKZMGwTbDa9l6tnrGK7IwK7xq /fN3T/JrB4VpoRxwJWp9Z1uz4dBsFtqcgVc7N5YSJEtcyAmE9DA+Gj66K ruGWUUwaG33F8Irt6dfvLgP1m5VJHkTVmvbaPp8wS4j+Gmi8zd0bwsTSd w==; X-IronPort-AV: E=McAfee;i="6200,9189,10224"; a="241252898" X-IronPort-AV: E=Sophos;i="5.88,282,1635231600"; d="scan'208";a="241252898" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2022 01:43:29 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,282,1635231600"; d="scan'208";a="490688357" Received: from silpixa00400899.ir.intel.com ([10.243.23.110]) by orsmga002.jf.intel.com with ESMTP; 12 Jan 2022 01:43:27 -0800 From: Emma Finn To: dev@openvswitch.org, harry.van.haaren@intel.com, kumar.amber@intel.com, ian.stokes@intel.com, i.maximets@ovn.org Date: Wed, 12 Jan 2022 09:42:42 +0000 Message-Id: <20220112094244.81402-7-emma.finn@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220112094244.81402-1-emma.finn@intel.com> References: <20220105165349.3447695-1-emma.finn@intel.com> <20220112094244.81402-1-emma.finn@intel.com> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH v5 6/8] odp-execute: Add ISA implementation of actions. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" This commit adds the AVX512 implementation of the action functionality. Usage: $ ovs-appctl dpif-netdev/action-impl-set avx512 Signed-off-by: Emma Finn Acked-by: Harry van Haaren --- Documentation/topics/dpdk/bridge.rst | 25 ++++++++++ Documentation/topics/testing.rst | 20 +++++--- NEWS | 1 + lib/automake.mk | 4 +- lib/cpu.c | 1 + lib/cpu.h | 1 + lib/odp-execute-avx512.c | 69 ++++++++++++++++++++++++++++ lib/odp-execute-private.c | 9 ++++ lib/odp-execute-private.h | 9 ++++ 9 files changed, 131 insertions(+), 8 deletions(-) create mode 100644 lib/odp-execute-avx512.c diff --git a/Documentation/topics/dpdk/bridge.rst b/Documentation/topics/dpdk/bridge.rst index ceee91015..67089e08f 100644 --- a/Documentation/topics/dpdk/bridge.rst +++ b/Documentation/topics/dpdk/bridge.rst @@ -321,3 +321,28 @@ following command:: ``scalar`` can be selected on core ``3`` by the following command:: $ ovs-appctl dpif-netdev/miniflow-parser-set -pmd 3 scalar + +Actions Performance +------------------- + +Actions are used in OpenFlow flows to describe what to do when the flow +matches a packet. Just like with the datapath interface, SIMD instructions +can be applied to the action implementation to improve performance. + +OVS provides multiple implementations of the actions. +Available implementations can be listed with the following command:: + + $ ovs-appctl dpif-netdev/action-impl-get + Available Actions implementations: + scalar (available: True, active: True) + autovalidator (available: True, active: False) + avx512 (available: True, active: False) + +By default, ``scalar`` is used. Implementations can be selected by +name:: + + $ ovs-appctl dpif-netdev/action-impl-set avx512 + action implementation set to avx512. + + $ ovs-appctl dpif-netdev/action-impl-set scalar + action implementation set to scalar. diff --git a/Documentation/topics/testing.rst b/Documentation/topics/testing.rst index c15d5b38f..10d0ecc48 100644 --- a/Documentation/topics/testing.rst +++ b/Documentation/topics/testing.rst @@ -361,12 +361,12 @@ testsuite. Userspace datapath: Testing and Validation of CPU-specific Optimizations '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' -As multiple versions of the datapath classifier and packet parsing functions -can co-exist, each with different CPU ISA optimizations, it is important to -validate that they all give the exact same results. To easily test all the -implementations, an ``autovalidator`` implementation of them exists. This -implementation runs all other available implementations, and verifies that the -results are identical. +As multiple versions of the datapath classifier, packet parsing functions and +actions can co-exist, each with different CPU ISA optimizations, it is +important to validate that they all give the exact same results. To easily +test all the implementations, an ``autovalidator`` implementation of them +exists. This implementation runs all other available implementations, and +verifies that the results are identical. Running the OVS unit tests with the autovalidator enabled ensures all implementations provide the same results. Note that the performance of the @@ -382,18 +382,24 @@ To set the autovalidator for the packet parser, use this command:: $ ovs-appctl dpif-netdev/miniflow-parser-set autovalidator +To set the autovalidator for actions, use this command:: + + $ ovs-appctl dpif-netdev/action-impl-set autovalidator + To run the OVS unit test suite with the autovalidator as the default implementation, it is required to recompile OVS. During the recompilation, the default priority of the `autovalidator` implementation is set to the maximum priority, ensuring every test will be run with every implementation:: - $ ./configure --enable-autovalidator --enable-mfex-default-autovalidator + $ ./configure --enable-autovalidator --enable-mfex-default-autovalidator \ + --enable-actions-default-autovalidator The following line should be seen in the configuration log when the above options are used:: checking whether DPCLS Autovalidator is default implementation... yes checking whether MFEX Autovalidator is default implementation... yes + checking whether actions Autovalidator is default implementation... yes Compile OVS in debug mode to have `ovs_assert` statements error out if there is a mis-match in the datapath classifier lookup or packet parser diff --git a/NEWS b/NEWS index 1fd2f7375..72787ccc1 100644 --- a/NEWS +++ b/NEWS @@ -25,6 +25,7 @@ Post-v2.16.0 implementations available at run time. * Add build time configure command to enable auto-validator as default actions implementation at build time. + * Add AVX512 implementation of actions. - Python: * For SSL support, the use of the pyOpenSSL library has been replaced with the native 'ssl' module. diff --git a/lib/automake.mk b/lib/automake.mk index 1bc855a6b..e332c3327 100644 --- a/lib/automake.mk +++ b/lib/automake.mk @@ -32,6 +32,7 @@ lib_libopenvswitch_la_LIBADD += lib/libopenvswitchavx512.la lib_libopenvswitchavx512_la_CFLAGS = \ -mavx512f \ -mavx512bw \ + -mavx512vl \ -mavx512dq \ -mbmi \ -mbmi2 \ @@ -42,7 +43,8 @@ lib_libopenvswitchavx512_la_SOURCES = \ lib/cpu.h \ lib/dpif-netdev-lookup-avx512-gather.c \ lib/dpif-netdev-extract-avx512.c \ - lib/dpif-netdev-avx512.c + lib/dpif-netdev-avx512.c \ + lib/odp-execute-avx512.c lib_libopenvswitchavx512_la_LDFLAGS = \ -static endif diff --git a/lib/cpu.c b/lib/cpu.c index 2df003c51..0292f715e 100644 --- a/lib/cpu.c +++ b/lib/cpu.c @@ -53,6 +53,7 @@ X86_ISA(X86_EXT_FEATURES_LEAF, EBX, 16, OVS_CPU_ISA_X86_AVX512F) X86_ISA(X86_EXT_FEATURES_LEAF, EBX, 30, OVS_CPU_ISA_X86_AVX512BW) X86_ISA(X86_EXT_FEATURES_LEAF, ECX, 1, OVS_CPU_ISA_X86_AVX512VBMI) X86_ISA(X86_EXT_FEATURES_LEAF, ECX, 14, OVS_CPU_ISA_X86_VPOPCNTDQ) +X86_ISA(X86_EXT_FEATURES_LEAF, EBX, 31, OVS_CPU_ISA_X86_AVX512VL) #endif bool diff --git a/lib/cpu.h b/lib/cpu.h index 92897bb71..3215229bc 100644 --- a/lib/cpu.h +++ b/lib/cpu.h @@ -25,6 +25,7 @@ enum ovs_cpu_isa { OVS_CPU_ISA_X86_AVX512F, OVS_CPU_ISA_X86_AVX512BW, OVS_CPU_ISA_X86_AVX512VBMI, + OVS_CPU_ISA_X86_AVX512VL, OVS_CPU_ISA_X86_VPOPCNTDQ, OVS_CPU_ISA_X86_LAST = OVS_CPU_ISA_X86_VPOPCNTDQ, }; diff --git a/lib/odp-execute-avx512.c b/lib/odp-execute-avx512.c new file mode 100644 index 000000000..aa71faa1c --- /dev/null +++ b/lib/odp-execute-avx512.c @@ -0,0 +1,69 @@ +/* + * 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 +#include + +#include "cpu.h" +#include "odp-execute-private.h" +#include "odp-netlink.h" +#include "dp-packet.h" +#include "openvswitch/vlog.h" + +#include "immintrin.h" + + +/* Probe functions to check ISA requirements. */ +static int32_t +avx512_isa_probe(uint32_t needs_vbmi) +{ + static enum ovs_cpu_isa isa_required[] = { + OVS_CPU_ISA_X86_AVX512F, + OVS_CPU_ISA_X86_AVX512BW, + OVS_CPU_ISA_X86_BMI2, + OVS_CPU_ISA_X86_AVX512VL + }; + + int32_t ret = 0; + for (uint32_t i = 0; i < ARRAY_SIZE(isa_required); i++) { + if (!cpu_has_isa(isa_required[i])) { + ret = -ENOTSUP; + } + } + + if (needs_vbmi) { + if (!cpu_has_isa(OVS_CPU_ISA_X86_AVX512VBMI)) { + ret = -ENOTSUP; + } + } + + return ret; +} + +int32_t +action_avx512_probe(void) +{ + const uint32_t needs_vbmi = 0; + return avx512_isa_probe(needs_vbmi); +} + + +int32_t +action_avx512_init(void) +{ + avx512_isa_probe(0); + return 0; +} diff --git a/lib/odp-execute-private.c b/lib/odp-execute-private.c index c17882a33..e61136e8b 100644 --- a/lib/odp-execute-private.c +++ b/lib/odp-execute-private.c @@ -46,6 +46,15 @@ static struct odp_execute_action_impl action_impls[] = { .probe = NULL, .init_func = odp_action_scalar_init, }, + + #if (__x86_64__ && HAVE_AVX512F && HAVE_LD_AVX512_GOOD && __SSE4_2__) + [ACTION_IMPL_AVX512] = { + .available = 1, + .name = "avx512", + .probe = action_avx512_probe, + .init_func = NULL, + }, + #endif }; static void diff --git a/lib/odp-execute-private.h b/lib/odp-execute-private.h index d49714bd2..4c09bee63 100644 --- a/lib/odp-execute-private.h +++ b/lib/odp-execute-private.h @@ -73,6 +73,9 @@ enum odp_execute_action_impl_idx { * Do not change the autovalidator position in this list without updating * the define below. */ + #if (__x86_64__ && HAVE_AVX512F && HAVE_LD_AVX512_GOOD && __SSE4_2__) + ACTION_IMPL_AVX512, + #endif ACTION_IMPL_MAX, }; @@ -98,4 +101,10 @@ int32_t odp_execute_action_set(const char *name, */ int32_t odp_action_scalar_init(struct odp_execute_action_impl *self); +/* Init function for the optimized with AVX512 actions. */ +int32_t action_avx512_init(void); + +/* Probe function to check ISA requirements. */ +int32_t action_avx512_probe(void); + #endif /* ODP_EXTRACT_PRIVATE */ From patchwork Wed Jan 12 09:42:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Finn, Emma" X-Patchwork-Id: 1578956 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=fa9uVuh1; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JYjMJ2kLMz9s0r for ; Wed, 12 Jan 2022 20:44:28 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 0638884B66; Wed, 12 Jan 2022 09:44:25 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FrzGnX7j-a52; Wed, 12 Jan 2022 09:44:23 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp1.osuosl.org (Postfix) with ESMTPS id DCFF384B58; Wed, 12 Jan 2022 09:44:14 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id B029DC002F; Wed, 12 Jan 2022 09:44:14 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 46A4EC001E for ; Wed, 12 Jan 2022 09:44:13 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 178E840A16 for ; Wed, 12 Jan 2022 09:43:38 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp2.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=intel.com Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id EL3Ll7bhFWPS for ; Wed, 12 Jan 2022 09:43:37 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by smtp2.osuosl.org (Postfix) with ESMTPS id 55F2A409FD for ; Wed, 12 Jan 2022 09:43:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641980617; x=1673516617; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UV+gYK2GjlkGCQLA8kknKz/NA2bTdbH6uCg0zAPuxoY=; b=fa9uVuh1rafSYlmVykijBnOFBFoQ/UMcZYMT9mwUXBXOWNIyuBebRquQ AT4dMNOOtiYEXoNvxYDsAQCx9CU9FKaWA1YXKhHs7FxMJF+bNXPp+HP+9 bLketXxZgKRk0X2H2TkVXUxeaStTSL7PzfVC8fU3c2B3UCD9/n7xEPd0j dXsPVFdMz4P1ytDc78Se1TrTN6xGDa4Ctjt1GkxfVldgv495Bzvv2zTHY MIc5/hB5r+W/iY+qoLYr39vdJsxaJBi5+lUv1SF4JV31SoH042LNH3DR3 W+mbyUiV++j8g+bedRAVuigf3AnVQQ8VKk1L2QxrTi/M/YCvOb1HH5BRQ Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10224"; a="242516774" X-IronPort-AV: E=Sophos;i="5.88,282,1635231600"; d="scan'208";a="242516774" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2022 01:43:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,282,1635231600"; d="scan'208";a="490688367" Received: from silpixa00400899.ir.intel.com ([10.243.23.110]) by orsmga002.jf.intel.com with ESMTP; 12 Jan 2022 01:43:34 -0800 From: Emma Finn To: dev@openvswitch.org, harry.van.haaren@intel.com, kumar.amber@intel.com, ian.stokes@intel.com, i.maximets@ovn.org Date: Wed, 12 Jan 2022 09:42:43 +0000 Message-Id: <20220112094244.81402-8-emma.finn@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220112094244.81402-1-emma.finn@intel.com> References: <20220105165349.3447695-1-emma.finn@intel.com> <20220112094244.81402-1-emma.finn@intel.com> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH v5 7/8] odp-execute: Add ISA implementation of pop_vlan action. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" This commit adds the AVX512 implementation of the pop_vlan action. The implementation here is auto-validated by the miniflow extract autovalidator, hence its correctness can be easily tested and verified. Signed-off-by: Emma Finn --- lib/odp-execute-avx512.c | 77 ++++++++++++++++++++++++++++++++++++++- lib/odp-execute-private.c | 2 +- lib/odp-execute-private.h | 2 +- 3 files changed, 78 insertions(+), 3 deletions(-) diff --git a/lib/odp-execute-avx512.c b/lib/odp-execute-avx512.c index aa71faa1c..fcf27f070 100644 --- a/lib/odp-execute-avx512.c +++ b/lib/odp-execute-avx512.c @@ -14,6 +14,11 @@ * limitations under the License. */ +#ifdef __x86_64__ +/* Sparse cannot handle the AVX512 instructions. */ +#if !defined(__CHECKER__) + + #include #include @@ -25,6 +30,71 @@ #include "immintrin.h" +VLOG_DEFINE_THIS_MODULE(odp_execute_avx512); +BUILD_ASSERT_DECL(offsetof(struct dp_packet, l2_5_ofs) + + MEMBER_SIZEOF(struct dp_packet, l2_5_ofs) == + offsetof(struct dp_packet, l3_ofs)); + +BUILD_ASSERT_DECL(offsetof(struct dp_packet, l3_ofs) + + MEMBER_SIZEOF(struct dp_packet, l3_ofs) == + offsetof(struct dp_packet, l4_ofs)); + +static inline void ALWAYS_INLINE +avx512_dp_packet_resize_l2(struct dp_packet *b, int resize_by_bytes) +{ + /* update packet size/data pointers */ + dp_packet_set_data(b, (char *) dp_packet_data(b) - resize_by_bytes); + dp_packet_set_size(b, dp_packet_size(b) + resize_by_bytes); + + /* Increment u16 packet offset values */ + const __m128i v_zeros = _mm_setzero_si128(); + const __m128i v_u16_max = _mm_cmpeq_epi16(v_zeros, v_zeros); + + /* Only these lanes can be incremented for push-VLAN action. */ + const uint8_t k_lanes = 0b1110; + __m128i v_offset = _mm_set1_epi16(VLAN_HEADER_LEN); + + /* Load packet and compare with UINT16_MAX */ + void *adjust_ptr = &b->l2_pad_size; + __m128i v_adjust_src = _mm_loadu_si128(adjust_ptr); + __mmask8 k_cmp = _mm_mask_cmpneq_epu16_mask(k_lanes, v_adjust_src, + v_u16_max); + + /* Add VLAN_HEADER_LEN using compare mask, store results. */ + __m128i v_adjust_wip = _mm_mask_sub_epi16(v_adjust_src, k_cmp, + v_adjust_src, v_offset); + _mm_storeu_si128(adjust_ptr, v_adjust_wip); + +} + +static inline void ALWAYS_INLINE +avx512_eth_pop_vlan(struct dp_packet *packet) +{ + struct vlan_eth_header *veh = dp_packet_eth(packet); + + if (veh && dp_packet_size(packet) >= sizeof *veh && + eth_type_vlan(veh->veth_type)) { + + __m128i v_ether = _mm_loadu_si128((void *) veh); + __m128i v_realign = _mm_alignr_epi8(v_ether, _mm_setzero_si128(), + 16 - VLAN_HEADER_LEN); + _mm_storeu_si128((void *) veh, v_realign); + avx512_dp_packet_resize_l2(packet, -VLAN_HEADER_LEN); + + } +} + +static void +action_avx512_pop_vlan(void *dp OVS_UNUSED, struct dp_packet_batch *batch, + const struct nlattr *a OVS_UNUSED, + bool should_steal OVS_UNUSED) +{ + struct dp_packet *packet; + + DP_PACKET_BATCH_FOR_EACH (i, packet, batch) { + avx512_eth_pop_vlan(packet); + } +} /* Probe functions to check ISA requirements. */ static int32_t @@ -62,8 +132,13 @@ action_avx512_probe(void) int32_t -action_avx512_init(void) +action_avx512_init(struct odp_execute_action_impl *self) { avx512_isa_probe(0); + self->funcs[OVS_ACTION_ATTR_POP_VLAN] = action_avx512_pop_vlan; + return 0; } + +#endif +#endif diff --git a/lib/odp-execute-private.c b/lib/odp-execute-private.c index e61136e8b..175a80159 100644 --- a/lib/odp-execute-private.c +++ b/lib/odp-execute-private.c @@ -52,7 +52,7 @@ static struct odp_execute_action_impl action_impls[] = { .available = 1, .name = "avx512", .probe = action_avx512_probe, - .init_func = NULL, + .init_func = action_avx512_init, }, #endif }; diff --git a/lib/odp-execute-private.h b/lib/odp-execute-private.h index 4c09bee63..5ba2868bf 100644 --- a/lib/odp-execute-private.h +++ b/lib/odp-execute-private.h @@ -102,7 +102,7 @@ int32_t odp_execute_action_set(const char *name, int32_t odp_action_scalar_init(struct odp_execute_action_impl *self); /* Init function for the optimized with AVX512 actions. */ -int32_t action_avx512_init(void); +int32_t action_avx512_init(struct odp_execute_action_impl *self); /* Probe function to check ISA requirements. */ int32_t action_avx512_probe(void); From patchwork Wed Jan 12 09:42:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Finn, Emma" X-Patchwork-Id: 1578958 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=JKqXZmjX; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JYjND3Lwvz9s0r for ; Wed, 12 Jan 2022 20:45:16 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 166CB40A2B; Wed, 12 Jan 2022 09:45:14 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id NQgOLObOZGXv; Wed, 12 Jan 2022 09:45:12 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp2.osuosl.org (Postfix) with ESMTPS id CBAB4409C6; Wed, 12 Jan 2022 09:45:11 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 8FBA0C002F; Wed, 12 Jan 2022 09:45:11 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) by lists.linuxfoundation.org (Postfix) with ESMTP id DCD10C001E for ; Wed, 12 Jan 2022 09:45:10 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 7C6E940A2A for ; Wed, 12 Jan 2022 09:43:56 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PgAfXfRhvSzM for ; Wed, 12 Jan 2022 09:43:55 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by smtp2.osuosl.org (Postfix) with ESMTPS id 52CAA40A48 for ; Wed, 12 Jan 2022 09:43:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641980635; x=1673516635; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=W2jhziTvHuZAEnMaU9A6Qr9R11FIowjFxJNwqDl+/A4=; b=JKqXZmjXuLD+KhM1Z8Ixp+62tySUzgldB/Ob75pTeoq/KXeCDFn/GAgE kX/vuH8L9s7xlQAb0g8d/UziAYrYz5o9NtE2Cj0QzXz36zqx91hUZSKSF B9ot+2t5IFEh/v0E8xuNSd1iVGcilbH8cUq+3/zO+hnRPtAtvyukGFpvP PyzR6E/5irPkg1yOU5s3w5HGEfXnQHdYNQYIVrGyrO+0Gm3V/ZIWRtIVf 2xbrknt/wkv33dFbJy5C3z6jc52kaingLHb1z0YSur4Cjj401h73oYCdu pfGfZWtxWcSSzN8K1k3341xH0MZ2m65M7DXj3bIPi4xYg8x1wDDVrZgy8 A==; X-IronPort-AV: E=McAfee;i="6200,9189,10224"; a="268043494" X-IronPort-AV: E=Sophos;i="5.88,282,1635231600"; d="scan'208";a="268043494" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2022 01:43:42 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,282,1635231600"; d="scan'208";a="490688375" Received: from silpixa00400899.ir.intel.com ([10.243.23.110]) by orsmga002.jf.intel.com with ESMTP; 12 Jan 2022 01:43:40 -0800 From: Emma Finn To: dev@openvswitch.org, harry.van.haaren@intel.com, kumar.amber@intel.com, ian.stokes@intel.com, i.maximets@ovn.org Date: Wed, 12 Jan 2022 09:42:44 +0000 Message-Id: <20220112094244.81402-9-emma.finn@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220112094244.81402-1-emma.finn@intel.com> References: <20220105165349.3447695-1-emma.finn@intel.com> <20220112094244.81402-1-emma.finn@intel.com> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH v5 8/8] odp-execute: Add ISA implementation of push_vlan action. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" This commit adds the AVX512 implementation of the push_vlan action. The implementation here is auto-validated by the miniflow extract autovalidator, hence its correctness can be easily tested and verified. Signed-off-by: Emma Finn --- lib/odp-execute-avx512.c | 62 +++++++++++++++++++++++++++++++++++---- lib/odp-execute-private.c | 1 + lib/odp-execute.c | 24 +++++++++------ 3 files changed, 72 insertions(+), 15 deletions(-) diff --git a/lib/odp-execute-avx512.c b/lib/odp-execute-avx512.c index fcf27f070..03c0fd446 100644 --- a/lib/odp-execute-avx512.c +++ b/lib/odp-execute-avx512.c @@ -43,6 +43,13 @@ static inline void ALWAYS_INLINE avx512_dp_packet_resize_l2(struct dp_packet *b, int resize_by_bytes) { /* update packet size/data pointers */ + if (resize_by_bytes >= 0) { + dp_packet_prealloc_headroom(b, resize_by_bytes); + } else { + ovs_assert(dp_packet_size(b) - dp_packet_l2_pad_size(b) >= + -resize_by_bytes); + } + dp_packet_set_data(b, (char *) dp_packet_data(b) - resize_by_bytes); dp_packet_set_size(b, dp_packet_size(b) + resize_by_bytes); @@ -50,9 +57,9 @@ avx512_dp_packet_resize_l2(struct dp_packet *b, int resize_by_bytes) const __m128i v_zeros = _mm_setzero_si128(); const __m128i v_u16_max = _mm_cmpeq_epi16(v_zeros, v_zeros); - /* Only these lanes can be incremented for push-VLAN action. */ + /* Only these lanes can be incremented/decremented for L2. */ const uint8_t k_lanes = 0b1110; - __m128i v_offset = _mm_set1_epi16(VLAN_HEADER_LEN); + __m128i v_offset = _mm_set1_epi16(abs(resize_by_bytes)); /* Load packet and compare with UINT16_MAX */ void *adjust_ptr = &b->l2_pad_size; @@ -60,9 +67,17 @@ avx512_dp_packet_resize_l2(struct dp_packet *b, int resize_by_bytes) __mmask8 k_cmp = _mm_mask_cmpneq_epu16_mask(k_lanes, v_adjust_src, v_u16_max); - /* Add VLAN_HEADER_LEN using compare mask, store results. */ - __m128i v_adjust_wip = _mm_mask_sub_epi16(v_adjust_src, k_cmp, - v_adjust_src, v_offset); + /* Update VLAN_HEADER_LEN using compare mask, store results. */ + __m128i v_adjust_wip; + + if (resize_by_bytes >= 0) { + v_adjust_wip = _mm_mask_add_epi16(v_adjust_src, k_cmp, + v_adjust_src, v_offset); + } else { + v_adjust_wip = _mm_mask_sub_epi16(v_adjust_src, k_cmp, + v_adjust_src, v_offset); + } + _mm_storeu_si128(adjust_ptr, v_adjust_wip); } @@ -80,7 +95,6 @@ avx512_eth_pop_vlan(struct dp_packet *packet) 16 - VLAN_HEADER_LEN); _mm_storeu_si128((void *) veh, v_realign); avx512_dp_packet_resize_l2(packet, -VLAN_HEADER_LEN); - } } @@ -96,6 +110,41 @@ action_avx512_pop_vlan(void *dp OVS_UNUSED, struct dp_packet_batch *batch, } } +static inline void ALWAYS_INLINE +avx512_eth_push_vlan(struct dp_packet *packet, ovs_be16 tpid, ovs_be16 tci) +{ + avx512_dp_packet_resize_l2(packet, VLAN_HEADER_LEN); + + /* Build up the VLAN TCI/TPID, and merge with the moving of Ether. */ + char *pkt_data = (char *) dp_packet_data(packet); + const uint16_t tci_proc = tci & htons(~VLAN_CFI); + const uint32_t tpid_tci = (tci_proc << 16) | tpid; + + static const uint8_t vlan_push_shuffle_mask[16] = { + 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 0xFF, 0xFF, 0xFF, 0xFF + }; + + __m128i v_ether = _mm_loadu_si128((void *) pkt_data); + __m128i v_index = _mm_loadu_si128((void *) vlan_push_shuffle_mask); + __m128i v_shift = _mm_shuffle_epi8(v_ether, v_index); + __m128i v_vlan_hdr = _mm_insert_epi32(v_shift, tpid_tci, 3); + _mm_storeu_si128((void *) pkt_data, v_vlan_hdr); +} + +static void +action_avx512_push_vlan(void *dp OVS_UNUSED, struct dp_packet_batch *batch, + const struct nlattr *a, + bool should_steal OVS_UNUSED) +{ + struct dp_packet *packet; + const struct ovs_action_push_vlan *vlan = nl_attr_get(a); + + DP_PACKET_BATCH_FOR_EACH (i, packet, batch) { + avx512_eth_push_vlan(packet, vlan->vlan_tpid, vlan->vlan_tci); + } +} + /* Probe functions to check ISA requirements. */ static int32_t avx512_isa_probe(uint32_t needs_vbmi) @@ -136,6 +185,7 @@ action_avx512_init(struct odp_execute_action_impl *self) { avx512_isa_probe(0); self->funcs[OVS_ACTION_ATTR_POP_VLAN] = action_avx512_pop_vlan; + self->funcs[OVS_ACTION_ATTR_PUSH_VLAN] = action_avx512_push_vlan; return 0; } diff --git a/lib/odp-execute-private.c b/lib/odp-execute-private.c index 175a80159..607f0fa94 100644 --- a/lib/odp-execute-private.c +++ b/lib/odp-execute-private.c @@ -218,6 +218,7 @@ int32_t action_autoval_init(struct odp_execute_action_impl *self) { self->funcs[OVS_ACTION_ATTR_POP_VLAN] = action_autoval_generic; + self->funcs[OVS_ACTION_ATTR_PUSH_VLAN] = action_autoval_generic; return 0; } diff --git a/lib/odp-execute.c b/lib/odp-execute.c index 1bc9fae09..40f71fa96 100644 --- a/lib/odp-execute.c +++ b/lib/odp-execute.c @@ -842,6 +842,19 @@ action_pop_vlan(void *dp OVS_UNUSED, struct dp_packet_batch *batch, } } +static void +action_push_vlan(void *dp OVS_UNUSED, struct dp_packet_batch *batch, + const struct nlattr *a OVS_UNUSED, + bool should_steal OVS_UNUSED) +{ + struct dp_packet *packet; + const struct ovs_action_push_vlan *vlan = nl_attr_get(a); + + DP_PACKET_BATCH_FOR_EACH (i, packet, batch) { + eth_push_vlan(packet, vlan->vlan_tpid, vlan->vlan_tci); + } +} + /* Implementation of the scalar actions impl init function. Build up the * array of func ptrs here. */ @@ -849,6 +862,7 @@ int32_t odp_action_scalar_init(struct odp_execute_action_impl *self) { self->funcs[OVS_ACTION_ATTR_POP_VLAN] = action_pop_vlan; + self->funcs[OVS_ACTION_ATTR_PUSH_VLAN] = action_push_vlan; return 0; } @@ -991,15 +1005,6 @@ odp_execute_actions(void *dp, struct dp_packet_batch *batch, bool steal, break; } - case OVS_ACTION_ATTR_PUSH_VLAN: { - const struct ovs_action_push_vlan *vlan = nl_attr_get(a); - - DP_PACKET_BATCH_FOR_EACH (i, packet, batch) { - eth_push_vlan(packet, vlan->vlan_tpid, vlan->vlan_tci); - } - break; - } - case OVS_ACTION_ATTR_PUSH_MPLS: { const struct ovs_action_push_mpls *mpls = nl_attr_get(a); @@ -1133,6 +1138,7 @@ odp_execute_actions(void *dp, struct dp_packet_batch *batch, bool steal, case OVS_ACTION_ATTR_OUTPUT: case OVS_ACTION_ATTR_LB_OUTPUT: case OVS_ACTION_ATTR_POP_VLAN: + case OVS_ACTION_ATTR_PUSH_VLAN: case OVS_ACTION_ATTR_TUNNEL_PUSH: case OVS_ACTION_ATTR_TUNNEL_POP: case OVS_ACTION_ATTR_USERSPACE: