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: 86c012924e58
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: dc1472826426
Choose a head ref
  • 3 commits
  • 4 files changed
  • 1 contributor

Commits on Apr 27, 2015

  1. Copy the full SHA
    cae473e View commit details
  2. Copy the full SHA
    8a19766 View commit details
  3. Copy the full SHA
    dc14728 View commit details
Showing with 97 additions and 69 deletions.
  1. +22 −15 artiq/coredevice/comm_generic.py
  2. +7 −7 artiq/test/full_stack.py
  3. +1 −1 benchmarks/rpc_timing.py
  4. +67 −46 soc/runtime/session.c
37 changes: 22 additions & 15 deletions artiq/coredevice/comm_generic.py
Original file line number Diff line number Diff line change
@@ -120,27 +120,34 @@ def run(self, kname):
self.write(bytes(kname, "ascii"))
logger.debug("running kernel: %s", kname)

def _receive_rpc_value(self, type_tag):
if type_tag == "n":
return None
if type_tag == "b":
return bool(struct.unpack("B", self.read(1))[0])
if type_tag == "i":
return struct.unpack(">l", self.read(4))[0]
if type_tag == "I":
return struct.unpack(">q", self.read(8))[0]
if type_tag == "f":
return struct.unpack(">d", self.read(8))[0]
if type_tag == "F":
n, d = struct.unpack(">qq", self.read(16))
return Fraction(n, d)

def _receive_rpc_values(self):
r = []
while True:
type_tag = chr(struct.unpack("B", self.read(1))[0])
if type_tag == "\x00":
return r
if type_tag == "n":
r.append(None)
if type_tag == "b":
r.append(bool(struct.unpack("B", self.read(1))[0]))
if type_tag == "i":
r.append(struct.unpack(">l", self.read(4))[0])
if type_tag == "I":
r.append(struct.unpack(">q", self.read(8))[0])
if type_tag == "f":
r.append(struct.unpack(">d", self.read(8))[0])
if type_tag == "F":
n, d = struct.unpack(">qq", self.read(16))
r.append(Fraction(n, d))
if type_tag == "l":
r.append(self._receive_rpc_values())
elif type_tag == "l":
elt_type_tag = chr(struct.unpack("B", self.read(1))[0])
length = struct.unpack(">l", self.read(4))[0]
r.append([self._receive_rpc_value(elt_type_tag)
for i in range(length)])
else:
r.append(self._receive_rpc_value(type_tag))

def _serve_rpc(self, rpc_wrapper, rpc_map, user_exception_map):
rpc_num = struct.unpack(">l", self.read(4))[0]
14 changes: 7 additions & 7 deletions artiq/test/full_stack.py
Original file line number Diff line number Diff line change
@@ -5,15 +5,15 @@

from artiq import *
from artiq.language.units import DimensionError
from artiq.coredevice import comm_serial, core, runtime_exceptions, rtio
from artiq.coredevice import comm_tcp, core, runtime_exceptions, rtio
from artiq.sim import devices as sim_devices


core_device = os.getenv("ARTIQ_CORE_DEVICE")


def _run_on_device(k_class, **parameters):
comm = comm_serial.Comm(serial_dev=core_device)
comm = comm_tcp.Comm(host=core_device)
try:
coredev = core.Core(comm=comm)
k_inst = k_class(core=coredev, **parameters)
@@ -208,7 +208,7 @@ def test_primes(self):
self.assertEqual(l_device, l_host)

def test_misc(self):
comm = comm_serial.Comm(serial_dev=core_device)
comm = comm_tcp.Comm(host=core_device)
try:
coredev = core.Core(comm=comm)
uut = _Misc(core=coredev)
@@ -249,7 +249,7 @@ def test_exceptions(self):
self.assertEqual(t_device, t_host)

