summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2015-11-02 16:33:54 +0100
committerTobias Klauser <tklauser@distanz.ch>2015-11-02 16:33:54 +0100
commitb5d757ae6de3b28f326644c63f7e2b9df4109764 (patch)
tree82db80b1e06ae1a25784d39b107bfcbea677e442
parentdddf36f0b747dde13fe6af4d368c927c8d1c76c9 (diff)
trafgen: Pre-calculate checksums if possible
The TCP/UDP checksums cannot be calculated in the parser as the packet payload following the TCP/UDP header is not yet know. However, we can calculate these checksums before the send loop if the only dynamic elements of the packet are checksums. This change avoids the overhead of recalculating the checksums for every iteration the send loop in these cases. Suggested-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
-rw-r--r--trafgen.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/trafgen.c b/trafgen.c
index c35182e..8752255 100644
--- a/trafgen.c
+++ b/trafgen.c
@@ -366,6 +366,21 @@ static void apply_csum16(int id)
}
}
+static void preprocess_packets(void)
+{
+ size_t i;
+
+ for (i = 0; i < plen; i++) {
+ struct packet_dyn *pktd = &packet_dyn[i];
+
+ if (packet_dyn_has_only_csums(pktd)) {
+ apply_csum16(i);
+ pktd->slen = 0;
+ xfree(pktd->csum);
+ }
+ }
+}
+
static struct cpu_stats *setup_shared_var(unsigned int cpus)
{
int fd;
@@ -539,6 +554,8 @@ static void xmit_slowpath_or_die(struct ctx *ctx, unsigned int cpu, unsigned lon
drop_privileges(ctx->enforce, ctx->uid, ctx->gid);
+ preprocess_packets();
+
bug_on(gettimeofday(&start, NULL));
while (likely(sigint == 0 && num > 0 && plen > 0)) {
@@ -628,6 +645,8 @@ static void xmit_fastpath_or_die(struct ctx *ctx, unsigned int cpu, unsigned lon
if (ctx->num == 0 && orig_num > 0)
num = 0;
+ preprocess_packets();
+
bug_on(gettimeofday(&start, NULL));
while (likely(sigint == 0 && num > 0 && plen > 0)) {