From 965fdd35e52d772474d12c29bf1fb40fdfd2afb4 Mon Sep 17 00:00:00 2001 From: whitequark Date: Tue, 22 Nov 2016 14:45:40 +0000 Subject: [PATCH 1/6] runtime: show a prompt to erase startup/idle kernels. --- artiq/runtime.rs/src/lib.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/artiq/runtime.rs/src/lib.rs b/artiq/runtime.rs/src/lib.rs index b3350dfc8..f29a83eb3 100644 --- a/artiq/runtime.rs/src/lib.rs +++ b/artiq/runtime.rs/src/lib.rs @@ -18,6 +18,7 @@ use logger::BufferLogger; extern { fn putchar(c: libc::c_int) -> libc::c_int; fn readchar() -> libc::c_char; + fn readchar_nonblock() -> libc::c_int; } #[macro_export] @@ -100,11 +101,23 @@ pub unsafe extern fn rust_main() { static mut LOG_BUFFER: [u8; 65536] = [0; 65536]; BufferLogger::new(&mut LOG_BUFFER[..]) .register(move || { - info!("booting ARTIQ..."); + clock::init(); + info!("booting ARTIQ"); info!("software version {}", GIT_COMMIT); info!("gateware version {}", ::board::ident(&mut [0; 64])); - clock::init(); + let t = clock::get_ms(); + info!("press 'e' to erase startup and idle kernels..."); + while clock::get_ms() < t + 1000 { + if readchar_nonblock() != 0 && readchar() == b'e' as libc::c_char { + config::remove("startup_kernel"); + config::remove("idle_kernel"); + info!("startup and idle kernels erased"); + break + } + } + info!("continuing boot"); + rtio_crg::init(); network_init(); From fbd83cf9ee586536d31d48c540b24b5aee45b4e9 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Tue, 22 Nov 2016 22:46:19 +0800 Subject: [PATCH 2/6] kc705: remove stale DDS definition --- artiq/gateware/targets/kc705.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/artiq/gateware/targets/kc705.py b/artiq/gateware/targets/kc705.py index d7672b435..502ca5902 100755 --- a/artiq/gateware/targets/kc705.py +++ b/artiq/gateware/targets/kc705.py @@ -229,8 +229,6 @@ class NIST_CLOCK(_NIST_Ions): rtio_channels.append(rtio.LogChannel()) self.add_rtio(rtio_channels) - assert self.rtio.fine_ts_width <= 3 - self.config["DDS_RTIO_CLK_RATIO"] = 24 >> self.rtio.fine_ts_width class NIST_QC2(_NIST_Ions): @@ -309,8 +307,6 @@ class NIST_QC2(_NIST_Ions): rtio_channels.append(rtio.LogChannel()) self.add_rtio(rtio_channels) - assert self.rtio.fine_ts_width <= 3 - self.config["DDS_RTIO_CLK_RATIO"] = 24 >> self.rtio.fine_ts_width def main(): From cd40d5b107aa3de5f2b06678460f02bb53c6cade Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Wed, 23 Nov 2016 10:43:33 +0800 Subject: [PATCH 3/6] runtime: support for targets without I2C --- artiq/runtime.rs/libksupport/api.rs | 5 +++++ artiq/runtime.rs/libksupport/lib.rs | 1 + 2 files changed, 6 insertions(+) diff --git a/artiq/runtime.rs/libksupport/api.rs b/artiq/runtime.rs/libksupport/api.rs index 5a12ea691..dbfbd759b 100644 --- a/artiq/runtime.rs/libksupport/api.rs +++ b/artiq/runtime.rs/libksupport/api.rs @@ -105,9 +105,14 @@ static mut API: &'static [(&'static str, *const ())] = &[ api!(rtio_input_timestamp = ::rtio::input_timestamp), api!(rtio_input_data = ::rtio::input_data), + #[cfg(has_i2c)] api!(i2c_init = ::i2c::init), + #[cfg(has_i2c)] api!(i2c_start = ::i2c::start), + #[cfg(has_i2c)] api!(i2c_stop = ::i2c::stop), + #[cfg(has_i2c)] api!(i2c_write = ::i2c::write), + #[cfg(has_i2c)] api!(i2c_read = ::i2c::read), ]; diff --git a/artiq/runtime.rs/libksupport/lib.rs b/artiq/runtime.rs/libksupport/lib.rs index 6b285f889..027c0e3b3 100644 --- a/artiq/runtime.rs/libksupport/lib.rs +++ b/artiq/runtime.rs/libksupport/lib.rs @@ -50,6 +50,7 @@ macro_rules! artiq_raise { } mod rtio; +#[cfg(has_i2c)] mod i2c; use core::{mem, ptr, slice, str}; From 0443f83d5ee31cc532bba2f1d0b4948dd81e2fd9 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Wed, 23 Nov 2016 10:48:26 +0800 Subject: [PATCH 4/6] runtime: support for targets without RTIO log channel --- artiq/gateware/targets/kc705.py | 2 ++ artiq/gateware/targets/pipistrello.py | 1 + artiq/runtime.rs/libksupport/rtio.rs | 4 ++++ 3 files changed, 7 insertions(+) diff --git a/artiq/gateware/targets/kc705.py b/artiq/gateware/targets/kc705.py index 502ca5902..75de1ae8d 100755 --- a/artiq/gateware/targets/kc705.py +++ b/artiq/gateware/targets/kc705.py @@ -225,6 +225,7 @@ class NIST_CLOCK(_NIST_Ions): ofifo_depth=512, ififo_depth=4)) + self.config["HAS_RTIO_LOG"] = None self.config["RTIO_LOG_CHANNEL"] = len(rtio_channels) rtio_channels.append(rtio.LogChannel()) @@ -303,6 +304,7 @@ class NIST_QC2(_NIST_Ions): ofifo_depth=512, ififo_depth=4)) + self.config["HAS_RTIO_LOG"] = None self.config["RTIO_LOG_CHANNEL"] = len(rtio_channels) rtio_channels.append(rtio.LogChannel()) diff --git a/artiq/gateware/targets/pipistrello.py b/artiq/gateware/targets/pipistrello.py index 42dc87dac..42b217185 100755 --- a/artiq/gateware/targets/pipistrello.py +++ b/artiq/gateware/targets/pipistrello.py @@ -212,6 +212,7 @@ trce -v 12 -fastpaths -tsi {build_name}.tsi -o {build_name}.twr {build_name}.ncd rtio_channels.append(rtio.Channel.from_phy( phy, ofifo_depth=64, ififo_depth=64)) + self.config["HAS_RTIO_LOG"] = None self.config["RTIO_LOG_CHANNEL"] = len(rtio_channels) rtio_channels.append(rtio.LogChannel()) diff --git a/artiq/runtime.rs/libksupport/rtio.rs b/artiq/runtime.rs/libksupport/rtio.rs index 107583da4..4363b255d 100644 --- a/artiq/runtime.rs/libksupport/rtio.rs +++ b/artiq/runtime.rs/libksupport/rtio.rs @@ -125,6 +125,7 @@ pub extern fn input_data(channel: u32) -> u32 { } } +#[cfg(has_rtio_log)] pub fn log(timestamp: i64, data: &[u8]) { unsafe { csr::rtio::chan_sel_write(csr::CONFIG_RTIO_LOG_CHANNEL); @@ -146,3 +147,6 @@ pub fn log(timestamp: i64, data: &[u8]) { csr::rtio::o_we_write(1); } } + +#[cfg(not(has_rtio_log))] +pub fn log(timestamp: i64, data: &[u8]) {} From cd7527b701575b8c8998fca6f895c1265c31e9f5 Mon Sep 17 00:00:00 2001 From: whitequark Date: Wed, 23 Nov 2016 13:49:19 +0000 Subject: [PATCH 5/6] runtime: print trace level log messages to UART during startup. There's no way to retrieve them otherwise if the startup kernel hangs. --- artiq/runtime.rs/src/logger.rs | 21 +++++++++++++++++---- artiq/runtime.rs/src/session.rs | 2 ++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/artiq/runtime.rs/src/logger.rs b/artiq/runtime.rs/src/logger.rs index 77d1d01d5..e4093e48a 100644 --- a/artiq/runtime.rs/src/logger.rs +++ b/artiq/runtime.rs/src/logger.rs @@ -1,11 +1,12 @@ use core::{mem, ptr}; -use core::cell::RefCell; +use core::cell::{Cell, RefCell}; use log::{self, Log, LogLevel, LogMetadata, LogRecord, LogLevelFilter}; use log_buffer::LogBuffer; use clock; pub struct BufferLogger { - buffer: RefCell> + buffer: RefCell>, + trace_to_uart: Cell } unsafe impl Sync for BufferLogger {} @@ -15,7 +16,8 @@ static mut LOGGER: *const BufferLogger = ptr::null(); impl BufferLogger { pub fn new(buffer: &'static mut [u8]) -> BufferLogger { BufferLogger { - buffer: RefCell::new(LogBuffer::new(buffer)) + buffer: RefCell::new(LogBuffer::new(buffer)), + trace_to_uart: Cell::new(true) } } @@ -48,6 +50,14 @@ impl BufferLogger { pub fn extract R>(&self, f: F) -> R { f(self.buffer.borrow_mut().extract()) } + + pub fn disable_trace_to_uart(&self) { + if self.trace_to_uart.get() { + trace!("disabling tracing to UART; all further trace messages \ + are sent to core log only"); + self.trace_to_uart.set(false) + } + } } impl Log for BufferLogger { @@ -61,7 +71,10 @@ impl Log for BufferLogger { writeln!(self.buffer.borrow_mut(), "[{:12}us] {:>5}({}): {}", clock::get_us(), record.level(), record.target(), record.args()).unwrap(); - if record.level() <= LogLevel::Info { + + // Printing to UART is really slow, so avoid doing that when we have an alternative + // route to retrieve the debug messages. + if self.trace_to_uart.get() || record.level() <= LogLevel::Info { println!("[{:12}us] {:>5}({}): {}", clock::get_us(), record.level(), record.target(), record.args()); } diff --git a/artiq/runtime.rs/src/session.rs b/artiq/runtime.rs/src/session.rs index 78eba0faa..083cfa8a9 100644 --- a/artiq/runtime.rs/src/session.rs +++ b/artiq/runtime.rs/src/session.rs @@ -583,6 +583,8 @@ pub fn thread(waiter: Waiter, spawner: Spawner) { } } + BufferLogger::with_instance(|logger| logger.disable_trace_to_uart()); + let addr = SocketAddr::new(IP_ANY, 1381); let listener = TcpListener::bind(waiter, addr).expect("cannot bind socket"); listener.set_keepalive(true); From 4df7941a9797542f461ed11730ad222c88faef81 Mon Sep 17 00:00:00 2001 From: whitequark Date: Wed, 23 Nov 2016 13:53:12 +0000 Subject: [PATCH 6/6] runtime: don't attempt to perform writeback if disabled in kernel. Otherwise, the startup kernel session hangs. --- artiq/runtime.rs/libksupport/lib.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/artiq/runtime.rs/libksupport/lib.rs b/artiq/runtime.rs/libksupport/lib.rs index 027c0e3b3..08673e759 100644 --- a/artiq/runtime.rs/libksupport/lib.rs +++ b/artiq/runtime.rs/libksupport/lib.rs @@ -307,7 +307,10 @@ pub unsafe fn main() { (mem::transmute::(library.lookup("__modinit__")))(); send(&NowSave(NOW)); - attribute_writeback(library.lookup("typeinfo") as *const ()); + let typeinfo = library.lookup("typeinfo"); + if typeinfo != 0 { + attribute_writeback(typeinfo as *const ()) + } send(&RunFinished);