2 * sampler/sampler_hrtimer.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 for high resolution timers.
32 #include <linux/types.h>
33 #include "sampler_timers.h"
36 static u64 sampler_timer_quantum = 0;
37 static DEFINE_PER_CPU(struct hrtimer, swap_hrtimer);
38 static int swap_hrtimer_running;
41 * @brief Restarts sampling.
43 * @param timer Pointer to hrtimer struct.
44 * @return hrtimer_restart flag.
46 restart_ret sampler_timers_restart(swap_timer *timer)
50 hrtimer_forward_now(timer, ns_to_ktime(sampler_timer_quantum));
51 ret = HRTIMER_RESTART;
57 * @brief Sets running flag true.
61 void sampler_timers_set_run(void)
63 swap_hrtimer_running = 1;
67 * @brief Sets running flag false.
71 void sampler_timers_set_stop(void)
73 swap_hrtimer_running = 0;
77 * @brief Starts timer sampling.
79 * @param restart_func Pointer to restart function.
82 void sampler_timers_start(void *restart_func)
84 struct hrtimer *hrtimer = &__get_cpu_var(swap_hrtimer);
86 if (!swap_hrtimer_running)
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);
96 * @brief Stops timer sampling.
98 * @param cpu Online CPUs.
101 void sampler_timers_stop(int cpu)
103 struct hrtimer *hrtimer = &per_cpu(swap_hrtimer, cpu);
105 if (!swap_hrtimer_running)
108 hrtimer_cancel(hrtimer);
112 * @brief Sets timer quantum.
114 * @param timer_quantum Timer quantum.
117 void sampler_timers_set_quantum(unsigned int timer_quantum)
119 sampler_timer_quantum = timer_quantum * 1000 * 1000;