From patchwork Sat May 23 10:33:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tonghao Zhang X-Patchwork-Id: 1296673 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=u5GzZVD0; 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 49Tfpc39QWz9sPK for ; Sat, 23 May 2020 20:33:44 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id B43DC874E3; Sat, 23 May 2020 10:33:42 +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 mm18nA1AQYqD; Sat, 23 May 2020 10:33:40 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id 7029C87470; Sat, 23 May 2020 10:33:40 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 53639C0178; Sat, 23 May 2020 10:33:40 +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 7EFF6C08A2 for ; Sat, 23 May 2020 10:33:39 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 5DA8B2051B for ; Sat, 23 May 2020 10:33:39 +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 waGfV7yp5wzW for ; Sat, 23 May 2020 10:33:36 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by silver.osuosl.org (Postfix) with ESMTPS id B875B20455 for ; Sat, 23 May 2020 10:33:36 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id u5so6189799pgn.5 for ; Sat, 23 May 2020 03:33:36 -0700 (PDT) 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=vvGZeXBJIyGQ3FeI3RNESOSt4zD3IMSbY0VOMpoBDfU=; b=u5GzZVD0APcmaqRA9VoG3yRt6B+Ct4SaqxePlE/7EzSfbb1xsxjd9nKkEo1hMVRU7w 40NAKI7TA9EjZVpk7UWimPEgBnSiqxbGl5NBbbAeSYmfVFUMzeMzTY4BP1nWQUTF0ZBA rrSleOkBjhIEtxbGf8ZhkjEqx+j/dRBuh6qIprWj+0OvSzk+LPDmd8587U4w2mq9VNyO Tshis73/SYfSBU8qO4WJRjHC08HS6LUejHXEVLdwkZyA3qzfQ2kmpK454T0etvK01lxR LSo+NcA4OsjBZMKnQ5j0mVhxAsB/xB4K/m71vVb+jAd2PWhBMHVIGE/aLH1pvuHfoPbP LH8w== 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=vvGZeXBJIyGQ3FeI3RNESOSt4zD3IMSbY0VOMpoBDfU=; b=a7x1aD7UERGK9Pmu/mpIUVzSVS72DPRIWh+0IkFQO1atXPjxobk3FwF3fSpfJ18NVK F+QPR26KIUcuqq6LzLWyv80qt7nzAi3yIry5zeXUsWDLOfY2q5KRSrJp+yvCewyTv6PQ isOirG+9JMTHVvBMXA9vC6tlTRLEiueNQbbdYJhVAWRFWNu/dq08w7+OrSA5P8kQHV5H WlqVTORwWhGQq70DM1tI+riBI/o321qb5m73svtwrfID46IT00SqR1Y88owbP6Febnt9 6ZMU9Qe7rnP+kegdVq5JNGV7Uu3HDDNFxs34eg3QaVUydRJ1ZrqC3OcktZ4tLaunmnDd QW0g== X-Gm-Message-State: AOAM531EiTOhmyj+voBqvXxuyklHM5muelEwPdWd9h8vyYygykPhJREC ZvAzIJDypIAq7Y2cnPBy+Bw= X-Google-Smtp-Source: ABdhPJxHhQpQdfzhAAvE+STz8eJ263SHyPYGaTBbCu9mP9jPtiS0y+jkGLE4o0f8XQF+cnT6z3z5Yg== X-Received: by 2002:aa7:9f0c:: with SMTP id g12mr8234246pfr.126.1590230016195; Sat, 23 May 2020 03:33:36 -0700 (PDT) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id mt3sm1405205pjb.23.2020.05.23.03.33.33 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 23 May 2020 03:33:35 -0700 (PDT) From: xiangxia.m.yue@gmail.com To: i.maximets@ovn.org, u9012063@gmail.com, jarno@ovn.org, blp@ovn.org, azhou@ovn.org, pshelar@ovn.org Date: Sat, 23 May 2020 18:33:17 +0800 Message-Id: <20200523103320.47497-2-xiangxia.m.yue@gmail.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20200523103320.47497-1-xiangxia.m.yue@gmail.com> References: <20200523103320.47497-1-xiangxia.m.yue@gmail.com> Cc: dev@openvswitch.org Subject: [ovs-dev] [PATCH ovs-dev v3 1/4] dpif-netdev: Expand the meters supported number. 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 For now, ovs-vswitchd use the array of the dp_meter struct to store meter's data, and at most, there are only 65536 (defined by MAX_METERS) meters that can be used. But in some case, for example, in the edge gateway, we should use 200,000, at least, meters for IP address bandwidth limitation. Every one IP address will use two meters for its rx and tx path[1]. In other way, ovs-vswitchd should support meter-offload (rte_mtr_xxx api introduced by dpdk.), but there are more than 65536 meters in the hardware, such as Mellanox ConnectX-6. This patch use array to manage the meter, but it can ben expanded. [1]. $ in_port=p0,ip,ip_dst=1.1.1.x action=meter:n,output:p1 $ in_port=p1,ip,ip_src=1.1.1.x action=meter:m,output:p0 Cc: Ilya Maximets Cc: William Tu Cc: Jarno Rajahalme Cc: Ben Pfaff Cc: Andy Zhou Cc: Pravin Shelar Signed-off-by: Tonghao Zhang --- v3: * rename n_meters -> n_allocated in dp_meter_instance * rename count -> n_used in dp_meter_table * rename "ti" -> "meter_inst" or "inst" in different functions/struction * remove parenthesize for sizeof * rename dp_netdev_meter_destroy/init to dp_netdev_meter_table_destroy/init * fix OVS_REQUIRES style v2: * add comments for dp_meter_instance * change the log * remove extra newline * I don't move the dp_netdev_meter_init/destroy up. because them depends other meters function and put all meter function together may make the codes clean. --- lib/dpif-netdev.c | 319 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 250 insertions(+), 69 deletions(-) diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 51c888501bdf..920fef3ec572 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -99,9 +99,12 @@ DEFINE_STATIC_PER_THREAD_DATA(uint32_t, recirc_depth, 0) /* Configuration parameters. */ enum { MAX_FLOWS = 65536 }; /* Maximum number of flows in flow table. */ -enum { MAX_METERS = 65536 }; /* Maximum number of meters. */ -enum { MAX_BANDS = 8 }; /* Maximum number of bands / meter. */ -enum { N_METER_LOCKS = 64 }; /* Maximum number of meters. */ + +/* Maximum number of meters in the table. */ +#define METER_ENTRY_MAX (200000ULL) +/* Maximum number of bands / meter. */ +#define METER_BAND_MAX (8) +#define DP_METER_ARRAY_SIZE_MIN (1ULL << 10) COVERAGE_DEFINE(datapath_drop_meter); COVERAGE_DEFINE(datapath_drop_upcall_error); @@ -284,12 +287,26 @@ struct dp_meter { uint16_t flags; uint16_t n_bands; uint32_t max_delta_t; + uint32_t id; + struct ovs_mutex lock; uint64_t used; uint64_t packet_count; uint64_t byte_count; struct dp_meter_band bands[]; }; +struct dp_meter_instance { + uint32_t n_allocated; + /* Followed by struct dp_meter[n]; where n is the n_allocated. */ + OVSRCU_TYPE(struct dp_meter *) dp_meters[]; +}; + +struct dp_meter_table { + OVSRCU_TYPE(struct dp_meter_instance *) meter_inst; + uint32_t n_used; + struct ovs_mutex lock; +}; + struct pmd_auto_lb { bool auto_lb_requested; /* Auto load balancing requested by user. */ bool is_enabled; /* Current status of Auto load balancing. */ @@ -330,8 +347,7 @@ struct dp_netdev { atomic_uint32_t tx_flush_interval; /* Meters. */ - struct ovs_mutex meter_locks[N_METER_LOCKS]; - struct dp_meter *meters[MAX_METERS]; /* Meter bands. */ + struct dp_meter_table meter_tbl; /* Probability of EMC insertions is a factor of 'emc_insert_min'.*/ OVS_ALIGNED_VAR(CACHE_LINE_SIZE) atomic_uint32_t emc_insert_min; @@ -379,19 +395,6 @@ struct dp_netdev { struct pmd_auto_lb pmd_alb; }; -static void meter_lock(const struct dp_netdev *dp, uint32_t meter_id) - OVS_ACQUIRES(dp->meter_locks[meter_id % N_METER_LOCKS]) -{ - ovs_mutex_lock(&dp->meter_locks[meter_id % N_METER_LOCKS]); -} - -static void meter_unlock(const struct dp_netdev *dp, uint32_t meter_id) - OVS_RELEASES(dp->meter_locks[meter_id % N_METER_LOCKS]) -{ - ovs_mutex_unlock(&dp->meter_locks[meter_id % N_METER_LOCKS]); -} - - static struct dp_netdev_port *dp_netdev_lookup_port(const struct dp_netdev *dp, odp_port_t) OVS_REQUIRES(dp->port_mutex); @@ -1524,6 +1527,9 @@ choose_port(struct dp_netdev *dp, const char *name) return ODPP_NONE; } +static void dp_netdev_meter_table_init(struct dp_meter_table *tbl); +static void dp_netdev_meter_table_destroy(struct dp_meter_table *tbl); + static int create_dp_netdev(const char *name, const struct dpif_class *class, struct dp_netdev **dpp) @@ -1557,9 +1563,7 @@ create_dp_netdev(const char *name, const struct dpif_class *class, dp->reconfigure_seq = seq_create(); dp->last_reconfigure_seq = seq_read(dp->reconfigure_seq); - for (int i = 0; i < N_METER_LOCKS; ++i) { - ovs_mutex_init_adaptive(&dp->meter_locks[i]); - } + dp_netdev_meter_table_init(&dp->meter_tbl); /* Disable upcalls by default. */ dp_netdev_disable_upcall(dp); @@ -1648,16 +1652,6 @@ dp_netdev_destroy_upcall_lock(struct dp_netdev *dp) fat_rwlock_destroy(&dp->upcall_rwlock); } -static void -dp_delete_meter(struct dp_netdev *dp, uint32_t meter_id) - OVS_REQUIRES(dp->meter_locks[meter_id % N_METER_LOCKS]) -{ - if (dp->meters[meter_id]) { - free(dp->meters[meter_id]); - dp->meters[meter_id] = NULL; - } -} - /* Requires dp_netdev_mutex so that we can't get a new reference to 'dp' * through the 'dp_netdevs' shash while freeing 'dp'. */ static void @@ -1695,16 +1689,7 @@ dp_netdev_free(struct dp_netdev *dp) /* Upcalls must be disabled at this point */ dp_netdev_destroy_upcall_lock(dp); - int i; - - for (i = 0; i < MAX_METERS; ++i) { - meter_lock(dp, i); - dp_delete_meter(dp, i); - meter_unlock(dp, i); - } - for (i = 0; i < N_METER_LOCKS; ++i) { - ovs_mutex_destroy(&dp->meter_locks[i]); - } + dp_netdev_meter_table_destroy(&dp->meter_tbl); free(dp->pmd_cmask); free(CONST_CAST(char *, dp->name)); @@ -5714,14 +5699,197 @@ dp_netdev_disable_upcall(struct dp_netdev *dp) /* Meters */ +static uint32_t +meter_hash(struct dp_meter_instance *inst, uint32_t id) +{ + uint32_t n_allocated = inst->n_allocated; + + return id % n_allocated; +} + +static void +dp_meter_free(struct dp_meter *meter) +{ + ovs_mutex_destroy(&meter->lock); + free(meter); +} + +static struct dp_meter_instance * +dp_meter_instance_alloc(const uint32_t size) +{ + struct dp_meter_instance *inst; + + inst = xzalloc(sizeof *inst + sizeof(struct dp_meter *) * size); + inst->n_allocated = size; + + return inst; +} + +static void +dp_meter_instance_realloc(struct dp_meter_table *tbl, const uint32_t size) +{ + struct dp_meter_instance *new_inst; + struct dp_meter_instance *inst; + int n_meters; + int i; + + new_inst = dp_meter_instance_alloc(size); + + inst = ovsrcu_get(struct dp_meter_instance *, &tbl->meter_inst); + n_meters = MIN(size, inst->n_allocated); + + for (i = 0; i < n_meters; i++) { + if (ovsrcu_get(struct dp_meter *, &inst->dp_meters[i])) { + new_inst->dp_meters[i] = inst->dp_meters[i]; + } + } + + ovsrcu_set(&tbl->meter_inst, new_inst); + ovsrcu_postpone(free, inst); +} + +static void +dp_meter_instance_insert(struct dp_meter_instance *inst, + struct dp_meter *meter) +{ + uint32_t hash; + + hash = meter_hash(inst, meter->id); + ovsrcu_set(&inst->dp_meters[hash], meter); +} + +static void +dp_meter_instance_remove(struct dp_meter_instance *inst, + struct dp_meter *meter) +{ + uint32_t hash; + + hash = meter_hash(inst, meter->id); + ovsrcu_set(&inst->dp_meters[hash], NULL); +} + +static void +dp_netdev_meter_table_init(struct dp_meter_table *tbl) +{ + struct dp_meter_instance *inst; + + inst = dp_meter_instance_alloc(DP_METER_ARRAY_SIZE_MIN); + ovsrcu_set(&tbl->meter_inst, inst); + + ovs_mutex_init(&tbl->lock); + tbl->n_used = 0; +} + +static void +dp_netdev_meter_table_destroy(struct dp_meter_table *tbl) +{ + struct dp_meter_instance *inst; + int i; + + inst = ovsrcu_get(struct dp_meter_instance *, &tbl->meter_inst); + for (i = 0; i < inst->n_allocated; i++) { + struct dp_meter *meter; + + meter = ovsrcu_get(struct dp_meter *, &inst->dp_meters[i]); + if (meter) { + ovsrcu_postpone(dp_meter_free, meter); + } + } + + ovsrcu_postpone(free, inst); + ovs_mutex_destroy(&tbl->lock); +} + +static struct dp_meter * +dp_meter_lookup(struct dp_meter_table *tbl, uint32_t meter_id) +{ + struct dp_meter_instance *meter_inst; + struct dp_meter *meter; + uint32_t hash; + + meter_inst = ovsrcu_get(struct dp_meter_instance *, &tbl->meter_inst); + hash = meter_hash(meter_inst, meter_id); + + meter = ovsrcu_get(struct dp_meter *, &meter_inst->dp_meters[hash]); + if (meter && meter->id == meter_id) { + return meter; + } + + return NULL; +} + +static void +dp_meter_detach_free(struct dp_meter_table *tbl, uint32_t meter_id) + OVS_REQUIRES(tbl->lock) +{ + struct dp_meter_instance *meter_inst; + struct dp_meter *meter; + + meter = dp_meter_lookup(tbl, meter_id); + if (!meter) { + return; + } + + meter_inst = ovsrcu_get(struct dp_meter_instance *, &tbl->meter_inst); + dp_meter_instance_remove(meter_inst, meter); + ovsrcu_postpone(dp_meter_free, meter); + + tbl->n_used--; + /* Shrink the meter array if necessary. */ + if (meter_inst->n_allocated > DP_METER_ARRAY_SIZE_MIN && + tbl->n_used <= (meter_inst->n_allocated / 4)) { + int half_size = meter_inst->n_allocated / 2; + int i; + + /* Avoid hash collision, don't move slots to other place. + * Make sure there are no references of meters in array + * which will be released. + */ + for (i = half_size; i < meter_inst->n_allocated; i++) { + if (ovsrcu_get(struct dp_meter *, &meter_inst->dp_meters[i])) { + return; + } + } + + dp_meter_instance_realloc(tbl, half_size); + } +} + +static int +dp_meter_attach(struct dp_meter_table *tbl, struct dp_meter *meter) + OVS_REQUIRES(tbl->lock) +{ + struct dp_meter_instance *meter_inst; + uint32_t hash; + + meter_inst = ovsrcu_get(struct dp_meter_instance *, &tbl->meter_inst); + hash = meter_hash(meter_inst, meter->id); + + if (OVS_UNLIKELY(ovsrcu_get(struct dp_meter *, + &meter_inst->dp_meters[hash]))) { + VLOG_WARN("Failed to attach meter id %u to slot %u/%u.\n", + meter->id, hash, meter_inst->n_allocated); + return EBUSY; + } + + dp_meter_instance_insert(meter_inst, meter); + + tbl->n_used++; + if (tbl->n_used >= meter_inst->n_allocated) { + dp_meter_instance_realloc(tbl, meter_inst->n_allocated * 2); + } + + return 0; +} + static void dpif_netdev_meter_get_features(const struct dpif * dpif OVS_UNUSED, struct ofputil_meter_features *features) { - features->max_meters = MAX_METERS; + features->max_meters = METER_ENTRY_MAX; features->band_types = DP_SUPPORTED_METER_BAND_TYPES; features->capabilities = DP_SUPPORTED_METER_FLAGS_MASK; - features->max_bands = MAX_BANDS; + features->max_bands = METER_BAND_MAX; features->max_color = 0; } @@ -5743,14 +5911,13 @@ dp_netdev_run_meter(struct dp_netdev *dp, struct dp_packet_batch *packets_, uint32_t exceeded_rate[NETDEV_MAX_BURST]; int exceeded_pkt = cnt; /* First packet that exceeded a band rate. */ - if (meter_id >= MAX_METERS) { + if (meter_id >= METER_ENTRY_MAX) { return; } - meter_lock(dp, meter_id); - meter = dp->meters[meter_id]; + meter = dp_meter_lookup(&dp->meter_tbl, meter_id); if (!meter) { - goto out; + return; } /* Initialize as negative values. */ @@ -5758,6 +5925,7 @@ dp_netdev_run_meter(struct dp_netdev *dp, struct dp_packet_batch *packets_, /* Initialize as zeroes. */ memset(exceeded_rate, 0, cnt * sizeof *exceeded_rate); + ovs_mutex_lock(&meter->lock); /* All packets will hit the meter at the same time. */ long_delta_t = now / 1000 - meter->used / 1000; /* msec */ @@ -5875,8 +6043,8 @@ dp_netdev_run_meter(struct dp_netdev *dp, struct dp_packet_batch *packets_, dp_packet_batch_refill(packets_, packet, j); } } - out: - meter_unlock(dp, meter_id); + + ovs_mutex_unlock(&meter->lock); } /* Meter set/get/del processing is still single-threaded. */ @@ -5885,11 +6053,12 @@ dpif_netdev_meter_set(struct dpif *dpif, ofproto_meter_id meter_id, struct ofputil_meter_config *config) { struct dp_netdev *dp = get_dp_netdev(dpif); + struct dp_meter_table *meter_tbl = &dp->meter_tbl; uint32_t mid = meter_id.uint32; struct dp_meter *meter; - int i; + int err, i; - if (mid >= MAX_METERS) { + if (mid >= METER_ENTRY_MAX) { return EFBIG; /* Meter_id out of range. */ } @@ -5897,7 +6066,7 @@ dpif_netdev_meter_set(struct dpif *dpif, ofproto_meter_id meter_id, return EBADF; /* Unsupported flags set */ } - if (config->n_bands > MAX_BANDS) { + if (config->n_bands > METER_BAND_MAX) { return EINVAL; } @@ -5918,6 +6087,8 @@ dpif_netdev_meter_set(struct dpif *dpif, ofproto_meter_id meter_id, meter->n_bands = config->n_bands; meter->max_delta_t = 0; meter->used = time_usec(); + meter->id = mid; + ovs_mutex_init(&meter->lock); /* set up bands */ for (i = 0; i < config->n_bands; ++i) { @@ -5943,12 +6114,22 @@ dpif_netdev_meter_set(struct dpif *dpif, ofproto_meter_id meter_id, } } - meter_lock(dp, mid); - dp_delete_meter(dp, mid); /* Free existing meter, if any */ - dp->meters[mid] = meter; - meter_unlock(dp, mid); + ovs_mutex_lock(&meter_tbl->lock); + + dp_meter_detach_free(meter_tbl, mid); /* Free existing meter, if any */ + err = dp_meter_attach(meter_tbl, meter); + if (err) { + goto unlock_out; + } + + ovs_mutex_unlock(&meter_tbl->lock); return 0; + +unlock_out: + ovs_mutex_unlock(&meter_tbl->lock); + dp_meter_free(meter); + return err; } static int @@ -5956,23 +6137,23 @@ dpif_netdev_meter_get(const struct dpif *dpif, ofproto_meter_id meter_id_, struct ofputil_meter_stats *stats, uint16_t n_bands) { - const struct dp_netdev *dp = get_dp_netdev(dpif); + struct dp_netdev *dp = get_dp_netdev(dpif); uint32_t meter_id = meter_id_.uint32; - int retval = 0; + const struct dp_meter *meter; - if (meter_id >= MAX_METERS) { + if (meter_id >= METER_ENTRY_MAX) { return EFBIG; } - meter_lock(dp, meter_id); - const struct dp_meter *meter = dp->meters[meter_id]; + meter = dp_meter_lookup(&dp->meter_tbl, meter_id); if (!meter) { - retval = ENOENT; - goto done; + return ENOENT; } + if (stats) { int i = 0; + ovs_mutex_lock(&meter->lock); stats->packet_in_count = meter->packet_count; stats->byte_in_count = meter->byte_count; @@ -5980,13 +6161,12 @@ dpif_netdev_meter_get(const struct dpif *dpif, stats->bands[i].packet_count = meter->bands[i].packet_count; stats->bands[i].byte_count = meter->bands[i].byte_count; } + ovs_mutex_unlock(&meter->lock); stats->n_bands = i; } -done: - meter_unlock(dp, meter_id); - return retval; + return 0; } static int @@ -5995,15 +6175,16 @@ dpif_netdev_meter_del(struct dpif *dpif, struct ofputil_meter_stats *stats, uint16_t n_bands) { struct dp_netdev *dp = get_dp_netdev(dpif); + struct dp_meter_table *meter_tbl = &dp->meter_tbl; int error; error = dpif_netdev_meter_get(dpif, meter_id_, stats, n_bands); if (!error) { uint32_t meter_id = meter_id_.uint32; - meter_lock(dp, meter_id); - dp_delete_meter(dp, meter_id); - meter_unlock(dp, meter_id); + ovs_mutex_lock(&meter_tbl->lock); + dp_meter_detach_free(meter_tbl, meter_id); + ovs_mutex_unlock(&meter_tbl->lock); } return error; } From patchwork Sat May 23 10:33:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tonghao Zhang X-Patchwork-Id: 1296674 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.136; helo=silver.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=Aa6/+4MO; dkim-atps=neutral Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49Tfpj2nQrz9sPK for ; Sat, 23 May 2020 20:33:49 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 4FD8C25E87; Sat, 23 May 2020 10:33:47 +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 9ui41ARo2566; Sat, 23 May 2020 10:33:44 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by silver.osuosl.org (Postfix) with ESMTP id 51FB72040E; Sat, 23 May 2020 10:33:42 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 1F85BC0176; Sat, 23 May 2020 10:33:42 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 3262CC0178 for ; Sat, 23 May 2020 10:33:40 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 1C8A9885DB for ; Sat, 23 May 2020 10:33:40 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xphppw5oV86F for ; Sat, 23 May 2020 10:33:39 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by hemlock.osuosl.org (Postfix) with ESMTPS id 90543885DE for ; Sat, 23 May 2020 10:33:39 +0000 (UTC) Received: by mail-pf1-f195.google.com with SMTP id 145so6357346pfw.13 for ; Sat, 23 May 2020 03:33:39 -0700 (PDT) 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=RXdLgxzrwtz6Invsf4515GERwf5GHUNgeodgWQZz880=; b=Aa6/+4MOmTBpES3vjPnl24A/xLLbJeb+v9dPyqwZrOpSLLkmqtnY46VIrI0t1jNgNz ZxggfPX+PlTH/XOG6+mHQxKB/8tHMm/9YjjMurecpgalSCC5U8REO2zDeWBEysKcbhPE EuFGM0zI8kILOP/4blVUfIfPIbbZb/3l49du8Rp7d+2W+3YiGkd+pEe9CJDA4xn7mS0e HvQVCXlclPdlzifyCQiqjGepFbEcsGWTRM+0tbJqRT8wUejhcgvly8MywG2BQOoLMVd4 b9TuPlYHiL+i7AAAXuv822zg2+iH7/+mUopgsMGPJe+ogGFdL41S41A8EMkKRsTHOwuX DHJw== 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=RXdLgxzrwtz6Invsf4515GERwf5GHUNgeodgWQZz880=; b=A+o6DIq0GEwL+INt4DxJfLiISWezssHTxhjzfFw7NlMr0y1nTU6XvPI2bt6XRkocas K3EXNKjNJDnokHcdROWAEi8aOtPVhL4FN0+Vj5NbZ8oRI/ifJsh0JJzEqOezzQtFzH/Q osEgLAp1dwgDJkZ6+SsE2cjuflUKFBIgcsp+ZV48Zfo8RRzl/PxhMgg374nexqzRwUtZ Y+7L84OyvJkLkxd1RBDayEDhGB4gfbqXoKeax0aMkindHYQ8yLPUrbrgQLZ3c9ZmOH1z v5Z7n4xrYnc4YEi7At6/5yVEU02KQndIl7vgmSMq6cEgDMP3PlKPb0Wyi61t7gjet/AB 7kdw== X-Gm-Message-State: AOAM532fYNuWSzLcRnz5MUp5MF9y/RSgbxnAgiLJUujPwM+GJiwxfJTx Pjsiwuq/wc3GL4D2cVaZHkE= X-Google-Smtp-Source: ABdhPJxkBRkNxnUYJ7fPm07loo2SBob5Fx+YvtjxCeF3MgPEAcAWeJ7ipxko/6ATV+PRCIivWflkTQ== X-Received: by 2002:a63:520f:: with SMTP id g15mr13579458pgb.317.1590230019235; Sat, 23 May 2020 03:33:39 -0700 (PDT) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id mt3sm1405205pjb.23.2020.05.23.03.33.36 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 23 May 2020 03:33:38 -0700 (PDT) From: xiangxia.m.yue@gmail.com To: i.maximets@ovn.org, u9012063@gmail.com, jarno@ovn.org, blp@ovn.org, azhou@ovn.org, pshelar@ovn.org Date: Sat, 23 May 2020 18:33:18 +0800 Message-Id: <20200523103320.47497-3-xiangxia.m.yue@gmail.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20200523103320.47497-1-xiangxia.m.yue@gmail.com> References: <20200523103320.47497-1-xiangxia.m.yue@gmail.com> Cc: dev@openvswitch.org Subject: [ovs-dev] [PATCH ovs-dev v3 2/4] dpif-netdev: Add burst size to buckets. 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 For now, the meter of the userspace datapath, don't include the bucket burst size to buckets. This patch includes it now. $ ovs-ofctl -O OpenFlow13 add-meter br0 \ 'meter=1 pktps burst stats bands=type=drop rate=10000 burst_size=2000' Cc: Ilya Maximets Cc: William Tu Cc: Jarno Rajahalme Cc: Ben Pfaff Cc: Andy Zhou Cc: Pravin Shelar Signed-off-by: Tonghao Zhang --- v2: * burst size unit is kilobits. should x1000. --- lib/dpif-netdev.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 920fef3ec572..b23bb8281a89 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -6094,15 +6094,11 @@ 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; + meter->bands[i].up.burst_size += config->bands[i].rate; + meter->bands[i].up.burst_size *= 1000ULL; /* Initialize bucket to empty. */ meter->bands[i].bucket = 0; From patchwork Sat May 23 10:33:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tonghao Zhang X-Patchwork-Id: 1296676 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.136; helo=silver.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=PxyqmsCS; dkim-atps=neutral Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49Tfq24v5Vz9sPK for ; Sat, 23 May 2020 20:34:06 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 10E1625D72; Sat, 23 May 2020 10:34:05 +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 VfTJMDx8C4wa; Sat, 23 May 2020 10:33:55 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by silver.osuosl.org (Postfix) with ESMTP id 7147A25F87; Sat, 23 May 2020 10:33:50 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 39548C0178; Sat, 23 May 2020 10:33:50 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 244EEC0178 for ; Sat, 23 May 2020 10:33:48 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 12E74886FC for ; Sat, 23 May 2020 10:33:48 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jGpm43UATn5m for ; Sat, 23 May 2020 10:33:43 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pj1-f66.google.com (mail-pj1-f66.google.com [209.85.216.66]) by hemlock.osuosl.org (Postfix) with ESMTPS id C068A886EF for ; Sat, 23 May 2020 10:33:42 +0000 (UTC) Received: by mail-pj1-f66.google.com with SMTP id a5so6091764pjh.2 for ; Sat, 23 May 2020 03:33:42 -0700 (PDT) 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=OUhjytkFi88OuVRNsplXLEQwNR7Tc9ubPqcokAsZvoY=; b=PxyqmsCScVaW5wj2jK+4ElGjPeyvgy9xYodSXVhLZ0BoWCnLaY281IMHBW2Lczx17P sJrLrWacWVI/c5KSpIA+aQaLoJCiLjo80WjoddE0Kodna0IxFQCJIwc1CElFmUfrDb72 i9CNo3oG0RuHuH/+KVSE/oYY2acAEifMA1MvCzXqI9A3eV6J0JRVtPKiKlI01uDpvxWb R+P8fdrtRPpo0dcZXBmrfL/RpoloAyJLCU/wX0KwHjc11MYBXwe2zU/BZ3Kllvk+WxXU 0yecIpbD0OSUWLsz3DqJmjIIiTvNK4tnAjMPXNmVyo6bzFFjpU4yv3tRfyr3HYG+3FqG Lyog== 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=OUhjytkFi88OuVRNsplXLEQwNR7Tc9ubPqcokAsZvoY=; b=Qsh3W0t/xi3vCKpKM81zoyuXuUDeV+yinQYakQrS4kSurtAAtfYT43mMpu7va0LyMs woSHwfLhL78GeeNvrrCIE1dM0GvURDYSMQ42ozP69m29oXHG1umNf1QIo7GUIsYlR26R k/EpebPIQbPOUXuqaeO4SpiCs1wu0dUH9pEJyUVhDBDNPe94Wm0bHDpMyUVi3Zsfh1pl DFine0ELJ7veK0pQdPruzjmffwsaIRfYyRVH2WzL2/YgRc5iYVwrmObER7p4Nnl+jJt8 zWL4LoeT3gqeRDuyo5odKP5N5W9L8xXFWG62DfFfh6m1zGsJnjlA7M0XlgznifM1T65X 4UEg== X-Gm-Message-State: AOAM531TkZIhkCWdwbat0AUggsBsPdWk71fBzzIK2hOj/gzlUkK18H52 1VkOHdnFQHTaFT+tLdcTDGc= X-Google-Smtp-Source: ABdhPJxUflap2s+aLhAdE5wyxNEVSZtiiarxvKIv7oIdabKlmBTbNxAU3z+YciTHVzoybIUGe2yUgw== X-Received: by 2002:a17:90a:c393:: with SMTP id h19mr10228503pjt.125.1590230022217; Sat, 23 May 2020 03:33:42 -0700 (PDT) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id mt3sm1405205pjb.23.2020.05.23.03.33.39 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 23 May 2020 03:33:41 -0700 (PDT) From: xiangxia.m.yue@gmail.com To: i.maximets@ovn.org, u9012063@gmail.com, jarno@ovn.org, blp@ovn.org, azhou@ovn.org, pshelar@ovn.org Date: Sat, 23 May 2020 18:33:19 +0800 Message-Id: <20200523103320.47497-4-xiangxia.m.yue@gmail.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20200523103320.47497-1-xiangxia.m.yue@gmail.com> References: <20200523103320.47497-1-xiangxia.m.yue@gmail.com> Cc: dev@openvswitch.org Subject: [ovs-dev] [PATCH ovs-dev v3 3/4] dpif-netdev: Use the u64 instead of u32 for buckets. 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. Cc: Ilya Maximets Cc: William Tu Cc: Jarno Rajahalme Cc: Ben Pfaff Cc: Andy Zhou Cc: Pravin Shelar Acked-by: William Tu Signed-off-by: Tonghao Zhang --- include/openvswitch/ofp-meter.h | 2 +- lib/dpif-netdev.c | 4 ++-- lib/ofp-meter.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/openvswitch/ofp-meter.h b/include/openvswitch/ofp-meter.h index 6776eae87e26..f55f89ac1a71 100644 --- a/include/openvswitch/ofp-meter.h +++ b/include/openvswitch/ofp-meter.h @@ -37,7 +37,7 @@ struct ofputil_meter_band { uint16_t type; uint8_t prec_level; /* Non-zero if type == OFPMBT_DSCP_REMARK. */ uint32_t rate; - uint32_t burst_size; + uint64_t burst_size; }; void ofputil_format_meter_band(struct ds *, enum ofp13_meter_flags, diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index b23bb8281a89..776a16dab6e8 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -278,7 +278,7 @@ static bool dpcls_lookup(struct dpcls *cls, 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) */ + uint64_t bucket; /* In 1/1000 packets (for PKTPS), or in bits (for KBPS) */ uint64_t packet_count; uint64_t byte_count; }; @@ -5972,7 +5972,7 @@ dp_netdev_run_meter(struct dp_netdev *dp, struct dp_packet_batch *packets_, band = &meter->bands[m]; /* Update band's bucket. */ - band->bucket += delta_t * band->up.rate; + band->bucket += (uint64_t)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; diff --git a/lib/ofp-meter.c b/lib/ofp-meter.c index 9ea40a0bfb63..1ac993bb028b 100644 --- a/lib/ofp-meter.c +++ b/lib/ofp-meter.c @@ -72,7 +72,7 @@ ofputil_format_meter_band(struct ds *s, enum ofp13_meter_flags flags, ds_put_format(s, " rate=%"PRIu32, mb->rate); if (flags & OFPMF13_BURST) { - ds_put_format(s, " burst_size=%"PRIu32, mb->burst_size); + ds_put_format(s, " burst_size=%"PRIu64, mb->burst_size); } if (mb->type == OFPMBT13_DSCP_REMARK) { ds_put_format(s, " prec_level=%"PRIu8, mb->prec_level); @@ -703,7 +703,7 @@ parse_ofp_meter_mod_str__(struct ofputil_meter_mod *mm, char *string, return error; } } else if (!strcmp(name, "burst_size")) { - char *error = str_to_u32(value, &band->burst_size); + char *error = str_to_u64(value, &band->burst_size); if (error) { return error; } From patchwork Sat May 23 10:33:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tonghao Zhang X-Patchwork-Id: 1296675 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=whitealder.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=UMkYvPYY; dkim-atps=neutral Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49Tfpx5nX7z9sPK for ; Sat, 23 May 2020 20:34:01 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id A2184883D4; Sat, 23 May 2020 10:33:59 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id RHT+ObZQJYLg; Sat, 23 May 2020 10:33:54 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id E7A7D88472; Sat, 23 May 2020 10:33:52 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id D41A5C0176; Sat, 23 May 2020 10:33:52 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id B689EC0892 for ; Sat, 23 May 2020 10:33:49 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 91DF2886DF for ; Sat, 23 May 2020 10:33:49 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DE6Ini6YILR1 for ; Sat, 23 May 2020 10:33:46 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pl1-f193.google.com (mail-pl1-f193.google.com [209.85.214.193]) by hemlock.osuosl.org (Postfix) with ESMTPS id D6CCE88776 for ; Sat, 23 May 2020 10:33:45 +0000 (UTC) Received: by mail-pl1-f193.google.com with SMTP id k22so5424446pls.10 for ; Sat, 23 May 2020 03:33:45 -0700 (PDT) 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=fy6OJsoIsoSMcx0B4LQhdHzQphHIaDJ/nInYnbdHYZI=; b=UMkYvPYYnUqj+UBiT2Gvm0UFc8wcL6VPtFKixjIzXURROx4NW19TzzvIzmydP4g9xc O9qk06Ek28SAyFIMNnSISFZaBnMQkxdMngda6GG1mncP2juKfHLJ7RpFAGnwvR3PQKXv Y/6eRgXuO7GVDm1sEINSsflyxhNn9qkwrFsXlgEQu2PZjYxBMwaZA7A8YZ8DS1IBQreK T6VpV4E339pMdrMPNA6pBlPt2jBdyUd3BsxK15NlAunkX31ULBcYEkcE/YEw8f1FI9v+ 2FfXhtB3NoS/phafLbFZeZG+QZsyGYinGJ2RxpLGVrXA0EjDUjXTF4BsgTaV2DEBwq9K S/PQ== 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=fy6OJsoIsoSMcx0B4LQhdHzQphHIaDJ/nInYnbdHYZI=; b=RZGeU6k5ypGzQsC4MfThT1DtqBt9f0GibJcJ9EgpSYEewRG8mgkNCCi01m+vkOrRfa ZlPN0rv42gTjXLp9Lm6vukcKwtPRrYqJBUL45kbSbZYI1UwKpStoFnjV65H7m8cgrXfs SRcgfo1Cfqpe695dcKgIInOBPyRse9Y6WaTlZmv3eLcMSfoLpa2vxXtRox7x61isKdmV EYBKjhpP2mpSFRRX/RuWKceVP7yDUWBhg4I4pMfsayQ0GeyG/PS/s4DEXEcR3lNnMcvw lQjU7TDUulqnazoFUmWRA2g7nsyADB5H2jBciRdehNKt5h2l/p/shY1LkPgSCQhsw1/e F2nA== X-Gm-Message-State: AOAM533foj53ySSBFLR+jBSPMcFa+cGN//z3AifIQX/J1wPNRHIDSbdn mA97jNI3hy4WsoAquaX7Xw4= X-Google-Smtp-Source: ABdhPJxLrXmdvpO08TGDj4BTmjDg629Ro+ufkVi4dNVFDdsiZ1B2P2qQ+J+lCgE1RaQUpYaV3jxvXQ== X-Received: by 2002:a17:902:5a04:: with SMTP id q4mr18939897pli.284.1590230025434; Sat, 23 May 2020 03:33:45 -0700 (PDT) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id mt3sm1405205pjb.23.2020.05.23.03.33.42 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 23 May 2020 03:33:44 -0700 (PDT) From: xiangxia.m.yue@gmail.com To: i.maximets@ovn.org, u9012063@gmail.com, jarno@ovn.org, blp@ovn.org, azhou@ovn.org, pshelar@ovn.org Date: Sat, 23 May 2020 18:33:20 +0800 Message-Id: <20200523103320.47497-5-xiangxia.m.yue@gmail.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20200523103320.47497-1-xiangxia.m.yue@gmail.com> References: <20200523103320.47497-1-xiangxia.m.yue@gmail.com> Cc: dev@openvswitch.org Subject: [ovs-dev] [PATCH ovs-dev v3 4/4] Revert "dpif-netdev: includes microsecond delta in meter bucket 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 This reverts commit 5c41c31ebd64fda821fb733a5784a7a440a794f8. Use the pktgen-dpdk to test the commit 5c41c31ebd64 ("dpif-netdev: includes microsecond delta in meter bucket calculation"), it does't work as expected. And it broken the meter function (e.g. set rate 200Mbps, the rate watched was 400Mbps). To reproduce it: $ ovs-vsctl add-br br-int -- set bridge br-int datapath_type=netdev $ ovs-ofctl -O OpenFlow13 add-meter br-int \ "meter=100 kbps burst stats bands=type=drop rate=200000 burst_size=200000" $ ovs-ofctl -O OpenFlow13 add-flow br-int \ "in_port=dpdk0 action=meter:100,output:dpdk1" $ pktgen -l 1,3,5,7,9,11,13,15,17,19 -n 8 --socket-mem 4096 --file-prefix pg1 \ -w 0000:82:00.0 -w 0000:82:00.1 -- -T -P -m "[3/5/7/9/11/13/15].[0-1]" -f meter-test.pkt meter-test.pkt: | set 0 count 0 | set 0 size 1500 | set 0 rate 100 | set 0 burst 64 | set 0 sport 1234 | set 0 dport 5678 | set 0 prime 1 | set 0 type ipv4 | set 0 proto udp | set 0 dst ip 1.1.1.2 | set 0 src ip 1.1.1.1/24 | set 0 dst mac ec:0d:9a:ab:54:0a | set 0 src mac ec:0d:9a:bf:df:bb | set 0 vlanid 0 | start 0 Note that 42697ca7757b ("dpif-netdev: fix meter at high packet rate.") has fixed it as 5c41c31ebd64. Cc: Ilya Maximets Cc: William Tu Cc: Jarno Rajahalme Cc: Ben Pfaff Cc: Andy Zhou Cc: Jiang Lidong Cc: Pravin Shelar Signed-off-by: Tonghao Zhang --- lib/dpif-netdev.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 776a16dab6e8..46eb1e3d97c9 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -5904,7 +5904,6 @@ 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]; @@ -5935,9 +5934,6 @@ 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 @@ -5973,7 +5969,6 @@ dp_netdev_run_meter(struct dp_netdev *dp, struct dp_packet_batch *packets_, /* Update band's bucket. */ band->bucket += (uint64_t)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; }