From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id 882C6C6D6 for ; Fri, 29 Jan 2016 16:34:37 +0100 (CET) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga104.fm.intel.com with ESMTP; 29 Jan 2016 07:34:20 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,364,1449561600"; d="scan'208";a="891916938" Received: from fanzhan2-mobl.ger.corp.intel.com (HELO [10.237.221.58]) ([10.237.221.58]) by fmsmga001.fm.intel.com with ESMTP; 29 Jan 2016 07:34:19 -0800 To: Panu Matilainen , dev@dpdk.org References: <1453916363-26709-1-git-send-email-roy.fan.zhang@intel.com> <1453916363-26709-4-git-send-email-roy.fan.zhang@intel.com> <56A9FEDB.9000102@redhat.com> From: "Zhang, Roy Fan" Message-ID: <56AB867A.8080001@intel.com> Date: Fri, 29 Jan 2016 15:34:18 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: <56A9FEDB.9000102@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH 3/4] lib/librte_port: add packet dumping to PCAP file support in sink port X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Jan 2016 15:34:38 -0000 Hi Panu, Thank you again for careful review and comments. On 28/01/2016 11:43, Panu Matilainen wrote: > On 01/27/2016 07:39 PM, Fan Zhang wrote: >> Originally, sink ports in librte_port releases received mbufs back to >> mempool. This patch adds optional packet dumping to PCAP feature in sink >> port: the packets will be dumped to user defined PCAP file for >> storage or >> debugging. The user may also choose the sink port's activity: either it >> continuously dump the packets to the file, or stops at certain dumping >> >> This feature shares same CONFIG_RTE_PORT_PCAP compiler option as source >> port PCAP file support feature. Users can enable or disable this feature >> by setting CONFIG_RTE_PORT_PCAP compiler option "y" or "n". >> >> Signed-off-by: Fan Zhang >> Acked-by: Cristian Dumitrescu >> --- >> lib/librte_port/rte_port_source_sink.c | 268 >> +++++++++++++++++++++++++++++++-- >> lib/librte_port/rte_port_source_sink.h | 11 +- >> 2 files changed, 263 insertions(+), 16 deletions(-) >> > [...] >> +#ifdef RTE_PORT_PCAP >> + >> +/** >> + * Open PCAP file for dumping packets to the file later >> + * >> + * @param port >> + * Handle to sink port >> + * @param p >> + * Sink port parameter >> + * @return >> + * 0 on SUCCESS >> + * error code otherwise >> + */ > [...] >> + >> +#else >> + >> +static int >> +pcap_sink_open(struct rte_port_sink *port, >> + __rte_unused struct rte_port_sink_params *p) >> +{ >> + port->dumper = NULL; >> + port->max_pkts = 0; >> + port->pkt_index = 0; >> + port->dump_finish = 0; >> + >> + return 0; >> +} > > Shouldn't this just return -ENOTSUP instead of success when the pcap > feature is not built in? I agree, I will modify the code in v2. >> + >> +static void >> +pcap_sink_dump_pkt(__rte_unused struct rte_port_sink *port, >> + __rte_unused struct rte_mbuf *mbuf) {} >> + >> +static void >> +pcap_sink_flush_pkt(__rte_unused void *dumper) {} >> + >> +static void >> +pcap_sink_close(__rte_unused void *dumper) {} >> + >> +#endif >> + >> static void * >> rte_port_sink_create(__rte_unused void *params, int socket_id) >> { >> struct rte_port_sink *port; >> + struct rte_port_sink_params *p = params; >> + int status; >> >> /* Memory allocation */ >> port = rte_zmalloc_socket("PORT", sizeof(*port), >> @@ -360,6 +532,19 @@ rte_port_sink_create(__rte_unused void *params, >> int socket_id) >> return NULL; >> } >> >> + /* Try to open PCAP file for dumping, if possible */ >> + status = pcap_sink_open(port, p); >> + if (status < 0) { >> + RTE_LOG(ERR, PORT, "%s: Failed to enable PCAP support " >> + "support\n", __func__); >> + rte_free(port); >> + port = NULL; >> + } else { >> + if (port->dumper != NULL) >> + RTE_LOG(INFO, PORT, "Ready to dump packets to file " >> + "%s\n", p->file_name); >> + } >> + >> return port; >> } >> >> @@ -369,6 +554,8 @@ rte_port_sink_tx(void *port, struct rte_mbuf *pkt) >> __rte_unused struct rte_port_sink *p = (struct rte_port_sink *) >> port; >> >> RTE_PORT_SINK_STATS_PKTS_IN_ADD(p, 1); >> + if (p->dumper != NULL) >> + pcap_sink_dump_pkt(p, pkt); >> rte_pktmbuf_free(pkt); >> RTE_PORT_SINK_STATS_PKTS_DROP_ADD(p, 1); >> >> @@ -387,21 +574,44 @@ rte_port_sink_tx_bulk(void *port, struct >> rte_mbuf **pkts, >> >> RTE_PORT_SINK_STATS_PKTS_IN_ADD(p, n_pkts); >> RTE_PORT_SINK_STATS_PKTS_DROP_ADD(p, n_pkts); >> - for (i = 0; i < n_pkts; i++) { >> - struct rte_mbuf *pkt = pkts[i]; >> - >> - rte_pktmbuf_free(pkt); >> + if (p->dumper) { >> + for (i = 0; i < n_pkts; i++) { >> + struct rte_mbuf *pkt = pkts[i]; >> + >> + pcap_sink_dump_pkt(p, pkt); >> + rte_pktmbuf_free(pkt); >> + } >> + } else { >> + for (i = 0; i < n_pkts; i++) { >> + struct rte_mbuf *pkt = pkts[i]; >> + >> + rte_pktmbuf_free(pkt); >> + } >> } >> } else { >> - for ( ; pkts_mask; ) { >> - uint32_t pkt_index = __builtin_ctzll(pkts_mask); >> - uint64_t pkt_mask = 1LLU << pkt_index; >> - struct rte_mbuf *pkt = pkts[pkt_index]; >> - >> - RTE_PORT_SINK_STATS_PKTS_IN_ADD(p, 1); >> - RTE_PORT_SINK_STATS_PKTS_DROP_ADD(p, 1); >> - rte_pktmbuf_free(pkt); >> - pkts_mask &= ~pkt_mask; >> + if (p->dumper) { >> + for ( ; pkts_mask; ) { >> + uint32_t pkt_index = __builtin_ctzll(pkts_mask); >> + uint64_t pkt_mask = 1LLU << pkt_index; >> + struct rte_mbuf *pkt = pkts[pkt_index]; >> + >> + RTE_PORT_SINK_STATS_PKTS_IN_ADD(p, 1); >> + RTE_PORT_SINK_STATS_PKTS_DROP_ADD(p, 1); >> + pcap_sink_dump_pkt(p, pkt); >> + rte_pktmbuf_free(pkt); >> + pkts_mask &= ~pkt_mask; >> + } >> + } else { >> + for ( ; pkts_mask; ) { >> + uint32_t pkt_index = __builtin_ctzll(pkts_mask); >> + uint64_t pkt_mask = 1LLU << pkt_index; >> + struct rte_mbuf *pkt = pkts[pkt_index]; >> + >> + RTE_PORT_SINK_STATS_PKTS_IN_ADD(p, 1); >> + RTE_PORT_SINK_STATS_PKTS_DROP_ADD(p, 1); >> + rte_pktmbuf_free(pkt); >> + pkts_mask &= ~pkt_mask; >> + } > > These add quite a fair chunk of nearly identical duplicate code, which > could be easily avoided with an _ops-style function pointer between > say, null_sink_dump_pkt() which is a no-op function and > pcap_sink_dump_pkt(). The reason of doing this is to avoid using if/else in for loop to speed up a little. But your suggestion is quite nice, I will think better way like this and modify the code. > - Panu - Best regards, Fan