Commit 2dc54366f9e65cc2b1ea4b5d1ca8319697a3a2d9

Kano 2013-09-23T20:16:15

klondike store and report errorcount and noise

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
diff --git a/driver-klondike.c b/driver-klondike.c
index 1be043a..389444a 100644
--- a/driver-klondike.c
+++ b/driver-klondike.c
@@ -64,6 +64,7 @@ typedef struct klondike_status {
 	uint8_t errorcount;
 	uint16_t hashcount;
 	uint16_t maxcount;
+	uint8_t noise;
 } WORKSTATUS;
 
 typedef struct _worktask {
@@ -102,13 +103,15 @@ struct klondike_info {
 	bool shutdown;
 	pthread_rwlock_t stat_lock;
 	struct thr_info replies_thr;
-	WORKSTATUS *status; 
+	WORKSTATUS *status;
 	DEVINFO *devinfo;
 	WORKCFG *cfg;
 	char *replies;
 	int nextreply;
 	int noncecount;
 	uint64_t hashcount;
+	uint64_t errorcount;
+	uint64_t noisecount;
 };
 
 IDENTITY KlondikeID;
@@ -131,7 +134,7 @@ static char *SendCmdGetReply(struct cgpu_info *klncgpu, char Cmd, int device, in
 	int retries = CMD_REPLY_RETRIES;
 	int chkreply = klninfo->nextreply;
 	int sent, err;
-	
+
 	if (klncgpu->usbinfo.nodev)
 		return NULL;
 
@@ -157,7 +160,7 @@ static char *SendCmdGetReply(struct cgpu_info *klncgpu, char Cmd, int device, in
 	}
 	return NULL;
 }
-			
+
 static bool klondike_get_stats(struct cgpu_info *klncgpu)
 {
 	struct klondike_info *klninfo = (struct klondike_info *)(klncgpu->device_data);
@@ -168,7 +171,7 @@ static bool klondike_get_stats(struct cgpu_info *klncgpu)
 
 	applog(LOG_DEBUG, "Klondike getting status");
 	slaves = klninfo->status[0].slavecount;
-	
+
 	// loop thru devices and get status for each
 	wr_lock(&(klninfo->stat_lock));
 	for (dev = 0; dev <= slaves; dev++) {
@@ -177,9 +180,9 @@ static bool klondike_get_stats(struct cgpu_info *klncgpu)
 			memcpy((void *)(&(klninfo->status[dev])), reply+2, sizeof(klninfo->status[dev]));
 	}
 	wr_unlock(&(klninfo->stat_lock));
-	
+
 	// todo: detect slavecount change and realloc space
-		
+
 	return true;
 }
 
@@ -187,15 +190,15 @@ static bool klondike_init(struct cgpu_info *klncgpu)
 {
 	struct klondike_info *klninfo = (struct klondike_info *)(klncgpu->device_data);
 	int slaves, dev;
-	
+
 	char *reply = SendCmdGetReply(klncgpu, 'S', 0, 0, NULL);
 	if (reply == NULL)
 		return false;
-		
+
 	slaves = ((WORKSTATUS *)(reply+2))->slavecount;
 	if (klninfo->status == NULL) {
 		applog(LOG_DEBUG, "Klondike initializing data");
-		
+
 		// alloc space for status, devinfo and cfg for master and slaves
 		klninfo->status = calloc(slaves+1, sizeof(WORKSTATUS));
 		if (unlikely(!klninfo->status))
@@ -207,27 +210,27 @@ static bool klondike_init(struct cgpu_info *klncgpu)
 		if (unlikely(!klninfo->cfg))
 			quit(1, "Failed to calloc cfg array in klondke_get_stats");
 	}
-		
+
 	WORKCFG cfgset = { 0,0,0,0,0 }; // zero init triggers read back only
 	double temp1, temp2;
 	int size = 2;
-	
+
 	if (opt_klondike_options != NULL) {  // boundaries are checked by device, with valid values returned
 		sscanf(opt_klondike_options, "%hu:%lf:%lf:%hhu", &cfgset.hashclock, &temp1, &temp2, &cfgset.fantarget);
 		cfgset.temptarget = cvtCToKln(temp1);
 		cfgset.tempcritical = cvtCToKln(temp2);
 		cfgset.fantarget = (int)255*cfgset.fantarget/100;
-		size = sizeof(cfgset); 
+		size = sizeof(cfgset);
 	}
-	
+
 	for (dev = 0; dev <= slaves; dev++) {
 		char *reply = SendCmdGetReply(klncgpu, 'C', dev, size, &cfgset);
 		if (reply != NULL) {
 			klninfo->cfg[dev] = *(WORKCFG *)(reply+2);
-			applog(LOG_NOTICE, "Klondike config (%d: Clk: %d, T:%.0lf, C:%.0lf, F:%d)", 
-				dev, klninfo->cfg[dev].hashclock, 
-				cvtKlnToC(klninfo->cfg[dev].temptarget), 
-				cvtKlnToC(klninfo->cfg[dev].tempcritical), 
+			applog(LOG_NOTICE, "Klondike config (%d: Clk: %d, T:%.0lf, C:%.0lf, F:%d)",
+				dev, klninfo->cfg[dev].hashclock,
+				cvtKlnToC(klninfo->cfg[dev].temptarget),
+				cvtKlnToC(klninfo->cfg[dev].tempcritical),
 				(int)100*klninfo->cfg[dev].fantarget/256);
 		}
 	}
@@ -236,9 +239,9 @@ static bool klondike_init(struct cgpu_info *klncgpu)
 		klninfo->devinfo[dev].rangesize = ((uint64_t)1<<32) / klninfo->status[dev].chipcount;
 		klninfo->devinfo[dev].chipstats = calloc(klninfo->status[dev].chipcount*2 , sizeof(uint32_t));
 	}
-		
+
 	SendCmdGetReply(klncgpu, 'E', 0, 1, "1");
-		
+
 	return true;
 }
 
@@ -249,23 +252,23 @@ static bool klondike_detect_one(struct libusb_device *dev, struct usb_find_devic
 
 	if (unlikely(!klncgpu))
 		quit(1, "Failed to calloc klncgpu in klondike_detect_one");
-		
+
 	klninfo = calloc(1, sizeof(*klninfo));
 	if (unlikely(!klninfo))
 		quit(1, "Failed to calloc klninfo in klondke_detect_one");
 	klncgpu->device_data = (FILE *)klninfo;
-	
+
 	klninfo->replies = calloc(MAX_REPLY_COUNT, REPLY_BUFSIZE);
 	if (unlikely(!klninfo->replies))
 		quit(1, "Failed to calloc replies buffer in klondke_detect_one");
 	klninfo->nextreply = 0;
-	
+
 	if (usb_init(klncgpu, dev, found)) {
-		int attempts = 0;		
+		int attempts = 0;
 		while (attempts++ < 3) {
 			char devpath[20], reply[REPLY_SIZE];
 			int sent, recd, err;
-			
+
 			sprintf(devpath, "%d:%d", (int)(klncgpu->usbinfo.bus_number), (int)(klncgpu->usbinfo.device_address));
 			err = usb_write(klncgpu, "I", 2, &sent, C_REQUESTRESULTS);
 			if (err < 0 || sent != 2) {
@@ -310,28 +313,28 @@ static void klondike_check_nonce(struct cgpu_info *klncgpu, WORKRESULT *result)
 {
 	struct klondike_info *klninfo = (struct klondike_info *)(klncgpu->device_data);
 	struct work *work, *tmp;
-	
+
 	applog(LOG_DEBUG, "Klondike FOUND NONCE (%02x:%08x)", result->workid, result->nonce);
 
 	HASH_ITER(hh, klncgpu->queued_work, work, tmp) {
 		if (work->queued && (work->subid == (result->device*256 + result->workid))) {
-			
+
 			wr_lock(&(klninfo->stat_lock));
 			klninfo->devinfo[result->device].noncecount++;
 			klninfo->noncecount++;
 			wr_unlock(&(klninfo->stat_lock));
-			
+
 			result->nonce = le32toh(result->nonce - 0xC0);
 			applog(LOG_DEBUG, "Klondike SUBMIT NONCE (%02x:%08x)", result->workid, result->nonce);
 			bool ok = submit_nonce(klncgpu->thr[0], work, result->nonce);
-			
+
 			applog(LOG_DEBUG, "Klondike chip stats %d, %08x, %d, %d", result->device, result->nonce, klninfo->devinfo[result->device].rangesize, klninfo->status[result->device].chipcount);
 			klninfo->devinfo[result->device].chipstats[(result->nonce / klninfo->devinfo[result->device].rangesize) + (ok ? 0 : klninfo->status[result->device].chipcount)]++;
 			return;
 		}
 	}
-	
-	applog(LOG_ERR, "%s%i:%d unknown work (%02x:%08x) - ignored",	
+
+	applog(LOG_ERR, "%s%i:%d unknown work (%02x:%08x) - ignored",
 		klncgpu->drv->name, klncgpu->device_id, result->device, result->workid, result->nonce);
 	//inc_hw_errors(klncgpu->thr[0]);
 }
@@ -341,18 +344,19 @@ static void *klondike_get_replies(void *userdata)
 {
 	struct cgpu_info *klncgpu = (struct cgpu_info *)userdata;
 	struct klondike_info *klninfo = (struct klondike_info *)(klncgpu->device_data);
+	struct klondike_status *ks;
 	char *replybuf;
 	int err, recd;
 
-	applog(LOG_DEBUG, "Klondike listening for replies");	
-	
+	applog(LOG_DEBUG, "Klondike listening for replies");
+
 	while (klninfo->shutdown == false) {
 		if (klncgpu->usbinfo.nodev)
 			return NULL;
-		
+
 		replybuf = klninfo->replies + klninfo->nextreply * REPLY_BUFSIZE;
 		replybuf[0] = 0;
-		
+
 		err = usb_read(klncgpu, replybuf+1, REPLY_SIZE, &recd, C_GETRESULTS);
 		if (!err && recd == REPLY_SIZE) {
 			if (opt_log_level <= LOG_DEBUG) {
@@ -362,10 +366,25 @@ static void *klondike_get_replies(void *userdata)
 			}
 			if (++klninfo->nextreply == MAX_REPLY_COUNT)
 				klninfo->nextreply = 0;
-				
+
 			replybuf[0] = replybuf[1];
-			if (replybuf[0] == '=')
-				klondike_check_nonce(klncgpu, (WORKRESULT *)replybuf);
+			switch (replybuf[0]) {
+				case '=':
+					klondike_check_nonce(klncgpu, (WORKRESULT *)replybuf);
+					break;
+				case 'S':
+				case 'W':
+				case 'A':
+				case 'E':
+					ks = (struct klondike_status *)(replybuf+1);
+					wr_lock(&(klninfo->stat_lock));
+					klninfo->errorcount += ks->errorcount;
+					klninfo->noisecount += ks->noise;
+					wr_unlock(&(klninfo->stat_lock));
+					break;
+				default:
+					break;
+			}
 		}
 	}
 	return NULL;
@@ -375,7 +394,7 @@ static void klondike_flush_work(struct cgpu_info *klncgpu)
 {
 	struct klondike_info *klninfo = (struct klondike_info *)(klncgpu->device_data);
 	int dev;
-			
+
 	applog(LOG_DEBUG, "Klondike flushing work");
 	for (dev = 0; dev <= klninfo->status->slavecount; dev++) {
 		char *reply = SendCmdGetReply(klncgpu, 'A', dev, 0, NULL);
@@ -391,16 +410,16 @@ static bool klondike_thread_prepare(struct thr_info *thr)
 {
 	struct cgpu_info *klncgpu = thr->cgpu;
 	struct klondike_info *klninfo = (struct klondike_info *)(klncgpu->device_data);
-	
+
 	if (thr_info_create(&(klninfo->replies_thr), NULL, klondike_get_replies, (void *)klncgpu)) {
 		applog(LOG_ERR, "%s%i: thread create failed", klncgpu->drv->name, klncgpu->device_id);
 		return false;
 	}
 	pthread_detach(klninfo->replies_thr.pth);
-	
+
 	// let the listening get started
 	cgsleep_ms(100);
-	
+
 	return klondike_init(klncgpu);
 }
 
@@ -412,7 +431,7 @@ static bool klondike_thread_init(struct thr_info *thr)
 		return false;
 
 	klondike_flush_work(klncgpu);
-	
+
 	return true;
 }
 
@@ -421,7 +440,7 @@ static void klondike_shutdown(struct thr_info *thr)
 	struct cgpu_info *klncgpu = thr->cgpu;
 	struct klondike_info *klninfo = (struct klondike_info *)(klncgpu->device_data);
 	int dev;
-	
+
 	applog(LOG_DEBUG, "Klondike shutting down work");
 	for (dev = 0; dev <= klninfo->status->slavecount; dev++) {
 		SendCmdGetReply(klncgpu, 'E', dev, 1, "0");
@@ -435,7 +454,7 @@ static void klondike_thread_enable(struct thr_info *thr)
 
 	if (klncgpu->usbinfo.nodev)
 		return;
-		
+
 	//SendCmdGetReply(klncgpu, 'E', 0, 1, "0");
 
 }
@@ -445,29 +464,29 @@ static bool klondike_send_work(struct cgpu_info *klncgpu, int dev, struct work *
 	struct klondike_info *klninfo = (struct klondike_info *)(klncgpu->device_data);
 	struct work *tmp;
 	WORKTASK data;
-	
+
 	if (klncgpu->usbinfo.nodev)
 		return false;
-			
+
 	memcpy(data.midstate, work->midstate, MIDSTATE_BYTES);
 	memcpy(data.merkle, work->data + MERKLE_OFFSET, MERKLE_BYTES);
 	data.workid = (uint8_t)(klninfo->devinfo[dev].nextworkid++ & 0xFF);
 	work->subid = dev*256 + data.workid;
-	
+
 	if (opt_log_level <= LOG_DEBUG) {
 		char *hexdata = bin2hex(&data.workid, sizeof(data)-3);
 		applog(LOG_DEBUG, "WORKDATA: %s", hexdata);
 		free(hexdata);
 	}
-	
+
 	applog(LOG_DEBUG, "Klondike sending work (%d:%02x)", dev, data.workid);
 	char *reply = SendCmdGetReply(klncgpu, 'W', dev, sizeof(data)-3, &data.workid);
 	if (reply != NULL) {
 		wr_lock(&(klninfo->stat_lock));
 		klninfo->status[dev] = *(WORKSTATUS *)(reply+2);
 		wr_unlock(&(klninfo->stat_lock));
-		
-		// remove old work 
+
+		// remove old work
 		HASH_ITER(hh, klncgpu->queued_work, work, tmp) {
 		if (work->queued && (work->subid == (int)(dev*256 + ((klninfo->devinfo[dev].nextworkid-2*MAX_WORK_COUNT) & 0xFF))))
 			work_completed(klncgpu, work);
@@ -482,7 +501,7 @@ static bool klondike_queue_full(struct cgpu_info *klncgpu)
 	struct klondike_info *klninfo = (struct klondike_info *)(klncgpu->device_data);
 	struct work *work = NULL;
 	int dev, queued;
-	
+
 	for (queued = 0; queued < MAX_WORK_COUNT-1; queued++)
 		for (dev = 0; dev <= klninfo->status->slavecount; dev++)
 			if (klninfo->status[dev].workqc <= queued) {
@@ -495,7 +514,7 @@ static bool klondike_queue_full(struct cgpu_info *klncgpu)
 					break;
 				}
 			}
-			
+
 	return true;
 }
 
@@ -505,10 +524,10 @@ static int64_t klondike_scanwork(struct thr_info *thr)
 	struct klondike_info *klninfo = (struct klondike_info *)(klncgpu->device_data);
 	int64_t newhashcount = 0;
 	int dev;
-	
+
 	if (klncgpu->usbinfo.nodev)
 		return -1;
-		
+
 	restart_wait(thr, 200);
 	if (klninfo->status != NULL) {
 		rd_lock(&(klninfo->stat_lock));
@@ -519,7 +538,7 @@ static int64_t klondike_scanwork(struct thr_info *thr)
 			newhashdev += klninfo->status[dev].hashcount - klninfo->devinfo[dev].lasthashcount;
 			klninfo->devinfo[dev].lasthashcount = klninfo->status[dev].hashcount;
 			klninfo->hashcount += (newhashdev << 32) / klninfo->status[dev].maxcount;
-			
+
 			// todo: check stats for critical conditions
 		}
 		newhashcount += 0xffffffffull * (uint64_t)klninfo->noncecount;
@@ -536,12 +555,12 @@ static void get_klondike_statline_before(char *buf, size_t siz, struct cgpu_info
 	uint8_t temp = 0xFF;
 	uint16_t fan = 0;
 	int dev;
-	
+
 	if (klninfo->status == NULL)
 		return;
 
 	rd_lock(&(klninfo->stat_lock));
-	for (dev = 0; dev <= klninfo->status->slavecount; dev++) { 
+	for (dev = 0; dev <= klninfo->status->slavecount; dev++) {
 		if (klninfo->status[dev].temp < temp)
 			temp = klninfo->status[dev].temp;
 		fan += klninfo->cfg[dev].fantarget;
@@ -558,21 +577,21 @@ static struct api_data *klondike_api_stats(struct cgpu_info *klncgpu)
 	struct api_data *root = NULL;
 	char buf[32];
 	int dev;
-	
+
 	if (klninfo->status == NULL)
 		return NULL;
-	
+
 	rd_lock(&(klninfo->stat_lock));
-	for (dev = 0; dev <= klninfo->status->slavecount; dev++) { 
+	for (dev = 0; dev <= klninfo->status->slavecount; dev++) {
 
 		float fTemp = cvtKlnToC(klninfo->status[dev].temp);
 		sprintf(buf, "Temp %d", dev);
 		root = api_add_temp(root, buf, &fTemp, true);
-	
+
 		double dClk = (double)klninfo->cfg[dev].hashclock;
 		sprintf(buf, "Clock %d", dev);
 		root = api_add_freq(root, buf, &dClk, true);
-		
+
 		unsigned int iFan = (unsigned int)100 * klninfo->cfg[dev].fantarget / 255;
 		sprintf(buf, "Fan Percent %d", dev);
 		root = api_add_int(root, buf, (int *)(&iFan), true);
@@ -582,7 +601,7 @@ static struct api_data *klondike_api_stats(struct cgpu_info *klncgpu)
 			iFan = (unsigned int)TACH_FACTOR / klninfo->status[dev].fanspeed;
 		sprintf(buf, "Fan RPM %d", dev);
 		root = api_add_int(root, buf, (int *)(&iFan), true);
-		
+
 		if (klninfo->devinfo[dev].chipstats != NULL) {
 			char data[2048];
 			char one[32];
@@ -595,7 +614,7 @@ static struct api_data *klondike_api_stats(struct cgpu_info *klncgpu)
 				strcat(data, one);
 			}
 			root = api_add_string(root, buf, data, true);
-		
+
 			sprintf(buf, "Errors / Chip %d", dev);
 			data[0] = '\0';
 			for (n = 0; n < klninfo->status[dev].chipcount; n++) {
@@ -607,9 +626,11 @@ static struct api_data *klondike_api_stats(struct cgpu_info *klncgpu)
 	}
 
 	root = api_add_uint64(root, "Hash Count", &(klninfo->hashcount), true);
+	root = api_add_uint64(root, "Error Count", &(klninfo->errorcount), true);
+	root = api_add_uint64(root, "Noise Count", &(klninfo->noisecount), true);
 
 	rd_unlock(&(klninfo->stat_lock));
-	
+
 	return root;
 }