1
0
mirror of https://github.com/GOSTSec/sgminer synced 2025-01-09 06:18:06 +00:00

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

This commit is contained in:
ckolivas 2013-06-09 12:20:04 +10:00
parent 29b2d68832
commit 9b2e517f30
4 changed files with 14 additions and 45 deletions

View File

@ -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))

View File

@ -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
View File

@ -785,30 +785,11 @@ out:
int thr_info_create(struct thr_info *thr, pthread_attr_t *attr, void *(*start) (void *), void *arg)
{
cgsem_init(&thr->sem);
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;
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);
}
void thr_info_cancel(struct thr_info *thr)
{
if (!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
View File

@ -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);