Reinstate the mining thread watchdog restart. Add a getpoll bool into the thread information and don't restart threads stuck waiting on work. Rename the idlenet bool for the pool for later use.
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
diff --git a/main.c b/main.c
index 7e91836..be0129e 100644
--- a/main.c
+++ b/main.c
@@ -1096,17 +1096,10 @@ static void inc_staged(struct pool *pool, int inc, bool lp)
if (lp) {
lp_staged += inc;
total_staged += inc;
- pool->idlenet = true;
+ pool->idle = true;
} else if (lp_staged) {
- if (!--lp_staged) {
- unsigned int i;
-
- /* Make sure the watchdog thread doesn't kill the mining
- * threads once we unset the idlenet flag */
- for (i = 0; i < mining_threads; i++)
- gettimeofday(&thr_info[i].last, NULL);
- pool->idlenet = false;
- }
+ if (!--lp_staged)
+ pool->idle = false;
} else
total_staged += inc;
pthread_mutex_unlock(&stgd_lock);
@@ -1248,6 +1241,17 @@ static void *workio_thread(void *userdata)
return NULL;
}
+static void thread_reportin(struct thr_info *thr)
+{
+ gettimeofday(&thr->last, NULL);
+ thr->getwork = false;
+}
+
+static inline void thread_reportout(struct thr_info *thr)
+{
+ thr->getwork = true;
+}
+
static void hashmeter(int thr_id, struct timeval *diff,
unsigned long hashes_done)
{
@@ -1428,7 +1432,8 @@ static void flush_requests(bool longpoll)
}
}
-static bool get_work(struct work *work, bool queued)
+static bool get_work(struct work *work, bool queued, struct thr_info *thr,
+ const int thr_id)
{
struct timespec abstime = {};
struct timeval now;
@@ -1437,6 +1442,9 @@ static bool get_work(struct work *work, bool queued)
bool ret = false;
int failures = 0;
+ /* Tell the watchdog thread this thread is waiting on getwork and
+ * should not be restarted */
+ thread_reportout(thr);
retry:
pool = current_pool();
if (unlikely(!queued && !queue_request())) {
@@ -1524,6 +1532,9 @@ out:
sleep(opt_fail_pause);
goto retry;
}
+
+ work->thr_id = thr_id;
+ thread_reportin(thr);
return ret;
}
@@ -1605,13 +1616,12 @@ static void *miner_thread(void *userdata)
if (needs_work) {
gettimeofday(&tv_workstart, NULL);
/* obtain new work from internal workio thread */
- if (unlikely(!get_work(&work, requested))) {
+ if (unlikely(!get_work(&work, requested, mythr, thr_id))) {
applog(LOG_ERR, "work retrieval failed, exiting "
"mining thread %d", thr_id);
goto out;
}
mythr->cgpu->getworks++;
- work.thr_id = thr_id;
needs_work = requested = false;
work.blk.nonce = 0;
max_nonce = hashes_done;
@@ -1865,13 +1875,12 @@ static void *gpuminer_thread(void *userdata)
{ applog(LOG_ERR, "Error: clEnqueueWriteBuffer failed."); goto out; }
gettimeofday(&tv_workstart, NULL);
/* obtain new work from internal workio thread */
- if (unlikely(!get_work(work, requested))) {
+ if (unlikely(!get_work(work, requested, mythr, thr_id))) {
applog(LOG_ERR, "work retrieval failed, exiting "
- "gpu mining thread %d", mythr->id);
+ "gpu mining thread %d", thr_id);
goto out;
}
mythr->cgpu->getworks++;
- work->thr_id = thr_id;
requested = false;
precalc_hash(&work->blk, (uint32_t *)(work->midstate), (uint32_t *)(work->data + 64));
work->blk.nonce = 0;
@@ -1916,13 +1925,12 @@ static void *gpuminer_thread(void *userdata)
gettimeofday(&tv_workstart, NULL);
/* obtain new work from internal workio thread */
- if (unlikely(!get_work(work, requested))) {
+ if (unlikely(!get_work(work, requested, mythr, thr_id))) {
applog(LOG_ERR, "work retrieval failed, exiting "
- "gpu mining thread %d", mythr->id);
+ "gpu mining thread %d", thr_id);
goto out;
}
mythr->cgpu->getworks++;
- work->thr_id = thr_id;
requested = false;
precalc_hash(&work->blk, (uint32_t *)(work->midstate), (uint32_t *)(work->data + 64));
@@ -2130,7 +2138,6 @@ out:
return NULL;
}
-#if 0
static void reinit_cputhread(int thr_id)
{
struct thr_info *thr = &thr_info[thr_id];
@@ -2144,7 +2151,7 @@ static void reinit_cputhread(int thr_id)
applog(LOG_INFO, "Reinit CPU thread %d", thr_id);
tq_thaw(thr->q);
- gettimeofday(&thr->last, NULL);
+ thread_reportin(thr);
if (unlikely(pthread_create(&thr->pth, NULL, miner_thread, thr))) {
applog(LOG_ERR, "thread %d create failed", thr_id);
@@ -2179,7 +2186,7 @@ static void reinit_gputhread(int thr_id)
}
applog(LOG_INFO, "initCl() finished. Found %s", name);
- gettimeofday(&thr->last, NULL);
+ thread_reportin(thr);
if (unlikely(pthread_create(&thr->pth, NULL, gpuminer_thread, thr))) {
applog(LOG_ERR, "thread %d create failed", thr_id);
@@ -2204,7 +2211,6 @@ static void reinit_thread(int thr_id)
reinit_cputhread(thr_id);
}
#endif
-#endif /* 0 */
/* Determine which are the first threads belonging to a device and if they're
* active */
@@ -2265,17 +2271,18 @@ static void *watchdog_thread(void *userdata)
}
gettimeofday(&now, NULL);
-#if 0
//for (i = 0; i < mining_threads; i++) {
for (i = 0; i < gpu_threads; i++) {
struct thr_info *thr = &thr_info[i];
- /* Do not kill threads waiting on longpoll staged work
- * or idle network */
- if (now.tv_sec - thr->last.tv_sec > 60 && !pool->idlenet) {
+ /* Thread is waiting on getwork, don't test it */
+ if (thr->getwork)
+ continue;
+
+ if (now.tv_sec - thr->last.tv_sec > 60) {
applog(LOG_ERR, "Attempting to restart thread %d, idle for more than 60 seconds", i);
/* Create one mandatory work item */
- inc_staged(1, true);
+ inc_staged(current_pool(), 1, true);
if (unlikely(!queue_request())) {
applog(LOG_ERR, "Failed to queue_request in watchdog_thread");
kill_work();
@@ -2285,7 +2292,6 @@ static void *watchdog_thread(void *userdata)
applog(LOG_WARNING, "Thread %d restarted", i);
}
}
-#endif
}
return NULL;
@@ -2645,7 +2651,7 @@ int main (int argc, char *argv[])
}
applog(LOG_INFO, "initCl() finished. Found %s", name);
- gettimeofday(&thr->last, NULL);
+ thread_reportin(thr);
if (unlikely(pthread_create(&thr->pth, NULL, gpuminer_thread, thr))) {
applog(LOG_ERR, "thread %d create failed", i);
@@ -2673,7 +2679,7 @@ int main (int argc, char *argv[])
return 1;
}
- gettimeofday(&thr->last, NULL);
+ thread_reportin(thr);
if (unlikely(pthread_create(&thr->pth, NULL, miner_thread, thr))) {
applog(LOG_ERR, "thread %d create failed", i);
diff --git a/miner.h b/miner.h
index 63ab517..238b8b5 100644
--- a/miner.h
+++ b/miner.h
@@ -149,6 +149,7 @@ struct thr_info {
struct thread_q *q;
struct cgpu_info *cgpu;
struct timeval last;
+ bool getwork;
};
static inline uint32_t swab32(uint32_t v)
@@ -268,7 +269,7 @@ struct pool {
int accepted, rejected;
bool submit_fail;
bool localgen;
- bool idlenet;
+ bool idle;
bool has_rolltime;
bool probed;
unsigned int getwork_requested;