From patchwork Mon Dec 31 19:45:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ophir Munk X-Patchwork-Id: 1019702 X-Patchwork-Delegate: ian.stokes@intel.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.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 mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43T7CJ2jrBz9sDP for ; Tue, 1 Jan 2019 06:48:12 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id F3CBDB2F; Mon, 31 Dec 2018 19:46:30 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id D375BB01 for ; Mon, 31 Dec 2018 19:46:27 +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 smtp1.linuxfoundation.org (Postfix) with ESMTP id DF600844 for ; Mon, 31 Dec 2018 19:46:25 +0000 (UTC) Received: from Internal Mail-Server by MTLPINE1 (envelope-from ophirmu@mellanox.com) with ESMTPS (AES256-SHA encrypted); 31 Dec 2018 21:46:20 +0200 Received: from localhost.localdomain (pegasus05.mtr.labs.mlnx [10.210.16.100]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id wBVJkKYl022039; Mon, 31 Dec 2018 21:46:20 +0200 Received: from pegasus05.mtr.labs.mlnx (localhost [127.0.0.1]) by localhost.localdomain (8.14.7/8.14.7) with ESMTP id wBVJkK5o001687; Mon, 31 Dec 2018 19:46:20 GMT Received: (from root@localhost) by pegasus05.mtr.labs.mlnx (8.14.7/8.14.7/Submit) id wBVJkKbi001686; Mon, 31 Dec 2018 19:46:20 GMT From: Ophir Munk To: ovs-dev@openvswitch.org Date: Mon, 31 Dec 2018 19:45:57 +0000 Message-Id: <1546285557-1617-6-git-send-email-ophirmu@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1546285557-1617-1-git-send-email-ophirmu@mellanox.com> References: <1546285557-1617-1-git-send-email-ophirmu@mellanox.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Shahaf Shuler , Simon Horman , Ilya Maximets , Thomas Monjalon Subject: [ovs-dev] [hwol RFC v1 5/5] dpif-netdev: Read hw stats during flow_dump_next() call X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Flow stats are retrieved by revalidator threads. Specifically for dpif-netdev the function dpif_netdev_flow_dump_next() is called. When the flow is fully offloaded reading the PMD SW stats alone will result in no updates and will cause the revalidator to falsely delete the flow after some aging time. This commit adds a new function called dp_netdev_offload_used() which reads the hw counters during the flow_dump_next() call. The new function calls netdev_flow_stats_get() which in turn reads the hw stats by calling DPDK rte_flow_query() API. Signed-off-by: Ophir Munk --- lib/dpif-netdev.c | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 5d06036..dc6a989 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -3563,6 +3563,37 @@ dpif_netdev_flow_dump_thread_destroy(struct dpif_flow_dump_thread *thread_) } static int +dp_netdev_offload_used(struct dp_netdev_flow *netdev_flow, + struct dp_netdev_pmd_thread *pmd) +{ + int ret; + struct dp_netdev_port *port; + struct dpif_flow_stats stats; + + odp_port_t in_port = netdev_flow->flow.in_port.odp_port; + + ovs_mutex_lock(&pmd->dp->port_mutex); + port = dp_netdev_lookup_port(pmd->dp, in_port); + if (!port) { + ovs_mutex_unlock(&pmd->dp->port_mutex); + return -1; + } + /* get offloaded stats */ + ret = netdev_flow_stats_get(port->netdev, + &netdev_flow->mega_ufid, &stats); + ovs_mutex_unlock(&pmd->dp->port_mutex); + if (ret) { + return -1; + } + 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) { @@ -3594,14 +3625,21 @@ dpif_netdev_flow_dump_next(struct dpif_flow_dump_thread *thread_, do { for (n_flows = 0; n_flows < flow_limit; n_flows++) { struct cmap_node *node; + struct dp_netdev_flow *flow; node = cmap_next_position(&pmd->flow_table, &dump->flow_pos); if (!node) { break; } - netdev_flows[n_flows] = CONTAINER_OF(node, - struct dp_netdev_flow, - node); + flow = netdev_flows[n_flows] = CONTAINER_OF(node, + struct dp_netdev_flow, + node); + /* Read offload stats in case ufid equals mega_ufid. */ + if (netdev_is_flow_api_enabled() && + (!memcmp(&flow->ufid, &flow->mega_ufid, + sizeof flow->ufid))) { + dp_netdev_offload_used(flow, pmd); + } } /* When finishing dumping the current pmd thread, moves to * the next. */