qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v3 00/50] tcg plugin support


From: Alex Bennée
Subject: Re: [Qemu-devel] [PATCH v3 00/50] tcg plugin support
Date: Fri, 21 Jun 2019 09:21:28 +0100
User-agent: mu4e 1.3.2; emacs 26.1

Pranith Kumar <address@hidden> writes:

> Hi Alex/Emilio,
>
> I am really happy to see the progress you made on the plugin feature. Looking
> forward to seeing it merged soon! Please CC me on future versions of the
> patchset. I am happy to help review and contribute to this effort.

Will do.

>
> I have a few general comments from experience writing a very similar system
> (qsim) below.
>
> On Fri, Jun 14, 2019 at 10:23 AM Alex Bennée <address@hidden> wrote:
>>
>> Hi,
>>
>> This is v3 of the proposed plugins API for QEMU. As Emilio is busy
>> having finished his time at Columbia I have volunteered to take the
>> patch series forward. Emilio's RFC v2 was posted last year:
>>
>>   Subject: [RFC v2 00/38] Plugin support
>>   Date: Sun,  9 Dec 2018 14:37:11 -0500
>>   Message-Id: <address@hidden>
>>
>
> * Register and memory read/write API
>
>   It would be great to have register and memory read/write API i.e., ability
>   to read/write to registers/memory from within the callback. This gives the
>   plugin ability to do system introspection. (Not sure if the current patchset
>   implements this already).

Not currently. The trick is to have something flexible enough without
exposing internals. I guess we could consider the gdb register
enumeration or maybe hook into stuff declared as
tcg_global_mem_new_i[64|32]. That won't get every "register" but it
should certainly cover the main general purpose ones. Things like SVE
and AdvSIMD vector registers wouldn't be seen though.

> * Register callbacks
>
>   A callback needs to be invoked whenever a specified registers is read or
>   written to.

Again tricky as not every register read/write is obvious from TCG -
vector registers tweaked from helpers would be a good example.

>
> * Where do new plugins live in the tree?
>
>   The current source files in plugins (api, core etc.,) I think are better if
>   moved to tcg/plugins/.  The various plugins we write would then live in the
>   plugins/ folder instead of the current tests/plugin/ folder.

The example plugins are really just toys for experimenting with the API
- I don't see too much problem with them being in tests. However the
howvec plugin is very guest architecture specific so we could consider a
bit more of a hierarchy. Maybe these should all live in tests/tcg?

>
> * Timer interrupts
>
>   What I observed is that the system execution is affected by what you do in
>   the callbacks because of timer interrupts. For example, if you spend time in
>   the memory callback doing a bit of processing and writing to a file, you
>   will see more timer interrupt instructions. One solution to this would be to
>   use 'icount', but it does not work that well. I think we need to do
>   something similar to what gdb does in debug mode. How would you handle MTTCG
>   guests in that case?

icount is going to be the best you can get for deterministic time -
other efforts to pause/restart virtual time going in and out of plugins
are just going to add a lot of overhead.

Remember QEMU doesn't even try to be a cycle accurate emulation so
expecting to get reasonable timing information out of these plugins is a
stretch. Maybe I should make that clearer in the design document?

The gdb behaviour is just a massive hack. When single-stepping in GDB we
prevent timer IRQs from being delivered - they have still fired and are
pending and will execute as soon as you hit continue.

>   Another approach would be to offload callback generation to a separate
>   plugin thread. The main thread will copy data required by a callback and
>   invoke the callback asynchronously (std::async in C++ if you are
>   familiar).

This would complicate things - the current iteration I'm working on
drops the haddr cb in favour of dynamically resolving the vaddr in the
callback. But that approach is only valid during the callback before
something else potentially pollutes the TLB.

>
> * Starting and stopping callback generation
>
>   It would be great if we have a mechanism to dynamically start/stop callbacks
>   when a sequence of code (magic instruction) is executed. This would be
>   useful to annotate region-of-interest (ROI) in benchmarks to
> generate callbacks.

Well we have that now. At each TB generation event the callback is free to 
register
as many or few callbacks as it likes dynamically.

>
>   Also, the return value from a callback can be used to decide further course
>   of action. For example, if our plugin needs 10000 callbacks, it can indicate
>   to stop generating further callbacks in the return value of the callback
>   once it got the necessary callbacks.

This can be done internally - a plugin can unregister itself once it has
collected everything it wanted. If it wants to hang around you can
qemu_plugin_reset to reset all callbacks.

Do you want something finer grained?

> * State saving API
>
>   An API to save the state of the VM from the plugin code.

This would be tricky for -smp > 1 because other threads will have run on
while you are making your decision. It would certainly be useful for
analyzing failed states though.

>
> Let me know your thoughts and any other ideas you might have.
>
> Thanks,


--
Alex Bennée



reply via email to

[Prev in Thread] Current Thread [Next in Thread]