From: ogawa.yasufumi@lab.ntt.co.jp
To: spp@dpdk.org, ferruh.yigit@intel.com, ogawa.yasufumi@lab.ntt.co.jp
Cc: Hideyuki Yamashita <yamashita.hideyuki@po.ntt-tx.co.jp>
Subject: [spp] [PATCH 2/3] spp_pcap: fix bug pkts remained after pcap stopped
Date: Mon, 4 Mar 2019 15:53:46 +0900 [thread overview]
Message-ID: <1551682427-13835-3-git-send-email-ogawa.yasufumi@lab.ntt.co.jp> (raw)
In-Reply-To: <1551682427-13835-1-git-send-email-ogawa.yasufumi@lab.ntt.co.jp>
From: Hideyuki Yamashita <yamashita.hideyuki@po.ntt-tx.co.jp>
* Add dequeueing before finalize pcap because spp_pcap does not dequeue
remained packets from ring and discards it while stopping pcap.
* Refactors for naming and log messages.
Signed-off-by: Hideyuki Yamashita <yamashita.hideyuki@po.ntt-tx.co.jp>
Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
src/pcap/spp_pcap.c | 74 +++++++++++++++++++++++++--------------------
1 file changed, 42 insertions(+), 32 deletions(-)
diff --git a/src/pcap/spp_pcap.c b/src/pcap/spp_pcap.c
index a6b58d5..a59a89b 100644
--- a/src/pcap/spp_pcap.c
+++ b/src/pcap/spp_pcap.c
@@ -746,10 +746,10 @@ static int compress_file_packet(struct pcap_mng_info *info,
return SPP_RET_OK;
}
-/* receive thread */
+/* Receive packets from shared ring buffer */
static int pcap_proc_receive(int lcore_id)
{
- struct timespec now_time;
+ struct timespec cur_time; /* Used as timestamp for the file name */
struct tm l_time;
int buf;
int nb_rx = 0;
@@ -761,36 +761,41 @@ static int pcap_proc_receive(int lcore_id)
if (g_capture_request == SPP_CAPTURE_IDLE) {
if (info->status == SPP_CAPTURE_RUNNING) {
- RTE_LOG(DEBUG, SPP_PCAP, "recive[%d], run->idle\n",
- lcore_id);
+ RTE_LOG(DEBUG, SPP_PCAP,
+ "Recive on lcore %d, run->idle\n",
+ lcore_id);
+
info->status = SPP_CAPTURE_IDLE;
g_capture_status = SPP_CAPTURE_IDLE;
}
return SPP_RET_OK;
}
if (info->status == SPP_CAPTURE_IDLE) {
- /* get time */
- clock_gettime(CLOCK_REALTIME, &now_time);
+ /* Get time for output file name */
+ clock_gettime(CLOCK_REALTIME, &cur_time);
memset(g_pcap_option.compress_file_date, 0, PCAP_FDATE_STRLEN);
- localtime_r(&now_time.tv_sec, &l_time);
+ localtime_r(&cur_time.tv_sec, &l_time);
strftime(g_pcap_option.compress_file_date, PCAP_FDATE_STRLEN,
"%Y%m%d%H%M%S", &l_time);
info->status = SPP_CAPTURE_RUNNING;
g_capture_status = SPP_CAPTURE_RUNNING;
- RTE_LOG(DEBUG, SPP_PCAP, "recive[%d], idle->run\n", lcore_id);
- RTE_LOG(DEBUG, SPP_PCAP, "recive[%d], start time=%s\n",
- lcore_id, g_pcap_option.compress_file_date);
+
+ RTE_LOG(DEBUG, SPP_PCAP,
+ "Recive on lcore %d, idle->run\n", lcore_id);
+ RTE_LOG(DEBUG, SPP_PCAP,
+ "Recive on lcore %d, start time=%s\n",
+ lcore_id, g_pcap_option.compress_file_date);
+
}
/* Receive packets */
rx = &g_pcap_option.port_cap;
-
nb_rx = spp_eth_rx_burst(rx->dpdk_port, 0, bufs, MAX_PCAP_BURST);
if (unlikely(nb_rx == 0))
return SPP_RET_OK;
- /* Write ring packets */
- nb_tx = rte_ring_enqueue_bulk(write_ring, (void *)bufs, nb_rx, NULL);
+ /* Forward to ring for writer thread */
+ nb_tx = rte_ring_enqueue_burst(write_ring, (void *)bufs, nb_rx, NULL);
/* Discard remained packets to release mbuf */
if (unlikely(nb_tx < nb_rx)) {
@@ -803,7 +808,7 @@ static int pcap_proc_receive(int lcore_id)
return SPP_RET_OK;
}
-/* write thread */
+/* Output packets to file on writer thread */
static int pcap_proc_write(int lcore_id)
{
int ret = SPP_RET_OK;
@@ -815,15 +820,8 @@ static int pcap_proc_write(int lcore_id)
struct rte_ring *read_ring = g_pcap_option.cap_ring;
if (g_capture_status == SPP_CAPTURE_IDLE) {
- if (info->status == SPP_CAPTURE_RUNNING) {
- RTE_LOG(DEBUG, SPP_PCAP, "write[%d] run->idle\n",
- lcore_id);
- info->status = SPP_CAPTURE_IDLE;
- if (file_compression_operation(info, CLOSE_MODE)
- != SPP_RET_OK)
- return SPP_RET_NG;
- }
- return SPP_RET_OK;
+ if (info->status == SPP_CAPTURE_IDLE)
+ return SPP_RET_OK;
}
if (info->status == SPP_CAPTURE_IDLE) {
RTE_LOG(DEBUG, SPP_PCAP, "write[%d] idle->run\n", lcore_id);
@@ -835,28 +833,40 @@ static int pcap_proc_write(int lcore_id)
}
}
- /* Read packets */
- nb_rx = rte_ring_dequeue_bulk(read_ring, (void *)bufs, MAX_PCAP_BURST,
- NULL);
- if (unlikely(nb_rx == 0))
+ /* Read packets from shared ring */
+ nb_rx = rte_ring_mc_dequeue_burst(read_ring, (void *)bufs,
+ MAX_PCAP_BURST, NULL);
+ if (unlikely(nb_rx == 0)) {
+ if (g_capture_status == SPP_CAPTURE_IDLE) {
+ RTE_LOG(DEBUG, SPP_PCAP,
+ "Write on lcore %d, run->idle\n",
+ lcore_id);
+
+ info->status = SPP_CAPTURE_IDLE;
+ if (file_compression_operation(info, CLOSE_MODE)
+ != SPP_RET_OK)
+ return SPP_RET_NG;
+ }
return SPP_RET_OK;
+ }
for (buf = 0; buf < nb_rx; buf++) {
mbuf = bufs[buf];
rte_prefetch0(rte_pktmbuf_mtod(mbuf, void *));
if (compress_file_packet(&g_pcap_info[lcore_id], mbuf)
!= SPP_RET_OK) {
- RTE_LOG(ERR, SPP_PCAP, "capture file write error: "
- "%d (%s)\n", errno, strerror(errno));
- RTE_LOG(ERR, SPP_PCAP, "drop packets(write) %d\n",
- (nb_rx - buf));
+ RTE_LOG(ERR, SPP_PCAP,
+ "Failed compress_file_packet(), "
+ "errno=%d (%s)\n",
+ errno, strerror(errno));
ret = SPP_RET_NG;
info->status = SPP_CAPTURE_IDLE;
file_compression_operation(info, CLOSE_MODE);
break;
}
}
- /* mbuf free */
+
+ /* Free mbuf */
for (buf = 0; buf < nb_rx; buf++)
rte_pktmbuf_free(bufs[buf]);
--
2.17.1
next prev parent reply other threads:[~2019-03-04 6:56 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-04 6:53 [spp] [PATCH 0/3] Fix bugs of spp_pcap ogawa.yasufumi
2019-03-04 6:53 ` [spp] [PATCH 1/3] spp_pcap: change mbuf size for dequeue packets ogawa.yasufumi
2019-03-04 6:53 ` ogawa.yasufumi [this message]
2019-03-04 6:53 ` [spp] [PATCH 3/3] spp_pcap: add buffer size to reduce dropped pkts ogawa.yasufumi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1551682427-13835-3-git-send-email-ogawa.yasufumi@lab.ntt.co.jp \
--to=ogawa.yasufumi@lab.ntt.co.jp \
--cc=ferruh.yigit@intel.com \
--cc=spp@dpdk.org \
--cc=yamashita.hideyuki@po.ntt-tx.co.jp \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).