]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android-sdk/arm-ds5-gator.git/blob - driver/gator_hrtimer_gator.c
Merge branch 'master' into android
[android-sdk/arm-ds5-gator.git] / driver / gator_hrtimer_gator.c
1 /**
2  * Copyright (C) ARM Limited 2011-2014. 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 void (*callback)(void);
11 DEFINE_PER_CPU(struct hrtimer, percpu_hrtimer);
12 DEFINE_PER_CPU(ktime_t, hrtimer_expire);
13 DEFINE_PER_CPU(int, hrtimer_is_active);
14 static ktime_t profiling_interval;
15 static void gator_hrtimer_online(void);
16 static void gator_hrtimer_offline(void);
18 static enum hrtimer_restart gator_hrtimer_notify(struct hrtimer *hrtimer)
19 {
20         int cpu = get_logical_cpu();
21         hrtimer_forward(hrtimer, per_cpu(hrtimer_expire, cpu), profiling_interval);
22         per_cpu(hrtimer_expire, cpu) = ktime_add(per_cpu(hrtimer_expire, cpu), profiling_interval);
23         (*callback)();
24         return HRTIMER_RESTART;
25 }
27 static void gator_hrtimer_online(void)
28 {
29         int cpu = get_logical_cpu();
30         struct hrtimer *hrtimer = &per_cpu(percpu_hrtimer, cpu);
32         if (per_cpu(hrtimer_is_active, cpu) || profiling_interval.tv64 == 0)
33                 return;
35         per_cpu(hrtimer_is_active, cpu) = 1;
36         hrtimer_init(hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
37         hrtimer->function = gator_hrtimer_notify;
38 #ifdef CONFIG_PREEMPT_RT_BASE
39         hrtimer->irqsafe = 1;
40 #endif
41         per_cpu(hrtimer_expire, cpu) = ktime_add(hrtimer->base->get_time(), profiling_interval);
42         hrtimer_start(hrtimer, per_cpu(hrtimer_expire, cpu), HRTIMER_MODE_ABS_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 }