Log messages to the serial atomically and rename arch::serial

Co-authored-by: Chuandong Li <lichuand@pku.edu.cn>
This commit is contained in:
Zhang Junyang
2024-06-29 11:54:01 +00:00
committed by Tate, Hongliang Tian
parent 6ff6db2167
commit 9e5f3123e1
7 changed files with 29 additions and 16 deletions

View File

@ -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);
}