Skip to content

Commit

Permalink
pktgen: avoid expensive set_current_state() call in loop
Browse files Browse the repository at this point in the history
Avoid calling set_current_state() inside the busy-loop in
pktgen_thread_worker().  In case of pkt_dev->delay, then it is still
used/enabled in pktgen_xmit() via the spin() call.

The set_current_state(TASK_INTERRUPTIBLE) uses a xchg, which implicit
is LOCK prefixed.  I've measured the asm LOCK operation to take approx
8ns on this E5-2630 CPU.  Performance increase corrolate with this
measurement.

Performance data with CLONE_SKB==100000, rx-usecs=30:
 (single CPU performance, ixgbe 10Gbit/s, E5-2630)
 * Prev:  5454050 pps --> 183.35ns (1/5454050*10^9)
 * Now:   5684009 pps --> 175.93ns (1/5684009*10^9)
 * Diff:  +229959 pps -->  -7.42ns

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Jesper Dangaard Brouer authored and David S. Miller committed Jul 1, 2014
1 parent 9ceb87f commit baac167
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions net/core/pktgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -3407,10 +3407,10 @@ static int pktgen_thread_worker(void *arg)

pr_debug("starting pktgen/%d: pid=%d\n", cpu, task_pid_nr(current));

set_current_state(TASK_INTERRUPTIBLE);

set_freezable();

__set_current_state(TASK_RUNNING);

while (!kthread_should_stop()) {
pkt_dev = next_to_run(t);

Expand All @@ -3424,8 +3424,6 @@ static int pktgen_thread_worker(void *arg)
continue;
}

__set_current_state(TASK_RUNNING);

if (likely(pkt_dev)) {
pktgen_xmit(pkt_dev);

Expand Down Expand Up @@ -3456,9 +3454,8 @@ static int pktgen_thread_worker(void *arg)
}

try_to_freeze();

set_current_state(TASK_INTERRUPTIBLE);
}
set_current_state(TASK_INTERRUPTIBLE);

pr_debug("%s stopping all device\n", t->tsk->comm);
pktgen_stop(t);
Expand Down

0 comments on commit baac167

Please sign in to comment.