Browse Source

some improvements for the zero-hashrate fix, and more debug output

djm34
Jan Berdajs 11 years ago
parent
commit
a0e95b3687
  1. 38
      sgminer.c

38
sgminer.c

@ -3413,6 +3413,7 @@ static void kill_mining(void) @@ -3413,6 +3413,7 @@ static void kill_mining(void)
if (thr && PTH(thr) != 0L)
pth = &thr->pth;
thr_info_cancel(thr);
forcelog(LOG_DEBUG, "Waiting for thread %d to finish...", thr->id);
#ifndef WIN32
if (pth && *pth)
pthread_join(*pth, NULL);
@ -6284,6 +6285,11 @@ static unsigned long compare_pool_settings(struct pool *pool1, struct pool *pool @@ -6284,6 +6285,11 @@ static unsigned long compare_pool_settings(struct pool *pool1, struct pool *pool
return options;
}
static void mutex_unlock_cleanup_handler(void *mutex)
{
mutex_unlock((pthread_mutex_t *) mutex);
}
static void get_work_prepare_thread(struct thr_info *mythr, struct work *work)
{
int i;
@ -6525,12 +6531,6 @@ static void get_work_prepare_thread(struct thr_info *mythr, struct work *work) @@ -6525,12 +6531,6 @@ static void get_work_prepare_thread(struct thr_info *mythr, struct work *work)
rd_unlock(&mining_thr_lock);
mutex_unlock(&algo_switch_lock);
//reset switch thread counter
mutex_lock(&algo_switch_wait_lock);
algo_switch_n = 0;
mutex_unlock(&algo_switch_wait_lock);
// Signal other threads to start working now
// Hard restart if needed
if(opt_isset(pool_switch_options, SWITCHER_HARD_RESET))
{
@ -6565,6 +6565,7 @@ static void get_work_prepare_thread(struct thr_info *mythr, struct work *work) @@ -6565,6 +6565,7 @@ static void get_work_prepare_thread(struct thr_info *mythr, struct work *work)
if (unlikely(pthread_create(&restart_thr, NULL, restart_mining_threads_thread, (void *) (intptr_t) n_threads)))
quit(1, "restart_mining_threads create thread failed");
sleep(60);
#ifdef __TEMP_ALGO_SWITCH_FIX__
@ -6573,6 +6574,11 @@ static void get_work_prepare_thread(struct thr_info *mythr, struct work *work) @@ -6573,6 +6574,11 @@ static void get_work_prepare_thread(struct thr_info *mythr, struct work *work)
{
applog(LOG_DEBUG, "thread %d not found in fix list, don't exit sgminer", restart_thr);
pthread_cancel(restart_thr);
mutex_lock(&algo_switch_wait_lock);
algo_switch_n = 0;
pthread_cond_broadcast(&algo_switch_wait_cond);
mutex_unlock(&algo_switch_wait_lock);
return;
}
#endif /* __TEMP_ALGO_SWITCH_FIX__ */
@ -6581,8 +6587,9 @@ static void get_work_prepare_thread(struct thr_info *mythr, struct work *work) @@ -6581,8 +6587,9 @@ static void get_work_prepare_thread(struct thr_info *mythr, struct work *work)
}
else
{
//signal threads to resume work
// Signal other threads to start working now
mutex_lock(&algo_switch_wait_lock);
algo_switch_n = 0;
pthread_cond_broadcast(&algo_switch_wait_cond);
mutex_unlock(&algo_switch_wait_lock);
@ -6596,10 +6603,11 @@ static void get_work_prepare_thread(struct thr_info *mythr, struct work *work) @@ -6596,10 +6603,11 @@ static void get_work_prepare_thread(struct thr_info *mythr, struct work *work)
// Wait for signal to start working again
mutex_lock(&algo_switch_wait_lock);
//set cleanup instructions in the event that the thread is cancelled
pthread_cleanup_push((_Voidfp) pthread_mutex_unlock, (void *)&algo_switch_wait_lock);
// Set cleanup instructions in the event that the thread is cancelled
pthread_cleanup_push(mutex_unlock_cleanup_handler, (void *)&algo_switch_wait_lock);
while(algo_switch_n > 0)
pthread_cond_wait(&algo_switch_wait_cond, &algo_switch_wait_lock);
// Non-zero argument will execute the cleanup handler after popping it
pthread_cleanup_pop(1);
}
}
@ -8083,6 +8091,14 @@ static void restart_mining_threads(unsigned int new_n_threads) @@ -8083,6 +8091,14 @@ static void restart_mining_threads(unsigned int new_n_threads)
// kill_mining will rd lock mining_thr_lock
kill_mining();
applog(LOG_DEBUG, "Finish switching pools");
// Finish switching pools
mutex_lock(&algo_switch_wait_lock);
algo_switch_n = 0;
mutex_unlock(&algo_switch_wait_lock);
applog(LOG_DEBUG, "Shutdown OpenCL contexts...");
rd_lock(&mining_thr_lock);
for (i = 0; i < mining_threads; i++)
{
@ -8097,6 +8113,7 @@ static void restart_mining_threads(unsigned int new_n_threads) @@ -8097,6 +8113,7 @@ static void restart_mining_threads(unsigned int new_n_threads)
if (mining_thr)
{
applog(LOG_DEBUG, "Free old mining and device thread memory...");
rd_lock(&devices_lock);
for (i = 0; i < total_devices; i++) {
if (devices[i]->thr) free(devices[i]->thr);
@ -8111,6 +8128,7 @@ static void restart_mining_threads(unsigned int new_n_threads) @@ -8111,6 +8128,7 @@ static void restart_mining_threads(unsigned int new_n_threads)
}
// Alloc
applog(LOG_DEBUG, "Allocate new threads...");
mining_threads = (int) new_n_threads;
#ifdef HAVE_CURSES
adj_width(mining_threads, &dev_width);
@ -8147,6 +8165,7 @@ static void restart_mining_threads(unsigned int new_n_threads) @@ -8147,6 +8165,7 @@ static void restart_mining_threads(unsigned int new_n_threads)
continue;
}
applog(LOG_DEBUG, "Assign threads for device %d", i);
for (j = 0; j < cgpu->threads; ++j, ++k)
{
thr = mining_thr[k];
@ -8175,6 +8194,7 @@ static void restart_mining_threads(unsigned int new_n_threads) @@ -8175,6 +8194,7 @@ static void restart_mining_threads(unsigned int new_n_threads)
for (j = 0; j < cgpu->threads; ++j) {
thr = cgpu->thr[j];
applog(LOG_DEBUG, "Starting device %d mining thread %d...", i, j);
if (unlikely(thr_info_create(thr, NULL, miner_thread, thr)))
quit(1, "thread %d create failed", thr->id);

Loading…
Cancel
Save