Commit ea1817c2 authored by David G Andersen's avatar David G Andersen

Added SPIN_OK option to force it to simply spin waiting on the socket.

This improves our granularity to the range I'm interested in, but at
the expense of maxing out a CPU.

Remove -DSPIN_OK from the CFLAGS line in the makefile if you don't
want this behavior.  Note that this only happens if you're attempting
sleeps of < 1second.  If your sleeps are longer than that, the code
will just use the 10ms timers and figure you're getting time target
hits within 1% anyway.
parent cf53375b
CFLAGS += -Wall -O2 #-DDEBUG=1 -g
CFLAGS += -Wall -O2 -DSPIN_OK #-DDEBUG=1 -g
LIBS=-L. -ldivert
......@@ -223,6 +223,8 @@ int main(int argc, char **argv) {
int rc;
int proto = IPPROTO_UDP;
fd_set readfds;
/* getopt stuff */
extern char *optarg;
extern int optind;
......@@ -324,15 +326,38 @@ int main(int argc, char **argv) {
* after running the queue, or they don't rest long enough.
granularity = delay / 100;
while (1) {
struct sockaddr_in from;
int fromlen;
int len;
int rc;
if (!packetbuf) {
packetbuf = (char *)malloc(MAXPACKET);
if (granularity < MIN_USEC) {
#ifdef SPIN_OK
granularity = 0;
granularity = MIN_USEC;
mytv.tv_sec = granularity / 1000000;
mytv.tv_usec = granularity % 1000000;
FD_SET(msock->sock, &readfds);
rc = select(msock->sock+1, &readfds, NULL, NULL, &mytv);
len = 0;
if (FD_ISSET(msock->sock, &readfds)) {
bzero(&from, sizeof(from));
fromlen = sizeof(struct sockaddr_in);
len = recvfrom(msock->sock, packetbuf, MAXPACKET, 0,
......@@ -341,7 +366,7 @@ int main(int argc, char **argv) {
if (len > 0) {
DPRINTF("Received packet of length %d\n", len);
gettimeofday(&time_now, NULL);
pq_run(timediff(&time_now, &time_prev));
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment