ACPI: create acpi_dmi_dump()
[pandora-kernel.git] / block / blktrace.c
index 20fa034..9b4da4a 100644 (file)
@@ -25,7 +25,6 @@
 #include <linux/time.h>
 #include <asm/uaccess.h>
 
-static DEFINE_PER_CPU(unsigned long long, blk_trace_cpu_offset) = { 0, };
 static unsigned int blktrace_seq __read_mostly = 1;
 
 /*
@@ -41,7 +40,7 @@ static void trace_note(struct blk_trace *bt, pid_t pid, int action,
                const int cpu = smp_processor_id();
 
                t->magic = BLK_IO_TRACE_MAGIC | BLK_IO_TRACE_VERSION;
-               t->time = cpu_clock(cpu) - per_cpu(blk_trace_cpu_offset, cpu);
+               t->time = ktime_to_ns(ktime_get());
                t->device = bt->dev;
                t->action = action;
                t->pid = pid;
@@ -159,7 +158,7 @@ void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes,
 
                t->magic = BLK_IO_TRACE_MAGIC | BLK_IO_TRACE_VERSION;
                t->sequence = ++(*sequence);
-               t->time = cpu_clock(cpu) - per_cpu(blk_trace_cpu_offset, cpu);
+               t->time = ktime_to_ns(ktime_get());
                t->sector = sector;
                t->bytes = bytes;
                t->action = what;
@@ -179,7 +178,7 @@ void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes,
 EXPORT_SYMBOL_GPL(__blk_add_trace);
 
 static struct dentry *blk_tree_root;
-static struct mutex blk_tree_mutex;
+static DEFINE_MUTEX(blk_tree_mutex);
 static unsigned int root_users;
 
 static inline void blk_remove_root(void)
@@ -202,6 +201,7 @@ static void blk_remove_tree(struct dentry *dir)
 static struct dentry *blk_create_tree(const char *blk_name)
 {
        struct dentry *dir = NULL;
+       int created = 0;
 
        mutex_lock(&blk_tree_mutex);
 
@@ -209,13 +209,17 @@ static struct dentry *blk_create_tree(const char *blk_name)
                blk_tree_root = debugfs_create_dir("block", NULL);
                if (!blk_tree_root)
                        goto err;
+               created = 1;
        }
 
        dir = debugfs_create_dir(blk_name, blk_tree_root);
        if (dir)
                root_users++;
-       else
-               blk_remove_root();
+       else {
+               /* Delete root only if we created it */
+               if (created)
+                       blk_remove_root();
+       }
 
 err:
        mutex_unlock(&blk_tree_mutex);
