[STYLE] Sampler: doxygen comments
[kernel/swap-modules.git] / sampler / sampler_hrtimer.c
1 /**
2  * sampler/sampler_hrtimer.c
3  * @author Alexander Aksenov <a.aksenov@samsung.com>
4  *
5  * @section LICENSE
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  *
21  * @section COPYRIGHT
22  *
23  * Copyright (C) Samsung Electronics, 2013
24  *
25  * @section DESCRIPTION
26  *
27  * Sampler for high resolution timers.
28  */
29
30
31
32 #include <linux/types.h>
33 #include "sampler_timers.h"
34
35
36 static u64 sampler_timer_quantum = 0;
37 static DEFINE_PER_CPU(struct hrtimer, swap_hrtimer);
38 static int swap_hrtimer_running;
39
40 /**
41  * @brief Restarts sampling.
42  *
43  * @param timer Pointer to hrtimer struct.
44  * @return hrtimer_restart flag.
45  */
46 restart_ret sampler_timers_restart(swap_timer *timer)
47 {
48         restart_ret ret;
49
50         hrtimer_forward_now(timer, ns_to_ktime(sampler_timer_quantum));
51         ret = HRTIMER_RESTART;
52
53         return ret;
54 }
55
56 /**
57  * @brief Sets running flag true.
58  *
59  * @return Void.
60  */
61 void sampler_timers_set_run(void)
62 {
63         swap_hrtimer_running = 1;
64 }
65
66 /**
67  * @brief Sets running flag false.
68  *
69  * @return Void.
70  */
71 void sampler_timers_set_stop(void)
72 {
73         swap_hrtimer_running = 0;
74 }
75
76 /**
77  * @brief Starts timer sampling.
78  *
79  * @param restart_func Pointer to restart function.
80  * @return Void.
81  */
82 void sampler_timers_start(void *restart_func)
83 {
84         struct hrtimer *hrtimer = &__get_cpu_var(swap_hrtimer);
85
86         if (!swap_hrtimer_running)
87                 return;
88
89         hrtimer_init(hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
90         hrtimer->function = restart_func;
91         hrtimer_start(hrtimer, ns_to_ktime(sampler_timer_quantum),
92                   HRTIMER_MODE_REL_PINNED);
93 }
94
95 /**
96  * @brief Stops timer sampling.
97  *
98  * @param cpu Online CPUs.
99  * @return Void.
100  */
101 void sampler_timers_stop(int cpu)
102 {
103         struct hrtimer *hrtimer = &per_cpu(swap_hrtimer, cpu);
104
105         if (!swap_hrtimer_running)
106                 return;
107
108         hrtimer_cancel(hrtimer);
109 }
110
111 /**
112  * @brief Sets timer quantum.
113  *
114  * @param timer_quantum Timer quantum.
115  * @return Void.
116  */
117 void sampler_timers_set_quantum(unsigned int timer_quantum)
118 {
119         sampler_timer_quantum = timer_quantum * 1000 * 1000;
120 }