KnC: Use knc_decode_response() to make response processing more readable
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
diff --git a/driver-knc.c b/driver-knc.c
index 249733f..faa6b5c 100644
--- a/driver-knc.c
+++ b/driver-knc.c
@@ -62,10 +62,7 @@ struct knc_core_state {
int slot;
struct work *work;
} workslot[WORKS_PER_CORE]; /* active, next */
- struct {
- int slot;
- uint32_t nonce;
- } seen_nonces[5];
+ struct knc_report report;
struct {
int slot;
uint32_t nonce;
@@ -390,31 +387,23 @@ static int knc_core_handle_nonce(struct thr_info *thr, struct knc_core_state *co
}
}
-static int knc_core_process_report(struct thr_info *thr, struct knc_core_state *core, uint8_t *report)
+static int knc_core_process_report(struct thr_info *thr, struct knc_core_state *core, uint8_t *response)
{
- int n_nonces = core->die->version == KNC_VERSION_NEPTUNE ? 5 : 1;
- struct {
- int slot;
- uint32_t nonce;
- } nonces[5];
+ struct knc_report *report = &core->report;
+ knc_decode_report(response, report, core->die->version);
+
int n;
- for (n = 0; n < n_nonces; n++) {
- int slot = report[1+1+0+(1+4)*n]&0x0f;
- uint32_t nonce = report[1+1+1+(1+4)*n] << 24 |
- report[1+1+2+(1+4)*n] << 16 |
- report[1+1+3+(1+4)*n] << 8 |
- report[1+1+4+(1+4)*n] << 0;
- if (core->last_nonce.slot == slot && core->last_nonce.nonce == nonce)
+ for (n = 0; n < KNC_NONCES_PER_REPORT; n++) {
+ if (report->nonce[n].slot < 0)
+ break;
+ if (core->last_nonce.slot == report->nonce[n].slot && core->last_nonce.nonce == report->nonce[n].nonce)
break;
- nonces[n].slot = slot;
- nonces[n].nonce = nonce;
}
while(n-- > 0) {
- knc_core_handle_nonce(thr, core, nonces[n].slot, nonces[n].nonce);
+ knc_core_handle_nonce(thr, core, report->nonce[n].slot, report->nonce[n].nonce);
}
- int active_slot = report[2] >> 4;
- if (active_slot && core->workslot[1].slot == active_slot) {
+ if (report->active_slot && core->workslot[1].slot == report->active_slot) {
/* Core switched to next work */
if (core->workslot[0].work) {
core->die->knc->completed++;