From patchwork Sun Dec 8 13:22:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eli Britstein X-Patchwork-Id: 1205670 X-Patchwork-Delegate: i.maximets@samsung.com 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.133; helo=hemlock.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=mellanox.com Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47W6Vb5QF0z9sP6 for ; Mon, 9 Dec 2019 00:24:23 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 3DD5588603; Sun, 8 Dec 2019 13:24:22 +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 g1-KaVE2SkI2; Sun, 8 Dec 2019 13:24:18 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by hemlock.osuosl.org (Postfix) with ESMTP id DD28E88391; Sun, 8 Dec 2019 13:23:45 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id BBAA7C1D88; Sun, 8 Dec 2019 13:23:45 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id F36CFC1D8C for ; Sun, 8 Dec 2019 13:23:44 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 45AD0868BE for ; Sun, 8 Dec 2019 13:23:44 +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 b9leTheLduIg for ; Sun, 8 Dec 2019 13:23:35 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by fraxinus.osuosl.org (Postfix) with ESMTP id D35A286308 for ; Sun, 8 Dec 2019 13:23:26 +0000 (UTC) Received: from Internal Mail-Server by MTLPINE1 (envelope-from elibr@mellanox.com) with ESMTPS (AES256-SHA encrypted); 8 Dec 2019 15:23:20 +0200 Received: from dev-r-vrt-215.mtr.labs.mlnx. (dev-r-vrt-215.mtr.labs.mlnx [10.212.215.1]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id xB8DNJh4002052; Sun, 8 Dec 2019 15:23:20 +0200 From: Eli Britstein To: dev@openvswitch.org, Ilya Maximets , Sriharsha Basavapatna Date: Sun, 8 Dec 2019 13:22:55 +0000 Message-Id: <20191208132304.15521-11-elibr@mellanox.com> X-Mailer: git-send-email 2.14.5 In-Reply-To: <20191208132304.15521-1-elibr@mellanox.com> References: <20191208132304.15521-1-elibr@mellanox.com> Cc: Oz Shlomo , Majd Dibbiny , Eli Britstein , Ameer Mahagneh Subject: [ovs-dev] [PATCH V3 10/19] dpif-netdev: Read hw stats during flow_dump_next() call 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: Ophir Munk Use netdev flow get API in order to update the statistics of fully offloaded flows. Co-authored-by: Eli Britstein Signed-off-by: Ophir Munk Reviewed-by: Oz Shlomo Signed-off-by: Eli Britstein --- lib/dpif-netdev.c | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 1e5493615..37e7e5c38 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -527,6 +527,7 @@ struct dp_netdev_flow { bool dead; uint32_t mark; /* Unique flow mark assigned to a flow */ + bool actions_offloaded; /* true if flow is fully offloaded. */ /* Statistics. */ struct dp_netdev_flow_stats stats; @@ -2409,6 +2410,7 @@ dp_netdev_flow_offload_put(struct dp_flow_offload_item *offload) } } info.flow_mark = mark; + info.actions_offloaded = &flow->actions_offloaded; port = netdev_ports_get(in_port, pmd->dp->dpif->dpif_class); if (!port || netdev_vport_is_vport_class(port->netdev_class)) { @@ -3071,8 +3073,8 @@ dp_netdev_flow_to_dpif_flow(const struct dp_netdev_flow *netdev_flow, flow->pmd_id = netdev_flow->pmd_id; get_dpif_flow_stats(netdev_flow, &flow->stats); - flow->attrs.offloaded = false; - flow->attrs.dp_layer = "ovs"; + flow->attrs.offloaded = netdev_flow->actions_offloaded; + flow->attrs.dp_layer = flow->attrs.offloaded ? "in_hw" : "ovs"; } static int @@ -3242,6 +3244,7 @@ dp_netdev_flow_add(struct dp_netdev_pmd_thread *pmd, flow->dead = false; flow->batch = NULL; flow->mark = INVALID_FLOW_MARK; + flow->actions_offloaded = false; *CONST_CAST(unsigned *, &flow->pmd_id) = pmd->core_id; *CONST_CAST(struct flow *, &flow->flow) = match->flow; *CONST_CAST(ovs_u128 *, &flow->ufid) = *ufid; @@ -3596,6 +3599,42 @@ dpif_netdev_flow_dump_thread_destroy(struct dpif_flow_dump_thread *thread_) free(thread); } +static int +dpif_netdev_offload_used(struct dp_netdev_flow *netdev_flow, + struct dp_netdev_pmd_thread *pmd) +{ + struct dpif_flow_stats stats; + struct netdev *netdev; + struct match match; + struct nlattr *actions; + struct dpif_flow_attrs attrs; + struct ofpbuf wbuffer; + + ovs_u128 ufid; + int ret = 0; + + netdev = netdev_ports_get(netdev_flow->flow.in_port.odp_port, + pmd->dp->class); + if (!netdev) { + return -1; + } + /* get offloaded stats */ + ufid = netdev_flow->mega_ufid; + ret = netdev_flow_get(netdev, &match, &actions, &ufid, &stats, &attrs, + &wbuffer); + netdev_close(netdev); + if (ret) { + return -1; + } + if (stats.n_packets) { + atomic_store_relaxed(&netdev_flow->stats.used, pmd->ctx.now / 1000); + non_atomic_ullong_add(&netdev_flow->stats.packet_count, stats.n_packets); + non_atomic_ullong_add(&netdev_flow->stats.byte_count, stats.n_bytes); + } + + return 0; +} + static int dpif_netdev_flow_dump_next(struct dpif_flow_dump_thread *thread_, struct dpif_flow *flows, int max_flows) @@ -3636,6 +3675,10 @@ dpif_netdev_flow_dump_next(struct dpif_flow_dump_thread *thread_, netdev_flows[n_flows] = CONTAINER_OF(node, struct dp_netdev_flow, node); + /* Read hardware stats in case of hardware offload */ + if (netdev_flows[n_flows]->actions_offloaded) { + dpif_netdev_offload_used(netdev_flows[n_flows], pmd); + } } /* When finishing dumping the current pmd thread, moves to * the next. */