2 * Copyright (C) ARM Limited 2010-2013. 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/sched.h>
13 #define SCHED_SWITCH 0
14 #define SCHED_TOTAL (SCHED_SWITCH+1)
16 static ulong sched_switch_enabled;
17 static ulong sched_switch_key;
18 static DEFINE_PER_CPU(int[SCHED_TOTAL], schedCnt);
19 static DEFINE_PER_CPU(int[SCHED_TOTAL * 2], schedGet);
21 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35)
22 GATOR_DEFINE_PROBE(sched_switch, TP_PROTO(struct rq *rq, struct task_struct *prev, struct task_struct *next))
24 GATOR_DEFINE_PROBE(sched_switch, TP_PROTO(struct task_struct *prev, struct task_struct *next))
29 // disable interrupts to synchronize with gator_events_sched_read()
30 // spinlocks not needed since percpu buffers are used
31 local_irq_save(flags);
32 per_cpu(schedCnt, get_physical_cpu())[SCHED_SWITCH]++;
33 local_irq_restore(flags);
36 static int gator_events_sched_create_files(struct super_block *sb, struct dentry *root)
41 dir = gatorfs_mkdir(sb, root, "Linux_sched_switch");
45 gatorfs_create_ulong(sb, dir, "enabled", &sched_switch_enabled);
46 gatorfs_create_ro_ulong(sb, dir, "key", &sched_switch_key);
51 static int gator_events_sched_start(void)
53 // register tracepoints
54 if (sched_switch_enabled)
55 if (GATOR_REGISTER_TRACE(sched_switch))
56 goto sched_switch_exit;
57 pr_debug("gator: registered scheduler event tracepoints\n");
61 // unregister tracepoints on error
63 pr_err("gator: scheduler event tracepoints failed to activate, please verify that tracepoints are enabled in the linux kernel\n");
68 static void gator_events_sched_stop(void)
70 if (sched_switch_enabled)
71 GATOR_UNREGISTER_TRACE(sched_switch);
72 pr_debug("gator: unregistered scheduler event tracepoints\n");
74 sched_switch_enabled = 0;
77 static int gator_events_sched_read(int **buffer)
81 int cpu = get_physical_cpu();
84 if (sched_switch_enabled) {
85 local_irq_save(flags);
86 value = per_cpu(schedCnt, cpu)[SCHED_SWITCH];
87 per_cpu(schedCnt, cpu)[SCHED_SWITCH] = 0;
88 local_irq_restore(flags);
89 per_cpu(schedGet, cpu)[len++] = sched_switch_key;
90 per_cpu(schedGet, cpu)[len++] = value;
94 *buffer = per_cpu(schedGet, cpu);
99 static struct gator_interface gator_events_sched_interface = {
100 .create_files = gator_events_sched_create_files,
101 .start = gator_events_sched_start,
102 .stop = gator_events_sched_stop,
103 .read = gator_events_sched_read,
106 int gator_events_sched_init(void)
108 sched_switch_enabled = 0;
110 sched_switch_key = gator_events_get_key();
112 return gator_events_install(&gator_events_sched_interface);