Browse Source

Keep track of how much work is staged per-algorithm

Luke Dashjr 11 years ago
parent
commit
6c03a3b59a
2 changed files with 19 additions and 9 deletions
  1. 16 7
      miner.c
  2. 3 2
      miner.h

+ 16 - 7
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 @@ retry:
 		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);

+ 3 - 2
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;
 }