-
-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(driver/acpi_pm): Implement ACPI PM Timer #772
feat(driver/acpi_pm): Implement ACPI PM Timer #772
Conversation
r? @fslongjin dragonosbot has assigned @fslongjin. Use |
rv64编译报错的话,按照构建内核的那个文档,编译一下试试看看错哪了 |
kernel/src/arch/x86_64/acpi.rs
Outdated
@@ -34,3 +42,24 @@ pub(super) fn early_acpi_boot_init() -> Result<(), SystemError> { | |||
// todo!("early_acpi_boot_init") | |||
return Ok(()); | |||
} | |||
|
|||
/// # 解析fadt | |||
fn acpi_parse_fadt() -> Result<(), SystemError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这些操作应该放在这个PM timer的初始化代码里面,并且按照现在这种写法,一旦机器上没有PM timer,就会直接报错无法启动。这是不正确的
/// | ||
/// ## 返回值 | ||
/// - u32: 读取到的acpi_pmtmr值 | ||
pub fn acpi_pm_read_verified() -> u32 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这些参考了linux的话,把linux里面的代码链接也贴一贴
} | ||
|
||
lazy_static! { | ||
pub static ref CLOCKSOURCE_ACPI_PM: Arc<Acpipm> = Acpipm::new(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不要使用lazy static,而是弄个option。这样才能在确定的初始化时机,把它初始化了。这样有助于以后排除bug
kernel/src/time/clocksource.rs
Outdated
@@ -57,12 +57,15 @@ pub static mut FINISHED_BOOTING: AtomicBool = AtomicBool::new(false); | |||
|
|||
/// Interval: 0.5sec Threshold: 0.0625s | |||
/// 系统节拍率 | |||
pub const HZ: u64 = 250; | |||
pub const HZ: u64 = 4; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个地方要改回去
/// watchdog检查间隔 | ||
pub const WATCHDOG_INTERVAL: u64 = HZ >> 1; | ||
/// 最大能接受的误差大小 | ||
pub const WATCHDOG_THRESHOLD: u32 = NSEC_PER_SEC >> 4; | ||
|
||
pub const MAX_SKEW_USEC: u64 = 125 * WATCHDOG_INTERVAL / HZ; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这些值从哪个地方弄过来的?麻烦打个链接
然后麻烦把对应的那个issue的链接,粘贴到PR的简介里面,并且编写PR简介 |
@dragonosbot review |
} | ||
} | ||
|
||
#[cfg(target_arch = "riscv64")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
按照linux的语义,这个应写为#[cfg(not(target_arch = "x86_64"))]
,所有linux里面为#ifndef x86_64
的地方,都要写成#[cfg(not(target_arch = "x86_64"))]
,而不是#[cfg(target_arch = "riscv64")]
kernel/src/driver/acpi/pmtmr.rs
Outdated
} | ||
|
||
#[inline(always)] | ||
#[cfg(target_arch = "riscv64")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里也是。
pub const CALIBRATE_LATCH: u64 = (PIT_TICK_RATE * CALIBRATE_TIME_MSEC + 1000 / 2) / 1000; | ||
|
||
#[inline(always)] | ||
pub fn mach_prepare_counter() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这些代码明明是x86的,为什么写到riscv64里面来?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的代码使用是在非x86的配置下使用的,如果放在x86里面不能用了。要不把这个文件的东西写到acpi_pm.rs里面?我看linux这这个文件的方法和常量仅在acpi_pm里面使用
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
要不把这个文件的东西写到acpi_pm.rs里面?
Ok我感觉可以
|
||
fn update_clocksource_data(&self, _data: ClocksourceData) -> Result<(), SystemError> { | ||
let d = &mut self.0.lock_irqsave().data; | ||
d.set_flags(_data.flags); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_data
用到了的话就不用加_
前缀了。
let value1 = clocksource_acpi_pm().read().data(); | ||
let mut i = 0; | ||
for _ in 0..ACPI_PM_READ_CHECKS { | ||
i += 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
按照linux里面的含义,这个+=1的操作应当是在每次循环之后才加,而不是在循环开始的地方加。
} | ||
|
||
// 检查ACPI PM Timer的频率是否正确 | ||
if verify_pmtmr_rate() != 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个函数linux里面的含义就是返回一个bool。因此需要修改一下。
kernel/src/time/clocksource.rs
Outdated
let mut sft = 1; | ||
|
||
// 计算限制转换范围的shift | ||
let mut tmp = (maxsec * from) as u64 >> 32; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
应当是两个都转成u64之后再相乘。
kernel/src/time/clocksource.rs
Outdated
/// # 计算时钟源可以进行的最大调整量 | ||
fn clocksource_max_adjustment(&self) -> u32 { | ||
let cs_data = self.clocksource_data(); | ||
let ret = cs_data.mult * 11 / 100; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cs_data.mult先转u64再乘11
kernel/src/time/clocksource.rs
Outdated
} | ||
|
||
let mut cs_data = self.clocksource_data(); | ||
cs_data.set_mult(tmp as u32); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的设置的操作应当在调用方那边写。linux里面这个函数是个通用函数,而你这样写的话是把这函数跟cs_data耦合起来了。因此应当把mult和shift返回出去,并且在外层调用cs_data相关的方法。
@dragonosbot review |
* feat: Implement ACPI PM Timer
feat: 实现 ACPI PM Timer
本 PR 实现了 ACPI的 PM Timer 功能,PM Timer 用于在没有hpet时校准tsc。
这次更改包括:
相关 Issue:#741