Browse Source

Merge commit 'a76b09e' into cg_merges_20131023a

Conflicts:
	miner.c
Luke Dashjr 12 years ago
parent
commit
305a4e3b74
4 changed files with 54 additions and 6 deletions
  1. 3 3
      README
  2. 1 0
      api.c
  3. 48 3
      miner.c
  4. 2 0
      miner.h

+ 3 - 3
README

@@ -506,9 +506,9 @@ If all pools are set to zero quota or all pools with quota are dead, it will
 fall back to a failover mode. See quota below for more information.
 
 The failover-only flag has special meaning in combination with load-balance
-mode and it will distribute quota back to pool 0 from any pools that are
-unable to provide work for any reason so as to maintain quota ratios between
-the rest of the pools.
+mode and it will distribute quota back to priority pool 0 from any pools that
+are unable to provide work for any reason so as to maintain quota ratios
+between the rest of the pools.
 
 BALANCE:
 This strategy monitors the amount of difficulty 1 shares solved for each pool

+ 1 - 0
api.c

@@ -2567,6 +2567,7 @@ static void poolquota(struct io_data *io_data, __maybe_unused SOCKETTYPE c, char
 	}
 
 	pool->quota = quota;
+	adjust_quota_gcd();
 	message(io_data, MSG_SETQUOTA, quota, pool->rpc_url, isjson);
 }
 

+ 48 - 3
miner.c

@@ -148,6 +148,7 @@ int opt_expiry_lp = 3600;
 int opt_bench_algo = -1;
 unsigned long long global_hashrate;
 static bool opt_unittest = false;
+unsigned long global_quota_gcd = 1;
 
 #ifdef HAVE_OPENCL
 int opt_dynamic_interval = 7;
@@ -605,6 +606,47 @@ static void sharelog(const char*disposition, const struct work*work)
 
 static char *getwork_req = "{\"method\": \"getwork\", \"params\": [], \"id\":0}\n";
 
+/* Adjust all the pools' quota to the greatest common denominator after a pool
+ * has been added or the quotas changed. */
+void adjust_quota_gcd(void)
+{
+	unsigned long gcd, lowest_quota = ~0UL, quota;
+	struct pool *pool;
+	int i;
+
+	for (i = 0; i < total_pools; i++) {
+		pool = pools[i];
+		quota = pool->quota;
+		if (!quota)
+			continue;
+		if (quota < lowest_quota)
+			lowest_quota = quota;
+	}
+
+	if (likely(lowest_quota < ~0UL)) {
+		gcd = lowest_quota;
+		for (i = 0; i < total_pools; i++) {
+			pool = pools[i];
+			quota = pool->quota;
+			if (!quota)
+				continue;
+			while (quota % gcd)
+				gcd--;
+		}
+	} else
+		gcd = 1;
+
+	for (i = 0; i < total_pools; i++) {
+		pool = pools[i];
+		pool->quota_used *= global_quota_gcd;
+		pool->quota_used /= gcd;
+		pool->quota_gcd = pool->quota / gcd;
+	}
+
+	global_quota_gcd = gcd;
+	applog(LOG_DEBUG, "Global quota greatest common denominator set to %lu", gcd);
+}
+
 /* Return value is ignored if not called from add_pool_details */
 struct pool *add_pool(void)
 {
@@ -629,6 +671,7 @@ struct pool *add_pool(void)
 
 	pool->rpc_proxy = NULL;
 	pool->quota = 1;
+	adjust_quota_gcd();
 
 	pool->sock = INVSOCK;
 	pool->lp_socket = CURL_SOCKET_BAD;
@@ -1085,6 +1128,7 @@ static char *set_quota(char *arg)
 	setup_url(pool, url);
 	pool->quota = quota;
 	applog(LOG_INFO, "Setting pool %d to quota %d", pool->pool_no, pool->quota);
+	adjust_quota_gcd();
 
 	return NULL;
 }
@@ -4017,16 +4061,16 @@ retry:
 	tested = 0;
 	while (!pool && tested++ < total_pools) {
 		pool = pools[rotating_pool];
-		if (pool->quota_used++ >= pool->quota) {
+		if (pool->quota_used++ >= pool->quota_gcd) {
 			pool->quota_used = 0;
 			pool = NULL;
 		} else {
 			if (!pool_unworkable(pool))
 				break;
 			/* Failover-only flag for load-balance means distribute
-			 * unused quota to pool 0. */
+			 * unused quota to priority pool 0. */
 			if (opt_fail_only)
-				pools[0]->quota++;
+				priority_pool(0)->quota_used--;
 		}
 		pool = NULL;
 		if (++rotating_pool >= total_pools)
@@ -6568,6 +6612,7 @@ retry:
 			goto retry;
 		}
 		pool->quota = selected;
+		adjust_quota_gcd();
 		goto updated;
 	} else if (!strncasecmp(&input, "f", 1)) {
 		opt_fail_only ^= true;

+ 2 - 0
miner.h

@@ -1012,6 +1012,7 @@ extern int enabled_pools;
 extern bool get_intrange(const char *arg, int *val1, int *val2);
 extern bool detect_stratum(struct pool *pool, char *url);
 extern void print_summary(void);
+extern void adjust_quota_gcd(void);
 extern struct pool *add_pool(void);
 extern bool add_pool_details(struct pool *pool, bool live, char *url, char *user, char *pass);
 
@@ -1183,6 +1184,7 @@ struct pool {
 	int diff1;
 	char diff[8];
 	int quota;
+	int quota_gcd;
 	int quota_used;
 
 	double diff_accepted;