core: add underflow recovery function

This commit is contained in:
Sebastien Bourdeauducq 2014-11-20 12:38:52 -08:00
parent 96720d20e9
commit dfd779c7c5
5 changed files with 13 additions and 3 deletions

View File

@ -7,6 +7,7 @@ from artiq.coredevice.runtime import LinkInterface
class _RuntimeEnvironment(LinkInterface): class _RuntimeEnvironment(LinkInterface):
def __init__(self, ref_period): def __init__(self, ref_period):
self.ref_period = ref_period self.ref_period = ref_period
self.initial_time = 0
def emit_object(self): def emit_object(self):
return str(self.llvm_module) return str(self.llvm_module)

View File

@ -11,6 +11,7 @@ from artiq.transforms.interleave import interleave
from artiq.transforms.lower_time import lower_time from artiq.transforms.lower_time import lower_time
from artiq.transforms.unparse import unparse from artiq.transforms.unparse import unparse
from artiq.py2llvm import get_runtime_binary from artiq.py2llvm import get_runtime_binary
from artiq.language.core import *
def _announce_unparse(label, node): def _announce_unparse(label, node):
@ -46,6 +47,7 @@ class Core:
runtime_env = comm.get_runtime_env() runtime_env = comm.get_runtime_env()
self.runtime_env = runtime_env self.runtime_env = runtime_env
self.comm = comm self.comm = comm
self.core = self
def transform_stack(self, func_def, rpc_map, exception_map, def transform_stack(self, func_def, rpc_map, exception_map,
debug_unparse=_no_debug_unparse): debug_unparse=_no_debug_unparse):
@ -67,7 +69,7 @@ class Core:
interleave(func_def) interleave(func_def)
debug_unparse("interleave", func_def) debug_unparse("interleave", func_def)
lower_time(func_def, getattr(self.runtime_env, "initial_time", 0)) lower_time(func_def, self.runtime_env.initial_time)
debug_unparse("lower_time", func_def) debug_unparse("lower_time", func_def)
remove_inter_assigns(func_def) remove_inter_assigns(func_def)
@ -103,3 +105,8 @@ class Core:
self.comm.load(binary) self.comm.load(binary)
self.comm.run(func_def.name) self.comm.run(func_def.name)
self.comm.serve(rpc_map, exception_map) self.comm.serve(rpc_map, exception_map)
@kernel
def recover_underflow(self):
t = syscall("rtio_get_counter") + self.runtime_env.initial_time
at(cycles_to_time(t))

View File

@ -17,6 +17,7 @@ _syscalls = {
"rtio_set": "Iii:n", "rtio_set": "Iii:n",
"rtio_replace": "Iii:n", "rtio_replace": "Iii:n",
"rtio_sync": "i:n", "rtio_sync": "i:n",
"rtio_get_counter": "n:I",
"rtio_get": "i:I", "rtio_get": "i:I",
"rtio_pileup_count": "i:i", "rtio_pileup_count": "i:i",
"dds_phase_clear_en": "ib:n", "dds_phase_clear_en": "ib:n",
@ -48,7 +49,7 @@ def _str_to_functype(s):
if c == "+": if c == "+":
type_args.append(lc.Type.int()) type_args.append(lc.Type.int())
var_arg_fixcount = n var_arg_fixcount = n
else: elif c != "n":
type_args.append(_chr_to_type[c]()) type_args.append(_chr_to_type[c]())
return (var_arg_fixcount, return (var_arg_fixcount,
lc.Type.function(type_ret, type_args, lc.Type.function(type_ret, type_args,

View File

@ -20,7 +20,7 @@ class PulsePerformance(AutoContext):
delay(cycles_to_time(T)) delay(cycles_to_time(T))
except RTIOUnderflow: except RTIOUnderflow:
T += 1 T += 1
delay(1*ms) self.core.recover_underflow()
else: else:
print_min_period(int(cycles_to_time(2*T)/(1*ns))) print_min_period(int(cycles_to_time(2*T)/(1*ns)))
break break

View File

@ -15,6 +15,7 @@ static const struct symbol syscalls[] = {
{"rtio_set", rtio_set}, {"rtio_set", rtio_set},
{"rtio_replace", rtio_replace}, {"rtio_replace", rtio_replace},
{"rtio_sync", rtio_sync}, {"rtio_sync", rtio_sync},
{"rtio_get_counter", rtio_get_counter},
{"rtio_get", rtio_get}, {"rtio_get", rtio_get},
{"rtio_pileup_count", rtio_pileup_count}, {"rtio_pileup_count", rtio_pileup_count},
{"dds_phase_clear_en", dds_phase_clear_en}, {"dds_phase_clear_en", dds_phase_clear_en},