Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exanic-capture: add support for yielding CPU between spins #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions util/exanic-capture.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <ctype.h>
#include <signal.h>
#include <unistd.h>
#include <sched.h>
#include <stdio.h>
#include <errno.h>
#include <time.h>
Expand Down Expand Up @@ -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;
Expand All @@ -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)
{
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -599,7 +603,12 @@ int main(int argc, char *argv[])
&timestamp, &status);

if (rx_size < 0 && status == EXANIC_RX_FRAME_OK)
{
if(yield)
sched_yield();

continue;
}

/* Get timestamp */
if (rx_size > 0 && hw_tstamp)
Expand Down Expand Up @@ -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");
Expand Down