From 408e36cf6e12d34d67bf2c1694428533060f9b14 Mon Sep 17 00:00:00 2001 From: Daniel Borkmann Date: Thu, 12 Sep 2013 18:50:16 +0200 Subject: trafgen: remove inner loop Get rid of inner loop in fast path. This simplifies code and readability. Signed-off-by: Daniel Borkmann --- trafgen.c | 62 +++++++++++++++++++++++++++++++------------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) (limited to 'trafgen.c') diff --git a/trafgen.c b/trafgen.c index 5150a91..cb8cb52 100644 --- a/trafgen.c +++ b/trafgen.c @@ -650,44 +650,44 @@ static void xmit_fastpath_or_die(struct ctx *ctx, int cpu, unsigned long orig_nu bug_on(gettimeofday(&start, NULL)); while (likely(sigint == 0 && num > 0 && plen > 0)) { - while (user_may_pull_from_tx(tx_ring.frames[it].iov_base) && likely(num > 0)) { - hdr = tx_ring.frames[it].iov_base; - out = ((uint8_t *) hdr) + TPACKET2_HDRLEN - sizeof(struct sockaddr_ll); - - hdr->tp_h.tp_snaplen = packets[i].len; - hdr->tp_h.tp_len = packets[i].len; - - pktd = &packet_dyn[i]; - if (pktd->clen + pktd->rlen + pktd->slen) { - apply_counter(i); - apply_randomizer(i); - apply_csum16(i); - } + if (!user_may_pull_from_tx(tx_ring.frames[it].iov_base)) { + sched_yield(); + continue; + } + + hdr = tx_ring.frames[it].iov_base; + out = ((uint8_t *) hdr) + TPACKET2_HDRLEN - sizeof(struct sockaddr_ll); + + hdr->tp_h.tp_snaplen = packets[i].len; + hdr->tp_h.tp_len = packets[i].len; - fmemcpy(out, packets[i].payload, packets[i].len); + pktd = &packet_dyn[i]; + if (pktd->clen + pktd->rlen + pktd->slen) { + apply_counter(i); + apply_randomizer(i); + apply_csum16(i); + } - tx_bytes += packets[i].len; - tx_packets++; + fmemcpy(out, packets[i].payload, packets[i].len); - if (!ctx->rand) { - i++; - if (i >= plen) - i = 0; - } else - i = rand() % plen; + tx_bytes += packets[i].len; + tx_packets++; - kernel_may_pull_from_tx(&hdr->tp_h); + if (!ctx->rand) { + i++; + if (i >= plen) + i = 0; + } else + i = rand() % plen; - it++; - if (it >= tx_ring.layout.tp_frame_nr) - it = 0; + kernel_may_pull_from_tx(&hdr->tp_h); - if (ctx->num > 0) - num--; + it++; + if (it >= tx_ring.layout.tp_frame_nr) + it = 0; - if (unlikely(sigint == 1)) - break; - } + if (ctx->num > 0) + num--; } bug_on(gettimeofday(&end, NULL)); -- cgit v1.2.3-54-g00ecf