From patchwork Thu Aug 25 06:27:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yiding Zhou X-Patchwork-Id: 115403 X-Patchwork-Delegate: andrew.rybchenko@oktetlabs.ru Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 424FEA00C5; Thu, 25 Aug 2022 08:25:14 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CF75940DFD; Thu, 25 Aug 2022 08:25:13 +0200 (CEST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by mails.dpdk.org (Postfix) with ESMTP id 8F7D240156; Thu, 25 Aug 2022 08:25:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661408712; x=1692944712; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=0wCxq4rjjCffiPa9wiAJ5jmiRjuTrfvWCNe/5iF/aDg=; b=YYBEQKNOwvbRvXvuw5SilcCWZ+iXV4XpQWco+yPjg69yQToAOlJjNAEc nGtlNusgyYRDbvx6S84neQ4fcoLlKQ+cv3VWpepnTN9l/sVx442tpUUBt a4dg07pNGPG1vPfDsM8b+USXfDfryrxBJw7XC03YGFAWWqWtGSxzX2/yD NWB1VnrjM0nX4M00wYr8ONUr3ydU1WU58lnlZk/ZVJKDBDX5Az2G2nPuW RBJDThpzGqDL2NUEgcy9nNLTcRBLKDSijmJREIe+jIt1ZsLsXdE6COHR5 Z31ezaS/cDeq+MRIid33yROnjKT8m8a0LfVfQYf4y8ZuHiuqS8bqe/alO A==; X-IronPort-AV: E=McAfee;i="6500,9779,10449"; a="291726815" X-IronPort-AV: E=Sophos;i="5.93,262,1654585200"; d="scan'208";a="291726815" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Aug 2022 23:25:11 -0700 X-IronPort-AV: E=Sophos;i="5.93,262,1654585200"; d="scan'208";a="639453927" Received: from unknown (HELO dpdkserver..) ([10.239.252.174]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Aug 2022 23:25:09 -0700 From: Yiding Zhou To: dev@dpdk.org Cc: qi.z.zhang@intel.com, stable.dpdk.org@dpdk.org, Yiding Zhou , stable@dpdk.org Subject: [PATCH] net/pcap: reduce time for stopping device Date: Thu, 25 Aug 2022 14:27:07 +0800 Message-Id: <20220825062707.10273-1-yidingx.zhou@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The pcap file will be synchronized to the disk when stopping the device. It takes a long time if the file is large that would cause the 'detach sync request' timeout when the device is closed under multi-process scenario. This commit fixes the issue by performing synchronization in Tx path Fixes: 4c173302c307 ("pcap: add new driver") Cc: stable@dpdk.org Signed-off-by: Yiding Zhou --- drivers/net/pcap/pcap_ethdev.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/net/pcap/pcap_ethdev.c b/drivers/net/pcap/pcap_ethdev.c index ec29fd6bc5..52eafa5674 100644 --- a/drivers/net/pcap/pcap_ethdev.c +++ b/drivers/net/pcap/pcap_ethdev.c @@ -3,7 +3,7 @@ * Copyright(c) 2014 6WIND S.A. * All rights reserved. */ - +#include #include #include @@ -38,6 +38,8 @@ #define RTE_PMD_PCAP_MAX_QUEUES 16 +#define ETH_PCAP_SYNC_THRESHOLD 0x20000000 + static char errbuf[PCAP_ERRBUF_SIZE]; static struct timespec start_time; static uint64_t start_cycles; @@ -47,6 +49,8 @@ static uint8_t iface_idx; static uint64_t timestamp_rx_dynflag; static int timestamp_dynfield_offset = -1; +RTE_DEFINE_PER_LCORE(uint64_t, _pcap_cached_bytes); + struct queue_stat { volatile unsigned long pkts; volatile unsigned long bytes; @@ -144,6 +148,16 @@ static struct rte_eth_link pmd_link = { RTE_LOG_REGISTER_DEFAULT(eth_pcap_logtype, NOTICE); +static inline void +pcap_dumper_data_sync(pcap_dumper_t *dumper, uint32_t bytes) +{ + RTE_PER_LCORE(_pcap_cached_bytes) += bytes; + if (unlikely(RTE_PER_LCORE(_pcap_cached_bytes) > ETH_PCAP_SYNC_THRESHOLD)) { + if (!fdatasync(fileno(pcap_dump_file(dumper)))) + RTE_PER_LCORE(_pcap_cached_bytes) = 0; + } +} + static struct queue_missed_stat* queue_missed_stat_update(struct rte_eth_dev *dev, unsigned int qid) { @@ -421,7 +435,7 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) * process stops and to make sure the pcap file is actually written, * we flush the pcap dumper within each burst. */ - pcap_dump_flush(dumper); + pcap_dumper_data_sync(dumper, tx_bytes); dumper_q->tx_stat.pkts += num_tx; dumper_q->tx_stat.bytes += tx_bytes; dumper_q->tx_stat.err_pkts += nb_pkts - num_tx;