From 06b266fb3204312e877b36f0ef6f2ccb0bbedb03 Mon Sep 17 00:00:00 2001 From: Alexey Rychkov Date: Tue, 6 Feb 2018 18:44:17 +0300 Subject: [PATCH] exanic-capture: add support for yielding CPU between spins --- util/exanic-capture.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/util/exanic-capture.c b/util/exanic-capture.c index e585046..8904e2f 100644 --- a/util/exanic-capture.c +++ b/util/exanic-capture.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -471,7 +472,7 @@ int main(int argc, char *argv[]) exanic_cycles32_t timestamp; struct timespec ts; struct exanic_timespecps tsps; - int hw_tstamp = 0, nsec_pcap = 0, snaplen = sizeof(rx_buf), flush = 0; + int hw_tstamp = 0, nsec_pcap = 0, snaplen = sizeof(rx_buf), flush = 0, yield = 0; int promisc = 1, set_promisc, filter; unsigned long rx_success = 0, rx_aborted = 0, rx_corrupt = 0, rx_hwovfl = 0, rx_swovfl = 0, rx_other = 0; @@ -481,7 +482,7 @@ int main(int argc, char *argv[]) char file_name_buf[4096]; int c; - while ((c = getopt(argc, argv, "i:w:s:C:F:pHNh?")) != -1) + while ((c = getopt(argc, argv, "i:w:s:C:F:pHNYh?")) != -1) { switch (c) { @@ -516,6 +517,9 @@ int main(int argc, char *argv[]) case 'N': nsec_pcap = 1; break; + case 'Y': + yield = 1; + break; default: goto usage_error; } @@ -599,7 +603,12 @@ int main(int argc, char *argv[]) ×tamp, &status); if (rx_size < 0 && status == EXANIC_RX_FRAME_OK) + { + if(yield) + sched_yield(); + continue; + } /* Get timestamp */ if (rx_size > 0 && hw_tstamp) @@ -728,7 +737,8 @@ int main(int argc, char *argv[]) fprintf(stderr, " -F: file format [pcap|erf] (default is pcap)\n"); fprintf(stderr, " -p: do not attempt to put interface in promiscuous mode\n"); fprintf(stderr, " -H: use hardware timestamps (requires exanic-clock-sync or exanic-ptpd)\n"); - fprintf(stderr, " -N: write nanosecond-resolution pcap format\n\n"); + fprintf(stderr, " -N: write nanosecond-resolution pcap format\n"); + fprintf(stderr, " -Y: yield CPU between spins\n\n"); fprintf(stderr, "Filter examples:\n"); fprintf(stderr, " tcp port 80 (to/from tcp port 80)\n"); fprintf(stderr, " host 192.168.0.1 tcp port 80 (to/from 192.168.0.1:80)\n");