minion - always check the chip queue before queuing new work
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
diff --git a/driver-minion.c b/driver-minion.c
index 960940a..dc25838 100644
--- a/driver-minion.c
+++ b/driver-minion.c
@@ -42,7 +42,7 @@ static bool minreread = true;
* If disabled, it will test chips just as 'pin 0'
* but never do any gpio - the equivalent of the previous 'no pins' code
*/
-static bool usepins = true;
+static bool usepins = false;
#define MINION_PAGE_SIZE 4096
@@ -386,7 +386,7 @@ struct minion_status {
uint32_t freq;
uint32_t quework;
uint32_t chipwork;
- uint32_t realwork; // chipwork, but FIFO_STA can update it
+ uint32_t realwork; // FIFO_STA
struct timeval last;
bool overheat;
bool islow;
@@ -493,7 +493,7 @@ typedef struct witem {
struct timeval sent;
int nonces;
bool urgent;
- bool stale; // if stale, don't decrement que/chip/realwork when discarded
+ bool stale; // if stale, don't decrement que/chipwork when discarded
bool rolled;
int errors; // uncertain since the error could mean task_id is wrong
} WITEM;
@@ -2272,17 +2272,23 @@ static void *minion_spi_write(void *userdata)
case WRITE_ADDR(MINION_SYS_RSTN_CTL):
// Do this here after it has actually been flushed
if ((titem->wbuf[0] & SYS_RSTN_CTL_FLUSH) == SYS_RSTN_CTL_FLUSH) {
+ int cnt = 0;
K_WLOCK(minioninfo->wwork_list);
work = minioninfo->wchip_list[chip]->head;
while (work) {
+ cnt++;
DATAW(work)->stale = true;
- minioninfo->chip_status[chip].chipwork--;
- if (minioninfo->chip_status[chip].realwork > 0)
- minioninfo->chip_status[chip].realwork--;
work = work->next;
}
minioninfo->chip_status[chip].chipwork = 0;
minioninfo->chip_status[chip].realwork = 0;
+#if MINION_SHOW_IO
+ applog(IOCTRL_LOG, "RSTN chip %d (cnt=%d) cw0=%u rw0=%u qw=%u",
+ chip, cnt,
+ minioninfo->chip_status[chip].chipwork,
+ minioninfo->chip_status[chip].realwork,
+ minioninfo->chip_status[chip].quework);
+#endif
K_WUNLOCK(minioninfo->wwork_list);
}
break;
@@ -2292,7 +2298,13 @@ static void *minion_spi_write(void *userdata)
k_add_head(minioninfo->wchip_list[chip], titem->witem);
minioninfo->chip_status[chip].quework--;
minioninfo->chip_status[chip].chipwork++;
- minioninfo->chip_status[chip].realwork++;
+#if MINION_SHOW_IO
+ applog(IOCTRL_LOG, "QUE_0 chip %d cw+1=%u rw=%u qw-1=%u",
+ chip,
+ minioninfo->chip_status[chip].chipwork,
+ minioninfo->chip_status[chip].realwork,
+ minioninfo->chip_status[chip].quework);
+#endif
K_WUNLOCK(minioninfo->wchip_list[chip]);
break;
case READ_ADDR(MINION_CORE_ENA0_31):
@@ -2352,7 +2364,6 @@ static void *minion_spi_reply(void *userdata)
K_ITEM *item;
TITEM fifo_task, res1_task, res2_task;
int chip, resoff;
- int chipwork, gap;
bool somelow;
struct timeval now;
@@ -2432,14 +2443,18 @@ static void *minion_spi_reply(void *userdata)
fifo_task.chip = chip;
fifo_task.reply = 0;
minion_txrx(&fifo_task);
- if (fifo_task.reply <= 0)
+ if (fifo_task.reply <= 0) {
+ minioninfo->spi_errors++;
+ minioninfo->fifo_spi_errors[chip]++;
+ minioninfo->res_err_count[chip]++;
break;
- else {
+ } else {
if (fifo_task.reply < (int)(fifo_task.osiz)) {
char *buf = bin2hex((unsigned char *)(&(fifo_task.rbuf[fifo_task.osiz - fifo_task.rsiz])),
(int)(fifo_task.rsiz));
- applog(LOG_ERR, "%s%i: Bad fifo reply (%s) size %d, should be %d",
- minioncgpu->drv->name, minioncgpu->device_id, buf,
+ applog(LOG_ERR, "%s%i: Chip %d Bad fifo reply (%s) size %d, should be %d",
+ minioncgpu->drv->name, minioncgpu->device_id,
+ chip, buf,
fifo_task.reply, (int)(fifo_task.osiz));
free(buf);
minioninfo->spi_errors++;
@@ -2447,19 +2462,19 @@ static void *minion_spi_reply(void *userdata)
minioninfo->res_err_count[chip]++;
} else {
if (fifo_task.reply > (int)(fifo_task.osiz)) {
- applog(LOG_ERR, "%s%i: Unexpected fifo reply size %d, expected only %d",
+ applog(LOG_ERR, "%s%i: Chip %d Unexpected fifo reply size %d, expected only %d",
minioncgpu->drv->name, minioncgpu->device_id,
- fifo_task.reply, (int)(fifo_task.osiz));
+ chip, fifo_task.reply, (int)(fifo_task.osiz));
}
res = FIFO_RES(fifo_task.rbuf, fifo_task.osiz - fifo_task.rsiz);
cmd = FIFO_CMD(fifo_task.rbuf, fifo_task.osiz - fifo_task.rsiz);
// valid reply?
- if (res <= MINION_QUE_MAX && cmd <= MINION_QUE_HIGH)
+ if (res <= MINION_QUE_MAX && cmd <= MINION_QUE_MAX)
break;
- applog(LOG_ERR, "%s%i: Bad fifo reply res %d (max is %d) cmd %d (max is %d)",
+ applog(LOG_ERR, "%s%i: Chip %d Bad fifo reply res %d (max is %d) cmd %d (max is %d)",
minioncgpu->drv->name, minioncgpu->device_id,
- (int)res, MINION_QUE_MAX, (int)cmd, MINION_QUE_HIGH);
+ chip, (int)res, MINION_QUE_MAX, (int)cmd, MINION_QUE_MAX);
minioninfo->spi_errors++;
minioninfo->fifo_spi_errors[chip]++;
minioninfo->res_err_count[chip]++;
@@ -2472,23 +2487,16 @@ static void *minion_spi_reply(void *userdata)
continue;
K_WLOCK(minioninfo->wwork_list);
- // it shouldn't go up
- if (cmd < minioninfo->chip_status[chip].realwork)
- minioninfo->chip_status[chip].realwork = (uint32_t)cmd;
- else {
- cmd = (uint8_t)(minioninfo->chip_status[chip].realwork);
- minioninfo->spi_errors++;
- minioninfo->fifo_spi_errors[chip]++;
- minioninfo->res_err_count[chip]++;
- }
- chipwork = (int)(minioninfo->chip_status[chip].chipwork);
+ // have to just assume it's always correct since we can't verify it
+ minioninfo->chip_status[chip].realwork = (uint32_t)cmd;
+#if MINION_SHOW_IO
+ applog(IOCTRL_LOG, "SetReal chip %d cw=%u rw==%u qw=%u",
+ chip,
+ minioninfo->chip_status[chip].chipwork,
+ minioninfo->chip_status[chip].realwork,
+ minioninfo->chip_status[chip].quework);
+#endif
K_WUNLOCK(minioninfo->wwork_list);
- gap = chipwork - (int)cmd;
- if (gap < -1 || gap > 1) {
-// applog(LOG_ERR, "%s%i: fifo cmd difference > 1 for chip %d - work %d cmd %d gap %d",
-// minioncgpu->drv->name, minioncgpu->device_id,
-// chip, chipwork, (int)cmd, gap);
- }
if (cmd < MINION_QUE_LOW) {
somelow = true;
@@ -2534,8 +2542,9 @@ repeek:
cgtime(&now);
if (res1_task.reply < (int)MINION_RES_DATA_SIZ) {
char *buf = bin2hex((unsigned char *)(&(res1_task.rbuf[res1_task.osiz - res1_task.rsiz])), (int)(res1_task.rsiz));
- applog(LOG_ERR, "%s%i: Bad work reply (%s) size %d, should be at least %d",
- minioncgpu->drv->name, minioncgpu->device_id, buf,
+ applog(LOG_ERR, "%s%i: Chip %d Bad work reply (%s) size %d, should be at least %d",
+ minioncgpu->drv->name, minioncgpu->device_id,
+ chip, buf,
res1_task.reply, (int)MINION_RES_DATA_SIZ);
free(buf);
minioninfo->spi_errors++;
@@ -2543,9 +2552,9 @@ repeek:
minioninfo->res_err_count[chip]++;
} else {
if (res1_task.reply != (int)(res1_task.osiz)) {
- applog(LOG_ERR, "%s%i: Unexpected work reply size %d, expected %d",
+ applog(LOG_ERR, "%s%i: Chip %d Unexpected work reply size %d, expected %d",
minioncgpu->drv->name, minioncgpu->device_id,
- res1_task.reply, (int)(res1_task.osiz));
+ chip, res1_task.reply, (int)(res1_task.osiz));
minioninfo->spi_errors++;
minioninfo->res_spi_errors[chip]++;
minioninfo->res_err_count[chip]++;
@@ -2771,8 +2780,13 @@ static void cleanup_older(struct cgpu_info *minioncgpu, int chip, K_ITEM *item,
k_unlink_item(minioninfo->wchip_list[chip], tail);
if (!(DATAW(tail)->stale)) {
minioninfo->chip_status[chip].chipwork--;
- if (minioninfo->chip_status[chip].realwork > 0)
- minioninfo->chip_status[chip].realwork--;
+#if MINION_SHOW_IO
+ applog(IOCTRL_LOG, "COld chip %d cw-1=%u rw=%u qw=%u",
+ chip,
+ minioninfo->chip_status[chip].chipwork,
+ minioninfo->chip_status[chip].realwork,
+ minioninfo->chip_status[chip].quework);
+#endif
/*
// If it had no valid work (only errors) then it won't have been cleaned up
errs = (DATAW(tail)->errors > 0);
@@ -2799,8 +2813,13 @@ static void cleanup_older(struct cgpu_info *minioncgpu, int chip, K_ITEM *item,
k_unlink_item(minioninfo->wchip_list[chip], item);
if (!(DATAW(item)->stale)) {
minioninfo->chip_status[chip].chipwork--;
- if (minioninfo->chip_status[chip].realwork > 0)
- minioninfo->chip_status[chip].realwork--;
+#if MINION_SHOW_IO
+ applog(IOCTRL_LOG, "CONoN chip %d cw-1=%u rw=%u qw=%u",
+ chip,
+ minioninfo->chip_status[chip].chipwork,
+ minioninfo->chip_status[chip].realwork,
+ minioninfo->chip_status[chip].quework);
+#endif
}
K_WUNLOCK(minioninfo->wchip_list[chip]);
applog(MINION_LOG, "%s%i: marking complete - no_nonce task 0x%04x chip %d",
@@ -3047,6 +3066,13 @@ static void minion_flush_work(struct cgpu_info *minioncgpu)
prev_task = task->prev;
if (DATAT(task)->address == WRITE_ADDR(MINION_QUE_0)) {
minioninfo->chip_status[DATAT(task)->chip].quework--;
+#if MINION_SHOW_IO
+ applog(IOCTRL_LOG, "QueFlush chip %d cw=%u rw=%u qw-1=%u",
+ (int)DATAT(task)->chip,
+ minioninfo->chip_status[DATAT(task)->chip].chipwork,
+ minioninfo->chip_status[DATAT(task)->chip].realwork,
+ minioninfo->chip_status[DATAT(task)->chip].quework);
+#endif
witem = DATAT(task)->witem;
k_unlink_item(minioninfo->wque_list[DATAT(task)->chip], witem);
k_free_head(minioninfo->wfree_list, witem);
@@ -3232,6 +3258,13 @@ static void new_work_task(struct cgpu_info *minioncgpu, K_ITEM *witem, int chip,
K_WLOCK(minioninfo->wque_list[chip]);
k_add_head(minioninfo->wque_list[chip], witem);
minioninfo->chip_status[chip].quework++;
+#if MINION_SHOW_IO
+ applog(IOCTRL_LOG, "Que chip %d cw=%u rw=%u qw+1=%u",
+ chip,
+ minioninfo->chip_status[chip].chipwork,
+ minioninfo->chip_status[chip].realwork,
+ minioninfo->chip_status[chip].quework);
+#endif
K_WUNLOCK(minioninfo->wque_list[chip]);
K_WLOCK(minioninfo->task_list);
@@ -3262,13 +3295,20 @@ static void minion_do_work(struct cgpu_info *minioncgpu)
{
struct minion_info *minioninfo = (struct minion_info *)(minioncgpu->device_data);
int count, chip, j, lowcount;
- uint8_t state;
+ TITEM fifo_task;
+ uint8_t state, cmd;
K_ITEM *item;
#if ENABLE_INT_NONO
K_ITEM *task;
#endif
bool islow, sentwork;
+ fifo_task.chip = 0;
+ fifo_task.write = false;
+ fifo_task.address = MINION_SYS_FIFO_STA;
+ fifo_task.wsiz = 0;
+ fifo_task.rsiz = MINION_SYS_SIZ;
+
// TODO: (remove this) Fake starved of work to test CMD Interrupt
// if (total_secs > 120) {
// cgsleep_ms(888);
@@ -3291,6 +3331,55 @@ static void minion_do_work(struct cgpu_info *minioncgpu)
for (chip = 0; chip < (int)MINION_CHIPS; chip++) {
if (minioninfo->has_chip[chip] && !minioninfo->chip_status[chip].overheat) {
+ int tries = 0;
+ while (tries++ < 4) {
+ cmd = 0;
+ fifo_task.chip = chip;
+ fifo_task.reply = 0;
+ minion_txrx(&fifo_task);
+ if (fifo_task.reply <= 0) {
+ if (fifo_task.reply < (int)(fifo_task.osiz)) {
+ char *buf = bin2hex((unsigned char *)(&(fifo_task.rbuf[fifo_task.osiz - fifo_task.rsiz])),
+ (int)(fifo_task.rsiz));
+ applog(LOG_ERR, "%s%i: Chip %d Bad fifo reply (%s) size %d, should be %d",
+ minioncgpu->drv->name, minioncgpu->device_id,
+ chip, buf,
+ fifo_task.reply, (int)(fifo_task.osiz));
+ free(buf);
+ minioninfo->spi_errors++;
+ minioninfo->fifo_spi_errors[chip]++;
+ minioninfo->res_err_count[chip]++;
+ } else {
+ if (fifo_task.reply > (int)(fifo_task.osiz)) {
+ applog(LOG_ERR, "%s%i: Chip %d Unexpected fifo reply size %d, expected only %d",
+ minioncgpu->drv->name, minioncgpu->device_id,
+ chip, fifo_task.reply, (int)(fifo_task.osiz));
+ }
+ cmd = FIFO_CMD(fifo_task.rbuf, fifo_task.osiz - fifo_task.rsiz);
+ // valid reply?
+ if (cmd < MINION_QUE_MAX) {
+ K_WLOCK(minioninfo->wchip_list[chip]);
+ minioninfo->chip_status[chip].realwork = cmd;
+ K_WUNLOCK(minioninfo->wchip_list[chip]);
+ if (cmd < 10 || cmd >= MINION_QUE_HIGH) {
+ applog(LOG_DEBUG, "%s%i: Chip %d fifo cmd %d",
+ minioncgpu->drv->name,
+ minioncgpu->device_id,
+ chip, (int)cmd);
+ }
+ break;
+ }
+
+ applog(LOG_ERR, "%s%i: Chip %d Bad fifo reply cmd %d (max is %d)",
+ minioncgpu->drv->name, minioncgpu->device_id,
+ chip, (int)cmd, MINION_QUE_MAX);
+ minioninfo->spi_errors++;
+ minioninfo->fifo_spi_errors[chip]++;
+ minioninfo->res_err_count[chip]++;
+ }
+ }
+ }
+
K_WLOCK(minioninfo->wchip_list[chip]);
count = minioninfo->chip_status[chip].quework +
minioninfo->chip_status[chip].realwork;