From 2781179985f14fb9b5365defa53f30e54ed9f906 Mon Sep 17 00:00:00 2001 From: pmf Date: Tue, 31 Jul 2007 19:46:14 +0000 Subject: [PATCH] add block device resource tracing infrastructure to state.{c,h} git-svn-id: http://ltt.polymtl.ca/svn@2567 04897980-b3bd-0310-b5e0-8ef037075253 --- ltt/branches/poly/lttv/lttv/state.c | 129 +++++++++++++++++++++++++++- ltt/branches/poly/lttv/lttv/state.h | 26 +++++- 2 files changed, 148 insertions(+), 7 deletions(-) diff --git a/ltt/branches/poly/lttv/lttv/state.c b/ltt/branches/poly/lttv/lttv/state.c index ff5e27b5..848e6b1e 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,9 @@ 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; /* Fields Quarks */ @@ -96,7 +99,10 @@ 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; LttvExecutionMode LTTV_STATE_MODE_UNKNOWN, @@ -139,6 +145,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, @@ -440,6 +452,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 = @@ -1671,6 +1686,26 @@ static void cpu_pop_mode(LttvCPUState *cpust) } /* 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); @@ -2167,6 +2202,71 @@ static gboolean soft_irq_entry(void *hook_data, void *call_data) return FALSE; } +LttvBdevState *bdev_state_get(LttvTraceState *ts, guint16 devcode) +{ + gint devcode_gint = devcode; + gpointer bdev = g_hash_table_lookup(ts->bdev_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); + printf("adding key %u to hash table\n", *key); + + bdev = bdevstate; + } + + return bdev; +} + +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 = bdev_state_get(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 = bdev_state_get(ts, devcode); + + /* update block device */ + bdev_pop_mode(bdev); + + return FALSE; +} + static void push_function(LttvTracefileState *tfs, guint64 funcptr) { guint64 *new_func; @@ -2926,6 +3026,18 @@ 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_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, @@ -3615,6 +3727,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 +3749,8 @@ 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_FIELD_SYSCALL_ID = g_quark_from_string("syscall_id"); @@ -3658,6 +3773,9 @@ 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"); LTTV_CPU_UNKNOWN = g_quark_from_string("unknown"); LTTV_CPU_IDLE = g_quark_from_string("idle"); @@ -3668,6 +3786,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() diff --git a/ltt/branches/poly/lttv/lttv/state.h b/ltt/branches/poly/lttv/lttv/state.h index be2e0b1c..c8259f28 100644 --- a/ltt/branches/poly/lttv/lttv/state.h +++ b/ltt/branches/poly/lttv/lttv/state.h @@ -60,7 +60,8 @@ extern GQuark LTT_FACILITY_KERNEL_ARCH, LTT_FACILITY_FS, LTT_FACILITY_LIST, - LTT_FACILITY_USER_GENERIC; + LTT_FACILITY_USER_GENERIC, + LTT_FACILITY_BLOCK; /* Events Quarks */ @@ -83,7 +84,9 @@ extern 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; /* Fields Quarks */ @@ -106,7 +109,10 @@ extern 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; typedef struct _LttvTracesetState LttvTracesetState; typedef struct _LttvTracesetStateClass LttvTracesetStateClass; @@ -212,6 +218,13 @@ extern LttvIRQMode LTTV_IRQ_IDLE, LTTV_IRQ_BUSY; +typedef GQuark LttvBdevMode; +extern LttvBdevMode + LTTV_BDEV_UNKNOWN, + LTTV_BDEV_IDLE, + LTTV_BDEV_BUSY_READING, + LTTV_BDEV_BUSY_WRITING; + typedef struct _LttvExecutionState { LttvExecutionMode t; LttvExecutionSubmode n; @@ -300,6 +313,10 @@ typedef struct _LttvIRQState { GArray *mode_stack; } LttvIRQState; +typedef struct _LttvBdevState { + GArray *mode_stack; +} LttvBdevState; + struct _LttvTraceState { LttvTraceContext parent; @@ -325,6 +342,7 @@ struct _LttvTraceState { gboolean has_precomputed_states; LttvCPUState *cpu_states; /* state of each cpu */ LttvIRQState *irq_states; /* state of each irq handler */ + GHashTable *bdev_states; /* state of the block devices */ }; struct _LttvTraceStateClass { @@ -391,6 +409,6 @@ static inline guint lttv_state_get_target_pid(LttvTracefileState *tfs) #define HDR_QUARKS 9 #define HDR_QUARK 10 - +#define MKDEV(ma,mi) ((ma)<<8 | (mi)) #endif // STATE_H -- 2.34.1