Commit 08a7821072fb4a7f9373fc714ec5691fd0f37725

ckolivas 2011-06-29T10:12:00

Make the log show what the thread is: cpu or gpu and what number.

diff --git a/cpu-miner.c b/cpu-miner.c
index 89a7654..5f597f8 100644
--- a/cpu-miner.c
+++ b/cpu-miner.c
@@ -337,7 +337,7 @@ static bool submit_upstream_work(CURL *curl, const struct work *work)
 	json_t *val, *res;
 	char s[345];
 	bool rc = false;
-	const int thr_id = work->thr_id;
+	struct cgpu_info *cgpu = thr_info[work->thr_id].cgpu;
 
 	/* build hex string */
 	hexstr = bin2hex(work->data, sizeof(work->data));
@@ -367,17 +367,18 @@ static bool submit_upstream_work(CURL *curl, const struct work *work)
 	 * rejected values but the chance of two submits completing at the
 	 * same time is zero so there is no point adding extra locking */
 	if (json_is_true(res)) {
-		thr_info[thr_id].accepted++;
+		cgpu->accepted++;
 		accepted++;
 		if (opt_debug)
 			applog(LOG_DEBUG, "PROOF OF WORK RESULT: true (yay!!!)");
 	} else {
-		thr_info[thr_id].rejected++;
+		cgpu->rejected++;
 		rejected++;
 		if (opt_debug)
 			applog(LOG_DEBUG, "PROOF OF WORK RESULT: false (booooo)");
 	}
-	applog(LOG_INFO, "Thread: %d Accepted: %d Rejected: %d HW errors: %d", thr_id, thr_info[thr_id].accepted, thr_info[thr_id].rejected, thr_info[thr_id].hw_errors);
+	applog(LOG_INFO, "%sPU: %d Accepted: %d Rejected: %d HW errors: %d",
+	       cgpu->is_gpu? "G" : "C", cgpu->cpu_gpu, cgpu->accepted, cgpu->rejected, cgpu->hw_errors);
 
 	json_decref(val);
 
@@ -1397,9 +1398,20 @@ int main (int argc, char *argv[])
 	/* start GPU mining threads */
 	for (i = 0; i < gpu_threads; i++) {
 		int gpu = i % nDevs;
-		thr = &thr_info[i];
 
+		thr = &thr_info[i];
 		thr->id = i;
+		if (! (i % opt_g_threads)) {
+			thr->cgpu = calloc(1, sizeof(struct cgpu_info));
+			if (unlikely(!thr->cgpu)) {
+				applog(LOG_ERR, "Failed to calloc cgpu_info");
+				return 1;
+			}
+			thr->cgpu->is_gpu = 1;
+			thr->cgpu->cpu_gpu = gpu;
+		} else
+			thr->cgpu = thr_info[i - (i % opt_g_threads)].cgpu;
+
 		thr->q = tq_new();
 		if (!thr->q)
 			return 1;
@@ -1426,6 +1438,16 @@ int main (int argc, char *argv[])
 		thr = &thr_info[i];
 
 		thr->id = i;
+		if (! (i % opt_g_threads)) {
+			thr->cgpu = calloc(1, sizeof(struct cgpu_info));
+			if (unlikely(!thr->cgpu)) {
+				applog(LOG_ERR, "Failed to calloc cgpu_info");
+				return 1;
+			}
+			thr->cgpu->cpu_gpu = cpu_from_thr_id(i);
+		} else
+			thr->cgpu = thr_info[cpu_from_thr_id(i - (i % opt_g_threads))].cgpu;
+
 		thr->q = tq_new();
 		if (!thr->q)
 			return 1;
diff --git a/findnonce.c b/findnonce.c
index 8cc21c8..ca9b12f 100644
--- a/findnonce.c
+++ b/findnonce.c
@@ -204,7 +204,7 @@ out:
 		if (opt_debug)
 			applog(LOG_DEBUG, "No best_g found! Error in OpenCL code?");
 		hw_errors++;
-		thr->hw_errors++;
+		thr->cgpu->hw_errors++;
 	}
 	free(pcd);
 }
diff --git a/miner.h b/miner.h
index bb42cb5..a0913f2 100644
--- a/miner.h
+++ b/miner.h
@@ -110,13 +110,19 @@ enum {
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
 #endif
 
+struct cgpu_info {
+	int is_gpu;
+	int cpu_gpu;
+	int accepted;
+	int rejected;
+	int hw_errors;
+};
+
 struct thr_info {
 	int		id;
 	pthread_t	pth;
 	struct thread_q	*q;
-	int		accepted;
-	int		rejected;
-	int		hw_errors;
+	struct cgpu_info *cgpu;
 };
 
 static inline uint32_t swab32(uint32_t v)