9 #include <linux/module.h>
10 #include <linux/time.h>
11 #include <asm/local.h>
24 static int wakeup_interval = 100;
26 static int reader_finish;
33 static unsigned long read;
35 static int disable_reader;
39 static int write_iteration = 50;
43 static int producer_nice = 19;
44 static int consumer_nice = 19;
46 static int producer_fifo = -1;
47 static int consumer_fifo = -1;
61 static int read_events;
118 for (i = 0; i < commit && !kill_test; i +=
inc) {
126 event = (
void *)&rpage->
data[i];
132 inc =
event->array[0] + 4;
144 if (!event->
array[0]) {
148 inc =
event->array[0] + 4;
157 inc = ((
event->type_len + 1) * 4);
175 static void ring_buffer_consumer(
void)
181 while (!reader_finish && !kill_test) {
194 stat = read_page(cpu);
201 }
while (found && !kill_test);
214 static void ring_buffer_producer(
void)
218 unsigned long long time;
220 unsigned long long overruns;
221 unsigned long missed = 0;
222 unsigned long hit = 0;
230 trace_printk(
"Starting ring buffer hammer\n");
237 for (i = 0; i < write_iteration; i++) {
251 if (consumer && !(cnt % wakeup_interval))
254 #ifndef CONFIG_PREEMPT
264 if (cnt % wakeup_interval)
268 }
while (end_tv.tv_sec < (start_tv.tv_sec +
RUN_TIME) && !kill_test);
269 trace_printk(
"End ring buffer hammer\n");
273 init_completion(&read_start);
284 time = end_tv.tv_sec - start_tv.tv_sec;
286 time += (
long long)((
long)end_tv.tv_usec - (
long)start_tv.tv_usec);
292 trace_printk(
"ERROR!\n");
294 if (!disable_reader) {
295 if (consumer_fifo < 0)
296 trace_printk(
"Running Consumer at nice: %d\n",
299 trace_printk(
"Running Consumer at SCHED_FIFO %d\n",
302 if (producer_fifo < 0)
303 trace_printk(
"Running Producer at nice: %d\n",
306 trace_printk(
"Running Producer at SCHED_FIFO %d\n",
310 if (producer_fifo < 0 && consumer_fifo < 0 &&
311 producer_nice == 19 && consumer_nice == 19)
312 trace_printk(
"WARNING!!! This test is running at lowest priority.\n");
314 trace_printk(
"Time: %lld (usecs)\n", time);
315 trace_printk(
"Overruns: %lld\n", overruns);
317 trace_printk(
"Read: (reader disabled)\n");
319 trace_printk(
"Read: %ld (by %s)\n",
read,
320 read_events ?
"events" :
"pages");
321 trace_printk(
"Entries: %lld\n", entries);
322 trace_printk(
"Total: %lld\n", entries + overruns +
read);
323 trace_printk(
"Missed: %ld\n", missed);
324 trace_printk(
"Hit: %ld\n", hit);
331 trace_printk(
"TIME IS ZERO??\n");
333 trace_printk(
"Entries per millisec: %ld\n", hit);
338 trace_printk(
"%ld ns per entry\n", avg);
343 missed /= (
long)time;
345 trace_printk(
"Total iterations per millisec: %ld\n",
349 if (!(hit + missed)) {
350 trace_printk(
"hit + missed overflowed and totalled zero!\n");
356 trace_printk(
"%ld ns per entry\n", avg);
360 static void wait_to_die(
void)
370 static int ring_buffer_consumer_thread(
void *
arg)
375 ring_buffer_consumer();
392 static int ring_buffer_producer_thread(
void *arg)
394 init_completion(&read_start);
405 ring_buffer_producer();
407 trace_printk(
"Sleeping for 10 secs\n");
419 static int __init ring_buffer_benchmark_init(
void)
428 if (!disable_reader) {
430 NULL,
"rb_consumer");
431 ret = PTR_ERR(consumer);
432 if (IS_ERR(consumer))
436 producer =
kthread_run(ring_buffer_producer_thread,
437 NULL,
"rb_producer");
438 ret = PTR_ERR(producer);
440 if (IS_ERR(producer))
446 if (!disable_reader) {
447 if (consumer_fifo >= 0) {
449 .sched_priority = consumer_fifo
456 if (producer_fifo >= 0) {
458 .sched_priority = consumer_fifo
475 static void __exit ring_buffer_benchmark_exit(
void)