X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Flttv%2Flttv%2Fstate.c;h=b0f79fcfac323326486c13e6cebc26e81ae3dbd6;hb=29af7cfdc9979121f09db4ba7c154f52d0fb518e;hp=ff5e27b59312083e53530b0cb2561d5a635fb2c7;hpb=fbfbd4dbe2e32419701b36cc4a1b266cc999c1f6;p=lttv.git diff --git a/ltt/branches/poly/lttv/lttv/state.c b/ltt/branches/poly/lttv/lttv/state.c index ff5e27b5..b0f79fcf 100644 --- a/ltt/branches/poly/lttv/lttv/state.c +++ b/ltt/branches/poly/lttv/lttv/state.c @@ -49,7 +49,8 @@ GQuark LTT_FACILITY_KERNEL_ARCH, LTT_FACILITY_LIST, LTT_FACILITY_FS, - LTT_FACILITY_USER_GENERIC; + LTT_FACILITY_USER_GENERIC, + LTT_FACILITY_BLOCK; /* Events Quarks */ @@ -72,7 +73,10 @@ GQuark LTT_EVENT_STATEDUMP_END, LTT_EVENT_FUNCTION_ENTRY, LTT_EVENT_FUNCTION_EXIT, - LTT_EVENT_THREAD_BRAND; + LTT_EVENT_THREAD_BRAND, + LTT_EVENT_REQUEST_ISSUE, + LTT_EVENT_REQUEST_COMPLETE, + LTT_EVENT_LIST_INTERRUPT; /* Fields Quarks */ @@ -96,7 +100,12 @@ GQuark LTT_FIELD_SUBMODE, LTT_FIELD_STATUS, LTT_FIELD_THIS_FN, - LTT_FIELD_CALL_SITE; + LTT_FIELD_CALL_SITE, + LTT_FIELD_MINOR, + LTT_FIELD_MAJOR, + LTT_FIELD_OPERATION, + LTT_FIELD_ACTION, + LTT_FIELD_NUM; LttvExecutionMode LTTV_STATE_MODE_UNKNOWN, @@ -139,6 +148,12 @@ LttvIRQMode LTTV_IRQ_IDLE, LTTV_IRQ_BUSY; +LttvBdevMode + LTTV_BDEV_UNKNOWN, + LTTV_BDEV_IDLE, + LTTV_BDEV_BUSY_READING, + LTTV_BDEV_BUSY_WRITING; + static GQuark LTTV_STATE_TRACEFILES, LTTV_STATE_PROCESSES, @@ -151,7 +166,9 @@ static GQuark LTTV_STATE_HOOKS, LTTV_STATE_NAME_TABLES, LTTV_STATE_TRACE_STATE_USE_COUNT, - LTTV_STATE_RESOURCE_CPUS; + LTTV_STATE_RESOURCE_CPUS, + LTTV_STATE_RESOURCE_IRQS, + LTTV_STATE_RESOURCE_BLKDEVS; static void create_max_time(LttvTraceState *tcs); @@ -172,6 +189,15 @@ static void lttv_state_free_process_table(GHashTable *processes); static void lttv_trace_states_read_raw(LttvTraceState *tcs, FILE *fp, GPtrArray *quarktable); +/* Resource function prototypes */ +static LttvBdevState *get_hashed_bdevstate(LttvTraceState *ts, guint16 devcode); +static LttvBdevState *bdevstate_new(void); +static void bdevstate_free(LttvBdevState *); +static void bdevstate_free_cb(gpointer key, gpointer value, gpointer user_data); +static LttvBdevState *bdevstate_copy(LttvBdevState *bds); +static LttvBdevState *bdev_state_get(LttvTraceState *ts, guint16 devcode); + + void lttv_state_save(LttvTraceState *self, LttvAttribute *container) { LTTV_TRACE_STATE_GET_CLASS(self)->state_save(self, container); @@ -231,7 +257,7 @@ static void lttv_state_free_usertraces(GHashTable *usertraces) static void restore_init_state(LttvTraceState *self) { - guint i, nb_cpus; + guint i, nb_cpus, nb_irqs; LttvTracefileState *tfcs; @@ -256,6 +282,7 @@ restore_init_state(LttvTraceState *self) //lttv_process_trace_seek_time(&self->parent, ltt_time_zero); nb_cpus = ltt_trace_get_num_cpu(self->parent.t); + nb_irqs = self->nb_irqs; /* Put the per cpu running_process to beginning state : process 0. */ for(i=0; i< nb_cpus; i++) { @@ -274,7 +301,21 @@ restore_init_state(LttvTraceState *self) //self->running_process[i]->state->s = LTTV_STATE_RUN; self->running_process[i]->cpu = i; + + /* reset cpu states */ + if(self->cpu_states[i].mode_stack->len > 0) + g_array_remove_range(self->cpu_states[i].mode_stack, 0, self->cpu_states[i].mode_stack->len); } + + /* reset irq states */ + for(i=0; iirq_states[i].mode_stack->len > 0) + g_array_remove_range(self->irq_states[i].mode_stack, 0, self->irq_states[i].mode_stack->len); + } + + /* reset bdev states */ + g_hash_table_foreach(self->bdev_states, bdevstate_free_cb, NULL); + g_hash_table_steal_all(self->bdev_states); #if 0 nb_tracefile = self->parent.tracefiles->len; @@ -440,6 +481,9 @@ init(LttvTracesetState *self, LttvTraceset *ts) g_assert(tcs->irq_states[j].mode_stack != NULL); } + /* init bdev resource stuff */ + tcs->bdev_states = g_hash_table_new(g_int_hash, g_int_equal); + restore_init_state(tcs); for(j = 0 ; j < nb_tracefile ; j++) { tfcs = @@ -1118,6 +1162,118 @@ static void lttv_state_free_cpu_states(LttvCPUState *states, guint n) g_free(states); } +static LttvIRQState *lttv_state_copy_irq_states(LttvIRQState *states, guint n) +{ + guint i,j; + LttvIRQState *retval; + + retval = g_malloc(n*sizeof(LttvIRQState)); + + for(i=0; ilen); + for(j=0; jlen; j++) { + g_array_index(retval[i].mode_stack, GQuark, j) = g_array_index(states[i].mode_stack, GQuark, j); + } + } + + return retval; +} + +static void lttv_state_free_irq_states(LttvIRQState *states, guint n) +{ + guint i; + + for(i=0; ibdev_states, &devcode_gint); + if(bdev == NULL) { + LttvBdevState *bdevstate = g_malloc(sizeof(LttvBdevState)); + bdevstate->mode_stack = g_array_new(FALSE, FALSE, sizeof(GQuark)); + + gint * key = g_malloc(sizeof(gint)); + *key = devcode; + g_hash_table_insert(ts->bdev_states, key, bdevstate); + + bdev = bdevstate; + } + + return bdev; +} + +static LttvBdevState *bdevstate_new(void) +{ + LttvBdevState *retval; + retval = g_malloc(sizeof(LttvBdevState)); + retval->mode_stack = g_array_new(FALSE, FALSE, sizeof(GQuark)); + + return retval; +} + +static void bdevstate_free(LttvBdevState *bds) +{ + g_array_free(bds->mode_stack, FALSE); + g_free(bds); +} + +static void bdevstate_free_cb(gpointer key, gpointer value, gpointer user_data) +{ + LttvBdevState *bds = (LttvBdevState *) value; + + bdevstate_free(bds); +} + +static LttvBdevState *bdevstate_copy(LttvBdevState *bds) +{ + LttvBdevState *retval; + + retval = bdevstate_new(); + g_array_insert_vals(retval->mode_stack, 0, bds->mode_stack->data, bds->mode_stack->len); + + return retval; +} + +static void insert_and_copy_bdev_state(gpointer k, gpointer v, gpointer u) +{ + GHashTable *ht = (GHashTable *)u; + LttvBdevState *bds = (LttvBdevState *)v; + LttvBdevState *newbds; + + newbds = bdevstate_copy(v); + + g_hash_table_insert(u, k, newbds); +} + +static GHashTable *lttv_state_copy_blkdev_hashtable(GHashTable *ht) +{ + GHashTable *retval; + + retval = g_hash_table_new(g_int_hash, g_int_equal); + + g_hash_table_foreach(ht, insert_and_copy_bdev_state, retval); + + return retval; +} + +/* Free a hashtable and the LttvBdevState structures its values + * point to. */ + +static void lttv_state_free_blkdev_hashtable(GHashTable *ht) +{ + g_hash_table_foreach(ht, bdevstate_free_cb, NULL); + g_hash_table_destroy(ht); +} + /* The saved state for each trace contains a member "processes", which stores a copy of the process table, and a member "tracefiles" with one entry per tracefile. Each tracefile has a "process" member pointing @@ -1126,7 +1282,7 @@ static void lttv_state_free_cpu_states(LttvCPUState *states, guint n) static void state_save(LttvTraceState *self, LttvAttribute *container) { - guint i, nb_tracefile, nb_cpus; + guint i, nb_tracefile, nb_cpus, nb_irqs; LttvTracefileState *tfcs; @@ -1199,16 +1355,33 @@ static void state_save(LttvTraceState *self, LttvAttribute *container) } } - value = lttv_attribute_add(container, LTTV_STATE_RESOURCE_CPUS, - LTTV_POINTER); - guint size = sizeof(LttvCPUState)*nb_cpus; - *(value.v_pointer) = lttv_state_copy_cpu_states(self->cpu_states, nb_cpus); + /* save the cpu state */ + { + guint size = sizeof(LttvCPUState)*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); + } + + /* save the irq state */ + nb_irqs = self->nb_irqs; + { + guint size = sizeof(LttvCPUState)*nb_irqs; + value = lttv_attribute_add(container, LTTV_STATE_RESOURCE_IRQS, + LTTV_POINTER); + *(value.v_pointer) = lttv_state_copy_irq_states(self->irq_states, nb_irqs); + } + + /* save the blkdev states */ + value = lttv_attribute_add(container, LTTV_STATE_RESOURCE_BLKDEVS, + LTTV_POINTER); + *(value.v_pointer) = lttv_state_copy_blkdev_hashtable(self->bdev_states); } static void state_restore(LttvTraceState *self, LttvAttribute *container) { - guint i, nb_tracefile, pid, nb_cpus; + guint i, nb_tracefile, pid, nb_cpus, nb_irqs; LttvTracefileState *tfcs; @@ -1249,8 +1422,6 @@ static void state_restore(LttvTraceState *self, LttvAttribute *container) g_assert(self->running_process[i] != NULL); } - printf("state restore\n"); - nb_tracefile = self->parent.tracefiles->len; //g_tree_destroy(tsc->pqueue); @@ -1262,6 +1433,19 @@ static void state_restore(LttvTraceState *self, LttvAttribute *container) lttv_state_free_cpu_states(self->cpu_states, nb_cpus); self->cpu_states = lttv_state_copy_cpu_states(*(value.v_pointer), nb_cpus); + /* restore 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(self->irq_states, nb_irqs); + self->irq_states = lttv_state_copy_irq_states(*(value.v_pointer), nb_irqs); + + /* restore 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(self->bdev_states); + self->bdev_states = lttv_state_copy_blkdev_hashtable(*(value.v_pointer)); + for(i = 0 ; i < nb_tracefile ; i++) { tfcs = LTTV_TRACEFILE_STATE(g_array_index(self->parent.tracefiles, @@ -1664,13 +1848,33 @@ static void cpu_push_mode(LttvCPUState *cpust, LttvCPUMode state) static void cpu_pop_mode(LttvCPUState *cpust) { - if(cpust->mode_stack->len == 1) + if(cpust->mode_stack->len <= 1) cpu_set_base_mode(cpust, LTTV_CPU_UNKNOWN); else g_array_set_size(cpust->mode_stack, cpust->mode_stack->len - 1); } /* clears the stack and sets the state passed as argument */ +static void bdev_set_base_mode(LttvBdevState *bdevst, LttvBdevMode state) +{ + g_array_set_size(bdevst->mode_stack, 1); + ((GQuark *)bdevst->mode_stack->data)[0] = state; +} + +static void bdev_push_mode(LttvBdevState *bdevst, LttvBdevMode state) +{ + g_array_set_size(bdevst->mode_stack, bdevst->mode_stack->len + 1); + ((GQuark *)bdevst->mode_stack->data)[bdevst->mode_stack->len - 1] = state; +} + +static void bdev_pop_mode(LttvBdevState *bdevst) +{ + if(bdevst->mode_stack->len <= 1) + bdev_set_base_mode(bdevst, LTTV_BDEV_UNKNOWN); + else + g_array_set_size(bdevst->mode_stack, bdevst->mode_stack->len - 1); +} + static void irq_set_base_mode(LttvIRQState *irqst, LttvIRQMode state) { g_array_set_size(irqst->mode_stack, 1); @@ -1685,7 +1889,7 @@ static void irq_push_mode(LttvIRQState *irqst, LttvIRQMode state) static void irq_pop_mode(LttvIRQState *irqst) { - if(irqst->mode_stack->len == 1) + if(irqst->mode_stack->len <= 1) irq_set_base_mode(irqst, LTTV_IRQ_UNKNOWN); else g_array_set_size(irqst->mode_stack, irqst->mode_stack->len - 1); @@ -2167,6 +2371,70 @@ static gboolean soft_irq_entry(void *hook_data, void *call_data) return FALSE; } +static gboolean enum_interrupt(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 fac_id = ltt_event_facility_id(e); + guint8 ev_id = ltt_event_eventtype_id(e); + LttvTraceHookByFacility *thf = (LttvTraceHookByFacility *)hook_data; + + GQuark action = g_quark_from_string(ltt_event_get_string(e, thf->f1)); + guint irq = ltt_event_get_long_unsigned(e, thf->f2); + + ts->irq_names[irq] = action; + + return FALSE; +} + + +static gboolean bdev_request_issue(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 fac_id = ltt_event_facility_id(e); + guint8 ev_id = ltt_event_eventtype_id(e); + LttvTraceHookByFacility *thf = (LttvTraceHookByFacility *)hook_data; + + guint major = ltt_event_get_long_unsigned(e, thf->f1); + guint minor = ltt_event_get_long_unsigned(e, thf->f2); + guint oper = ltt_event_get_long_unsigned(e, thf->f3); + guint16 devcode = MKDEV(major,minor); + + /* have we seen this block device before? */ + gpointer bdev = get_hashed_bdevstate(ts, devcode); + + if(oper == 0) + bdev_push_mode(bdev, LTTV_BDEV_BUSY_READING); + else + bdev_push_mode(bdev, LTTV_BDEV_BUSY_WRITING); + + return FALSE; +} + +static gboolean bdev_request_complete(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); + LttvTraceHookByFacility *thf = (LttvTraceHookByFacility *)hook_data; + + guint major = ltt_event_get_long_unsigned(e, thf->f1); + guint minor = ltt_event_get_long_unsigned(e, thf->f2); + guint oper = ltt_event_get_long_unsigned(e, thf->f3); + guint16 devcode = MKDEV(major,minor); + + /* have we seen this block device before? */ + gpointer bdev = get_hashed_bdevstate(ts, devcode); + + /* update block device */ + bdev_pop_mode(bdev); + + return FALSE; +} + static void push_function(LttvTracefileState *tfs, guint64 funcptr) { guint64 *new_func; @@ -2926,6 +3194,24 @@ void lttv_state_add_event_hooks(LttvTracesetState *self) statedump_end, NULL, &g_array_index(hooks, LttvTraceHook, hn++)); if(ret) hn--; + ret = lttv_trace_find_hook(ts->parent.t, + LTT_FACILITY_LIST, LTT_EVENT_LIST_INTERRUPT, + LTT_FIELD_ACTION, LTT_FIELD_NUM, 0, + enum_interrupt, NULL, &g_array_index(hooks, LttvTraceHook, hn++)); + if(ret) hn--; + + ret = lttv_trace_find_hook(ts->parent.t, + LTT_FACILITY_BLOCK, LTT_EVENT_REQUEST_ISSUE, + LTT_FIELD_MAJOR, LTT_FIELD_MINOR, LTT_FIELD_OPERATION, + bdev_request_issue, NULL, &g_array_index(hooks, LttvTraceHook, hn++)); + if(ret) hn--; + + ret = lttv_trace_find_hook(ts->parent.t, + LTT_FACILITY_BLOCK, LTT_EVENT_REQUEST_COMPLETE, + LTT_FIELD_MAJOR, LTT_FIELD_MINOR, LTT_FIELD_OPERATION, + bdev_request_complete, NULL, &g_array_index(hooks, LttvTraceHook, hn++)); + if(ret) hn--; + ret = lttv_trace_find_hook(ts->parent.t, LTT_FACILITY_USER_GENERIC, LTT_EVENT_FUNCTION_ENTRY, LTT_FIELD_THIS_FN, LTT_FIELD_CALL_SITE, 0, @@ -3608,6 +3894,8 @@ 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_IRQS = g_quark_from_string("irq resource states"); + LTTV_STATE_RESOURCE_BLKDEVS = g_quark_from_string("blkdevs resource states"); LTT_FACILITY_KERNEL = g_quark_from_string("kernel"); @@ -3615,6 +3903,7 @@ static void module_init() LTT_FACILITY_FS = g_quark_from_string("fs"); LTT_FACILITY_LIST = g_quark_from_string("list"); LTT_FACILITY_USER_GENERIC = g_quark_from_string("user_generic"); + LTT_FACILITY_BLOCK = g_quark_from_string("block"); LTT_EVENT_SYSCALL_ENTRY = g_quark_from_string("syscall_entry"); @@ -3636,6 +3925,9 @@ static void module_init() LTT_EVENT_FUNCTION_ENTRY = g_quark_from_string("function_entry"); LTT_EVENT_FUNCTION_EXIT = g_quark_from_string("function_exit"); LTT_EVENT_THREAD_BRAND = g_quark_from_string("thread_brand"); + LTT_EVENT_REQUEST_ISSUE = g_quark_from_string("_blk_request_issue"); + LTT_EVENT_REQUEST_COMPLETE = g_quark_from_string("_blk_request_complete"); + LTT_EVENT_LIST_INTERRUPT = g_quark_from_string("interrupt");; LTT_FIELD_SYSCALL_ID = g_quark_from_string("syscall_id"); @@ -3658,6 +3950,11 @@ static void module_init() LTT_FIELD_STATUS = g_quark_from_string("status"); LTT_FIELD_THIS_FN = g_quark_from_string("this_fn"); LTT_FIELD_CALL_SITE = g_quark_from_string("call_site"); + LTT_FIELD_MAJOR = g_quark_from_string("major"); + 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"); @@ -3668,6 +3965,11 @@ static void module_init() LTTV_IRQ_UNKNOWN = g_quark_from_string("unknown"); LTTV_IRQ_IDLE = g_quark_from_string("idle"); LTTV_IRQ_BUSY = g_quark_from_string("busy"); + + LTTV_BDEV_UNKNOWN = g_quark_from_string("unknown"); + LTTV_BDEV_IDLE = g_quark_from_string("idle"); + LTTV_BDEV_BUSY_READING = g_quark_from_string("busy_reading"); + LTTV_BDEV_BUSY_WRITING = g_quark_from_string("busy_writing"); } static void module_destroy()