Merge remote-tracking branch 'lsk/v3.10/topic/arm64-fvp' into linux-linaro-lsk
[firefly-linux-kernel-4.4.55.git] / drivers / gator / gator_hrtimer_gator.c
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  */
9
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
13
14 void (*callback)(void);
15 DEFINE_PER_CPU(struct hrtimer, percpu_hrtimer);
16 DEFINE_PER_CPU(ktime_t, hrtimer_expire);
17 DEFINE_PER_CPU(int, hrtimer_is_active);
18 static ktime_t profiling_interval;
19 static void gator_hrtimer_online(void);
20 static void gator_hrtimer_offline(void);
21
22 static enum hrtimer_restart gator_hrtimer_notify(struct hrtimer *hrtimer)
23 {
24         int cpu = get_logical_cpu();
25         hrtimer_forward(hrtimer, per_cpu(hrtimer_expire, cpu), profiling_interval);
26         per_cpu(hrtimer_expire, cpu) = ktime_add(per_cpu(hrtimer_expire, cpu), profiling_interval);
27         (*callback)();
28         return HRTIMER_RESTART;
29 }
30
31 static void gator_hrtimer_online(void)
32 {
33         int cpu = get_logical_cpu();
34         struct hrtimer *hrtimer = &per_cpu(percpu_hrtimer, cpu);
35
36         if (per_cpu(hrtimer_is_active, cpu) || profiling_interval.tv64 == 0)
37                 return;
38
39         per_cpu(hrtimer_is_active, cpu) = 1;
40         hrtimer_init(hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
41         hrtimer->function = gator_hrtimer_notify;
42 #ifdef CONFIG_PREEMPT_RT_BASE
43         hrtimer->irqsafe = 1;
44 #endif
45         per_cpu(hrtimer_expire, cpu) = ktime_add(hrtimer->base->get_time(), profiling_interval);
46         hrtimer_start(hrtimer, per_cpu(hrtimer_expire, cpu), HRTIMER_MODE_ABS_PINNED);
47 }
48
49 static void gator_hrtimer_offline(void)
50 {
51         int cpu = get_logical_cpu();
52         struct hrtimer *hrtimer = &per_cpu(percpu_hrtimer, cpu);
53
54         if (!per_cpu(hrtimer_is_active, cpu))
55                 return;
56
57         per_cpu(hrtimer_is_active, cpu) = 0;
58         hrtimer_cancel(hrtimer);
59 }
60
61 static int gator_hrtimer_init(int interval, void (*func)(void))
62 {
63         int cpu;
64
65         (callback) = (func);
66
67         for_each_present_cpu(cpu) {
68                 per_cpu(hrtimer_is_active, cpu) = 0;
69         }
70
71         // calculate profiling interval
72         if (interval > 0) {
73                 profiling_interval = ns_to_ktime(1000000000UL / interval);
74         } else {
75                 profiling_interval.tv64 = 0;
76         }
77
78         return 0;
79 }
80
81 static void gator_hrtimer_shutdown(void)
82 {
83         /* empty */
84 }
85
86 #endif