diff options
| author | John Fastabend <john.fastabend@gmail.com> | 2018-01-22 13:36:36 -0500 |
|---|---|---|
| committer | Daniel Borkmann <daniel@iogearbox.net> | 2018-01-24 04:46:59 -0500 |
| commit | ce5373be1aeac7889eb31f4bcf2b1dc2ad3c263c (patch) | |
| tree | 53e9a024335ad18357568bbc0788015d49b1902d /samples | |
| parent | 66fdd1a3cdf9bcee9790bc6b6322f0cafaf0d3f2 (diff) | |
bpf: sockmap sample add base test without any BPF for comparison
Add a base test that does not use BPF hooks to test baseline case.
Signed-off-by: John Fastabend <john.fastabend@gmail.com>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'samples')
| -rw-r--r-- | samples/sockmap/sockmap_user.c | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/samples/sockmap/sockmap_user.c b/samples/sockmap/sockmap_user.c index 661ea7e4a350..f9d3785fb183 100644 --- a/samples/sockmap/sockmap_user.c +++ b/samples/sockmap/sockmap_user.c | |||
| @@ -298,18 +298,24 @@ static inline float recvdBps(struct msg_stats s) | |||
| 298 | return s.bytes_recvd / (s.end.tv_sec - s.start.tv_sec); | 298 | return s.bytes_recvd / (s.end.tv_sec - s.start.tv_sec); |
| 299 | } | 299 | } |
| 300 | 300 | ||
| 301 | static int sendmsg_test(int iov_count, int iov_buf, int cnt, int verbose) | 301 | static int sendmsg_test(int iov_count, int iov_buf, int cnt, |
| 302 | int verbose, bool base) | ||
| 302 | { | 303 | { |
| 303 | int txpid, rxpid, err = 0; | 304 | float sent_Bps = 0, recvd_Bps = 0; |
| 305 | int rx_fd, txpid, rxpid, err = 0; | ||
| 304 | struct msg_stats s = {0}; | 306 | struct msg_stats s = {0}; |
| 305 | int status; | 307 | int status; |
| 306 | float sent_Bps = 0, recvd_Bps = 0; | ||
| 307 | 308 | ||
| 308 | errno = 0; | 309 | errno = 0; |
| 309 | 310 | ||
| 311 | if (base) | ||
| 312 | rx_fd = p1; | ||
| 313 | else | ||
| 314 | rx_fd = p2; | ||
| 315 | |||
| 310 | rxpid = fork(); | 316 | rxpid = fork(); |
| 311 | if (rxpid == 0) { | 317 | if (rxpid == 0) { |
| 312 | err = msg_loop(p2, iov_count, iov_buf, cnt, &s, false); | 318 | err = msg_loop(rx_fd, iov_count, iov_buf, cnt, &s, false); |
| 313 | if (err) | 319 | if (err) |
| 314 | fprintf(stderr, | 320 | fprintf(stderr, |
| 315 | "msg_loop_rx: iov_count %i iov_buf %i cnt %i err %i\n", | 321 | "msg_loop_rx: iov_count %i iov_buf %i cnt %i err %i\n", |
| @@ -435,6 +441,7 @@ static int forever_ping_pong(int rate, int verbose) | |||
| 435 | enum { | 441 | enum { |
| 436 | PING_PONG, | 442 | PING_PONG, |
| 437 | SENDMSG, | 443 | SENDMSG, |
| 444 | BASE, | ||
| 438 | }; | 445 | }; |
| 439 | 446 | ||
| 440 | int main(int argc, char **argv) | 447 | int main(int argc, char **argv) |
| @@ -474,6 +481,8 @@ int main(int argc, char **argv) | |||
| 474 | test = PING_PONG; | 481 | test = PING_PONG; |
| 475 | } else if (strcmp(optarg, "sendmsg") == 0) { | 482 | } else if (strcmp(optarg, "sendmsg") == 0) { |
| 476 | test = SENDMSG; | 483 | test = SENDMSG; |
| 484 | } else if (strcmp(optarg, "base") == 0) { | ||
| 485 | test = BASE; | ||
| 477 | } else { | 486 | } else { |
| 478 | usage(argv); | 487 | usage(argv); |
| 479 | return -1; | 488 | return -1; |
| @@ -499,6 +508,10 @@ int main(int argc, char **argv) | |||
| 499 | /* catch SIGINT */ | 508 | /* catch SIGINT */ |
| 500 | signal(SIGINT, running_handler); | 509 | signal(SIGINT, running_handler); |
| 501 | 510 | ||
| 511 | /* If base test skip BPF setup */ | ||
| 512 | if (test == BASE) | ||
| 513 | goto run; | ||
| 514 | |||
| 502 | if (load_bpf_file(filename)) { | 515 | if (load_bpf_file(filename)) { |
| 503 | fprintf(stderr, "load_bpf_file: (%s) %s\n", | 516 | fprintf(stderr, "load_bpf_file: (%s) %s\n", |
| 504 | filename, strerror(errno)); | 517 | filename, strerror(errno)); |
| @@ -530,6 +543,7 @@ int main(int argc, char **argv) | |||
| 530 | return err; | 543 | return err; |
| 531 | } | 544 | } |
| 532 | 545 | ||
| 546 | run: | ||
| 533 | err = sockmap_init_sockets(); | 547 | err = sockmap_init_sockets(); |
| 534 | if (err) { | 548 | if (err) { |
| 535 | fprintf(stderr, "ERROR: test socket failed: %d\n", err); | 549 | fprintf(stderr, "ERROR: test socket failed: %d\n", err); |
| @@ -539,7 +553,9 @@ int main(int argc, char **argv) | |||
| 539 | if (test == PING_PONG) | 553 | if (test == PING_PONG) |
| 540 | err = forever_ping_pong(rate, verbose); | 554 | err = forever_ping_pong(rate, verbose); |
| 541 | else if (test == SENDMSG) | 555 | else if (test == SENDMSG) |
| 542 | err = sendmsg_test(iov_count, length, rate, verbose); | 556 | err = sendmsg_test(iov_count, length, rate, verbose, false); |
| 557 | else if (test == BASE) | ||
| 558 | err = sendmsg_test(iov_count, length, rate, verbose, true); | ||
| 543 | else | 559 | else |
| 544 | fprintf(stderr, "unknown test\n"); | 560 | fprintf(stderr, "unknown test\n"); |
| 545 | out: | 561 | out: |
