2 * Copyright (c) 2001-2006 Hewlett-Packard Development Company, L.P.
3 * Contributed by Stephane Eranian <eranian@hpl.hp.com>
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.
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.
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
20 #ifndef __PERFMON_PRIV_H__
21 #define __PERFMON_PRIV_H__
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
27 * For shared definitions, use include/linux/perfmon_kern.h
33 * type of PMD reset for pfm_reset_pmds() or pfm_switch_sets*()
35 #define PFM_PMD_RESET_SHORT 1 /* use short reset value */
36 #define PFM_PMD_RESET_LONG 2 /* use long reset value */
39 * context lazy save/restore activation count
41 #define PFM_INVALID_ACTIVATION ((u64)~0)
43 DECLARE_PER_CPU(u64, pmu_activation_number);
44 DECLARE_PER_CPU(struct hrtimer, pfm_hrtimer);
46 static inline void pfm_set_pmu_owner(struct task_struct *task,
47 struct pfm_context *ctx)
49 __get_cpu_var(pmu_owner) = task;
50 __get_cpu_var(pmu_ctx) = ctx;
53 static inline int pfm_msgq_is_empty(struct pfm_context *ctx)
55 return ctx->msgq_head == ctx->msgq_tail;
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,
63 int pfm_alloc_fd(struct pfm_context *ctx);
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,
68 int __pfm_create_evtsets(struct pfm_context *ctx, struct pfarg_setdesc *req,
72 int pfm_init_ctx(void);
74 int pfm_pmu_acquire(struct pfm_context *ctx);
75 void pfm_pmu_release(void);
77 int pfm_session_acquire(int is_system, u32 cpu);
78 void pfm_session_release(int is_system, u32 cpu);
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);
84 int pfm_init_sysfs(void);
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);
91 static inline int pfm_init_debugfs(void)
95 static inline int pfm_debugfs_add_cpu(int mycpu)
100 static inline void pfm_debugfs_del_cpu(int mycpu)
105 void pfm_reset_pmds(struct pfm_context *ctx, struct pfm_event_set *set,
109 struct pfm_event_set *pfm_prepare_sets(struct pfm_context *ctx, u16 load_set);
110 int pfm_init_sets(void);
112 ssize_t pfm_sysfs_res_show(char *buf, size_t sz, int what);
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);
120 enum hrtimer_restart pfm_switch_sets(struct pfm_context *ctx,
121 struct pfm_event_set *new_set,
126 * pfm_save_prev_ctx - check if previous context exists and save state
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.
132 * PMU ownership is not cleared because the function is always called while
133 * trying to install a new owner.
135 static inline void pfm_check_save_prev_ctx(void)
138 struct pfm_event_set *set;
139 struct pfm_context *ctxp;
141 ctxp = __get_cpu_var(pmu_ctx);
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
150 set = ctxp->active_set;
151 pfm_save_pmds(ctxp, set);
153 * do not clear ownership because we rewrite
159 int pfm_init_hotplug(void);
160 int pfm_init_control(void);
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);
166 static inline void pfm_post_work(struct task_struct *task,
167 struct pfm_context *ctx, int type)
169 ctx->flags.work_type = type;
170 set_tsk_thread_flag(task, TIF_PERFMON_WORK);
171 pfm_arch_arm_handle_work(task);
174 #define PFM_PMC_STK_ARG PFM_ARCH_PMC_STK_ARG
175 #define PFM_PMD_STK_ARG PFM_ARCH_PMD_STK_ARG
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,
183 asmlinkage long sys_pfm_write_pmds(int fd, struct pfarg_pmd __user *ureq,
185 asmlinkage long sys_pfm_read_pmds(int fd, struct pfarg_pmd __user *ureq,
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,
195 asmlinkage long sys_pfm_create_evtsets(int fd,
196 struct pfarg_setdesc __user *ureq,
198 asmlinkage long sys_pfm_getinfo_evtsets(int fd,
199 struct pfarg_setinfo __user *ureq,
201 #endif /* CONFIG_PERFMON */
203 #endif /* __PERFMON_PRIV_H__ */