Misc cleanups.

- change early logging (pre kata-shell prompt) to trace level so by
  default nothing shows up unless kata-debug-console::pre_init sets
  log::set_max_level to Trace (default is Debug)
- log allocator init's in caller so log msgs identify per-component heap
  setups (all the same for now but at some point may diverge)
- shorten kata-shell prompt to "KATA> " - remove unused camkes control's
  and consolidate other early work in pre_init and <component>__init hooks
- cargo fmt components

Change-Id: I010eb5cc5af2e379691cb2e62d82dbab32a06bc3
GitOrigin-RevId: badddf46f5ba50fa60e9cbead9f6d99d5ff3808b
This commit is contained in:
Sam Leffler 2021-09-03 09:44:09 -07:00
parent a3bd1a6026
commit d97a78316e
11 changed files with 35 additions and 40 deletions

View File

@ -6,5 +6,4 @@ edition = "2018"
[dependencies]
linked_list_allocator = { version = "0.9", default-features = false, features = ["const_mut_refs"] }
log = "0.4"
spin = "0.9"

View File

@ -6,7 +6,6 @@
use core::alloc::{GlobalAlloc, Layout};
use core::panic;
use core::ptr::{self, NonNull};
use log::info;
use linked_list_allocator::Heap;
use spin::Mutex;
@ -53,10 +52,9 @@ impl KataHeap {
///
/// Obey these or Bad Stuff will happen.
///
/// - This function must be called exactly ONCE.
/// - This function must be called exactly ONCE (per thread).
/// - `size > 0`
pub unsafe fn init(&self, start_addr: usize, size: usize) {
info!("init: start_addr {:#x} size {}", start_addr, size);
(*self.heap.lock()).init(start_addr, size);
}

View File

@ -17,30 +17,31 @@ use kata_allocator;
use kata_logger::KataLogger;
use kata_shell;
use kata_uart_client;
use log::debug;
static KATA_LOGGER: KataLogger = KataLogger;
use log::trace;
#[no_mangle]
pub extern "C" fn pre_init() {
static KATA_LOGGER: KataLogger = KataLogger;
log::set_logger(&KATA_LOGGER).unwrap();
// NB: set to Trace for early-boot msgs
log::set_max_level(log::LevelFilter::Debug);
}
#[no_mangle]
// NB: use post_init insted of pre_init so syslog interface is setup
pub extern "C" fn post_init() {
// TODO(sleffler): temp until we integrate with seL4
static mut HEAP_MEMORY: [u8; 16 * 1024] = [0; 16 * 1024];
unsafe {
kata_allocator::ALLOCATOR.init(HEAP_MEMORY.as_mut_ptr() as usize, HEAP_MEMORY.len());
trace!(
"setup heap: start_addr {:p} size {}",
HEAP_MEMORY.as_ptr(),
HEAP_MEMORY.len()
);
}
}
/// Entry point for DebugConsole. Runs the shell with UART IO.
#[no_mangle]
pub extern "C" fn run() -> ! {
debug!("run");
trace!("run");
let mut tx = kata_uart_client::Tx {};
let mut rx = kata_uart_client::Rx {};
kata_shell::repl(&mut tx, &mut rx);

View File

@ -23,8 +23,7 @@ impl log::Log for KataLogger {
let mut buf = [0 as u8; MAX_MSG_LEN];
let mut cur = Cursor::new(&mut buf[..]);
// Log msgs are of the form: '<target>::<fmt'd-msg>
write!(&mut cur, "{}::{}\0", record.target(), record.args())
.unwrap_or_else(|_| {
write!(&mut cur, "{}::{}\0", record.target(), record.args()).unwrap_or_else(|_| {
// Too big, indicate overflow with a trailing "...".
cur.set_position((MAX_MSG_LEN - 4) as u64);
cur.write(b"...\0").expect("write!");
@ -38,8 +37,7 @@ impl log::Log for KataLogger {
record: &Record,
) -> &'a cstr_core::CStr {
let mut cur = Cursor::new(&mut buf[..]);
write!(&mut cur, "{}::<embedded nul>\0", record.target())
.expect("nul!");
write!(&mut cur, "{}::<embedded nul>\0", record.target()).expect("nul!");
let pos = cur.position() as usize;
CStr::from_bytes_with_nul(&buf[..pos]).unwrap()
}

View File

@ -3,7 +3,6 @@
use core::fmt;
use core::fmt::Write;
use cstr_core::CString;
use log::info;
use kata_io as io;
use kata_line_reader::LineReader;
@ -46,10 +45,9 @@ impl From<fmt::Error> for CommandError {
/// Read-eval-print loop for the DebugConsole command line interface.
pub fn repl(output: &mut dyn io::Write, input: &mut dyn io::Read) -> ! {
info!("DebugConsole::repl()");
let mut line_reader = LineReader::new();
loop {
const PROMPT: &str = "KATA_PROMPT> ";
const PROMPT: &str = "KATA> ";
let _ = output.write_str(PROMPT);
match line_reader.read_line(output, input) {
Ok(cmdline) => dispatch_command(cmdline, output),

View File

@ -21,14 +21,12 @@ extern "C" {
#[no_mangle]
pub extern "C" fn logger_log(level: u8, msg: *const cstr_core::c_char) {
use log::Level;
// TODO(sleffler): seems like this should be try_from?
let l = match level {
x if x == Level::Error as u8 => Level::Error,
x if x == Level::Warn as u8 => Level::Warn,
x if x == Level::Info as u8 => Level::Info,
x if x == Level::Debug as u8 => Level::Debug,
x if x == Level::Trace as u8 => Level::Trace,
_ => { return }, // TODO(sleffler): accept or not?
_ => Level::Trace,
};
if l <= log::max_level() {
// TODO(sleffler): is the uart driver ok w/ multiple writers?

View File

@ -2,7 +2,6 @@ import <LoggerInterface.camkes>;
import <MlCoordinatorInterface.camkes>;
component MlCoordinator {
control;
provides MlCoordinatorInterface mlcoord;
uses LoggerInterface logger;

View File

@ -5,19 +5,19 @@
extern crate kata_panic;
use kata_logger::KataLogger;
use log::debug;
static KATA_LOGGER: KataLogger = KataLogger;
use log::trace;
#[no_mangle]
pub extern "C" fn pre_init() {
static KATA_LOGGER: KataLogger = KataLogger;
log::set_logger(&KATA_LOGGER).unwrap();
log::set_max_level(log::LevelFilter::Debug);
log::set_max_level(log::LevelFilter::Trace);
}
#[no_mangle]
pub extern "C" fn run() {
debug!("run");
pub extern "C" fn mlcoord__init() {
// TODO(sleffler): maybe not needed?
trace!("init");
}
// TODO: Move out of this file into separate (auto-generated?) file.

View File

@ -1,14 +1,13 @@
// Kata OS ProcessManager services.
import <LoggerInterface.camkes>;
import <ProcessControlInterface.camkes>;
import <PackageManagementInterface.camkes>;
import <ProcessControlInterface.camkes>;
import <SeL4DebugInterface.camkes>;
component ProcessManager {
control;
provides ProcessControlInterface proc_ctrl;
provides PackageManagementInterface pkg_mgmt;
provides ProcessControlInterface proc_ctrl;
uses LoggerInterface logger;
uses SeL4DebugInterface sel4debug;

View File

@ -126,7 +126,8 @@ impl RawBundleIdData {
// TODO(sleffler): handle truncation better
pub fn pack_bundles(&mut self, bundles: &BundleIdArray) -> bare_io::Result<()> {
let mut result = Cursor::new(&mut self.data[..]);
let bundle_count = [u8::try_from(bundles.len()).map_err(|_| bare_io::ErrorKind::InvalidData)?];
let bundle_count =
[u8::try_from(bundles.len()).map_err(|_| bare_io::ErrorKind::InvalidData)?];
result.write(&bundle_count[..])?; // # bundles
for bid in bundles.ids.as_slice().iter() {
let bid_len = [u8::try_from(bid.len()).map_err(|_| bare_io::ErrorKind::InvalidData)?];

View File

@ -9,7 +9,7 @@ use kata_allocator;
use kata_logger::KataLogger;
use kata_proc_common::*;
use kata_proc_manager::KATA_PROC;
use log::{info, trace};
use log::trace;
#[no_mangle]
pub extern "C" fn pre_init() {
@ -22,25 +22,29 @@ pub extern "C" fn pre_init() {
static mut HEAP_MEMORY: [u8; 16 * 1024] = [0; 16 * 1024];
unsafe {
kata_allocator::ALLOCATOR.init(HEAP_MEMORY.as_mut_ptr() as usize, HEAP_MEMORY.len());
trace!(
"setup heap: start_addr {:p} size {}",
HEAP_MEMORY.as_ptr(),
HEAP_MEMORY.len()
);
}
// Complete KATA_PROC setup. This is as early as we can do it given that
// it needs the GlobalAllocator.
unsafe {
KATA_PROC.init();
info!(
trace!(
"ProcessManager has capacity for {} bundles",
KATA_PROC.capacity()
);
}
}
// TODO(sleffler): move to init or similar if a thread isn't needed
#[no_mangle]
pub extern "C" fn run() {
pub extern "C" fn pkg_mgmt__init() {
// Setup the userland address spaces, lifecycles, and system introspection
// for third-party applications.
trace!("run");
trace!("init");
}
// PackageManagerInterface glue stubs.