tracing: Have stack_tracer use a separate list of functions
[linux-2.6.git] / kernel / trace / ring_buffer_benchmark.c
index cf6b0f5..a5457d5 100644 (file)
@@ -8,6 +8,7 @@
 #include <linux/kthread.h>
 #include <linux/module.h>
 #include <linux/time.h>
+#include <asm/local.h>
 
 struct rb_page {
        u64             ts;
@@ -35,6 +36,28 @@ static int disable_reader;
 module_param(disable_reader, uint, 0644);
 MODULE_PARM_DESC(disable_reader, "only run producer");
 
+static int write_iteration = 50;
+module_param(write_iteration, uint, 0644);
+MODULE_PARM_DESC(write_iteration, "# of writes between timestamp readings");
+
+static int producer_nice = 19;
+static int consumer_nice = 19;
+
+static int producer_fifo = -1;
+static int consumer_fifo = -1;
+
+module_param(producer_nice, uint, 0644);
+MODULE_PARM_DESC(producer_nice, "nice prio for producer");
+
+module_param(consumer_nice, uint, 0644);
+MODULE_PARM_DESC(consumer_nice, "nice prio for consumer");
+
+module_param(producer_fifo, uint, 0644);
+MODULE_PARM_DESC(producer_fifo, "fifo prio for producer");
+
+module_param(consumer_fifo, uint, 0644);
+MODULE_PARM_DESC(consumer_fifo, "fifo prio for consumer");
+
 static int read_events;
 
 static int kill_test;
@@ -58,7 +81,7 @@ static enum event_status read_event(int cpu)
        int *entry;
        u64 ts;
 
-       event = ring_buffer_consume(buffer, cpu, &ts);
+       event = ring_buffer_consume(buffer, cpu, &ts, NULL);
        if (!event)
                return EVENT_DROPPED;
 
@@ -83,14 +106,15 @@ static enum event_status read_page(int cpu)
        int inc;
        int i;
 
-       bpage = ring_buffer_alloc_read_page(buffer);
+       bpage = ring_buffer_alloc_read_page(buffer, cpu);
        if (!bpage)
                return EVENT_DROPPED;
 
        ret = ring_buffer_read_page(buffer, &bpage, PAGE_SIZE, cpu, 1);
        if (ret >= 0) {
                rpage = bpage;
-               commit = local_read(&rpage->commit);
+               /* The commit may have missed event flags set, clear them */
+               commit = local_read(&rpage->commit) & 0xfffff;
                for (i = 0; i < commit && !kill_test; i += inc) {
 
                        if (i >= (PAGE_SIZE - offsetof(struct rb_page, data))) {
@@ -203,20 +227,23 @@ static void ring_buffer_producer(void)
         * Hammer the buffer for 10 secs (this may
         * make the system stall)
         */
-       pr_info("Starting ring buffer hammer\n");
+       trace_printk("Starting ring buffer hammer\n");
        do_gettimeofday(&start_tv);
        do {
                struct ring_buffer_event *event;
                int *entry;
-
-               event = ring_buffer_lock_reserve(buffer, 10);
-               if (!event) {
-                       missed++;
-               } else {
-                       hit++;
-                       entry = ring_buffer_event_data(event);
-                       *entry = smp_processor_id();
-                       ring_buffer_unlock_commit(buffer, event);
+               int i;
+
+               for (i = 0; i < write_iteration; i++) {
+                       event = ring_buffer_lock_reserve(buffer, 10);
+                       if (!event) {
+                               missed++;
+                       } else {
+                               hit++;
+                               entry = ring_buffer_event_data(event);
+                               *entry = smp_processor_id();
+                               ring_buffer_unlock_commit(buffer, event);
+                       }
                }
                do_gettimeofday(&end_tv);
 
@@ -239,7 +266,7 @@ static void ring_buffer_producer(void)
 #endif
 
        } while (end_tv.tv_sec < (start_tv.tv_sec + RUN_TIME) && !kill_test);
-       pr_info("End ring buffer hammer\n");
+       trace_printk("End ring buffer hammer\n");
 
        if (consumer) {
                /* Init both completions here to avoid races */
@@ -262,49 +289,71 @@ static void ring_buffer_producer(void)
        overruns = ring_buffer_overruns(buffer);
 
        if (kill_test)
-               pr_info("ERROR!\n");
-       pr_info("Time:     %lld (usecs)\n", time);
-       pr_info("Overruns: %lld\n", overruns);
+               trace_printk("ERROR!\n");
+
+       if (!disable_reader) {
+               if (consumer_fifo < 0)
+                       trace_printk("Running Consumer at nice: %d\n",
+                                    consumer_nice);
+               else
+                       trace_printk("Running Consumer at SCHED_FIFO %d\n",
+                                    consumer_fifo);
+       }
+       if (producer_fifo < 0)
+               trace_printk("Running Producer at nice: %d\n",
+                            producer_nice);
+       else
+               trace_printk("Running Producer at SCHED_FIFO %d\n",
+                            producer_fifo);
+
+       /* Let the user know that the test is running at low priority */
+       if (producer_fifo < 0 && consumer_fifo < 0 &&
+           producer_nice == 19 && consumer_nice == 19)
+               trace_printk("WARNING!!! This test is running at lowest priority.\n");
+
+       trace_printk("Time:     %lld (usecs)\n", time);
+       trace_printk("Overruns: %lld\n", overruns);
        if (disable_reader)
-               pr_info("Read:     (reader disabled)\n");
+               trace_printk("Read:     (reader disabled)\n");
        else
-               pr_info("Read:     %ld  (by %s)\n", read,
+               trace_printk("Read:     %ld  (by %s)\n", read,
                        read_events ? "events" : "pages");
-       pr_info("Entries:  %lld\n", entries);
-       pr_info("Total:    %lld\n", entries + overruns + read);
-       pr_info("Missed:   %ld\n", missed);
-       pr_info("Hit:      %ld\n", hit);
+       trace_printk("Entries:  %lld\n", entries);
+       trace_printk("Total:    %lld\n", entries + overruns + read);
+       trace_printk("Missed:   %ld\n", missed);
+       trace_printk("Hit:      %ld\n", hit);
 
        /* Convert time from usecs to millisecs */
        do_div(time, USEC_PER_MSEC);
        if (time)
                hit /= (long)time;
        else
-               pr_info("TIME IS ZERO??\n");
+               trace_printk("TIME IS ZERO??\n");
 
-       pr_info("Entries per millisec: %ld\n", hit);
+       trace_printk("Entries per millisec: %ld\n", hit);
 
        if (hit) {
                /* Calculate the average time in nanosecs */
                avg = NSEC_PER_MSEC / hit;
-               pr_info("%ld ns per entry\n", avg);
+               trace_printk("%ld ns per entry\n", avg);
        }
 
        if (missed) {
                if (time)
                        missed /= (long)time;
 
-               pr_info("Total iterations per millisec: %ld\n", hit + missed);
+               trace_printk("Total iterations per millisec: %ld\n",
+                            hit + missed);
 
                /* it is possible that hit + missed will overflow and be zero */
                if (!(hit + missed)) {
-                       pr_info("hit + missed overflowed and totalled zero!\n");
+                       trace_printk("hit + missed overflowed and totalled zero!\n");
                        hit--; /* make it non zero */
                }
 
                /* Caculate the average time in nanosecs */
                avg = NSEC_PER_MSEC / (hit + missed);
-               pr_info("%ld ns per entry\n", avg);
+               trace_printk("%ld ns per entry\n", avg);
        }
 }
 
@@ -355,7 +404,7 @@ static int ring_buffer_producer_thread(void *arg)
 
                ring_buffer_producer();
 
-               pr_info("Sleeping for 10 secs\n");
+               trace_printk("Sleeping for 10 secs\n");
                set_current_state(TASK_INTERRUPTIBLE);
                schedule_timeout(HZ * SLEEP_TIME);
                __set_current_state(TASK_RUNNING);
@@ -391,6 +440,27 @@ static int __init ring_buffer_benchmark_init(void)
        if (IS_ERR(producer))
                goto out_kill;
 
+       /*
+        * Run them as low-prio background tasks by default:
+        */
+       if (!disable_reader) {
+               if (consumer_fifo >= 0) {
+                       struct sched_param param = {
+                               .sched_priority = consumer_fifo
+                       };
+                       sched_setscheduler(consumer, SCHED_FIFO, &param);
+               } else
+                       set_user_nice(consumer, consumer_nice);
+       }
+
+       if (producer_fifo >= 0) {
+               struct sched_param param = {
+                       .sched_priority = consumer_fifo
+               };
+               sched_setscheduler(producer, SCHED_FIFO, &param);
+       } else
+               set_user_nice(producer, producer_nice);
+
        return 0;
 
  out_kill: