1 /**
2 * Copyright (C) ARM Limited 2011-2013. 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(void);
19 static void gator_hrtimer_offline(void);
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_online(void)
29 {
30 int cpu = get_logical_cpu();
31 struct hrtimer *hrtimer = &per_cpu(percpu_hrtimer, cpu);
33 if (per_cpu(hrtimer_is_active, cpu) || profiling_interval.tv64 == 0)
34 return;
36 per_cpu(hrtimer_is_active, cpu) = 1;
37 hrtimer_init(hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
38 hrtimer->function = gator_hrtimer_notify;
39 #ifdef CONFIG_PREEMPT_RT_BASE
40 hrtimer->irqsafe = 1;
41 #endif
42 hrtimer_start(hrtimer, profiling_interval, HRTIMER_MODE_REL_PINNED);
43 }
45 static void gator_hrtimer_offline(void)
46 {
47 int cpu = get_logical_cpu();
48 struct hrtimer *hrtimer = &per_cpu(percpu_hrtimer, cpu);
50 if (!per_cpu(hrtimer_is_active, cpu))
51 return;
53 per_cpu(hrtimer_is_active, cpu) = 0;
54 hrtimer_cancel(hrtimer);
55 }
57 static int gator_hrtimer_init(int interval, void (*func)(void))
58 {
59 int cpu;
61 (callback) = (func);
63 for_each_present_cpu(cpu) {
64 per_cpu(hrtimer_is_active, cpu) = 0;
65 }
67 // calculate profiling interval
68 if (interval > 0) {
69 profiling_interval = ns_to_ktime(1000000000UL / interval);
70 } else {
71 profiling_interval.tv64 = 0;
72 }
74 return 0;
75 }
77 static void gator_hrtimer_shutdown(void)
78 {
79 /* empty */
80 }
82 #endif