From nobody Wed Oct 23 01:22:56 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 ARC-Seal: i=1; a=rsa-sha256; t=1729356051; cv=none; d=zohomail.com; s=zohoarc; b=LBZoQ4g76lJM6gBBT72CI+w4DcG5g1hVMSBPHSZAdii3MawP6p3/NISID+Oakr/65BIgVn1FG1vWYTl6Sy9aoxc4fn4+J8fenktJybvZ1ymEoeDwyjBNTzLblm33J6KdOGVCblz9Ipmosaie9GaE+iNBRcyO7rYc/N5BCuKpYz0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729356051; h=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=Ur8L81I1H0e4vzzh5VrT7k+TDuhANP/KCZKThZCd3Jw=; b=gE17POW/8eei4YWPA6vRB4X7RtU+3xlKecwg9OjshpH8n1CB9krOt0joFn+3N5d+B/C1pAIwSTh9e5dmV0aWjGWLf6M3zChDh5+UrMld7hJ3ggN2EIZt+5xhsOgqZa1Y2rvLep5hw/P2ILjOEosIuL9TpcTHY69bo29XK+IwYs0= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1729356051303135.1057249822005; Sat, 19 Oct 2024 09:40:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t2CUu-0001xr-TW; Sat, 19 Oct 2024 12:40:12 -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 1t2CUr-0001v6-6L for qemu-devel@nongnu.org; Sat, 19 Oct 2024 12:40:09 -0400 Received: from mailgate02.uberspace.is ([185.26.156.114]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t2CUp-0003h0-Az for qemu-devel@nongnu.org; Sat, 19 Oct 2024 12:40:08 -0400 Received: from skiff.uberspace.de (skiff.uberspace.de [185.26.156.131]) by mailgate02.uberspace.is (Postfix) with ESMTPS id BAF9E180363 for ; Sat, 19 Oct 2024 18:39:58 +0200 (CEST) Received: (qmail 9755 invoked by uid 990); 19 Oct 2024 16:39:58 -0000 Received: from unknown (HELO unkown) (::1) by skiff.uberspace.de (Haraka/3.0.1) with ESMTPSA; Sat, 19 Oct 2024 18:39:58 +0200 Authentication-Results: skiff.uberspace.de; auth=pass (plain) From: Julian Ganz To: qemu-devel@nongnu.org Cc: Julian Ganz , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alexandre Iooss , Mahmoud Mandour , Pierrick Bouvier Subject: [RFC PATCH v2 3/7] contrib/plugins: add plugin showcasing new trap related API Date: Sat, 19 Oct 2024 18:39:36 +0200 Message-ID: <1a2a379011c3636cfc516a3d246566acf14dd44f.1729355735.git.neither@nut.email> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: <20231021122502.26746-1-neither@nut.email> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Bar: ---- X-Rspamd-Report: REPLY(-4) SUSPICIOUS_RECIPS(1.5) MID_CONTAINS_FROM(1) MIME_GOOD(-0.1) BAYES_HAM(-2.999999) R_MISSING_CHARSET(0.5) X-Rspamd-Score: -4.099999 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nut.email; s=uberspace; h=from:to:cc:subject:date; bh=bLp2Ya8EFnauSsMyOa8SMgEYE21yarlDHCE17UCplxA=; b=JheoeNHMF8IN71/x8thC36JxGDHBrOsrvGS/Db9bau+76mkcuTymlMZsX8YjVhL2ywIr6+Lh5X 73F4cE3M3C5p5ddlYzOb0jrQFOuUD7+eieN5f0uxzHRUjhvW9odyWFpyoTYT+ZcjGRSGRejGT/Vo ToBZiFe9Oo51MsqxJN+LG8HSdSZWzQRM5CXenuiTkNgeWDvc4hVK/3ZiHB1NUQI2rGPaLazoRWFA pI3cChuM427V38P7mO5MBUYFHHV/ny3Ty2IZJRtJLDvOzrnaMlAsyO4mQDixXyV/Vkgl4I8mhROR pL/xc5XTn8Gy++6g3yr5psvgEDJhJxWIi/VHWQFGv7gLThMhFNxwNPg9xkrgsNYlrze0OLaee/Jt +YOiVKYbNWnDvzzy+vqttTMZZEpL9y0j7r6ofzK4NjmJrCyF7tUnEUKb9Sww05Tz7fEnOuPbQEyk Aey+SMN6wPoKbqwo3IbtfCgGi+qHuAC6FRP7KdoIcJ58T2Piv96onY/y5UaZuSScwTjxnEAR/71G 1M70O4JPY4cURpwZyyqLpzten2EqlN39ImLlGPn99wCVhLSKl5BK/BwKNuolLpL/17rPYEauGbwd AGgLrk/Ik5p9+QfpGmOiUe/B5zBQjlLQyo1/9jZJAqDZUc4jetEk+lgBHanfcrjTpCBfMXOIIoy3 g= 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=185.26.156.114; envelope-from=neither@nut.email; helo=mailgate02.uberspace.is X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.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, NEW_PRODUCTS=1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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 @nut.email) X-ZM-MESSAGEID: 1729356054524116600 Content-Type: text/plain; charset="utf-8" We recently introduced new plugin API for registration of trap related callbacks. This change introduces a minimal plugin showcasing the new API. It simply counts the occurances of interrupts, exceptions and semihosting events per CPU and reports the counts when exitting. Signed-off-by: Julian Ganz --- contrib/plugins/Makefile | 1 + contrib/plugins/traps.c | 89 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 contrib/plugins/traps.c diff --git a/contrib/plugins/Makefile b/contrib/plugins/Makefile index bbddd4800f..6085fd701f 100644 --- a/contrib/plugins/Makefile +++ b/contrib/plugins/Makefile @@ -31,6 +31,7 @@ NAMES +=3D drcov NAMES +=3D ips NAMES +=3D stoptrigger NAMES +=3D cflow +NAMES +=3D traps =20 ifeq ($(CONFIG_WIN32),y) SO_SUFFIX :=3D .dll diff --git a/contrib/plugins/traps.c b/contrib/plugins/traps.c new file mode 100644 index 0000000000..2a38dbb8b3 --- /dev/null +++ b/contrib/plugins/traps.c @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2024, Julian Ganz + * + * Traps - count traps + * + * License: GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include + +#include + +QEMU_PLUGIN_EXPORT int qemu_plugin_version =3D QEMU_PLUGIN_VERSION; + +typedef struct { + uint64_t interrupts; + uint64_t exceptions; + uint64_t semihosting; + bool active; +} TrapCounters; + +static TrapCounters *traps; +size_t max_vcpus; + +static void vcpu_init(qemu_plugin_id_t id, unsigned int vcpu_index) +{ + traps[vcpu_index].active =3D true; +} + +static void vcpu_interrupt(qemu_plugin_id_t id, unsigned int vcpu_index) +{ + traps[vcpu_index].interrupts++; +} + +static void vcpu_exception(qemu_plugin_id_t id, unsigned int vcpu_index) +{ + traps[vcpu_index].exceptions++; +} + +static void vcpu_semihosting(qemu_plugin_id_t id, unsigned int vcpu_index) +{ + traps[vcpu_index].semihosting++; +} + +static void plugin_exit(qemu_plugin_id_t id, void *p) +{ + g_autoptr(GString) report; + report =3D g_string_new("VCPU, interrupts, exceptions, semihosting\n"); + int vcpu; + + for (vcpu =3D 0; vcpu < max_vcpus; vcpu++) { + TrapCounters *rec =3D &traps[vcpu]; + if (rec->active) { + g_string_append_printf(report, + "% 4d, % 10"PRId64", % 10"PRId64", % 10" + PRId64"\n", + vcpu, + rec->interrupts, rec->exceptions, + rec->semihosting); + } + } + + qemu_plugin_outs(report->str); +} + +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) { + fputs("trap plugin can only be used in system emulation mode.\n", + stderr); + return -1; + } + + max_vcpus =3D info->system.max_vcpus; + traps =3D calloc(max_vcpus, sizeof(TrapCounters)); + qemu_plugin_register_vcpu_init_cb(id, vcpu_init); + qemu_plugin_vcpu_for_each(id, vcpu_init); + + qemu_plugin_register_vcpu_interrupt_cb(id, vcpu_interrupt); + qemu_plugin_register_vcpu_exception_cb(id, vcpu_exception); + qemu_plugin_register_vcpu_semihosting_cb(id, vcpu_semihosting); + + qemu_plugin_register_atexit_cb(id, plugin_exit, NULL); + + return 0; +} --=20 2.45.2