From patchwork Sat Jul 2 03:18:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianbo Liu X-Patchwork-Id: 1651420 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=gI1GQfkp; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.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 4LZcjd0T9Sz9ryY for ; Sat, 2 Jul 2022 13:19:00 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id DF0864161B; Sat, 2 Jul 2022 03:18:57 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org DF0864161B 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=gI1GQfkp 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 Fvqi2_Y5EGGJ; Sat, 2 Jul 2022 03:18:55 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp2.osuosl.org (Postfix) with ESMTPS id A193D415EF; Sat, 2 Jul 2022 03:18:53 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org A193D415EF Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 5B63BC0086; Sat, 2 Jul 2022 03:18:52 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id C41E9C002D for ; Sat, 2 Jul 2022 03:18:50 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 90B3E403C8 for ; Sat, 2 Jul 2022 03:18:50 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 90B3E403C8 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 lcp5DlI0KFsj for ; Sat, 2 Jul 2022 03:18:49 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 913854018B Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2066.outbound.protection.outlook.com [40.107.244.66]) by smtp2.osuosl.org (Postfix) with ESMTPS id 913854018B for ; Sat, 2 Jul 2022 03:18:49 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gY66oGAEqz+73h6y7FzXkXLSKbqFFsrSr52lj38C4kWQMRMCz5VdCFd6fOXaqcuWjmxgNF8ZPbFTaiWu3R1b+m5xJgQnKq4S1qkA6mOoBH0cjg1SaqIald/8csof0xMRm4O75M9RhUdaURLim8zrwn45hsKNZbus9KS5+EWL1LrYsRdzMyl3FO9TBKD2HYu7qtMXDsV91MClgrU1Kr1oOhWLu6d42ZMB1RHgvmR2aixRJVXf64uaBkX+421HI+eIZ2JS9nsQ2vHDEc/srgCA9LaTlFv40u4CVKxtBTG/y5J7dD4QQXtlcMKpz1xs48J0LOo2tflQVQKfOeQviT6u6w== 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=Hu+NkxxK6zD/18BhwUcTfaN8olaFMz/2vVNFCA/zX9Q=; b=DZjZi8twEmazFsL6lHJ+2l0tlFOxiFJPXrnF8Lz1rJFr/pyPEouh419PXPQTTlPUi5GMgTah3eIvzOSCM9xSGKuI8utoSBrxXnKWcOJxrBAHVhY6qkM9GPGo197/TUgNX7qkx7fy/rEUUrlg24q7CMTcSjk6CiEUKBHq4yZN/iyyDnrW16jfNIB1ca2ijX4J/eMjDiOU03bqxQNVTERMMVNyfjQKlR9Db/DGY0In+WdIuHQ5WYWWA9HVUSl7rFed/gtugmkBDJuItcbSDrp1hQzK2GLfJkGYs7pduvtc9RXgEbrs/A/lIZqMQWfUyjZzu4U7RbbgnfAMYKN3r3Z+YA== 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=Hu+NkxxK6zD/18BhwUcTfaN8olaFMz/2vVNFCA/zX9Q=; b=gI1GQfkp66jzKI9dcFASSwn21fBWTAw2B0i875pWKBvY+p0YJ8QtJ82BkrWA6lieqKOWpXWDwt3JOqHGGP7yUZkaWkAN3eFaJ2henk+s8KWcYvr3rWDTreCt2zsT7hO19818KeZs95PYikznZTeAioMv/vsTtLyG9mRDwHb8o9fBpuLYSXNopO4sTjWnLIaFzD9DYgOm8YcbungcZK/WudG1wGAnDySFJnnoatD9RzhfBk6vQC/UH6K/3fXQMs7NWg/6XfqUAXQWntAXavhZmzocM4riPX7TjVl1kHolQnGYcF+97hewT7uTZhzEKGeBKfQjd81nPoReTbim5lZWbw== Received: from MW4PR03CA0166.namprd03.prod.outlook.com (2603:10b6:303:8d::21) by BL1PR12MB5362.namprd12.prod.outlook.com (2603:10b6:208:31d::18) 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:47 +0000 Received: from CO1NAM11FT016.eop-nam11.prod.protection.outlook.com (2603:10b6:303:8d:cafe::6b) by MW4PR03CA0166.outlook.office365.com (2603:10b6:303:8d::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.14 via Frontend Transport; Sat, 2 Jul 2022 03:18:46 +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 CO1NAM11FT016.mail.protection.outlook.com (10.13.175.141) 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:46 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Sat, 2 Jul 2022 03:18:45 +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:44 -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:42 -0700 To: , , , , , Date: Sat, 2 Jul 2022 03:18:26 +0000 Message-ID: <20220702031832.13282-4-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: 73aff9b0-80ae-4d70-9f45-08da5bd99344 X-MS-TrafficTypeDiagnostic: BL1PR12MB5362:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kQbxTojR5x5bP03w+g7nGvcEyCyH+DDMxOcgWxkORf6vjYXbi6ZLa0vbUKa72XydDh/UWWg//tGo3XIr5OpyIuoo/270mgZMMPIwGa/dUxUYTESoVdt6+gp8FwVMnV6gTGXMxyfdkNdydbtmWPJ/u4UkMAVUqfNnHyryDGeZFu6OJg/SBDulPgOuAwzkseY/dsEdT5FShAq1C1HNeh9+3jchXyzk+qLZrpbpp9K9OisPhAuE6GIYpujb8Wa7cshqdb2lqsCWCU8Qs21iaK2d42WZwKRTVXdJsQtgnEHmwgF6c1V5UAotLV6w/vAU6fKdPJ0B4ZbSKJiJ4LUSq2xAYGYkWiiF5Dp6rsqYCZ6ZdnNU39LgJKOpnxB9eg5n+1jJ7phYnu0whCQVZDKb4iWN0U5YDTeRJwm2wncwnCttiuWp+fVhToYGOqPRjAgGxAGeqjs3kGeysBVojbbcxn5ChuIVmdQjBif/+nKNQixTLshZoU9cYPjxe97oFQCuuAC4tNj0X3XrQaBwx4iqDvJSyJ94xxuPjHmdKGA96Pkebp59i7J8/1lPqgWLORtVCITnV0MAcXzKify0uSNTWxkXxI8idWQ6AFmCbXOTNBfofdBlE9XMWXHQJesV8ZX4dk3Z7SAyGwIYLe0O5tcpm0Q7Hvk6jeBLaQVWsNSJY4aMbpO0Tn7YPjDGPuDRMIleXkK0P6Pbk/Ag+R4eywGZCOfrgUuiCcBUMavL9N4r+itnOk7/LZBUVWD/qjsa3IwqgoHrCH9Ppr5Sa5XSuOZ8gA0eilz5KiA7u5FaLbEzv5q2HEQY5Nlvt9mZkiTkzo2Mo5hwVusbfql4wHYn3sNw4IahzDgh3mMLk5QY+PIx2IiQsFQ= 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)(396003)(346002)(39860400002)(136003)(46966006)(40470700004)(36840700001)(2906002)(41300700001)(36860700001)(15650500001)(4326008)(110136005)(8676002)(40480700001)(70586007)(86362001)(40460700003)(36756003)(316002)(70206006)(82310400005)(478600001)(356005)(1076003)(47076005)(81166007)(5660300002)(82740400003)(426003)(186003)(2616005)(107886003)(6666004)(8936002)(7696005)(26005)(83380400001)(336012)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jul 2022 03:18:46.2031 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 73aff9b0-80ae-4d70-9f45-08da5bd99344 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: CO1NAM11FT016.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5362 Cc: Jianbo Liu Subject: [ovs-dev] [v6 3/9] netdev-linux: Refactor put police action netlink message 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" To reuse the code for manipulating police action, move the common initialization code to a function, and change PPS parameters as meter pktps is in unit of packet per second. null_police is redundant because either BPS or PPS, not both, can be configured in one message. So the police passed in to nl_msg_put_act_police can be reused as its rate is zero for PPS, and it also provides the index for police action to be created. Signed-off-by: Jianbo Liu Acked-by: Eelco Chaudron --- lib/netdev-linux.c | 89 ++++++++++++++++++++++++---------------------- 1 file changed, 47 insertions(+), 42 deletions(-) diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index 2766b3f2b..039a99f49 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -2629,37 +2629,30 @@ nl_msg_act_police_end_nest(struct ofpbuf *request, size_t offset, } static void -nl_msg_put_act_police(struct ofpbuf *request, struct tc_police police, - uint32_t kpkts_rate, uint32_t kpkts_burst) +nl_msg_put_act_police(struct ofpbuf *request, struct tc_police *police, + uint64_t pkts_rate, uint64_t pkts_burst) { size_t offset, act_offset; uint32_t prio = 0; - /* used for PPS, set rate as 0 to act as a single action */ - struct tc_police null_police; - - memset(&null_police, 0, sizeof null_police); - - if (police.rate.rate) { - nl_msg_act_police_start_nest(request, ++prio, &offset, &act_offset); - tc_put_rtab(request, TCA_POLICE_RATE, &police.rate); - nl_msg_put_unspec(request, TCA_POLICE_TBF, &police, sizeof police); - nl_msg_act_police_end_nest(request, offset, act_offset); - } - if (kpkts_rate) { - unsigned int pkt_burst_ticks, pps_rate, size; - nl_msg_act_police_start_nest(request, ++prio, &offset, &act_offset); - pps_rate = kpkts_rate * 1000; - size = MIN(UINT32_MAX / 1000, kpkts_burst) * 1000; + + if (!police->rate.rate && !pkts_rate) { + return; + } + + nl_msg_act_police_start_nest(request, ++prio, &offset, &act_offset); + if (police->rate.rate) { + tc_put_rtab(request, TCA_POLICE_RATE, &police->rate); + } + if (pkts_rate) { + uint64_t pkt_burst_ticks; /* Here tc_bytes_to_ticks is used to convert packets rather than bytes to ticks. */ - pkt_burst_ticks = tc_bytes_to_ticks(pps_rate, size); - nl_msg_put_u64(request, TCA_POLICE_PKTRATE64, (uint64_t) pps_rate); - nl_msg_put_u64(request, TCA_POLICE_PKTBURST64, - (uint64_t) pkt_burst_ticks); - nl_msg_put_unspec(request, TCA_POLICE_TBF, &null_police, - sizeof null_police); - nl_msg_act_police_end_nest(request, offset, act_offset); + pkt_burst_ticks = tc_bytes_to_ticks(pkts_rate, pkts_burst); + nl_msg_put_u64(request, TCA_POLICE_PKTRATE64, pkts_rate); + nl_msg_put_u64(request, TCA_POLICE_PKTBURST64, pkt_burst_ticks); } + nl_msg_put_unspec(request, TCA_POLICE_TBF, police, sizeof *police); + nl_msg_act_police_end_nest(request, offset, act_offset); } static int @@ -2692,7 +2685,8 @@ tc_add_matchall_policer(struct netdev *netdev, uint32_t kbits_rate, nl_msg_put_string(&request, TCA_KIND, "matchall"); basic_offset = nl_msg_start_nested(&request, TCA_OPTIONS); action_offset = nl_msg_start_nested(&request, TCA_MATCHALL_ACT); - nl_msg_put_act_police(&request, pol_act, kpkts_rate, kpkts_burst); + nl_msg_put_act_police(&request, &pol_act, kpkts_rate * 1000, + kpkts_burst * 1000); nl_msg_end_nested(&request, action_offset); nl_msg_end_nested(&request, basic_offset); @@ -5599,6 +5593,29 @@ netdev_linux_tc_make_request(const struct netdev *netdev, int type, return tc_make_request(ifindex, type, flags, request); } +static void +tc_policer_init(struct tc_police *tc_police, uint64_t kbits_rate, + uint64_t kbits_burst) +{ + int mtu = 65535; + + memset(tc_police, 0, sizeof *tc_police); + + tc_police->action = TC_POLICE_SHOT; + tc_police->mtu = mtu; + tc_fill_rate(&tc_police->rate, kbits_rate * 1000 / 8, mtu); + + /* The following appears wrong in one way: In networking a kilobit is + * usually 1000 bits but this uses 1024 bits. + * + * However if you "fix" those problems then "tc filter show ..." shows + * "125000b", meaning 125,000 bits, when OVS configures it for 1000 kbit == + * 1,000,000 bits, whereas this actually ends up doing the right thing from + * tc's point of view. Whatever. */ + tc_police->burst = tc_bytes_to_ticks( + tc_police->rate.rate, kbits_burst * 1024 / 8); +} + /* Adds a policer to 'netdev' with a rate of 'kbits_rate' and a burst size * of 'kbits_burst', with a rate of 'kpkts_rate' and a burst size of * 'kpkts_burst'. @@ -5623,22 +5640,7 @@ tc_add_policer(struct netdev *netdev, uint32_t kbits_rate, struct ofpbuf request; struct tcmsg *tcmsg; int error; - int mtu = 65535; - memset(&tc_police, 0, sizeof tc_police); - tc_police.action = TC_POLICE_SHOT; - tc_police.mtu = mtu; - tc_fill_rate(&tc_police.rate, ((uint64_t) kbits_rate * 1000)/8, mtu); - - /* The following appears wrong in one way: In networking a kilobit is - * usually 1000 bits but this uses 1024 bits. - * - * However if you "fix" those problems then "tc filter show ..." shows - * "125000b", meaning 125,000 bits, when OVS configures it for 1000 kbit == - * 1,000,000 bits, whereas this actually ends up doing the right thing from - * tc's point of view. Whatever. */ - tc_police.burst = tc_bytes_to_ticks( - tc_police.rate.rate, MIN(UINT32_MAX / 1024, kbits_burst) * 1024 / 8); tcmsg = netdev_linux_tc_make_request(netdev, RTM_NEWTFILTER, NLM_F_EXCL | NLM_F_CREATE, &request); if (!tcmsg) { @@ -5648,9 +5650,12 @@ tc_add_policer(struct netdev *netdev, uint32_t kbits_rate, tcmsg->tcm_info = tc_make_handle(49, (OVS_FORCE uint16_t) htons(ETH_P_ALL)); nl_msg_put_string(&request, TCA_KIND, "basic"); + basic_offset = nl_msg_start_nested(&request, TCA_OPTIONS); police_offset = nl_msg_start_nested(&request, TCA_BASIC_ACT); - nl_msg_put_act_police(&request, tc_police, kpkts_rate, kpkts_burst); + tc_policer_init(&tc_police, kbits_rate, kbits_burst); + nl_msg_put_act_police(&request, &tc_police, kpkts_rate * 1000ULL, + kpkts_burst * 1000ULL); nl_msg_end_nested(&request, police_offset); nl_msg_end_nested(&request, basic_offset);