[REFACTOR] change prefix dbi* -> swap*
[kernel/swap-modules.git] / sampler / sampler_hrtimer.c
1 /*
2  *  SWAP sampler
3  *  modules/sampler/sampler_hrtimer.c
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  *
19  * Copyright (C) Samsung Electronics, 2013
20  *
21  * 2013  Alexander Aksenov <a.aksenov@samsung.com>: SWAP sampler porting
22  *
23  */
24
25
26
27 #include <linux/types.h>
28 #include "sampler_timers.h"
29
30
31 static u64 sampler_timer_quantum = 0;
32 static DEFINE_PER_CPU(struct hrtimer, swap_hrtimer);
33 static int swap_hrtimer_running;
34
35 restart_ret sampler_timers_restart(swap_timer *timer)
36 {
37         restart_ret ret;
38
39         hrtimer_forward_now(timer, ns_to_ktime(sampler_timer_quantum));
40         ret = HRTIMER_RESTART;
41
42         return ret;
43 }
44
45
46 void sampler_timers_set_run(void)
47 {
48         swap_hrtimer_running = 1;
49 }
50
51
52 void sampler_timers_set_stop(void)
53 {
54         swap_hrtimer_running = 0;
55 }
56
57
58 void sampler_timers_start(void *restart_func)
59 {
60         struct hrtimer *hrtimer = &__get_cpu_var(swap_hrtimer);
61
62         if (!swap_hrtimer_running)
63                 return;
64
65         hrtimer_init(hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
66         hrtimer->function = restart_func;
67         hrtimer_start(hrtimer, ns_to_ktime(sampler_timer_quantum),
68                   HRTIMER_MODE_REL_PINNED);
69 }
70
71
72 void sampler_timers_stop(int cpu)
73 {
74         struct hrtimer *hrtimer = &per_cpu(swap_hrtimer, cpu);
75
76         if (!swap_hrtimer_running)
77                 return;
78
79         hrtimer_cancel(hrtimer);
80 }
81
82
83 void sampler_timers_set_quantum(unsigned int timer_quantum)
84 {
85         sampler_timer_quantum = timer_quantum * 1000 * 1000;
86 }