- supported.conf: Added sparse_keymap (eeepc_laptop depends on it)
[linux-flexiantxendom0-3.2.10.git] / perfmon / perfmon_priv.h
1 /*
2  * Copyright (c) 2001-2006 Hewlett-Packard Development Company, L.P.
3  * Contributed by Stephane Eranian <eranian@hpl.hp.com>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of version 2 of the GNU General Public
7  * License as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17  * 02111-1307 USA
18  */
19
20 #ifndef __PERFMON_PRIV_H__
21 #define __PERFMON_PRIV_H__
22 /*
23  * This file contains all the definitions of data structures, variables, macros
24  * that are to private to the generic code, i.e., not shared with any code that
25  * lives under arch/ or include/asm-XX
26  *
27  * For shared definitions, use include/linux/perfmon_kern.h
28  */
29
30 #ifdef CONFIG_PERFMON
31
32 /*
33  * type of PMD reset for pfm_reset_pmds() or pfm_switch_sets*()
34  */
35 #define PFM_PMD_RESET_SHORT     1       /* use short reset value */
36 #define PFM_PMD_RESET_LONG      2       /* use long reset value  */
37
38 /*
39  * context lazy save/restore activation count
40  */
41 #define PFM_INVALID_ACTIVATION  ((u64)~0)
42
43 DECLARE_PER_CPU(u64, pmu_activation_number);
44 DECLARE_PER_CPU(struct hrtimer, pfm_hrtimer);
45
46 static inline void pfm_set_pmu_owner(struct task_struct *task,
47                                      struct pfm_context *ctx)
48 {
49         __get_cpu_var(pmu_owner) = task;
50         __get_cpu_var(pmu_ctx) = ctx;
51 }
52
53 static inline int pfm_msgq_is_empty(struct pfm_context *ctx)
54 {
55         return ctx->msgq_head == ctx->msgq_tail;
56 }
57
58 void pfm_get_next_msg(struct pfm_context *ctx, union pfarg_msg *m);
59 int pfm_end_notify(struct pfm_context *ctx);
60 int pfm_ovfl_notify(struct pfm_context *ctx, struct pfm_event_set *set,
61                     unsigned long ip);
62
63 int pfm_alloc_fd(struct pfm_context *ctx);
64
65 int __pfm_delete_evtsets(struct pfm_context *ctx, void *arg, int count);
66 int __pfm_getinfo_evtsets(struct pfm_context *ctx, struct pfarg_setinfo *req,
67                           int count);
68 int __pfm_create_evtsets(struct pfm_context *ctx, struct pfarg_setdesc *req,
69                         int count);
70
71
72 int pfm_init_ctx(void);
73
74 int pfm_pmu_acquire(struct pfm_context *ctx);
75 void pfm_pmu_release(void);
76
77 int pfm_session_acquire(int is_system, u32 cpu);
78 void pfm_session_release(int is_system, u32 cpu);
79
80 int pfm_smpl_buf_space_acquire(struct pfm_context *ctx, size_t size);
81 int pfm_smpl_buf_load_context(struct pfm_context *ctx);
82 void pfm_smpl_buf_unload_context(struct pfm_context *ctx);
83
84 int  pfm_init_sysfs(void);
85
86 #ifdef CONFIG_PERFMON_DEBUG_FS
87 int  pfm_init_debugfs(void);
88 int pfm_debugfs_add_cpu(int mycpu);
89 void pfm_debugfs_del_cpu(int mycpu);
90 #else
91 static inline int pfm_init_debugfs(void)
92 {
93         return 0;
94 }
95 static inline int pfm_debugfs_add_cpu(int mycpu)
96 {
97         return 0;
98 }
99
100 static inline void pfm_debugfs_del_cpu(int mycpu)
101 {}
102 #endif
103
104
105 void pfm_reset_pmds(struct pfm_context *ctx, struct pfm_event_set *set,
106                     int num_pmds,
107                     int reset_mode);
108
109 struct pfm_event_set *pfm_prepare_sets(struct pfm_context *ctx, u16 load_set);
110 int pfm_init_sets(void);
111
112 ssize_t pfm_sysfs_res_show(char *buf, size_t sz, int what);
113
114 void pfm_free_sets(struct pfm_context *ctx);
115 int pfm_create_initial_set(struct pfm_context *ctx);
116 void pfm_switch_sets_from_intr(struct pfm_context *ctx);
117 void pfm_restart_timer(struct pfm_context *ctx, struct pfm_event_set *set);
118 enum hrtimer_restart pfm_handle_switch_timeout(struct hrtimer *t);
119
120 enum hrtimer_restart pfm_switch_sets(struct pfm_context *ctx,
121                     struct pfm_event_set *new_set,
122                     int reset_mode,
123                     int no_restart);
124
125 /**
126  * pfm_save_prev_ctx - check if previous context exists and save state
127  *
128  * called from pfm_load_ctx_thread() and __pfm_ctxsin_thread() to
129  * check if previous context exists. If so saved its PMU state. This is used
130  * only for UP kernels.
131  *
132  * PMU ownership is not cleared because the function is always called while
133  * trying to install a new owner.
134  */
135 static inline void pfm_check_save_prev_ctx(void)
136 {
137 #ifndef CONFIG_SMP
138         struct pfm_event_set *set;
139         struct pfm_context *ctxp;
140
141         ctxp = __get_cpu_var(pmu_ctx);
142         if (!ctxp)
143                 return;
144         /*
145          * in UP per-thread, due to lazy save
146          * there could be a context from another
147          * task. We need to push it first before
148          * installing our new state
149          */
150         set = ctxp->active_set;
151         pfm_save_pmds(ctxp, set);
152         /*
153          * do not clear ownership because we rewrite
154          * right away
155          */
156 #endif
157 }
158
159 int pfm_init_hotplug(void);
160 int pfm_init_control(void);
161
162 void pfm_mask_monitoring(struct pfm_context *ctx, struct pfm_event_set *set);
163 void pfm_resume_after_ovfl(struct pfm_context *ctx);
164 int pfm_setup_smpl_fmt(struct pfm_context *ctx, u32 ctx_flags, void *fmt_arg, int fd);
165
166 static inline void pfm_post_work(struct task_struct *task,
167                                  struct pfm_context *ctx, int type)
168 {
169         ctx->flags.work_type = type;
170         set_tsk_thread_flag(task, TIF_PERFMON_WORK);
171         pfm_arch_arm_handle_work(task);
172 }
173
174 #define PFM_PMC_STK_ARG PFM_ARCH_PMC_STK_ARG
175 #define PFM_PMD_STK_ARG PFM_ARCH_PMD_STK_ARG
176
177 /* these used to be in linux/syscalls.h, now accessed via ioctl interface */
178 asmlinkage long sys_pfm_create_context(struct pfarg_ctx __user *ureq,
179                                        char __user *fmt_name,
180                                        void __user *fmt_uarg, size_t fmt_size);
181 asmlinkage long sys_pfm_write_pmcs(int fd, struct pfarg_pmc __user *ureq,
182                                    int count);
183 asmlinkage long sys_pfm_write_pmds(int fd, struct pfarg_pmd __user *ureq,
184                                    int count);
185 asmlinkage long sys_pfm_read_pmds(int fd, struct pfarg_pmd __user *ureq,
186                                   int count);
187 asmlinkage long sys_pfm_restart(int fd);
188 asmlinkage long sys_pfm_stop(int fd);
189 asmlinkage long sys_pfm_start(int fd, struct pfarg_start __user *ureq);
190 asmlinkage long sys_pfm_load_context(int fd, struct pfarg_load __user *ureq);
191 asmlinkage long sys_pfm_unload_context(int fd);
192 asmlinkage long sys_pfm_delete_evtsets(int fd,
193                                        struct pfarg_setinfo __user *ureq,
194                                        int count);
195 asmlinkage long sys_pfm_create_evtsets(int fd,
196                                        struct pfarg_setdesc __user *ureq,
197                                        int count);
198 asmlinkage long sys_pfm_getinfo_evtsets(int fd,
199                                         struct pfarg_setinfo __user *ureq,
200                                         int count);
201 #endif /* CONFIG_PERFMON */
202
203 #endif /* __PERFMON_PRIV_H__ */