2 * Copyright (c) 2005-2007, Joseph Koshy
3 * Copyright (c) 2007 The FreeBSD Foundation
6 * Portions of this software were developed by A. Joseph Koshy under
7 * sponsorship from the FreeBSD Foundation and Google, Inc.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #ifndef _SYS_PMCLOG_H_
34 #define _SYS_PMCLOG_H_
41 PMCLOG_TYPE_DROPNOTIFY,
42 PMCLOG_TYPE_INITIALIZE,
43 PMCLOG_TYPE_MAPPINGCHANGE, /* unused in v1 */
45 PMCLOG_TYPE_PMCALLOCATE,
46 PMCLOG_TYPE_PMCATTACH,
47 PMCLOG_TYPE_PMCDETACH,
57 * The MAP_{IN,OUT} event types obsolete the MAPPING_CHANGE
58 * event type. The CALLCHAIN event type obsoletes the
59 * PCSAMPLE event type.
67 * A log entry descriptor comprises of a 32 bit header and a 64 bit
68 * time stamp followed by as many 32 bit words are required to record
71 * Header field format:
74 * +------------+------------+-----------------------------------+
75 * | MAGIC | TYPE | LENGTH |
76 * +------------+------------+-----------------------------------+
78 * MAGIC is the constant PMCLOG_HEADER_MAGIC.
79 * TYPE contains a value of type enum pmclog_type.
80 * LENGTH contains the length of the event record, in bytes.
83 #define PMCLOG_ENTRY_HEADER \
90 * The following structures are used to describe the size of each kind
91 * of log entry to sizeof(). To keep the compiler from adding
92 * padding, the fields of each structure are aligned to their natural
93 * boundaries, and the structures are marked as 'packed'.
95 * The actual reading and writing of the log file is always in terms
96 * of 4 byte quantities.
99 struct pmclog_callchain {
103 uint32_t pl_cpuflags;
105 uintptr_t pl_pc[PMC_CALLCHAIN_DEPTH_MAX];
108 #define PMC_CALLCHAIN_CPUFLAGS_TO_CPU(CF) (((CF) >> 16) & 0xFFFF)
109 #define PMC_CALLCHAIN_CPUFLAGS_TO_USERMODE(CF) ((CF) & PMC_CC_F_USERSPACE)
110 #define PMC_CALLCHAIN_TO_CPUFLAGS(CPU,FLAGS) \
111 (((CPU) << 16) | ((FLAGS) & 0xFFFF))
113 struct pmclog_closelog {
117 struct pmclog_dropnotify {
121 struct pmclog_initialize {
123 uint32_t pl_version; /* driver version */
124 uint32_t pl_cpu; /* enum pmc_cputype */
127 struct pmclog_map_in {
130 uintfptr_t pl_start; /* 8 byte aligned */
131 char pl_pathname[PATH_MAX];
134 struct pmclog_map_out {
137 uintfptr_t pl_start; /* 8 byte aligned */
141 struct pmclog_pcsample {
144 uintfptr_t pl_pc; /* 8 byte aligned */
146 uint32_t pl_usermode;
149 struct pmclog_pmcallocate {
156 struct pmclog_pmcattach {
160 char pl_pathname[PATH_MAX];
163 struct pmclog_pmcdetach {
169 struct pmclog_proccsw {
172 uint64_t pl_value; /* keep 8 byte aligned */
176 struct pmclog_procexec {
179 uintfptr_t pl_start; /* keep 8 byte aligned */
181 char pl_pathname[PATH_MAX];
184 struct pmclog_procexit {
187 uint64_t pl_value; /* keep 8 byte aligned */
191 struct pmclog_procfork {
197 struct pmclog_sysexit {
202 struct pmclog_userdata {
204 uint32_t pl_userdata;
207 union pmclog_entry { /* only used to size scratch areas */
208 struct pmclog_callchain pl_cc;
209 struct pmclog_closelog pl_cl;
210 struct pmclog_dropnotify pl_dn;
211 struct pmclog_initialize pl_i;
212 struct pmclog_map_in pl_mi;
213 struct pmclog_map_out pl_mo;
214 struct pmclog_pcsample pl_s;
215 struct pmclog_pmcallocate pl_a;
216 struct pmclog_pmcattach pl_t;
217 struct pmclog_pmcdetach pl_d;
218 struct pmclog_proccsw pl_c;
219 struct pmclog_procexec pl_x;
220 struct pmclog_procexit pl_e;
221 struct pmclog_procfork pl_f;
222 struct pmclog_sysexit pl_se;
223 struct pmclog_userdata pl_u;
226 #define PMCLOG_HEADER_MAGIC 0xEEU
228 #define PMCLOG_HEADER_TO_LENGTH(H) \
230 #define PMCLOG_HEADER_TO_TYPE(H) \
231 (((H) & 0x00FF0000) >> 16)
232 #define PMCLOG_HEADER_TO_MAGIC(H) \
233 (((H) & 0xFF000000) >> 24)
234 #define PMCLOG_HEADER_CHECK_MAGIC(H) \
235 (PMCLOG_HEADER_TO_MAGIC(H) == PMCLOG_HEADER_MAGIC)
242 int pmclog_configure_log(struct pmc_owner *_po, int _logfd);
243 int pmclog_deconfigure_log(struct pmc_owner *_po);
244 int pmclog_flush(struct pmc_owner *_po);
245 void pmclog_initialize(void);
246 void pmclog_process_callchain(struct pmc *_pm, struct pmc_sample *_ps);
247 void pmclog_process_closelog(struct pmc_owner *po);
248 void pmclog_process_dropnotify(struct pmc_owner *po);
249 void pmclog_process_map_in(struct pmc_owner *po, pid_t pid,
250 uintfptr_t start, const char *path);
251 void pmclog_process_map_out(struct pmc_owner *po, pid_t pid,
252 uintfptr_t start, uintfptr_t end);
253 void pmclog_process_pmcallocate(struct pmc *_pm);
254 void pmclog_process_pmcattach(struct pmc *_pm, pid_t _pid, char *_path);
255 void pmclog_process_pmcdetach(struct pmc *_pm, pid_t _pid);
256 void pmclog_process_proccsw(struct pmc *_pm, struct pmc_process *_pp,
258 void pmclog_process_procexec(struct pmc_owner *_po, pmc_id_t _pmid, pid_t _pid,
259 uintfptr_t _startaddr, char *_path);
260 void pmclog_process_procexit(struct pmc *_pm, struct pmc_process *_pp);
261 void pmclog_process_procfork(struct pmc_owner *_po, pid_t _oldpid, pid_t _newpid);
262 void pmclog_process_sysexit(struct pmc_owner *_po, pid_t _pid);
263 int pmclog_process_userlog(struct pmc_owner *_po,
264 struct pmc_op_writelog *_wl);
265 void pmclog_shutdown(void);
268 #endif /* _SYS_PMCLOG_H_ */