4 ms·
> Every iteration of the loop polls the network and input drivers, draws the desktop interface, runs one step of each active WASM application, and flushes the G
by herobird 1y ago
> Every iteration of the loop polls the network and input drivers, draws the desktop interface, runs one step of each active WASM application, and flushes the GPU framebuffer.
This is really interesting and I was wondering how you implemented that using Wasmi. Seems like the code for that is here:
https://github.com/Askannz/munal-os/blob/2d3d361f67888cb2fe86ca5728606e012825d393/kernel/src/wasm/mod.rs#L281 https://github.com/Askannz/munal-os/blob/2d3d361f67888cb2fe8...
It might interest you that newer versions of Wasmi (v0.45+) extended the resumable function call feature to make it possible to yield upon running out of fuel:
https://docs.rs/wasmi/latest/wasmi/struct.TypedFunc.html#method.call_resumable https://docs.rs/wasmi/latest/wasmi/struct.TypedFunc.html#met...
Seeing that you are already using Wasmi's fuel metering this might be a more efficient or failure proof approach to execute Wasm apps in steps.
An example for how to do this can be found in Wasmi's own Wast runner:
https://github.com/wasmi-labs/wasmi/blob/019806547aae542d148b6714557c380069773b85/crates/wast/src/lib.rs#L569-L588 https://github.com/wasmi-labs/wasmi/blob/019806547aae542d148...
- 9d 1y agoNot OP, but I'm confused how this would be helpful. You're saying for example, he can use this function to create a coroutine out of a function, begin it, and if the function fails by e.g. running out of memory, you can give the module more memory and then resume the coroutine? If so, how is that different than what naturally happens? Does wasm not have try/catch? Also, wouldn't the module then need to back up manually and retry the malloc after it failed? I'm so lost.
- herobird 1y agoGreat question! Wasmi's fuel metering can be thought of as is there was an adjustable counter and for each instruction that Wasmi executes this counter is decreased by some amount. If it reached 0 the resumable call will yield back to the host (in this case the OS) where it can be decided how to, or if, the call shall be resumed. For efficiency reasons fuel metering in Wasmi is not implemented as described above but I wanted to provide a simple description. With this, one is no longer reliant on clocks or on other measures to provide each call its own time frame by providing an amount of fuel for each Wasm app that can be renewed (or not) when it runs out of fuel. So this is useful for building a Wasm scheduler.
- 9d 1y ago> Great question! Thanks! I have lots more too. Are there directions in space? What kind of matter is fire made of? If you shine a laser into a box with one-way mirrors on the inside, will it reflect forever? Do ants feel like they're going in regular motion and we're just going in slow motion? Why do people mainly marry and make friends with people who look extraordinarily similar to themselves? How do futures work in Rust? Why is the C standard still behind a paywall? Let me know if you need any more great questions.
- lukan 1y ago"If you shine a laser into a box with one-way mirrors on the inside, will it reflect forever?" No, because each reflection comes at a cost (some light transformed to heat) "Why do people mainly marry and make friends with people who look extraordinarily similar to themselves?" To not get so much surprises and have a more stable life. (I didn't choose that path.) (But I feel it would be too much OT answering the other questions and don't want to distract from this great submission or the interesting Wasmi concept)
- 9d 1y agoNo, I do not accept this. There must be a way. What if the mirror box has a high enough heat? Would it work then? The box could be made of a heat resistant material, like fiberglass.
- Bjartr 1y agoIt's not that the mirror or box is damaged by heat, it's that each bit of heat energy comes from a bit of light energy. Eventually the light bounces enough times that there's no energy left in it.
- 9d 1y agoI understand, but what I mean is, what if there is no more opportunity for the light to emit heat, because the surrounding environment is already saturated with so much heat that it can't accept more? Is this a possible way to prevent the light from emitting heat and therefore prevent the light from decreasing its luminousness? There must be a way!
- huem0n 1y ago> Does wasm not have try/catch Not currently. There's an accepted proposal, but its in progress.
- Gazoche 1y agoThanks again for making Wasmi :) > It might interest you that newer versions of Wasmi (v0.45+) extended the resumable function call feature to make it possible to yield upon running out of fuel: That is really interesting! I remember looking for something like that in the Wasmi docs at some point but it must have been before that feature was implemented. I would probably have chosen a different design for the WASM apps if I had it.
- herobird 1y agoI am really sorry I have waited so long to extend Wasmi's resumable calls with this very useful feature. :S Feel free to message me if you ever plan to adjust your design to make use of it.
- Gazoche 1y agoPlease don't take it as a reproach! Not your fault at all, and at least it forced me into creative problem-solving ;)
- apitman 1y agoIt's awesome that Wasmi is fast enough to run GUI apps. I'm working on an app runtime for making highly portable GUI apps. I'm targeting wasm because it seems to strike a good balance between performance and implementation simplicity. Ideally it would be possible to run apps on a runtime hacked together by a small team or even a single person. The fact that an interpreted (if highly optimized) wasm runtime like Wasmi is clearly capable of running GUI apps is exciting.