Stream: git-wasmtime

Topic: wasmtime / issue #8623 clock time difference?


view this post on Zulip Wasmtime GitHub notifications bot (May 15 2024 at 08:36):

Userzxcvbvnm added the bug label to Issue #8623.

view this post on Zulip Wasmtime GitHub notifications bot (May 15 2024 at 08:36):

Userzxcvbvnm opened issue #8623:

Test Case

The c program is as follows:

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

void clock_time_get_00002_obtwo() {
    printf("Enter function clock_time_get_00002_obtwo\n");

    struct timespec ts;
    if(clock_gettime(CLOCK_MONOTONIC, &ts) == -1) {
        perror("clock_gettime error");
        return;
    }

    printf("Current time: %ld seconds, %ld nanoseconds\n", ts.tv_sec, ts.tv_nsec);
}

int main() {
    printf("Enter function main\n");

    clock_time_get_00002_obtwo();

    return 0;
}

Steps to Reproduce

(1)compiler it into Wasm binaries by ./wasi-sdk-21.0/bin/clang --target=wasm32-unkown-wasi --sysroot=./wasi-sdk-21.0/share/wasi-sysroot test.c -o test.wasm

Expected Results

Print:

Enter function main
Enter function clock_time_get_00002_obtwo
Current time: 2177580 seconds, 0 nanoseconds

And this is what other Wasm runtimes print, including wasmer, wamr and wasmedge.

Actual Results

Print:

Enter function main
Enter function clock_time_get_00002_obtwo
Current time: 0 seconds, 0 nanoseconds

Versions and Environment

Wasmtime version or commit: 19.0.2

Operating system: Ubuntu 20.04

Architecture: amd64

view this post on Zulip Wasmtime GitHub notifications bot (May 15 2024 at 15:07):

alexcrichton closed issue #8623:

Test Case

The c program is as follows:

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

void clock_time_get_00002_obtwo() {
    printf("Enter function clock_time_get_00002_obtwo\n");

    struct timespec ts;
    if(clock_gettime(CLOCK_MONOTONIC, &ts) == -1) {
        perror("clock_gettime error");
        return;
    }

    printf("Current time: %ld seconds, %ld nanoseconds\n", ts.tv_sec, ts.tv_nsec);
}

int main() {
    printf("Enter function main\n");

    clock_time_get_00002_obtwo();

    return 0;
}

Steps to Reproduce

(1)compiler it into Wasm binaries by ./wasi-sdk-21.0/bin/clang --target=wasm32-unkown-wasi --sysroot=./wasi-sdk-21.0/share/wasi-sysroot test.c -o test.wasm

Expected Results

Print:

Enter function main
Enter function clock_time_get_00002_obtwo
Current time: 2177580 seconds, 0 nanoseconds

And this is what other Wasm runtimes print, including wasmer, wamr and wasmedge.

Actual Results

Print:

Enter function main
Enter function clock_time_get_00002_obtwo
Current time: 0 seconds, 0 nanoseconds

Versions and Environment

Wasmtime version or commit: 19.0.2

Operating system: Ubuntu 20.04

Architecture: amd64

view this post on Zulip Wasmtime GitHub notifications bot (May 15 2024 at 15:07):

alexcrichton commented on issue #8623:

Using wasi-sdk it generates a warning:

foo.c:14:60: warning: format specifies type 'long' but the argument has type 'time_t' (aka 'long long') [-Wformat]
   14 |     printf("Current time: %ld seconds, %ld nanoseconds\n", ts.tv_sec, ts.tv_nsec);
      |                           ~~~                              ^~~~~~~~~
      |                           %lld

which when fixed causes the program to print:

Enter function main
Enter function clock_time_get_00002_obtwo
Current time: 0 seconds, 571458 nanoseconds

which is the expected behavior of Wasmtime. The monotonic clock is relative to an arbitrary point and Wasmtime chooses instance creation as the relative point.


Last updated: Nov 22 2024 at 17:03 UTC