1 /**
2 * Copyright (C) ARM Limited 2011-2012. All rights reserved.
3 *
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.
7 *
8 */
10 // gator_hrtimer_perf.c is used if perf is supported
11 // update, gator_hrtimer_gator.c always used until issues resolved with perf hrtimers
12 #if 1
14 void (*callback)(void);
15 DEFINE_PER_CPU(struct hrtimer, percpu_hrtimer);
16 DEFINE_PER_CPU(int, hrtimer_is_active);
17 static ktime_t profiling_interval;
18 static void gator_hrtimer_online(int cpu);
19 static void gator_hrtimer_offline(int cpu);
21 static enum hrtimer_restart gator_hrtimer_notify(struct hrtimer *hrtimer)
22 {
23 hrtimer_forward_now(hrtimer, profiling_interval);
24 (*callback)();
25 return HRTIMER_RESTART;
26 }
28 static void gator_hrtimer_switch_cpus_online(void *unused)
29 {
30 gator_hrtimer_online(smp_processor_id());
31 }
33 static void gator_hrtimer_online(int cpu)
34 {
35 struct hrtimer *hrtimer = &per_cpu(percpu_hrtimer, cpu);
37 if (cpu != smp_processor_id()) {
38 smp_call_function_single(cpu, gator_hrtimer_switch_cpus_online, NULL, 1);
39 return;
40 }
42 if (per_cpu(hrtimer_is_active, cpu) || profiling_interval.tv64 == 0)
43 return;
45 per_cpu(hrtimer_is_active, cpu) = 1;
46 hrtimer_init(hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
47 hrtimer->function = gator_hrtimer_notify;
48 hrtimer_start(hrtimer, profiling_interval, HRTIMER_MODE_REL_PINNED);
49 }
51 static void gator_hrtimer_switch_cpus_offline(void *unused)
52 {
53 gator_hrtimer_offline(smp_processor_id());
54 }
56 static void gator_hrtimer_offline(int cpu)
57 {
58 struct hrtimer *hrtimer = &per_cpu(percpu_hrtimer, cpu);
60 if (cpu != smp_processor_id()) {
61 smp_call_function_single(cpu, gator_hrtimer_switch_cpus_offline, NULL, 1);
62 return;
63 }
65 if (!per_cpu(hrtimer_is_active, cpu))
66 return;
68 per_cpu(hrtimer_is_active, cpu) = 0;
69 hrtimer_cancel(hrtimer);
70 }
72 static int gator_hrtimer_init(int interval, void (*func)(void))
73 {
74 int cpu;
76 (callback) = (func);
78 for_each_present_cpu(cpu) {
79 per_cpu(hrtimer_is_active, cpu) = 0;
80 }
82 // calculate profiling interval
83 if (interval > 0) {
84 profiling_interval = ns_to_ktime(1000000000UL / interval);
85 } else {
86 profiling_interval.tv64 = 0;
87 }
89 return 0;
90 }
92 static void gator_hrtimer_shutdown(void)
93 {
94 /* empty */
95 }
97 #endif