def test_rpc_exceptions(self):
comm = comm_serial.Comm(serial_dev=core_device)
comm = comm_tcp.Comm(host=core_device)
try:
uut = _RPCExceptions(core=core.Core(comm=comm))
with self.assertRaises(_MyException):
@@ -312,7 +312,7 @@ class RTIOCase(unittest.TestCase):
# (C11 and C13 on Papilio Pro)
def test_loopback(self):
npulses = 4
comm = comm_serial.Comm(serial_dev=core_device)
comm = comm_tcp.Comm(host=core_device)
try:
coredev = core.Core(comm=comm)
uut = _RTIOLoopback(
@@ -327,7 +327,7 @@ def test_loopback(self):
comm.close()

def test_underflow(self):
comm = comm_serial.Comm(serial_dev=core_device)
comm = comm_tcp.Comm(host=core_device)
try:
coredev = core.Core(comm=comm)
uut = _RTIOUnderflow(
@@ -340,7 +340,7 @@ def test_underflow(self):
comm.close()

def test_sequence_error(self):
comm = comm_serial.Comm(serial_dev=core_device)
comm = comm_tcp.Comm(host=core_device)
try:
coredev = core.Core(comm=comm)
uut = _RTIOSequenceError(
2 changes: 1 addition & 1 deletion benchmarks/rpc_timing.py
Original file line number Diff line number Diff line change
@@ -28,5 +28,5 @@ def run(self):
self.bench()
mean = sum(self.ts)/self.repeats
self.rpc_time_stddev = sqrt(
sum([(t - mean)**2 for t in self.ts]))/self.repeats*s
sum([(t - mean)**2 for t in self.ts])/self.repeats)*s
self.rpc_time_mean = mean*s
113 changes: 67 additions & 46 deletions soc/runtime/session.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <string.h>
#include <stdio.h>
#include <stdarg.h>

#include <generated/csr.h>
@@ -105,66 +106,86 @@ enum {
REMOTEMSG_TYPE_RPC_REQUEST,
};

static int add_rpc_value(int bi, int type_tag, void *value)
static int add_base_rpc_value(char base_type, void *value, char *buffer_out, int available_space)
{
char base_type;
int obi, r;
int i, p;
int len;

obi = bi;
base_type = type_tag;

if((bi + 1) > BUFFER_OUT_SIZE)
return -1;
buffer_out[bi++] = base_type;

switch(base_type) {
case 'n':
return bi - obi;
return 0;
case 'b':
if((bi + 1) > BUFFER_OUT_SIZE)
if(available_space < 1)
return -1;
if(*(char *)value)
buffer_out[bi++] = 1;
buffer_out[0] = 1;
else
buffer_out[bi++] = 0;
return bi - obi;
buffer_out[0] = 0;
return 1;
case 'i':
if((bi + 4) > BUFFER_OUT_SIZE)
if(available_space < 4)
return -1;
memcpy(&buffer_out[bi], value, 4);
bi += 4;
return bi - obi;
memcpy(buffer_out, value, 4);
return 4;
case 'I':
case 'f':
if((bi + 8) > BUFFER_OUT_SIZE)
if(available_space < 8)
return -1;
memcpy(&buffer_out[bi], value, 8);
bi += 8;
return bi - obi;
memcpy(buffer_out, value, 8);
return 8;
case 'F':
if((bi + 16) > BUFFER_OUT_SIZE)
return -1;
memcpy(&buffer_out[bi], value, 16);
bi += 16;
return bi - obi;
case 'l':
len = *(int *)value;
p = 4;
for(i=0;i<len;i++) {
r = add_rpc_value(bi, type_tag >> 8, (char *)value + p);
if(r < 0)
return r;
bi += r;
p += r;
}
if((bi + 1) > BUFFER_OUT_SIZE)
if(available_space < 16)
return -1;
buffer_out[bi++] = 0;
return bi - obi;
memcpy(buffer_out, value, 16);
return 16;
default:
return -1;
}
return -1;
}

static int add_rpc_value(int bi, int type_tag, void *value)
{
char base_type;
int obi, r;

obi = bi;
base_type = type_tag;

if((bi + 1) > BUFFER_OUT_SIZE)
return -1;
buffer_out[bi++] = base_type;

if(base_type == 'l') {
char elt_type;
int len;
int i, p;

elt_type = type_tag >> 8;
if((bi + 1) > BUFFER_OUT_SIZE)
return -1;
buffer_out[bi++] = elt_type;

len = *(int *)value;
if((bi + 4) > BUFFER_OUT_SIZE)
return -1;
memcpy(&buffer_out[bi], &len, 4);
bi += 4;

p = 4;
for(i=0;i<len;i++) {
r = add_base_rpc_value(elt_type, (char *)value + p,
&buffer_out[bi], BUFFER_OUT_SIZE - bi);
if(r < 0)
return r;
bi += r;
p += r;
}
} else {
r = add_base_rpc_value(base_type, value,
&buffer_out[bi], BUFFER_OUT_SIZE - bi);
if(r < 0)
return r;
bi += r;
}

return bi - obi;
}

static int send_rpc_request(int rpc_num, va_list args)
@@ -181,7 +202,7 @@ static int send_rpc_request(int rpc_num, va_list args)
while((type_tag = va_arg(args, int))) {
r = add_rpc_value(bi, type_tag,
type_tag == 'n' ? NULL : va_arg(args, void *));
if(bi < 0)
if(r < 0)
return 0;
bi += r;
}