40 #include <linux/module.h>
42 #include <linux/sched.h>
46 #include <asm/uaccess.h>
104 static ktime_t time_start, time_stop;
113 #define MAX_ENTRIES_BITS 10
114 #define MAX_ENTRIES (1UL << MAX_ENTRIES_BITS)
116 static unsigned long nr_entries;
124 #define TSTAT_HASH_BITS (MAX_ENTRIES_BITS - 1)
125 #define TSTAT_HASH_SIZE (1UL << TSTAT_HASH_BITS)
126 #define TSTAT_HASH_MASK (TSTAT_HASH_SIZE - 1)
128 #define __tstat_hashfn(entry) \
129 (((unsigned long)(entry)->timer ^ \
130 (unsigned long)(entry)->start_func ^ \
131 (unsigned long)(entry)->expire_func ^ \
132 (unsigned long)(entry)->pid ) & TSTAT_HASH_MASK)
134 #define tstat_hashentry(entry) (tstat_hash_table + __tstat_hashfn(entry))
138 static void reset_entries(
void)
142 memset(tstat_hash_table, 0,
sizeof(tstat_hash_table));
146 static struct entry *alloc_entry(
void)
154 static int match_entries(
struct entry *entry1,
struct entry *entry2)
159 entry1->
pid == entry2->
pid;
180 if (match_entries(curr, entry))
196 if (match_entries(curr, entry))
203 curr = alloc_entry();
235 void *timerf,
char *comm,
260 entry = tstat_lookup(&input, comm);
270 static void print_name_offset(
struct seq_file *
m,
unsigned long addr)
280 static int tstats_show(
struct seq_file *m,
void *
v)
296 time = ktime_sub(time_stop, time_start);
298 period = ktime_to_timespec(time);
299 ms =
period.tv_nsec / 1000000;
301 seq_puts(m,
"Timer Stats Version: v0.2\n");
307 for (i = 0; i < nr_entries; i++) {
309 if (entry->
timer_flag & TIMER_STATS_FLAG_DEFERRABLE) {
317 print_name_offset(m, (
unsigned long)entry->
start_func);
319 print_name_offset(m, (
unsigned long)entry->
expire_func);
322 events += entry->
count;
325 ms +=
period.tv_sec * 1000;
329 if (events &&
period.tv_sec)
330 seq_printf(m,
"%ld total events, %ld.%03ld events/sec\n",
331 events, events * 1000 / ms,
332 (events * 1000000 / ms) % 1000);
345 static void sync_access(
void)
364 if (count != 2 || *offs)
395 static int tstats_open(
struct inode *
inode,
struct file *filp)
403 .write = tstats_write,
416 static int __init init_tstats_procfs(
void)
420 pe = proc_create(
"timer_stats", 0644,
NULL, &tstats_fops);