Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/artiq
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0416da8634ab
Choose a base ref
...
head repository: m-labs/artiq
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2b3641ac0aed
Choose a head ref
  • 4 commits
  • 14 files changed
  • 1 contributor

Commits on Mar 12, 2015

  1. Copy the full SHA
    330e7e1 View commit details

Commits on Mar 13, 2015

  1. Copy the full SHA
    84732a4 View commit details
  2. coredevice,runtime,language: add parameters to runtime exceptions, in…

    …clude information with RTIO errors
    sbourdeauducq committed Mar 13, 2015
    Copy the full SHA
    7a1d60e View commit details
  3. Copy the full SHA
    2b3641a View commit details
6 changes: 4 additions & 2 deletions artiq/coredevice/comm_serial.py
Original file line number Diff line number Diff line change
@@ -195,13 +195,15 @@ def _serve_rpc(self, rpc_map, user_exception_map):
rpc_num, args, r))

def _serve_exception(self, user_exception_map):
eid = struct.unpack(">l", _read_exactly(self.port, 4))[0]
eid, p0, p1, p2 = struct.unpack(">lqqq",
_read_exactly(self.port, 4+3*8))
self.rpc_wrapper.filter_rpc_exception(eid)
if eid < core_language.first_user_eid:
exception = runtime_exceptions.exception_map[eid]
raise exception(self.core, p0, p1, p2)
else:
exception = user_exception_map[eid]
raise exception
raise exception

def serve(self, rpc_map, user_exception_map):
while True:
1 change: 1 addition & 0 deletions artiq/coredevice/core.py
Original file line number Diff line number Diff line change
@@ -52,6 +52,7 @@ class DBKeys:
def build(self):
self.runtime_env = self.comm.get_runtime_env()
self.core = self
self.comm.core = self

if self.external_clock is None:
self.ref_period = self.runtime_env.internal_ref_period
2 changes: 1 addition & 1 deletion artiq/coredevice/gpio.py
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

class GPIOOut(AutoDB):
class DBKeys:
core = Device()
core = Device()
channel = Argument()

