FreeBSD/Linux Kernel Cross Reference
sys/sys/pmclog.h
1 /*-
2 * Copyright (c) 2005 Joseph Koshy
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
13 *
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
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD$
27 */
28
29 #ifndef _SYS_PMCLOG_H_
30 #define _SYS_PMCLOG_H_
31
32 #include <sys/pmc.h>
33
34 enum pmclog_type {
35 PMCLOG_TYPE_CLOSELOG,
36 PMCLOG_TYPE_DROPNOTIFY,
37 PMCLOG_TYPE_INITIALIZE,
38 PMCLOG_TYPE_MAPPINGCHANGE,
39 PMCLOG_TYPE_PCSAMPLE,
40 PMCLOG_TYPE_PMCALLOCATE,
41 PMCLOG_TYPE_PMCATTACH,
42 PMCLOG_TYPE_PMCDETACH,
43 PMCLOG_TYPE_PROCCSW,
44 PMCLOG_TYPE_PROCEXEC,
45 PMCLOG_TYPE_PROCEXIT,
46 PMCLOG_TYPE_PROCFORK,
47 PMCLOG_TYPE_SYSEXIT,
48 PMCLOG_TYPE_USERDATA
49 };
50
51 #define PMCLOG_MAPPING_INSERT 0x01
52 #define PMCLOG_MAPPING_DELETE 0x02
53
54 /*
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
57 * the event.
58 *
59 * Header field format:
60 *
61 * 31 24 16 0
62 * +------------+------------+-----------------------------------+
63 * | MAGIC | TYPE | LENGTH |
64 * +------------+------------+-----------------------------------+
65 *
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.
69 */
70
71 #define PMCLOG_ENTRY_HEADER \
72 uint32_t pl_header; \
73 uint32_t pl_ts_sec; \
74 uint32_t pl_ts_nsec;
75
76
77 /*
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'.
82 *
83 * The actual reading and writing of the log file is always in terms
84 * of 4 byte quantities.
85 */
86
87 struct pmclog_closelog {
88 PMCLOG_ENTRY_HEADER
89 };
90
91 struct pmclog_dropnotify {
92 PMCLOG_ENTRY_HEADER
93 };
94
95 struct pmclog_initialize {
96 PMCLOG_ENTRY_HEADER
97 uint32_t pl_version; /* driver version */
98 uint32_t pl_cpu; /* enum pmc_cputype */
99 } __packed;
100
101 struct pmclog_mappingchange {
102 PMCLOG_ENTRY_HEADER
103 uint32_t pl_type;
104 uintfptr_t pl_start; /* 8 byte aligned */
105 uintfptr_t pl_end;
106 uint32_t pl_pid;
107 char pl_pathname[PATH_MAX];
108 } __packed;
109
110
111 struct pmclog_pcsample {
112 PMCLOG_ENTRY_HEADER
113 uint32_t pl_pid;
114 uintfptr_t pl_pc; /* 8 byte aligned */
115 uint32_t pl_pmcid;
116 uint32_t pl_usermode;
117 } __packed;
118
119 struct pmclog_pmcallocate {
120 PMCLOG_ENTRY_HEADER
121 uint32_t pl_pmcid;
122 uint32_t pl_event;
123 uint32_t pl_flags;
124 } __packed;
125
126 struct pmclog_pmcattach {
127 PMCLOG_ENTRY_HEADER
128 uint32_t pl_pmcid;
129 uint32_t pl_pid;
130 char pl_pathname[PATH_MAX];
131 } __packed;
132
133 struct pmclog_pmcdetach {
134 PMCLOG_ENTRY_HEADER
135 uint32_t pl_pmcid;
136 uint32_t pl_pid;
137 } __packed;
138
139 struct pmclog_proccsw {
140 PMCLOG_ENTRY_HEADER
141 uint32_t pl_pmcid;
142 uint64_t pl_value; /* keep 8 byte aligned */
143 uint32_t pl_pid;
144 } __packed;
145
146 struct pmclog_procexec {
147 PMCLOG_ENTRY_HEADER
148 uint32_t pl_pid;
149 uintfptr_t pl_start; /* keep 8 byte aligned */
150 uint32_t pl_pmcid;
151 char pl_pathname[PATH_MAX];
152 } __packed;
153
154 struct pmclog_procexit {
155 PMCLOG_ENTRY_HEADER
156 uint32_t pl_pmcid;
157 uint64_t pl_value; /* keep 8 byte aligned */
158 uint32_t pl_pid;
159 } __packed;
160
161 struct pmclog_procfork {
162 PMCLOG_ENTRY_HEADER
163 uint32_t pl_oldpid;
164 uint32_t pl_newpid;
165 } __packed;
166
167 struct pmclog_sysexit {
168 PMCLOG_ENTRY_HEADER
169 uint32_t pl_pid;
170 } __packed;
171
172 struct pmclog_userdata {
173 PMCLOG_ENTRY_HEADER
174 uint32_t pl_userdata;
175 } __packed;
176
177 union pmclog_entry { /* only used to size scratch areas */
178 struct pmclog_closelog pl_cl;
179 struct pmclog_dropnotify pl_dn;
180 struct pmclog_initialize pl_i;
181 struct pmclog_pcsample pl_s;
182 struct pmclog_pmcallocate pl_a;
183 struct pmclog_pmcattach pl_t;
184 struct pmclog_pmcdetach pl_d;
185 struct pmclog_proccsw pl_c;
186 struct pmclog_procexec pl_x;
187 struct pmclog_procexit pl_e;
188 struct pmclog_procfork pl_f;
189 struct pmclog_sysexit pl_se;
190 struct pmclog_userdata pl_u;
191 };
192
193 #define PMCLOG_HEADER_MAGIC 0xEEU
194
195 #define PMCLOG_HEADER_TO_LENGTH(H) \
196 ((H) & 0x0000FFFF)
197 #define PMCLOG_HEADER_TO_TYPE(H) \
198 (((H) & 0x00FF0000) >> 16)
199 #define PMCLOG_HEADER_TO_MAGIC(H) \
200 (((H) & 0xFF000000) >> 24)
201 #define PMCLOG_HEADER_CHECK_MAGIC(H) \
202 (PMCLOG_HEADER_TO_MAGIC(H) == PMCLOG_HEADER_MAGIC)
203
204 #ifdef _KERNEL
205
206 /*
207 * Prototypes
208 */
209 int pmclog_configure_log(struct pmc_owner *_po, int _logfd);
210 int pmclog_deconfigure_log(struct pmc_owner *_po);
211 int pmclog_flush(struct pmc_owner *_po);
212 void pmclog_initialize(void);
213 void pmclog_process_closelog(struct pmc_owner *po);
214 void pmclog_process_dropnotify(struct pmc_owner *po);
215 void pmclog_process_mappingchange(struct pmc_owner *po, pid_t pid, int type,
216 uintfptr_t start, uintfptr_t end, char *path);
217 void pmclog_process_pcsample(struct pmc *_pm, struct pmc_sample *_ps);
218 void pmclog_process_pmcallocate(struct pmc *_pm);
219 void pmclog_process_pmcattach(struct pmc *_pm, pid_t _pid, char *_path);
220 void pmclog_process_pmcdetach(struct pmc *_pm, pid_t _pid);
221 void pmclog_process_proccsw(struct pmc *_pm, struct pmc_process *_pp,
222 pmc_value_t _v);
223 void pmclog_process_procexec(struct pmc_owner *_po, pmc_id_t _pmid, pid_t _pid,
224 uintfptr_t _startaddr, char *_path);
225 void pmclog_process_procexit(struct pmc *_pm, struct pmc_process *_pp);
226 void pmclog_process_procfork(struct pmc_owner *_po, pid_t _oldpid, pid_t _newpid);
227 void pmclog_process_sysexit(struct pmc_owner *_po, pid_t _pid);
228 int pmclog_process_userlog(struct pmc_owner *_po,
229 struct pmc_op_writelog *_wl);
230 void pmclog_shutdown(void);
231 #endif /* _KERNEL */
232
233 #endif /* _SYS_PMCLOG_H_ */
Cache object: 84e8d4461008f05ee0b719124eb9e5b5
|