Browse Source

Merge commit 'd93e8ec' into bfgminer

Luke Dashjr 12 years ago
parent
commit
65ba8cf703
4 changed files with 19 additions and 2 deletions
  1. 1 0
      README
  2. 5 0
      deviceapi.c
  3. 12 2
      miner.c
  4. 1 0
      miner.h

+ 1 - 0
README

@@ -173,6 +173,7 @@ Options for both config file and command line:
 --api-port          Port number of miner API (default: 4028)
 --balance           Change multipool strategy from failover to even share balance
 --benchmark         Run BFGMiner in benchmark mode - produces no shares
+--cmd-idle <arg>    Execute a command when a device is allowed to be idle (rest or wait)
 --cmd-sick <arg>    Execute a command when a device is declared sick
 --cmd-dead <arg>    Execute a command when a device is declared dead
 --coinbase-addr <arg> Set coinbase payout address for solo mining

+ 5 - 0
deviceapi.c

@@ -48,6 +48,7 @@ bool hashes_done(struct thr_info *thr, int64_t hashes, struct timeval *tvp_hashe
 		} else {
 			applog(LOG_ERR, "%"PRIpreprv" failure, disabling!", cgpu->proc_repr);
 			cgpu->deven = DEV_RECOVER_ERR;
+			run_cmd(cmd_idle);
 			return false;
 		}
 	}
@@ -136,6 +137,7 @@ struct work *get_and_prepare_work(struct thr_info *thr)
 		free_work(work);
 		applog(LOG_ERR, "%"PRIpreprv": Work prepare failed, disabling!", proc->proc_repr);
 		proc->deven = DEV_RECOVER_ERR;
+		run_cmd(cmd_idle);
 		return NULL;
 	}
 	return work;
@@ -324,7 +326,10 @@ void job_start_abort(struct thr_info *mythr, bool failure)
 	struct cgpu_info *proc = mythr->cgpu;
 	
 	if (failure)
+	{
 		proc->deven = DEV_RECOVER_ERR;
+		run_cmd(cmd_idle);
+	}
 	mythr->work = NULL;
 	mythr->_job_transition_in_progress = false;
 }

+ 12 - 2
miner.c

@@ -363,7 +363,7 @@ static int include_count;
 #define JSON_MAX_DEPTH 10
 #define JSON_MAX_DEPTH_ERR "Too many levels of JSON includes (limit 10) or a loop"
 
-char *cmd_sick, *cmd_dead;
+char *cmd_idle, *cmd_sick, *cmd_dead;
 
 #if defined(unix) || defined(__APPLE__)
 	static char *opt_stderr_cmd = NULL;
@@ -1389,6 +1389,9 @@ static struct opt_table opt_config_table[] = {
 		     set_int_0_to_9999, opt_show_intval, &opt_bench_algo,
 		     opt_hidden),
 #endif
+	OPT_WITH_ARG("--cmd-idle",
+	             opt_set_charp, NULL, &cmd_idle,
+	             "Execute a command when a device is allowed to be idle (rest or wait)"),
 	OPT_WITH_ARG("--cmd-sick",
 	             opt_set_charp, NULL, &cmd_sick,
 	             "Execute a command when a device is declared sick"),
@@ -7500,6 +7503,7 @@ static struct work *hash_pop(void)
 {
 	struct work *work = NULL, *tmp;
 	int hc;
+	struct timespec ts;
 
 retry:
 	mutex_lock(stgd_lock);
@@ -7516,7 +7520,12 @@ retry:
 				applog(LOG_WARNING, "Staged work underrun; not automatically increasing above %d", opt_queue);
 			staged_full = false;  // Let it fill up before triggering an underrun again
 		}
-		pthread_cond_wait(&getq->cond, stgd_lock);
+		ts = (struct timespec){ .tv_sec = opt_log_interval, };
+		if (ETIMEDOUT == pthread_cond_timedwait(&getq->cond, stgd_lock, &ts))
+		{
+			run_cmd(cmd_idle);
+			pthread_cond_wait(&getq->cond, stgd_lock);
+		}
 	}
 
 	hc = HASH_COUNT(staged_work);
@@ -8709,6 +8718,7 @@ static void *watchdog_thread(void __maybe_unused *userdata)
 				*denable = DEV_RECOVER;
 
 				dev_error(cgpu, REASON_DEV_THERMAL_CUTOFF);
+				run_cmd(cmd_idle);
 			}
 
 			if (thr->getwork) {

+ 1 - 0
miner.h

@@ -854,6 +854,7 @@ extern bool have_longpoll;
 extern int opt_skip_checks;
 extern char *opt_kernel_path;
 extern char *opt_socks_proxy;
+extern char *cmd_idle, *cmd_sick, *cmd_dead;
 extern char *cgminer_path;
 extern bool opt_fail_only;
 extern bool opt_autofan;