Skip to content

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

@kiria-moe

Description

@kiria-moe

至少在ch4分支中,os/src/timer.rs中对于get_time_msget_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确认了我的猜想,并给出了先乘再除的解决方案(在此感谢大佬)。

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