Skip to content

Bug: 由于整数除法而导致 get_time_ms()!=get_time_us()*1000 #1

Description

@kiria-moe

至少在ch4分支中,os/src/timer.rs中对于get_time_ms和get_time_us的实现是这样的:

pub fn get_time_ms() -> usize {
    time::read() / (CLOCK_FREQ / MSEC_PER_SEC)
}
pub fn get_time_us() -> usize {
    time::read() / (CLOCK_FREQ / MICRO_PER_SEC)
}

而 CLOCK_FREQ的值是12500000,最后的结果存在误差。

群内的@misonoi确认了我的猜想,并给出了先乘再除的解决方案(在此感谢大佬)。

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions