Update FSF address
[lttv.git] / lttv / lttv / state.h
CommitLineData
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
b9ce0bad
YB
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
16 * MA 02110-1301, USA.
9c312311 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
51typedef struct _LttvTraceset LttvTraceset;
52
53typedef struct _LttvTrace LttvTrace;
54
55typedef struct _LttvTracesetPosition LttvTracesetPosition;
56
57struct 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
77extern 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
97extern 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_REQUEST_ISSUE,
123 LTT_EVENT_REQUEST_COMPLETE,
124 LTT_EVENT_LIST_INTERRUPT,
125 LTT_EVENT_SYS_CALL_TABLE,
126 LTT_EVENT_SOFTIRQ_VEC,
127 LTT_EVENT_KPROBE_TABLE,
128 LTT_EVENT_KPROBE,
129 LTT_EVENT_OPEN,
130 LTT_EVENT_READ,
131 LTT_EVENT_POLL_EVENT;
eed2ef37 132
133/* Fields Quarks */
134
135extern GQuark
90e19f82
AM
136 LTT_FIELD_SYSCALL_ID,
137 LTT_FIELD_TRAP_ID,
138 LTT_FIELD_IRQ_ID,
139 LTT_FIELD_SOFT_IRQ_ID,
140 LTT_FIELD_PREV_PID,
141 LTT_FIELD_NEXT_PID,
142 LTT_FIELD_PREV_STATE,
143 LTT_FIELD_PARENT_PID,
144 LTT_FIELD_CHILD_PID,
145 LTT_FIELD_PID,
146 LTT_FIELD_TGID,
147 LTT_FIELD_FILENAME,
148 LTT_FIELD_NAME,
149 LTT_FIELD_TYPE,
150 LTT_FIELD_MODE,
151 LTT_FIELD_SUBMODE,
152 LTT_FIELD_STATUS,
153 LTT_FIELD_THIS_FN,
154 LTT_FIELD_CALL_SITE,
155 LTT_FIELD_MINOR,
156 LTT_FIELD_MAJOR,
157 LTT_FIELD_OPERATION,
158 LTT_FIELD_ACTION,
159 LTT_FIELD_ID,
160 LTT_FIELD_ADDRESS,
161 LTT_FIELD_SYMBOL,
162 LTT_FIELD_IP,
163 LTT_FIELD_FD,
164 LTT_FIELD_STATE,
165 LTT_FIELD_CPU_ID;
eed2ef37 166
ffd54a90 167typedef struct _LttvTraceState LttvTraceState;
168typedef struct _LttvTraceStateClass LttvTraceStateClass;
169
170typedef struct _LttvTracefileState LttvTracefileState;
171typedef struct _LttvTracefileStateClass LttvTracefileStateClass;
172
58b4e4ae
YB
173void lttv_state_add_event_hooks(LttvTraceset *traceset);
174gint lttv_state_hook_add_event_hooks(void *hook_data, void *call_data);
308711e5 175
58b4e4ae
YB
176void lttv_state_remove_event_hooks(LttvTraceset *traceset);
177gint lttv_state_hook_remove_event_hooks(void *hook_data, void *call_data);
dc877563 178
58b4e4ae
YB
179gint lttv_state_save_hook_add_event_hooks(void *hook_data, void *call_data);
180gint lttv_state_save_hook_remove_event_hooks(void *hook_data, void *call_data);
181
182
183//TODO ybrosseau 2012-07-30: Change name of seek_time_closest to:
184//void lttv_traceset_seek_time_closest_prior_state(LttvTraceset *traceset, LttTime t);
185
186void lttv_state_traceset_seek_time_closest(LttvTraceset *traceset, LttTime t);
187void lttv_state_traceset_seek_time(LttvTraceset *traceset, LttTime t);
188void lttv_state_traceset_seek_position(LttvTraceset *traceset, LttvTracesetPosition *position);
dc877563 189
b445142a 190/* The LttvProcessState structure defines the current state for each process.
191 A process can make system calls (in some rare cases nested) and receive
192 interrupts/faults. For instance, a process may issue a system call,
193 generate a page fault while reading an argument from user space, and
194 get caught by an interrupt. To represent these nested states, an
195 execution mode stack is maintained. The stack bottom is normal user mode
196 and the top of stack is the current execution mode.
197
198 The execution mode stack tells about the process status, execution mode and
199 submode (interrupt, system call or IRQ number). All these could be
200 defined as enumerations but may need extensions (e.g. new process state).
201 GQuark are thus used. They are as easy to manipulate as integers but have
202 a string associated, just like enumerations.
dc877563 203
b445142a 204 The execution mode is one of "user mode", "kernel thread", "system call",
dc877563 205 "interrupt request", "fault". */
206
b445142a 207typedef GQuark LttvExecutionMode;
dc877563 208
b445142a 209extern LttvExecutionMode
90e19f82 210 LTTV_STATE_USER_MODE,
f044974e 211 LTTV_STATE_MAYBE_USER_MODE,
90e19f82 212 LTTV_STATE_SYSCALL,
f044974e 213 LTTV_STATE_MAYBE_SYSCALL,
90e19f82 214 LTTV_STATE_TRAP,
f044974e 215 LTTV_STATE_MAYBE_TRAP, /* TODO */
90e19f82
AM
216 LTTV_STATE_IRQ,
217 LTTV_STATE_SOFT_IRQ,
218 LTTV_STATE_MODE_UNKNOWN;
ffd54a90 219
dc877563 220
b445142a 221/* The submode number depends on the execution mode. For user mode or kernel
222 thread, which are the normal mode (execution mode stack bottom),
223 it is set to "none". For interrupt requests, faults and system calls,
224 it is set respectively to the interrupt name (e.g. "timer"), fault name
996acd92 225 (e.g. "page fault"), and system call name (e.g. "select"). */
dc877563 226
b445142a 227typedef GQuark LttvExecutionSubmode;
dc877563 228
b445142a 229extern LttvExecutionSubmode
90e19f82
AM
230 LTTV_STATE_SUBMODE_NONE,
231 LTTV_STATE_SUBMODE_UNKNOWN;
dc877563 232
233/* The process status is one of "running", "wait-cpu" (runnable), or "wait-*"
234 where "*" describes the resource waited for (e.g. timer, process,
235 disk...). */
236
237typedef GQuark LttvProcessStatus;
238
ffd54a90 239extern LttvProcessStatus
90e19f82
AM
240 LTTV_STATE_UNNAMED,
241 LTTV_STATE_WAIT_FORK,
242 LTTV_STATE_WAIT_CPU,
243 LTTV_STATE_EXIT,
244 LTTV_STATE_ZOMBIE,
245 LTTV_STATE_WAIT,
246 LTTV_STATE_RUN,
247 LTTV_STATE_DEAD;
dc877563 248
e62e7f3a 249typedef GQuark LttvProcessType;
250
251extern LttvProcessType
90e19f82
AM
252 LTTV_STATE_USER_THREAD,
253 LTTV_STATE_KERNEL_THREAD;
ffd54a90 254
44ffb95f 255typedef GQuark LttvCPUMode;
256extern LttvCPUMode
90e19f82
AM
257 LTTV_CPU_UNKNOWN,
258 LTTV_CPU_IDLE,
259 LTTV_CPU_BUSY,
260 LTTV_CPU_IRQ,
261 LTTV_CPU_SOFT_IRQ,
262 LTTV_CPU_TRAP;
44ffb95f 263
5e563da0 264typedef GQuark LttvIRQMode;
265extern LttvIRQMode
90e19f82
AM
266 LTTV_IRQ_UNKNOWN,
267 LTTV_IRQ_IDLE,
268 LTTV_IRQ_BUSY;
5e563da0 269
27811799 270typedef GQuark LttvBdevMode;
271extern LttvBdevMode
90e19f82
AM
272 LTTV_BDEV_UNKNOWN,
273 LTTV_BDEV_IDLE,
274 LTTV_BDEV_BUSY_READING,
275 LTTV_BDEV_BUSY_WRITING;
27811799 276
b445142a 277typedef struct _LttvExecutionState {
90e19f82
AM
278 LttvExecutionMode t;
279 LttvExecutionSubmode n;
280 LttTime entry;
281 LttTime change;
282 LttTime cum_cpu_time;
283 LttvProcessStatus s;
b445142a 284} LttvExecutionState;
dc877563 285
dc877563 286typedef struct _LttvProcessState {
90e19f82
AM
287 guint pid;
288 guint tgid;
289 guint ppid;
290 LttTime creation_time;
291 LttTime insertion_time;
292 GQuark name;
90e19f82
AM
293 GQuark pid_time;
294 GArray *execution_stack; /* Array of LttvExecutionState */
295 LttvExecutionState *state; /* Top of interrupt stack */
296 /* WARNING : each time the execution_stack size is modified, the state
297 * must be reget : g_array_set_size can have to move the array.
298 * (Mathieu) */
299 guint cpu; /* CPU where process is scheduled (being either in
300 the active or inactive runqueue)*/
301// guint last_tracefile_index; /* index in the trace for cpu tracefile */
90e19f82 302 /* opened file descriptors, address map?... */
90e19f82 303 LttvProcessType type; /* kernel thread or user space ? */
90e19f82
AM
304 guint free_events; /* 0 : none, 1 : free or exit dead, 2 : should delete */
305 GHashTable *fds; /* hash table of int (file descriptor) -> GQuark (file name) */
dc877563 306} LttvProcessState;
307
348c6ba8 308#define ANY_CPU 0 /* For clarity sake : a call to lttv_state_find_process for
309 a PID != 0 will search on any cpu automatically. */
310
90e19f82
AM
311LttvProcessState *lttv_state_find_process(LttvTraceState *ts, guint cpu,
312 guint pid);
2a2fa4f0 313
90e19f82
AM
314LttvProcessState *lttv_state_find_process_or_create(LttvTraceState *ts,
315 guint cpu, guint pid, const LttTime *timestamp);
2a2fa4f0 316
90e19f82
AM
317LttvProcessState *lttv_state_create_process(LttvTraceState *tcs,
318 LttvProcessState *parent, guint cpu, guint pid,
319 guint tgid, GQuark name, const LttTime *timestamp);
b445142a 320
7a4bdb54
YB
321//void lttv_state_write(LttvTraceState *trace_state, LttTime t, FILE *fp);
322//void lttv_state_write_raw(LttvTraceState *trace_state, LttTime t, FILE *fp);
dc877563 323
44ffb95f 324typedef struct _LttvCPUState {
90e19f82
AM
325 GArray *mode_stack;
326 GArray *irq_stack;
327 GArray *softirq_stack;
328 GArray *trap_stack;
44ffb95f 329} LttvCPUState;
330
5e563da0 331typedef struct _LttvIRQState {
90e19f82 332 GArray *mode_stack;
5e563da0 333} LttvIRQState;
334
0305fe77 335typedef struct _LttvSoftIRQState {
90e19f82
AM
336 guint pending; /* number of times it is pending */
337 guint running; /* number of times it is currently running (on different processors) */
0305fe77 338} LttvSoftIRQState;
339
38726a78 340typedef struct _LttvTrapState {
90e19f82 341 guint running; /* number of times it is currently running (on different processors) */
38726a78 342} LttvTrapState;
343
27811799 344typedef struct _LttvBdevState {
90e19f82 345 GArray *mode_stack;
27811799 346} LttvBdevState;
347
1cd9058f 348typedef struct _LttvNameTables {
90e19f82
AM
349 GQuark *syscall_names;
350 guint nb_syscalls;
351 GQuark *trap_names;
352 guint nb_traps;
353 GQuark *irq_names;
354 guint nb_irqs;
355 GQuark *soft_irq_names;
356 guint nb_soft_irqs;
357 GHashTable *kprobe_hash;
1cd9058f
MD
358} LttvNameTables;
359
dc877563 360struct _LttvTraceState {
7a4bdb54 361 LttvTrace *trace; /* LttvTrace this state belongs to */
90e19f82
AM
362 GHashTable *processes; /* LttvProcessState objects indexed by pid and
363 last_cpu */
90e19f82
AM
364 guint nb_event, save_interval;
365 /* Block/char devices, locks, memory pages... */
366 GQuark *eventtype_names;
367 LttvNameTables *name_tables;
368 LttTime *max_time_state_recomputed_in_seek;
369 GHashTable *kprobe_hash;
370
371 /* Array of per cpu running process */
372 LttvProcessState **running_process;
58b4e4ae 373
90e19f82
AM
374 LttvCPUState *cpu_states; /* state of each cpu */
375 /* FIXME should be a g_array to deal with resize and copy. */
376 LttvIRQState *irq_states; /* state of each irq handler */
377 /* FIXME should be a g_array to deal with resize and copy. */
378 LttvSoftIRQState *soft_irq_states; /* state of each softirq */
379 /* FIXME should be a g_array to deal with resize and copy. */
380 LttvTrapState *trap_states; /* state of each trap */
381 GHashTable *bdev_states; /* state of the block devices */
dc877563 382};
383
7a4bdb54
YB
384void lttv_trace_state_init(LttvTraceState *self, LttvTrace *trace);
385void lttv_trace_state_fini(LttvTraceState *self);
dc877563 386
308711e5 387void lttv_state_save(LttvTraceState *self, LttvAttribute *container);
308711e5 388void lttv_state_restore(LttvTraceState *self, LttvAttribute *container);
7a4bdb54
YB
389LttvTracesetPosition *lttv_trace_state_get_position(LttvAttribute *container);
390void lttv_state_saved_free(LttvTraceState *self, LttvAttribute *container);
308711e5 391
7a4bdb54
YB
392//TODO ybrosseau Need to export that cleanly
393//int lttv_state_pop_state_cleanup(LttvProcessState *process,
394// LttvEvent *event);
dc877563 395
6d0cdf22 396#define HDR_PROCESS 0
397#define HDR_ES 1
398#define HDR_USER_STACK 2
7a4bdb54 399//#define HDR_USERTRACE 3
6d0cdf22 400#define HDR_PROCESS_STATE 4
401#define HDR_CPU 5
402#define HDR_TRACEFILE 6
403#define HDR_TRACESET 7
404#define HDR_TRACE 8
405#define HDR_QUARKS 9
406#define HDR_QUARK 10
407
67f72973 408/* Device number manipulation macros from kernel source */
409#define MINORBITS 20
410#define MINORMASK ((1U << MINORBITS) - 1)
411#define MAJOR(dev) ((unsigned int) ((dev) >> MINORBITS))
412#define MINOR(dev) ((unsigned int) ((dev) & MINORMASK))
59dc1f2a 413#define MKDEV(ma, mi) ((((unsigned int) (ma)) << MINORBITS) | (unsigned int) (mi))
6d0cdf22 414
b445142a 415#endif // STATE_H
This page took 0.091381 seconds and 4 git commands to generate.