Commit | Line | Data |
---|---|---|
9c312311 | 1 | /* This file is part of the Linux Trace Toolkit viewer |
2 | * Copyright (C) 2003-2004 Michel Dagenais | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License Version 2 as | |
6 | * published by the Free Software Foundation; | |
7 | * | |
8 | * This program is distributed in the hope that it will be useful, | |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | * GNU General Public License for more details. | |
12 | * | |
13 | * You should have received a copy of the GNU General Public License | |
14 | * along with this program; if not, write to the Free Software | |
15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, | |
16 | * MA 02111-1307, USA. | |
17 | */ | |
18 | ||
dc877563 | 19 | #ifndef STATE_H |
20 | #define STATE_H | |
21 | ||
ffd54a90 | 22 | #include <glib.h> |
dbb7bb09 | 23 | #include <stdio.h> |
7a4bdb54 YB |
24 | #include <babeltrace/context.h> |
25 | #include <lttv/attribute.h> | |
dd025f91 | 26 | /* The operating system state, kept during the trace analysis, |
dc877563 | 27 | contains a subset of the real operating system state, |
28 | sufficient for the analysis, and possibly organized quite differently. | |
29 | ||
ffd54a90 | 30 | The state information is added to LttvTracesetContext, LttvTraceContext |
d3e01c7a | 31 | and LttvTracefileContext objects, used by process_traceset, through |
dc877563 | 32 | subtyping. The context objects already reflect the multiple tracefiles |
33 | (one per cpu) per trace and multiple traces per trace set. The state | |
308711e5 | 34 | objects defined here simply add fields to the relevant context objects. |
35 | ||
36 | There is no traceset specific state yet. It may eventually contains such | |
37 | things as clock differences over time. | |
38 | ||
39 | The trace state currently consists in a process table. | |
40 | ||
41 | The tracefile level state relates to the associated cpu. It contains the | |
42 | position of the current event in the tracefile (since the state depends on | |
43 | which events have been processed) and a pointer to the current process, | |
44 | in the process table, being run on that cpu. | |
45 | ||
1aeb0ff5 | 46 | For each process in the process table, various information such as exec |
308711e5 | 47 | file name, pid, ppid and creation time are stored. Each process state also |
48 | contains an execution mode stack (e.g. irq within system call, called | |
49 | from user mode). */ | |
dc877563 | 50 | |
7a4bdb54 YB |
51 | typedef struct _LttvTraceset LttvTraceset; |
52 | ||
53 | typedef struct _LttvTrace LttvTrace; | |
54 | ||
55 | typedef struct _LttvTracesetPosition LttvTracesetPosition; | |
56 | ||
57 | struct bt_context; | |
58 | ||
a5ba1787 | 59 | /* Priority of state hooks */ |
60 | #define LTTV_PRIO_STATE 25 | |
61 | ||
eed2ef37 | 62 | #define LTTV_STATE_SAVE_INTERVAL 50000 |
63 | ||
df6c9904 MD |
64 | |
65 | #define PREALLOC_NB_SYSCALLS 256 | |
66 | /* | |
67 | * As of 2.6.38, IRQ 239 has been seen (and we have seen higher than | |
68 | * 256 too. | |
69 | */ | |
70 | #define PREALLOC_NB_IRQS 512 | |
71 | /* As of 2.6.38, 255 softirqs are used. */ | |
72 | #define PREALLOC_NB_SOFT_IRQS 512 | |
73 | #define PREALLOC_NB_TRAPS 256 | |
74 | ||
750eb11a | 75 | /* Channel Quarks */ |
eed2ef37 | 76 | |
77 | extern GQuark | |
90e19f82 AM |
78 | LTT_CHANNEL_FD_STATE, |
79 | LTT_CHANNEL_GLOBAL_STATE, | |
80 | LTT_CHANNEL_IRQ_STATE, | |
81 | LTT_CHANNEL_MODULE_STATE, | |
82 | LTT_CHANNEL_NETIF_STATE, | |
83 | LTT_CHANNEL_SOFTIRQ_STATE, | |
84 | LTT_CHANNEL_SWAP_STATE, | |
85 | LTT_CHANNEL_SYSCALL_STATE, | |
86 | LTT_CHANNEL_TASK_STATE, | |
87 | LTT_CHANNEL_VM_STATE, | |
88 | LTT_CHANNEL_KPROBE_STATE, | |
89 | LTT_CHANNEL_FS, | |
90 | LTT_CHANNEL_KERNEL, | |
91 | LTT_CHANNEL_MM, | |
92 | LTT_CHANNEL_USERSPACE, | |
93 | LTT_CHANNEL_BLOCK; | |
eed2ef37 | 94 | |
95 | /* Events Quarks */ | |
96 | ||
97 | extern GQuark | |
90e19f82 AM |
98 | LTT_EVENT_SYSCALL_ENTRY, |
99 | LTT_EVENT_SYSCALL_EXIT, | |
100 | LTT_EVENT_TRAP_ENTRY, | |
101 | LTT_EVENT_TRAP_EXIT, | |
102 | LTT_EVENT_PAGE_FAULT_ENTRY, | |
103 | LTT_EVENT_PAGE_FAULT_EXIT, | |
104 | LTT_EVENT_PAGE_FAULT_NOSEM_ENTRY, | |
105 | LTT_EVENT_PAGE_FAULT_NOSEM_EXIT, | |
106 | LTT_EVENT_IRQ_ENTRY, | |
107 | LTT_EVENT_IRQ_EXIT, | |
108 | LTT_EVENT_SOFT_IRQ_RAISE, | |
109 | LTT_EVENT_SOFT_IRQ_ENTRY, | |
110 | LTT_EVENT_SOFT_IRQ_EXIT, | |
111 | LTT_EVENT_SCHED_SCHEDULE, | |
112 | LTT_EVENT_SCHED_TRY_WAKEUP, | |
113 | LTT_EVENT_PROCESS_FORK, | |
114 | LTT_EVENT_KTHREAD_CREATE, | |
115 | LTT_EVENT_PROCESS_EXIT, | |
116 | LTT_EVENT_PROCESS_FREE, | |
117 | LTT_EVENT_EXEC, | |
118 | LTT_EVENT_PROCESS_STATE, | |
119 | LTT_EVENT_STATEDUMP_END, | |
7a4bdb54 YB |
120 | //LTT_EVENT_FUNCTION_ENTRY, |
121 | //LTT_EVENT_FUNCTION_EXIT, | |
90e19f82 AM |
122 | LTT_EVENT_THREAD_BRAND, |
123 | LTT_EVENT_REQUEST_ISSUE, | |
124 | LTT_EVENT_REQUEST_COMPLETE, | |
125 | LTT_EVENT_LIST_INTERRUPT, | |
126 | LTT_EVENT_SYS_CALL_TABLE, | |
127 | LTT_EVENT_SOFTIRQ_VEC, | |
128 | LTT_EVENT_KPROBE_TABLE, | |
129 | LTT_EVENT_KPROBE, | |
130 | LTT_EVENT_OPEN, | |
131 | LTT_EVENT_READ, | |
132 | LTT_EVENT_POLL_EVENT; | |
eed2ef37 | 133 | |
134 | /* Fields Quarks */ | |
135 | ||
136 | extern GQuark | |
90e19f82 AM |
137 | LTT_FIELD_SYSCALL_ID, |
138 | LTT_FIELD_TRAP_ID, | |
139 | LTT_FIELD_IRQ_ID, | |
140 | LTT_FIELD_SOFT_IRQ_ID, | |
141 | LTT_FIELD_PREV_PID, | |
142 | LTT_FIELD_NEXT_PID, | |
143 | LTT_FIELD_PREV_STATE, | |
144 | LTT_FIELD_PARENT_PID, | |
145 | LTT_FIELD_CHILD_PID, | |
146 | LTT_FIELD_PID, | |
147 | LTT_FIELD_TGID, | |
148 | LTT_FIELD_FILENAME, | |
149 | LTT_FIELD_NAME, | |
150 | LTT_FIELD_TYPE, | |
151 | LTT_FIELD_MODE, | |
152 | LTT_FIELD_SUBMODE, | |
153 | LTT_FIELD_STATUS, | |
154 | LTT_FIELD_THIS_FN, | |
155 | LTT_FIELD_CALL_SITE, | |
156 | LTT_FIELD_MINOR, | |
157 | LTT_FIELD_MAJOR, | |
158 | LTT_FIELD_OPERATION, | |
159 | LTT_FIELD_ACTION, | |
160 | LTT_FIELD_ID, | |
161 | LTT_FIELD_ADDRESS, | |
162 | LTT_FIELD_SYMBOL, | |
163 | LTT_FIELD_IP, | |
164 | LTT_FIELD_FD, | |
165 | LTT_FIELD_STATE, | |
166 | LTT_FIELD_CPU_ID; | |
eed2ef37 | 167 | |
ffd54a90 | 168 | typedef struct _LttvTraceState LttvTraceState; |
169 | typedef struct _LttvTraceStateClass LttvTraceStateClass; | |
170 | ||
171 | typedef struct _LttvTracefileState LttvTracefileState; | |
172 | typedef struct _LttvTracefileStateClass LttvTracefileStateClass; | |
173 | ||
58b4e4ae YB |
174 | void lttv_state_add_event_hooks(LttvTraceset *traceset); |
175 | gint lttv_state_hook_add_event_hooks(void *hook_data, void *call_data); | |
308711e5 | 176 | |
58b4e4ae YB |
177 | void lttv_state_remove_event_hooks(LttvTraceset *traceset); |
178 | gint lttv_state_hook_remove_event_hooks(void *hook_data, void *call_data); | |
dc877563 | 179 | |
58b4e4ae YB |
180 | gint lttv_state_save_hook_add_event_hooks(void *hook_data, void *call_data); |
181 | gint lttv_state_save_hook_remove_event_hooks(void *hook_data, void *call_data); | |
182 | ||
183 | ||
184 | //TODO ybrosseau 2012-07-30: Change name of seek_time_closest to: | |
185 | //void lttv_traceset_seek_time_closest_prior_state(LttvTraceset *traceset, LttTime t); | |
186 | ||
187 | void lttv_state_traceset_seek_time_closest(LttvTraceset *traceset, LttTime t); | |
188 | void lttv_state_traceset_seek_time(LttvTraceset *traceset, LttTime t); | |
189 | void lttv_state_traceset_seek_position(LttvTraceset *traceset, LttvTracesetPosition *position); | |
dc877563 | 190 | |
b445142a | 191 | /* The LttvProcessState structure defines the current state for each process. |
192 | A process can make system calls (in some rare cases nested) and receive | |
193 | interrupts/faults. For instance, a process may issue a system call, | |
194 | generate a page fault while reading an argument from user space, and | |
195 | get caught by an interrupt. To represent these nested states, an | |
196 | execution mode stack is maintained. The stack bottom is normal user mode | |
197 | and the top of stack is the current execution mode. | |
198 | ||
199 | The execution mode stack tells about the process status, execution mode and | |
200 | submode (interrupt, system call or IRQ number). All these could be | |
201 | defined as enumerations but may need extensions (e.g. new process state). | |
202 | GQuark are thus used. They are as easy to manipulate as integers but have | |
203 | a string associated, just like enumerations. | |
dc877563 | 204 | |
b445142a | 205 | The execution mode is one of "user mode", "kernel thread", "system call", |
dc877563 | 206 | "interrupt request", "fault". */ |
207 | ||
b445142a | 208 | typedef GQuark LttvExecutionMode; |
dc877563 | 209 | |
b445142a | 210 | extern LttvExecutionMode |
90e19f82 | 211 | LTTV_STATE_USER_MODE, |
f044974e | 212 | LTTV_STATE_MAYBE_USER_MODE, |
90e19f82 | 213 | LTTV_STATE_SYSCALL, |
f044974e | 214 | LTTV_STATE_MAYBE_SYSCALL, |
90e19f82 | 215 | LTTV_STATE_TRAP, |
f044974e | 216 | LTTV_STATE_MAYBE_TRAP, /* TODO */ |
90e19f82 AM |
217 | LTTV_STATE_IRQ, |
218 | LTTV_STATE_SOFT_IRQ, | |
219 | LTTV_STATE_MODE_UNKNOWN; | |
ffd54a90 | 220 | |
dc877563 | 221 | |
b445142a | 222 | /* The submode number depends on the execution mode. For user mode or kernel |
223 | thread, which are the normal mode (execution mode stack bottom), | |
224 | it is set to "none". For interrupt requests, faults and system calls, | |
225 | it is set respectively to the interrupt name (e.g. "timer"), fault name | |
996acd92 | 226 | (e.g. "page fault"), and system call name (e.g. "select"). */ |
dc877563 | 227 | |
b445142a | 228 | typedef GQuark LttvExecutionSubmode; |
dc877563 | 229 | |
b445142a | 230 | extern LttvExecutionSubmode |
90e19f82 AM |
231 | LTTV_STATE_SUBMODE_NONE, |
232 | LTTV_STATE_SUBMODE_UNKNOWN; | |
dc877563 | 233 | |
234 | /* The process status is one of "running", "wait-cpu" (runnable), or "wait-*" | |
235 | where "*" describes the resource waited for (e.g. timer, process, | |
236 | disk...). */ | |
237 | ||
238 | typedef GQuark LttvProcessStatus; | |
239 | ||
ffd54a90 | 240 | extern LttvProcessStatus |
90e19f82 AM |
241 | LTTV_STATE_UNNAMED, |
242 | LTTV_STATE_WAIT_FORK, | |
243 | LTTV_STATE_WAIT_CPU, | |
244 | LTTV_STATE_EXIT, | |
245 | LTTV_STATE_ZOMBIE, | |
246 | LTTV_STATE_WAIT, | |
247 | LTTV_STATE_RUN, | |
248 | LTTV_STATE_DEAD; | |
dc877563 | 249 | |
c4a72569 | 250 | extern GQuark |
90e19f82 | 251 | LTTV_STATE_UNBRANDED; |
c4a72569 | 252 | |
e62e7f3a | 253 | typedef GQuark LttvProcessType; |
254 | ||
255 | extern LttvProcessType | |
90e19f82 AM |
256 | LTTV_STATE_USER_THREAD, |
257 | LTTV_STATE_KERNEL_THREAD; | |
ffd54a90 | 258 | |
44ffb95f | 259 | typedef GQuark LttvCPUMode; |
260 | extern LttvCPUMode | |
90e19f82 AM |
261 | LTTV_CPU_UNKNOWN, |
262 | LTTV_CPU_IDLE, | |
263 | LTTV_CPU_BUSY, | |
264 | LTTV_CPU_IRQ, | |
265 | LTTV_CPU_SOFT_IRQ, | |
266 | LTTV_CPU_TRAP; | |
44ffb95f | 267 | |
5e563da0 | 268 | typedef GQuark LttvIRQMode; |
269 | extern LttvIRQMode | |
90e19f82 AM |
270 | LTTV_IRQ_UNKNOWN, |
271 | LTTV_IRQ_IDLE, | |
272 | LTTV_IRQ_BUSY; | |
5e563da0 | 273 | |
27811799 | 274 | typedef GQuark LttvBdevMode; |
275 | extern LttvBdevMode | |
90e19f82 AM |
276 | LTTV_BDEV_UNKNOWN, |
277 | LTTV_BDEV_IDLE, | |
278 | LTTV_BDEV_BUSY_READING, | |
279 | LTTV_BDEV_BUSY_WRITING; | |
27811799 | 280 | |
b445142a | 281 | typedef struct _LttvExecutionState { |
90e19f82 AM |
282 | LttvExecutionMode t; |
283 | LttvExecutionSubmode n; | |
284 | LttTime entry; | |
285 | LttTime change; | |
286 | LttTime cum_cpu_time; | |
287 | LttvProcessStatus s; | |
b445142a | 288 | } LttvExecutionState; |
dc877563 | 289 | |
dc877563 | 290 | typedef struct _LttvProcessState { |
90e19f82 AM |
291 | guint pid; |
292 | guint tgid; | |
293 | guint ppid; | |
294 | LttTime creation_time; | |
295 | LttTime insertion_time; | |
296 | GQuark name; | |
297 | GQuark brand; | |
298 | GQuark pid_time; | |
299 | GArray *execution_stack; /* Array of LttvExecutionState */ | |
300 | LttvExecutionState *state; /* Top of interrupt stack */ | |
301 | /* WARNING : each time the execution_stack size is modified, the state | |
302 | * must be reget : g_array_set_size can have to move the array. | |
303 | * (Mathieu) */ | |
304 | guint cpu; /* CPU where process is scheduled (being either in | |
305 | the active or inactive runqueue)*/ | |
306 | // guint last_tracefile_index; /* index in the trace for cpu tracefile */ | |
90e19f82 | 307 | /* opened file descriptors, address map?... */ |
90e19f82 | 308 | LttvProcessType type; /* kernel thread or user space ? */ |
90e19f82 AM |
309 | guint free_events; /* 0 : none, 1 : free or exit dead, 2 : should delete */ |
310 | GHashTable *fds; /* hash table of int (file descriptor) -> GQuark (file name) */ | |
dc877563 | 311 | } LttvProcessState; |
312 | ||
348c6ba8 | 313 | #define ANY_CPU 0 /* For clarity sake : a call to lttv_state_find_process for |
314 | a PID != 0 will search on any cpu automatically. */ | |
315 | ||
90e19f82 AM |
316 | LttvProcessState *lttv_state_find_process(LttvTraceState *ts, guint cpu, |
317 | guint pid); | |
2a2fa4f0 | 318 | |
90e19f82 AM |
319 | LttvProcessState *lttv_state_find_process_or_create(LttvTraceState *ts, |
320 | guint cpu, guint pid, const LttTime *timestamp); | |
2a2fa4f0 | 321 | |
90e19f82 AM |
322 | LttvProcessState *lttv_state_create_process(LttvTraceState *tcs, |
323 | LttvProcessState *parent, guint cpu, guint pid, | |
324 | guint tgid, GQuark name, const LttTime *timestamp); | |
b445142a | 325 | |
7a4bdb54 YB |
326 | //void lttv_state_write(LttvTraceState *trace_state, LttTime t, FILE *fp); |
327 | //void lttv_state_write_raw(LttvTraceState *trace_state, LttTime t, FILE *fp); | |
dc877563 | 328 | |
44ffb95f | 329 | typedef struct _LttvCPUState { |
90e19f82 AM |
330 | GArray *mode_stack; |
331 | GArray *irq_stack; | |
332 | GArray *softirq_stack; | |
333 | GArray *trap_stack; | |
44ffb95f | 334 | } LttvCPUState; |
335 | ||
5e563da0 | 336 | typedef struct _LttvIRQState { |
90e19f82 | 337 | GArray *mode_stack; |
5e563da0 | 338 | } LttvIRQState; |
339 | ||
0305fe77 | 340 | typedef struct _LttvSoftIRQState { |
90e19f82 AM |
341 | guint pending; /* number of times it is pending */ |
342 | guint running; /* number of times it is currently running (on different processors) */ | |
0305fe77 | 343 | } LttvSoftIRQState; |
344 | ||
38726a78 | 345 | typedef struct _LttvTrapState { |
90e19f82 | 346 | guint running; /* number of times it is currently running (on different processors) */ |
38726a78 | 347 | } LttvTrapState; |
348 | ||
27811799 | 349 | typedef struct _LttvBdevState { |
90e19f82 | 350 | GArray *mode_stack; |
27811799 | 351 | } LttvBdevState; |
352 | ||
1cd9058f | 353 | typedef struct _LttvNameTables { |
90e19f82 AM |
354 | GQuark *syscall_names; |
355 | guint nb_syscalls; | |
356 | GQuark *trap_names; | |
357 | guint nb_traps; | |
358 | GQuark *irq_names; | |
359 | guint nb_irqs; | |
360 | GQuark *soft_irq_names; | |
361 | guint nb_soft_irqs; | |
362 | GHashTable *kprobe_hash; | |
1cd9058f MD |
363 | } LttvNameTables; |
364 | ||
dc877563 | 365 | struct _LttvTraceState { |
7a4bdb54 | 366 | LttvTrace *trace; /* LttvTrace this state belongs to */ |
90e19f82 AM |
367 | GHashTable *processes; /* LttvProcessState objects indexed by pid and |
368 | last_cpu */ | |
90e19f82 AM |
369 | guint nb_event, save_interval; |
370 | /* Block/char devices, locks, memory pages... */ | |
371 | GQuark *eventtype_names; | |
372 | LttvNameTables *name_tables; | |
373 | LttTime *max_time_state_recomputed_in_seek; | |
374 | GHashTable *kprobe_hash; | |
375 | ||
376 | /* Array of per cpu running process */ | |
377 | LttvProcessState **running_process; | |
58b4e4ae | 378 | |
90e19f82 AM |
379 | LttvCPUState *cpu_states; /* state of each cpu */ |
380 | /* FIXME should be a g_array to deal with resize and copy. */ | |
381 | LttvIRQState *irq_states; /* state of each irq handler */ | |
382 | /* FIXME should be a g_array to deal with resize and copy. */ | |
383 | LttvSoftIRQState *soft_irq_states; /* state of each softirq */ | |
384 | /* FIXME should be a g_array to deal with resize and copy. */ | |
385 | LttvTrapState *trap_states; /* state of each trap */ | |
386 | GHashTable *bdev_states; /* state of the block devices */ | |
dc877563 | 387 | }; |
388 | ||
7a4bdb54 YB |
389 | void lttv_trace_state_init(LttvTraceState *self, LttvTrace *trace); |
390 | void lttv_trace_state_fini(LttvTraceState *self); | |
dc877563 | 391 | |
308711e5 | 392 | void lttv_state_save(LttvTraceState *self, LttvAttribute *container); |
308711e5 | 393 | void lttv_state_restore(LttvTraceState *self, LttvAttribute *container); |
7a4bdb54 YB |
394 | LttvTracesetPosition *lttv_trace_state_get_position(LttvAttribute *container); |
395 | void lttv_state_saved_free(LttvTraceState *self, LttvAttribute *container); | |
308711e5 | 396 | |
7a4bdb54 YB |
397 | //TODO ybrosseau Need to export that cleanly |
398 | //int lttv_state_pop_state_cleanup(LttvProcessState *process, | |
399 | // LttvEvent *event); | |
dc877563 | 400 | |
6d0cdf22 | 401 | #define HDR_PROCESS 0 |
402 | #define HDR_ES 1 | |
403 | #define HDR_USER_STACK 2 | |
7a4bdb54 | 404 | //#define HDR_USERTRACE 3 |
6d0cdf22 | 405 | #define HDR_PROCESS_STATE 4 |
406 | #define HDR_CPU 5 | |
407 | #define HDR_TRACEFILE 6 | |
408 | #define HDR_TRACESET 7 | |
409 | #define HDR_TRACE 8 | |
410 | #define HDR_QUARKS 9 | |
411 | #define HDR_QUARK 10 | |
412 | ||
67f72973 | 413 | /* Device number manipulation macros from kernel source */ |
414 | #define MINORBITS 20 | |
415 | #define MINORMASK ((1U << MINORBITS) - 1) | |
416 | #define MAJOR(dev) ((unsigned int) ((dev) >> MINORBITS)) | |
417 | #define MINOR(dev) ((unsigned int) ((dev) & MINORMASK)) | |
59dc1f2a | 418 | #define MKDEV(ma, mi) ((((unsigned int) (ma)) << MINORBITS) | (unsigned int) (mi)) |
6d0cdf22 | 419 | |
b445142a | 420 | #endif // STATE_H |