From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by dpdk.org (Postfix) with ESMTP id 3687BC3F2 for ; Thu, 28 Jan 2016 12:43:26 +0100 (CET) Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id AF95342E5D0; Thu, 28 Jan 2016 11:43:25 +0000 (UTC) Received: from sopuli.koti.laiskiainen.org (vpn1-4-63.ams2.redhat.com [10.36.4.63]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u0SBhO5a027775; Thu, 28 Jan 2016 06:43:24 -0500 To: Fan Zhang , 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> From: Panu Matilainen Message-ID: <56A9FEDB.9000102@redhat.com> Date: Thu, 28 Jan 2016 13:43:23 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.0 MIME-Version: 1.0 In-Reply-To: <1453916363-26709-4-git-send-email-roy.fan.zhang@intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 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: Thu, 28 Jan 2016 11:43:26 -0000 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? > + > +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(). - Panu -