From 9b2e517f30745a8064afc5026ef2935fc7a76cf2 Mon Sep 17 00:00:00 2001 From: ckolivas Date: Sun, 9 Jun 2013 12:20:04 +1000 Subject: [PATCH] Use cgsem structures instead of the flaky pings in the work queue to start mining threads and remove the unused thr_info_freeze function. --- cgminer.c | 33 ++++++++++----------------------- miner.h | 1 + util.c | 24 +++--------------------- util.h | 1 - 4 files changed, 14 insertions(+), 45 deletions(-) diff --git a/cgminer.c b/cgminer.c index 5f02d4e6..4997b2bd 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 752de5ee..9708e098 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 4d48dab2..8f8718ed 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 8f82b87b..c95f7f46 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);