forked from M-Labs/artiq
1
0
Fork 0

host: support runtime device exceptions

This commit is contained in:
Sebastien Bourdeauducq 2014-09-25 12:57:26 +08:00
parent f4d6bfc094
commit 4f26b6281d
4 changed files with 27 additions and 6 deletions

View File

@ -6,7 +6,9 @@ from enum import Enum
import logging import logging
from artiq.language import units from artiq.language import units
from artiq.language import core as core_language
from artiq.devices.runtime import Environment from artiq.devices.runtime import Environment
from artiq.devices import runtime_exceptions
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -142,7 +144,7 @@ class CoreCom:
_write_exactly(self.port, struct.pack("B", ord(c))) _write_exactly(self.port, struct.pack("B", ord(c)))
logger.debug("running kernel: {}".format(kname)) logger.debug("running kernel: {}".format(kname))
def serve(self, rpc_map, exception_map): def serve(self, rpc_map, user_exception_map):
while True: while True:
msg = self._get_device_msg() msg = self._get_device_msg()
if msg == _D2HMsgType.RPC_REQUEST: if msg == _D2HMsgType.RPC_REQUEST:
@ -160,9 +162,12 @@ class CoreCom:
logger.debug("rpc service: {} ({}) == {}".format( logger.debug("rpc service: {} ({}) == {}".format(
rpc_num, args, r)) rpc_num, args, r))
elif msg == _D2HMsgType.KERNEL_EXCEPTION: elif msg == _D2HMsgType.KERNEL_EXCEPTION:
(exception_num, ) = struct.unpack(">l", (eid, ) = struct.unpack(">l", _read_exactly(self.port, 4))
_read_exactly(self.port, 4)) if eid < core_language.first_user_eid:
raise exception_map[exception_num] exception = runtime_exceptions.exception_map[eid]
else:
exception = user_exception_map[eid]
raise exception
elif msg == _D2HMsgType.KERNEL_FINISHED: elif msg == _D2HMsgType.KERNEL_FINISHED:
return return
else: else:

View File

@ -0,0 +1,15 @@
class RuntimeException(Exception):
pass
class OutOfMemory(RuntimeException):
eid = 0
class RTIOUnderflow(RuntimeException):
eid = 1
exception_map = {e.eid: e for e in globals().values()
if isinstance(e, RuntimeException.__class__)
and hasattr(e, "eid")}

View File

@ -330,6 +330,8 @@ def syscall(*args):
_encoded_exceptions = dict() _encoded_exceptions = dict()
first_user_eid = 1024
def EncodedException(eid): def EncodedException(eid):
"""Represents exceptions on the core device, which are identified """Represents exceptions on the core device, which are identified

View File

@ -41,8 +41,7 @@ class _ReferenceManager:
# inlined_name -> use_count # inlined_name -> use_count
self.use_count = dict() self.use_count = dict()
self.rpc_mapper = _HostObjectMapper() self.rpc_mapper = _HostObjectMapper()
# exceptions 0-1023 are for runtime self.exception_mapper = _HostObjectMapper(core_language.first_user_eid)
self.exception_mapper = _HostObjectMapper(1024)
self.kernel_attr_init = [] self.kernel_attr_init = []
# reserved names # reserved names