@kernel
13 changes: 13 additions & 0 deletions artiq/coredevice/runtime_exceptions.py
Original file line number Diff line number Diff line change
@@ -25,6 +25,12 @@ class RTIOUnderflow(RuntimeException):
"""
eid = 3

def __str__(self):
return "at {} on channel {}, violation {}".format(
self.p0*self.core.ref_period,
self.p1,
(self.p2 - self.p0)*self.core.ref_period)


class RTIOSequenceError(RuntimeException):
"""Raised when an event is submitted on a given channel with a timestamp
@@ -35,6 +41,10 @@ class RTIOSequenceError(RuntimeException):
"""
eid = 4

def __str__(self):
return "at {} on channel {}".format(self.p0*self.core.ref_period,
self.p1)


class RTIOOverflow(RuntimeException):
"""Raised when at least one event could not be registered into the RTIO
@@ -47,6 +57,9 @@ class RTIOOverflow(RuntimeException):
"""
eid = 5

def __str__(self):
return "on channel {}".format(self.p0)


exception_map = {e.eid: e for e in globals().values()
if inspect.isclass(e)
4 changes: 3 additions & 1 deletion artiq/frontend/artiq_run.py
Original file line number Diff line number Diff line change
@@ -118,7 +118,8 @@ def main():
if args.arguments:
print("Run arguments are not supported in ELF mode")
sys.exit(1)
exp_inst = ELFRunner(dps)
exp_inst = ELFRunner(dbh)
rdb.build()
exp_inst.run(args.file)
else:
module = file_import(args.file)
@@ -159,6 +160,7 @@ def main():
scheduler=DummyScheduler(),
run_params=run_params,
**run_params["arguments"])
rdb.build()
exp_inst.run()
exp_inst.analyze()

8 changes: 6 additions & 2 deletions artiq/language/core.py
Original file line number Diff line number Diff line change
@@ -283,9 +283,13 @@ def __init__(self):
class RuntimeException(Exception):
"""Base class for all exceptions used by the device runtime.
Those exceptions are defined in ``artiq.coredevice.runtime_exceptions``.
"""
pass
def __init__(self, core, p0, p1, p2):
Exception.__init__(self)
self.core = core
self.p0 = p0
self.p1 = p1
self.p2 = p2


first_user_eid = 1024
2 changes: 1 addition & 1 deletion artiq/language/db.py
Original file line number Diff line number Diff line change
@@ -83,7 +83,7 @@ def __init__(self, dbh=None, **kwargs):
object.__setattr__(self, k, dev)
self.build()
if self.dbh is not None:
self.dbh.init_results(self.realtime_results)
self.dbh.add_rt_results(self.realtime_results)

def __getattr__(self, name):
ak = getattr(self.DBKeys, name)
17 changes: 11 additions & 6 deletions artiq/master/worker_db.py
Original file line number Diff line number Diff line change
@@ -10,13 +10,18 @@ class ResultDB:
def __init__(self, init_rt_results, update_rt_results):
self.init_rt_results = init_rt_results
self.update_rt_results = update_rt_results
self.rtr_description = dict()

def init(self, rtr_description):
assert not hasattr(self, "realtime_data")
assert not hasattr(self, "data")
def add_rt_results(self, rtr_description):
intr = set(self.rtr_description.keys()).intersection(
set(rtr_description.keys()))
if intr:
raise ValueError("Duplicate realtime results: " + ", ".join(intr))
self.rtr_description.update(rtr_description)

def build(self):
realtime_results_set = set()
for rtr in rtr_description.keys():
for rtr in self.rtr_description.keys():
if isinstance(rtr, tuple):
for e in rtr:
realtime_results_set.add(e)
@@ -26,7 +31,7 @@ def init(self, rtr_description):
self.realtime_data = Notifier({x: [] for x in realtime_results_set})
self.data = Notifier(dict())

self.init_rt_results(rtr_description)
self.init_rt_results(self.rtr_description)
self.realtime_data.publish = lambda notifier, data: \
self.update_rt_results(data)

@@ -83,7 +88,7 @@ def __init__(self, ddb, pdb, rdb):

self.get_parameter = pdb.request
self.set_parameter = pdb.set
self.init_results = rdb.init
self.add_rt_results = rdb.add_rt_results
self.get_result = rdb.request
self.set_result = rdb.set

1 change: 1 addition & 0 deletions artiq/master/worker_impl.py
Original file line number Diff line number Diff line change
@@ -112,6 +112,7 @@ def main():
scheduler=Scheduler,
run_params=run_params,
**run_params["arguments"])
rdb.build()
put_object({"action": "completed"})
elif action == "run":
exp_inst.run()
1 change: 1 addition & 0 deletions doc/manual/developing_a_ndsp.rst
Original file line number Diff line number Diff line change
@@ -172,6 +172,7 @@ The program below exemplifies how to use logging: ::
General guidelines
------------------

* Do not use ``__del__`` to implement the cleanup code of your driver. Instead, define a ``close`` method, and call it using a ``try...finally...`` block in the controller.
* Format your source code according to PEP8. We suggest using ``flake8`` to check for compliance.
* Use new-style formatting (``str.format``) except for logging where it is not well supported, and double quotes for strings.
* The device identification (e.g. serial number) to attach to must be passed as a command-line parameter to the controller. We suggest using ``-s`` and ``--serial`` as parameter name.
12 changes: 12 additions & 0 deletions soc/runtime/comm_serial.c
Original file line number Diff line number Diff line change
@@ -55,6 +55,16 @@ static char receive_char(void)
return uart_read();
}

static void send_llint(long long int x)
{
int i;

for(i=0;i<8;i++) {
uart_write((x & 0xff00000000000000LL) >> 56);
x <<= 8;
}
}

static void send_int(int x)
{
int i;
@@ -140,6 +150,8 @@ static void receive_and_run_kernel(kernel_runner run_kernel)
case KERNEL_RUN_EXCEPTION:
send_char(MSGTYPE_KERNEL_EXCEPTION);
send_int(eid);
for(i=0;i<3;i++)
send_llint(exception_params[i]);
break;
case KERNEL_RUN_STARTUP_FAILED:
send_char(MSGTYPE_KERNEL_STARTUP_FAILED);
11 changes: 11 additions & 0 deletions soc/runtime/exceptions.c
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ struct exception_context {
static struct exception_context exception_contexts[MAX_EXCEPTION_CONTEXTS];
static int ec_top;
static int stored_id;
long long int exception_params[3];

void *exception_push(void)
{
@@ -29,9 +30,19 @@ int exception_getid(void)
}

void exception_raise(int id)
{
exception_raise_params(id, 0, 0, 0);
}

void exception_raise_params(int id,
long long int p0, long long int p1,
long long int p2)
{
if(ec_top > 0) {
stored_id = id;
exception_params[0] = p0;
exception_params[1] = p1;
exception_params[2] = p2;
exception_longjmp(exception_contexts[--ec_top].jb);
} else {
comm_log("ERROR: uncaught exception, ID=%d\n", id);
5 changes: 5 additions & 0 deletions soc/runtime/exceptions.h
Original file line number Diff line number Diff line change
@@ -10,12 +10,17 @@ enum {
EID_RTIO_OVERFLOW = 5,
};

extern long long int exception_params[3];

int exception_setjmp(void *jb) __attribute__((returns_twice));
void exception_longjmp(void *jb) __attribute__((noreturn));

void *exception_push(void);
void exception_pop(int levels);
int exception_getid(void);
void exception_raise(int id) __attribute__((noreturn));
void exception_raise_params(int id,
long long int p0, long long int p1,
long long int p2) __attribute__((noreturn));

#endif /* __EXCEPTIONS_H */
15 changes: 10 additions & 5 deletions soc/runtime/rtio.c
Original file line number Diff line number Diff line change
@@ -38,11 +38,13 @@ void rtio_set(long long int timestamp, int channel, int value)
while(rtio_o_status_read() & RTIO_O_STATUS_FULL);
if(status & RTIO_O_STATUS_UNDERFLOW) {
rtio_o_underflow_reset_write(1);
exception_raise(EID_RTIO_UNDERFLOW);
exception_raise_params(EID_RTIO_UNDERFLOW,
timestamp, channel, rtio_get_counter());
}
if(status & RTIO_O_STATUS_SEQUENCE_ERROR) {
rtio_o_sequence_error_reset_write(1);
exception_raise(EID_RTIO_SEQUENCE_ERROR);
exception_raise_params(EID_RTIO_SEQUENCE_ERROR,
timestamp, channel, 0);
}
}
}
@@ -62,7 +64,8 @@ long long int rtio_get(int channel, long long int time_limit)
while((status = rtio_i_status_read())) {
if(rtio_i_status_read() & RTIO_I_STATUS_OVERFLOW) {
rtio_i_overflow_reset_write(1);
exception_raise(EID_RTIO_OVERFLOW);
exception_raise_params(EID_RTIO_OVERFLOW,
channel, 0, 0);
}
if(rtio_get_counter() >= time_limit) {
/* check empty flag again to prevent race condition.
@@ -114,11 +117,13 @@ void rtio_fud(long long int fud_time)
if(status) {
if(status & RTIO_O_STATUS_UNDERFLOW) {
rtio_o_underflow_reset_write(1);
exception_raise(EID_RTIO_UNDERFLOW);
exception_raise_params(EID_RTIO_UNDERFLOW,
fud_time, RTIO_FUD_CHANNEL, rtio_get_counter());
}
if(status & RTIO_O_STATUS_SEQUENCE_ERROR) {
rtio_o_sequence_error_reset_write(1);
exception_raise(EID_RTIO_SEQUENCE_ERROR);
exception_raise_params(EID_RTIO_SEQUENCE_ERROR,
fud_time, RTIO_FUD_CHANNEL, 0);
}
}
}