From b8e25228f42c5eb0f2b8f8dea682bc6d86543e01 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Tue, 9 Sep 2014 22:22:46 +0200 Subject: [PATCH] Keeps a cumulative tick for all disk operations. --- cmdline/state.c | 23 ++++++++--------------- cmdline/state.h | 26 ++++++++++++++++++-------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/cmdline/state.c b/cmdline/state.c index 8b5f06a6..0d9cc922 100644 --- a/cmdline/state.c +++ b/cmdline/state.c @@ -85,8 +85,9 @@ void state_init(struct snapraid_state* state) for(l=0;lparity_path[l][0] = 0; state->parity_device[l] = 0; - state->tick[l] = 0; + state->tick_parity[l] = 0; } + state->tick_io = 0; state->tick_cpu = 0; state->tick_last = tick(); state->share[0] = 0; @@ -4333,8 +4334,6 @@ int state_progress(struct snapraid_state* state, block_off_t blockpos, block_off fflush(stdlog); } else { time_t now; - tommy_node* i; - unsigned l; int pred; now = time(0); @@ -4350,13 +4349,7 @@ int state_progress(struct snapraid_state* state, block_off_t blockpos, block_off printf("%u%%, %u MiB", countpos * 100 / countmax, (unsigned)(countsize / (1024*1024))); - tick_total = state->tick_cpu; - for(i=state->disklist;i!=0;i=i->next) { - struct snapraid_disk* disk = i->data; - tick_total += disk->tick; - } - for(l=0;llevel;++l) - tick_total += state->tick[l]; + tick_total = state->tick_cpu + state->tick_io; if (tick_total != 0) printf(", CPU %"PRIu64"%%", state->tick_cpu * 100U / tick_total); @@ -4457,9 +4450,9 @@ void state_usage_print(struct snapraid_state* state) tick_max = disk->tick; } for(l=0;llevel;++l) { - tick_total += state->tick[l]; - if (state->tick[l] > tick_max) - tick_max = state->tick[l]; + tick_total += state->tick_parity[l]; + if (state->tick_parity[l] > tick_max) + tick_max = state->tick_parity[l]; } if (!tick_total) @@ -4478,11 +4471,11 @@ void state_usage_print(struct snapraid_state* state) printf("Time for parity:"); for(l=0;llevel;++l) { - if (state->tick[l] == tick_max) + if (state->tick_parity[l] == tick_max) printf(" %s:", lev_config_name(l)); else printf(" "); - printf("%"PRIu64"%%", state->tick[l] * 100U / tick_total); + printf("%"PRIu64"%%", state->tick_parity[l] * 100U / tick_total); } printf("\n"); } diff --git a/cmdline/state.h b/cmdline/state.h index 0a3063cc..b61af92b 100644 --- a/cmdline/state.h +++ b/cmdline/state.h @@ -128,16 +128,21 @@ struct snapraid_state { tommy_hashdyn previmportset; /**< Hashtable by prevhash of all the import blocks. Valid only if we are in a rehash state. */ tommy_arrayblkof infoarr; /**< Block information array. */ - /** - * Cumulative time used for parity disks. - */ - uint64_t tick[LEV_MAX]; - /** * Cumulative time used for computations. */ uint64_t tick_cpu; + /** + * Cumulative time used for all io operations of disks. + */ + uint64_t tick_io; + + /** + * Cumulative time used for parity disks. + */ + uint64_t tick_parity[LEV_MAX]; + /** * Last time used for time measure. */ @@ -301,9 +306,10 @@ static inline void state_usage_waste(struct snapraid_state* state) static inline void state_usage_cpu(struct snapraid_state* state) { uint64_t now = tick(); + uint64_t delta = now - state->tick_last; /* increment the time spent in computations */ - state->tick_cpu += now - state->tick_last; + state->tick_cpu += delta; state->tick_last = now; } @@ -314,9 +320,11 @@ static inline void state_usage_cpu(struct snapraid_state* state) static inline void state_usage_disk(struct snapraid_state* state, struct snapraid_disk* disk) { uint64_t now = tick(); + uint64_t delta = now - state->tick_last; /* increment the time spent in the data disk */ - disk->tick += now - state->tick_last; + disk->tick += delta; + state->tick_io += delta; state->tick_last = now; } @@ -327,11 +335,13 @@ static inline void state_usage_disk(struct snapraid_state* state, struct snaprai static inline void state_usage_parity(struct snapraid_state* state, unsigned level) { uint64_t now = tick(); + uint64_t delta = now - state->tick_last; assert(level < LEV_MAX); /* increment the time spent in the parity disk */ - state->tick[level] += now - state->tick_last; + state->tick_parity[level] += delta; + state->tick_io += delta; state->tick_last = now; }