-
Notifications
You must be signed in to change notification settings - Fork 576
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
Implementation for the wasi_clock_time/res #2637
Conversation
core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c
Outdated
Show resolved
Hide resolved
beb4921
to
dbd8f53
Compare
@@ -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); |
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.
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); |
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'm actually wondering if we should move those two declarations to platform_api_extension.h
file.
dbd8f53
to
ffaf3d6
Compare
*resolution = convert_timespec(&ts); | ||
return 0; | ||
#endif | ||
return __WASI_ESUCCESS; | ||
} | ||
|
||
__wasi_errno_t | ||
wasmtime_ssp_clock_time_get(__wasi_clockid_t clock_id, |
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.
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?
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 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?
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.
Agree, I think the PR is in a good state to merge now and we can simplify the code later once #2585 is merged.
d1b4d12
to
cc86166
Compare
@wenyongh would you be able to have a look at this PR? |
core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c
Outdated
Show resolved
Hide resolved
core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c
Outdated
Show resolved
Hide resolved
core/shared/utils/bh_time.c
Outdated
#include "bh_time.h" | ||
|
||
uint64 | ||
convert_timespec_to_nanoseconds(const struct timespec *ts) |
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.
How about renaming to bh_timespec_to_nanoseconds? Adding bh_ prefix is because that APIs in core/shared/utils usually start with it.
105abc9
to
bf15d84
Compare
33b4b61
to
e1aacc0
Compare
{ | ||
} |
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.
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, |
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.
Should be placeholder
*/ | ||
bool | ||
wasi_clockid_to_clockid(__wasi_clockid_t in, clockid_t* out) | ||
{ |
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.
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; | ||
} | ||
|
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.
Had better remove unused line?
e1aacc0
to
0408808
Compare
core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c
Outdated
Show resolved
Hide resolved
db4fa6c
to
04820c0
Compare
core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c
Outdated
Show resolved
Hide resolved
core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c
Outdated
Show resolved
Hide resolved
04820c0
to
884de74
Compare
884de74
to
330fda5
Compare
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.
LGTM
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.
LGTM
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.
Good job!
a874bf0
into
bytecodealliance:dev/wasi-libc-windows
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.
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.
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.
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.
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.
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.
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.
Refactoring the clock functions to use WASI types so we can simplify the code and remove some unnecessary boilerplate. See #2637 (comment) for details.
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.
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.
No description provided.