From 4a418e158a42536c6a8006611277ff9b0723dea3 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Sun, 31 Jan 2016 16:38:29 +0100 Subject: [PATCH] Add time stats also for thread scheduling --- cmdline/dry.c | 3 +++ cmdline/scrub.c | 3 +++ cmdline/state.c | 22 ++++++++++++++++++++++ cmdline/state.h | 3 +++ cmdline/sync.c | 3 +++ 5 files changed, 34 insertions(+) diff --git a/cmdline/dry.c b/cmdline/dry.c index 47ba69dd..cfe33da5 100644 --- a/cmdline/dry.c +++ b/cmdline/dry.c @@ -217,6 +217,9 @@ static int state_dry_process(struct snapraid_state* state, struct snapraid_parit if (blockcur >= blockmax) break; + /* until now is scheduling */ + state_usage_sched(state); + /* for each disk, process the block */ for (j = 0; j < diskmax; ++j) { struct snapraid_task* task; diff --git a/cmdline/scrub.c b/cmdline/scrub.c index f9c3a78c..b85e1097 100644 --- a/cmdline/scrub.c +++ b/cmdline/scrub.c @@ -329,6 +329,9 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par if (blockcur >= blockmax) break; + /* until now is scheduling */ + state_usage_sched(state); + /* one more block processed for autosave */ ++autosavedone; --autosavemissing; diff --git a/cmdline/state.c b/cmdline/state.c index 8da0ad6f..1eb2fe1f 100644 --- a/cmdline/state.c +++ b/cmdline/state.c @@ -162,6 +162,7 @@ void state_init(struct snapraid_state* state) } state->tick_io = 0; state->tick_misc = 0; + state->tick_sched = 0; state->tick_raid = 0; state->tick_hash = 0; state->tick_last = tick(); @@ -3917,6 +3918,7 @@ static void state_progress_latest(struct snapraid_state* state) unsigned l; state->progress_tick_misc[state->progress_ptr] = state->tick_misc; + state->progress_tick_sched[state->progress_ptr] = state->tick_sched; state->progress_tick_raid[state->progress_ptr] = state->tick_raid; state->progress_tick_hash[state->progress_ptr] = state->tick_hash; state->progress_tick_io[state->progress_ptr] = state->tick_io; @@ -3950,6 +3952,7 @@ static void state_progress_graph(struct snapraid_state* state, struct snapraid_i tick_total = 0; tick_total += state->progress_tick_misc[current] - ref(state->progress_tick_misc, oldest); + tick_total += state->progress_tick_sched[current] - ref(state->progress_tick_sched, oldest); tick_total += state->progress_tick_raid[current] - ref(state->progress_tick_raid, oldest); tick_total += state->progress_tick_hash[current] - ref(state->progress_tick_hash, oldest); tick_total += state->progress_tick_io[current] - ref(state->progress_tick_io, oldest); @@ -4043,6 +4046,12 @@ static void state_progress_graph(struct snapraid_state* state, struct snapraid_i printc('*', v * bar / tick_total); printf("\n"); + v = state->progress_tick_sched[current] - ref(state->progress_tick_sched, oldest); + printr("sched", pad); + printf("%3" PRIu64 "%% | ", v * 100 / tick_total); + printc('*', v * bar / tick_total); + printf("\n"); + v = state->progress_tick_misc[current] - ref(state->progress_tick_misc, oldest); printr("misc", pad); printf("%3" PRIu64 "%% | ", v * 100 / tick_total); @@ -4140,11 +4149,13 @@ int state_progress(struct snapraid_state* state, struct snapraid_io* io, block_o oldest -= PROGRESS_MAX; tick_cpu = state->progress_tick_misc[state->progress_ptr] + + state->progress_tick_sched[state->progress_ptr] + state->progress_tick_raid[state->progress_ptr] + state->progress_tick_hash[state->progress_ptr]; tick_total = tick_cpu + state->progress_tick_io[state->progress_ptr]; oldest_tick_cpu = state->progress_tick_misc[oldest] + + state->progress_tick_sched[oldest] + state->progress_tick_raid[oldest] + state->progress_tick_hash[oldest]; oldest_tick_total = oldest_tick_cpu + state->progress_tick_io[oldest]; @@ -4230,6 +4241,17 @@ void state_usage_misc(struct snapraid_state* state) state->tick_last = now; } +void state_usage_sched(struct snapraid_state* state) +{ + uint64_t now = tick(); + uint64_t delta = now - state->tick_last; + + /* increment the time spent in computations */ + state->tick_sched += delta; + + state->tick_last = now; +} + void state_usage_raid(struct snapraid_state* state) { uint64_t now = tick(); diff --git a/cmdline/state.h b/cmdline/state.h index e4fcf72b..e51e4382 100644 --- a/cmdline/state.h +++ b/cmdline/state.h @@ -156,6 +156,7 @@ struct snapraid_state { * Cumulative time used for computations. */ uint64_t tick_misc; + uint64_t tick_sched; uint64_t tick_raid; uint64_t tick_hash; @@ -179,6 +180,7 @@ struct snapraid_state { block_off_t progress_pos[PROGRESS_MAX]; /**< Last positions of progress. */ data_off_t progress_size[PROGRESS_MAX]; /**< Last sizes of progress. */ uint64_t progress_tick_misc[PROGRESS_MAX]; /**< Last cpu ticks of progress. */ + uint64_t progress_tick_sched[PROGRESS_MAX]; /**< Last scheduling ticks of progress. */ uint64_t progress_tick_raid[PROGRESS_MAX]; /**< Last raid ticks of progress. */ uint64_t progress_tick_hash[PROGRESS_MAX]; /**< Last hash ticks of progress. */ uint64_t progress_tick_io[PROGRESS_MAX]; /**< Last io ticks of progress. */ @@ -342,6 +344,7 @@ void state_usage_waste(struct snapraid_state* state); * Set the usage time for CPU. */ void state_usage_misc(struct snapraid_state* state); +void state_usage_sched(struct snapraid_state* state); void state_usage_raid(struct snapraid_state* state); void state_usage_hash(struct snapraid_state* state); diff --git a/cmdline/sync.c b/cmdline/sync.c index cadbf7a3..43f474b4 100644 --- a/cmdline/sync.c +++ b/cmdline/sync.c @@ -772,6 +772,9 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari if (blockcur >= blockmax) break; + /* until now is scheduling */ + state_usage_sched(state); + /* one more block processed for autosave */ ++autosavedone; --autosavemissing;