From patchwork Thu Sep 2 10:18:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roi Dayan X-Patchwork-Id: 1523589 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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=CqWHmJ5s; 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 (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4H0cMv6c9Mz9sCD for ; Thu, 2 Sep 2021 20:18:51 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id D6D1940712; Thu, 2 Sep 2021 10:18:48 +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 TzzxoqsZTFzP; Thu, 2 Sep 2021 10:18:45 +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 CB7E4406EA; Thu, 2 Sep 2021 10:18:42 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 9C6DFC001B; Thu, 2 Sep 2021 10:18:42 +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 522DEC001A for ; Thu, 2 Sep 2021 10:18:41 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 33C09406D8 for ; Thu, 2 Sep 2021 10:18:41 +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 Q0QH8mkFaPNJ for ; Thu, 2 Sep 2021 10:18:37 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2080.outbound.protection.outlook.com [40.107.237.80]) by smtp2.osuosl.org (Postfix) with ESMTPS id 0FB6C406D0 for ; Thu, 2 Sep 2021 10:18:36 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YbRA3/Us08ujCkrRTiN56/yfj3FF6yVD2hOXvpBnVkLEqtXQk8qw0s5oaDeF56rxvJK0SBhpJFU7Jbyv50WDgO45fduQTPBM3D9+m4Q3w5l4n8IXp+9vphoXRTkzm2ftjwuHWYfrOnUmv1G0V0YWw/tK48QcqkB4R1aS6HhEvK5nIQhuisuDyNAmlDbUfkB0jClXKmuTn0JK7U/1wZ4PGd8qO0A5/wPaX4jCbzEhsVHr+OxU7NT00apCEWb63rm9g/rvF0HWOgKWPj2auM+rRCrihJq8p+BENqf9y/ornHIu7iY3f8Zmq98mJH9xae98BcuLBgMO273gZDguQa5GaQ== 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; bh=3lwRT7NpqwxqlJ1CzLHP18aP8OoXbzUEfGPp12vKXRg=; b=ZDbPG8R8VOIzISyDkbpmmeW9kU/yAXYlro++HHMSxMySYyg9kFCl4XRwTHIuQ4KsHsmmzURU/RoB9GFtupp9LZPRbKabI6FOIRG+VolcbrXzYICBgk0smrSiH+K6QKVM8rbKcVnr9LfPOdhm5vaW9TnbBQzMgNJ9Xdj1fVVM9b14svctPMY1od63/7sJ/I2r/WyUmdGkZv40M8Yu4Uj5z/Bbbca3TJM8t+ujHZwS/Vp7x3u1jKmG87+2lHRbFirZK4HK9OesNbWlYy/RqLOAnPk03c9p6v+5IaSpVyPxNCelGvxrIh5dc3XE7hAir9ONDrQyHukqUTTyJ5wCGy+WCA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.35) smtp.rcpttodomain=ovn.org smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=none 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=3lwRT7NpqwxqlJ1CzLHP18aP8OoXbzUEfGPp12vKXRg=; b=CqWHmJ5sBBvT0ZkN2yKI5EOXwLenmK7zOMCYCk5/xabRSfUMmOdN0fGxXVuP3sw/+pEFMCRd0uaQKJklxbBOfSNrytmtIZP7jhVAybOwfybxADG0WFv7BT2m8lMIMvDC332Few7jzGaDqQXLYkFe+2LckApEvSis9lPkjGg/PYN1O+O1pwNg2pKCjurNFjQtY61qbIwbqMldnb/PvnIXC3lnvZoPoqWhwiblliEEbHTclY5wx5jLu/vM6apvK85XK4u3rurdJvHHsUFxL+ePh0ARbPAyLtsY3m7bBJxEA+rL2OLIcW69usw4SE2HNQcY/XfVchjGlPYNi1M2C5O26A== Received: from MW4PR03CA0251.namprd03.prod.outlook.com (2603:10b6:303:b4::16) by CO6PR12MB5409.namprd12.prod.outlook.com (2603:10b6:5:357::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.19; Thu, 2 Sep 2021 10:18:34 +0000 Received: from CO1NAM11FT013.eop-nam11.prod.protection.outlook.com (2603:10b6:303:b4:cafe::c3) by MW4PR03CA0251.outlook.office365.com (2603:10b6:303:b4::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.17 via Frontend Transport; Thu, 2 Sep 2021 10:18:32 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.35) smtp.mailfrom=nvidia.com; ovn.org; dkim=none (message not signed) header.d=none;ovn.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.35 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.35; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.35) by CO1NAM11FT013.mail.protection.outlook.com (10.13.174.227) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4478.19 via Frontend Transport; Thu, 2 Sep 2021 10:18:31 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 2 Sep 2021 10:18:31 +0000 Received: from dev-r-vrt-138.mtr.labs.mlnx (172.20.187.5) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 2 Sep 2021 03:18:30 -0700 To: , Ilya Maximets Date: Thu, 2 Sep 2021 13:18:18 +0300 Message-ID: <20210902101823.3403153-2-roid@nvidia.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210902101823.3403153-1-roid@nvidia.com> References: <20210902101823.3403153-1-roid@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: def9c856-57c6-40fd-3c6a-08d96dfb03f4 X-MS-TrafficTypeDiagnostic: CO6PR12MB5409: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: J44c7cejAKVAQIZz80retrCPGNmjvF7k+NyQYmjUxkWrv2uGoZcMxYMbFKTNocx25xXwpx5dQfKKd26OzeAMSkBrzC9veuOhdOqzDLBVhRH6g1FbLnqAin7AkomZ4KIiK5mVWtdQNcLJiEY1BJvOdesRVvLPMFFgmd6mF/Nype5BofEKa5PJoBIGQxtJ9p4kbUwUMqV60UOFQUq8Z9IrdPDmHsrBixdPzO0P6Xufre9V4YC98dpEBf1NcoTLm48hjtGTxJyJcYXsL4HHP56ZpNlNbq+wjDzfoJ7uOTTx2edtyyB08BJtSax3qgU0eVzGYDej/C9CGTVt2MGZlDpTHxacoN0dgp62qXf6ATJbH+biWYKnXAXkCdy3P5VlBCn98lsGtul9r3WCnlajcgBSF1dXLPxFV91Ir29SIDRLTjpzmZ1q+6cEJOShS0canM0gJztNWnCD/f7Xhpl/nlixpWfaAVC5gX8cJ3UmE3DtK1CRsygh1Mk1Z074upPM7V2pXUu47dwcN6vZIfbJNmpsEzhDbiy4opzTcS6ei1tzrvkQ9wNAmUfkMiQ5C1rCDU4cVJ16D5/Ohd8vt2IJSmmdOehdHMPPUnMDhBIEJhsgIQVK24nOqU1caMcFHQcbnttYuHhhXZ5HReHJwcJ4zOIO/IQRLHstir524/G7oiwzZHYWxWxZwEiEY7xijvgaSuMN9ErxmRlFNXc9D1Gfdt1HIA== X-Forefront-Antispam-Report: CIP:216.228.112.35; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid04.nvidia.com; CAT:NONE; SFS:(4636009)(136003)(39860400002)(396003)(376002)(346002)(36840700001)(46966006)(4326008)(1076003)(47076005)(107886003)(36906005)(5660300002)(54906003)(478600001)(356005)(26005)(110136005)(6666004)(316002)(7636003)(82740400003)(15650500001)(83380400001)(70586007)(70206006)(36756003)(86362001)(2906002)(82310400003)(36860700001)(8936002)(336012)(2616005)(186003)(8676002)(426003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2021 10:18:31.9083 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: def9c856-57c6-40fd-3c6a-08d96dfb03f4 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.35]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT013.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR12MB5409 Cc: Jianbo Liu Subject: [ovs-dev] [PATCH 1/6] 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: Roi Dayan via dev From: Roi Dayan Reply-To: Roi Dayan Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Jianbo Liu 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 Reviewed-by: Roi Dayan --- lib/netdev-linux.c | 82 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 42 insertions(+), 40 deletions(-) diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index 60dd138914a2..ca730a15fede 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -2629,37 +2629,27 @@ 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, + uint32_t pkts_rate, uint32_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; + + 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) { + unsigned int 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); + pkt_burst_ticks = tc_bytes_to_ticks(pkts_rate, pkts_burst); + nl_msg_put_u64(request, TCA_POLICE_PKTRATE64, (uint64_t) pkts_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); } + 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 +2682,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); @@ -5589,6 +5580,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, uint32_t kbits_rate, + uint32_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, ((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); +} + /* 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'. @@ -5613,22 +5627,8 @@ 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); + tc_policer_init(&tc_police, kbits_rate, kbits_burst); tcmsg = netdev_linux_tc_make_request(netdev, RTM_NEWTFILTER, NLM_F_EXCL | NLM_F_CREATE, &request); if (!tcmsg) { @@ -5638,9 +5638,11 @@ 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); + nl_msg_put_act_police(&request, &tc_police, kpkts_rate * 1000, + kpkts_burst * 1000); nl_msg_end_nested(&request, police_offset); nl_msg_end_nested(&request, basic_offset);