]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/oprofile/timer_int.c
UBUNTU: SAUCE: ACPI / bus: Add some Lenovo laptops in list of acpi table term list
[mirror_ubuntu-bionic-kernel.git] / drivers / oprofile / timer_int.c
CommitLineData
1da177e4
LT
1/**
2 * @file timer_int.c
3 *
4 * @remark Copyright 2002 OProfile authors
5 * @remark Read the file COPYING
6 *
7 * @author John Levon <levon@movementarian.org>
8 */
9
10#include <linux/kernel.h>
11#include <linux/notifier.h>
12#include <linux/smp.h>
13#include <linux/oprofile.h>
14#include <linux/profile.h>
15#include <linux/init.h>
bc078e4e
MS
16#include <linux/cpu.h>
17#include <linux/hrtimer.h>
18#include <asm/irq_regs.h>
1da177e4
LT
19#include <asm/ptrace.h>
20
21#include "oprof.h"
22
bc078e4e 23static DEFINE_PER_CPU(struct hrtimer, oprofile_hrtimer);
4ac3dbec 24static int ctr_running;
bc078e4e
MS
25
26static enum hrtimer_restart oprofile_hrtimer_notify(struct hrtimer *hrtimer)
27{
28 oprofile_add_sample(get_irq_regs(), 0);
29 hrtimer_forward_now(hrtimer, ns_to_ktime(TICK_NSEC));
30 return HRTIMER_RESTART;
31}
32
33static void __oprofile_hrtimer_start(void *unused)
34{
879d9274 35 struct hrtimer *hrtimer = this_cpu_ptr(&oprofile_hrtimer);
bc078e4e 36
4ac3dbec
SS
37 if (!ctr_running)
38 return;
39
bc078e4e
MS
40 hrtimer_init(hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
41 hrtimer->function = oprofile_hrtimer_notify;
42
43 hrtimer_start(hrtimer, ns_to_ktime(TICK_NSEC),
44 HRTIMER_MODE_REL_PINNED);
45}
46
47static int oprofile_hrtimer_start(void)
1da177e4 48{
4ac3dbec
SS
49 get_online_cpus();
50 ctr_running = 1;
bc078e4e 51 on_each_cpu(__oprofile_hrtimer_start, NULL, 1);
4ac3dbec 52 put_online_cpus();
1da177e4
LT
53 return 0;
54}
55
bc078e4e 56static void __oprofile_hrtimer_stop(int cpu)
1da177e4 57{
bc078e4e
MS
58 struct hrtimer *hrtimer = &per_cpu(oprofile_hrtimer, cpu);
59
4ac3dbec
SS
60 if (!ctr_running)
61 return;
62
bc078e4e 63 hrtimer_cancel(hrtimer);
1da177e4
LT
64}
65
bc078e4e
MS
66static void oprofile_hrtimer_stop(void)
67{
68 int cpu;
69
4ac3dbec 70 get_online_cpus();
bc078e4e
MS
71 for_each_online_cpu(cpu)
72 __oprofile_hrtimer_stop(cpu);
4ac3dbec
SS
73 ctr_running = 0;
74 put_online_cpus();
bc078e4e 75}
1da177e4 76
a4e0591e 77static int oprofile_timer_online(unsigned int cpu)
1da177e4 78{
a4e0591e
SAS
79 local_irq_disable();
80 __oprofile_hrtimer_start(NULL);
81 local_irq_enable();
82 return 0;
1da177e4
LT
83}
84
a4e0591e
SAS
85static int oprofile_timer_prep_down(unsigned int cpu)
86{
87 __oprofile_hrtimer_stop(cpu);
88 return 0;
89}
90
91static enum cpuhp_state hp_online;
1da177e4 92
75c43a20 93static int oprofile_hrtimer_setup(void)
1da177e4 94{
a4e0591e
SAS
95 int ret;
96
97 ret = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN,
98 "oprofile/timer:online",
99 oprofile_timer_online,
100 oprofile_timer_prep_down);
101 if (ret < 0)
102 return ret;
103 hp_online = ret;
104 return 0;
bc078e4e
MS
105}
106
75c43a20 107static void oprofile_hrtimer_shutdown(void)
bc078e4e 108{
a4e0591e 109 cpuhp_remove_state_nocalls(hp_online);
1da177e4 110}
75c43a20
RR
111
112int oprofile_timer_init(struct oprofile_operations *ops)
113{
114 ops->create_files = NULL;
115 ops->setup = oprofile_hrtimer_setup;
116 ops->shutdown = oprofile_hrtimer_shutdown;
117 ops->start = oprofile_hrtimer_start;
118 ops->stop = oprofile_hrtimer_stop;
119 ops->cpu_type = "timer";
120 printk(KERN_INFO "oprofile: using timer interrupt.\n");
121 return 0;
122}