From 6c03a3b59a616a72019b87f08df0d9a973cd1a0d Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Tue, 4 Nov 2014 15:50:31 +0000 Subject: [PATCH] Keep track of how much work is staged per-algorithm --- miner.c | 23 ++++++++++++++++------- miner.h | 5 +++-- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/miner.c b/miner.c index cf8c65ab97..d1dfd604d3 100644 --- a/miner.c +++ b/miner.c @@ -7131,6 +7131,18 @@ static void discard_work(struct work *work) free_work(work); } +static bool work_rollable(struct work *); + +static +void unstage_work(struct work * const work) +{ + HASH_DEL(staged_work, work); + --work_mining_algorithm(work)->staged; + if (work_rollable(work)) + --staged_rollable; + staged_full = false; +} + static void wake_gws(void) { mutex_lock(stgd_lock); @@ -7146,10 +7158,9 @@ static void discard_stale(void) mutex_lock(stgd_lock); HASH_ITER(hh, staged_work, work, tmp) { if (stale_work(work, false)) { - HASH_DEL(staged_work, work); + unstage_work(work); discard_work(work); stale++; - staged_full = false; } } pthread_cond_signal(&gws_cond); @@ -7441,6 +7452,7 @@ static bool hash_push(struct work *work) mutex_lock(stgd_lock); if (work_rollable(work)) staged_rollable++; + ++work_mining_algorithm(work)->staged; if (likely(!getq->frozen)) { HASH_ADD_INT(staged_work, id, work); HASH_SORT(staged_work, tv_sort); @@ -9199,10 +9211,9 @@ static void clear_pool_work(struct pool *pool) mutex_lock(stgd_lock); HASH_ITER(hh, staged_work, work, tmp) { if (work->pool == pool) { - HASH_DEL(staged_work, work); + unstage_work(work); free_work(work); cleared++; - staged_full = false; } } mutex_unlock(stgd_lock); @@ -9822,9 +9833,7 @@ static struct work *hash_pop(struct cgpu_info * const proc) goto retry; } - HASH_DEL(staged_work, work); - if (work_rollable(work)) - staged_rollable--; + unstage_work(work); /* Signal the getwork scheduler to look for more work */ pthread_cond_signal(&gws_cond); diff --git a/miner.h b/miner.h index 0471291169..4ff0f05d60 100644 --- a/miner.h +++ b/miner.h @@ -1133,6 +1133,7 @@ struct mining_algorithm { void (*hash_data_f)(void *digest, const void *data); int goal_refs; + int staged; struct mining_algorithm *next; }; @@ -1595,11 +1596,11 @@ extern void work_set_simple_ntime_roll_limit(struct work *, int ntime_roll, cons extern int work_ntime_range(struct work *, const struct timeval *tvp_earliest, const struct timeval *tvp_latest, int desired_roll); static inline -const struct mining_algorithm *work_mining_algorithm(const struct work * const work) +struct mining_algorithm *work_mining_algorithm(const struct work * const work) { const struct pool * const pool = work->pool; const struct mining_goal_info * const goal = pool->goal; - const struct mining_algorithm * const malgo = goal->malgo; + struct mining_algorithm * const malgo = goal->malgo; return malgo; }