Commit ff639ef
authored
add monotonic clock "pause" feature to p1->p2 adapter (#13563)
This adds a new `adapter_monotonic_clock_set_paused` export to the adapter which
toggles whether `clock_time_get` will call `monotonic_clock::now` when called
with `CLOCKID_MONOTONIC` versus returning a cached value instead.
This is a workaround for guest language runtimes whose `cabi_realloc`
implementations may call `clock_time_get`. Since calling imports from
`cabi_realloc` is disallowed, this will trap if the adapter calls
`monotonic_clock::now`. We can avoid the trap by using a cached value instead.
This helps us address
bytecodealliance/componentize-go#56. In that case,
`cabi_realloc` is implemented by calling
[unsafe.SliceData](https://pkg.go.dev/unsafe#SliceData) to allocate a segment of
the appropriate size and alignment from the GC-managed heap and then pinning it
using [pinner.Pin](https://pkg.go.dev/runtime#Pinner.Pin) until it is no longer
needed. However, such an allocation may trigger a GC under memory pressure, and
as of this writing the Go collector calls `clock_time_get` to measure time spent
in various stages of the GC process.
An alternative fix for the `componentize-go` issue would be to modify the Go
runtime to avoid such calls on WASI during GC, but getting that upstream is
likely to be significantly more difficult than working around it in the adapter.
If and when Go supports WASIp3 or later natively, the adapter will no longer be
used, in which case we will certainly address this upstream.1 parent eb98ce9 commit ff639ef
1 file changed
Lines changed: 58 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
199 | 199 | | |
200 | 200 | | |
201 | 201 | | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
202 | 221 | | |
203 | 222 | | |
204 | 223 | | |
| |||
685 | 704 | | |
686 | 705 | | |
687 | 706 | | |
688 | | - | |
689 | | - | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
690 | 733 | | |
691 | 734 | | |
692 | 735 | | |
| |||
2704 | 2747 | | |
2705 | 2748 | | |
2706 | 2749 | | |
| 2750 | + | |
| 2751 | + | |
| 2752 | + | |
| 2753 | + | |
| 2754 | + | |
| 2755 | + | |
| 2756 | + | |
| 2757 | + | |
| 2758 | + | |
| 2759 | + | |
2707 | 2760 | | |
2708 | 2761 | | |
2709 | 2762 | | |
| |||
2765 | 2818 | | |
2766 | 2819 | | |
2767 | 2820 | | |
2768 | | - | |
| 2821 | + | |
2769 | 2822 | | |
2770 | 2823 | | |
2771 | 2824 | | |
| |||
2882 | 2935 | | |
2883 | 2936 | | |
2884 | 2937 | | |
| 2938 | + | |
| 2939 | + | |
2885 | 2940 | | |
2886 | 2941 | | |
2887 | 2942 | | |
| |||
0 commit comments