2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2005-2007, Joseph Koshy
5 * Copyright (c) 2007 The FreeBSD Foundation
8 * Portions of this software were developed by A. Joseph Koshy under
9 * sponsorship from the FreeBSD Foundation and Google, Inc.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #ifndef _SYS_PMCLOG_H_
34 #define _SYS_PMCLOG_H_
40 PMCLOG_TYPE_CLOSELOG = 1,
41 PMCLOG_TYPE_DROPNOTIFY = 2,
42 PMCLOG_TYPE_INITIALIZE = 3,
44 PMCLOG_TYPE_PMCALLOCATE = 5,
45 PMCLOG_TYPE_PMCATTACH = 6,
46 PMCLOG_TYPE_PMCDETACH = 7,
47 PMCLOG_TYPE_PROCCSW = 8,
48 PMCLOG_TYPE_PROCEXEC = 9,
49 PMCLOG_TYPE_PROCEXIT = 10,
50 PMCLOG_TYPE_PROCFORK = 11,
51 PMCLOG_TYPE_SYSEXIT = 12,
52 PMCLOG_TYPE_USERDATA = 13,
56 * The MAP_{IN,OUT} event types obsolete the MAPPING_CHANGE
57 * event type. The CALLCHAIN event type obsoletes the
58 * PCSAMPLE event type.
60 PMCLOG_TYPE_MAP_IN = 14,
61 PMCLOG_TYPE_MAP_OUT = 15,
62 PMCLOG_TYPE_CALLCHAIN = 16,
66 * New variant of PMCLOG_TYPE_PMCALLOCATE for dynamic event.
68 PMCLOG_TYPE_PMCALLOCATEDYN = 17,
72 PMCLOG_TYPE_THR_CREATE = 18,
73 PMCLOG_TYPE_THR_EXIT = 19,
74 PMCLOG_TYPE_PROC_CREATE = 20
78 * A log entry descriptor comprises of a 32 bit header and a 64 bit
79 * time stamp followed by as many 32 bit words are required to record
82 * Header field format:
85 * +------------+------------+-----------------------------------+
86 * | MAGIC | TYPE | LENGTH |
87 * +------------+------------+-----------------------------------+
89 * MAGIC is the constant PMCLOG_HEADER_MAGIC.
90 * TYPE contains a value of type enum pmclog_type.
91 * LENGTH contains the length of the event record, in bytes.
94 #define PMCLOG_ENTRY_HEADER \
99 struct pmclog_header {
104 * The following structures are used to describe the size of each kind
105 * of log entry to sizeof(). To keep the compiler from adding
106 * padding, the fields of each structure are aligned to their natural
107 * boundaries, and the structures are marked as 'packed'.
109 * The actual reading and writing of the log file is always in terms
110 * of 4 byte quantities.
113 struct pmclog_callchain {
118 uint32_t pl_cpuflags;
120 uintptr_t pl_pc[PMC_CALLCHAIN_DEPTH_MAX];
123 #define PMC_CALLCHAIN_CPUFLAGS_TO_CPU(CF) (((CF) >> 16) & 0xFFFF)
124 #define PMC_CALLCHAIN_CPUFLAGS_TO_USERMODE(CF) ((CF) & PMC_CC_F_USERSPACE)
125 #define PMC_CALLCHAIN_TO_CPUFLAGS(CPU,FLAGS) \
126 (((CPU) << 16) | ((FLAGS) & 0xFFFF))
128 struct pmclog_closelog {
132 struct pmclog_dropnotify {
136 struct pmclog_initialize {
138 uint32_t pl_version; /* driver version */
139 uint32_t pl_cpu; /* enum pmc_cputype */
140 uint64_t pl_tsc_freq;
141 struct timespec pl_ts;
142 char pl_cpuid[PMC_CPUID_LEN];
145 struct pmclog_map_in {
149 uintfptr_t pl_start; /* 8 byte aligned */
150 char pl_pathname[PATH_MAX];
153 struct pmclog_map_out {
157 uintfptr_t pl_start; /* 8 byte aligned */
161 struct pmclog_pmcallocate {
170 struct pmclog_pmcattach {
174 char pl_pathname[PATH_MAX];
177 struct pmclog_pmcdetach {
183 struct pmclog_proccsw {
185 uint64_t pl_value; /* keep 8 byte aligned */
192 struct pmclog_proccreate {
196 char pl_pcomm[MAXCOMLEN+1]; /* keep 8 byte aligned */
199 struct pmclog_procexec {
203 /* keep 8 byte aligned */
204 uintptr_t pl_base; /* AT_BASE */
205 /* keep 8 byte aligned */
206 uintptr_t pl_dyn; /* PIE load base */
207 char pl_pathname[PATH_MAX];
210 struct pmclog_procexit {
214 uint64_t pl_value; /* keep 8 byte aligned */
217 struct pmclog_procfork {
223 struct pmclog_sysexit {
229 struct pmclog_threadcreate {
235 char pl_tdname[MAXCOMLEN+1]; /* keep 8 byte aligned */
238 struct pmclog_threadexit {
244 struct pmclog_userdata {
246 uint32_t pl_userdata;
250 struct pmclog_pmcallocatedyn {
256 char pl_evname[PMC_NAME_MAX];
259 union pmclog_entry { /* only used to size scratch areas */
260 struct pmclog_callchain pl_cc;
261 struct pmclog_closelog pl_cl;
262 struct pmclog_dropnotify pl_dn;
263 struct pmclog_initialize pl_i;
264 struct pmclog_map_in pl_mi;
265 struct pmclog_map_out pl_mo;
266 struct pmclog_pmcallocate pl_a;
267 struct pmclog_pmcallocatedyn pl_ad;
268 struct pmclog_pmcattach pl_t;
269 struct pmclog_pmcdetach pl_d;
270 struct pmclog_proccsw pl_c;
271 struct pmclog_proccreate pl_pc;
272 struct pmclog_procexec pl_x;
273 struct pmclog_procexit pl_e;
274 struct pmclog_procfork pl_f;
275 struct pmclog_sysexit pl_se;
276 struct pmclog_threadcreate pl_tc;
277 struct pmclog_threadexit pl_te;
278 struct pmclog_userdata pl_u;
281 #define PMCLOG_HEADER_MAGIC 0xEEU
283 #define PMCLOG_HEADER_TO_LENGTH(H) \
285 #define PMCLOG_HEADER_TO_TYPE(H) \
286 (((H) & 0x00FF0000) >> 16)
287 #define PMCLOG_HEADER_TO_MAGIC(H) \
288 (((H) & 0xFF000000) >> 24)
289 #define PMCLOG_HEADER_CHECK_MAGIC(H) \
290 (PMCLOG_HEADER_TO_MAGIC(H) == PMCLOG_HEADER_MAGIC)
297 int pmclog_configure_log(struct pmc_mdep *_md, struct pmc_owner *_po,
299 int pmclog_deconfigure_log(struct pmc_owner *_po);
300 int pmclog_flush(struct pmc_owner *_po, int force);
301 int pmclog_close(struct pmc_owner *_po);
302 void pmclog_initialize(void);
303 int pmclog_proc_create(struct thread *td, void **handlep);
304 void pmclog_proc_ignite(void *handle, struct pmc_owner *po);
305 void pmclog_process_callchain(struct pmc *_pm, struct pmc_sample *_ps);
306 void pmclog_process_closelog(struct pmc_owner *po);
307 void pmclog_process_dropnotify(struct pmc_owner *po);
308 void pmclog_process_map_in(struct pmc_owner *po, pid_t pid,
309 uintfptr_t start, const char *path);
310 void pmclog_process_map_out(struct pmc_owner *po, pid_t pid,
311 uintfptr_t start, uintfptr_t end);
312 void pmclog_process_pmcallocate(struct pmc *_pm);
313 void pmclog_process_pmcattach(struct pmc *_pm, pid_t _pid, char *_path);
314 void pmclog_process_pmcdetach(struct pmc *_pm, pid_t _pid);
315 void pmclog_process_proccsw(struct pmc *_pm, struct pmc_process *_pp,
316 pmc_value_t _v, struct thread *);
317 void pmclog_process_procexec(struct pmc_owner *_po, pmc_id_t _pmid, pid_t _pid,
318 uintfptr_t _baseaddr, uintptr_t _dynaddr, char *_path);
319 void pmclog_process_procexit(struct pmc *_pm, struct pmc_process *_pp);
320 void pmclog_process_procfork(struct pmc_owner *_po, pid_t _oldpid, pid_t _newpid);
321 void pmclog_process_sysexit(struct pmc_owner *_po, pid_t _pid);
322 void pmclog_process_threadcreate(struct pmc_owner *_po, struct thread *td, int sync);
323 void pmclog_process_threadexit(struct pmc_owner *_po, struct thread *td);
324 void pmclog_process_proccreate(struct pmc_owner *_po, struct proc *p, int sync);
325 int pmclog_process_userlog(struct pmc_owner *_po,
326 struct pmc_op_writelog *_wl);
327 void pmclog_shutdown(void);
330 #endif /* _SYS_PMCLOG_H_ */