Stream: git-wasmtime

Topic: wasmtime / issue #7419 Clock print error ?


view this post on Zulip Wasmtime GitHub notifications bot (Oct 31 2023 at 12:53):

orangeC23 added the bug label to Issue #7419.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 31 2023 at 12:53):

orangeC23 opened issue #7419:

Steps to Reproduce

(1) The cfile is :

#define _POSIX_C_SOURCE 199309L

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int clock_time_get(clockid_t clock_id) {
    struct timespec tp;

    if (clock_gettime(clock_id, &tp) == 0) {
        printf("Successfully get the clock time.\n");
        printf("seconds: %ld\n", tp.tv_sec);
        printf("nano seconds: %ld\n", tp.tv_nsec);
    } else {
        perror("Failed to get the clock time.\n");
        return 1;
    }

    return 0;
}

int clock_time_geto2Ei6c4mXI (){
    clockid_t clock_id = CLOCK_MONOTONIC;
    return clock_time_get(clock_id);
}

int main() {
    clock_time_geto2Ei6c4mXI ();
}

(2)compile the c file into wasm: ./wasi-sdk-16.0/bin/clang --target=wasm32-unkown-wasi --sysroot=./wasi-sdk-16.0/share/wasi-sysroot clock.c -o clock.wasm
(3)exeute clock.wasm
wasmtime run clock.wasm

Expected Results

Using gcc clock.c -o clock and ./clock to execute get the following result:

Successfully get the clock time.
seconds: 17709947
nano seconds: 519650825

And wamr, wasmedge,wasmer also print the above message.

Actual Results

wasmtime prints:

Successfully get the clock time.
seconds: 0
nano seconds: 1053984

wasmtime print the seconds is zero ? I'm not sure whether this is a bug.
Sorry for bothering you. Thanks a lot !

Versions and Environment

wasmtime 13.0.0
Operating system: Ubuntu 20.04

Architecture: x86_64

view this post on Zulip Wasmtime GitHub notifications bot (Oct 31 2023 at 13:25):

bjorn3 commented on issue #7419:

https://github.com/bytecodealliance/wasmtime/blob/2f83f97c9f4f7f98750eb2be19a336339da931e2/crates/wasi-common/src/snapshots/preview_1.rs#L97-L100 It is supposed to work at least. Not sure what the issue is here.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 31 2023 at 15:20):

alexcrichton closed issue #7419:

Steps to Reproduce

(1) The cfile is :

#define _POSIX_C_SOURCE 199309L

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int clock_time_get(clockid_t clock_id) {
    struct timespec tp;

    if (clock_gettime(clock_id, &tp) == 0) {
        printf("Successfully get the clock time.\n");
        printf("seconds: %ld\n", tp.tv_sec);
        printf("nano seconds: %ld\n", tp.tv_nsec);
    } else {
        perror("Failed to get the clock time.\n");
        return 1;
    }

    return 0;
}

int clock_time_geto2Ei6c4mXI (){
    clockid_t clock_id = CLOCK_MONOTONIC;
    return clock_time_get(clock_id);
}

int main() {
    clock_time_geto2Ei6c4mXI ();
}

(2)compile the c file into wasm: ./wasi-sdk-16.0/bin/clang --target=wasm32-unkown-wasi --sysroot=./wasi-sdk-16.0/share/wasi-sysroot clock.c -o clock.wasm
(3)exeute clock.wasm
wasmtime run clock.wasm

Expected Results

Using gcc clock.c -o clock and ./clock to execute get the following result:

Successfully get the clock time.
seconds: 17709947
nano seconds: 519650825

And wamr, wasmedge,wasmer also print the above message.

Actual Results

wasmtime prints:

Successfully get the clock time.
seconds: 0
nano seconds: 1053984

wasmtime print the seconds is zero ? I'm not sure whether this is a bug.
Sorry for bothering you. Thanks a lot !

Versions and Environment

wasmtime 13.0.0
Operating system: Ubuntu 20.04

Architecture: x86_64

view this post on Zulip Wasmtime GitHub notifications bot (Oct 31 2023 at 15:20):

alexcrichton commented on issue #7419:

The monotonic clock is relative to an arbitrary point in time, and Wasmtime's arbitrary point is the start of the instance itself, so what's happening here is the time is being measured shortly after the instance starts. This is to avoid leaking information about the host's own clocks to the guest which doesn't need to know that information by default.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 31 2023 at 16:26):

alexcrichton commented on issue #7419:

@orangeC23 is there perhaps something we can help you out with at a higher level? You've opened a number of issues here which appear to be mostly poking at WASI behavior. Is there a way we could perhaps help out with that and/or help steer? I'm curious how these programs are coming into existence for example and if it might be good to file issues for clarifications/etc on the WASI specifications themselves for example.


Last updated: Nov 22 2024 at 16:03 UTC