Skip to content
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

Implementation for the wasi_clock_time/res #2637

Conversation

fadumina1
Copy link
Contributor

No description provided.

core/shared/platform/windows/win_clock.c Show resolved Hide resolved
core/shared/platform/windows/win_clock.c Outdated Show resolved Hide resolved
core/shared/platform/windows/win_clock.c Outdated Show resolved Hide resolved
core/shared/platform/windows/win_clock.c Outdated Show resolved Hide resolved
@fadumina1 fadumina1 force-pushed the dev/wasi-libc-windows branch 3 times, most recently from beb4921 to dbd8f53 Compare October 17, 2023 09:19
@@ -66,6 +66,14 @@ os_vprintf(const char *format, va_list ap);
uint64
os_time_get_boot_microsecond(void);

/* Get current resolution of clock id */
int
os_clock_res_get(bh_clock_id_t clock_id, uint64 *resolution);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we already have the declaration in platform_common.h so the declaration should probably be removed from this file.

* @return BHT_OK if success; otherwise, BHT_ERROR
*/
int
os_clock_res_get(bh_clock_id_t clock_id, uint64 *resolution);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually wondering if we should move those two declarations to platform_api_extension.h file.

core/shared/platform/windows/win_clock.c Outdated Show resolved Hide resolved
core/shared/platform/windows/win_clock.c Outdated Show resolved Hide resolved
core/shared/platform/windows/win_clock.c Outdated Show resolved Hide resolved
core/shared/platform/windows/win_clock.c Outdated Show resolved Hide resolved
product-mini/platforms/windows/CMakeLists.txt Outdated Show resolved Hide resolved
*resolution = convert_timespec(&ts);
return 0;
#endif
return __WASI_ESUCCESS;
}

