All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: qemu-devel@nongnu.org
Cc: robert.foley@futurewei.com,
	"Richard Henderson" <richard.henderson@linaro.org>,
	peter.puhov@futurewei.com, aaron@os.amperecomputing.com,
	cota@braap.org, "Alex Bennée" <alex.bennee@linaro.org>
Subject: [PATCH  v5 05/55] docs/devel: add plugins.rst design document
Date: Mon, 14 Oct 2019 11:48:58 +0100	[thread overview]
Message-ID: <20191014104948.4291-6-alex.bennee@linaro.org> (raw)
In-Reply-To: <20191014104948.4291-1-alex.bennee@linaro.org>

This is mostly extracted from Emilio's more verbose commit comments
with some additional verbiage from me.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
v4
  - some rewording and tweaks
  - made non-atomicity of inline ops more explicit
  - expanded description of plugin unload
v5
  - more explicit statements:
    - cannot modify system state, only observer
    - call to action to upstream plugins
---
 docs/devel/index.rst   |   1 +
 docs/devel/plugins.rst | 112 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 113 insertions(+)
 create mode 100644 docs/devel/plugins.rst

diff --git a/docs/devel/index.rst b/docs/devel/index.rst
index 1ec61fcfed..2ff058bae3 100644
--- a/docs/devel/index.rst
+++ b/docs/devel/index.rst
@@ -22,3 +22,4 @@ Contents:
    decodetree
    secure-coding-practices
    tcg
+   plugins
diff --git a/docs/devel/plugins.rst b/docs/devel/plugins.rst
new file mode 100644
index 0000000000..b18fb6729e
--- /dev/null
+++ b/docs/devel/plugins.rst
@@ -0,0 +1,112 @@
+..
+   Copyright (C) 2017, Emilio G. Cota <cota@braap.org>
+   Copyright (c) 2019, Linaro Limited
+   Written by Emilio Cota and Alex Bennée
+
+================
+QEMU TCG Plugins
+================
+
+QEMU TCG plugins provide a way for users to run experiments taking
+advantage of the total system control emulation can have over a guest.
+It provides a mechanism for plugins to subscribe to events during
+translation and execution and optionally callback into the plugin
+during these events. TCG plugins are unable to change the system state
+only monitor it passively. However they can do this down to an
+individual instruction granularity including potentially subscribing
+to all load and store operations.
+
+API Stability
+=============
+
+This is a new feature for QEMU and it does allow people to develop
+out-of-tree plugins that can be dynamically linked into a running QEMU
+process. However the project reserves the right to change or break the
+API should it need to do so. The best way to avoid this is to submit
+your plugin upstream so they can be updated if/when the API changes.
+
+
+Exposure of QEMU internals
+--------------------------
+
+The plugin architecture actively avoids leaking implementation details
+about how QEMU's translation works to the plugins. While there are
+conceptions such as translation time and translation blocks the
+details are opaque to plugins. The plugin is able to query select
+details of instructions and system configuration only through the
+exported *qemu_plugin* functions. The types used to describe
+instructions and events are opaque to the plugins themselves.
+
+Usage
+=====
+
+The QEMU binary needs to be compiled for plugin support:
+
+::
+    configure --enable-plugins
+
+Once built a program can be run with multiple plugins loaded each with
+their own arguments:
+
+::
+    $QEMU $OTHER_QEMU_ARGS \
+      -plugin tests/plugin/libhowvec.so,arg=inline,arg=hint \
+      -plugin tests/plugin/libhotblocks.so
+
+Arguments are plugin specific and can be used to modify their
+behaviour. In this case the howvec plugin is being asked to use inline
+ops to count and break down the hint instructions by type.
+
+Plugin Life cycle
+=================
+
+First the plugin is loaded and the public qemu_plugin_install function
+is called. The plugin will then register callbacks for various plugin
+events. Generally plugins will register a handler for the *atexit*
+if they want to dump a summary of collected information once the
+program/system has finished running.
+
+When a registered event occurs the plugin callback is invoked. The
+callbacks may provide additional information. In the case of a
+translation event the plugin has an option to enumerate the
+instructions in a block of instructions and optionally register
+callbacks to some or all instructions when they are executed.
+
+There is also a facility to add an inline event where code to
+increment a counter can be directly inlined with the translation.
+Currently only a simple increment is supported. This is not atomic so
+can miss counts. If you want absolute precision you should use a
+callback which can then ensure atomicity itself.
+
+Finally when QEMU exits all the registered *atexit* callbacks are
+invoked.
+
+Internals
+=========
+
+Locking
+-------
+
+We have to ensure we cannot deadlock, particularly under MTTCG. For
+this we acquire a lock when called from plugin code. We also keep the
+list of callbacks under RCU so that we do not have to hold the lock
+when calling the callbacks. This is also for performance, since some
+callbacks (e.g. memory access callbacks) might be called very
+frequently.
+
+  * A consequence of this is that we keep our own list of CPUs, so that
+    we do not have to worry about locking order wrt cpu_list_lock.
+  * Use a recursive lock, since we can get registration calls from
+    callbacks.
+
+As a result registering/unregistering callbacks is "slow", since it
+takes a lock. But this is very infrequent; we want performance when
+calling (or not calling) callbacks, not when registering them. Using
+RCU is great for this.
+
+We support the uninstallation of a plugin at any time (e.g. from
+plugin callbacks). This allows plugins to remove themselves if they no
+longer want to instrument the code. This operation is asynchronous
+which means callbacks may still occur after the uninstall operation is
+requested. The plugin isn't completely uninstalled until the safe work
+has executed while all vCPUs are quiescent.
-- 
2.20.1



  parent reply	other threads:[~2019-10-14 10:55 UTC|newest]

