Commit 89b6989fb31a72120985a2460e439a36bf545142

Kano 2012-09-19T00:54:55

Store and report Accepted,Rejected,Stale difficulty in the summary and API

diff --git a/API-README b/API-README
index 1fa904d..ad89b1f 100644
--- a/API-README
+++ b/API-README
@@ -387,16 +387,18 @@ API V1.19
 
 Added API commands:
  'debug'
- 'pgaidentify|N'
+ 'pgaidentify|N' (only works for BFL Singles so far)
  'setconfig|name,N'
 
 Modified API commands:
  Change pool field name 'Diff1 Shares' to 'Diff1 Work'
- 'devs' - add 'Diff1 Work' to all devices
- 'gpu|N' - add 'Diff1 Work'
- 'pga|N' - add 'Diff1 Work'
+ 'devs' - add 'Diff1 Work', 'Difficulty Accepted', 'Difficulty Rejected'
+          to all devices
+ 'gpu|N' - add 'Diff1 Work', 'Difficulty Accepted', 'Difficulty Rejected'
+ 'pga|N' - add 'Diff1 Work', 'Difficulty Accepted', 'Difficulty Rejected'
  'notify' - add '*Dev Throttle' (for BFL Singles)
- 'pools' - add 'Proxy Type', 'Proxy'
+ 'pools' - add 'Proxy Type', 'Proxy', 'Difficulty Accepted',
+               'Difficulty Rejected', 'Difficulty Stale'
  'config' - add 'Queue', 'Expiry'
 
 ----------
