bytecodealliance / wasmtime

A fast and secure runtime for WebAssembly
https://wasmtime.dev/
Apache License 2.0
15.24k stars 1.29k forks source link

Preview2: No Easy Way To Set Custom Initial Time For Monotonic Clock #6589

Open adamgfraser opened 1 year ago

adamgfraser commented 1 year ago

Currently all monotonic clock times are based on the time since the clock was created. See here. It would be nice to have an easy way to set this initial time to some other arbitrary value.

jameysharp commented 1 year ago

I'd love to hear more about the use case for this. At least in POSIX, the monotonic clock "represents the amount of time since an unspecified point in the past", so a consumer of such a clock is not allowed to care about when that base time was. Under what circumstance are you finding that it's important to be able to control this?

adamgfraser commented 1 year ago

If we have different instances we would like the monotonic time to represent the length of time since the same unspecified point in time.

sunfishcode commented 1 year ago

Are your instances running inside the same store, or are they in different stores?

Also, are you relying on the clocks being in sync for correctness, or is it just for performance measurements or some other perhaps non-critical activity?

At a high level, this is an interesting question. If two independent components can assume that they're seeing the same monotonic clock without any explicit coordination, that's an implicit contract which breaks virtualization. In practical terms, this would prevent them from running on different machines connected via a network, without some kind of prearranged side channel to coordinate the clocks, for example.

One possible direction to explore here would be APIs for TAI time, which would add monotonic clocks that have a physical-world correspondence, that instances could share just by virtue of occupying the same physical world. Strictly speaking, virtualization doesn't guarantee that two instances have the same physical-world correspondence, but we may be able to find some way to rationalize this.