From patchwork Tue Aug 13 20:23:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 818863 Delivered-To: patch@linaro.org Received: by 2002:adf:cd01:0:b0:367:895a:4699 with SMTP id w1csp432008wrm; Tue, 13 Aug 2024 13:30:59 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUwbJne5E/p5mdyod09bgsYUl3XvrVB18LGXPTc9zUKX1IHgIrYb6Ew6KAcjj0F+Sreqrmc2Bvj7Xl00O4rREg5 X-Google-Smtp-Source: AGHT+IGUGtxzvVVBEyYVDhaXk2Pk7yKS0f6zB0z4fYrUkLGSB/MjYqiyIzfLyp1tsrlbff89RLy7 X-Received: by 2002:a05:6808:144d:b0:3da:a6ce:f046 with SMTP id 5614622812f47-3dd29962ademr669328b6e.38.1723581059043; Tue, 13 Aug 2024 13:30:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1723581059; cv=none; d=google.com; s=arc-20160816; b=cbR+XHGh7I0TX7DFoTp0O0iQDhmY2EtWQVywtU9cU5eFa0GXsDpAojtU5rzgJwBgGN K/3V33WW1VKlbc6GIBvY+udBLQ9XymQIrNI1rjxIXSvqeST780WQ1eX1TvwvlaYsHWvH Lt1HJRKjrPSc6o0OpOdbLeWSprZ+2n9MR2SR6Mp/8TIt54uGhBzn3SjCOVockFcs9BQ5 H7FGWyLryLQ9qpBDBWShvuAwMIH52gYuto2OD7Wf7wTgssf2+iY1DIFzj6Z4MCVw4TY0 8PLAKJRPAFF5RZrYaloZh3INyrgtxZ/aXQwUVrIk5SMtrRVfJXmru2IQhZqchIPGI9Is F5DA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=U/qnItM0U27UVVqG1z6IvgJtaIK4Kvloy70lZ6Kixi0=; fh=Ldnso273692IMU0X0frFRUfKP3dGY55NqM4JNuJFPqQ=; b=cF/5PoFoY2Xk3BNlgtlHQ8B2sUvmixGoSLNOSI350/dT1RwMdTqo6ekym0jRmJ5A1+ O71OOzWzyuOlijig7o34t6M8CNqzJLxqGMslXIBpQXfML3axKG8cVX518voXFKPsMp0C vXSrBjO9fgBWgFjzl56pHM13VxDLYF9SUC7punaCSOKDCNfCIy7H0f4as7fLPNvapZEK YzwAo+keqx9oraq0He3sgwtpYW+bapD6H5B6A1ob0jGQlMOBINf9UCWvrimaQPjYXA8x wn6as2CZ0Cl/GozMRPTLTzC7zahb++Ozh+cUquFPJwOHZSq2P8YHQbFS0ehRJYF4vm8D qVqg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fIJ4SzX1; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-4531c2cace4si92798891cf.725.2024.08.13.13.30.58 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 13 Aug 2024 13:30:59 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fIJ4SzX1; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sdy9y-0008BP-UN; Tue, 13 Aug 2024 16:30:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sdy9t-0007rA-Tm for qemu-devel@nongnu.org; Tue, 13 Aug 2024 16:30:21 -0400 Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sdy9p-0007hO-Sj for qemu-devel@nongnu.org; Tue, 13 Aug 2024 16:30:21 -0400 Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-5af326eddb2so363823a12.1 for ; Tue, 13 Aug 2024 13:30:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1723581010; x=1724185810; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=U/qnItM0U27UVVqG1z6IvgJtaIK4Kvloy70lZ6Kixi0=; b=fIJ4SzX1zihH4tIRKCBshNOqk7omZiJZ20vilw0ItpslrStbGTol7GysE7T8NsKwS9 jNT3EoN1mB1rkMOSyLfx3AGKa+PDYuFIpQ0WaQ27shVdm2fMlT0G404F8y85cjE0kxMM 67XHfnpvZT2k67jM4k2ljJ5jY79ydIh7TkSXG+zZuy5hyvzH80h/ouzdlaX955ibz7az 6m4odo+YZltSbcU2P3MgH3HzCnm6qeR7NgVtjcZbTlMUAuwzpDsUrUNl3b6u7nt1Jz6o cRvX5KZ9Wcz7YC2lgzd8x7ztMAAE5OoQmNGDuo4a5wfy2ShPxetno7MLyqnPt4z0U5C6 8t0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723581010; x=1724185810; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=U/qnItM0U27UVVqG1z6IvgJtaIK4Kvloy70lZ6Kixi0=; b=D81K6Cs/4NV4H6FfFLXiiaBpLolr2nhIZ1ABebYrBaXKmQHZPtxPS34gMytK6FLNXi FJfCd++22Ygjua6R3txz0lrRvV4kZMo2/qYi4FLk1rajQuJOXfVtLmXO1aCZ8TZL1GBh cUKedyXKC0H73rlCI3XlWsZTTDkVmpZoxYz/PbWRFjdAPrCR66+AGKCtXZ8Pv/WfIrLj udlt1kONOx5Rqwk0YKStIRIXZfhcnU58txSJyhwOkOQY8juVQDUaXF7y8krtLe6MYaiv IO4N0sDXAeKY1JQnKvLj1hXnwKCWfbzlkQhjqzMu+uoS30tywhrMuyERLbRXNPgcDMFI eyxQ== X-Gm-Message-State: AOJu0YyXRvxfy7OIupxQzcARual9jRvTCPW/MwDuhuCthAimyJfp9OqP mpxcDKYNqh4g2uYcivyIDHoH63o1cjR7Q34a+XIYD7MC2+itaoawX2lJ2/IXdx4= X-Received: by 2002:a17:907:f729:b0:a7d:c352:c502 with SMTP id a640c23a62f3a-a8362d64c1emr74542666b.30.1723581009952; Tue, 13 Aug 2024 13:30:09 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a80f3fb3581sm95891166b.88.2024.08.13.13.30.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Aug 2024 13:30:09 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 61C4060642; Tue, 13 Aug 2024 21:23:31 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Alistair Francis , Michael Roth , Palmer Dabbelt , Mahmoud Mandour , Pavel Dovgalyuk , Yoshinori Sato , Weiwei Li , Eduardo Habkost , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Markus Armbruster , David Hildenbrand , Beraldo Leal , Liu Zhiwei , Eric Auger , Song Gao , =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-arm@nongnu.org, Peter Xu , Jiri Pirko , Eric Blake , Fabiano Rosas , qemu-s390x@nongnu.org, Peter Maydell , "Michael S. Tsirkin" , Daniel Henrique Barboza , John Snow , Alexandre Iooss , Konstantin Kostiuk , Pierrick Bouvier , Cleber Rosa , Ilya Leoshkevich , qemu-riscv@nongnu.org, Thomas Huth , Paolo Bonzini , Richard Henderson , Jason Wang , Bin Meng , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Wainer dos Santos Moschetta Subject: [PATCH v2 20/21] docs/devel: update tcg-plugins page Date: Tue, 13 Aug 2024 21:23:28 +0100 Message-Id: <20240813202329.1237572-21-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240813202329.1237572-1-alex.bennee@linaro.org> References: <20240813202329.1237572-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::52c; envelope-from=alex.bennee@linaro.org; helo=mail-ed1-x52c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Pierrick Bouvier Reflect recent changes on API (inline ops) and new plugins. Signed-off-by: Pierrick Bouvier Message-Id: <20240812231945.169310-1-pierrick.bouvier@linaro.org> Signed-off-by: Alex Bennée --- docs/about/emulation.rst | 49 ++++++++++++++++++++++++++++++++------ docs/devel/tcg-plugins.rst | 13 ++++++---- 2 files changed, 50 insertions(+), 12 deletions(-) diff --git a/docs/about/emulation.rst b/docs/about/emulation.rst index c03033e4e9..eea1261baa 100644 --- a/docs/about/emulation.rst +++ b/docs/about/emulation.rst @@ -207,8 +207,8 @@ Once built a program can be run with multiple plugins loaded each with their own arguments:: $QEMU $OTHER_QEMU_ARGS \ - -plugin contrib/plugin/libhowvec.so,inline=on,count=hint \ - -plugin contrib/plugin/libhotblocks.so + -plugin contrib/plugins/libhowvec.so,inline=on,count=hint \ + -plugin contrib/plugins/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 @@ -219,6 +219,14 @@ Linux user-mode emulation also evaluates the environment variable QEMU_PLUGIN="file=contrib/plugins/libhowvec.so,inline=on,count=hint" $QEMU +QEMU plugins avoid to write directly to stdin/stderr, and use the log provided +by the API (see function ``qemu_plugin_outs``). +To show output, you may use this additional parameter:: + + $QEMU $OTHER_QEMU_ARGS \ + -d plugin \ + -plugin contrib/plugins/libhowvec.so,inline=on,count=hint + Example Plugins ~~~~~~~~~~~~~~~ @@ -260,8 +268,7 @@ Behaviour can be tweaked with the following arguments: * - Option - Description * - inline=true|false - - Use faster inline addition of a single counter. Not per-cpu and not - thread safe. + - Use faster inline addition of a single counter. * - idle=true|false - Dump the current execution stats whenever the guest vCPU idles @@ -381,6 +388,15 @@ run:: 160 1 0 135 1 0 +Test inline operations +...................... + +``tests/plugins/inline.c`` + +This plugin is used for testing all inline operations, conditional callbacks and +scoreboard. It prints a per-cpu summary of all events. + + Hot Blocks .......... @@ -394,9 +410,6 @@ with linux-user execution as system emulation tends to generate re-translations as blocks from different programs get swapped in and out of system memory. -If your program is single-threaded you can use the ``inline`` option for -slightly faster (but not thread safe) counters. - Example:: $ qemu-aarch64 \ @@ -736,6 +749,28 @@ The plugin will log the reason of exit, for example:: 0xd4 reached, exiting +Limit instructions per second +............................. + +This plugin can limit the number of Instructions Per Second that are executed:: + + # get number of instructions + $ num_insn=$(./build/qemu-x86_64 -plugin ./build/tests/plugin/libinsn.so -d plugin /bin/true |& grep total | sed -e 's/.*: //') + # limit speed to execute in 10 seconds + $ time ./build/qemu-x86_64 -plugin ./build/contrib/plugins/libips.so,ips=$(($num_insn/10)) /bin/true + real 10.000s + + +.. list-table:: IPS arguments + :widths: 20 80 + :header-rows: 1 + + * - Option + - Description + * - ips=N + - Maximum number of instructions per cpu that can be executed in one second. + The plugin will sleep when the given number of instructions is reached. + Other emulation features ------------------------ diff --git a/docs/devel/tcg-plugins.rst b/docs/devel/tcg-plugins.rst index d8725c2854..9463692c41 100644 --- a/docs/devel/tcg-plugins.rst +++ b/docs/devel/tcg-plugins.rst @@ -61,11 +61,14 @@ 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. +There is also a facility to add inline instructions doing various operations, +like adding or storing an immediate value. It is also possible to execute a +callback conditionally, with condition being evaluated inline. All those inline +operations are associated to a ``scoreboard``, which is a thread-local storage +automatically expanded when new cores/threads are created and that can be +accessed/modified in a thread-safe way without any lock needed. Combining inline +operations and conditional callbacks offer a more efficient way to instrument +binaries, compared to classic callbacks. Finally when QEMU exits all the registered *atexit* callbacks are invoked.