From nobody Fri Nov 14 19:35:08 2025 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=1761563282; cv=none; d=zohomail.com; s=zohoarc; b=LX4u/xbf/u74kJtHE0eFmCGVpZOMBbnzeXPKx2xMLB5D63rjfSO1EgWfUNRGSbH25nUkrmW+SmipNXerEGDuVd2jPniE/I0ey11nD3wD1SZasSF5bB9qhkWTAeP6Qr/vDl4HnyawmSoZm/d26BnW7SIIfSCTTLdmIgPCPoAg/BQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761563282; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=FdYYc9UfPJiJOmUk4OWh6nheP5mSB2HOK4r3KtorV48=; b=MTJgPGSQdRSAB6xpmzzeJv5IyT4wOtYJkBvXEWkagH8YN9I2etMTST9hHr1Nx4T1SJtrMbDkZQ8oX1yfyLaaeM2p5arLnPmPRZYZNY4vO31694hMfH//9IfCn1u34vle1LbMxqerkfW0/PGiE/mF8B9UJstwE98ABZrG3BXSIyQ= 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 1761563282683773.1665632450377; Mon, 27 Oct 2025 04:08:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vDL2R-0001gI-9c; Mon, 27 Oct 2025 07:05:23 -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 1vDL2P-0001eq-Ei for qemu-devel@nongnu.org; Mon, 27 Oct 2025 07:05:22 -0400 Received: from mail-ed1-x531.google.com ([2a00:1450:4864:20::531]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vDL1a-0005dn-JI for qemu-devel@nongnu.org; Mon, 27 Oct 2025 07:05:20 -0400 Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-63c31c20b64so7306306a12.1 for ; Mon, 27 Oct 2025 04:03:54 -0700 (PDT) Received: from draig.lan ([185.126.160.19]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-63ecf3686c5sm356035a12.36.2025.10.27.04.03.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Oct 2025 04:03:49 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 13AD460915; Mon, 27 Oct 2025 11:03:45 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1761563032; x=1762167832; 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=FdYYc9UfPJiJOmUk4OWh6nheP5mSB2HOK4r3KtorV48=; b=iizFSWCne8dtm4AE8rAmqRWuFEYhpe7lTw/Fubft+FpBsD35TdVMUjHAkPmqX5LaGV xp/QOmMyPa2lFgTqnxaL7ck6WHWFzw3vbG8KiRcB74UobMCPLe31xWSv2Oj8O+CiS19T lBHluuZc4ZMw0JXGQSNr34koFzqJwtAmSIzKr8HxMu2vZXRSxLkSqWyOkEsFAC+a0nT2 7TgU2OLerF4y6wJ5IcI1ffD/3HsV4yvwJaHXLOQosxyPYH7mMJzWvQ23NnqV3I6RMWYJ x/dulghvbgw2dJgteam8D9pYTaDBdnU9+vIIEv84uM15VjVzrGIte6a5JjNlAtiWKkrF WPtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761563032; x=1762167832; 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=FdYYc9UfPJiJOmUk4OWh6nheP5mSB2HOK4r3KtorV48=; b=YCb+WbWsMkzmaMkLkE636/qf+AUlZV12J64cpsEx5uKLP9K6penEIi+fy25Xt2yhMF BA8e+OdX1hux/U3raDiIsNfy120yLOdo1GIMVTguBBFuKgDtRg4E2pmKuAitivTWScMb uxjMjbvnWpZb/HBelGO6NhMMk0BQVwlpN0z2cNmuNixttY1W0qwGt/kvV2tpEjqh4HMH iidgfjDW90co0fKY1++iDADcc9wjKoIsZa+lp0Xy8TAsFWe8BLhQU0iZ9R7d0sbVpSuA HdaqrNbeBxl3CNsVjKRnQBvY1mw2SBMro5u8qM8CNZ1ev8Ib8IGPI2d25OyGQRfZ9VAB qXJA== X-Gm-Message-State: AOJu0YxS3O6bWFwFFQqH5APL3iATEy0YUspw6g9gNsa+CNbpaD+IoS7D sKY1bRomJaW42aGg47X2TXxSMXl2KztT+rvZb7lh65IEtwALA6qY19D5oblDEkKRxu8= X-Gm-Gg: ASbGncuKB91JRvX7MFASM+UzHxc2NygC0D2ZEnWqSX1CeczeJ1kt70/duaZofwhkaGY 9Kwe332BtDdrT1FxfvdXJ8yBgInUj904Tns7ng7WD/MqBkd7XtrDq106nR6iCkhha53MAPIRkoD sAT128DdcoWKfYA4m1G5OZZ1xpOkw7SXxz0ceG2l1ESnFlf/CEyQpXU8ThRYsLYTAp+ldE9ampl 3zKymYzGynfjd1ThKjMrg7uHpUMYe4iBiJQ8eyu9PYHoVPbf0W5J8H/ziaXNK5MYUslwmPYxUY2 YG0joMD4dOUY+NBUMkNs7Ca7cQkvEo9SL+Pt2AjXufZGX3+hFAFLhh80FsyP57SgjLvwaO6Qozo vhS9driXti3gG/zMZJdGdMc2lQdvU9dramT+RHb4JSegu7KQAtq5lgSJ8iy8daxg7x4kVZADUKc fQTrtDVrJjIVE= X-Google-Smtp-Source: AGHT+IE146XaimMpIxyppkc5SJJoPLUyMmLDLovFokulHH30KUzEQB5Xf7fiUrkKHn734LTDcCF5qA== X-Received: by 2002:a05:6402:51d1:b0:63c:3efe:d996 with SMTP id 4fb4d7f45d1cf-63c3efeee79mr31902705a12.20.1761563032280; Mon, 27 Oct 2025 04:03:52 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Liu Zhiwei , Alexandre Iooss , Chinmay Rath , qemu-arm@nongnu.org, Peter Maydell , Nicholas Piggin , Ilya Leoshkevich , David Hildenbrand , qemu-ppc@nongnu.org, Paolo Bonzini , qemu-s390x@nongnu.org, Pierrick Bouvier , Bastian Koppelmann , Helge Deller , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Stafford Horne , Mahmoud Mandour , Artyom Tarasenko , Eduardo Habkost , Palmer Dabbelt , Alistair Francis , Laurent Vivier , Weiwei Li , Daniel Henrique Barboza , Mark Cave-Ayland , Yoshinori Sato , "Edgar E. Iglesias" , Aurelien Jarno , Richard Henderson , Thomas Huth , Max Filippov , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Jiaxun Yang , Michael Rolnik , Song Gao , qemu-riscv@nongnu.org, Aleksandar Rikalo , Julian Ganz Subject: [PATCH 10/35] contrib/plugins: add plugin showcasing new dicontinuity related API Date: Mon, 27 Oct 2025 11:03:17 +0000 Message-ID: <20251027110344.2289945-11-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251027110344.2289945-1-alex.bennee@linaro.org> References: <20251027110344.2289945-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=2a00:1450:4864:20::531; envelope-from=alex.bennee@linaro.org; helo=mail-ed1-x531.google.com X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 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, NEW_PRODUCTS=1.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: 1761563284044154100 From: Julian Ganz We recently introduced new plugin API for registration of discontinuity related callbacks. This change introduces a minimal plugin showcasing the new API. It simply counts the occurances of interrupts, exceptions and host calls per CPU and reports the counts when exitting. Reviewed-by: Pierrick Bouvier Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Julian Ganz Signed-off-by: Alex Benn=C3=A9e --- docs/about/emulation.rst | 8 ++++ contrib/plugins/traps.c | 83 +++++++++++++++++++++++++++++++++++++ contrib/plugins/meson.build | 2 +- 3 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 contrib/plugins/traps.c diff --git a/docs/about/emulation.rst b/docs/about/emulation.rst index 8a5e128f677..92c219119e8 100644 --- a/docs/about/emulation.rst +++ b/docs/about/emulation.rst @@ -1015,6 +1015,14 @@ interesting to generate them around a particular poi= nt of execution:: # generate trace around init execution (2 seconds): $ uftrace dump --chrome --time-range=3D1753122320~1753122322 > init.js= on =20 +Count traps +........... + +``contrib/plugins/traps.c`` + +This plugin counts the number of interrupts (asyncronous events), exceptio= ns +(synchronous events) and host calls (e.g. semihosting) per cpu. + Other emulation features ------------------------ =20 diff --git a/contrib/plugins/traps.c b/contrib/plugins/traps.c new file mode 100644 index 00000000000..d5ddc0f3dd6 --- /dev/null +++ b/contrib/plugins/traps.c @@ -0,0 +1,83 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * Copyright (C) 2025, Julian Ganz + * + * Traps - count traps + * + * Count the number of interrupts (asyncronous events), exceptions (synchr= onous + * events) and host calls (e.g. semihosting) per cpu and report those coun= ts on + * exit. + */ + +#include + +#include + +QEMU_PLUGIN_EXPORT int qemu_plugin_version =3D QEMU_PLUGIN_VERSION; + +typedef struct { + uint64_t interrupts; + uint64_t exceptions; + uint64_t hostcalls; +} TrapCounters; + +static struct qemu_plugin_scoreboard *traps; + +static void vcpu_discon(qemu_plugin_id_t id, unsigned int vcpu_index, + enum qemu_plugin_discon_type type, uint64_t from_p= c, + uint64_t to_pc) +{ + TrapCounters *rec =3D qemu_plugin_scoreboard_find(traps, vcpu_index); + switch (type) { + case QEMU_PLUGIN_DISCON_INTERRUPT: + rec->interrupts++; + break; + case QEMU_PLUGIN_DISCON_EXCEPTION: + rec->exceptions++; + break; + case QEMU_PLUGIN_DISCON_HOSTCALL: + rec->hostcalls++; + break; + default: + g_assert_not_reached(); + break; + } +} + +static void plugin_exit(qemu_plugin_id_t id, void *p) +{ + g_autoptr(GString) report; + report =3D g_string_new("VCPU, interrupts, exceptions, hostcalls\n"); + int max_vcpus =3D qemu_plugin_num_vcpus(); + int vcpu; + + for (vcpu =3D 0; vcpu < max_vcpus; vcpu++) { + TrapCounters *rec =3D qemu_plugin_scoreboard_find(traps, vcpu); + g_string_append_printf(report, + "% 4d, % 10"PRId64", % 10"PRId64", % 10"PRI= d64 + "\n", vcpu, rec->interrupts, rec->exception= s, + rec->hostcalls); + } + + qemu_plugin_outs(report->str); + qemu_plugin_scoreboard_free(traps); +} + +QEMU_PLUGIN_EXPORT +int qemu_plugin_install(qemu_plugin_id_t id, const qemu_info_t *info, + int argc, char **argv) +{ + if (!info->system_emulation) { + qemu_plugin_outs("Note: interrupts are only reported in system" + " emulation mode."); + } + + traps =3D qemu_plugin_scoreboard_new(sizeof(TrapCounters)); + + qemu_plugin_register_vcpu_discon_cb(id, QEMU_PLUGIN_DISCON_ALL, + vcpu_discon); + + qemu_plugin_register_atexit_cb(id, plugin_exit, NULL); + + return 0; +} diff --git a/contrib/plugins/meson.build b/contrib/plugins/meson.build index 7eb3629c95d..eb944b5159a 100644 --- a/contrib/plugins/meson.build +++ b/contrib/plugins/meson.build @@ -1,6 +1,6 @@ contrib_plugins =3D ['bbv', 'cache', 'cflow', 'drcov', 'execlog', 'hotbloc= ks', 'hotpages', 'howvec', 'hwprofile', 'ips', 'stoptrigger', - 'uftrace'] + 'traps', 'uftrace'] if host_os !=3D 'windows' # lockstep uses socket.h contrib_plugins +=3D 'lockstep' --=20 2.47.3