]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/sys/pmclog.h
This commit was generated by cvs2svn to compensate for changes in r147466,
[FreeBSD/FreeBSD.git] / 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 } __packed;
117
118 struct pmclog_pmcallocate {
119         PMCLOG_ENTRY_HEADER
120         uint32_t                pl_pmcid;
121         uint32_t                pl_event;
122         uint32_t                pl_flags;
123 } __packed;
124
125 struct pmclog_pmcattach {
126         PMCLOG_ENTRY_HEADER
127         uint32_t                pl_pmcid;
128         uint32_t                pl_pid;
129         char                    pl_pathname[PATH_MAX];
130 } __packed;
131
132 struct pmclog_pmcdetach {
133         PMCLOG_ENTRY_HEADER
134         uint32_t                pl_pmcid;
135         uint32_t                pl_pid;
136 } __packed;
137
138 struct pmclog_proccsw {
139         PMCLOG_ENTRY_HEADER
140         uint32_t                pl_pmcid;
141         uint64_t                pl_value;       /* keep 8 byte aligned */
142         uint32_t                pl_pid;
143 } __packed;
144
145 struct pmclog_procexec {
146         PMCLOG_ENTRY_HEADER
147         uint32_t                pl_pid;
148         char                    pl_pathname[PATH_MAX];
149 } __packed;
150
151 struct pmclog_procexit {
152         PMCLOG_ENTRY_HEADER
153         uint32_t                pl_pmcid;
154         uint64_t                pl_value;       /* keep 8 byte aligned */
155         uint32_t                pl_pid;
156 } __packed;
157
158 struct pmclog_procfork {
159         PMCLOG_ENTRY_HEADER
160         uint32_t                pl_oldpid;
161         uint32_t                pl_newpid;
162 } __packed;
163
164 struct pmclog_sysexit {
165         PMCLOG_ENTRY_HEADER
166         uint32_t                pl_pid;
167 } __packed;
168
169 struct pmclog_userdata {
170         PMCLOG_ENTRY_HEADER
171         uint32_t                pl_userdata;
172 } __packed;
173
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;
188 };
189
190 #define PMCLOG_HEADER_MAGIC                                     0xEEU
191
192 #define PMCLOG_HEADER_TO_LENGTH(H)                              \
193         ((H) & 0x0000FFFF)
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)
200
201 #ifdef  _KERNEL
202
203 /*
204  * Prototypes
205  */
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,
219     pmc_value_t _v);
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);
227 #endif  /* _KERNEL */
228
229 #endif  /* _SYS_PMCLOG_H_ */