[STYLE] Sampler: doxygen comments
[kernel/swap-modules.git] / sampler / sampler_timer.c
1 /**
2  * sampler/sampler_timer.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 based on common timers.
28  */
29
30
31
32 #include "sampler_timers.h"
33
34
35
36 static unsigned long sampler_timer_quantum = 0;
37 static DEFINE_PER_CPU(struct timer_list, swap_timer);
38 static int swap_timer_running;
39
40 /**
41  * @brief Restarts sampling.
42  *
43  * @param timer Pointer to timer_list struct.
44  * @return 0.
45  */
46 restart_ret sampler_timers_restart(swap_timer *timer)
47 {
48         restart_ret ret;
49
50         mod_timer_pinned((struct timer_list *)timer,
51                      jiffies + sampler_timer_quantum);
52         ret = 0;
53
54         return ret;
55 }
56
57 /**
58  * @brief Sets running flag true.
59  *
60  * @return Void.
61  */
62 void sampler_timers_set_run(void)
63 {
64         swap_timer_running = 1;
65 }
66
67 /**
68  * @brief Sets running flag false.
69  *
70  * @return Void.
71  */
72 void sampler_timers_set_stop(void)
73 {
74         swap_timer_running = 0;
75 }
76
77 /**
78  * @brief Starts timer sampling.
79  *
80  * @param restart_func Pointer to restart function.
81  * @return Void.
82  */
83 void sampler_timers_start(void *restart_func)
84 {
85         struct timer_list *timer = &__get_cpu_var(swap_timer);
86
87         if (!swap_timer_running)
88                 return;
89
90         init_timer(timer);
91         timer->data = (unsigned long)timer;
92         timer->function = restart_func;
93
94         mod_timer_pinned(timer, jiffies + sampler_timer_quantum);
95 }
96
97 /**
98  * @brief Stops timer sampling.
99  *
100  * @param cpu Online CPUs.
101  * @return Void.
102  */
103 void sampler_timers_stop(int cpu)
104 {
105         struct timer_list *timer = &per_cpu(swap_timer, cpu);
106
107         if (!swap_timer_running)
108                 return;
109         del_timer_sync(timer);
110 }
111
112 /**
113  * @brief Sets timer quantum.
114  *
115  * @param timer_quantum Timer quantum.
116  * @return Void.
117  */
118 void sampler_timers_set_quantum(unsigned int timer_quantum)
119 {
120         sampler_timer_quantum = timer_quantum;
121 }