diff mbox series

[ovs-dev] dpif-netdev: includes microsecond delta in meter bucket calculation

Message ID e189949abd3d4d398e729dfb60edbc55@jd.com
State Superseded
Headers show
Series [ovs-dev] dpif-netdev: includes microsecond delta in meter bucket calculation | expand

Commit Message

Li,Rongqing via dev April 7, 2020, 3:28 a.m. UTC
From 077ab5387ca2b1dbe64389ef2d2aa8f3956f7c57 Mon Sep 17 00:00:00 2001
From: Jiang Lidong <jianglidong3@jd.com>
Date: Tue, 7 Apr 2020 10:33:14 +0800
Subject: [PATCH] dpif-netdev: includes microsecond delta in meter bucket calculation

When dp-netdev meter rate is higher than 200Mbps, observe
more than 10% bias from configured rate value with UDP traffic.

In dp-netdev meter, millisecond delta between now and last used
is taken into bucket size calcualtion, while sub-millisecond part
is truncated.

If traffic rate is pretty high, time delta can be few milliseconds,
its ratio to truncated part is less than 10:1, the loss of bucket
size caused by truncated can be observed obviously by commited
traffic rate.

In this patch, microsendcond delta part is included in calculation
of meter bucket to make it more precise.

Signed-off-by: Jiang Lidong <jianglidong3@jd.com>
---
 lib/dpif-netdev.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

William Tu April 7, 2020, 3:28 p.m. UTC | #1
On Tue, Apr 07, 2020 at 03:28:06AM +0000, 姜立东 via dev wrote:
> From 077ab5387ca2b1dbe64389ef2d2aa8f3956f7c57 Mon Sep 17 00:00:00 2001
> From: Jiang Lidong <jianglidong3@jd.com>
> Date: Tue, 7 Apr 2020 10:33:14 +0800
> Subject: [PATCH] dpif-netdev: includes microsecond delta in meter bucket calculation
> 
> When dp-netdev meter rate is higher than 200Mbps, observe
> more than 10% bias from configured rate value with UDP traffic.
> 
> In dp-netdev meter, millisecond delta between now and last used
> is taken into bucket size calcualtion, while sub-millisecond part
> is truncated.
> 
> If traffic rate is pretty high, time delta can be few milliseconds,
> its ratio to truncated part is less than 10:1, the loss of bucket
> size caused by truncated can be observed obviously by commited
> traffic rate.
> 
> In this patch, microsendcond delta part is included in calculation
> of meter bucket to make it more precise.
> 
> Signed-off-by: Jiang Lidong <jianglidong3@jd.com>

one minor typo s/microsendcond/microsecond/

Otherwise, looks good to me, thanks!
Acked-by: William Tu <u9012063@gmail.com>

> ---
>  lib/dpif-netdev.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
> index e456cc9..ef14e83 100644
> --- a/lib/dpif-netdev.c
> +++ b/lib/dpif-netdev.c
> @@ -5735,6 +5735,7 @@ dp_netdev_run_meter(struct dp_netdev *dp, struct dp_packet_batch *packets_,
>      struct dp_packet *packet;
>      long long int long_delta_t; /* msec */
>      uint32_t delta_t; /* msec */
> +    uint32_t delta_in_us; /* usec */
>      const size_t cnt = dp_packet_batch_size(packets_);
>      uint32_t bytes, volume;
>      int exceeded_band[NETDEV_MAX_BURST];
> @@ -5765,6 +5766,9 @@ dp_netdev_run_meter(struct dp_netdev *dp, struct dp_packet_batch *packets_,
>             Assuming that all racing threads received packets at the same time
>             to avoid overflow. */
>          long_delta_t = 0;
> +        delta_in_us  = 0;
> +    } else {
> +        delta_in_us  = (now - meter->used) % 1000;
>      }
>  
>      /* Make sure delta_t will not be too large, so that bucket will not
> @@ -5800,6 +5804,7 @@ dp_netdev_run_meter(struct dp_netdev *dp, struct dp_packet_batch *packets_,
>  
>          /* Update band's bucket. */
>          band->bucket += delta_t * band->up.rate;
> +        band->bucket += delta_in_us * band->up.rate / 1000;
>          if (band->bucket > band->up.burst_size) {
>              band->bucket = band->up.burst_size;
>          }
> -- 
> 1.8.3.1
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
diff mbox series

Patch

diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index e456cc9..ef14e83 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -5735,6 +5735,7 @@  dp_netdev_run_meter(struct dp_netdev *dp, struct dp_packet_batch *packets_,
     struct dp_packet *packet;
     long long int long_delta_t; /* msec */
     uint32_t delta_t; /* msec */
+    uint32_t delta_in_us; /* usec */
     const size_t cnt = dp_packet_batch_size(packets_);
     uint32_t bytes, volume;
     int exceeded_band[NETDEV_MAX_BURST];
@@ -5765,6 +5766,9 @@  dp_netdev_run_meter(struct dp_netdev *dp, struct dp_packet_batch *packets_,
            Assuming that all racing threads received packets at the same time
            to avoid overflow. */
         long_delta_t = 0;
+        delta_in_us  = 0;
+    } else {
+        delta_in_us  = (now - meter->used) % 1000;
     }
 
     /* Make sure delta_t will not be too large, so that bucket will not
@@ -5800,6 +5804,7 @@  dp_netdev_run_meter(struct dp_netdev *dp, struct dp_packet_batch *packets_,
 
         /* Update band's bucket. */
         band->bucket += delta_t * band->up.rate;
+        band->bucket += delta_in_us * band->up.rate / 1000;
         if (band->bucket > band->up.burst_size) {
             band->bucket = band->up.burst_size;
         }