Browse Source

Use cgsem structures instead of the flaky pings in the work queue to start mining threads and remove the unused thr_info_freeze function.

nfactor-troky
ckolivas 11 years ago
parent
commit
9b2e517f30
  1. 33
      cgminer.c
  2. 1
      miner.h
  3. 24
      util.c
  4. 1
      util.h

33
cgminer.c

@ -292,8 +292,6 @@ static int include_count; @@ -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, @@ -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) @@ -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: @@ -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) @@ -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() @@ -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: @@ -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))

1
miner.h

@ -572,6 +572,7 @@ struct thr_info { @@ -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;

24
util.c

@ -785,28 +785,9 @@ out: @@ -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) @@ -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

1
util.h

@ -69,7 +69,6 @@ struct pool; @@ -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);

Loading…
Cancel
Save