From nobody Sun Nov 24 11:09:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1723504788; cv=none; d=zohomail.com; s=zohoarc; b=FdQudIPCccgzD/DH0DuM3mZ4ykXpGP+2Cqzfo+FsAvBpQRNMEGnX11NZGJbYW21/53H/pSr0KX64CFuA8a33toSXCIBIncy0bwEJ5f3QPkHnqjKkSMkZ4djhqet6yRIaiD3wwqudnGvT9mbW/cU3Wkubxbdiovtu63BqX+5527Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1723504788; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=XveoTt72Ig0J1NMgFKGkqnotzijPfu5WMeFb68HnIUc=; b=SFVGgRoeNXS8eCsRjE2LaWFouGXNtIXnBQ8WTc0DZH5uvo9UfvFOJNnWEgX7aUzPlDmu0QVrWS55SqDE+gFaJGqwonsdTwnl+WLi+axvSixWVSYCcH/sWwQqu9FR+t62Hq0+1oNNOxKLe6gMHZYhoLrouHbs5KHrZYEV0R+KuOw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1723504788114769.4726473983955; Mon, 12 Aug 2024 16:19:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sdeJK-0000Ey-1v; Mon, 12 Aug 2024 19:18:46 -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 1sdeJI-0000DX-La for qemu-devel@nongnu.org; Mon, 12 Aug 2024 19:18:44 -0400 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sdeJ9-0003tt-VH for qemu-devel@nongnu.org; Mon, 12 Aug 2024 19:18:38 -0400 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1ff67158052so31040845ad.0 for ; Mon, 12 Aug 2024 16:18:35 -0700 (PDT) Received: from linaro.vn.shawcable.net ([2604:3d08:9384:1d00:5b09:8db7:b002:cf61]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-201cd1bd3d6sm1979005ad.236.2024.08.12.16.18.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Aug 2024 16:18:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1723504714; x=1724109514; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=XveoTt72Ig0J1NMgFKGkqnotzijPfu5WMeFb68HnIUc=; b=ACE8AwRZr6fAxl01Qjsq2Nfnv+gg8820jFAFvqJM+CRbtrGwoGPZoTKCrGD/l1b2EB IwoNe+PPdp6Rjt57z5fyivEtbam292SexnlpqbrvQgW5vH9e71s7ABCzbCqjBl7A+xVp VZdvhH2H3YqMLxdetx09RxaZU2VeKsElPxAJ0WRqXnhdxApmYciPsdm+cHtc1QVjKCus PwqsTEhjJ6neBXKLfPMH+S/VamTOVvPvxMvVpIwFzJEow/s582czDXmP0Gn/THXVsj+p f5czEO4sgdY5YnRz+SPxrO5wT+ZUUS7E/bvJRBv1L++Ye6Ty0u86YBKnS1k9aA2ua65X LYVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723504714; x=1724109514; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=XveoTt72Ig0J1NMgFKGkqnotzijPfu5WMeFb68HnIUc=; b=R1p1iq3V9dujRzMAe2zWLhAYjrSuMMF4URb7sf4OcYcxoTW3zbSajVf0aMI4NmPe2p iCfVwLa3LHuw7LgzKK7/skzgfvvQCIweWZomSW9RK+4UDBzwqs7BKKhmN4PIkRHxbgmN tk1Oz0yfmFqVNYTKeoJ6xsdbq8veMOr0sPQnfhtQ1fvnhwrl6/H4oHkc/VwUGyy/nkub wIrcXnAHDIMPdrHllvwGfA6YHpgZsH0DN69jmbWpZmmFj6MQ0gxfu/7nhzbMzEBB2Z0e nJ+6j5wovfbX2CwqJwCTtodLkvh42iXs5SV/UzdS4elU/N76uY0WHxl5blGZnOpqVup6 3gWA== X-Gm-Message-State: AOJu0YzPE99Q4olNWJqIouLLC+7Lz4jFA4O6+XAwivpGNt3Cm+YRvYUe f7p/BWXSFvmOttlibvswRf/TMRsF1Z4tuwLYfc43baTgW+JP0nGhe5OOnM+xOy1OEtd+4/jzvIn 3NFg= X-Google-Smtp-Source: AGHT+IEN+F0DTvFJKpujiF3InFCV85vQFfiJB/23reDFUHrBf3TrF3Tsh3DJyQvojGM5C2rslYxFXw== X-Received: by 2002:a17:902:ccc7:b0:1fa:d1df:d41e with SMTP id d9443c01a7336-201ca1d4959mr23977945ad.58.1723504713931; Mon, 12 Aug 2024 16:18:33 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Richard Henderson , Alexandre Iooss , Pierrick Bouvier , Mahmoud Mandour , Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PATCH v2] Reflect recent changes on API (inline ops) and new plugins. Date: Mon, 12 Aug 2024 16:18:22 -0700 Message-Id: <20240812231822.168034-1-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62b; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pl1-x62b.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=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1723504790715116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pierrick Bouvier --- 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 c03033e4e95..eea1261baac 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 l= oaded each with their own arguments:: =20 $QEMU $OTHER_QEMU_ARGS \ - -plugin contrib/plugin/libhowvec.so,inline=3Don,count=3Dhint \ - -plugin contrib/plugin/libhotblocks.so + -plugin contrib/plugins/libhowvec.so,inline=3Don,count=3Dhint \ + -plugin contrib/plugins/libhotblocks.so =20 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 environme= nt variable =20 QEMU_PLUGIN=3D"file=3Dcontrib/plugins/libhowvec.so,inline=3Don,count=3Dh= int" $QEMU =20 +QEMU plugins avoid to write directly to stdin/stderr, and use the log prov= ided +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=3Don,count=3Dhint + Example Plugins ~~~~~~~~~~~~~~~ =20 @@ -260,8 +268,7 @@ Behaviour can be tweaked with the following arguments: * - Option - Description * - inline=3Dtrue|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=3Dtrue|false - Dump the current execution stats whenever the guest vCPU idles =20 @@ -381,6 +388,15 @@ run:: 160 1 0 135 1 0 =20 +Test inline operations +...................... + +``tests/plugins/inline.c`` + +This plugin is used for testing all inline operations, conditional callbac= ks and +scoreboard. It prints a per-cpu summary of all events. + + Hot Blocks .......... =20 @@ -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. =20 -If your program is single-threaded you can use the ``inline`` option for -slightly faster (but not thread safe) counters. - Example:: =20 $ qemu-aarch64 \ @@ -736,6 +749,28 @@ The plugin will log the reason of exit, for example:: =20 0xd4 reached, exiting =20 +Limit instructions per second +............................. + +This plugin can limit the number of Instructions Per Second that are execu= ted:: + + # get number of instructions + $ num_insn=3D$(./build/qemu-x86_64 -plugin ./build/tests/plugin/libins= n.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,i= ps=3D$(($num_insn/10)) /bin/true + real 10.000s + + +.. list-table:: IPS arguments + :widths: 20 80 + :header-rows: 1 + + * - Option + - Description + * - ips=3DN + - Maximum number of instructions per cpu that can be executed in one s= econd. + The plugin will sleep when the given number of instructions is reach= ed. + Other emulation features ------------------------ =20 diff --git a/docs/devel/tcg-plugins.rst b/docs/devel/tcg-plugins.rst index d8725c2854a..9463692c411 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. =20 -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 operatio= ns, +like adding or storing an immediate value. It is also possible to execute a +callback conditionally, with condition being evaluated inline. All those i= nline +operations are associated to a ``scoreboard``, which is a thread-local sto= rage +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 instrum= ent +binaries, compared to classic callbacks. =20 Finally when QEMU exits all the registered *atexit* callbacks are invoked. --=20 2.39.2