diff --git a/tools/xudpperf.c b/tools/xudpperf.c index 3c0fba13e2a28c2b54089e7087201e927042e0f8..e232eac45f23d7f984a71c7a67014ebe6964eb61 100644 --- a/tools/xudpperf.c +++ b/tools/xudpperf.c @@ -229,6 +229,26 @@ static void handler_recv(struct th *th) } } +static void __handler_send_err(int ret) +{ + g_err_send++; + + if (ret == -XUDP_ERR_CQ_NOSPACE) + g_err_cq++; + + if (ret == -XUDP_ERR_TX_NOSPACE) + g_err_tx++; + + if (ret == -XUDP_ERR_PACKET_TOO_BIG) + g_err_inval++; + + if (ret == -XUDP_ERR_COMMIT_AGAIN) + { + g_err_commit += 1; + sent_n += 1; + } +} + static void __handler_echo(xudp_channel *ch) { int n = 1, i, ret, send = 0, err_cq = 0, err_tx = 0, err_inval = 0; @@ -296,9 +316,12 @@ static int send_one_by_one(struct th *th) while (conf.npkt--) { - xudp_send_channel(ch, buf, conf.msglen, (struct sockaddr *)&conf.dst, 0); - xudp_send_channel(ch, buf, conf.msglen, (struct sockaddr *)&conf.dst, 0); - xudp_send_channel(ch, buf, conf.msglen, (struct sockaddr *)&conf.dst, 0); + ret = xudp_send_channel(ch, buf, conf.msglen, (struct sockaddr *)&conf.dst, 0); + if (ret < 0) + { + __handler_send_err(ret); + } + sent_n += 1; xudp_commit_channel(ch); sleep(1); } @@ -459,25 +482,6 @@ static int flood_send(xudp *x) return 0; } -static void __handler_send_err(int ret) -{ - g_err_send++; - - if (ret == -XUDP_ERR_CQ_NOSPACE) - g_err_cq++; - - if (ret == -XUDP_ERR_TX_NOSPACE) - g_err_tx++; - - if (ret == -XUDP_ERR_PACKET_TOO_BIG) - g_err_inval++; - - if (ret == -XUDP_ERR_COMMIT_AGAIN) { - g_err_commit += 1; - sent_n += 1; - } -} - static int ___handler_pp_flood(xudp_channel *ch) { struct timeval *tp, now; @@ -576,7 +580,11 @@ static int __handler_pp(xudp_channel *ch) usec = (now.tv_sec - start.tv_sec) * 1000 * 1000; usec += now.tv_usec - start.tv_usec; - printf("pp avg usec: %ld\n", usec / num); + if (num != 0){ + printf("pp avg usec: %ld\n", usec / num); + }else { + printf("pp avg usec: 0\n"); + } return 0; } @@ -616,7 +624,7 @@ static void handler_send(struct th *th) { if (-1 != conf.npkt) { send_one_by_one(th); - return; + exit(0); } __handler_send(th); } @@ -726,10 +734,12 @@ static void parse_argv(int argc, char **argv) } if (0 == strcmp(k, "pp")) { conf.work_mode = WORK_MODE_PP; + conf.poll = true; continue; } if (0 == strcmp(k, "pp-flood")) { conf.work_mode = WORK_MODE_PP_FLOOD; + conf.poll = true; continue; } printf("Invalid work mode(%s), should be: echo, recv, send, pp.\n", k);