@@ -312,33 +316,26 @@ static struct rchan_callbacks blk_relay_callbacks = {
 /*
  * Setup everything required to start tracing
  */
-static int blk_trace_setup(struct request_queue *q, struct block_device *bdev,
-                          char __user *arg)
+int do_blk_trace_setup(struct request_queue *q, struct block_device *bdev,
+                       struct blk_user_trace_setup *buts)
 {
-       struct blk_user_trace_setup buts;
        struct blk_trace *old_bt, *bt = NULL;
        struct dentry *dir = NULL;
        char b[BDEVNAME_SIZE];
        int ret, i;
 
-       if (copy_from_user(&buts, arg, sizeof(buts)))
-               return -EFAULT;
-
-       if (!buts.buf_size || !buts.buf_nr)
+       if (!buts->buf_size || !buts->buf_nr)
                return -EINVAL;
 
-       strcpy(buts.name, bdevname(bdev, b));
+       strcpy(buts->name, bdevname(bdev, b));
 
        /*
         * some device names have larger paths - convert the slashes
         * to underscores for this to work as expected
         */
-       for (i = 0; i < strlen(buts.name); i++)
-               if (buts.name[i] == '/')
-                       buts.name[i] = '_';
-
-       if (copy_to_user(arg, &buts, sizeof(buts)))
-               return -EFAULT;
+       for (i = 0; i < strlen(buts->name); i++)
+               if (buts->name[i] == '/')
+                       buts->name[i] = '_';
 
        ret = -ENOMEM;
        bt = kzalloc(sizeof(*bt), GFP_KERNEL);
@@ -350,7 +347,7 @@ static int blk_trace_setup(struct request_queue *q, struct block_device *bdev,
                goto err;
 
        ret = -ENOENT;
-       dir = blk_create_tree(buts.name);
+       dir = blk_create_tree(buts->name);
        if (!dir)
                goto err;
 
@@ -363,20 +360,21 @@ static int blk_trace_setup(struct request_queue *q, struct block_device *bdev,
        if (!bt->dropped_file)
                goto err;
 
-       bt->rchan = relay_open("trace", dir, buts.buf_size, buts.buf_nr, &blk_relay_callbacks, bt);
+       bt->rchan = relay_open("trace", dir, buts->buf_size,
+                               buts->buf_nr, &blk_relay_callbacks, bt);
        if (!bt->rchan)
                goto err;
 
-       bt->act_mask = buts.act_mask;
+       bt->act_mask = buts->act_mask;
        if (!bt->act_mask)
                bt->act_mask = (u16) -1;
 
-       bt->start_lba = buts.start_lba;
-       bt->end_lba = buts.end_lba;
+       bt->start_lba = buts->start_lba;
+       bt->end_lba = buts->end_lba;
        if (!bt->end_lba)
                bt->end_lba = -1ULL;
 
-       bt->pid = buts.pid;
+       bt->pid = buts->pid;
        bt->trace_state = Blktrace_setup;
 
        ret = -EBUSY;
@@ -401,6 +399,26 @@ err:
        return ret;
 }
 
+static int blk_trace_setup(struct request_queue *q, struct block_device *bdev,
+                          char __user *arg)
+{
+       struct blk_user_trace_setup buts;
+       int ret;
+
+       ret = copy_from_user(&buts, arg, sizeof(buts));
+       if (ret)
+               return -EFAULT;
+
+       ret = do_blk_trace_setup(q, bdev, &buts);
+       if (ret)
+               return ret;
+
+       if (copy_to_user(arg, &buts, sizeof(buts)))
+               return -EFAULT;
+
+       return 0;
+}
+
 static int blk_trace_startstop(struct request_queue *q, int start)
 {
        struct blk_trace *bt;
@@ -486,77 +504,3 @@ void blk_trace_shutdown(struct request_queue *q)
                blk_trace_remove(q);
        }
 }
-
-/*
- * Average offset over two calls to cpu_clock() with a gettimeofday()
- * in the middle
- */
-static void blk_check_time(unsigned long long *t, int this_cpu)
-{
-       unsigned long long a, b;
-       struct timeval tv;
-
-       a = cpu_clock(this_cpu);
-       do_gettimeofday(&tv);
-       b = cpu_clock(this_cpu);
-
-       *t = tv.tv_sec * 1000000000 + tv.tv_usec * 1000;
-       *t -= (a + b) / 2;
-}
-
-/*
- * calibrate our inter-CPU timings
- */
-static void blk_trace_check_cpu_time(void *data)
-{
-       unsigned long long *t;
-       int this_cpu = get_cpu();
-
-       t = &per_cpu(blk_trace_cpu_offset, this_cpu);
-
-       /*
-        * Just call it twice, hopefully the second call will be cache hot
-        * and a little more precise
-        */
-       blk_check_time(t, this_cpu);
-       blk_check_time(t, this_cpu);
-
-       put_cpu();
-}
-
-static void blk_trace_set_ht_offsets(void)
-{
-#if defined(CONFIG_SCHED_SMT)
-       int cpu, i;
-
-       /*
-        * now make sure HT siblings have the same time offset
-        */
-       preempt_disable();
-       for_each_online_cpu(cpu) {
-               unsigned long long *cpu_off, *sibling_off;
-
-               for_each_cpu_mask(i, cpu_sibling_map[cpu]) {
-                       if (i == cpu)
-                               continue;
-
-                       cpu_off = &per_cpu(blk_trace_cpu_offset, cpu);
-                       sibling_off = &per_cpu(blk_trace_cpu_offset, i);
-                       *sibling_off = *cpu_off;
-               }
-       }
-       preempt_enable();
-#endif
-}
-
-static __init int blk_trace_init(void)
-{
-       mutex_init(&blk_tree_mutex);
-       on_each_cpu(blk_trace_check_cpu_time, NULL, 1, 1);
-       blk_trace_set_ht_offsets();
-
-       return 0;
-}
-
-module_init(blk_trace_init);
-