From patchwork Wed Mar 3 14:46:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tonghao Zhang X-Patchwork-Id: 1446839 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=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=VZuwT0fc; dkim-atps=neutral Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (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 4DrQFl1wgsz9sS8 for ; Thu, 4 Mar 2021 07:14:35 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id ACE7582D12; Wed, 3 Mar 2021 20:14:33 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9OHL-vHM6i0J; Wed, 3 Mar 2021 20:14:32 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp1.osuosl.org (Postfix) with ESMTP id C93CA82BFD; Wed, 3 Mar 2021 20:14:31 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 9ACA0C000B; Wed, 3 Mar 2021 20:14:31 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id B1DD0C0001 for ; Wed, 3 Mar 2021 20:14:29 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 870DA82A27 for ; Wed, 3 Mar 2021 20:14:29 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nFtbT62nz5HC for ; Wed, 3 Mar 2021 20:14:28 +0000 (UTC) X-Greylist: delayed 12:09:49 by SQLgrey-1.8.0 Received: from mail-vs1-xe35.google.com (mail-vs1-xe35.google.com [IPv6:2607:f8b0:4864:20::e35]) by smtp1.osuosl.org (Postfix) with ESMTPS id 9F2B582A0E for ; Wed, 3 Mar 2021 20:14:28 +0000 (UTC) Received: by mail-vs1-xe35.google.com with SMTP id b189so7364101vsd.0 for ; Wed, 03 Mar 2021 12:14:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dhXmN72LoHAwpZpM3H7CMUsvKATAR523VGrvgrg7vB8=; b=VZuwT0fcE6kccs3C6hcEfURfgu2X2MzycdPuicQHjbh4zVHAEV2y337fCSZLtnzUtm UewIl3X1sz2vieTqUbpGMYeXPCsase0s8sSvpRdoGgU9RtEHGSIXU6ctH1Uncb2c3OWM Zb4tarO5OCOR6B5K6VrlF7ZEiEPIHvXCmu/OybtRYo6jm3SoAQ0ziuuup78pac0zGzYL yyPSbHMu8/s7nknt6Hf7BEWjkWYfAEfSXn/ZAW1Yan5u0qnBlp8QXxGOn+0HIhBHWsdH oSH4mnc0Gcs0k1EJexJ+rKBT3Ds/aPeoNF/LJ23HXjssJu0pKf404W7+j0aLYBSeWZhf 88Zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=dhXmN72LoHAwpZpM3H7CMUsvKATAR523VGrvgrg7vB8=; b=D6N23k4cjKeiycHwu8Q9h6jqcpIXE+P1yShK76dUN6RWQtHoGUMeHhZH0WR40shHr2 xgLLQRj5VwmNAhGQJGG+n4H95dG5EaGN45zk4LtK8CCOKPV8ThbCWUTpgezRFNYjg09q vCS3dyZxp9rEBceujQrxjz1b4YuEh1ie5bjGoL+PBDMTcC9kQlguZDXpLs+sCshYKq9X ANx9LUeqok0eYBL5Qh0XRS2jlHSxYgvWTyNUI9/X04RVuXXXoeXyqGZe7QcNO21589SU YH8GQVlH9Gx41nlgPgh+JxxtBoY76wP5L6Dv3XqFV5EEJSOeuupnZaUgR6SRi0ATcenY Ipiw== X-Gm-Message-State: AOAM532r6CpGVv3BUMrtwy6QBuvTkKl5tz5sNkspoZxxk/Xk90IN5Peh ceWqyia+FTW20+W8Rgp+gKDQErOL9k/F/g== X-Google-Smtp-Source: ABdhPJy0ZsFlTc/0lXbNaxm153mIvSO6BOnpK9zp4DOpOiT232PHl7D5fHjFGVWLNvOsmxHqdrpO1A== X-Received: by 2002:aa7:9711:0:b029:1ee:b2c7:ecfe with SMTP id a17-20020aa797110000b02901eeb2c7ecfemr3339953pfg.58.1614783004283; Wed, 03 Mar 2021 06:50:04 -0800 (PST) Received: from localhost.localdomain ([106.39.151.89]) by smtp.gmail.com with ESMTPSA id i10sm27767499pgo.75.2021.03.03.06.49.58 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Mar 2021 06:50:03 -0800 (PST) From: xiangxia.m.yue@gmail.com To: i.maximets@ovn.org, blp@ovn.org, u9012063@gmail.com, horms@ovn.org Date: Wed, 3 Mar 2021 22:46:56 +0800 Message-Id: <20210303144658.47858-3-xiangxia.m.yue@gmail.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20210303144658.47858-1-xiangxia.m.yue@gmail.com> References: <20210303144658.47858-1-xiangxia.m.yue@gmail.com> Cc: dev@openvswitch.org Subject: [ovs-dev] [PATCH RESEND ovs v3 2/4] dpif-netdev: Refactor the buckets calculation. 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" From: Tonghao Zhang The way that "burst_size" was used as total buckets is very strange. If user set the "burst_size" too smaller while "rate" larger, that may affect the meter normal work. This patch refactor the buckets calculation, and start with a full buckets. Signed-off-by: Tonghao Zhang --- lib/dpif-netdev.c | 17 ++++++++++------- tests/dpif-netdev.at | 14 +++++++------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 78f3eef5381b..77df376a26bc 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -280,8 +280,8 @@ static bool dpcls_lookup(struct dpcls *cls, struct dp_meter_band { uint32_t rate; + uint32_t burst_size; uint64_t bucket; /* In 1/1000 packets (for PKTPS), or in bits (for KBPS) */ - uint64_t burst_size; uint64_t packet_count; uint64_t byte_count; }; @@ -6204,12 +6204,14 @@ dp_netdev_run_meter(struct dp_netdev *dp, struct dp_packet_batch *packets_, /* Update all bands and find the one hit with the highest rate for each * packet (if any). */ for (int m = 0; m < meter->n_bands; ++m) { - band = &meter->bands[m]; + uint64_t max_bucket_size; + band = &meter->bands[m]; + max_bucket_size = band->rate * 1000ULL; /* Update band's bucket. */ band->bucket += (uint64_t) delta_t * band->rate; - if (band->bucket > band->burst_size) { - band->bucket = band->burst_size; + if (band->bucket > max_bucket_size) { + band->bucket = max_bucket_size; } /* Drain the bucket for all the packets, if possible. */ @@ -6330,13 +6332,14 @@ dpif_netdev_meter_set(struct dpif *dpif, ofproto_meter_id meter_id, config->bands[i].burst_size = config->bands[i].rate; } - meter->bands[i].bucket = 0; meter->bands[i].rate = config->bands[i].rate; - meter->bands[i].burst_size = config->bands[i].burst_size * 1000ULL; + meter->bands[i].burst_size = config->bands[i].burst_size; + /* Start with a full bucket. */ + meter->bands[i].bucket = meter->bands[i].rate * 1000ULL; /* Figure out max delta_t that is enough to fill any bucket. */ band_max_delta_t - = meter->bands[i].burst_size / meter->bands[i].rate; + = meter->bands[i].bucket / meter->bands[i].rate; if (band_max_delta_t > meter->max_delta_t) { meter->max_delta_t = band_max_delta_t; } diff --git a/tests/dpif-netdev.at b/tests/dpif-netdev.at index 2862a3c9b96d..a30d026cabe1 100644 --- a/tests/dpif-netdev.at +++ b/tests/dpif-netdev.at @@ -314,15 +314,15 @@ sleep 1 # wait for forwarders process packets # Meter 1 is measuring packets, allowing one packet per second with # bursts of one packet, so 4 out of 5 packets should hit the drop # band. -# Meter 2 is measuring kbps, with burst size 2 (== 2000 bits). 4 packets -# (240 bytes == 1920 bits) pass, but the last packet should hit the drop band. +# Meter 2 is measuring kbps, with burst size 2 (== 1000 bits). 2 packets +# (120 bytes == 960 bits) pass, but the last packet should hit the drop band. AT_CHECK([ovs-ofctl -O OpenFlow13 meter-stats br0 | strip_timers], [0], [dnl OFPST_METER reply (OF1.3) (xid=0x2): meter:1 flow_count:1 packet_in_count:5 byte_in_count:300 duration:0.0s bands: 0: packet_count:4 byte_count:240 meter:2 flow_count:1 packet_in_count:5 byte_in_count:300 duration:0.0s bands: -0: packet_count:1 byte_count:60 +0: packet_count:3 byte_count:180 ]) # Advance time by 1/2 second @@ -343,8 +343,8 @@ sleep 1 # wait for forwarders process packets # Meter 1 is measuring packets, allowing one packet per second with # bursts of one packet, so all 5 of the new packets should hit the drop # band. -# Meter 2 is measuring kbps, with burst size 2 (== 2000 bits). After 500ms -# there should be space for 80 + 500 bits, so one new 60 byte (480 bit) packet +# Meter 2 is measuring kbps, with burst size 2 (== 1000 bits). After 500ms +# there should be space for 40 + 500 bits, so one new 60 byte (480 bit) packet # should pass, remaining 4 should hit the drop band. AT_CHECK([ovs-ofctl -O OpenFlow13 meter-stats br0 | strip_timers], [0], [dnl OFPST_METER reply (OF1.3) (xid=0x2): @@ -352,7 +352,7 @@ meter:1 flow_count:1 packet_in_count:10 byte_in_count:600 duration:0.0s bands: 0: packet_count:9 byte_count:540 meter:2 flow_count:1 packet_in_count:10 byte_in_count:600 duration:0.0s bands: -0: packet_count:5 byte_count:300 +0: packet_count:7 byte_count:420 ]) ovs-appctl time/warp 5000 @@ -360,7 +360,7 @@ ovs-appctl time/warp 5000 AT_CHECK([ ovs-appctl coverage/read-counter datapath_drop_meter ], [0], [dnl -14 +16 ]) AT_CHECK([cat ovs-vswitchd.log | filter_flow_install | strip_xout_keep_actions], [0], [dnl