Skip to content

Commit

Permalink
trafgen: inherit netsniff-ng's -H -Q options
Browse files Browse the repository at this point in the history
Also make these options available to trafgen.

Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
  • Loading branch information
borkmann committed Nov 25, 2013
1 parent 6feb596 commit b168f5f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
9 changes: 9 additions & 0 deletions trafgen.8
Expand Up @@ -152,6 +152,15 @@ testing.
.SS -u <uid>, --user <uid> resp. -g <gid>, --group <gid>
After ring setup, drop privileges to a non-root user/group combination.
.PP
.SS -H, --prio-high
Set this process as a high priority process in order to achieve a higher
scheduling rate resp. CPU time. This is however not the default setting, since
it could lead to starvation of other processes, for example low priority kernel
threads.
.PP
.SS -Q, --notouch-irq
Do not reassign the NIC's IRQ CPU affinity settings.
.PP
.SS -V, --verbose
Let trafgen be more talkative and let it print the parsed configuration and
some ring buffer statistics.
Expand Down
24 changes: 21 additions & 3 deletions trafgen.c
Expand Up @@ -80,7 +80,7 @@ size_t plen = 0;
struct packet_dyn *packet_dyn = NULL;
size_t dlen = 0;

static const char *short_options = "d:c:n:t:vJhS:rk:i:o:VRs:P:eE:pu:g:C";
static const char *short_options = "d:c:n:t:vJhS:rk:i:o:VRs:P:eE:pu:g:CHQ";
static const struct option long_options[] = {
{"dev", required_argument, NULL, 'd'},
{"out", required_argument, NULL, 'o'},
Expand All @@ -95,6 +95,8 @@ static const struct option long_options[] = {
{"seed", required_argument, NULL, 'E'},
{"user", required_argument, NULL, 'u'},
{"group", required_argument, NULL, 'g'},
{"prio-high", no_argument, NULL, 'H'},
{"notouch-irq", no_argument, NULL, 'Q'},
{"jumbo-support", no_argument, NULL, 'J'},
{"no-cpu-stats", no_argument, NULL, 'C'},
{"cpp", no_argument, NULL, 'p'},
Expand Down Expand Up @@ -189,6 +191,8 @@ static void __noreturn help(void)
" -E|--seed <uint> Manually set srand(3) seed\n"
" -u|--user <userid> Drop privileges and change to userid\n"
" -g|--group <groupid> Drop privileges and change to groupid\n"
" -H|--prio-high Make this high priority process\n"
" -Q|--notouch-irq Do not touch IRQ CPU affinity of NIC\n"
" -V|--verbose Be more verbose\n"
" -C|--no-cpu-stats Do not print CPU time statistics on exit\n"
" -v|--version Show version and exit\n"
Expand Down Expand Up @@ -880,6 +884,7 @@ static unsigned int generate_srand_seed(void)
int main(int argc, char **argv)
{
bool slow = false, invoke_cpp = false, reseed = true, cpustats = true;
bool prio_high = false, set_irq_aff = true;
int c, opt_index, vals[4] = {0}, irq;
uint64_t gap = 0;
unsigned int i, j;
Expand Down Expand Up @@ -923,6 +928,12 @@ int main(int argc, char **argv)
case 'o':
ctx.device = xstrndup(optarg, IFNAMSIZ);
break;
case 'H':
prio_high = true;
break;
case 'Q':
set_irq_aff = false;
break;
case 'r':
ctx.rand = true;
break;
Expand Down Expand Up @@ -1060,6 +1071,11 @@ int main(int argc, char **argv)
register_signal(SIGHUP, signal_handler);
register_signal_f(SIGALRM, timer_elapsed, SA_SIGINFO);

if (prio_high) {
set_proc_prio(-20);
set_sched_status(SCHED_FIFO, sched_get_priority_max(SCHED_FIFO));
}

set_system_socket_memory(vals, array_size(vals));
xlockme();

Expand All @@ -1072,7 +1088,8 @@ int main(int argc, char **argv)
}

irq = device_irq_number(ctx.device);
device_set_irq_affinity_list(irq, 0, ctx.cpus - 1);
if (set_irq_aff)
device_set_irq_affinity_list(irq, 0, ctx.cpus - 1);

stats = setup_shared_var(ctx.cpus);

Expand Down Expand Up @@ -1128,7 +1145,8 @@ int main(int argc, char **argv)
thread_out:
xunlockme();
destroy_shared_var(stats, ctx.cpus);
device_restore_irq_affinity_list();
if (set_irq_aff)
device_restore_irq_affinity_list();

free(ctx.device);
free(ctx.device_trans);
Expand Down
2 changes: 2 additions & 0 deletions trafgen.zsh
Expand Up @@ -48,6 +48,8 @@ _arguments -s -S \
"(-E --seed)"{-E,--seed}"[Manually set srand(3) seed]" \
"(-u --user)"{-u,--user}"[Drop privileges and change to userid]:user:_user_info" \
"(-g --group)"{-g,--group}"[Drop privileges and change to groupid]:group:_group_info" \
"(-H --prio-high)"{-H,--prio-high}"[Make this high priority process]" \
"(-Q --notouch-irq)"{-Q,--notouch-irq}"[Do not touch IRQ CPU affinity of NIC]" \
"(-e --example)"{-e,--example}"[Show built-in packet config example]:" \
"(-V --verbose)"{-V,--verbose}"[Be more verbose]" \
"(-C --no-cpu-stats)"{-C,--no-cpu-stats}"[Do not print CPU time statistics on exit]" \
Expand Down

0 comments on commit b168f5f

Please sign in to comment.