timer stats: speedups
[safe/jmp/linux-2.6] / kernel / time / timer_stats.c
index 946ed45..3216937 100644 (file)
@@ -117,21 +117,6 @@ static struct entry entries[MAX_ENTRIES];
 
 static atomic_t overflow_count;
 
-static void reset_entries(void)
-{
-       nr_entries = 0;
-       memset(entries, 0, sizeof(entries));
-       atomic_set(&overflow_count, 0);
-}
-
-static struct entry *alloc_entry(void)
-{
-       if (nr_entries >= MAX_ENTRIES)
-               return NULL;
-
-       return entries + nr_entries++;
-}
-
 /*
  * The entries are in a hash-table, for fast lookup:
  */
@@ -149,6 +134,22 @@ static struct entry *alloc_entry(void)
 
 static struct entry *tstat_hash_table[TSTAT_HASH_SIZE] __read_mostly;
 
+static void reset_entries(void)
+{
+       nr_entries = 0;
+       memset(entries, 0, sizeof(entries));
+       memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
+       atomic_set(&overflow_count, 0);
+}
+
+static struct entry *alloc_entry(void)
+{
+       if (nr_entries >= MAX_ENTRIES)
+               return NULL;
+
+       return entries + nr_entries++;
+}
+
 static int match_entries(struct entry *entry1, struct entry *entry2)
 {
        return entry1->timer       == entry2->timer       &&
@@ -202,12 +203,15 @@ static struct entry *tstat_lookup(struct entry *entry, char *comm)
        if (curr) {
                *curr = *entry;
                curr->count = 0;
+               curr->next = NULL;
                memcpy(curr->comm, comm, TASK_COMM_LEN);
+
+               smp_mb(); /* Ensure that curr is initialized before insert */
+
                if (prev)
                        prev->next = curr;
                else
                        *head = curr;
-               curr->next = NULL;
        }
  out_unlock:
        spin_unlock(&table_lock);
@@ -232,10 +236,15 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
        /*
         * It doesnt matter which lock we take:
         */
-       spinlock_t *lock = &per_cpu(lookup_lock, raw_smp_processor_id());
+       spinlock_t *lock;
        struct entry *entry, input;
        unsigned long flags;
 
+       if (likely(!active))
+               return;
+
+       lock = &per_cpu(lookup_lock, raw_smp_processor_id());
+
        input.timer = timer;
        input.start_func = startf;
        input.expire_func = timerf;
@@ -257,14 +266,12 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
 
 static void print_name_offset(struct seq_file *m, unsigned long addr)
 {
-       char namebuf[KSYM_NAME_LEN+1];
-       const char *sym_name;
+       char symname[KSYM_NAME_LEN+1];
 
-       sym_name = kallsyms_lookup(addr, NULL, NULL, NULL, namebuf);
-       if (sym_name)
-               seq_printf(m, "%s", sym_name);
-       else
+       if (lookup_symbol_name(addr, symname) < 0)
                seq_printf(m, "<%p>", (void *)addr);
+       else
+               seq_printf(m, "%s", symname);
 }
 
 static int tstats_show(struct seq_file *m, void *v)
@@ -362,6 +369,7 @@ static ssize_t tstats_write(struct file *file, const char __user *buf,
                if (!active) {
                        reset_entries();
                        time_start = ktime_get();
+                       smp_mb();
                        active = 1;
                }
                break;