X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Flttv%2Flttv%2Fstate.c;h=c02a32275afcd75412ed1e9396df14116975d636;hb=c7620c793509802e9bc0b789a5b72b9510bb6b0e;hp=bcdf3ef8a3dbc7aa573c04fe528c571aa53fabc7;hpb=61ab5e97ee7296773f7e0b8630752471c3d84e3d;p=lttv.git diff --git a/ltt/branches/poly/lttv/lttv/state.c b/ltt/branches/poly/lttv/lttv/state.c index bcdf3ef8..c02a3227 100644 --- a/ltt/branches/poly/lttv/lttv/state.c +++ b/ltt/branches/poly/lttv/lttv/state.c @@ -172,6 +172,7 @@ static GQuark LTTV_STATE_RESOURCE_CPUS_COUNT, LTTV_STATE_RESOURCE_IRQS, LTTV_STATE_RESOURCE_SOFT_IRQS, + LTTV_STATE_RESOURCE_TRAPS, LTTV_STATE_RESOURCE_BLKDEVS; static void create_max_time(LttvTraceState *tcs); @@ -263,7 +264,7 @@ gboolean rettrue(gpointer key, gpointer value, gpointer user_data) static void restore_init_state(LttvTraceState *self) { - guint i, nb_cpus, nb_irqs, nb_soft_irqs; + guint i, nb_cpus, nb_irqs, nb_soft_irqs, nb_traps; //LttvTracefileState *tfcs; @@ -290,6 +291,7 @@ restore_init_state(LttvTraceState *self) nb_cpus = ltt_trace_get_num_cpu(self->parent.t); nb_irqs = self->nb_irqs; nb_soft_irqs = self->nb_soft_irqs; + nb_traps = self->nb_traps; /* Put the per cpu running_process to beginning state : process 0. */ for(i=0; i< nb_cpus; i++) { @@ -325,6 +327,11 @@ restore_init_state(LttvTraceState *self) self->soft_irq_states[i].running = 0; } + /* reset trap states */ + for(i=0; itrap_states[i].running = 0; + } + /* reset bdev states */ g_hash_table_foreach(self->bdev_states, bdevstate_free_cb, NULL); //g_hash_table_steal_all(self->bdev_states); @@ -498,6 +505,9 @@ init(LttvTracesetState *self, LttvTraceset *ts) /* the kernel has a statically fixed max of 32 softirqs */ tcs->soft_irq_states = g_new(LttvSoftIRQState, tcs->nb_soft_irqs); + /* init trap stuff */ + tcs->trap_states = g_new(LttvTrapState, tcs->nb_traps); + /* init bdev resource stuff */ tcs->bdev_states = g_hash_table_new(g_int_hash, g_int_equal); @@ -606,7 +616,7 @@ static void write_process_state(gpointer key, gpointer value, process = (LttvProcessState *)value; fprintf(fp, -" \n", +" \n", process, process->pid, process->tgid, process->ppid, g_quark_to_string(process->type), process->creation_time.tv_sec, @@ -615,7 +625,7 @@ static void write_process_state(gpointer key, gpointer value, process->insertion_time.tv_nsec, g_quark_to_string(process->name), g_quark_to_string(process->brand), - process->cpu); + process->cpu, process->free_events); for(i = 0 ; i < process->execution_stack->len; i++) { es = &g_array_index(process->execution_stack, LttvExecutionState, i); @@ -716,6 +726,7 @@ static void write_process_state_raw(gpointer key, gpointer value, //fputc('\0', fp); fwrite(&process->brand, sizeof(process->brand), 1, fp); fwrite(&process->pid, sizeof(process->pid), 1, fp); + fwrite(&process->free_events, sizeof(process->free_events), 1, fp); fwrite(&process->tgid, sizeof(process->tgid), 1, fp); fwrite(&process->ppid, sizeof(process->ppid), 1, fp); fwrite(&process->cpu, sizeof(process->cpu), 1, fp); @@ -865,6 +876,7 @@ static void read_process_state_raw(LttvTraceState *self, FILE *fp, fread(&tmp.name, sizeof(tmp.name), 1, fp); fread(&tmp.brand, sizeof(tmp.brand), 1, fp); fread(&tmp.pid, sizeof(tmp.pid), 1, fp); + fread(&tmp.free_events, sizeof(tmp.free_events), 1, fp); fread(&tmp.tgid, sizeof(tmp.tgid), 1, fp); fread(&tmp.ppid, sizeof(tmp.ppid), 1, fp); fread(&tmp.cpu, sizeof(tmp.cpu), 1, fp); @@ -895,7 +907,7 @@ static void read_process_state_raw(LttvTraceState *self, FILE *fp, (gchar*)g_ptr_array_index(quarktable, tmp.brand)); process->name = g_quark_from_string((gchar*)g_ptr_array_index(quarktable, tmp.name)); - + process->free_events = tmp.free_events; do { if(feof(fp) || ferror(fp)) goto end_loop; @@ -1208,7 +1220,7 @@ static void lttv_state_free_irq_states(LttvIRQState *states, guint n) static LttvSoftIRQState *lttv_state_copy_soft_irq_states(LttvSoftIRQState *states, guint n) { - guint i,j; + guint i; LttvSoftIRQState *retval; retval = g_malloc(n*sizeof(LttvSoftIRQState)); @@ -1225,6 +1237,25 @@ static void lttv_state_free_soft_irq_states(LttvSoftIRQState *states, guint n) g_free(states); } +static LttvTrapState *lttv_state_copy_trap_states(LttvTrapState *states, guint n) +{ + guint i; + LttvTrapState *retval; + + retval = g_malloc(n*sizeof(LttvTrapState)); + + for(i=0; inb_irqs; + nb_soft_irqs = self->nb_soft_irqs; { value = lttv_attribute_add(container, LTTV_STATE_RESOURCE_SOFT_IRQS, LTTV_POINTER); - *(value.v_pointer) = lttv_state_copy_soft_irq_states(self->soft_irq_states, nb_irqs); + *(value.v_pointer) = lttv_state_copy_soft_irq_states(self->soft_irq_states, nb_soft_irqs); + } + + /* save the trap state */ + nb_traps = self->nb_traps; + { + value = lttv_attribute_add(container, LTTV_STATE_RESOURCE_TRAPS, + LTTV_POINTER); + *(value.v_pointer) = lttv_state_copy_trap_states(self->trap_states, nb_traps); } /* save the blkdev states */ @@ -1421,7 +1460,7 @@ static void state_save(LttvTraceState *self, LttvAttribute *container) static void state_restore(LttvTraceState *self, LttvAttribute *container) { - guint i, nb_tracefile, pid, nb_cpus, nb_irqs, nb_soft_irqs; + guint i, nb_tracefile, pid, nb_cpus, nb_irqs, nb_soft_irqs, nb_traps; LttvTracefileState *tfcs; @@ -1487,6 +1526,13 @@ static void state_restore(LttvTraceState *self, LttvAttribute *container) lttv_state_free_soft_irq_states(self->soft_irq_states, nb_soft_irqs); self->soft_irq_states = lttv_state_copy_soft_irq_states(*(value.v_pointer), nb_soft_irqs); + /* restore trap resource states */ + nb_traps = self->nb_traps; + type = lttv_attribute_get_by_name(container, LTTV_STATE_RESOURCE_TRAPS, &value); + g_assert(type == LTTV_POINTER); + lttv_state_free_trap_states(self->trap_states, nb_traps); + self->trap_states = lttv_state_copy_trap_states(*(value.v_pointer), nb_traps); + /* restore the blkdev states */ type = lttv_attribute_get_by_name(container, LTTV_STATE_RESOURCE_BLKDEVS, &value); g_assert(type == LTTV_POINTER); @@ -2118,6 +2164,7 @@ lttv_state_create_process(LttvTraceState *tcs, LttvProcessState *parent, process->creation_time.tv_nsec); process->pid_time = g_quark_from_string(buffer); process->cpu = cpu; + process->free_events = 0; //process->last_cpu = tfs->cpu_name; //process->last_cpu_index = ltt_tracefile_num(((LttvTracefileContext*)tfs)->tf); process->execution_stack = g_array_sized_new(FALSE, FALSE, @@ -2192,17 +2239,23 @@ lttv_state_find_process_or_create(LttvTraceState *ts, guint cpu, guint pid, * has the flag SA_NOCLDWAIT. It can also happen when the child is part * of a killed thread group, but isn't the leader. */ -static void exit_process(LttvTracefileState *tfs, LttvProcessState *process) +static int exit_process(LttvTracefileState *tfs, LttvProcessState *process) { LttvTraceState *ts = LTTV_TRACE_STATE(tfs->parent.t_context); LttvProcessState key; + /* Wait for both schedule with exit dead and process free to happen. + * They can happen in any order. */ + if (++(process->free_events) < 2) + return 0; + key.pid = process->pid; key.cpu = process->cpu; g_hash_table_remove(ts->processes, &key); g_array_free(process->execution_stack, TRUE); g_array_free(process->user_stack, TRUE); g_free(process); + return 1; } @@ -2270,6 +2323,7 @@ static gboolean syscall_exit(void *hook_data, void *call_data) static gboolean trap_entry(void *hook_data, void *call_data) { LttvTracefileState *s = (LttvTracefileState *)call_data; + LttvTraceState *ts = (LttvTraceState *)s->parent.t_context; LttEvent *e = ltt_tracefile_get_event(s->parent.tf); LttvTraceHook *th = (LttvTraceHook *)hook_data; struct marker_field *f = lttv_trace_get_hook_field(th, 0); @@ -2294,18 +2348,28 @@ static gboolean trap_entry(void *hook_data, void *call_data) /* update cpu status */ cpu_push_mode(s->cpu_state, LTTV_CPU_TRAP); + /* update trap status */ + s->cpu_state->last_trap = trap; + ts->trap_states[trap].running++; + return FALSE; } static gboolean trap_exit(void *hook_data, void *call_data) { LttvTracefileState *s = (LttvTracefileState *)call_data; + LttvTraceState *ts = (LttvTraceState *)s->parent.t_context; + guint trap = s->cpu_state->last_trap; pop_state(s, LTTV_STATE_TRAP); /* update cpu status */ cpu_pop_mode(s->cpu_state); + /* update trap status */ + if(ts->trap_states[trap].running) + ts->trap_states[trap].running--; + return FALSE; } @@ -2614,9 +2678,13 @@ static gboolean schedchange(void *hook_data, void *call_data) process->state->change = s->parent.timestamp; } - if(state_out == 32 || state_out == 64) - exit_process(s, process); /* EXIT_DEAD || TASK_DEAD */ - /* see sched.h for states */ + if(state_out == 32 || state_out == 64) { /* EXIT_DEAD || TASK_DEAD */ + /* see sched.h for states */ + if (!exit_process(s, process)) { + process->state->s = LTTV_STATE_DEAD; + process->state->change = s->parent.timestamp; + } + } } } process = ts->running_process[cpu] = @@ -2714,8 +2782,9 @@ static gboolean process_fork(void *hook_data, void *call_data) * * Simply put a correct parent. */ - g_assert(0); /* This is a problematic case : the process has been created - before the fork event */ + g_error("Process %u has been created before fork on cpu %u. Probably an unsynchronized TSC problem on the traced machine.", child_pid, cpu); + //g_assert(0); /* This is a problematic case : the process has been created + // before the fork event */ child_process->ppid = process->pid; child_process->tgid = child_tgid; } @@ -2744,11 +2813,13 @@ static gboolean process_kernel_thread(void *hook_data, void *call_data) process = lttv_state_find_process_or_create(ts, ANY_CPU, pid, <t_time_zero); - process->execution_stack = - g_array_set_size(process->execution_stack, 1); - es = process->state = - &g_array_index(process->execution_stack, LttvExecutionState, 0); - es->t = LTTV_STATE_SYSCALL; + if (process->state->s != LTTV_STATE_DEAD) { + process->execution_stack = + g_array_set_size(process->execution_stack, 1); + es = process->state = + &g_array_index(process->execution_stack, LttvExecutionState, 0); + es->t = LTTV_STATE_SYSCALL; + } process->type = LTTV_STATE_KERNEL_THREAD; return FALSE; @@ -2792,7 +2863,10 @@ static gboolean process_free(void *hook_data, void *call_data) g_assert(release_pid != 0); process = lttv_state_find_process(ts, ANY_CPU, release_pid); - + if(likely(process != NULL)) + exit_process(s, process); + return FALSE; +//DISABLED if(likely(process != NULL)) { /* release_task is happening at kernel level : we can now safely release * the data structure of the process */ @@ -3929,6 +4003,7 @@ static void module_init() LTTV_STATE_RESOURCE_CPUS = g_quark_from_string("cpu count"); LTTV_STATE_RESOURCE_IRQS = g_quark_from_string("irq resource states"); LTTV_STATE_RESOURCE_SOFT_IRQS = g_quark_from_string("soft irq resource states"); + LTTV_STATE_RESOURCE_TRAPS = g_quark_from_string("trap resource states"); LTTV_STATE_RESOURCE_BLKDEVS = g_quark_from_string("blkdevs resource states");