Changeset View
Changeset View
Standalone View
Standalone View
tools/tools/netrate/juggle/juggle.c
Show First 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | |||||
/* | /* | ||||
* Number of in-flight messages per cycle. I adjusting this value, be | * Number of in-flight messages per cycle. I adjusting this value, be | ||||
* careful not to exceed the socket/etc buffer depth, or messages may be lost | * careful not to exceed the socket/etc buffer depth, or messages may be lost | ||||
* or result in blocking. | * or result in blocking. | ||||
*/ | */ | ||||
#define PIPELINE_MAX 4 | #define PIPELINE_MAX 4 | ||||
/* | |||||
* As in all programs, steal timespecsub() from time.h. | |||||
*/ | |||||
#define timespecsub(vvp, uvp) \ | |||||
do { \ | |||||
(vvp)->tv_sec -= (uvp)->tv_sec; \ | |||||
(vvp)->tv_nsec -= (uvp)->tv_nsec; \ | |||||
if ((vvp)->tv_nsec < 0) { \ | |||||
(vvp)->tv_sec--; \ | |||||
(vvp)->tv_nsec += 1000000000; \ | |||||
} \ | |||||
} while (0) | |||||
static int | static int | ||||
udp_create(int *fd1p, int *fd2p) | udp_create(int *fd1p, int *fd2p) | ||||
{ | { | ||||
struct sockaddr_in sin1, sin2; | struct sockaddr_in sin1, sin2; | ||||
int sock1, sock2; | int sock1, sock2; | ||||
sock1 = socket(PF_INET, SOCK_DGRAM, 0); | sock1 = socket(PF_INET, SOCK_DGRAM, 0); | ||||
if (sock1 == -1) | if (sock1 == -1) | ||||
▲ Show 20 Lines • Show All 155 Lines • ▼ Show 20 Lines | for (j = 0; j < pipeline; j++) { | ||||
if (message_recv(fd1) < 0) | if (message_recv(fd1) < 0) | ||||
err(-1, "message_recv fd1"); | err(-1, "message_recv fd1"); | ||||
} | } | ||||
} | } | ||||
if (clock_gettime(CLOCK_REALTIME, &tfinish) < 0) | if (clock_gettime(CLOCK_REALTIME, &tfinish) < 0) | ||||
err(-1, "juggle: clock_gettime"); | err(-1, "juggle: clock_gettime"); | ||||
timespecsub(&tfinish, &tstart); | timespecsub(&tfinish, &tstart, &tfinish); | ||||
return (tfinish); | return (tfinish); | ||||
} | } | ||||
/* | /* | ||||
* Juggle messages between two file descriptors in two threads, so measure | * Juggle messages between two file descriptors in two threads, so measure | ||||
* the cost of IPC and the cost of a thread context switch. | * the cost of IPC and the cost of a thread context switch. | ||||
* | * | ||||
▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | thread_juggle(int fd1, int fd2, int pipeline) | ||||
} | } | ||||
if (clock_gettime(CLOCK_REALTIME, &tfinish) < 0) | if (clock_gettime(CLOCK_REALTIME, &tfinish) < 0) | ||||
err(-1, "thread_juggle: clock_gettime"); | err(-1, "thread_juggle: clock_gettime"); | ||||
if (pthread_join(thread, NULL) != 0) | if (pthread_join(thread, NULL) != 0) | ||||
err(-1, "thread_juggle: pthread_join"); | err(-1, "thread_juggle: pthread_join"); | ||||
timespecsub(&tfinish, &tstart); | timespecsub(&tfinish, &tstart, &tfinish); | ||||
return (tfinish); | return (tfinish); | ||||
} | } | ||||
/* | /* | ||||
* Juggle messages between two file descriptors in two processes, so measure | * Juggle messages between two file descriptors in two processes, so measure | ||||
* the cost of IPC and the cost of a process context switch. | * the cost of IPC and the cost of a process context switch. | ||||
* | * | ||||
▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | process_juggle(int fd1, int fd2, int pipeline) | ||||
} | } | ||||
wpid = waitpid(pid, NULL, 0); | wpid = waitpid(pid, NULL, 0); | ||||
if (wpid < 0) | if (wpid < 0) | ||||
err(-1, "process_juggle: waitpid"); | err(-1, "process_juggle: waitpid"); | ||||
if (wpid != pid) | if (wpid != pid) | ||||
errx(-1, "process_juggle: waitpid: pid != wpid"); | errx(-1, "process_juggle: waitpid: pid != wpid"); | ||||
timespecsub(&tfinish, &tstart); | timespecsub(&tfinish, &tstart, &tfinish); | ||||
return (tfinish); | return (tfinish); | ||||
} | } | ||||
/* | /* | ||||
* When we print out results for larger pipeline sizes, we scale back by the | * When we print out results for larger pipeline sizes, we scale back by the | ||||
* depth of the pipeline. This generally means dividing by the pipeline | * depth of the pipeline. This generally means dividing by the pipeline | ||||
* depth. Except when it means dividing by zero. | * depth. Except when it means dividing by zero. | ||||
▲ Show 20 Lines • Show All 123 Lines • Show Last 20 Lines |