Merge branch 'linus' into cont_syslog
[safe/jmp/linux-2.6] / drivers / oprofile / oprof.c
index 50062ce..b336cd9 100644 (file)
@@ -12,6 +12,8 @@
 #include <linux/init.h>
 #include <linux/oprofile.h>
 #include <linux/moduleparam.h>
+#include <linux/workqueue.h>
+#include <linux/time.h>
 #include <asm/mutex.h>
 
 #include "oprof.h"
@@ -23,7 +25,7 @@
 struct oprofile_operations oprofile_ops;
 
 unsigned long oprofile_started;
-unsigned long backtrace_depth;
+unsigned long oprofile_backtrace_depth;
 static unsigned long is_setup;
 static DEFINE_MUTEX(start_mutex);
 
@@ -87,6 +89,69 @@ out:
        return err;
 }
 
+#ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
+
+static void switch_worker(struct work_struct *work);
+static DECLARE_DELAYED_WORK(switch_work, switch_worker);
+
+static void start_switch_worker(void)
+{
+       if (oprofile_ops.switch_events)
+               schedule_delayed_work(&switch_work, oprofile_time_slice);
+}
+
+static void stop_switch_worker(void)
+{
+       cancel_delayed_work_sync(&switch_work);
+}
+
+static void switch_worker(struct work_struct *work)
+{
+       if (oprofile_ops.switch_events())
+               return;
+
+       atomic_inc(&oprofile_stats.multiplex_counter);
+       start_switch_worker();
+}
+
+/* User inputs in ms, converts to jiffies */
+int oprofile_set_timeout(unsigned long val_msec)
+{
+       int err = 0;
+       unsigned long time_slice;
+
+       mutex_lock(&start_mutex);
+
+       if (oprofile_started) {
+               err = -EBUSY;
+               goto out;
+       }
+
+       if (!oprofile_ops.switch_events) {
+               err = -EINVAL;
+               goto out;
+       }
+
+       time_slice = msecs_to_jiffies(val_msec);
+       if (time_slice == MAX_JIFFY_OFFSET) {
+               err = -EINVAL;
+               goto out;
+       }
+
+       oprofile_time_slice = time_slice;
+
+out:
+       mutex_unlock(&start_mutex);
+       return err;
+
+}
+
+#else
+
+static inline void start_switch_worker(void) { }
+static inline void stop_switch_worker(void) { }
+
+#endif
 
 /* Actually start profiling (echo 1>/dev/oprofile/enable) */
 int oprofile_start(void)
@@ -94,7 +159,7 @@ int oprofile_start(void)
        int err = -EINVAL;
 
        mutex_lock(&start_mutex);
+
        if (!is_setup)
                goto out;
 
@@ -108,6 +173,8 @@ int oprofile_start(void)
        if ((err = oprofile_ops.start()))
                goto out;
 
+       start_switch_worker();
+
        oprofile_started = 1;
 out:
        mutex_unlock(&start_mutex);
@@ -123,6 +190,9 @@ void oprofile_stop(void)
                goto out;
        oprofile_ops.stop();
        oprofile_started = 0;
+
+       stop_switch_worker();
+
        /* wake up the daemon to read what remains */
        wake_up_buffer_waiter();
 out:
@@ -155,7 +225,6 @@ post_sync:
        mutex_unlock(&start_mutex);
 }
 
-
 int oprofile_set_backtrace(unsigned long val)
 {
        int err = 0;
@@ -172,7 +241,7 @@ int oprofile_set_backtrace(unsigned long val)
                goto out;
        }
 
-       backtrace_depth = val;
+       oprofile_backtrace_depth = val;
 
 out:
        mutex_unlock(&start_mutex);
@@ -184,22 +253,26 @@ static int __init oprofile_init(void)
        int err;
 
        err = oprofile_arch_init(&oprofile_ops);
-
        if (err < 0 || timer) {
                printk(KERN_INFO "oprofile: using timer interrupt.\n");
-               oprofile_timer_init(&oprofile_ops);
+               err = oprofile_timer_init(&oprofile_ops);
+               if (err)
+                       goto out_arch;
        }
-
        err = oprofilefs_register();
        if (err)
-               oprofile_arch_exit();
+               goto out_arch;
+       return 0;
 
+out_arch:
+       oprofile_arch_exit();
        return err;
 }
 
 
 static void __exit oprofile_exit(void)
 {
+       oprofile_timer_exit();
        oprofilefs_unregister();
        oprofile_arch_exit();
 }