2 * sampler/sampler_timer.c
3 * @author Alexander Aksenov <a.aksenov@samsung.com>
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.
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.
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.
23 * Copyright (C) Samsung Electronics, 2013
25 * @section DESCRIPTION
27 * Sampler based on common timers.
32 #include "sampler_timers.h"
36 static unsigned long sampler_timer_quantum = 0;
37 static DEFINE_PER_CPU(struct timer_list, swap_timer);
38 static int swap_timer_running;
41 * @brief Restarts sampling.
43 * @param timer Pointer to timer_list struct.
46 restart_ret sampler_timers_restart(swap_timer *timer)
50 mod_timer_pinned((struct timer_list *)timer,
51 jiffies + sampler_timer_quantum);
58 * @brief Sets running flag true.
62 void sampler_timers_set_run(void)
64 swap_timer_running = 1;
68 * @brief Sets running flag false.
72 void sampler_timers_set_stop(void)
74 swap_timer_running = 0;
78 * @brief Starts timer sampling.
80 * @param restart_func Pointer to restart function.
83 void sampler_timers_start(void *restart_func)
85 struct timer_list *timer = &__get_cpu_var(swap_timer);
87 if (!swap_timer_running)
91 timer->data = (unsigned long)timer;
92 timer->function = restart_func;
94 mod_timer_pinned(timer, jiffies + sampler_timer_quantum);
98 * @brief Stops timer sampling.
100 * @param cpu Online CPUs.
103 void sampler_timers_stop(int cpu)
105 struct timer_list *timer = &per_cpu(swap_timer, cpu);
107 if (!swap_timer_running)
109 del_timer_sync(timer);
113 * @brief Sets timer quantum.
115 * @param timer_quantum Timer quantum.
118 void sampler_timers_set_quantum(unsigned int timer_quantum)
120 sampler_timer_quantum = timer_quantum;