summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Borkmann <dborkman@redhat.com>2013-09-12 18:50:16 +0200
committerDaniel Borkmann <dborkman@redhat.com>2013-09-23 15:41:55 +0200
commit408e36cf6e12d34d67bf2c1694428533060f9b14 (patch)
treeede780d9b7fcf51419def09e85cc6a3a82a01d73
parent3726c9e5c593c49f67249bf77c551d371c600a21 (diff)
trafgen: remove inner loop
Get rid of inner loop in fast path. This simplifies code and readability. Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
-rw-r--r--trafgen.c62
1 files changed, 31 insertions, 31 deletions
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));