实现内核日志系统 (#489)

* 实现写日志和读取日志,并且能够在用户态下执行dmesg命令查看日志

* 通过klogctl实现dmesg

* 改用ConstGenericRingBuffer作内核缓冲区

* 更改缓冲区容量

* 将能够输出到控制台的日志级别改为日志级别枚举类,使用SpinLock控制KMSG,使用枚举类定义SYSLOG_ACTION,将do_syslog系统调用接口放在syscall.rs

* fix warning

* 完善do_syslog注释

* 将KMSG接入kinfo、kdebug等

* fix warning

* 修复显示的秒数不正确,·以及无法通过CI的问题
This commit is contained in:
Jomo
2024-01-24 16:13:15 +08:00
committed by GitHub
parent d46c6d2794
commit 8d72b68da9
27 changed files with 763 additions and 26 deletions

View File

@ -1,8 +1,11 @@
use core::{
fmt,
intrinsics::unlikely,
ops::{self, Sub},
};
use crate::arch::CurrentTimeArch;
use self::timekeep::ktime_get_real_ns;
pub mod clocksource;
@ -55,6 +58,27 @@ impl TimeSpec {
tv_nsec: nsec,
};
}
/// 获取当前时间
pub fn now() -> Self {
#[cfg(target_arch = "x86_64")]
{
use crate::arch::driver::tsc::TSCManager;
let khz = TSCManager::cpu_khz();
if unlikely(khz == 0) {
return TimeSpec::default();
} else {
return Self::from(Duration::from_millis(
CurrentTimeArch::get_cycles() as u64 / khz,
));
}
}
#[cfg(target_arch = "riscv64")]
{
unimplemented!("TimeSpec::now()")
}
}
}
impl Sub for TimeSpec {

View File

@ -129,7 +129,7 @@ impl Timer {
if unlikely(r.is_err()) {
kerror!(
"Failed to run timer function: {self:?} {:?}",
r.err().unwrap()
r.as_ref().err().unwrap()
);
}
}