From 48097ae5585c856ce676baa006dd018f86eda565 Mon Sep 17 00:00:00 2001 From: Vadim Kochan Date: Tue, 31 Mar 2015 12:29:58 +0300 Subject: trafgen: Alloc cpus according to specified number of packets Trafgen uses all the online CPUs even if the number of packets specified by -n is less than the number of selected CPUs. Such behaviour leads to issues: - trafgen re-calculates number of packets per CPU which leads to rounding it to 0 then no packets will be sent. - trafgen might send more packets than specified by -n because of using all the online cpus. Fixed by taking min(#CPUs, #packets) as the number of CPUs if a number of packets is specified by -n. Signed-off-by: Vadim Kochan [tklauser: moved code and added explanatory comment] Signed-off-by: Tobias Klauser --- trafgen.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'trafgen.c') diff --git a/trafgen.c b/trafgen.c index 22264cb..deef1f2 100644 --- a/trafgen.c +++ b/trafgen.c @@ -1070,6 +1070,14 @@ int main(int argc, char **argv) sleep(0); } + /* + * If number of packets is smaller than number of CPUs use only as + * many CPUs as there are packets. Otherwise we end up sending more + * packets than intended or none at all. + */ + if (ctx.num) + ctx.cpus = min_t(unsigned int, ctx.num, ctx.cpus); + irq = device_irq_number(ctx.device); if (set_irq_aff) device_set_irq_affinity_list(irq, 0, ctx.cpus - 1); -- cgit v1.2.3-54-g00ecf