forked from M-Labs/artiq
1
0
Fork 0

language/core: integrate watchdogs

This commit is contained in:
Sebastien Bourdeauducq 2015-04-28 23:23:59 +08:00
parent 37ac6c4542
commit 283695e8aa
3 changed files with 34 additions and 14 deletions

View File

@ -1,6 +1,5 @@
""" """
Core ARTIQ extensions to the Python language. Core ARTIQ extensions to the Python language.
""" """
from collections import namedtuple as _namedtuple from collections import namedtuple as _namedtuple
@ -170,14 +169,12 @@ def set_syscall_manager(syscall_manager):
kernel_globals = ("sequential", "parallel", kernel_globals = ("sequential", "parallel",
"delay", "now", "at", "time_to_cycles", "cycles_to_time", "delay", "now", "at", "time_to_cycles", "cycles_to_time",
"syscall") "syscall", "watchdog")
class _Sequential: class _Sequential:
"""In a sequential block, statements are executed one after another, with """In a sequential block, statements are executed one after another, with
the time increasing as one moves down the statement list. the time increasing as one moves down the statement list."""
"""
def __enter__(self): def __enter__(self):
_time_manager.enter_sequential() _time_manager.enter_sequential()
@ -243,7 +240,6 @@ def cycles_to_time(cycles, core=None):
:param time: Cycle count to convert. :param time: Cycle count to convert.
:param core: Core device for which to perform the conversion. Specify only :param core: Core device for which to perform the conversion. Specify only
when running in the interpreter (not in kernel). when running in the interpreter (not in kernel).
""" """
if core is None: if core is None:
raise ValueError("Core device must be specified for time conversion") raise ValueError("Core device must be specified for time conversion")
@ -257,19 +253,40 @@ def syscall(*args):
events, make RPCs, etc. events, make RPCs, etc.
Only drivers should normally use ``syscall``. Only drivers should normally use ``syscall``.
""" """
return _syscall_manager.do(*args) return _syscall_manager.do(*args)
class _DummyWatchdog:
def __init__(self, timeout):
pass
def __enter__(self):
pass
def __exit__(self, type, value, traceback):
pass
# Watchdogs are simply not enforced by default.
_watchdog_factory = _DummyWatchdog
def set_watchdog_factory(f):
global _watchdog_factory
_watchdog_factory = f
def watchdog(timeout):
return _watchdog_factory(timeout)
_encoded_exceptions = dict() _encoded_exceptions = dict()
def EncodedException(eid): def EncodedException(eid):
"""Represents exceptions on the core device, which are identified """Represents exceptions on the core device, which are identified
by a single number. by a single number."""
"""
try: try:
return _encoded_exceptions[eid] return _encoded_exceptions[eid]
except KeyError: except KeyError:

View File

@ -6,6 +6,7 @@ from artiq.tools import file_import
from artiq.master.worker_db import DBHub, ResultDB from artiq.master.worker_db import DBHub, ResultDB
from artiq.master.results import get_hdf5_output from artiq.master.results import get_hdf5_output
from artiq.language.experiment import is_experiment from artiq.language.experiment import is_experiment
from artiq.language.core import set_watchdog_factory
def get_object(): def get_object():
@ -66,13 +67,15 @@ class Watchdog:
Watchdog._delete(self.wid) Watchdog._delete(self.wid)
set_watchdog_factory(Watchdog)
class Scheduler: class Scheduler:
run_queued = make_parent_action("scheduler_run_queued", "run_params") run_queued = make_parent_action("scheduler_run_queued", "run_params")
cancel_queued = make_parent_action("scheduler_cancel_queued", "rid") cancel_queued = make_parent_action("scheduler_cancel_queued", "rid")
run_timed = make_parent_action("scheduler_run_timed", run_timed = make_parent_action("scheduler_run_timed",
"run_params next_run") "run_params next_run")
cancel_timed = make_parent_action("scheduler_cancel_timed", "trid") cancel_timed = make_parent_action("scheduler_cancel_timed", "trid")
watchdog = Watchdog
def get_exp(file, exp): def get_exp(file, exp):

View File

@ -10,19 +10,19 @@ from artiq.master.worker import *
class WatchdogNoTimeout(Experiment, AutoDB): class WatchdogNoTimeout(Experiment, AutoDB):
def run(self): def run(self):
for i in range(10): for i in range(10):
with self.scheduler.watchdog(0.5*s): with watchdog(0.5*s):
sleep(0.1) sleep(0.1)
class WatchdogTimeout(Experiment, AutoDB): class WatchdogTimeout(Experiment, AutoDB):
def run(self): def run(self):
with self.scheduler.watchdog(0.1*s): with watchdog(0.1*s):
sleep(100.0) sleep(100.0)
class WatchdogTimeoutInBuild(Experiment, AutoDB): class WatchdogTimeoutInBuild(Experiment, AutoDB):
def build(self): def build(self):
with self.scheduler.watchdog(0.1*s): with watchdog(0.1*s):
sleep(100.0) sleep(100.0)
def run(self): def run(self):