Thread overview: 94+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-14 10:48 [PATCH for 4.2 v5 00/55] Support for TCG plugins Alex Bennée
2019-10-14 10:48 ` [PATCH v5 01/55] trace: expand mem_info:size_shift to 4 bits Alex Bennée
2019-10-14 14:35   ` Richard Henderson
2019-10-14 10:48 ` [PATCH v5 02/55] trace: add mmu_index to mem_info Alex Bennée
2019-10-14 14:53   ` Richard Henderson
2019-10-15 11:15     ` Alex Bennée
2019-10-14 10:48 ` [PATCH v5 03/55] cpu: introduce cpu_in_exclusive_context() Alex Bennée
2019-10-14 10:48 ` [PATCH v5 04/55] translate-all: use cpu_in_exclusive_work_context() in tb_flush Alex Bennée
2019-10-14 10:48 ` Alex Bennée [this message]
2019-10-14 10:48 ` [PATCH v5 06/55] configure: add --enable-plugins (MOVE TO END) Alex Bennée
2019-10-14 10:49 ` [PATCH v5 07/55] plugin: add user-facing API Alex Bennée
2019-10-14 10:49 ` [PATCH v5 08/55] plugin: add core code Alex Bennée
2019-10-14 10:49 ` [PATCH v5 09/55] plugin: add implementation of the api Alex Bennée
2019-10-14 10:49 ` [PATCH v5 10/55] queue: add QTAILQ_REMOVE_SEVERAL Alex Bennée
2019-10-14 10:49 ` [PATCH v5 11/55] cputlb: document get_page_addr_code Alex Bennée
2019-10-14 10:49 ` [PATCH v5 12/55] cputlb: introduce get_page_addr_code_hostp Alex Bennée
2019-10-14 10:49 ` [PATCH v5 13/55] tcg: add tcg_gen_st_ptr Alex Bennée
2019-10-14 10:49 ` [PATCH v5 14/55] plugin-gen: add module for TCG-related code Alex Bennée
2019-10-14 15:23   ` Richard Henderson
2019-10-14 10:49 ` [PATCH v5 15/55] atomic_template: add inline trace/plugin helpers Alex Bennée
2019-10-14 10:49 ` [PATCH v5 16/55] tcg: let plugins instrument virtual memory accesses Alex Bennée
2019-10-14 10:49 ` [PATCH v5 17/55] plugins: implement helpers for resolving hwaddr Alex Bennée
2019-10-14 15:45   ` Richard Henderson
2019-10-14 15:54   ` Peter Maydell
2019-10-14 16:34     ` Alex Bennée
2019-10-14 16:56       ` Peter Maydell
2019-10-14 10:49 ` [PATCH v5 18/55] translate-all: notify plugin code of tb_flush Alex Bennée
2019-10-14 10:49 ` [PATCH v5 19/55] *-user: notify plugin of exit Alex Bennée
2019-10-14 10:49 ` [PATCH v5 20/55] *-user: plugin syscalls Alex Bennée
2019-10-14 10:49 ` [PATCH v5 21/55] cpu: hook plugin vcpu events Alex Bennée
2019-10-14 10:49 ` [PATCH v5 22/55] plugin-gen: add plugin_insn_append Alex Bennée
2019-10-14 10:49 ` [PATCH v5 23/55] translator: add translator_ld{ub,sw,uw,l,q} Alex Bennée
2019-10-14 16:08   ` Richard Henderson
2019-10-14 17:31   ` Peter Maydell
2019-10-15 18:55     ` Alex Bennée
2019-10-15 21:34       ` Alex Bennée
2019-10-15 19:03     ` Alex Bennée
2019-10-14 10:49 ` [PATCH v5 24/55] target/arm: fetch code with translator_ld Alex Bennée
2019-10-14 10:49 ` [PATCH v5 25/55] target/ppc: " Alex Bennée
2019-10-14 10:49 ` [PATCH v5 26/55] target/sh4: " Alex Bennée
2019-10-14 10:49 ` [PATCH v5 27/55] target/i386: " Alex Bennée
2019-10-14 10:49 ` [PATCH v5 28/55] target/hppa: " Alex Bennée
2019-10-14 10:49 ` [PATCH v5 29/55] target/m68k: " Alex Bennée
2019-10-14 10:49 ` [PATCH v5 30/55] target/alpha: " Alex Bennée
2019-10-14 10:49 ` [PATCH v5 31/55] target/riscv: " Alex Bennée
2019-10-14 10:49   ` Alex Bennée
2019-10-14 17:59   ` Alistair Francis
2019-10-14 17:59     ` Alistair Francis
2019-10-18 18:32     ` Palmer Dabbelt
2019-10-18 18:32       ` Palmer Dabbelt
2019-10-14 10:49 ` [PATCH v5 32/55] target/sparc: " Alex Bennée
2019-10-14 10:49 ` [PATCH v5 33/55] target/xtensa: " Alex Bennée
2019-10-14 10:49 ` [PATCH v5 34/55] target/openrisc: " Alex Bennée
2019-10-14 10:49 ` [PATCH v5 35/55] translator: inject instrumentation from plugins Alex Bennée
2019-10-14 10:49 ` [PATCH v5 36/55] plugin: add API symbols to qemu-plugins.symbols Alex Bennée
2019-10-14 16:13   ` Richard Henderson
2019-10-14 10:49 ` [PATCH v5 37/55] vl: support -plugin option Alex Bennée
2019-10-14 10:49 ` [PATCH v5 38/55] linux-user: " Alex Bennée
2019-10-14 10:49 ` [PATCH v5 39/55] tests/plugin: add sample plugins Alex Bennée
2019-10-14 16:14   ` Richard Henderson
2019-10-14 10:49 ` [PATCH v5 40/55] tests/tcg/Makefile.target: fix path to config-host.mak Alex Bennée
2019-10-14 16:15   ` Richard Henderson
2019-10-14 10:49 ` [PATCH v5 41/55] tests/tcg: set QEMU_OPTS for all cris runs Alex Bennée
2019-10-14 16:16   ` Richard Henderson
2019-10-14 10:49 ` [PATCH v5 42/55] tests/tcg: move "virtual" tests to EXTRA_TESTS Alex Bennée
2019-10-14 16:16   ` Richard Henderson
2019-10-14 10:49 ` [PATCH v5 43/55] tests/tcg: drop test-i386-fprem from TESTS when not SLOW Alex Bennée
2019-10-14 16:44   ` Richard Henderson
2019-10-14 10:49 ` [PATCH v5 44/55] tests/tcg: enable plugin testing Alex Bennée
2019-10-14 16:46   ` Richard Henderson
2019-10-14 10:49 ` [PATCH v5 45/55] tests/plugin: add a hotblocks plugin Alex Bennée
2019-10-14 16:49   ` Richard Henderson
2019-10-14 10:49 ` [PATCH v5 46/55] plugin: add qemu_plugin_insn_disas helper Alex Bennée
2019-10-14 10:49 ` [PATCH v5 47/55] tests/plugin: add instruction execution breakdown Alex Bennée
2019-10-14 16:50   ` Richard Henderson
2019-10-14 10:49 ` [PATCH v5 48/55] tests/plugin: add hotpages plugin to breakdown memory access patterns Alex Bennée
2019-10-14 16:51   ` Richard Henderson
2019-10-14 10:49 ` [PATCH v5 49/55] accel/stubs: reduce headers from tcg-stub Alex Bennée
2019-10-14 10:49 ` [PATCH v5 50/55] include/exec: wrap cpu_ldst.h in CONFIG_TCG Alex Bennée
2019-10-14 10:49 ` [PATCH v5 51/55] plugins: expand the plugin_init function to include an info block Alex Bennée
2019-10-14 16:54   ` Richard Henderson
2019-10-14 10:49 ` [PATCH v5 52/55] plugins: make howvec plugin more generic Alex Bennée
2019-10-14 16:59   ` Richard Henderson
2019-10-14 17:14     ` Alex Bennée
2019-10-14 17:39       ` Richard Henderson
2019-10-14 10:49 ` [PATCH v5 53/55] plugins: add sparc64 instruction classification table Alex Bennée
2019-10-14 17:01   ` Richard Henderson
2019-10-15 19:09     ` Alex Bennée
2019-10-15 19:37       ` Richard Henderson
2019-10-14 10:49 ` [PATCH v5 54/55] plugins: add qemu_plugin_outs and use it Alex Bennée
2019-10-14 17:03   ` Richard Henderson
2019-10-14 10:49 ` [PATCH v5 55/55] .travis.yml: add --enable-plugins tests Alex Bennée
2019-10-14 17:04   ` Richard Henderson
2019-10-15  4:36 ` [PATCH for 4.2 v5 00/55] Support for TCG plugins no-reply

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=20191014104948.4291-6-alex.bennee@linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=aaron@os.amperecomputing.com \
    --cc=cota@braap.org \
    --cc=peter.puhov@futurewei.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=robert.foley@futurewei.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.