diff --git a/api.c b/api.c
index 01660af..9b4e017 100644
--- a/api.c
+++ b/api.c
@@ -776,6 +776,7 @@ static struct api_data *api_add_data_full(struct api_data *root, char *name, enu
 			case API_UTILITY:
 			case API_FREQ:
 			case API_HS:
+			case API_DIFF:
 				api_data->data = (void *)malloc(sizeof(double));
 				*((double *)(api_data->data)) = *((double *)data);
 				break;
@@ -902,6 +903,11 @@ struct api_data *api_add_hs(struct api_data *root, char *name, double *data, boo
 	return api_add_data_full(root, name, API_HS, (void *)data, copy_data);
 }
 
+struct api_data *api_add_diff(struct api_data *root, char *name, double *data, bool copy_data)
+{
+	return api_add_data_full(root, name, API_DIFF, (void *)data, copy_data);
+}
+
 static struct api_data *print_data(struct api_data *root, char *buf, bool isjson)
 {
 	struct api_data *tmp;
@@ -973,6 +979,9 @@ static struct api_data *print_data(struct api_data *root, char *buf, bool isjson
 			case API_HS:
 				sprintf(buf, "%.15f", *((double *)(root->data)));
 				break;
+			case API_DIFF:
+				sprintf(buf, "%.8f", *((double *)(root->data)));
+				break;
 			case API_BOOL:
 				sprintf(buf, "%s", *((bool *)(root->data)) ? TRUESTR : FALSESTR);
 				break;
@@ -1376,6 +1385,8 @@ static void gpustatus(int gpu, bool isjson)
 		root = api_add_time(root, "Last Share Time", &(cgpu->last_share_pool_time), false);
 		root = api_add_mhtotal(root, "Total MH", &(cgpu->total_mhashes), false);
 		root = api_add_int(root, "Diff1 Work", &(cgpu->diff1), false);
+		root = api_add_diff(root, "Difficulty Accepted", &(cgpu->diff_accepted), false);
+		root = api_add_diff(root, "Difficulty Rejected", &(cgpu->diff_rejected), false);
 
 		root = print_data(root, buf, isjson);
 		strcat(io_buffer, buf);
@@ -1460,6 +1471,8 @@ static void pgastatus(int pga, bool isjson)
 		root = api_add_mhtotal(root, "Total MH", &(cgpu->total_mhashes), false);
 		root = api_add_freq(root, "Frequency", &frequency, false);
 		root = api_add_int(root, "Diff1 Work", &(cgpu->diff1), false);
+		root = api_add_diff(root, "Difficulty Accepted", &(cgpu->diff_accepted), false);
+		root = api_add_diff(root, "Difficulty Rejected", &(cgpu->diff_rejected), false);
 
 		root = print_data(root, buf, isjson);
 		strcat(io_buffer, buf);
@@ -1493,6 +1506,8 @@ static void cpustatus(int cpu, bool isjson)
 		root = api_add_time(root, "Last Share Time", &(cgpu->last_share_pool_time), false);
 		root = api_add_mhtotal(root, "Total MH", &(cgpu->total_mhashes), false);
 		root = api_add_int(root, "Diff1 Work", &(cgpu->diff1), false);
+		root = api_add_diff(root, "Difficulty Accepted", &(cgpu->diff_accepted), false);
+		root = api_add_diff(root, "Difficulty Rejected", &(cgpu->diff_rejected), false);
 
 		root = print_data(root, buf, isjson);
 		strcat(io_buffer, buf);
@@ -1872,6 +1887,9 @@ static void poolstatus(__maybe_unused SOCKETTYPE c, __maybe_unused char *param, 
 			root = api_add_const(root, "Proxy Type", BLANK, false);
 			root = api_add_const(root, "Proxy", BLANK, false);
 		}
+		root = api_add_diff(root, "Difficulty Accepted", &(pool->diff_accepted), false);
+		root = api_add_diff(root, "Difficulty Rejected", &(pool->diff_rejected), false);
+		root = api_add_diff(root, "Difficulty Stale", &(pool->diff_stale), false);
 
 		if (isjson && (i > 0))
 			strcat(io_buffer, COMMA);
@@ -1924,6 +1942,9 @@ static void summary(__maybe_unused SOCKETTYPE c, __maybe_unused char *param, boo
 	root = api_add_uint(root, "Network Blocks", &(new_blocks), false);
 	root = api_add_mhtotal(root, "Total MH", &(total_mhashes_done), false);
 	root = api_add_utility(root, "Work Utility", &(work_utility), false);
+	root = api_add_diff(root, "Difficulty Accepted", &(total_diff_accepted), false);
+	root = api_add_diff(root, "Difficulty Rejected", &(total_diff_rejected), false);
+	root = api_add_diff(root, "Difficulty Stale", &(total_diff_stale), false);
 
 	root = print_data(root, buf, isjson);
 	if (isjson)
diff --git a/cgminer.c b/cgminer.c
index 4ad666d..cb61958 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -187,6 +187,7 @@ pthread_mutex_t control_lock;
 int hw_errors;
 int total_accepted, total_rejected, total_diff1;
 int total_getworks, total_stale, total_discarded;
+double total_diff_accepted, total_diff_rejected, total_diff_stale;
 static int total_queued, staged_rollable;
 unsigned int new_blocks;
 static unsigned int work_block;
@@ -1870,6 +1871,9 @@ static bool submit_upstream_work(const struct work *work, CURL *curl, bool resub
 		cgpu->accepted++;
 		total_accepted++;
 		pool->accepted++;
+		cgpu->diff_accepted += work->work_difficulty;
+		total_diff_accepted += work->work_difficulty;
+		pool->diff_accepted += work->work_difficulty;
 		pool->seq_rejects = 0;
 		cgpu->last_share_pool = pool->pool_no;
 		cgpu->last_share_pool_time = time(NULL);
@@ -1903,6 +1907,9 @@ static bool submit_upstream_work(const struct work *work, CURL *curl, bool resub
 		cgpu->rejected++;
 		total_rejected++;
 		pool->rejected++;
+		cgpu->diff_rejected += work->work_difficulty;
+		total_diff_rejected += work->work_difficulty;
+		pool->diff_rejected += work->work_difficulty;
 		pool->seq_rejects++;
 		applog(LOG_DEBUG, "PROOF OF WORK RESULT: false (booooo)");
 		if (!QUIET) {
@@ -2621,6 +2628,8 @@ static void *submit_work_thread(void *userdata)
 			sharelog("discard", work);
 			total_stale++;
 			pool->stale_shares++;
+			total_diff_stale += work->work_difficulty;
+			pool->diff_stale += work->work_difficulty;
 			goto out;
 		}
 		work->stale = true;
@@ -2634,6 +2643,8 @@ static void *submit_work_thread(void *userdata)
 			applog(LOG_NOTICE, "Share became stale while retrying submit, discarding");
 			total_stale++;
 			pool->stale_shares++;
+			total_diff_stale += work->work_difficulty;
+			pool->diff_stale += work->work_difficulty;
 			break;
 		}
 
@@ -3080,6 +3091,8 @@ static void display_pool_summary(struct pool *pool)
 		wlog(" Share submissions: %d\n", pool->accepted + pool->rejected);
 		wlog(" Accepted shares: %d\n", pool->accepted);
 		wlog(" Rejected shares: %d\n", pool->rejected);
+		wlog(" Accepted difficulty shares: %1.f\n", pool->diff_accepted);
+		wlog(" Rejected difficulty shares: %1.f\n", pool->diff_rejected);
 		if (pool->accepted || pool->rejected)
 			wlog(" Reject ratio: %.1f%%\n", (double)(pool->rejected * 100) / (double)(pool->accepted + pool->rejected));
 		efficiency = pool->getwork_requested ? pool->accepted * 100.0 / pool->getwork_requested : 0.0;
@@ -4996,6 +5009,8 @@ static void print_summary(void)
 	applog(LOG_WARNING, "Share submissions: %d", total_accepted + total_rejected);
 	applog(LOG_WARNING, "Accepted shares: %d", total_accepted);
 	applog(LOG_WARNING, "Rejected shares: %d", total_rejected);
+	applog(LOG_WARNING, "Accepted difficulty shares: %1.f", total_diff_accepted);
+	applog(LOG_WARNING, "Rejected difficulty shares: %1.f", total_diff_rejected);
 	if (total_accepted || total_rejected)
 		applog(LOG_WARNING, "Reject ratio: %.1f%%", (double)(total_rejected * 100) / (double)(total_accepted + total_rejected));
 	applog(LOG_WARNING, "Hardware errors: %d", hw_errors);
@@ -5021,6 +5036,8 @@ static void print_summary(void)
 			applog(LOG_WARNING, " Share submissions: %d", pool->accepted + pool->rejected);
 			applog(LOG_WARNING, " Accepted shares: %d", pool->accepted);
 			applog(LOG_WARNING, " Rejected shares: %d", pool->rejected);
+			applog(LOG_WARNING, " Accepted difficulty shares: %1.f", pool->diff_accepted);
+			applog(LOG_WARNING, " Rejected difficulty shares: %1.f", pool->diff_rejected);
 			if (pool->accepted || pool->rejected)
 				applog(LOG_WARNING, " Reject ratio: %.1f%%", (double)(pool->rejected * 100) / (double)(pool->accepted + pool->rejected));
 			efficiency = pool->getwork_requested ? pool->accepted * 100.0 / pool->getwork_requested : 0.0;
diff --git a/miner.h b/miner.h
index f3e9303..b94645e 100644
--- a/miner.h
+++ b/miner.h
@@ -401,6 +401,8 @@ struct cgpu_info {
 	float gpu_vddc;
 #endif
 	int diff1;
+	double diff_accepted;
+	double diff_rejected;
 	int last_share_pool;
 	time_t last_share_pool_time;
 
@@ -684,6 +686,7 @@ extern unsigned int new_blocks;
 extern unsigned int found_blocks;
 extern int total_accepted, total_rejected, total_diff1;;
 extern int total_getworks, total_stale, total_discarded;
+extern double total_diff_accepted, total_diff_rejected, total_diff_stale;
 extern unsigned int local_work;
 extern unsigned int total_go, total_ro;
 extern const int opt_cutofftemp;
@@ -748,6 +751,10 @@ struct pool {
 	int solved;
 	int diff1;
 
+	double diff_accepted;
+	double diff_rejected;
+	double diff_stale;
+
 	int queued;
 	int staged;
 
@@ -906,7 +913,8 @@ enum api_data_type {
 	API_UTILITY,
 	API_FREQ,
 	API_VOLTS,
-	API_HS
+	API_HS,
+	API_DIFF
 };
 
 struct api_data {
@@ -937,5 +945,6 @@ extern struct api_data *api_add_utility(struct api_data *root, char *name, doubl
 extern struct api_data *api_add_freq(struct api_data *root, char *name, double *data, bool copy_data);
 extern struct api_data *api_add_volts(struct api_data *root, char *name, float *data, bool copy_data);
 extern struct api_data *api_add_hs(struct api_data *root, char *name, double *data, bool copy_data);
+extern struct api_data *api_add_diff(struct api_data *root, char *name, double *data, bool copy_data);
 
 #endif /* __MINER_H__ */