From patchwork Mon Feb 24 16:03:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Van Haaren, Harry" X-Patchwork-Id: 1243299 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.138; helo=whitealder.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=intel.com Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48R6LT1nxXz9sP7 for ; Tue, 25 Feb 2020 03:03:45 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 29C4F85BC9; Mon, 24 Feb 2020 16:03:43 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id KpxqoaS-JO94; Mon, 24 Feb 2020 16:03:42 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id 0091B855BD; Mon, 24 Feb 2020 16:03:41 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id E2B4FC07FF; Mon, 24 Feb 2020 16:03:41 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id A5C7EC0177 for ; Mon, 24 Feb 2020 16:03:40 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 879EE85207 for ; Mon, 24 Feb 2020 16:03:40 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id sYJIsWVtq8UF for ; Mon, 24 Feb 2020 16:03:37 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by hemlock.osuosl.org (Postfix) with ESMTPS id 1FF20847C8 for ; Mon, 24 Feb 2020 16:03:37 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Feb 2020 08:03:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,480,1574150400"; d="scan'208";a="270940812" Received: from silpixa00399779.ir.intel.com (HELO silpixa00399779.ger.corp.intel.com) ([10.237.222.209]) by fmsmga002.fm.intel.com with ESMTP; 24 Feb 2020 08:03:34 -0800 From: Harry van Haaren To: dev@openvswitch.org Date: Mon, 24 Feb 2020 16:03:30 +0000 Message-Id: <20200224160330.3682-1-harry.van.haaren@intel.com> X-Mailer: git-send-email 2.17.1 Cc: i.maximets@ovn.org Subject: [ovs-dev] [PATCH] dpcls: enable cpu feature detection 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: , MIME-Version: 1.0 Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" This commit implements a method to retrieve the CPU ISA capabilities, and allows each DPCLS implementation to use these ISA capabilities to decide if the specific implemenation is a valid candidate for the CPU. Please note this is a POC patch only, the actual generic code here can always run. Future DPCLS implementations may require specific ISA, which is what this patch enables. Signed-off-by: Harry van Haaren --- lib/dpdk-stub.c | 11 +++++++++++ lib/dpdk.c | 16 ++++++++++++++++ lib/dpdk.h | 7 +++++++ lib/dpif-netdev-lookup-generic.c | 7 +++++++ 4 files changed, 41 insertions(+) diff --git a/lib/dpdk-stub.c b/lib/dpdk-stub.c index c332c217c..0aaccd983 100644 --- a/lib/dpdk-stub.c +++ b/lib/dpdk-stub.c @@ -79,6 +79,17 @@ print_dpdk_version(void) { } +int +dpdk_get_cpu_has_isa(const char *arch, const char *feature) +{ + static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER; + if (ovsthread_once_start(&once)) { + VLOG_ERR("DPDK not supported in this copy of Open vSwitch, cannot use CPU flag based optimizations"); + ovsthread_once_done(&once); + } + return 0; +} + void dpdk_status(const struct ovsrec_open_vswitch *cfg) { diff --git a/lib/dpdk.c b/lib/dpdk.c index 37ea2973c..927dc6867 100644 --- a/lib/dpdk.c +++ b/lib/dpdk.c @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -525,6 +526,21 @@ print_dpdk_version(void) puts(rte_version()); } +int +dpdk_get_cpu_has_isa(const char *arch, const char *feature) +{ + /* Ensure Arch is x86_64 */ + if (strncmp(arch, "x86_64", 6)) + return 0; + + if (strncmp(feature, "avx512f", 7) == 0) + return rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512F) > 0; + + VLOG_WARN("%s does not know the %s, %s combo, returning not supported.\n", + __func__, arch, feature); + return 0; +} + void dpdk_status(const struct ovsrec_open_vswitch *cfg) { diff --git a/lib/dpdk.h b/lib/dpdk.h index 736a64279..6c2144624 100644 --- a/lib/dpdk.h +++ b/lib/dpdk.h @@ -44,4 +44,11 @@ bool dpdk_per_port_memory(void); bool dpdk_available(void); void print_dpdk_version(void); void dpdk_status(const struct ovsrec_open_vswitch *); + +/* Returns 1 if the CPU has support for the requested architecture specific + * ISA capability. Eg: "x86_64", "avx512f". The strings to use here are as + * shown in "lscpu" Architecture: and Flags: fields. + */ +int dpdk_get_cpu_has_isa(const char * arch, const char *feature); + #endif /* dpdk.h */ diff --git a/lib/dpif-netdev-lookup-generic.c b/lib/dpif-netdev-lookup-generic.c index 89c8be0fa..dbc830512 100644 --- a/lib/dpif-netdev-lookup-generic.c +++ b/lib/dpif-netdev-lookup-generic.c @@ -301,6 +301,13 @@ DECLARE_OPTIMIZED_LOOKUP_FUNCTION(4, 0) dpcls_subtable_lookup_func dpcls_subtable_generic_probe(uint32_t u0_bits, uint32_t u1_bits) { + /* POC only: check if we can use CPU based info */ + int avx512f_available = dpdk_get_cpu_has_isa("x86_64", "avx512f"); + printf("avx512f available? %d\n", avx512f_available); + + if (!avx512f_available) + return 0; + dpcls_subtable_lookup_func f = NULL; CHECK_LOOKUP_FUNCTION(5, 1);