qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@gmail.com>
To: Anatoly Trosinenko <anatoly.trosinenko@gmail.com>
Cc: qemu-devel <qemu-devel@nongnu.org>, Jim Mussared <jim@groklearning.com>
Subject: Re: [Qemu-devel] Building QEMU for WebAssembly
Date: Tue, 8 Jan 2019 13:34:54 +0000	[thread overview]
Message-ID: <CAJSP0QUTMsB4RfH6v3MeR7P_1bFDVecMeht049QOWLs-LZFzkQ@mail.gmail.com> (raw)
In-Reply-To: <CAE5jQCfLLRyT5fZ24jbFw52wa2d2kfi7B_47cq_sgB=O0=4prA@mail.gmail.com>

On Mon, Jan 7, 2019 at 5:07 PM Anatoly Trosinenko
<anatoly.trosinenko@gmail.com> wrote:
> > Multi-threading is not yet available in WebAssembly.  Hopefully this
> > will change soon because multi-threading and related infrastructure
> > like atomics are used at the core of several areas in QEMU.
>
> Technically, I have managed to serialize the QEMU code to the extent
> that it was successfully running QEMU (v2.4.1 IIRC) with some
> glitches.

Cool :).  Great to hear that you've been looking into this.

> It would be great to have some stub extension points upstreamed, such
> as converting
>
> void *thread_entry_function(void *) {
>     // some initialization
>     while (true) {
>         // do some work
>     }
> }
>
> into separate initialization, work and glue functions, so it would
> behave as previously in the upstream QEMU, but can be textually
> patched by merely fully removing only the **glue** function (or even
> just its invocation) and writing "serializing" somewhere else (but
> that's another story). I am not sure, though, it will not introduce
> any performance issues at all, so it may be worth manually reapplying
> this patch once a year when merging with upstream.

QEMU has relied more and more on multi-threading over time (it's only
natural so we can take advantage of multi-core hosts!).  My hope was
that multi-threaded WebAssembly would land in major browsers soon and
that empscripten would offer pthreads-like APIs.

> > Stack-switching is not supported so QEMU's coroutines won't work.
> > This mostly affects the block layer, which depends heavily on
> > coroutines.
>
> Emscripten has its own coroutines: the old approach was to instrument
> affected code paths so they can be restarted from the middle
> (Asyncify, it generates huge code and is now unsupported) and the new
> one -- Emterpretify, it generates bytecode instead of the affected
> code and runs it in its own interpreter but, after all, what you want
> from hard disk emulated in a browser. ;)

Interesting, I didn't know about that!

> > Self-modifying code is not really supported.  Runtime code generation
> > is possible (if you jump back into Javascript) but it doesn't seem
> > designed for JIT compilers.  This makes TCG difficult.
>
> I had implemented a proof-of-concept TCI-to-Asm.JS JIT that was run
> after several executions of particular Translation Block.
>
> All of the above can be tried here:
> https://atrosinenko.github.io/qemujs-demo/ -- it is an old demo using
> Asm.JS and QEMU 2.4.1.
>
> Now I am completely rewriting this port to make proper implementation
> of WebAssembly backend:
> repo: https://github.com/atrosinenko/qemujs/tree/qemujs-v2
> discussion: https://github.com/WebAssembly/binaryen/issues/1494
>
> The main issues I have faced so far is to properly select functions
> for Emterpretifying and linking the TBs compiled to WASM in the
> efficient way -- both these issues are on the Emscripten side.
>
> Another my concern is the scale of software that can be run inside
> this emulator. When run with -accel tcg, QEMU runs many times slower
> than when run in the KVM mode on Linux. Hardly we can outperform
> native TCG mode in browser on the same hardware (**technically** the
> WASM engine itself can perform some very aggressive optimizations, but
> this looks like some very optimistic assumption).

Yes, performance will be poor.  It would be neat if hardware
virtualization APIs (e.g. KVM) were made available to the WebAssembly
world now that all major OSes (Linux, Windows, Mac) have standard APIs
(KVM, WHPX, Hypervisor.framework).  But it would probably require a
lot of muscle from influential organizations to get that accepted into
the web standards ;-).

Stefan

      reply	other threads:[~2019-01-08 13:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-07 16:36 [Qemu-devel] Building QEMU for WebAssembly Stefan Hajnoczi
2019-01-07 17:07 ` Anatoly Trosinenko
2019-01-08 13:34   ` Stefan Hajnoczi [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAJSP0QUTMsB4RfH6v3MeR7P_1bFDVecMeht049QOWLs-LZFzkQ@mail.gmail.com \
    --to=stefanha@gmail.com \
    --cc=anatoly.trosinenko@gmail.com \
    --cc=jim@groklearning.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).