diff --git a/Miner.py b/Miner.py index ccb92ea..db0157b 100644 --- a/Miner.py +++ b/Miner.py @@ -18,6 +18,8 @@ def __init__(self, device_index, options): self.accept_hist = [] self.rate = self.estimated_rate = 0 + self.idle = True + def start(self): self.should_stop = False Thread(target=self.mining_thread).start() @@ -41,4 +43,10 @@ def update_rate(self, now, iterations, t, targetQ, rate_divisor=1000): self.estimated_rate = Decimal(new_accept) * (targetQ) / min(int(now - self.start_time), self.options.estimate) / 1000 self.estimated_rate = Decimal(self.estimated_rate) / 1000 - self.switch.status_updated(self) \ No newline at end of file + self.switch.status_updated(self) + + def on_idle(self): + pass + + def on_active(self): + pass \ No newline at end of file diff --git a/OpenCLMiner.py b/OpenCLMiner.py index f1a1725..b158a2e 100644 --- a/OpenCLMiner.py +++ b/OpenCLMiner.py @@ -135,6 +135,14 @@ def __init__(self, device_index, options): if self.adapterIndex: self.adapterIndex = self.adapterIndex[self.device_index].iAdapterIndex + def on_idle(self): + self.idle = True + say_line('%s is now idle', (self.id())) + + def on_active(self): + self.idle = False + say_line('%s is now active', (self.id())) + def id(self): return str(self.options.platform) + ':' + str(self.device_index) + ':' + self.device_name @@ -204,7 +212,7 @@ def mining_thread(self): self.kernel.set_arg(18, f[3]) self.kernel.set_arg(19, f[4]) - if temperature < self.cutoff_temp: + if temperature < self.cutoff_temp and not self.idle: self.kernel.set_arg(14, pack('I', base)) cl.enqueue_nd_range_kernel(queue, self.kernel, (global_threads,), (self.worksize,)) @@ -215,7 +223,10 @@ def mining_thread(self): else: threads_run_pace = 0 last_rated_pace = time() - sleep(self.cutoff_interval) + if self.idle: + sleep(1) + else: + sleep(self.cutoff_interval) now = time() if self.adapterIndex != None: @@ -226,7 +237,7 @@ def mining_thread(self): temperature = self.get_temperature() t = now - last_rated_pace - if t > 1: + if t > 1 and threads_run_pace != 0: rate = (threads_run_pace / t) / rate_divisor last_rated_pace = now; threads_run_pace = 0 r = last_hash_rate / rate diff --git a/poclbm.py b/poclbm.py index cc87f78..f022913 100755 --- a/poclbm.py +++ b/poclbm.py @@ -6,6 +6,7 @@ from util import if_else, tokenize from version import VERSION import log +import signal import socket @@ -68,10 +69,22 @@ def socketwrap(family=socket.AF_INET, type=socket.SOCK_STREAM, proto=0): options.device = tokenize(options.device, 'device', []) +switch = None + +def signal_handler(signum, frame): + if switch: + for miner in switch.miners: + if signum == signal.SIGUSR1: + miner.on_idle() + elif signum == signal.SIGUSR2: + miner.on_active() + +signal.signal(signal.SIGUSR1, signal_handler) +signal.signal(signal.SIGUSR2, signal_handler) + options.cutoff_temp = tokenize(options.cutoff_temp, 'cutoff_temp', [95], float) options.cutoff_interval = tokenize(options.cutoff_interval, 'cutoff_interval', [0.01], float) -switch = None try: switch = Switch(options) @@ -102,4 +115,4 @@ def socketwrap(family=socket.AF_INET, type=socket.SOCK_STREAM, proto=0): if not options.no_ocl: OpenCLMiner.shutdown() -sleep(1.1) \ No newline at end of file +sleep(1.1)