2 * Copyright (c) 2005 Joseph Koshy
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #ifndef _SYS_PMCLOG_H_
30 #define _SYS_PMCLOG_H_
36 PMCLOG_TYPE_DROPNOTIFY,
37 PMCLOG_TYPE_INITIALIZE,
38 PMCLOG_TYPE_MAPPINGCHANGE,
40 PMCLOG_TYPE_PMCALLOCATE,
41 PMCLOG_TYPE_PMCATTACH,
42 PMCLOG_TYPE_PMCDETACH,
51 #define PMCLOG_MAPPING_INSERT 0x01
52 #define PMCLOG_MAPPING_DELETE 0x02
55 * A log entry descriptor comprises of a 32 bit header and a 64 bit
56 * time stamp followed by as many 32 bit words are required to record
59 * Header field format:
62 * +------------+------------+-----------------------------------+
63 * | MAGIC | TYPE | LENGTH |
64 * +------------+------------+-----------------------------------+
66 * MAGIC is the constant PMCLOG_HEADER_MAGIC.
67 * TYPE contains a value of type enum pmclog_type.
68 * LENGTH contains the length of the event record, in bytes.
71 #define PMCLOG_ENTRY_HEADER \
78 * The following structures are used to describe the size of each kind
79 * of log entry to sizeof(). To keep the compiler from adding
80 * padding, the fields of each structure are aligned to their natural
81 * boundaries, and the structures are marked as 'packed'.
83 * The actual reading and writing of the log file is always in terms
84 * of 4 byte quantities.
87 struct pmclog_closelog {
91 struct pmclog_dropnotify {
95 struct pmclog_initialize {
97 uint32_t pl_version; /* driver version */
98 uint32_t pl_cpu; /* enum pmc_cputype */
101 struct pmclog_mappingchange {
104 uintfptr_t pl_start; /* 8 byte aligned */
107 char pl_pathname[PATH_MAX];
111 struct pmclog_pcsample {
114 uintfptr_t pl_pc; /* 8 byte aligned */
118 struct pmclog_pmcallocate {
125 struct pmclog_pmcattach {
129 char pl_pathname[PATH_MAX];
132 struct pmclog_pmcdetach {
138 struct pmclog_proccsw {
141 uint64_t pl_value; /* keep 8 byte aligned */
145 struct pmclog_procexec {
148 char pl_pathname[PATH_MAX];
151 struct pmclog_procexit {
154 uint64_t pl_value; /* keep 8 byte aligned */
158 struct pmclog_procfork {
164 struct pmclog_sysexit {
169 struct pmclog_userdata {
171 uint32_t pl_userdata;
174 union pmclog_entry { /* only used to size scratch areas */
175 struct pmclog_closelog pl_cl;
176 struct pmclog_dropnotify pl_dn;
177 struct pmclog_initialize pl_i;
178 struct pmclog_pcsample pl_s;
179 struct pmclog_pmcallocate pl_a;
180 struct pmclog_pmcattach pl_t;
181 struct pmclog_pmcdetach pl_d;
182 struct pmclog_proccsw pl_c;
183 struct pmclog_procexec pl_x;
184 struct pmclog_procexit pl_e;
185 struct pmclog_procfork pl_f;
186 struct pmclog_sysexit pl_se;
187 struct pmclog_userdata pl_u;
190 #define PMCLOG_HEADER_MAGIC 0xEEU
192 #define PMCLOG_HEADER_TO_LENGTH(H) \
194 #define PMCLOG_HEADER_TO_TYPE(H) \
195 (((H) & 0x00FF0000) >> 16)
196 #define PMCLOG_HEADER_TO_MAGIC(H) \
197 (((H) & 0xFF000000) >> 24)
198 #define PMCLOG_HEADER_CHECK_MAGIC(H) \
199 (PMCLOG_HEADER_TO_MAGIC(H) == PMCLOG_HEADER_MAGIC)
206 int pmclog_configure_log(struct pmc_owner *_po, int _logfd);
207 int pmclog_deconfigure_log(struct pmc_owner *_po);
208 int pmclog_flush(struct pmc_owner *_po);
209 void pmclog_initialize(void);
210 void pmclog_process_closelog(struct pmc_owner *po);
211 void pmclog_process_dropnotify(struct pmc_owner *po);
212 void pmclog_process_mappingchange(struct pmc_owner *po, pid_t pid, int type,
213 uintfptr_t start, uintfptr_t end, char *path);
214 void pmclog_process_pcsample(struct pmc *_pm, struct pmc_sample *_ps);
215 void pmclog_process_pmcallocate(struct pmc *_pm);
216 void pmclog_process_pmcattach(struct pmc *_pm, pid_t _pid, char *_path);
217 void pmclog_process_pmcdetach(struct pmc *_pm, pid_t _pid);
218 void pmclog_process_proccsw(struct pmc *_pm, struct pmc_process *_pp,
220 void pmclog_process_procexec(struct pmc_owner *_po, pid_t _pid, char *_path);
221 void pmclog_process_procexit(struct pmc *_pm, struct pmc_process *_pp);
222 void pmclog_process_procfork(struct pmc_owner *_po, pid_t _oldpid, pid_t _newpid);
223 void pmclog_process_sysexit(struct pmc_owner *_po, pid_t _pid);
224 int pmclog_process_userlog(struct pmc_owner *_po,
225 struct pmc_op_writelog *_wl);
226 void pmclog_shutdown(void);
229 #endif /* _SYS_PMCLOG_H_ */