2 * Copyright (C) ARM Limited 2010-2014. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
11 #include <trace/events/irq.h>
15 #define TOTALIRQ (SOFTIRQ+1)
17 static ulong hardirq_enabled;
18 static ulong softirq_enabled;
19 static ulong hardirq_key;
20 static ulong softirq_key;
21 static DEFINE_PER_CPU(atomic_t[TOTALIRQ], irqCnt);
22 static DEFINE_PER_CPU(int[TOTALIRQ * 2], irqGet);
24 GATOR_DEFINE_PROBE(irq_handler_exit,
25 TP_PROTO(int irq, struct irqaction *action, int ret))
27 atomic_inc(&per_cpu(irqCnt, get_physical_cpu())[HARDIRQ]);
30 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 37)
31 GATOR_DEFINE_PROBE(softirq_exit, TP_PROTO(struct softirq_action *h, struct softirq_action *vec))
33 GATOR_DEFINE_PROBE(softirq_exit, TP_PROTO(unsigned int vec_nr))
36 atomic_inc(&per_cpu(irqCnt, get_physical_cpu())[SOFTIRQ]);
39 static int gator_events_irq_create_files(struct super_block *sb, struct dentry *root)
44 dir = gatorfs_mkdir(sb, root, "Linux_irq_irq");
48 gatorfs_create_ulong(sb, dir, "enabled", &hardirq_enabled);
49 gatorfs_create_ro_ulong(sb, dir, "key", &hardirq_key);
52 dir = gatorfs_mkdir(sb, root, "Linux_irq_softirq");
56 gatorfs_create_ulong(sb, dir, "enabled", &softirq_enabled);
57 gatorfs_create_ro_ulong(sb, dir, "key", &softirq_key);
62 static int gator_events_irq_online(int **buffer, bool migrate)
64 int len = 0, cpu = get_physical_cpu();
66 // synchronization with the irq_exit functions is not necessary as the values are being reset
67 if (hardirq_enabled) {
68 atomic_set(&per_cpu(irqCnt, cpu)[HARDIRQ], 0);
69 per_cpu(irqGet, cpu)[len++] = hardirq_key;
70 per_cpu(irqGet, cpu)[len++] = 0;
73 if (softirq_enabled) {
74 atomic_set(&per_cpu(irqCnt, cpu)[SOFTIRQ], 0);
75 per_cpu(irqGet, cpu)[len++] = softirq_key;
76 per_cpu(irqGet, cpu)[len++] = 0;
80 *buffer = per_cpu(irqGet, cpu);
85 static int gator_events_irq_start(void)
87 // register tracepoints
89 if (GATOR_REGISTER_TRACE(irq_handler_exit))
90 goto fail_hardirq_exit;
92 if (GATOR_REGISTER_TRACE(softirq_exit))
93 goto fail_softirq_exit;
94 pr_debug("gator: registered irq tracepoints\n");
98 // unregister tracepoints on error
101 GATOR_UNREGISTER_TRACE(irq_handler_exit);
103 pr_err("gator: irq tracepoints failed to activate, please verify that tracepoints are enabled in the linux kernel\n");
108 static void gator_events_irq_stop(void)
111 GATOR_UNREGISTER_TRACE(irq_handler_exit);
113 GATOR_UNREGISTER_TRACE(softirq_exit);
114 pr_debug("gator: unregistered irq tracepoints\n");
120 static int gator_events_irq_read(int **buffer)
123 int cpu = get_physical_cpu();
126 if (hardirq_enabled) {
127 value = atomic_read(&per_cpu(irqCnt, cpu)[HARDIRQ]);
128 atomic_sub(value, &per_cpu(irqCnt, cpu)[HARDIRQ]);
130 per_cpu(irqGet, cpu)[len++] = hardirq_key;
131 per_cpu(irqGet, cpu)[len++] = value;
134 if (softirq_enabled) {
135 value = atomic_read(&per_cpu(irqCnt, cpu)[SOFTIRQ]);
136 atomic_sub(value, &per_cpu(irqCnt, cpu)[SOFTIRQ]);
138 per_cpu(irqGet, cpu)[len++] = softirq_key;
139 per_cpu(irqGet, cpu)[len++] = value;
143 *buffer = per_cpu(irqGet, cpu);
148 static struct gator_interface gator_events_irq_interface = {
149 .create_files = gator_events_irq_create_files,
150 .online = gator_events_irq_online,
151 .start = gator_events_irq_start,
152 .stop = gator_events_irq_stop,
153 .read = gator_events_irq_read,
156 int gator_events_irq_init(void)
158 hardirq_key = gator_events_get_key();
159 softirq_key = gator_events_get_key();
164 return gator_events_install(&gator_events_irq_interface);