Skip to content
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

Merged
merged 13 commits into from
Apr 28, 2024

Conversation

1037827920
Copy link
Contributor

@1037827920 1037827920 commented Apr 26, 2024

feat: 实现 ACPI PM Timer

本 PR 实现了 ACPI的 PM Timer 功能,PM Timer 用于在没有hpet时校准tsc。

这次更改包括:

  • 实现了 ACPI PM Timer 的初始化功能
  • 添加了 ACPI PM Timer 的读取
  • 在hpet读取失败时进行初始化acpi_pm

相关 Issue:#741

@dragonosbot
Copy link

r? @fslongjin

dragonosbot has assigned @fslongjin.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@dragonosbot dragonosbot added O-x86_64 Target: x86_64 S-等待审查 Status: 等待assignee以及相关方的审查。 T-driver Relevant to the driver team, which will review and decide on the PR/issue. labels Apr 26, 2024
@github-actions github-actions bot added the enhancement New feature or request label Apr 26, 2024
@1037827920 1037827920 changed the title feat: Implement ACPI PM Timer feat(driver/acpi_pm): Implement ACPI PM Timer Apr 26, 2024
@github-actions github-actions bot removed the enhancement New feature or request label Apr 26, 2024
@fslongjin
Copy link
Member

rv64编译报错的话,按照构建内核的那个文档,编译一下试试看看错哪了

@@ -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> {
Copy link
Member

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 {
Copy link
Member

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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要使用lazy static,而是弄个option。这样才能在确定的初始化时机,把它初始化了。这样有助于以后排除bug

@@ -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;
Copy link
Member

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这些值从哪个地方弄过来的?麻烦打个链接

@dragonosbot dragonosbot added S-等待作者修改 Status: 这正在等待作者的一些操作(例如代码更改或更多信息)。 and removed S-等待审查 Status: 等待assignee以及相关方的审查。 labels Apr 26, 2024
@fslongjin
Copy link
Member

然后麻烦把对应的那个issue的链接,粘贴到PR的简介里面,并且编写PR简介

@github-actions github-actions bot added the enhancement New feature or request label Apr 26, 2024
@dragonosbot dragonosbot added the O-riscv64 Target: riscv64 label Apr 26, 2024
@1037827920
Copy link
Contributor Author

@dragonosbot review

@dragonosbot dragonosbot added S-等待审查 Status: 等待assignee以及相关方的审查。 and removed S-等待作者修改 Status: 这正在等待作者的一些操作(例如代码更改或更多信息)。 labels Apr 26, 2024
}
}

#[cfg(target_arch = "riscv64")]
Copy link
Member

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")]

}

#[inline(always)]
#[cfg(target_arch = "riscv64")]
Copy link
Member

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() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这些代码明明是x86的,为什么写到riscv64里面来?

Copy link
Contributor Author

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里面使用

Copy link
Member

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);
Copy link
Member

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;
Copy link
Member

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个函数linux里面的含义就是返回一个bool。因此需要修改一下。

let mut sft = 1;

// 计算限制转换范围的shift
let mut tmp = (maxsec * from) as u64 >> 32;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应当是两个都转成u64之后再相乘。

/// # 计算时钟源可以进行的最大调整量
fn clocksource_max_adjustment(&self) -> u32 {
let cs_data = self.clocksource_data();
let ret = cs_data.mult * 11 / 100;
Copy link
Member

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

}

let mut cs_data = self.clocksource_data();
cs_data.set_mult(tmp as u32);
Copy link
Member

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 dragonosbot added S-等待作者修改 Status: 这正在等待作者的一些操作(例如代码更改或更多信息)。 and removed S-等待审查 Status: 等待assignee以及相关方的审查。 labels Apr 27, 2024
@1037827920
Copy link
Contributor Author

@dragonosbot review

@dragonosbot dragonosbot added S-等待审查 Status: 等待assignee以及相关方的审查。 and removed S-等待作者修改 Status: 这正在等待作者的一些操作(例如代码更改或更多信息)。 labels Apr 27, 2024
@fslongjin fslongjin merged commit dd8e74e into DragonOS-Community:master Apr 28, 2024
7 checks passed
BrahmaMantra pushed a commit to BrahmaMantra/DragonOS that referenced this pull request Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request O-riscv64 Target: riscv64 O-x86_64 Target: x86_64 S-等待审查 Status: 等待assignee以及相关方的审查。 T-driver Relevant to the driver team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants