Skip to content

Commit

Permalink
ring-buffer: change test to be more latency friendly
Browse files Browse the repository at this point in the history
The ring buffer benchmark/test runs a producer for 10 seconds.
This is done with preemption and interrupts enabled. But if the kernel
is not compiled with CONFIG_PREEMPT, it basically stops everything
but interrupts for 10 seconds.

Although this is just a test and is not for production, this attribute
can be quite annoying. It can also spawn badness elsewhere.

This patch solves the issues by calling "cond_resched" when the system
is not compiled with CONFIG_PREEMPT. It also keeps track of the time
spent to call cond_resched such that it does not go against the
time calculations. That is, if the task schedules away, the time scheduled
out is removed from the test data. Note, this only works for non PREEMPT
because we do not know when the task is scheduled out if we have PREEMPT
enabled.

[ Impact: prevent test from stopping the world for 10 seconds ]

Signed-off-by: Steven Rostedt <[email protected]>
  • Loading branch information
Steven Rostedt authored and rostedt committed May 6, 2009
1 parent 6634ff2 commit 3e07a4f
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions kernel/trace/ring_buffer_benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,35 @@ static void ring_buffer_consumer(void)
complete(&read_done);
}

/*
* If we are a non preempt kernel, the 10 second run will
* stop everything while it runs. Instead, we will call cond_resched
* and also add any time that was lost by a rescedule.
*/
#ifdef CONFIG_PREEMPT
static void sched_if_needed(struct timeval *start_tv, struct timeval *end_tv)
{
}
#else
static void sched_if_needed(struct timeval *start_tv, struct timeval *end_tv)
{
struct timeval tv;

cond_resched();
do_gettimeofday(&tv);
if (tv.tv_usec < end_tv->tv_usec) {
tv.tv_usec += 1000000;
tv.tv_sec--;
}
start_tv->tv_sec += tv.tv_sec - end_tv->tv_sec;
start_tv->tv_usec += tv.tv_usec - end_tv->tv_usec;
if (start_tv->tv_usec > 1000000) {
start_tv->tv_usec -= 1000000;
start_tv->tv_sec++;
}
}
#endif

static void ring_buffer_producer(void)
{
struct timeval start_tv;
Expand Down Expand Up @@ -221,6 +250,8 @@ static void ring_buffer_producer(void)
if (consumer && !(++cnt % wakeup_interval))
wake_up_process(consumer);

sched_if_needed(&start_tv, &end_tv);

} while (end_tv.tv_sec < (start_tv.tv_sec + RUN_TIME) && !kill_test);
pr_info("End ring buffer hammer\n");

Expand Down

0 comments on commit 3e07a4f

Please sign in to comment.