2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
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
35 #ifndef _SYS_PMCLOG_H_
36 #define _SYS_PMCLOG_H_
42 PMCLOG_TYPE_CLOSELOG = 1,
43 PMCLOG_TYPE_DROPNOTIFY = 2,
44 PMCLOG_TYPE_INITIALIZE = 3,
45 PMCLOG_TYPE_MAPPINGCHANGE = 4, /* unused in v1 */
46 PMCLOG_TYPE_PMCALLOCATE = 5,
47 PMCLOG_TYPE_PMCATTACH = 6,
48 PMCLOG_TYPE_PMCDETACH = 7,
49 PMCLOG_TYPE_PROCCSW = 8,
50 PMCLOG_TYPE_PROCEXEC = 9,
51 PMCLOG_TYPE_PROCEXIT = 10,
52 PMCLOG_TYPE_PROCFORK = 11,
53 PMCLOG_TYPE_SYSEXIT = 12,
54 PMCLOG_TYPE_USERDATA = 13,
58 * The MAP_{IN,OUT} event types obsolete the MAPPING_CHANGE
59 * event type. The CALLCHAIN event type obsoletes the
60 * PCSAMPLE event type.
62 PMCLOG_TYPE_MAP_IN = 14,
63 PMCLOG_TYPE_MAP_OUT = 15,
64 PMCLOG_TYPE_CALLCHAIN = 16,
68 * New variant of PMCLOG_TYPE_PMCALLOCATE for dynamic event.
70 PMCLOG_TYPE_PMCALLOCATEDYN = 17
74 * A log entry descriptor comprises of a 32 bit header and a 64 bit
75 * time stamp followed by as many 32 bit words are required to record
78 * Header field format:
81 * +------------+------------+-----------------------------------+
82 * | MAGIC | TYPE | LENGTH |
83 * +------------+------------+-----------------------------------+
85 * MAGIC is the constant PMCLOG_HEADER_MAGIC.
86 * TYPE contains a value of type enum pmclog_type.
87 * LENGTH contains the length of the event record, in bytes.
90 #define PMCLOG_ENTRY_HEADER \
97 * The following structures are used to describe the size of each kind
98 * of log entry to sizeof(). To keep the compiler from adding
99 * padding, the fields of each structure are aligned to their natural
100 * boundaries, and the structures are marked as 'packed'.
102 * The actual reading and writing of the log file is always in terms
103 * of 4 byte quantities.
106 struct pmclog_callchain {
111 uint32_t pl_cpuflags;
112 uint32_t pl_cpuflags2;
114 uintptr_t pl_pc[PMC_CALLCHAIN_DEPTH_MAX];
117 #define PMC_CALLCHAIN_CPUFLAGS_TO_CPU(CF) (((CF) >> 16) & 0xFFFF)
118 #define PMC_CALLCHAIN_CPUFLAGS_TO_USERMODE(CF) ((CF) & PMC_CC_F_USERSPACE)
119 #define PMC_CALLCHAIN_TO_CPUFLAGS(CPU,FLAGS) \
120 (((CPU) << 16) | ((FLAGS) & 0xFFFF))
122 struct pmclog_closelog {
127 struct pmclog_dropnotify {
132 struct pmclog_initialize {
134 uint32_t pl_version; /* driver version */
135 uint32_t pl_cpu; /* enum pmc_cputype */
139 struct pmclog_map_in {
142 uintfptr_t pl_start; /* 8 byte aligned */
143 char pl_pathname[PATH_MAX];
146 struct pmclog_map_out {
149 uintfptr_t pl_start; /* 8 byte aligned */
153 struct pmclog_pmcallocate {
160 struct pmclog_pmcattach {
165 char pl_pathname[PATH_MAX];
168 struct pmclog_pmcdetach {
175 struct pmclog_proccsw {
178 uint64_t pl_value; /* keep 8 byte aligned */
183 struct pmclog_procexec {
188 uintfptr_t pl_start; /* keep 8 byte aligned */
189 char pl_pathname[PATH_MAX];
192 struct pmclog_procexit {
197 uint64_t pl_value; /* keep 8 byte aligned */
200 struct pmclog_procfork {
207 struct pmclog_sysexit {
212 struct pmclog_userdata {
214 uint32_t pl_userdata;
217 struct pmclog_pmcallocatedyn {
222 char pl_evname[PMC_NAME_MAX];
225 union pmclog_entry { /* only used to size scratch areas */
226 struct pmclog_callchain pl_cc;
227 struct pmclog_closelog pl_cl;
228 struct pmclog_dropnotify pl_dn;
229 struct pmclog_initialize pl_i;
230 struct pmclog_map_in pl_mi;
231 struct pmclog_map_out pl_mo;
232 struct pmclog_pmcallocate pl_a;
233 struct pmclog_pmcallocatedyn pl_ad;
234 struct pmclog_pmcattach pl_t;
235 struct pmclog_pmcdetach pl_d;
236 struct pmclog_proccsw pl_c;
237 struct pmclog_procexec pl_x;
238 struct pmclog_procexit pl_e;
239 struct pmclog_procfork pl_f;
240 struct pmclog_sysexit pl_se;
241 struct pmclog_userdata pl_u;
244 #define PMCLOG_HEADER_MAGIC 0xEEU
246 #define PMCLOG_HEADER_TO_LENGTH(H) \
248 #define PMCLOG_HEADER_TO_TYPE(H) \
249 (((H) & 0x00FF0000) >> 16)
250 #define PMCLOG_HEADER_TO_MAGIC(H) \
251 (((H) & 0xFF000000) >> 24)
252 #define PMCLOG_HEADER_CHECK_MAGIC(H) \
253 (PMCLOG_HEADER_TO_MAGIC(H) == PMCLOG_HEADER_MAGIC)
260 int pmclog_configure_log(struct pmc_mdep *_md, struct pmc_owner *_po,
262 int pmclog_deconfigure_log(struct pmc_owner *_po);
263 int pmclog_flush(struct pmc_owner *_po);
264 int pmclog_close(struct pmc_owner *_po);
265 void pmclog_initialize(void);
266 int pmclog_proc_create(struct thread *td, void **handlep);
267 void pmclog_proc_ignite(void *handle, struct pmc_owner *po);
268 void pmclog_process_callchain(struct pmc *_pm, struct pmc_sample *_ps);
269 void pmclog_process_closelog(struct pmc_owner *po);
270 void pmclog_process_dropnotify(struct pmc_owner *po);
271 void pmclog_process_map_in(struct pmc_owner *po, pid_t pid,
272 uintfptr_t start, const char *path);
273 void pmclog_process_map_out(struct pmc_owner *po, pid_t pid,
274 uintfptr_t start, uintfptr_t end);
275 void pmclog_process_pmcallocate(struct pmc *_pm);
276 void pmclog_process_pmcattach(struct pmc *_pm, pid_t _pid, char *_path);
277 void pmclog_process_pmcdetach(struct pmc *_pm, pid_t _pid);
278 void pmclog_process_proccsw(struct pmc *_pm, struct pmc_process *_pp,
279 pmc_value_t _v, struct thread *);
280 void pmclog_process_procexec(struct pmc_owner *_po, pmc_id_t _pmid, pid_t _pid,
281 uintfptr_t _startaddr, char *_path);
282 void pmclog_process_procexit(struct pmc *_pm, struct pmc_process *_pp);
283 void pmclog_process_procfork(struct pmc_owner *_po, pid_t _oldpid, pid_t _newpid);
284 void pmclog_process_sysexit(struct pmc_owner *_po, pid_t _pid);
285 int pmclog_process_userlog(struct pmc_owner *_po,
286 struct pmc_op_writelog *_wl);
287 void pmclog_shutdown(void);
290 #endif /* _SYS_PMCLOG_H_ */