Use cgsem structures instead of the flaky pings in the work queue to start mining threads and remove the unused thr_info_freeze function.
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
diff --git a/cgminer.c b/cgminer.c
index 5f02d4e..4997b2b 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -292,8 +292,6 @@ static int include_count;
static int forkpid;
#endif // defined(unix)
-bool ping = true;
-
struct sigaction termhandler, inthandler;
struct thread_q *getq;
@@ -5707,11 +5705,9 @@ static void mt_disable(struct thr_info *mythr, const int thr_id,
{
applog(LOG_WARNING, "Thread %d being disabled", thr_id);
mythr->rolling = mythr->cgpu->rolling = 0;
- applog(LOG_DEBUG, "Popping wakeup ping in miner thread");
+ applog(LOG_DEBUG, "Waiting on sem in miner thread");
thread_reportout(mythr);
- do {
- tq_pop(mythr->q, NULL); /* Ignore ping that's popped */
- } while (mythr->pause);
+ cgsem_wait(&mythr->sem);
thread_reportin(mythr);
applog(LOG_WARNING, "Thread %d being re-enabled", thr_id);
drv->thread_enable(mythr);
@@ -6072,8 +6068,8 @@ void *miner_thread(void *userdata)
}
thread_reportout(mythr);
- applog(LOG_DEBUG, "Popping ping in miner thread");
- tq_pop(mythr->q, NULL); /* Wait for a ping to start */
+ applog(LOG_DEBUG, "Waiting on sem in miner thread");
+ cgsem_wait(&mythr->sem);
drv->hash_work(mythr);
out:
@@ -6081,7 +6077,6 @@ out:
thread_reportin(mythr);
applog(LOG_ERR, "Thread %d failure, exiting", thr_id);
- tq_freeze(mythr->q);
return NULL;
}
@@ -6499,7 +6494,8 @@ static void *watchdog_thread(void __maybe_unused *userdata)
if (thr->cgpu->deven == DEV_DISABLED)
continue;
thr->pause = false;
- tq_push(thr->q, &ping);
+ applog(LOG_DEBUG, "Pushing sem post to thread %d", thr->id);
+ cgsem_post(&thr->sem);
}
}
@@ -7181,15 +7177,11 @@ static void hotplug_process()
thr->cgpu = cgpu;
thr->device_thread = j;
- thr->q = tq_new();
- if (!thr->q)
- quit(1, "tq_new hotplug failed in starting %s%d mining thread (#%d)", cgpu->drv->name, cgpu->device_id, total_devices);
-
/* Enable threads for devices set not to mine but disable
* their queue in case we wish to enable them later */
if (cgpu->deven != DEV_DISABLED) {
- applog(LOG_DEBUG, "Pushing hotplug ping to thread %d", thr->id);
- tq_push(thr->q, &ping);
+ applog(LOG_DEBUG, "Pushing sem post to thread %d", thr->id);
+ cgsem_post(&thr->sem);
}
if (cgpu->drv->thread_prepare && !cgpu->drv->thread_prepare(thr))
@@ -7676,16 +7668,11 @@ begin_bench:
thr->cgpu = cgpu;
thr->device_thread = j;
- thr->q = tq_new();
- if (!thr->q)
- quit(1, "tq_new failed in starting %s%d mining thread (#%d)", cgpu->drv->name, cgpu->device_id, i);
-
/* Enable threads for devices set not to mine but disable
* their queue in case we wish to enable them later */
if (cgpu->deven != DEV_DISABLED) {
- applog(LOG_DEBUG, "Pushing ping to thread %d", thr->id);
-
- tq_push(thr->q, &ping);
+ applog(LOG_DEBUG, "Pushing sem post to thread %d", thr->id);
+ cgsem_post(&thr->sem);
}
if (!cgpu->drv->thread_prepare(thr))
diff --git a/miner.h b/miner.h
index 752de5e..9708e09 100644
--- a/miner.h
+++ b/miner.h
@@ -572,6 +572,7 @@ struct thr_info {
bool primary_thread;
pthread_t pth;
+ cgsem_t sem;
struct thread_q *q;
struct cgpu_info *cgpu;
void *cgpu_data;
diff --git a/util.c b/util.c
index 4d48dab..8f8718e 100644
--- a/util.c
+++ b/util.c
@@ -785,28 +785,9 @@ out:
int thr_info_create(struct thr_info *thr, pthread_attr_t *attr, void *(*start) (void *), void *arg)
{
- return pthread_create(&thr->pth, attr, start, arg);
-}
-
-void thr_info_freeze(struct thr_info *thr)
-{
- struct tq_ent *ent, *iter;
- struct thread_q *tq;
+ cgsem_init(&thr->sem);
- if (!thr)
- return;
-
- tq = thr->q;
- if (!tq)
- return;
-
- mutex_lock(&tq->mutex);
- tq->frozen = true;
- list_for_each_entry_safe(ent, iter, &tq->q, q_node) {
- list_del(&ent->q_node);
- free(ent);
- }
- mutex_unlock(&tq->mutex);
+ return pthread_create(&thr->pth, attr, start, arg);
}
void thr_info_cancel(struct thr_info *thr)
@@ -818,6 +799,7 @@ void thr_info_cancel(struct thr_info *thr)
pthread_cancel(thr->pth);
PTH(thr) = 0L;
}
+ cgsem_destroy(&thr->sem);
}
/* Provide a ms based sleep that uses nanosleep to avoid poor usleep accuracy
diff --git a/util.h b/util.h
index 8f82b87..c95f7f4 100644
--- a/util.h
+++ b/util.h
@@ -69,7 +69,6 @@ struct pool;
enum dev_reason;
struct cgpu_info;
int thr_info_create(struct thr_info *thr, pthread_attr_t *attr, void *(*start) (void *), void *arg);
-void thr_info_freeze(struct thr_info *thr);
void thr_info_cancel(struct thr_info *thr);
void nmsleep(unsigned int msecs);
void nusleep(unsigned int usecs);