From 721fb0de29e78a1cfd5d759758c69830333d7699 Mon Sep 17 00:00:00 2001 From: Daniel Borkmann Date: Sat, 15 Jun 2013 13:14:26 +0200 Subject: trafgen: fix -n1 bug for packet scheduling In the current situation, it can happen when we set -n1, that no packet at all will be scheduled. This is due to the case that nearbyint() will for e.g. 2 cpus round to 0 each, and since in __correct_global_delta() we only correct a total delta when a particular CPU is allowed to tx packets (means already has a num > 0), then we correct the delta on the first such CPU. Switch to using round(), so that on 0.5 it will be round to the next higher int, and fix the check to >= 0 in __correct_global_delta() so that a CPU could also get a 0 share of packets. I did a couple of tests with different -n params and cpu(..) configs and this seems to fix that. Signed-off-by: Daniel Borkmann --- trafgen.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/trafgen.c b/trafgen.c index 2d99a4b..3b2f471 100644 --- a/trafgen.c +++ b/trafgen.c @@ -757,7 +757,7 @@ static void __correct_global_delta(struct ctx *ctx, int cpu, unsigned long orig) for (cpu_sel = -1, i = 0; i < ctx->cpus; i++) { if (stats[i].cd_packets > 0) { if ((long long) stats[i].cd_packets + - delta_correction > 0) { + delta_correction >= 0) { cpu_sel = i; break; } @@ -797,7 +797,7 @@ static int xmit_packet_precheck(struct ctx *ctx, int cpu) plen_total = __wait_and_sum_others(ctx, cpu); if (orig > 0) { - ctx->num = (unsigned long) nearbyint((1.0 * plen / plen_total) * orig); + ctx->num = (unsigned long) round((1.0 * plen / plen_total) * orig); __set_state_cd(cpu, ctx->num, CPU_STATS_STATE_CHK | CPU_STATS_STATE_CFG); -- cgit v1.2.3-54-g00ecf