3 * modules/sampler/sampler_hrtimer.c
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.
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.
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.
19 * Copyright (C) Samsung Electronics, 2013
21 * 2013 Alexander Aksenov <a.aksenov@samsung.com>: SWAP sampler porting
27 #include <linux/types.h>
28 #include "sampler_timers.h"
31 static u64 sampler_timer_quantum = 0;
32 static DEFINE_PER_CPU(struct hrtimer, swap_hrtimer);
33 static int swap_hrtimer_running;
35 restart_ret sampler_timers_restart(swap_timer *timer)
39 hrtimer_forward_now(timer, ns_to_ktime(sampler_timer_quantum));
40 ret = HRTIMER_RESTART;
46 void sampler_timers_set_run(void)
48 swap_hrtimer_running = 1;
52 void sampler_timers_set_stop(void)
54 swap_hrtimer_running = 0;
58 void sampler_timers_start(void *restart_func)
60 struct hrtimer *hrtimer = &__get_cpu_var(swap_hrtimer);
62 if (!swap_hrtimer_running)
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);
72 void sampler_timers_stop(int cpu)
74 struct hrtimer *hrtimer = &per_cpu(swap_hrtimer, cpu);
76 if (!swap_hrtimer_running)
79 hrtimer_cancel(hrtimer);
83 void sampler_timers_set_quantum(unsigned int timer_quantum)
85 sampler_timer_quantum = timer_quantum * 1000 * 1000;