__wasi_errno_t
wasmtime_ssp_clock_time_get(__wasi_clockid_t clock_id,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late comment, did we consider implementing these functions (wasmtime_ssp_clock_time_get and wasmtime_ssp_clock_res_get) directly in each platform? Unlike the filesystem or socket functions, they don't contain any logic to lookup a fd object from the fd table so it seems they are very small wrapper around the platform implementation anyway.

Also, since os_clock_time_get and os_clock_res_get are only used in the WASI libc implementation, we could probably define the signature for these functions in terms of WASI types (__wasi_clockid_t etc.) to avoid some boilerplate. What do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's not been done mainly due to the circular dependency as discussed in #2585 (comment)

I think we can merge this as it is now, but once your change @zoraaver is merged, we'll make an update to this code and simplify it if possible. How does it sound to you?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, I think the PR is in a good state to merge now and we can simplify the code later once #2585 is merged.

@fadumina1 fadumina1 force-pushed the dev/wasi-libc-windows branch 2 times, most recently from d1b4d12 to cc86166 Compare October 18, 2023 10:27
@loganek
Copy link
Collaborator

loganek commented Oct 18, 2023

@wenyongh would you be able to have a look at this PR?

core/shared/platform/common/posix/posix_clock.c Outdated Show resolved Hide resolved
#include "bh_time.h"

uint64
convert_timespec_to_nanoseconds(const struct timespec *ts)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about renaming to bh_timespec_to_nanoseconds? Adding bh_ prefix is because that APIs in core/shared/utils usually start with it.

@fadumina1 fadumina1 force-pushed the dev/wasi-libc-windows branch 6 times, most recently from 105abc9 to bf15d84 Compare October 19, 2023 10:27
@fadumina1 fadumina1 force-pushed the dev/wasi-libc-windows branch 2 times, most recently from 33b4b61 to e1aacc0 Compare October 19, 2023 10:59
Comment on lines 3639 to 3663
{
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not change the code here. It will lead to CI code guideline check failure.

@@ -172,6 +172,38 @@ convert_errno(int error)
#undef X
return code;
}
#ifndef BH_PLATFORM_WINDOWS
/*
* wasi_clockid_to_clockid is a plceholder in this file so that poll_oneoff complies,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be placeholder

*/
bool
wasi_clockid_to_clockid(__wasi_clockid_t in, clockid_t* out)
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invalid coding style, could you use clang-format-12 to format the code?
https://github.com/bytecodealliance/wasm-micro-runtime/actions/runs/6573605221/job/17856981299

*out_counter = counter.QuadPart;
return BHT_OK;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had better remove unused line?

core/shared/platform/windows/win_clock.c Show resolved Hide resolved
core/shared/platform/windows/win_clock.c Show resolved Hide resolved
core/shared/platform/windows/win_clock.c Outdated Show resolved Hide resolved
core/shared/platform/windows/win_clock.c Outdated Show resolved Hide resolved
core/shared/platform/common/posix/posix_clock.c Outdated Show resolved Hide resolved
core/shared/platform/common/posix/posix_clock.c Outdated Show resolved Hide resolved
core/shared/platform/common/posix/posix_clock.c Outdated Show resolved Hide resolved
core/shared/platform/windows/win_clock.c Outdated Show resolved Hide resolved
core/shared/platform/windows/win_clock.c Outdated Show resolved Hide resolved
Copy link
Contributor

@zoraaver zoraaver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@wenyongh wenyongh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@loganek loganek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job!

@wenyongh wenyongh merged commit a874bf0 into bytecodealliance:dev/wasi-libc-windows Oct 22, 2023
381 checks passed
zoraaver added a commit to zoraaver/wasm-micro-runtime that referenced this pull request Oct 24, 2023
Refactoring the clock functions to use WASI types so we can simplify the
code and remove some unnecessary boilerplate. See
bytecodealliance#2637 (comment)
for details.
zoraaver added a commit to zoraaver/wasm-micro-runtime that referenced this pull request Oct 24, 2023
Refactoring the clock functions to use WASI types so we can simplify the
code and remove some unnecessary boilerplate. See
bytecodealliance#2637 (comment)
for details.
zoraaver added a commit to zoraaver/wasm-micro-runtime that referenced this pull request Oct 24, 2023
Refactoring the clock functions to use WASI types so we can simplify the
code and remove some unnecessary boilerplate. See
bytecodealliance#2637 (comment)
for details.
zoraaver added a commit to zoraaver/wasm-micro-runtime that referenced this pull request Oct 24, 2023
Refactoring the clock functions to use WASI types so we can simplify the
code and remove some unnecessary boilerplate. See
bytecodealliance#2637 (comment)
for details.
zoraaver added a commit to zoraaver/wasm-micro-runtime that referenced this pull request Oct 24, 2023
Refactoring the clock functions to use WASI types so we can simplify the
code and remove some unnecessary boilerplate. See
bytecodealliance#2637 (comment)
for details.
zoraaver added a commit to zoraaver/wasm-micro-runtime that referenced this pull request Oct 25, 2023
Refactoring the clock functions to use WASI types so we can simplify the
code and remove some unnecessary boilerplate. See
bytecodealliance#2637 (comment)
for details.
zoraaver added a commit to zoraaver/wasm-micro-runtime that referenced this pull request Oct 25, 2023
Refactoring the clock functions to use WASI types so we can simplify the
code and remove some unnecessary boilerplate. See
bytecodealliance#2637 (comment)
for details.
wenyongh pushed a commit that referenced this pull request Oct 25, 2023
Refactoring the clock functions to use WASI types so we can simplify the
code and remove some unnecessary boilerplate. See
#2637 (comment)
for details.
victoryang00 pushed a commit to victoryang00/wamr-aot-gc-checkpoint-restore that referenced this pull request May 27, 2024
Add os_clock_res_get and os_clock_time_get in platform_api_extension.h,
and implement them in posix like platforms and windows platform.
victoryang00 pushed a commit to victoryang00/wamr-aot-gc-checkpoint-restore that referenced this pull request May 27, 2024
Refactoring the clock functions to use WASI types so we can simplify the
code and remove some unnecessary boilerplate. See
bytecodealliance#2637 (comment)
for details.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants