Commit f7ec2dc826a3950971d14e1875e1ba9c0f073510

kanoi 2014-01-24T22:17:53

Merge pull request #538 from kanoi/master bab additions

diff --git a/driver-bab.c b/driver-bab.c
index e09d5f2..eaf7d42 100644
--- a/driver-bab.c
+++ b/driver-bab.c
@@ -2252,6 +2252,7 @@ static struct api_data *bab_api_stats(struct cgpu_info *babcgpu)
 {
 	struct bab_info *babinfo = (struct bab_info *)(babcgpu->device_data);
 	uint64_t history_good[BAB_MAXCHIPS], history_bad[BAB_MAXCHIPS];
+	uint64_t his_good_tot, his_bad_tot;
 	double history_elapsed[BAB_MAXCHIPS], diff;
 	bool elapsed_is_good[BAB_MAXCHIPS];
 	int speeds[BAB_CHIP_SPEEDS];
@@ -2261,7 +2262,7 @@ static struct api_data *bab_api_stats(struct cgpu_info *babcgpu)
 	int spi_work, chip_work, i, to, j, sp, bank, chip_off;
 	struct timeval now;
 	double elapsed, ghs;
-	float ghs_sum, ghs_tot;
+	float ghs_sum, his_ghs_tot;
 	float tot, hw;
 	K_ITEM *item;
 
@@ -2331,7 +2332,7 @@ static struct api_data *bab_api_stats(struct cgpu_info *babcgpu)
 	}
 	K_RUNLOCK(babinfo->nfree_list);
 
-	ghs_tot = 0;
+	his_ghs_tot = 0;
 	for (i = 0; i < babinfo->chips; i += CHIPS_PER_STAT) {
 		to = i + CHIPS_PER_STAT - 1;
 		if (to >= babinfo->chips)
@@ -2545,10 +2546,21 @@ static struct api_data *bab_api_stats(struct cgpu_info *babcgpu)
 		snprintf(buf, sizeof(buf), "Sum History GHs "FMT_RANGE, i, to);
 		root = api_add_avg(root, buf, &ghs_sum, true);
 
-		ghs_tot += ghs_sum;
+		his_ghs_tot += ghs_sum;
 	}
 
-	root = api_add_avg(root, "Total History GHs", &ghs_tot, true);
+	root = api_add_avg(root, "Total History GHs", &his_ghs_tot, true);
+
+	his_good_tot = his_bad_tot = 0;
+	for (i = 0; i < babinfo->chips; i++) {
+		his_good_tot += history_good[i];
+		his_bad_tot += history_bad[i];
+	}
+	if (his_good_tot + his_bad_tot)
+		tot = 100.0 * (float)his_bad_tot / (float)(his_good_tot + his_bad_tot);
+	else
+		tot = 0.0;
+	root = api_add_avg(root, "Total History HW%", &tot, true);
 
 	for (sp = 0; sp < BAB_CHIP_SPEEDS; sp++) {
 		if (sp < (BAB_CHIP_SPEEDS - 1))
@@ -2732,11 +2744,36 @@ static struct api_data *bab_api_stats(struct cgpu_info *babcgpu)
 static void bab_get_statline_before(char *buf, size_t bufsiz, struct cgpu_info *babcgpu)
 {
 	struct bab_info *babinfo = (struct bab_info *)(babcgpu->device_data);
+#if UPDATE_HISTORY
+	struct timeval now;
+	double elapsed;
+	int i, dead = 0;
+
+	cgtime(&now);
+	elapsed = tdiff(&now, &(babcgpu->dev_start_tv));
 
+	// At least get 15s of nonces before saying anything is dead
+	if (elapsed > 15.0) {
+		K_RLOCK(babinfo->nfree_list);
+		for (i = 0; i < babinfo->chips; i++) {
+			if (babinfo->good_nonces[i]->count == 0 &&
+			    babinfo->bad_nonces[i]->count > 1)
+				dead++;
+		}
+		K_RUNLOCK(babinfo->nfree_list);
+	}
+
+	tailsprintf(buf, bufsiz, "%d.%02d.%03d D:%03d | ",
+				 babinfo->banks,
+				 babinfo->boards,
+				 babinfo->chips,
+				 dead);
+#else
 	tailsprintf(buf, bufsiz, "B:%d B:%02d C:%03d | ",
 				 babinfo->banks,
 				 babinfo->boards,
 				 babinfo->chips);
+#endif
 }
 #endif