From patchwork Fri Jul 8 09:55:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianbo Liu X-Patchwork-Id: 1653999 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=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=bUNY6I1/; 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 (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LfTF267qKz9sFx for ; Fri, 8 Jul 2022 19:56:06 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id A7C13415D9; Fri, 8 Jul 2022 09:56:03 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org A7C13415D9 Authentication-Results: smtp2.osuosl.org; dkim=fail reason="signature verification failed" (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=bUNY6I1/ 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 mlHFeB_uh16w; Fri, 8 Jul 2022 09:56:01 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp2.osuosl.org (Postfix) with ESMTPS id 35F03415DF; Fri, 8 Jul 2022 09:56:00 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 35F03415DF Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id ED913C0035; Fri, 8 Jul 2022 09:55:59 +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 18D3CC0081 for ; Fri, 8 Jul 2022 09:55:58 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 3F794415BD for ; Fri, 8 Jul 2022 09:55:56 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 3F794415BD 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 HBhkJnHVH0Ii for ; Fri, 8 Jul 2022 09:55:55 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 1E3F1415BB Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2087.outbound.protection.outlook.com [40.107.237.87]) by smtp2.osuosl.org (Postfix) with ESMTPS id 1E3F1415BB for ; Fri, 8 Jul 2022 09:55:55 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aiCP59jA5cbVHzZwKx4ELvHuTCOmtc8C+KkbpJYZ5safIB1l27752VVuis9qnD4o+VQ2BP4Wrnh6iMviCtJAAjt/VlMvb/aMt9ebfDPu8xtrfTW/WSMAtVVu4GxBO/4CtEkjoyc2Y7HswBVhnTbSKo+E2KWpWVVwk3tHShboS7XMONSOgZAhizs8PWy4WIthMlBDiK0SspJgldoNAS3JdInjJF15/S3N8War9KjYiypWANVehCJoXZR59ZU/YfNaeqQWK5J2SxTwnontUAhwI34r78q9/wj0+KuVBsuripeEmugxPVmyDyCzxW+Ooyzwf5elFCJPuAPtvhO16Hlw+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=+U2Dj+GnjOfwFv2hBxsz5gXQ5RkNvKyshsZ0lJX+Hfw=; b=KoTOTrjBVesCEFy3jzXEwSRquKmS8kVnnAgkz542O+rRSk1WUDqrmMdrLxKBr3qt/F5bKXl+1umU1dE7gmnFp5vSwTuVUJjiuFUJ0JUWqKWPahBk2ujOOTyyCLeSFC5gyeYJlD4K65uRmqgLYi00flaCv+3c38iG/cGQCMOJUAknn3NJft2e7PIIRWFC2lG/PqUhZC0xDDkkbXiIiNMhmQ4h2mUyoqeBc7mfpEQYoZj4/WGZh/4YcBsnWceXYS4hwEfnq66f90rBinHsEdCK4NykdhgPMHMR8ABpgzDzLiFHM4DcbRLmSHN7MAsNndQ6vrnxUj4o73/UEvLMyl70WQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.235) smtp.rcpttodomain=corigine.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+U2Dj+GnjOfwFv2hBxsz5gXQ5RkNvKyshsZ0lJX+Hfw=; b=bUNY6I1/0jYUxXS6LYw341TT1GNZMdVJsidYh/U14O1t5o6VqVnIYF4NADe22nPLDSJHaegmrDczLm8OXvX5Y2rIiKTIIWQzUraHhAl1QTRqxzehqhNF5tLGW6GihI2hJGxJyax/2xzbkhkjIrZ85WYhFl80233s2AlNjMVWLqQ6VJEa6RXTpUJg9GTMUr3LgTZ0dyElYKufMAjoY/eIXbBaOo8/6WlZPqo7H4cep5KgjIYPchVEb7HflHHFrQ4VqYcLIzJLsIVoXTxjbtTcrmIWE8k0J4hz9TTMeqcJjjTMvvFBh2T2qKWoPcVN0yYmYYPVss/2jfWIn/5dPgOqEA== Received: from MW4PR03CA0333.namprd03.prod.outlook.com (2603:10b6:303:dc::8) by DM6PR12MB3242.namprd12.prod.outlook.com (2603:10b6:5:189::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.17; Fri, 8 Jul 2022 09:55:52 +0000 Received: from CO1NAM11FT067.eop-nam11.prod.protection.outlook.com (2603:10b6:303:dc:cafe::7e) by MW4PR03CA0333.outlook.office365.com (2603:10b6:303:dc::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5417.16 via Frontend Transport; Fri, 8 Jul 2022 09:55:52 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.235) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.235 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.235; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.235) by CO1NAM11FT067.mail.protection.outlook.com (10.13.174.212) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5417.15 via Frontend Transport; Fri, 8 Jul 2022 09:55:45 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Fri, 8 Jul 2022 09:55:40 +0000 Received: from drhqmail202.nvidia.com (10.126.190.181) by drhqmail203.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Fri, 8 Jul 2022 02:55:40 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.126.190.181) with Microsoft SMTP Server id 15.2.986.26 via Frontend Transport; Fri, 8 Jul 2022 02:55:38 -0700 To: , , , , , Date: Fri, 8 Jul 2022 09:55:25 +0000 Message-ID: <20220708095533.32489-2-jianbol@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220708095533.32489-1-jianbol@nvidia.com> References: <20220708095533.32489-1-jianbol@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9e64dd81-0719-47f2-2c2b-08da60c8070f X-MS-TrafficTypeDiagnostic: DM6PR12MB3242:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KejIC+LbPc1YWSj+pXrjzCx50OAk4qUSaZ0JOaxvOjs0tXzQcE+5DAx6Ui0Xvd6TrnSdj5ueL4FDcAPepTtFtKLBcbYFoDtyycEGSWGYDjMCdzDAxDQmaO1OCxy4GJ9/3DSDWcDZlxFMXPjzNMbGR96lpbUfV26dJU1Ofrau5tXSg+RxrUWNhS/MBFIzB6FLNNkuKLp560zQ88eVsUIao+j9EzFg91jyxMUDOa95dykis/simwDXsI+VEzGe4+vy+nbelCPKlEziYv4JY9oGp6COGvmnCKhBS62qVleChN4hLgLcKb1/Ws/LeBFoOXuK/EBa1u3DXHMDttQewRveJDs4HgN/7BgpRsCxdKcnHReihBvVYNjq8Re8w1bCqbYZBg/AgJKFdyiT+UqoYlYnSwmCjeCaZcSmZndyAuAsnPlpcFvt/Ggb6ZfsDzAXSmVvpgHBehXDLNyDzfQKuPiFNGwJlweCieGb8nulLHeuT8mZEWnAzwj99th3Jyz6+8arGmjxZps/zXKNBjF07Vhp1K5YH66Dp/NtvV9fKlZ0KHC0bBjXAtp6JyENzyRvUAwqxGdR7FeK2RzjhW2Ivfwr4iE65pae8+J5SLk0QGQrp/002Qfq+AsLzDwnheM4TqCh5qz6/k+b0962DkWvwOoCcorIIbFyXwWW+Aic6nn79/0JtNv+bqpWb+VSVCpdEU72IT5nbJ5cRQC+/uwIayhC3EsM5d1g+nhFlgA54Y4U96rmQbQhI2RfjwYwM4+zbHbtZ3FGb/9x88FRPsKNtlKL9w7yFXoVp7UR3q52z541HufO+l2EsKyJLvfk+IOL082Javp5L2uJ6c9jWsgPKG59WBZjFx2DHbqtWFRfYSgx4Ro= X-Forefront-Antispam-Report: CIP:12.22.5.235; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230016)(4636009)(376002)(39860400002)(346002)(396003)(136003)(36840700001)(46966006)(40470700004)(6666004)(110136005)(40460700003)(36860700001)(41300700001)(356005)(478600001)(316002)(5660300002)(40480700001)(82740400003)(26005)(86362001)(8936002)(4326008)(47076005)(107886003)(8676002)(81166007)(426003)(186003)(2616005)(83380400001)(70206006)(70586007)(82310400005)(7696005)(36756003)(2906002)(1076003)(336012)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jul 2022 09:55:45.3413 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9e64dd81-0719-47f2-2c2b-08da60c8070f X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.235]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT067.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3242 Cc: Jianbo Liu Subject: [ovs-dev] [v8 1/9] netdev-offload: Add meter offload API 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: , X-Patchwork-Original-From: Jianbo Liu via dev From: Jianbo Liu Reply-To: Jianbo Liu Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Add API to offload meter to HW, and the corresponding functions to call the meter callbacks from all the registered flow API providers. The interfaces are like those related to meter in dpif_class, in order to pass necessary info to HW. Signed-off-by: Jianbo Liu Acked-by: Eelco Chaudron --- lib/netdev-offload-provider.h | 27 ++++++++++++++++ lib/netdev-offload.c | 59 +++++++++++++++++++++++++++++++++++ lib/netdev-offload.h | 5 +++ 3 files changed, 91 insertions(+) diff --git a/lib/netdev-offload-provider.h b/lib/netdev-offload-provider.h index 8ff2de983..9108856d1 100644 --- a/lib/netdev-offload-provider.h +++ b/lib/netdev-offload-provider.h @@ -94,6 +94,33 @@ struct netdev_flow_api { * takes ownership of a packet if errno != EOPNOTSUPP. */ int (*hw_miss_packet_recover)(struct netdev *, struct dp_packet *); + /* Offloads or modifies the offloaded meter in HW with the given 'meter_id' + * and the configuration in 'config'. On failure, a non-zero error code is + * returned. + * + * The meter id specified through 'config->meter_id' is ignored. */ + int (*meter_set)(ofproto_meter_id meter_id, + struct ofputil_meter_config *config); + + /* Queries HW for meter stats with the given 'meter_id'. Store the stats + * of dropped packets to band 0. On failure, a non-zero error code is + * returned. + * + * Note that the 'stats' structure is already initialized, and only the + * available statistics should be incremented, not replaced. Those fields + * are packet_in_count, byte_in_count and band[]->byte_count and + * band[]->packet_count. */ + int (*meter_get)(ofproto_meter_id meter_id, + struct ofputil_meter_stats *stats); + + /* Removes meter 'meter_id' from HW. Store the stats of dropped packets to + * band 0. On failure, a non-zero error code is returned. + * + * 'stats' may be passed in as NULL if no stats are needed, See the above + * function for additional details on the 'stats' usage. */ + int (*meter_del)(ofproto_meter_id meter_id, + struct ofputil_meter_stats *stats); + /* Initializies the netdev flow api. * Return 0 if successful, otherwise returns a positive errno value. */ int (*init_flow_api)(struct netdev *); diff --git a/lib/netdev-offload.c b/lib/netdev-offload.c index fb108c0d5..9fde5f7a9 100644 --- a/lib/netdev-offload.c +++ b/lib/netdev-offload.c @@ -58,6 +58,7 @@ VLOG_DEFINE_THIS_MODULE(netdev_offload); +static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5); static bool netdev_flow_api_enabled = false; #define DEFAULT_OFFLOAD_THREAD_NB 1 @@ -195,6 +196,64 @@ netdev_assign_flow_api(struct netdev *netdev) return -1; } +void +meter_offload_set(ofproto_meter_id meter_id, + struct ofputil_meter_config *config) +{ + struct netdev_registered_flow_api *rfa; + + CMAP_FOR_EACH (rfa, cmap_node, &netdev_flow_apis) { + if (rfa->flow_api->meter_set) { + int ret = rfa->flow_api->meter_set(meter_id, config); + if (ret) { + VLOG_DBG_RL(&rl, "Failed setting meter %u for flow api %s, " + "error %d", meter_id.uint32, rfa->flow_api->type, + ret); + } + } + } + /* Offload APIs could fail, for example, because the offload is not + * supported. This is fine, as the offload API should take care of this. */ +} + +int +meter_offload_get(ofproto_meter_id meter_id, struct ofputil_meter_stats *stats) +{ + struct netdev_registered_flow_api *rfa; + + CMAP_FOR_EACH (rfa, cmap_node, &netdev_flow_apis) { + if (rfa->flow_api->meter_get) { + int ret = rfa->flow_api->meter_get(meter_id, stats); + if (ret) { + VLOG_DBG_RL(&rl, "Failed getting meter %u for flow api %s, " + "error %d", meter_id.uint32, rfa->flow_api->type, + ret); + } + } + } + + return 0; +} + +int +meter_offload_del(ofproto_meter_id meter_id, struct ofputil_meter_stats *stats) +{ + struct netdev_registered_flow_api *rfa; + + CMAP_FOR_EACH (rfa, cmap_node, &netdev_flow_apis) { + if (rfa->flow_api->meter_del) { + int ret = rfa->flow_api->meter_del(meter_id, stats); + if (ret) { + VLOG_DBG_RL(&rl, "Failed deleting meter %u for flow api %s, " + "error %d", meter_id.uint32, rfa->flow_api->type, + ret); + } + } + } + + return 0; +} + int netdev_flow_flush(struct netdev *netdev) { diff --git a/lib/netdev-offload.h b/lib/netdev-offload.h index 8237a85dd..249a3102a 100644 --- a/lib/netdev-offload.h +++ b/lib/netdev-offload.h @@ -22,6 +22,7 @@ #include "openvswitch/types.h" #include "ovs-rcu.h" #include "ovs-thread.h" +#include "openvswitch/ofp-meter.h" #include "packets.h" #include "flow.h" @@ -158,6 +159,10 @@ int netdev_ports_flow_get(const char *dpif_type, struct match *match, int netdev_ports_get_n_flows(const char *dpif_type, odp_port_t port_no, uint64_t *n_flows); +void meter_offload_set(ofproto_meter_id, struct ofputil_meter_config *); +int meter_offload_get(ofproto_meter_id, struct ofputil_meter_stats *); +int meter_offload_del(ofproto_meter_id, struct ofputil_meter_stats *); + #ifdef __cplusplus } #endif