X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Flttv%2Flttv%2Fstate.c;h=5bdfcebf40f3faa1f748d2bf9b62c1d6856b8c56;hb=9c731a505cf0d0ded02f8e90a823fa90084c7740;hp=d1120c7097c49b1ddcbf8761c113978b96f62713;hpb=60c5092c6e979b8cc1c9b762de473857d0ac7c97;p=lttv.git diff --git a/ltt/branches/poly/lttv/lttv/state.c b/ltt/branches/poly/lttv/lttv/state.c index d1120c70..5bdfcebf 100644 --- a/ltt/branches/poly/lttv/lttv/state.c +++ b/ltt/branches/poly/lttv/lttv/state.c @@ -21,6 +21,7 @@ #include #endif +#include #include #include #include @@ -105,8 +106,7 @@ GQuark LTT_FIELD_MINOR, LTT_FIELD_MAJOR, LTT_FIELD_OPERATION, - LTT_FIELD_ACTION, - LTT_FIELD_NUM; + LTT_FIELD_ACTION; LttvExecutionMode LTTV_STATE_MODE_UNKNOWN, @@ -168,7 +168,9 @@ static GQuark LTTV_STATE_NAME_TABLES, LTTV_STATE_TRACE_STATE_USE_COUNT, LTTV_STATE_RESOURCE_CPUS, + LTTV_STATE_RESOURCE_CPUS_COUNT, LTTV_STATE_RESOURCE_IRQS, + LTTV_STATE_RESOURCE_SOFT_IRQS, LTTV_STATE_RESOURCE_BLKDEVS; static void create_max_time(LttvTraceState *tcs); @@ -252,12 +254,15 @@ static void lttv_state_free_usertraces(GHashTable *usertraces) g_hash_table_destroy(usertraces); } - +gboolean rettrue(gpointer key, gpointer value, gpointer user_data) +{ + return TRUE; +} static void restore_init_state(LttvTraceState *self) { - guint i, nb_cpus, nb_irqs; + guint i, nb_cpus, nb_irqs, nb_soft_irqs; //LttvTracefileState *tfcs; @@ -283,6 +288,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; /* Put the per cpu running_process to beginning state : process 0. */ for(i=0; i< nb_cpus; i++) { @@ -313,9 +319,15 @@ restore_init_state(LttvTraceState *self) g_array_remove_range(self->irq_states[i].mode_stack, 0, self->irq_states[i].mode_stack->len); } + /* reset softirq states */ + for(i=0; isoft_irq_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); + //g_hash_table_steal_all(self->bdev_states); + g_hash_table_foreach_steal(self->bdev_states, rettrue, NULL); #if 0 nb_tracefile = self->parent.tracefiles->len; @@ -481,6 +493,10 @@ init(LttvTracesetState *self, LttvTraceset *ts) g_assert(tcs->irq_states[j].mode_stack != NULL); } + /* init soft irq stuff */ + /* the kernel has a statically fixed max of 32 softirqs */ + tcs->soft_irq_states = g_new(LttvSoftIRQState, tcs->nb_soft_irqs); + /* init bdev resource stuff */ tcs->bdev_states = g_hash_table_new(g_int_hash, g_int_equal); @@ -1154,7 +1170,7 @@ static void lttv_state_free_cpu_states(LttvCPUState *states, guint n) guint i; for(i=0; imode_stack, FALSE); + g_array_free(bds->mode_stack, TRUE); g_free(bds); } @@ -1351,6 +1386,10 @@ static void state_save(LttvTraceState *self, LttvAttribute *container) /* save the cpu state */ { + value = lttv_attribute_add(container, LTTV_STATE_RESOURCE_CPUS_COUNT, + LTTV_UINT); + *(value.v_uint) = nb_cpus; + value = lttv_attribute_add(container, LTTV_STATE_RESOURCE_CPUS, LTTV_POINTER); *(value.v_pointer) = lttv_state_copy_cpu_states(self->cpu_states, nb_cpus); @@ -1364,6 +1403,14 @@ static void state_save(LttvTraceState *self, LttvAttribute *container) *(value.v_pointer) = lttv_state_copy_irq_states(self->irq_states, nb_irqs); } + /* save the soft irq state */ + nb_irqs = self->nb_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); + } + /* save the blkdev states */ value = lttv_attribute_add(container, LTTV_STATE_RESOURCE_BLKDEVS, LTTV_POINTER); @@ -1373,7 +1420,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; + guint i, nb_tracefile, pid, nb_cpus, nb_irqs, nb_soft_irqs; LttvTracefileState *tfcs; @@ -1432,6 +1479,13 @@ static void state_restore(LttvTraceState *self, LttvAttribute *container) lttv_state_free_irq_states(self->irq_states, nb_irqs); self->irq_states = lttv_state_copy_irq_states(*(value.v_pointer), nb_irqs); + /* restore soft irq resource states */ + nb_soft_irqs = self->nb_soft_irqs; + type = lttv_attribute_get_by_name(container, LTTV_STATE_RESOURCE_SOFT_IRQS, &value); + g_assert(type == LTTV_POINTER); + 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 the blkdev states */ type = lttv_attribute_get_by_name(container, LTTV_STATE_RESOURCE_BLKDEVS, &value); g_assert(type == LTTV_POINTER); @@ -1479,7 +1533,7 @@ static void state_restore(LttvTraceState *self, LttvAttribute *container) static void state_saved_free(LttvTraceState *self, LttvAttribute *container) { - guint i, nb_tracefile, nb_cpus; + guint i, nb_tracefile, nb_cpus, nb_irqs; LttvTracefileState *tfcs; @@ -1508,13 +1562,31 @@ static void state_saved_free(LttvTraceState *self, LttvAttribute *container) lttv_attribute_remove_by_name(container, LTTV_STATE_PROCESSES); /* Free running processes array */ - nb_cpus = ltt_trace_get_num_cpu(self->parent.t); type = lttv_attribute_get_by_name(container, LTTV_STATE_RUNNING_PROCESS, &value); g_assert(type == LTTV_POINTER); running_process = *(value.v_pointer); g_free(running_process); + /* free cpu resource states */ + type = lttv_attribute_get_by_name(container, LTTV_STATE_RESOURCE_CPUS_COUNT, &value); + g_assert(type == LTTV_UINT); + nb_cpus = *value.v_uint; + type = lttv_attribute_get_by_name(container, LTTV_STATE_RESOURCE_CPUS, &value); + g_assert(type == LTTV_POINTER); + lttv_state_free_cpu_states(*(value.v_pointer), nb_cpus); + + /* free irq resource states */ + nb_irqs = self->nb_irqs; + type = lttv_attribute_get_by_name(container, LTTV_STATE_RESOURCE_IRQS, &value); + g_assert(type == LTTV_POINTER); + lttv_state_free_irq_states(*(value.v_pointer), nb_irqs); + + /* free the blkdev states */ + type = lttv_attribute_get_by_name(container, LTTV_STATE_RESOURCE_BLKDEVS, &value); + g_assert(type == LTTV_POINTER); + lttv_state_free_blkdev_hashtable(*(value.v_pointer)); + nb_tracefile = self->parent.tracefiles->len; for(i = 0 ; i < nb_tracefile ; i++) { @@ -1656,6 +1728,7 @@ create_name_tables(LttvTraceState *tcs) // } // } + name_tables->nb_syscalls = 256; name_tables->syscall_names = g_new(GQuark, 256); for(i = 0 ; i < 256 ; i++) { g_string_printf(fe_name, "syscall %d", i); @@ -1727,9 +1800,10 @@ create_name_tables(LttvTraceState *tcs) } */ - name_tables->nb_softirqs = 256; - name_tables->soft_irq_names = g_new(GQuark, 256); - for(i = 0 ; i < 256 ; i++) { + /* the kernel is limited to 32 statically defined softirqs */ + name_tables->nb_softirqs = 32; + name_tables->soft_irq_names = g_new(GQuark, name_tables->nb_softirqs); + for(i = 0 ; i < name_tables->nb_softirqs ; i++) { g_string_printf(fe_name, "softirq %d", i); name_tables->soft_irq_names[i] = g_quark_from_string(fe_name->str); } @@ -1758,7 +1832,7 @@ get_name_tables(LttvTraceState *tcs) tcs->irq_names = name_tables->irq_names; tcs->soft_irq_names = name_tables->soft_irq_names; tcs->nb_irqs = name_tables->nb_irqs; - tcs->nb_softirqs = name_tables->nb_softirqs; + tcs->nb_soft_irqs = name_tables->nb_softirqs; } @@ -2115,7 +2189,7 @@ lttv_state_find_process_or_create(LttvTraceState *ts, guint cpu, guint pid, * the parent waits for its child terminaison, but may also happen in special * cases in the child's exit : when the parent ignores its children SIGCCHLD or * has the flag SA_NOCLDWAIT. It can also happen when the child is part - * of a killed thread ground, but isn't the leader. + * of a killed thread group, but isn't the leader. */ static void exit_process(LttvTracefileState *tfs, LttvProcessState *process) { @@ -2273,12 +2347,17 @@ static gboolean irq_entry(void *hook_data, void *call_data) static gboolean soft_irq_exit(void *hook_data, void *call_data) { LttvTracefileState *s = (LttvTracefileState *)call_data; + LttvTraceState *ts = (LttvTraceState *)s->parent.t_context; + guint softirq = s->cpu_state->last_soft_irq; pop_state(s, LTTV_STATE_SOFT_IRQ); - return FALSE; -} + /* update softirq status */ + if(ts->soft_irq_states[softirq].running) + ts->soft_irq_states[softirq].running--; + return FALSE; +} static gboolean irq_exit(void *hook_data, void *call_data) { @@ -2299,6 +2378,7 @@ static gboolean irq_exit(void *hook_data, void *call_data) static gboolean soft_irq_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); //guint8 ev_id = ltt_event_eventtype_id(e); LttvTraceHook *th = (LttvTraceHook *)hook_data; @@ -2306,7 +2386,7 @@ static gboolean soft_irq_entry(void *hook_data, void *call_data) LttvExecutionSubmode submode; guint64 softirq = ltt_event_get_long_unsigned(e, f); - guint64 nb_softirqs = ((LttvTraceState *)(s->parent.t_context))->nb_softirqs; + guint64 nb_softirqs = ((LttvTraceState *)(s->parent.t_context))->nb_soft_irqs; if(softirq < nb_softirqs) { submode = ((LttvTraceState *)(s->parent.t_context))->soft_irq_names[softirq]; @@ -2320,6 +2400,11 @@ static gboolean soft_irq_entry(void *hook_data, void *call_data) /* Do something with the info about being in user or system mode when int? */ push_state(s, LTTV_STATE_SOFT_IRQ, submode); + + /* update softirq status */ + s->cpu_state->last_soft_irq = softirq; + ts->soft_irq_states[softirq].running++; + return FALSE; } @@ -2522,7 +2607,7 @@ static gboolean schedchange(void *hook_data, void *call_data) process->state->change = s->parent.timestamp; } - if(state_out == 32 || state_out == 128) + if(state_out == 32 || state_out == 64) exit_process(s, process); /* EXIT_DEAD || TASK_DEAD */ /* see sched.h for states */ } @@ -2541,9 +2626,18 @@ static gboolean schedchange(void *hook_data, void *call_data) /* update cpu status */ if(pid_in == 0) + /* going to idle task */ cpu_set_base_mode(s->cpu_state, LTTV_CPU_IDLE); - else + else { + /* scheduling a real task. + * we must be careful here: + * if we just schedule()'ed to a process that is + * in a trap, we must put the cpu in trap mode + */ cpu_set_base_mode(s->cpu_state, LTTV_CPU_BUSY); + if(process->state->t == LTTV_STATE_TRAP) + cpu_push_mode(s->cpu_state, LTTV_CPU_TRAP); + } return FALSE; } @@ -2872,6 +2966,8 @@ static gboolean enum_process_state(void *hook_data, void *call_data) f = lttv_trace_get_hook_field(th, 3); type = ltt_enum_string_get(f, ltt_event_get_unsigned(e, f)); + //FIXME: type is rarely used, enum must match possible types. + /* mode */ f = lttv_trace_get_hook_field(th, 4); mode = ltt_enum_string_get(f,ltt_event_get_unsigned(e, f)); @@ -3117,7 +3213,7 @@ void lttv_state_add_event_hooks(LttvTracesetState *self) process_free, NULL, &hooks); lttv_trace_find_hook(ts->parent.t, - LTT_FACILITY_KERNEL, + LTT_FACILITY_FS, LTT_EVENT_EXEC, FIELD_ARRAY(LTT_FIELD_FILENAME), process_exec, NULL, &hooks); @@ -3146,7 +3242,7 @@ void lttv_state_add_event_hooks(LttvTracesetState *self) lttv_trace_find_hook(ts->parent.t, LTT_FACILITY_LIST, LTT_EVENT_LIST_INTERRUPT, - FIELD_ARRAY(LTT_FIELD_ACTION, LTT_FIELD_NUM), + FIELD_ARRAY(LTT_FIELD_ACTION, LTT_FIELD_IRQ_ID), enum_interrupt, NULL, &hooks); lttv_trace_find_hook(ts->parent.t, @@ -3791,8 +3887,8 @@ lttv_tracefile_state_get_type(void) static void module_init() { - LTTV_STATE_UNNAMED = g_quark_from_string("UNNAMED"); - LTTV_STATE_UNBRANDED = g_quark_from_string("UNBRANDED"); + LTTV_STATE_UNNAMED = g_quark_from_string(""); + LTTV_STATE_UNBRANDED = g_quark_from_string(""); LTTV_STATE_MODE_UNKNOWN = g_quark_from_string("MODE_UNKNOWN"); LTTV_STATE_USER_MODE = g_quark_from_string("USER_MODE"); LTTV_STATE_SYSCALL = g_quark_from_string("SYSCALL"); @@ -3823,7 +3919,9 @@ static void module_init() LTTV_STATE_TRACE_STATE_USE_COUNT = g_quark_from_string("trace_state_use_count"); LTTV_STATE_RESOURCE_CPUS = g_quark_from_string("cpu resource states"); + 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_BLKDEVS = g_quark_from_string("blkdevs resource states"); @@ -3841,8 +3939,8 @@ static void module_init() LTT_EVENT_TRAP_EXIT = g_quark_from_string("trap_exit"); LTT_EVENT_IRQ_ENTRY = g_quark_from_string("irq_entry"); LTT_EVENT_IRQ_EXIT = g_quark_from_string("irq_exit"); - LTT_EVENT_SOFT_IRQ_ENTRY = g_quark_from_string("soft_irq_entry"); - LTT_EVENT_SOFT_IRQ_EXIT = g_quark_from_string("soft_irq_exit"); + LTT_EVENT_SOFT_IRQ_ENTRY = g_quark_from_string("softirq_entry"); + LTT_EVENT_SOFT_IRQ_EXIT = g_quark_from_string("softirq_exit"); LTT_EVENT_SCHED_SCHEDULE = g_quark_from_string("sched_schedule"); LTT_EVENT_PROCESS_FORK = g_quark_from_string("process_fork"); LTT_EVENT_KTHREAD_CREATE = g_quark_from_string("kthread_create"); @@ -3883,7 +3981,6 @@ static void module_init() LTT_FIELD_MINOR = g_quark_from_string("minor"); LTT_FIELD_OPERATION = g_quark_from_string("direction"); LTT_FIELD_ACTION = g_quark_from_string("action"); - LTT_FIELD_NUM = g_quark_from_string("num"); LTTV_CPU_UNKNOWN = g_quark_from_string("unknown"); LTTV_CPU_IDLE = g_quark_from_string("idle");