From nobody Sun May 5 10:08:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1599227925; cv=none; d=zohomail.com; s=zohoarc; b=fQ2ai6GVRHttK/Ec595n0mLo3sKk49q8JbZ+CarssJ14bAoaGH+8fD2p9Hc0S12+JUoMvhQ6cI7P8oSDXQhz+EZBMzoXdhfQMLbDO2YrqwKnIgxU/m2L1cBcl6HTeSXt5QxjgfpmmtHJF8S+oGpluQnrAra566lu6BEWiVRgS5g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599227925; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6ITqVnKRG6efTEDBxxDrqufzGTL9CoWQ38GxyiPoSjU=; b=F78ATE5chEpDGpYvjznz639hwg/JtkbYANLF7n6YR9vTYAhoGo84VMJawwvY8Io89bVNtl1wIzIeZiIZwwjxX6iRnJPeTvCM53bjp3vmV0uqZ2QaPhhSD8lJuRepXICXKglY8Qm4LkKv2L9TcvK5kPS67DQr4Mcp0SLW+q4iS5s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1599227925113235.05648700423626; Fri, 4 Sep 2020 06:58:45 -0700 (PDT) Received: from localhost ([::1]:57584 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kEC0W-000208-Hq for importer@patchew.org; Fri, 04 Sep 2020 09:44:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51018) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kEBws-0004tS-3p for qemu-devel@nongnu.org; Fri, 04 Sep 2020 09:40:14 -0400 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:53411) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kEBwq-0005f2-2N for qemu-devel@nongnu.org; Fri, 04 Sep 2020 09:40:13 -0400 Received: by mail-wm1-x341.google.com with SMTP id u18so6114535wmc.3 for ; Fri, 04 Sep 2020 06:40:11 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id l19sm11325775wmi.8.2020.09.04.06.40.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 06:40:08 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id D8A151FF87; Fri, 4 Sep 2020 14:40:07 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6ITqVnKRG6efTEDBxxDrqufzGTL9CoWQ38GxyiPoSjU=; b=aBnWQ0E4SPdPlq/yVhKDRj/x5MLVIDmQ00yeCIFlqavSSKyKpH2BcutINTzpaYb5is EKOpmKAoTWtng6YQFvqdJqDUpOV9UJ6AFPZlSqHxioIrTuyVCxhAIkQe4ibrXdok20Sb EvFb9MUzd18JFZKzLj+jelyV3OxqR3usbBkqIELOBRcTN/BxD3uSdRMYDI0N3HWAT5cz x3ELI9b8PDwCtCL6xzSU1xBNniJXqlE3Mv6AK94gmyOBORNiUq+xpoOYxrGyekU91Bd0 awIxezBtVGO0Sf1wFldaGlu/jOsYHYuwwpgQjrn2Z3t03rfrDSi/ekSx98KV69tA9j3i sv2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6ITqVnKRG6efTEDBxxDrqufzGTL9CoWQ38GxyiPoSjU=; b=SRVa9PqvznNB3LCjTuswzCCpPdq+gCPpFMZAb6Kf6/tVY0702Jp8x20b/rtBJWIymq MHJjga1EmUk0bWWqLWXXJkEGjGcZ+C+j82YlrRnjupqCQjxQiowA7awYjen1ASHGPVDo Ufi3QWfG24uhj5hkyziM0Z3aTsLDUW/PNyAC2RGJpTynFavrOKQoH8u+pMsJP8hLc40E pWUapEt5QykPdW9QAFtEuAZh10XIB9WOas57SkGFUgL4dCD98iKZglRwYetVQJedJTbx pa69DpkveglQDikFWXrPABcnlXheES9+oe4G8PebOJbx1SFwlAbptrF5bWSmaCxXTZw8 +CDg== X-Gm-Message-State: AOAM5315GRTF9mQE88VSWMTH10Do9+iQdOC8HzLytBbR8nbGDBDd+Pk9 eT9Is/BRKCwn5H5PBk2Vgw6GlQ== X-Google-Smtp-Source: ABdhPJwKnu/dhtp312SBK7ahiNtM/qp8vf8a+yZtZb0GbkszM2scbX+q9SYK+ySKnudVjavVohFdQw== X-Received: by 2002:a1c:2dcc:: with SMTP id t195mr7251321wmt.166.1599226810362; Fri, 04 Sep 2020 06:40:10 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 1/4] hw/virtio/pci: include vdev name in registered PCI sections Date: Fri, 4 Sep 2020 14:40:04 +0100 Message-Id: <20200904134007.4175-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200904134007.4175-1-alex.bennee@linaro.org> References: <20200904134007.4175-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::341; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x341.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: robert.foley@linaro.org, "Michael S . Tsirkin" , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , robhenry@microsoft.com, aaron@os.amperecomputing.com, cota@braap.org, kuhn.chenqun@huawei.com, peter.puhov@linaro.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) When viewing/debugging memory regions it is sometimes hard to figure out which PCI device something belongs to. Make the names unique by including the vdev name in the name string. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Michael S. Tsirkin Message-Id: <20200713200415.26214-10-alex.bennee@linaro.org> --- hw/virtio/virtio-pci.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 5bc769f685c..169d07ba20e 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -1421,7 +1421,8 @@ static void virtio_pci_device_write(void *opaque, hwa= ddr addr, } } =20 -static void virtio_pci_modern_regions_init(VirtIOPCIProxy *proxy) +static void virtio_pci_modern_regions_init(VirtIOPCIProxy *proxy, + const char *vdev_name) { static const MemoryRegionOps common_ops =3D { .read =3D virtio_pci_common_read, @@ -1468,36 +1469,41 @@ static void virtio_pci_modern_regions_init(VirtIOPC= IProxy *proxy) }, .endianness =3D DEVICE_LITTLE_ENDIAN, }; + g_autoptr(GString) name =3D g_string_new(NULL); =20 - + g_string_printf(name, "virtio-pci-common-%s", vdev_name); memory_region_init_io(&proxy->common.mr, OBJECT(proxy), &common_ops, proxy, - "virtio-pci-common", + name->str, proxy->common.size); =20 + g_string_printf(name, "virtio-pci-isr-%s", vdev_name); memory_region_init_io(&proxy->isr.mr, OBJECT(proxy), &isr_ops, proxy, - "virtio-pci-isr", + name->str, proxy->isr.size); =20 + g_string_printf(name, "virtio-pci-device-%s", vdev_name); memory_region_init_io(&proxy->device.mr, OBJECT(proxy), &device_ops, proxy, - "virtio-pci-device", + name->str, proxy->device.size); =20 + g_string_printf(name, "virtio-pci-notify-%s", vdev_name); memory_region_init_io(&proxy->notify.mr, OBJECT(proxy), ¬ify_ops, proxy, - "virtio-pci-notify", + name->str, proxy->notify.size); =20 + g_string_printf(name, "virtio-pci-notify-pio-%s", vdev_name); memory_region_init_io(&proxy->notify_pio.mr, OBJECT(proxy), ¬ify_pio_ops, proxy, - "virtio-pci-notify-pio", + name->str, proxy->notify_pio.size); } =20 @@ -1642,7 +1648,7 @@ static void virtio_pci_device_plugged(DeviceState *d,= Error **errp) =20 struct virtio_pci_cfg_cap *cfg_mask; =20 - virtio_pci_modern_regions_init(proxy); + virtio_pci_modern_regions_init(proxy, vdev->name); =20 virtio_pci_modern_mem_region_map(proxy, &proxy->common, &cap); virtio_pci_modern_mem_region_map(proxy, &proxy->isr, &cap); --=20 2.20.1 From nobody Sun May 5 10:08:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1599228046; cv=none; d=zohomail.com; s=zohoarc; b=ME7OxTLkZfvp7A8FXHf7Rl2O1bbUk7JIR3JAee6ITnJEApf4a/3DL6/3SG5+DToeaoM3nPqxmtp1u+xB13GXkOd/d3TI+EGuLNr91PcnLMAFIOzRW9Nfd+qz5Qav9SxjLhgPNzcS7jpXPvoCd16DHpiMNf+9zvg9+ZHMla0oU3I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599228046; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=5tQ4ZXGvdfdBTzlqZAhvWucrTP7Qmtc8hcYRkk0NrFQ=; b=X26eYsqvj0N/jVQ0L5scod/i8oMeKavCnbGfIaJCLGpH5KzS1xwpUCFlJRk40Zdr9C06Di0igNlFwPdZkKtzrlU5mMS1AkqhIiW6lQEXZwC/073deh3zOYxO9rwWSbR2RJqN5hMhFhmfWkM+x3mIowfs6hs3sbjmQq2T9YD8I4s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1599228046111512.1442067518766; Fri, 4 Sep 2020 07:00:46 -0700 (PDT) Received: from localhost ([::1]:34174 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kEC1a-0003v8-At for importer@patchew.org; Fri, 04 Sep 2020 09:45:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51076) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kEBwu-0004zS-NP for qemu-devel@nongnu.org; Fri, 04 Sep 2020 09:40:16 -0400 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]:39641) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kEBws-0005gh-47 for qemu-devel@nongnu.org; Fri, 04 Sep 2020 09:40:16 -0400 Received: by mail-wr1-x429.google.com with SMTP id a17so6780730wrn.6 for ; Fri, 04 Sep 2020 06:40:13 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id l126sm10845098wmf.39.2020.09.04.06.40.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 06:40:08 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id EF9E71FF8C; Fri, 4 Sep 2020 14:40:07 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5tQ4ZXGvdfdBTzlqZAhvWucrTP7Qmtc8hcYRkk0NrFQ=; b=n8Z9ul2wtO97Pg9kJ6tfUwtMZiWCH7NTHwxRPx2z2FLGkdYBhbYXXuIaGeu+GCmZSY bSgLX/ehJlL8KqaEx3+RUC39J3ZVZnIBRk28DbMyKHPCrKHweavj1YPX43RnS1EdQd2j wsUASGtqFsic+CvSPImFeywCPXYewdJG/z+q87pTxQsjcD/y73/joPMEduzDSV8mRVTW at1HVmRWtTcSzeXyv7rAclVbOrrkmqxLeBeyTTOaPKs+aUI0MnGic9odqjGim0XZ3JrG n/qYJFNDnNne2GeZ5M6OFd84qmb6aIdJVHcYAAyquM6EUU5UJ/5aGOOIp1OwzlGXq9PA w1MA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5tQ4ZXGvdfdBTzlqZAhvWucrTP7Qmtc8hcYRkk0NrFQ=; b=miUWWdzFbGK3BhHXBxiskMvnGmY4kO5vCtLCrnp967dM5HuTXsGy8jWq6TJLqTuTU7 Z7+q3CysFwSNChrlK9hsvjGLaorcQoM8EHzgiaBcpV3RUidtAZ0aes83M9Q8hCXP8Sjs thCea7xHxdDPXeIJqi6H29PBGQyjXbu1y/hTz5lUBus7OOKbCgViMxqN116PDU0HjPO5 I2RPEowo9a1VmSo3dZyvIkyip3Y+k/GDyVrN7FlIABJHQMATjEsViqyIFsAxcg04k5ar xYAMl4+bne5a/kNilHlCdPRYkoA5kDN56uTzJz+6mJfY+KwRbTNEEoLmsEvJGOLt+ZV4 WbPw== X-Gm-Message-State: AOAM532fMBV9r4QLaWRFBndU1olPBoOuXWB/m0dDo13YzRs9veY5VZ25 vQi2kBjMRYmeCQaYMVq28072dQ== X-Google-Smtp-Source: ABdhPJz9PYghRMSgIa4EODs7pyrusNg+TdqSpivUsE/C2zggQs+ZEPkn5Hl5qxUe3ZAEYYL3JrQnNQ== X-Received: by 2002:adf:ff83:: with SMTP id j3mr7973000wrr.135.1599226812600; Fri, 04 Sep 2020 06:40:12 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 2/4] plugins: add API to return a name for a IO device Date: Fri, 4 Sep 2020 14:40:05 +0100 Message-Id: <20200904134007.4175-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200904134007.4175-1-alex.bennee@linaro.org> References: <20200904134007.4175-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::429; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x429.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: robert.foley@linaro.org, Richard Henderson , robhenry@microsoft.com, aaron@os.amperecomputing.com, cota@braap.org, kuhn.chenqun@huawei.com, peter.puhov@linaro.org, Clement Deschamps , =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) This may well end up being anonymous but it should always be unique. Signed-off-by: Alex Benn=C3=A9e [r-b provisional given change to g_intern_string] Reviewed-by: Clement Deschamps Reviewed-by: Emilio G. Cota Reviewed-by: Richard Henderson Message-Id: <20200713200415.26214-11-alex.bennee@linaro.org> --- include/qemu/qemu-plugin.h | 6 ++++++ plugins/api.c | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index bab8b0d4b3a..c98c18d6b05 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -335,6 +335,12 @@ struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr(qemu= _plugin_meminfo_t info, bool qemu_plugin_hwaddr_is_io(const struct qemu_plugin_hwaddr *haddr); uint64_t qemu_plugin_hwaddr_device_offset(const struct qemu_plugin_hwaddr = *haddr); =20 +/* + * Returns a string representing the device. The string is valid for + * the lifetime of the plugin. + */ +const char *qemu_plugin_hwaddr_device_name(const struct qemu_plugin_hwaddr= *h); + typedef void (*qemu_plugin_vcpu_mem_cb_t)(unsigned int vcpu_index, qemu_plugin_meminfo_t info, uint64_t vaddr, diff --git a/plugins/api.c b/plugins/api.c index bbdc5a4eb46..4304e63f0cf 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -303,6 +303,26 @@ uint64_t qemu_plugin_hwaddr_device_offset(const struct= qemu_plugin_hwaddr *haddr return 0; } =20 +const char *qemu_plugin_hwaddr_device_name(const struct qemu_plugin_hwaddr= *h) +{ +#ifdef CONFIG_SOFTMMU + if (h && h->is_io) { + MemoryRegionSection *mrs =3D h->v.io.section; + if (!mrs->mr->name) { + unsigned long maddr =3D 0xffffffff & (uintptr_t) mrs->mr; + g_autofree char *temp =3D g_strdup_printf("anon%08lx", maddr); + return g_intern_string(temp); + } else { + return g_intern_string(mrs->mr->name); + } + } else { + return g_intern_string("RAM"); + } +#else + return g_intern_string("Invalid"); +#endif +} + /* * Queries to the number and potential maximum number of vCPUs there * will be. This helps the plugin dimension per-vcpu arrays. --=20 2.20.1 From nobody Sun May 5 10:08:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1599228772; cv=none; d=zohomail.com; s=zohoarc; b=VqPhV5NEy9ZFFfXuK84/xPhUsFJKZUSkwIPuyJwo3ioRPaNG2/AlpqsBMklYS2IW6SrtfufZfBwt2Z1dsJ7HfRGDAWNNgPiFlVsYz061PJXcq7qdcMrm8SL5dESH5MxDrC3drnsamNQphQuuBTKXxkd7vHxl7WM5jz37WdSirfo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599228772; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1HD7X9SbhYs6fGl3q12O38vXP04Gsb9f3vmT+04c5ec=; b=PEdJP3AUL1aOc7d6HULVfbEM6wdlkyByCMOPeevFOs8qvCF7GML9takHdA3x/9K1EmeIydcX7JxCpxUoKeG6SfspcmsBkvGty+s9s0DFoam3MmEd1kd9e2Qas7HhMB3nyfDzFxLh/lv0ODPRha0UO5syyy1QcU034Tjd+BW9/Y4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1599228772962571.68717570491; Fri, 4 Sep 2020 07:12:52 -0700 (PDT) Received: from localhost ([::1]:49586 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kEByM-00078A-5l for importer@patchew.org; Fri, 04 Sep 2020 09:41:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51122) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kEBww-00053m-TZ for qemu-devel@nongnu.org; Fri, 04 Sep 2020 09:40:18 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]:52079) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kEBwt-0005iH-MH for qemu-devel@nongnu.org; Fri, 04 Sep 2020 09:40:18 -0400 Received: by mail-wm1-x336.google.com with SMTP id w2so6137344wmi.1 for ; Fri, 04 Sep 2020 06:40:15 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id h185sm11751475wme.25.2020.09.04.06.40.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 06:40:12 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 1F8A31FF8F; Fri, 4 Sep 2020 14:40:08 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1HD7X9SbhYs6fGl3q12O38vXP04Gsb9f3vmT+04c5ec=; b=UcyU49PMY5f+n/yWE3tAx9XDNpB3bI11dI3IN52CocSlwpdwUgc+n6+kPQiHwQEMnf aZct18Z2yH3tl5NPIb4lKzEQJErBhiqb9mNEGvppSmdCexq94U8kUyKyk3Tg5S1kgAWl P2D+iqhoaCJi/clEPrqFuER+vZlZEWPz8kq7yq/xZjbnR1PrUeCWhc+GKYVDnJLziFsD tbD6gCr1ilsyAlSH7+h7u+wzjBwm4FPdFfFpSRojYMQHxJGFKEBFgmfF69I3xzUxyPtg BbxtaxzY2rYKofaDYd7EtCIDBpHXew7wCUbrgYjHdL+X7s6mmtFy2qd5Gxl+ui0ix+QO ECdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1HD7X9SbhYs6fGl3q12O38vXP04Gsb9f3vmT+04c5ec=; b=DLR2hCT7GerZcduO8Gf00Z0ja40fy4pMjBKfEfFs8FsMMJnVbH2Qewcnv2rPdO90Uu Tvl2t2venWfSGh9K2QJ5rYEl17REEbw3RMRyZm1nBWITcLHNE7tGgEtXkSBqQaAPUZyv QNk+WaB76PRYY7rQRIr7VOLKVPPlECpC7jvA0jbhqkhHSm5HFjU8Zn91XJANmTVssFyG 2ciBBf+wykajFgHMQWCbr6uIGP6uE/Rn7DV4hWSMf9ii/UIvqDSHJpVgnGxWYRRWe7EX VPV91I4q1Yn26+cz+X35QsTVZJ8htTgr5J9xptassBF6Xk90E6oVL6G5QxxQVOuJXwNY zBiQ== X-Gm-Message-State: AOAM5337FsyBbt3zZptE3l+9TSulZlfJZnp5yqFrsBJJE6wEzZSYYGv0 EhuVfkW4g5hI3lWRpfhc5eyc/g== X-Google-Smtp-Source: ABdhPJyB29zyFrI4WPILgBh0oUxGr0NO1NT0SkoFeQB/1iRymFWPnGDXhisy1QF/B6T3uqJ+pJpXiQ== X-Received: by 2002:a1c:f003:: with SMTP id a3mr7730566wmb.170.1599226813982; Fri, 04 Sep 2020 06:40:13 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 3/4] plugins: move the more involved plugins to contrib Date: Fri, 4 Sep 2020 14:40:06 +0100 Message-Id: <20200904134007.4175-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200904134007.4175-1-alex.bennee@linaro.org> References: <20200904134007.4175-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::336; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x336.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: robert.foley@linaro.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , robhenry@microsoft.com, aaron@os.amperecomputing.com, cota@braap.org, kuhn.chenqun@huawei.com, peter.puhov@linaro.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) We have an exploding complexity problem in the testing so lets just move the more involved plugins into contrib. tests/plugins still exist for the basic plugins that exercise the API. We restore the old pre-meson style Makefile for contrib as it also doubles as a guide for out-of-tree plugin builds. While we are at it add some examples to the documentation and a specific plugins build target. Signed-off-by: Alex Benn=C3=A9e --- docs/devel/tcg-plugins.rst | 142 ++++++++++++++++++ configure | 2 + Makefile | 11 ++ {tests/plugin =3D> contrib/plugins}/hotblocks.c | 0 {tests/plugin =3D> contrib/plugins}/hotpages.c | 0 {tests/plugin =3D> contrib/plugins}/howvec.c | 0 {tests/plugin =3D> contrib/plugins}/lockstep.c | 0 MAINTAINERS | 1 + contrib/plugins/Makefile | 42 ++++++ tests/Makefile.include | 2 +- tests/plugin/meson.build | 4 +- tests/tcg/Makefile.target | 3 +- 12 files changed, 202 insertions(+), 5 deletions(-) rename {tests/plugin =3D> contrib/plugins}/hotblocks.c (100%) rename {tests/plugin =3D> contrib/plugins}/hotpages.c (100%) rename {tests/plugin =3D> contrib/plugins}/howvec.c (100%) rename {tests/plugin =3D> contrib/plugins}/lockstep.c (100%) create mode 100644 contrib/plugins/Makefile diff --git a/docs/devel/tcg-plugins.rst b/docs/devel/tcg-plugins.rst index a05990906cc..e079695caf9 100644 --- a/docs/devel/tcg-plugins.rst +++ b/docs/devel/tcg-plugins.rst @@ -134,3 +134,145 @@ 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. + +Example Plugins +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +There are a number of plugins included with QEMU and you are +encouraged to contribute them upstream. There is a `contrib/plugins` +directory where they can go. + +- tests/plugins + +These are some basic plugins that are used to test and exercise the +API during the `make check-tcg` target. + +- contrib/plugins/hotblocks.c + +The hotblocks plugin allows you to examine the where hot paths of +execution are in your program. Once the program has finished you will +get a sorted list of blocks reporting the starting PC, translation +count, number of instructions and execution count. This will work best +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:: + + ./aarch64-linux-user/qemu-aarch64 -plugin contrib/plugins/libhotblocks.s= o -d plugin ./tests/tcg/aarch64-linux-user/sha1 + SHA1=3D15dd99a1991e0b3826fede3deffc1feba42278e6 + collected 903 entries in the hash table + pc, tcount, icount, ecount + 0x0000000041ed10, 1, 5, 66087 + 0x000000004002b0, 1, 4, 66087 + ... + +- contrib/plugins/hotpages.c + +Similar to hotblocks but this time tracks memory accesses:: + + ./aarch64-linux-user/qemu-aarch64 -plugin contrib/plugins/libhotpages.so= -d plugin ./tests/tcg/aarch64-linux-user/sha1 + SHA1=3D15dd99a1991e0b3826fede3deffc1feba42278e6 + Addr, RCPUs, Reads, WCPUs, Writes + 0x000055007fe000, 0x0001, 31747952, 0x0001, 8835161 + 0x000055007ff000, 0x0001, 29001054, 0x0001, 8780625 + 0x00005500800000, 0x0001, 687465, 0x0001, 335857 + 0x0000000048b000, 0x0001, 130594, 0x0001, 355 + 0x0000000048a000, 0x0001, 1826, 0x0001, 11 + +- contrib/plugins/howvec.c + +This is an instruction classifier so can be used to count different +types of instructions. It has a number of options to refine which get +counted. You can give an argument for a class of instructions to break +it down fully, so for example to see all the system registers +accesses:: + + ./aarch64-softmmu/qemu-system-aarch64 $(QEMU_ARGS) \ + -append "root=3D/dev/sda2 systemd.unit=3Dbenchmark.service" \ + -smp 4 -plugin ./contrib/plugins/libhowvec.so,arg=3Dsreg -d plugin + +which will lead to a sorted list after the class breakdown:: + + Instruction Classes: + Class: UDEF not counted + Class: SVE (68 hits) + Class: PCrel addr (47789483 hits) + Class: Add/Sub (imm) (192817388 hits) + Class: Logical (imm) (93852565 hits) + Class: Move Wide (imm) (76398116 hits) + Class: Bitfield (44706084 hits) + Class: Extract (5499257 hits) + Class: Cond Branch (imm) (147202932 hits) + Class: Exception Gen (193581 hits) + Class: NOP not counted + Class: Hints (6652291 hits) + Class: Barriers (8001661 hits) + Class: PSTATE (1801695 hits) + Class: System Insn (6385349 hits) + Class: System Reg counted individually + Class: Branch (reg) (69497127 hits) + Class: Branch (imm) (84393665 hits) + Class: Cmp & Branch (110929659 hits) + Class: Tst & Branch (44681442 hits) + Class: AdvSimd ldstmult (736 hits) + Class: ldst excl (9098783 hits) + Class: Load Reg (lit) (87189424 hits) + Class: ldst noalloc pair (3264433 hits) + Class: ldst pair (412526434 hits) + Class: ldst reg (imm) (314734576 hits) + Class: Loads & Stores (2117774 hits) + Class: Data Proc Reg (223519077 hits) + Class: Scalar FP (31657954 hits) + Individual Instructions: + Instr: mrs x0, sp_el0 (2682661 hits) (op=3D0xd5384100/ Syste= m Reg) + Instr: mrs x1, tpidr_el2 (1789339 hits) (op=3D0xd53cd041/ Syste= m Reg) + Instr: mrs x2, tpidr_el2 (1513494 hits) (op=3D0xd53cd042/ Syste= m Reg) + Instr: mrs x0, tpidr_el2 (1490823 hits) (op=3D0xd53cd040/ Syste= m Reg) + Instr: mrs x1, sp_el0 (933793 hits) (op=3D0xd5384101/ Syste= m Reg) + Instr: mrs x2, sp_el0 (699516 hits) (op=3D0xd5384102/ Syste= m Reg) + Instr: mrs x4, tpidr_el2 (528437 hits) (op=3D0xd53cd044/ Syste= m Reg) + Instr: mrs x30, ttbr1_el1 (480776 hits) (op=3D0xd538203e/ Syste= m Reg) + Instr: msr ttbr1_el1, x30 (480713 hits) (op=3D0xd518203e/ Syste= m Reg) + Instr: msr vbar_el1, x30 (480671 hits) (op=3D0xd518c01e/ Syste= m Reg) + ... + +To find the argument shorthand for the class you need to examine the +source code of the plugin at the moment, specifically the `*opt` +argument in the InsnClassExecCount tables. + +- contrib/plugins/lockstep.c + +This is a debugging tool for developers who want to find out when and +where execution diverges after a subtle change to TCG code generation. +It is not an exact science and results are likely to be mixed once +asynchronous events are introduced. While the use of -icount can +introduce determinism to the execution flow it doesn't always follow +the translation sequence will be exactly the same. Typically this is +caused by a timer firing to service the GUI causing a block to end +early. However in some cases it has proved to be useful in pointing +people at roughly where execution diverges. The only argument you need +for the plugin is a path for the socket the two instances will +communicate over:: + + + ./sparc-softmmu/qemu-system-sparc -monitor none -parallel none \ + -net none -M SS-20 -m 256 -kernel day11/zImage.elf \ + -plugin ./contrib/plugins/liblockstep.so,arg=3Dlockstep-sparc.sock \ + -d plugin,nochain + +which will eventually report:: + + qemu-system-sparc: warning: nic lance.0 has no peer + @ 0x000000ffd06678 vs 0x000000ffd001e0 (2/1 since last) + @ 0x000000ffd07d9c vs 0x000000ffd06678 (3/1 since last) + =CE=94 insn_count @ 0x000000ffd07d9c (809900609) vs 0x000000ffd06678 (80= 9900612) + previously @ 0x000000ffd06678/10 (809900609 insns) + previously @ 0x000000ffd001e0/4 (809900599 insns) + previously @ 0x000000ffd080ac/2 (809900595 insns) + previously @ 0x000000ffd08098/5 (809900593 insns) + previously @ 0x000000ffd080c0/1 (809900588 insns) + diff --git a/configure b/configure index f555923311f..2e4d3898012 100755 --- a/configure +++ b/configure @@ -8073,6 +8073,7 @@ DIRS=3D"$DIRS tests/qtest tests/qemu-iotests tests/vm= tests/fp tests/qgraph" DIRS=3D"$DIRS docs docs/interop fsdev scsi" DIRS=3D"$DIRS pc-bios/optionrom pc-bios/s390-ccw" DIRS=3D"$DIRS roms/seabios" +DIRS=3D"$DIRS contrib/plugins/" LINKS=3D"Makefile" LINKS=3D"$LINKS tests/tcg/lm32/Makefile" LINKS=3D"$LINKS tests/tcg/Makefile.target" @@ -8084,6 +8085,7 @@ LINKS=3D"$LINKS .gdbinit scripts" # scripts needed by= relative path in .gdbinit LINKS=3D"$LINKS tests/acceptance tests/data" LINKS=3D"$LINKS tests/qemu-iotests/check" LINKS=3D"$LINKS python" +LINKS=3D"$LINKS contrib/plugins/Makefile " UNLINK=3D"pc-bios/keymaps" for bios_file in \ $source_path/pc-bios/*.bin \ diff --git a/Makefile b/Makefile index ed354c43b0b..2f1b18327dc 100644 --- a/Makefile +++ b/Makefile @@ -98,6 +98,12 @@ config-host.mak: $(SRC_PATH)/configure $(SRC_PATH)/pc-bi= os $(SRC_PATH)/VERSION # Force configure to re-run if the API symbols are updated ifeq ($(CONFIG_PLUGIN),y) config-host.mak: $(SRC_PATH)/plugins/qemu-plugins.symbols + +.PHONY: plugins +plugins: + $(call quiet-command,\ + $(MAKE) $(SUBDIR_MAKEFLAGS) -C contrib/plugins V=3D"$(V)", \ + "BUILD", "example plugins") endif =20 else @@ -276,6 +282,11 @@ help: $(call print-help,cscope,Generate cscope index) $(call print-help,sparse,Run sparse on the QEMU source) @echo '' +ifeq ($(CONFIG_PLUGIN),y) + @echo 'Plugin targets:' + $(call print-help,plugins,Build the example TCG plugins) + @echo '' +endif @echo 'Cleaning targets:' $(call print-help,clean,Remove most generated files but keep the config) $(call print-help,distclean,Remove all generated files) diff --git a/tests/plugin/hotblocks.c b/contrib/plugins/hotblocks.c similarity index 100% rename from tests/plugin/hotblocks.c rename to contrib/plugins/hotblocks.c diff --git a/tests/plugin/hotpages.c b/contrib/plugins/hotpages.c similarity index 100% rename from tests/plugin/hotpages.c rename to contrib/plugins/hotpages.c diff --git a/tests/plugin/howvec.c b/contrib/plugins/howvec.c similarity index 100% rename from tests/plugin/howvec.c rename to contrib/plugins/howvec.c diff --git a/tests/plugin/lockstep.c b/contrib/plugins/lockstep.c similarity index 100% rename from tests/plugin/lockstep.c rename to contrib/plugins/lockstep.c diff --git a/MAINTAINERS b/MAINTAINERS index b233da2a737..8d8eeac61f5 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2746,6 +2746,7 @@ S: Maintained F: docs/devel/tcg-plugins.rst F: plugins/ F: tests/plugin +F: contrib/plugins =20 AArch64 TCG target M: Richard Henderson diff --git a/contrib/plugins/Makefile b/contrib/plugins/Makefile new file mode 100644 index 00000000000..7801b08b0d6 --- /dev/null +++ b/contrib/plugins/Makefile @@ -0,0 +1,42 @@ +# -*- Mode: makefile -*- +# +# This Makefile example is fairly independent from the main makefile +# so users can take and adapt it for their build. We only really +# include config-host.mak so we don't have to repeat probing for +# cflags that the main configure has already done for us. +# + +BUILD_DIR :=3D $(CURDIR)/../.. + +include $(BUILD_DIR)/config-host.mak + +VPATH +=3D $(SRC_PATH)/contrib/plugins + +NAMES :=3D +NAMES +=3D hotblocks +NAMES +=3D hotpages +NAMES +=3D howvec +NAMES +=3D lockstep + +SONAMES :=3D $(addsuffix .so,$(addprefix lib,$(NAMES))) + +# The main QEMU uses Glib extensively so it's perfectly fine to use it +# in plugins (which many example do). +CFLAGS =3D $(GLIB_CFLAGS) +CFLAGS +=3D -fPIC +CFLAGS +=3D $(if $(findstring no-psabi,$(QEMU_CFLAGS)),-Wpsabi) +CFLAGS +=3D -I$(SRC_PATH)/include/qemu + +all: $(SONAMES) + +%.o: %.c + $(CC) $(CFLAGS) -c -o $@ $< + +lib%.so: %.o + $(CC) -shared -Wl,-soname,$@ -o $@ $^ $(LDLIBS) + +clean: + rm -f *.o *.so *.d + rm -Rf .libs + +.PHONY: all clean diff --git a/tests/Makefile.include b/tests/Makefile.include index 9ac8f5b86a6..5a961d366e5 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -439,7 +439,7 @@ RUN_TCG_TARGET_RULES=3D$(patsubst %,run-tcg-tests-%, $(= TARGET_DIRS)) $(foreach PROBE_TARGET,$(TARGET_DIRS), \ $(eval -include $(SRC_PATH)/tests/tcg/Makefile.prereqs)) =20 -build-tcg-tests-%: $(if $(CONFIG_PLUGIN),plugins) +build-tcg-tests-%: $(if $(CONFIG_PLUGIN),test-plugins) $(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) \ -f $(SRC_PATH)/tests/tcg/Makefile.qemu \ SRC_PATH=3D$(SRC_PATH) \ diff --git a/tests/plugin/meson.build b/tests/plugin/meson.build index dbbdcbaa670..1eacfa6e355 100644 --- a/tests/plugin/meson.build +++ b/tests/plugin/meson.build @@ -1,7 +1,7 @@ t =3D [] -foreach i : ['bb', 'empty', 'insn', 'mem', 'hotblocks', 'howvec', 'hotpage= s', 'lockstep'] +foreach i : ['bb', 'empty', 'insn', 'mem'] t +=3D shared_module(i, files(i + '.c'), include_directories: '../../include/qemu', dependencies: glib) endforeach -alias_target('plugins', t) +alias_target('test-plugins', t) diff --git a/tests/tcg/Makefile.target b/tests/tcg/Makefile.target index 4b2b696fcee..2ae86776cdc 100644 --- a/tests/tcg/Makefile.target +++ b/tests/tcg/Makefile.target @@ -129,8 +129,7 @@ ifeq ($(CONFIG_PLUGIN),y) PLUGIN_SRC=3D$(SRC_PATH)/tests/plugin PLUGIN_LIB=3D../../plugin VPATH+=3D$(PLUGIN_LIB) -PLUGINS=3D$(filter-out liblockstep.so,\ - $(patsubst %.c, lib%.so, $(notdir $(wildcard $(PLUGIN_SRC)/*.c)))) +PLUGINS=3D$(patsubst %.c, lib%.so, $(notdir $(wildcard $(PLUGIN_SRC)/*.c))) =20 # We need to ensure expand the run-plugin-TEST-with-PLUGIN # pre-requistes manually here as we can't use stems to handle it. We --=20 2.20.1 From nobody Sun May 5 10:08:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1599228672; cv=none; d=zohomail.com; s=zohoarc; b=PfwqzjN8YePD6ndsdcpIvDni+kZO4FwiNpV4MPezuAN+6qsc6YZLbXdoAPwb0K9+jeTLjQCSgCEHL9sr6Pzf73aHXc9Iu1BVnaTmdJK57wBT6h1ONdX0TYO3J3ijZ9hJxQJ6HylgPtbS0VRNpQECNfHZT4fo86jRQ25fVQzFvzE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599228672; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=PxtiIAwJ1kjUeew0ERcC6AvTCfyYiyLhyq+ziAl/hGc=; b=nBo34FKjsQMRvJVmXf+l4GbnZo11Ke2MtVFR63NjSdHRbVpPiRRDX7Br9IOblX5g8ZcgVtS050w/HiqoZBntXN364MBDzYJ5hkpIvIJjEot+YeOREB9Y4Rkmv1s8VeT+BcWEd+oHYjv3pg+QZmkxr5fsN+kL7ZZBGr8jZ2xP+hs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1599228672875943.4907908259466; Fri, 4 Sep 2020 07:11:12 -0700 (PDT) Received: from localhost ([::1]:37838 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kEC37-0005VL-1Q for importer@patchew.org; Fri, 04 Sep 2020 09:46:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51132) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kEBwx-00055q-QQ for qemu-devel@nongnu.org; Fri, 04 Sep 2020 09:40:19 -0400 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]:44315) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kEBwv-0005jS-5v for qemu-devel@nongnu.org; Fri, 04 Sep 2020 09:40:19 -0400 Received: by mail-wr1-x429.google.com with SMTP id c15so6756762wrs.11 for ; Fri, 04 Sep 2020 06:40:16 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id c14sm11223431wrv.12.2020.09.04.06.40.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 06:40:12 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 3BD0D1FF90; Fri, 4 Sep 2020 14:40:08 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PxtiIAwJ1kjUeew0ERcC6AvTCfyYiyLhyq+ziAl/hGc=; b=OSQ2q91Vm33Pjw6Ot3tzHDgsOPn153a8bPUNHhBfkNsS8jL9xKa/rjl4iiGbJ7McaR 5eO1tBn8XbM8eTOV/oxgRHWzZRHXjKkGUPPIOO16MmAcvYq5z4ytGjtbP1fA/25rzgZe RUTX8S8bUr77swyMU8NpFvV8lze5u5k3kGhVvWx61Ha8uUomIIrSjGPHDM0Vr5IinIoU Lbr80FI8dQ9MhrlkIwaoST1G1cyNpooWq7FovbwNDbh6PExLXREz/n8DNuYDSsI7oyZ3 7r7xgnV3hdKekzG05XtS+vOvOZCpj6194Dkt+Wpf5/+O+3VyaA20n7vQciaj5LplPsF2 sgFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PxtiIAwJ1kjUeew0ERcC6AvTCfyYiyLhyq+ziAl/hGc=; b=R4CJGjblyvNjXb4rOWwB0KVGpBhmWNU//Pnyhhk0YIS1Sjk5bFGYaIVok7MdxReGxD DYcuBWLr66XtOmLOkNEJ1YpPV/ewR+Bt0EtnuVTorm7w9lktrB56JJFCwKIBsdwQGpRW acSXOtmKArH9EBEBLnn9TAAWWhjr+tvdWVH1xsG1lWis0y53AAtn9G0m4f3zZOCHAWax i3eGNUDcBwHN8VelgEjsyd5Gt5WLNO7A+ZdmOfNECVKdso6UwU3fEDFLavzDr8EFZgfw ZjvuAVw6nJ2k/ckbEiuIdbnQxPAQowaCnrId2SPxunFyy6/cfDoO3U1jnE1wiYxAxwHh xxGg== X-Gm-Message-State: AOAM530d0Eto31PCO2SmWpbV+6O9VD3Qz4G0va1mtPko5PxqrG93NPOA vLdahrFHsivjvLisYtJdtW6lnQ== X-Google-Smtp-Source: ABdhPJzEVNcsN1lcNONnBed52WDz/RVuuKoWxG3hJ0ZxO8FSLPgSxLkiiWwFsaRcB0Cb0RqJxIg8ew== X-Received: by 2002:adf:9e8d:: with SMTP id a13mr7339768wrf.94.1599226815571; Fri, 04 Sep 2020 06:40:15 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 4/4] plugins: new hwprofile plugin Date: Fri, 4 Sep 2020 14:40:07 +0100 Message-Id: <20200904134007.4175-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200904134007.4175-1-alex.bennee@linaro.org> References: <20200904134007.4175-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::429; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x429.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: robert.foley@linaro.org, robhenry@microsoft.com, aaron@os.amperecomputing.com, cota@braap.org, kuhn.chenqun@huawei.com, peter.puhov@linaro.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) This is a plugin intended to help with profiling access to various bits of system hardware. It only really makes sense for system emulation. It takes advantage of the recently exposed helper API that allows us to see the device name (memory region name) associated with a device. You can specify arg=3Dread or arg=3Dwrite to limit the tracking to just reads or writes (by default it does both). The pattern option: -plugin ./tests/plugin/libhwprofile.so,arg=3Dpattern will allow you to see the access pattern to devices, eg: gic_cpu @ 0xffffffc010040000 off:00000000, 8, 1, 8, 1 off:00000000, 4, 1, 4, 1 off:00000000, 2, 1, 2, 1 off:00000000, 1, 1, 1, 1 The source option: -plugin ./tests/plugin/libhwprofile.so,arg=3Dsource will track the virtual source address of the instruction making the access: pl011 @ 0xffffffc010031000 pc:ffffffc0104c785c, 1, 4, 0, 0 pc:ffffffc0104c7898, 1, 4, 0, 0 pc:ffffffc010512bcc, 2, 1867, 0, 0 You cannot mix source and pattern. Finally the match option allow you to limit the tracking to just the devices you care about. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Robert Foley Tested-by: Robert Foley Message-Id: <20200713200415.26214-12-alex.bennee@linaro.org> --- vN - add some notes to tcg-plugins.rst --- docs/devel/tcg-plugins.rst | 34 ++++ contrib/plugins/hwprofile.c | 305 ++++++++++++++++++++++++++++++++++++ contrib/plugins/Makefile | 1 + 3 files changed, 340 insertions(+) create mode 100644 contrib/plugins/hwprofile.c diff --git a/docs/devel/tcg-plugins.rst b/docs/devel/tcg-plugins.rst index e079695caf9..4af6d609c98 100644 --- a/docs/devel/tcg-plugins.rst +++ b/docs/devel/tcg-plugins.rst @@ -276,3 +276,37 @@ which will eventually report:: previously @ 0x000000ffd08098/5 (809900593 insns) previously @ 0x000000ffd080c0/1 (809900588 insns) =20 +- contrib/plugins/hwprofile + +The hwprofile tool can only be used with system emulation and allows +the user to see what hardware is accessed how often. It has a number of op= tions: + + * arg=3Dread or arg=3Dwrite + + By default the plugin tracks both reads and writes. You can use one + of these options to limit the tracking to just one class of accesses. + + * arg=3Dsource + + Will include a detailed break down of what the guest PC that made the + access was. Not compatible with arg=3Dpattern. Example output:: + + cirrus-low-memory @ 0xfffffd00000a0000 + pc:fffffc0000005cdc, 1, 256 + pc:fffffc0000005ce8, 1, 256 + pc:fffffc0000005cec, 1, 256 + + * arg=3Dpattern + + Instead break down the accesses based on the offset into the HW + region. This can be useful for seeing the most used registers of a + device. Example output:: + + pci0-conf @ 0xfffffd01fe000000 + off:00000004, 1, 1 + off:00000010, 1, 3 + off:00000014, 1, 3 + off:00000018, 1, 2 + off:0000001c, 1, 2 + off:00000020, 1, 2 + ... diff --git a/contrib/plugins/hwprofile.c b/contrib/plugins/hwprofile.c new file mode 100644 index 00000000000..6dac1d5f854 --- /dev/null +++ b/contrib/plugins/hwprofile.c @@ -0,0 +1,305 @@ +/* + * Copyright (C) 2020, Alex Benn=C3=A9e + * + * HW Profile - breakdown access patterns for IO to devices + * + * License: GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +QEMU_PLUGIN_EXPORT int qemu_plugin_version =3D QEMU_PLUGIN_VERSION; + +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) + +typedef struct { + uint64_t cpu_read; + uint64_t cpu_write; + uint64_t reads; + uint64_t writes; +} IOCounts; + +typedef struct { + uint64_t off_or_pc; + IOCounts counts; +} IOLocationCounts; + +typedef struct { + const char *name; + uint64_t base; + IOCounts totals; + GHashTable *detail; +} DeviceCounts; + +static GMutex lock; +static GHashTable *devices; + +/* track the access pattern to a piece of HW */ +static bool pattern; +/* track the source address of access to HW */ +static bool source; +/* track only matched regions of HW */ +static bool check_match; +static gchar **matches; + +static enum qemu_plugin_mem_rw rw =3D QEMU_PLUGIN_MEM_RW; + +static inline bool track_reads(void) +{ + return rw =3D=3D QEMU_PLUGIN_MEM_RW || rw =3D=3D QEMU_PLUGIN_MEM_R; +} + +static inline bool track_writes(void) +{ + return rw =3D=3D QEMU_PLUGIN_MEM_RW || rw =3D=3D QEMU_PLUGIN_MEM_W; +} + +static void plugin_init(void) +{ + devices =3D g_hash_table_new(NULL, NULL); +} + +static gint sort_cmp(gconstpointer a, gconstpointer b) +{ + DeviceCounts *ea =3D (DeviceCounts *) a; + DeviceCounts *eb =3D (DeviceCounts *) b; + return ea->totals.reads + ea->totals.writes > + eb->totals.reads + eb->totals.writes ? -1 : 1; +} + +static gint sort_loc(gconstpointer a, gconstpointer b) +{ + IOLocationCounts *ea =3D (IOLocationCounts *) a; + IOLocationCounts *eb =3D (IOLocationCounts *) b; + return ea->off_or_pc > eb->off_or_pc; +} + +static void fmt_iocount_record(GString *s, IOCounts *rec) +{ + if (track_reads()) { + g_string_append_printf(s, ", %"PRIx64", %"PRId64, + rec->cpu_read, rec->reads); + } + if (track_writes()) { + g_string_append_printf(s, ", %"PRIx64", %"PRId64, + rec->cpu_write, rec->writes); + } +} + +static void fmt_dev_record(GString *s, DeviceCounts *rec) +{ + g_string_append_printf(s, "%s, 0x%"PRIx64, + rec->name, rec->base); + fmt_iocount_record(s, &rec->totals); + g_string_append_c(s, '\n'); +} + +static void plugin_exit(qemu_plugin_id_t id, void *p) +{ + g_autoptr(GString) report =3D g_string_new(""); + GList *counts; + + if (!(pattern || source)) { + g_string_printf(report, "Device, Address"); + if (track_reads()) { + g_string_append_printf(report, ", RCPUs, Reads"); + } + if (track_writes()) { + g_string_append_printf(report, ", WCPUs, Writes"); + } + g_string_append_c(report, '\n'); + } + + counts =3D g_hash_table_get_values(devices); + if (counts && g_list_next(counts)) { + GList *it; + + it =3D g_list_sort(counts, sort_cmp); + + while (it) { + DeviceCounts *rec =3D (DeviceCounts *) it->data; + if (rec->detail) { + GList *accesses =3D g_hash_table_get_values(rec->detail); + GList *io_it =3D g_list_sort(accesses, sort_loc); + const char *prefix =3D pattern ? "off" : "pc"; + g_string_append_printf(report, "%s @ 0x%"PRIx64"\n", + rec->name, rec->base); + while (io_it) { + IOLocationCounts *loc =3D (IOLocationCounts *) io_it->= data; + g_string_append_printf(report, " %s:%08"PRIx64, + prefix, loc->off_or_pc); + fmt_iocount_record(report, &loc->counts); + g_string_append_c(report, '\n'); + io_it =3D io_it->next; + } + } else { + fmt_dev_record(report, rec); + } + it =3D it->next; + }; + g_list_free(it); + } + + qemu_plugin_outs(report->str); +} + +static DeviceCounts *new_count(const char *name, uint64_t base) +{ + DeviceCounts *count =3D g_new0(DeviceCounts, 1); + count->name =3D name; + count->base =3D base; + if (pattern || source) { + count->detail =3D g_hash_table_new(NULL, NULL); + } + g_hash_table_insert(devices, (gpointer) name, count); + return count; +} + +static IOLocationCounts *new_location(GHashTable *table, uint64_t off_or_p= c) +{ + IOLocationCounts *loc =3D g_new0(IOLocationCounts, 1); + loc->off_or_pc =3D off_or_pc; + g_hash_table_insert(table, (gpointer) off_or_pc, loc); + return loc; +} + +static void hwprofile_match_hit(DeviceCounts *rec, uint64_t off) +{ + g_autoptr(GString) report =3D g_string_new("hwprofile: match @ offset"= ); + g_string_append_printf(report, "%"PRIx64", previous hits\n", off); + fmt_dev_record(report, rec); + qemu_plugin_outs(report->str); +} + +static void inc_count(IOCounts *count, bool is_write, unsigned int cpu_ind= ex) +{ + if (is_write) { + count->writes++; + count->cpu_write |=3D (1 << cpu_index); + } else { + count->reads++; + count->cpu_read |=3D (1 << cpu_index); + } +} + +static void vcpu_haddr(unsigned int cpu_index, qemu_plugin_meminfo_t memin= fo, + uint64_t vaddr, void *udata) +{ + struct qemu_plugin_hwaddr *hwaddr =3D qemu_plugin_get_hwaddr(meminfo, = vaddr); + + if (!hwaddr || !qemu_plugin_hwaddr_is_io(hwaddr)) { + return; + } else { + const char *name =3D qemu_plugin_hwaddr_device_name(hwaddr); + uint64_t off =3D qemu_plugin_hwaddr_device_offset(hwaddr); + bool is_write =3D qemu_plugin_mem_is_store(meminfo); + DeviceCounts *counts; + + g_mutex_lock(&lock); + counts =3D (DeviceCounts *) g_hash_table_lookup(devices, name); + + if (!counts) { + uint64_t base =3D vaddr - off; + counts =3D new_count(name, base); + } + + if (check_match) { + if (g_strv_contains((const char * const *)matches, counts->nam= e)) { + hwprofile_match_hit(counts, off); + inc_count(&counts->totals, is_write, cpu_index); + } + } else { + inc_count(&counts->totals, is_write, cpu_index); + } + + /* either track offsets or source of access */ + if (source) { + off =3D (uint64_t) udata; + } + + if (pattern || source) { + IOLocationCounts *io_count =3D g_hash_table_lookup(counts->det= ail, + (gpointer) of= f); + if (!io_count) { + io_count =3D new_location(counts->detail, off); + } + inc_count(&io_count->counts, is_write, cpu_index); + } + + g_mutex_unlock(&lock); + } +} + +static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) +{ + size_t n =3D qemu_plugin_tb_n_insns(tb); + size_t i; + + for (i =3D 0; i < n; i++) { + struct qemu_plugin_insn *insn =3D qemu_plugin_tb_get_insn(tb, i); + gpointer udata =3D (gpointer) (source ? qemu_plugin_insn_vaddr(ins= n) : 0); + qemu_plugin_register_vcpu_mem_cb(insn, vcpu_haddr, + QEMU_PLUGIN_CB_NO_REGS, + rw, udata); + } +} + +QEMU_PLUGIN_EXPORT +int qemu_plugin_install(qemu_plugin_id_t id, const qemu_info_t *info, + int argc, char **argv) +{ + int i; + + for (i =3D 0; i < argc; i++) { + char *opt =3D argv[i]; + if (g_strcmp0(opt, "read") =3D=3D 0) { + rw =3D QEMU_PLUGIN_MEM_R; + } else if (g_strcmp0(opt, "write") =3D=3D 0) { + rw =3D QEMU_PLUGIN_MEM_W; + } else if (g_strcmp0(opt, "pattern") =3D=3D 0) { + pattern =3D true; + } else if (g_strcmp0(opt, "source") =3D=3D 0) { + source =3D true; + } else if (g_str_has_prefix(opt, "match")) { + gchar **parts =3D g_strsplit(opt, "=3D", 2); + check_match =3D true; + matches =3D g_strsplit(parts[1], ",", -1); + g_strfreev(parts); + } else { + fprintf(stderr, "option parsing failed: %s\n", opt); + return -1; + } + } + + if (source && pattern) { + fprintf(stderr, "can only currently track either source or pattern= .\n"); + return -1; + } + + if (!info->system_emulation) { + fprintf(stderr, "hwprofile: plugin only useful for system emulatio= n\n"); + return -1; + } + + /* Just warn about overflow */ + if (info->system.smp_vcpus > 64 || + info->system.max_vcpus > 64) { + fprintf(stderr, "hwprofile: can only track up to 64 CPUs\n"); + } + + plugin_init(); + + qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans); + qemu_plugin_register_atexit_cb(id, plugin_exit, NULL); + return 0; +} diff --git a/contrib/plugins/Makefile b/contrib/plugins/Makefile index 7801b08b0d6..b9d7935e5ef 100644 --- a/contrib/plugins/Makefile +++ b/contrib/plugins/Makefile @@ -17,6 +17,7 @@ NAMES +=3D hotblocks NAMES +=3D hotpages NAMES +=3D howvec NAMES +=3D lockstep +NAMES +=3D hwprofile =20 SONAMES :=3D $(addsuffix .so,$(addprefix lib,$(NAMES))) =20 --=20 2.20.1