Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toggle active #81

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Miner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
self.switch.status_updated(self)

def on_idle(self):
pass

def on_active(self):
pass
17 changes: 14 additions & 3 deletions OpenCLMiner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,))

Expand All @@ -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:
Expand All @@ -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
Expand Down
17 changes: 15 additions & 2 deletions poclbm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from util import if_else, tokenize
from version import VERSION
import log
import signal
import socket


Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
sleep(1.1)