From patchwork Sat Jul 2 03:18:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianbo Liu X-Patchwork-Id: 1651419 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=S+yaN3ne; 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 4LZcjX6Z8vz9sGG for ; Sat, 2 Jul 2022 13:18:56 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id E879D415D7; Sat, 2 Jul 2022 03:18:51 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org E879D415D7 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=S+yaN3ne 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 h9VWfYabBbre; Sat, 2 Jul 2022 03:18:50 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp2.osuosl.org (Postfix) with ESMTPS id BB7AC4026F; Sat, 2 Jul 2022 03:18:49 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org BB7AC4026F Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id A28FFC007B; Sat, 2 Jul 2022 03:18:47 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id B68FEC002D for ; Sat, 2 Jul 2022 03:18:45 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 82BBB60B5B for ; Sat, 2 Jul 2022 03:18:45 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 82BBB60B5B Authentication-Results: smtp3.osuosl.org; dkim=pass (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=S+yaN3ne 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 spyGGpaw9k3F for ; Sat, 2 Jul 2022 03:18:44 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 88ED660A97 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2046.outbound.protection.outlook.com [40.107.220.46]) by smtp3.osuosl.org (Postfix) with ESMTPS id 88ED660A97 for ; Sat, 2 Jul 2022 03:18:44 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bAEem/iWzZOkd02nCS1DJ81B1sJ76tVu+560ybAGgFj2brouIXCfH0yIYnAb01pTEPku2kcsSIVB7tZgwFi4Lmx8p4YstoRSPHYyZMoqWZNVn+GTKA2CV5DQp1ky33YlJejasZhJKoVXY46cPGCx+s0+mZuJcM0KXYZkqZVbGDvoJGcDIpsP7NW0QifjFKWlnK3c+Qrs4oGyn/V4SLBklmDz55W2FaynItJ4u/EPEpXSsYf5iBAD5sJM0JPpt4xnRwTMvIsmLvytCR+KvhTexoP790JAlRrMAMmfnp1bZn59s462LX8VKra0gTHqn/k25ggC0t5LtgjCewa9RFHupA== 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=qXNfaqE5sehmbXZegggHCcWnql/tbR4ZbGgBNmVGarE=; b=lAN6tZ1nJXOh3peHfbdwByjVHOYt3dFS8ik9PkwHbo5/oDSnSaXXZxebMnSzURLPS5NMNfQgygUUUkht91pBv1gpApLX0l/1WSEYfZ/4Ryc0KQLoQqPTcfGtdvJes/aeXvIrI3XpIAWh9qLYw1eZpkzH8wV40rOFXv54WKAkymlMId0F9QQ2Q8cybAiTwaQgsVtUVordKg17F3AHyQWXNd31GQGSDuN2OgJsLS6NSB3QEfoRfedJFtkuvc7GXWwo4h0O3nSN5zpPmozYduGvH7MeJVaFydbL2BlWTsqa0N0hENCSYuKDqGaes+h45cqYNuxJB9WMslqqJF7VDPpMuw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.236) 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=qXNfaqE5sehmbXZegggHCcWnql/tbR4ZbGgBNmVGarE=; b=S+yaN3nei3YLWzKCjNfi1gerOQkgWIkGq7BEL3QujXV6be9pj6djyfT9H42JJGPzwCCF9XdTIk38gW0PEuvQHfO+P767+0EB50CQKwLQmwzhAhJrjMoVctI06CMXlTIAB5Azv6voLrDR18NgNMGyg0aKOLHRthWabSgzkDGQM5Tf0lYv4m7kVgBkuEWXITnw5DHlKga89M1sH2TyyB6QAoeNX5FyD2xWcQfDPFcNlar8QESgbS/upyQl0N7nB1bPrserjbFijyRyjAjTOP5IPr9rYwvM+/+e4YsILDGucUI6Ju08mDbNHJIEfoEmk3LT7xZN0mfoZLNS+B3FKYV3NA== Received: from DM6PR02CA0118.namprd02.prod.outlook.com (2603:10b6:5:1b4::20) by BN7PR12MB2657.namprd12.prod.outlook.com (2603:10b6:408:32::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.15; Sat, 2 Jul 2022 03:18:41 +0000 Received: from DM6NAM11FT035.eop-nam11.prod.protection.outlook.com (2603:10b6:5:1b4:cafe::6) by DM6PR02CA0118.outlook.office365.com (2603:10b6:5:1b4::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.18 via Frontend Transport; Sat, 2 Jul 2022 03:18:41 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.236) 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.236 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.236; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.236) by DM6NAM11FT035.mail.protection.outlook.com (10.13.172.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5395.14 via Frontend Transport; Sat, 2 Jul 2022 03:18:41 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by DRHQMAIL109.nvidia.com (10.27.9.19) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Sat, 2 Jul 2022 03:18:40 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Fri, 1 Jul 2022 20:18:39 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.986.26 via Frontend Transport; Fri, 1 Jul 2022 20:18:37 -0700 To: , , , , , Date: Sat, 2 Jul 2022 03:18:24 +0000 Message-ID: <20220702031832.13282-2-jianbol@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220702031832.13282-1-jianbol@nvidia.com> References: <20220702031832.13282-1-jianbol@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2e307366-3e7c-4d08-4f35-08da5bd9904c X-MS-TrafficTypeDiagnostic: BN7PR12MB2657:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VGgEo6DGPSbIPcUa/Ikeew53LWk5AZRmxzxYQiTeQ9vwiesYJBIbw+65iSet7PfmNHUV52D4oourzdF/eGMAppj9MWJ663oaW8chCVVDqnZR/hWmeHFWpbwPyW7wEeLDY+uvg4GPCVQK6pdgzFFtvpNGLFVDd45lxyYrIv4QFX/4b7+O4f7iyh33vHWlvrIcy4fXdsjX0CB22emXYxTxXyHmAVNC21B8koPCyWb9fvOo1ebLeEx+UVwKnLE/jUrHQnNZ5tx3k3wGoD67dLmiBjbUV6UHy7e3032M56RcJy92uZaGk9uO0MATd4QoZPChlZJucgJZlk2saoC1JX+oyFNswzpyNHYKaBAbUWYHt/4akzVbM7z9roJqe/lDTYRl7XGn2SxqdfKGLR9eSkpxS05BqabjyvZo11s1qZfaVAtYvi/0wjeNNhtnM3R8CdvyHGXQ0D6UTbVBGyoPHankHIHB6dPYiD44bnCouUOnLX3mjT/SYXMQMD/LEeh3N5TI/LSh/8/5HqopnzWwkAPlfBMe7jbc1a/4zYE5LTbIjibZEe30qCual7iZPQXKSdhcpi2e8BOUPCWNvvxcpHZlwE6ExLnkAJFV6VopGygIIKByC2Uk+HF4YRh0twvpkZg2EvNVpiTzW+9VfScN+q4unz+rCOc9/ZHYPymCROHo1VVtvZ7fT8NjrTYx3/sWEjXPAK946J14Ykk+hqfOMnR3G2cGJdzPeWjRXNmVM0ZiOZlWlnEVk9DTYc1FOXWK+qlVJUgAni3hg4UrNig7Jf68e0sn9AJK/NkCX8PeZ/DXszf0UpQJM6PgUO1R7aqzYLn/+PiI5l9h365rjONTtZJYHT4r4sAeGKmuWGV17DI1tlY= X-Forefront-Antispam-Report: CIP:12.22.5.236; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230016)(4636009)(39860400002)(346002)(376002)(136003)(396003)(40470700004)(36840700001)(46966006)(70586007)(36860700001)(70206006)(8936002)(36756003)(478600001)(40480700001)(4326008)(82310400005)(8676002)(110136005)(83380400001)(316002)(5660300002)(81166007)(186003)(2616005)(26005)(107886003)(336012)(426003)(7696005)(1076003)(47076005)(6666004)(2906002)(356005)(82740400003)(40460700003)(41300700001)(86362001)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jul 2022 03:18:41.2203 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2e307366-3e7c-4d08-4f35-08da5bd9904c 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.236]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT035.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PR12MB2657 Cc: Jianbo Liu Subject: [ovs-dev] [v6 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