-
Notifications
You must be signed in to change notification settings - Fork 13.3k
std: sys: pal: uefi: Overhaul Time #139806
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
base: master
Are you sure you want to change the base?
Conversation
library/std/src/sys/pal/uefi/time.rs
Outdated
} | ||
|
||
pub(crate) const fn checked_add(&self, dur: Duration) -> Self { | ||
let temp: u32 = self.usecs + dur.subsec_nanos(); |
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.
you're combining something called usecs
with something called nanos
that doesn't seem to be correct?
EDIT: it looks like usecs
should be called nanos thruout the file?
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.
I have renamed it to nanos
now. The reason for using nanos
instead of normal microseconds (which is uses in unix) is because nanoseconds are stored in the UEFI Time normally.
52207df
to
f4cd07a
Compare
@rustbot label +O-UEFI |
f4cd07a
to
451a576
Compare
This still doesn't solve the problem that Then, there is a design question: I think it might be more advantageous to convert the time and date directly into seconds (just like in the old version) as all of the operations use seconds, and it's unlikely that one would create a |
You mean they should fail for bounds outside of those defined here? Or should it fail when the values don't fit in the underlying data structure?
Ok, but should unspecified to unspecified calculation be fine? Currently the timezone on my qemu also shows up as unspecified, so I think they should be allowed.
Ok, I was thinking the same as all that to and fro conversion for everything was getting a bit too much. |
I think we should use the defined bounds (so years from 1900–9999, etc.).
I agree. Only unspecified-specified calculations are undefined.
😄 yeah... I'd maybe still choose a different timebase than UNIX time. You could e.g. use 1900-01-01-00:00,0[local] as base, which would allow you to use |
So how should conversion be done? UEFI -> Unix -> Anchor to 1900-01-01-00:00,0 ? |
The source for the algorithm you cite already does a conversion from a timebase of 0000-03-01 to 1970-01-01 by adding/subtracting an offset from the day count.
We'd simply need to find the offset for 1900-01-01, use it in the algorithm instead and adjust the UNIX_EPOCH constant accordingly. |
By my calculation (well, by inputting the time into the algorithm), the day offset is 693901 for 1900-01-01. |
36dd216
to
1e8af15
Compare
I have adjusted both conversion offsets and run some initial tests with time anchored to 1900-01-01. Additionally, I have added checks to ensure that the results of calculations are representable in UEFI Time. |
ping @joboet |
I don't think keeping track of the timezone in
|
So, the timestamp in
Well, that does explain the weird behavior I was observing on OVMF. I can see that I get unspecified timezone, even though I can see the timestamp is UTC. Why does
Do you have any idea what Project Mu does? If everyone disregards the spec, I guess we might as well. But we probably still need to check. |
Some RTCs always store the current time in UTC, and their drivers will adjust the returned time for the
Project Mu is based on EDK II and it appears to have not changed how FAT timestamps are handled (it also seems to have the same RTC drivers more or less AFAICT). |
@beetrees Sorry for the late reply. Was busy with college stuff. I have been pondering things a bit, and I am not sure why we need to do any modification to the time we get from UEFI in Rust. Let's look at Rust's Construct a new instanceThe only way to do this, is So any instance used in comparison and other things will also only come from the same way of construction. Note: If someone calls SetTime, and goes from Unspecified to UTC or vice versa, and then tries to copare to previous time, then I personally would consider it a user error. Internal UsageThere might be use cases where we do want to interpret SystemTime Timezone differently, but I feel like that should be on a case by case basis. The base |
A |
1e8af15
to
3fb7543
Compare
Use a time representation with 1900-01-01-00:00:00 as anchor. This is the earliest time supported in UEFI. Signed-off-by: Ayush Singh <[email protected]>
3fb7543
to
51e4cb2
Compare
Good point. I have updated the PR. |
Use UEFI time format for SystemTime.
All calculations and comparisons are being done using UnixTime since UEFI Time format does not seem good fit for those calculations.
I have tested the conversions and calculations, but I am not sure if there is a way to run unit tests for platform specific code in Rust source.
The only real benefit from using UEFI Time representation is that to and fro conversion will preserve
daylight
andtimezone
values.r? @joboet