From patchwork Tue Jan 12 11:33:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tonghao Zhang X-Patchwork-Id: 1425180 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.137; helo=fraxinus.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com 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=DEqr4XLQ; dkim-atps=neutral Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DFT4Z4gNkz9srZ for ; Tue, 12 Jan 2021 22:34:20 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 64E4086113; Tue, 12 Jan 2021 11:34:18 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id A7L_AVW7zgsm; Tue, 12 Jan 2021 11:34:17 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id 067F485DC4; Tue, 12 Jan 2021 11:34:17 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id D0C88C088B; Tue, 12 Jan 2021 11:34:16 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id AD429C013A for ; Tue, 12 Jan 2021 11:34:15 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 79E7E204D3 for ; Tue, 12 Jan 2021 11:34:15 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xXYm6HM734Kz for ; Tue, 12 Jan 2021 11:34:12 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-oi1-f182.google.com (mail-oi1-f182.google.com [209.85.167.182]) by silver.osuosl.org (Postfix) with ESMTPS id D3A5C204C0 for ; Tue, 12 Jan 2021 11:34:11 +0000 (UTC) Received: by mail-oi1-f182.google.com with SMTP id p5so1984133oif.7 for ; Tue, 12 Jan 2021 03:34:11 -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; bh=0EeWgfAwDIGqrGcwP3Mv59DuSrx2n6pMiQcnZ5vaMqE=; b=DEqr4XLQKTmnD5fW5bGDq3BvYiBQNqYubZYxmSwBePfs217q8wkNTFpZsfZ/PKzs7s 0zmBmK+xDDopVEMOrt/i5YqTGb4eHJwqvjNfqpeX8gXwZZsgS5mGO1Cb8A3sgH2iHFi1 NJKU604SxTdCn97ihoa74J5ZoLCTnrwQLcEnwywH78igUTxdgnSa2uOyhKZAAxmhVoYQ +vnxIMsNk6owPCXSBuuHBe/noQTMavmxIUcLMlVUP1/JdCCgWFKCUhG51dp/yQwn2I86 Z3lvpoyy5MAnhEMNDUcDSEJIyIkdCqKEJL6tc47wn8dqphRi5uNoXvE01ytAoX/iwOi9 oZQw== 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; bh=0EeWgfAwDIGqrGcwP3Mv59DuSrx2n6pMiQcnZ5vaMqE=; b=lxxLFXdxwbILhExg/3unZvSe0noebzBlLH/6AJHo1cjdtolJI71m36U+AF/hQ6CPvZ 9fV+9etLfeFdfOB85U7rKZNR8qdBMbFXGaInxD0aS4H7U8mA5jYR8j03hO7Mg2DqIgP9 0FREN5N+Y56fWaPskObUKtqKgH4o1wr8DMdyRZT0S73faFJq1OKLcF8YrByJvQ6kzKZx jay6y02VSHgNdWjrfIpvKAcqCWfceZe5BrWIM85tOjVZyfTqXosI49O5Ao7g6dFxY0h4 Y4irn9qilKddyp/FeuNiJdHmQhIJ5YZ+vanZXvSCVrTGxDOXfF+5+ykBm2rIVMNlnOh4 CY5A== X-Gm-Message-State: AOAM530mDe0y1JD8K9elLB1QP+5+5gxuIgLUBYK9LtB3KBv3y0tr0ggH blHDA8Chbu9L3QN/cNiDvic= X-Google-Smtp-Source: ABdhPJx0rHEFihvN37cvWDXcz2fKDYoQruxhsTV9v6uCILVF1sjZdwJMtTTCKKKdIM+Frxe+C03rrg== X-Received: by 2002:aca:438b:: with SMTP id q133mr2049915oia.50.1610451251049; Tue, 12 Jan 2021 03:34:11 -0800 (PST) Received: from localhost.localdomain ([50.236.19.102]) by smtp.gmail.com with ESMTPSA id j11sm525472oos.47.2021.01.12.03.34.04 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Jan 2021 03:34:10 -0800 (PST) From: xiangxia.m.yue@gmail.com To: i.maximets@ovn.org, blp@ovn.org, pshelar@ovn.org Date: Tue, 12 Jan 2021 19:33:07 +0800 Message-Id: <20210112113308.48307-1-xiangxia.m.yue@gmail.com> X-Mailer: git-send-email 2.15.0 Cc: dev@openvswitch.org Subject: [ovs-dev] [PATCH ovs 1/2] dpif-netdev: Fix the meter buckets overflow. 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 When setting the meter rate to 4.3+Gbps, there is an overflow, the meters don't work as expected. $ ovs-ofctl -O OpenFlow13 add-meter br-int "meter=1 kbps stats bands=type=drop rate=4294968" Before the patch, the buckets of meters was stored in its burst_size of ofputil_meter_band. It was overflow when we set the rate to 4294968. This patch don't change the public API and structure. This patch remove the "up" from dp_meter_band, and introduce the type, rate to datapath's meter bands. Then datapath don't depend upper layer. Signed-off-by: Tonghao Zhang --- lib/dpif-netdev.c | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 300861ca5..3ad737248 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -279,8 +279,10 @@ static bool dpcls_lookup(struct dpcls *cls, ( 1 << OFPMBT13_DROP ) struct dp_meter_band { - struct ofputil_meter_band up; /* type, prec_level, pad, rate, burst_size */ - uint32_t bucket; /* In 1/1000 packets (for PKTPS), or in bits (for KBPS) */ + uint16_t type; + uint32_t rate; + uint32_t burst_size; + uint64_t bucket; /* In 1/1000 packets (for PKTPS), or in bits (for KBPS) */ uint64_t packet_count; uint64_t byte_count; }; @@ -6156,12 +6158,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]; /* Update band's bucket. */ - band->bucket += delta_t * band->up.rate; - if (band->bucket > band->up.burst_size) { - band->bucket = band->up.burst_size; + max_bucket_size = band->rate * 1000ULL; + band->bucket += (uint64_t)delta_t * band->rate; + if (band->bucket > max_bucket_size) { + band->bucket = max_bucket_size; } /* Drain the bucket for all the packets, if possible. */ @@ -6179,8 +6183,8 @@ dp_netdev_run_meter(struct dp_netdev *dp, struct dp_packet_batch *packets_, * (Only one band will be fired by a packet, and that * can be different for each packet.) */ for (int i = band_exceeded_pkt; i < cnt; i++) { - if (band->up.rate > exceeded_rate[i]) { - exceeded_rate[i] = band->up.rate; + if (band->rate > exceeded_rate[i]) { + exceeded_rate[i] = band->rate; exceeded_band[i] = m; } } @@ -6199,8 +6203,8 @@ dp_netdev_run_meter(struct dp_netdev *dp, struct dp_packet_batch *packets_, /* Update the exceeding band for the exceeding packet. * (Only one band will be fired by a packet, and that * can be different for each packet.) */ - if (band->up.rate > exceeded_rate[i]) { - exceeded_rate[i] = band->up.rate; + if (band->rate > exceeded_rate[i]) { + exceeded_rate[i] = band->rate; exceeded_band[i] = m; } } @@ -6277,21 +6281,15 @@ dpif_netdev_meter_set(struct dpif *dpif, ofproto_meter_id meter_id, for (i = 0; i < config->n_bands; ++i) { uint32_t band_max_delta_t; - /* Set burst size to a workable value if none specified. */ - if (config->bands[i].burst_size == 0) { - config->bands[i].burst_size = config->bands[i].rate; - } - - meter->bands[i].up = config->bands[i]; - /* Convert burst size to the bucket units: */ - /* pkts => 1/1000 packets, kilobits => bits. */ - meter->bands[i].up.burst_size *= 1000; - /* Initialize bucket to empty. */ - meter->bands[i].bucket = 0; + meter->bands[i].type = config->bands[i].type; + meter->bands[i].rate = config->bands[i].rate; + 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].up.burst_size / meter->bands[i].up.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; }