mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-19 12:36:46 +00:00
Log messages to the serial atomically and rename arch::serial
Co-authored-by: Chuandong Li <lichuand@pku.edu.cn>
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
6ff6db2167
commit
9e5f3123e1
@ -18,6 +18,7 @@ impl Write for VirtioConsolesPrinter {
|
||||
}
|
||||
}
|
||||
|
||||
/// Prints the formatted arguments to the standard output.
|
||||
pub fn _print(args: Arguments) {
|
||||
VirtioConsolesPrinter.write_fmt(args).unwrap();
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
#![allow(dead_code)]
|
||||
|
||||
pub use ostd::arch::console;
|
||||
use ostd::mm::VmReader;
|
||||
use spin::Once;
|
||||
|
||||
|
@ -3,7 +3,6 @@
|
||||
//! Platform-specific code for the x86 platform.
|
||||
|
||||
pub mod boot;
|
||||
pub mod console;
|
||||
pub(crate) mod cpu;
|
||||
pub mod device;
|
||||
pub(crate) mod ex_table;
|
||||
@ -13,6 +12,7 @@ pub(crate) mod kernel;
|
||||
pub(crate) mod mm;
|
||||
pub(crate) mod pci;
|
||||
pub mod qemu;
|
||||
pub mod serial;
|
||||
pub mod task;
|
||||
#[cfg(feature = "intel_tdx")]
|
||||
pub(crate) mod tdx_guest;
|
||||
@ -31,7 +31,7 @@ use log::{info, warn};
|
||||
|
||||
pub(crate) fn before_all_init() {
|
||||
enable_common_cpu_features();
|
||||
console::init();
|
||||
serial::init();
|
||||
}
|
||||
|
||||
pub(crate) fn after_all_init() {
|
||||
@ -46,7 +46,7 @@ pub(crate) fn after_all_init() {
|
||||
kernel::pic::enable();
|
||||
}
|
||||
}
|
||||
console::callback_init();
|
||||
serial::callback_init();
|
||||
timer::init();
|
||||
#[cfg(feature = "intel_tdx")]
|
||||
if !tdx_is_enabled() {
|
||||
|
@ -15,7 +15,7 @@ use trapframe::TrapFrame;
|
||||
use super::{device::serial::SerialPort, kernel::IO_APIC};
|
||||
use crate::{sync::SpinLock, trap::IrqLine};
|
||||
|
||||
/// Prints the formatted arguments to the standard output.
|
||||
/// Prints the formatted arguments to the standard output using the serial port.
|
||||
#[inline]
|
||||
pub fn print(args: fmt::Arguments) {
|
||||
Stdout.write_fmt(args).unwrap();
|
@ -158,7 +158,7 @@ fn run_ktests(test_whitelist: Option<&[&str]>, crate_whitelist: Option<&[&str]>)
|
||||
|
||||
use ktest::runner::{run_ktests, KtestResult};
|
||||
match run_ktests(
|
||||
&crate::console::print,
|
||||
&crate::console::early_print,
|
||||
fn_catch_unwind,
|
||||
test_whitelist.map(|s| s.iter().map(|s| s.to_string())),
|
||||
crate_whitelist,
|
||||
|
@ -5,23 +5,23 @@
|
||||
use core::fmt::Arguments;
|
||||
|
||||
/// Prints formatted arguments to the console.
|
||||
pub fn print(args: Arguments) {
|
||||
crate::arch::console::print(args);
|
||||
pub fn early_print(args: Arguments) {
|
||||
crate::arch::serial::print(args);
|
||||
}
|
||||
|
||||
/// Prints to the console.
|
||||
#[macro_export]
|
||||
macro_rules! early_print {
|
||||
($fmt: literal $(, $($arg: tt)+)?) => {
|
||||
$crate::console::print(format_args!($fmt $(, $($arg)+)?))
|
||||
$crate::console::early_print(format_args!($fmt $(, $($arg)+)?))
|
||||
}
|
||||
}
|
||||
|
||||
/// Prints to the console, with a newline.
|
||||
/// Prints to the console with a newline.
|
||||
#[macro_export]
|
||||
macro_rules! early_println {
|
||||
() => { $crate::early_print!("\n") };
|
||||
($fmt: literal $(, $($arg: tt)+)?) => {
|
||||
$crate::console::print(format_args!(concat!($fmt, "\n") $(, $($arg)+)?))
|
||||
$crate::console::early_print(format_args!(concat!($fmt, "\n") $(, $($arg)+)?))
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,14 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
//! Logging support.
|
||||
//!
|
||||
//! Currently the logger prints the logs to the console.
|
||||
//!
|
||||
//! This module guarantees _atomicity_ under concurrency: messages are always
|
||||
//! printed in their entirety without being mixed with messages generated
|
||||
//! concurrently on other cores.
|
||||
//!
|
||||
//! IRQs are disabled while printing. So do not print long log messages.
|
||||
|
||||
use alloc::format;
|
||||
|
||||
@ -48,6 +56,11 @@ impl log::Log for Logger {
|
||||
(timestamp, level, record_str)
|
||||
};
|
||||
|
||||
// Use a global lock to prevent interleaving of log messages.
|
||||
use crate::sync::SpinLock;
|
||||
static RECORD_LOCK: SpinLock<()> = SpinLock::new(());
|
||||
let _lock = RECORD_LOCK.lock_irq_disabled();
|
||||
|
||||
early_println!("{} {}: {}", timestamp, level, record_str);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user