From 739da9f1b3089c4a4de59939332f11e80b6915ce Mon Sep 17 00:00:00 2001 From: whitequark Date: Wed, 23 Nov 2016 13:49:19 +0000 Subject: [PATCH] runtime: print trace level log messages to UART during startup. There's no way to retrieve them otherwise if the startup kernel hangs. This commit was mistakenly removed in 88ad054. --- artiq/firmware/runtime/logger.rs | 21 +++++++++++++++++---- artiq/firmware/runtime/session.rs | 2 ++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/artiq/firmware/runtime/logger.rs b/artiq/firmware/runtime/logger.rs index 77d1d01d5..e4093e48a 100644 --- a/artiq/firmware/runtime/logger.rs +++ b/artiq/firmware/runtime/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/firmware/runtime/session.rs b/artiq/firmware/runtime/session.rs index 024aade89..08dea473c 100644 --- a/artiq/firmware/runtime/session.rs +++ b/artiq/firmware/runtime/session.rs @@ -590,6 +590,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);