From patchwork Mon Nov 5 18:51:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Lindsay X-Patchwork-Id: 10668931 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 668A71709 for ; Mon, 5 Nov 2018 18:53:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 563A9284FF for ; Mon, 5 Nov 2018 18:53:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4A5542851A; Mon, 5 Nov 2018 18:53:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C2B74284FF for ; Mon, 5 Nov 2018 18:53:39 +0000 (UTC) Received: from localhost ([::1]:37111 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJk0J-0007d3-0E for patchwork-qemu-devel@patchwork.kernel.org; Mon, 05 Nov 2018 13:53:39 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46509) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJjyn-0004a0-6q for qemu-devel@nongnu.org; Mon, 05 Nov 2018 13:52:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gJjyl-0000Wl-EC for qemu-devel@nongnu.org; Mon, 05 Nov 2018 13:52:05 -0500 Received: from mail-eopbgr810103.outbound.protection.outlook.com ([40.107.81.103]:6323 helo=NAM01-BY2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gJjya-0000MQ-J8; Mon, 05 Nov 2018 13:51:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amperemail.onmicrosoft.com; s=selector1-os-amperecomputing-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=STKh8Eqo6HA18AmpdKl/7DJjvk/NyLNwlfv6QlRGaqc=; b=mnlWAzo9O50ailJpALVpeVHh+2E7eOVrilZMWd0A0/1Ds+RhoeusvsffpULmYpRuslYKYzz1WtSR9ZyD9fhsWFnEN2O+gay0TylIS7wzNqsSIejI/ZyUs+8b1qc0WMg+CH/eVyx25xWXgmBhbrjFSwunV+YZWYNwo9o3CEBhzAM= Received: from DM6PR01MB4825.prod.exchangelabs.com (20.177.218.222) by DM6PR01MB5034.prod.exchangelabs.com (20.176.120.218) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.25; Mon, 5 Nov 2018 18:51:50 +0000 Received: from DM6PR01MB4825.prod.exchangelabs.com ([fe80::4cf7:c8dc:b673:ec66]) by DM6PR01MB4825.prod.exchangelabs.com ([fe80::4cf7:c8dc:b673:ec66%3]) with mapi id 15.20.1294.028; Mon, 5 Nov 2018 18:51:50 +0000 From: Aaron Lindsay To: "qemu-arm@nongnu.org" , Peter Maydell , Alistair Francis , Wei Huang , Peter Crosthwaite , Richard Henderson Thread-Topic: [PATCH v7 01/12] migration: Add post_save function to VMStateDescription Thread-Index: AQHUdTic+xF/b3bKKEmBMC9gYr82JQ== Date: Mon, 5 Nov 2018 18:51:50 +0000 Message-ID: <20181105185046.2802-2-aaron@os.amperecomputing.com> References: <20181105185046.2802-1-aaron@os.amperecomputing.com> In-Reply-To: <20181105185046.2802-1-aaron@os.amperecomputing.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BN6PR20CA0070.namprd20.prod.outlook.com (2603:10b6:404:151::32) To DM6PR01MB4825.prod.exchangelabs.com (2603:10b6:5:6b::30) authentication-results: spf=none (sender IP is ) smtp.mailfrom=aaron@os.amperecomputing.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [216.85.170.153] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DM6PR01MB5034; 6:9wjBNs8m887zt7jowrYpNXlcmeEUX4ypMl/FAusFtuvjPj9Fw5KDkpg/ZiaDUdDfXjRYODCZJbRkx5KYwsbX50bKfBi4mgMeu1jrw9rGCKdyCrJwi+ruLB5j9n8vyN20wfSSEmEGDp/GhDfw+1JlqrR5UuhBe8wV3gf27RbMeHEshRlMtXV+3QH/r7GTp8mb1HWrVjukl8eGpZP64Gow0cai8QVvcFSu69FvPBXIRfu+TL0Rw0x0HH1S1UtokSDaNONBz/Ws0oJv8upaB4/egt5twU+AxRe72r8NJ82/jedWsAg73MoKq2iml3sVHUtcgDGC64abZ/IMx6YsxoOy/eFEnSIQH6vrmJP0bquRl4VCioVJqi/ULjyhvXzs4wLkmIxrH/FP+PT4f7qG/oNeiYpSn9XpU6SLg8dWEzS5NY4+HtJaOclMQihbpOlQAghYD8S5ojBUlqVZxmfPF1km3Q==; 5:2s+d/EbncJoSt4UWfSwn8GJb5J9UgKWK11OGbu3LwQVJXHzTrLmwGK4ncOjHMpMi5fTxB83Acc5OVxE+zHKWjU3JPPWqTJvNlFQ222Faglq5rrvhWKep8IMgX81Uji8j201cL0IKWnjCjiX3ecnxHISIdg2pBk7qyqlyIvNmYEU=; 7:hMh6JQXxUGQthcuzyqnwm7BhJNbrLS5VoY8AyghjieZ2L1SY/mugWEIpIfyxGV0PPNb62viLPYUJy33hUfDwYd0z/u15KKCQdXTQDZ+dDvX93GiMkQ/HR5HfTlB7nH1cA8ceJCRggrqN294hWUXazQ== x-ms-office365-filtering-correlation-id: 07e7dcb4-8f5f-4f07-0ac5-08d6434fbee6 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(5600074)(711020)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020); SRVR:DM6PR01MB5034; x-ms-traffictypediagnostic: DM6PR01MB5034: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(17755550239193)(85827821059158); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(10201501046)(3002001)(93006095)(93001095)(3231382)(944501410)(52105095)(148016)(149066)(150057)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(20161123562045)(20161123558120)(201708071742011)(7699051)(76991095); SRVR:DM6PR01MB5034; BCL:0; PCL:0; RULEID:; SRVR:DM6PR01MB5034; x-forefront-prvs: 08476BC6EF x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(136003)(366004)(39840400004)(396003)(376002)(346002)(189003)(199004)(81166006)(52116002)(110136005)(105586002)(76176011)(1076002)(86362001)(8936002)(54906003)(68736007)(8676002)(81156014)(66066001)(102836004)(6512007)(14454004)(2900100001)(2906002)(53936002)(3846002)(6116002)(6506007)(386003)(7416002)(71200400001)(478600001)(14444005)(71190400001)(26005)(5660300001)(316002)(446003)(11346002)(6486002)(256004)(25786009)(106356001)(305945005)(99286004)(7736002)(39060400002)(476003)(2616005)(486006)(6436002)(97736004)(4326008)(2501003)(186003); DIR:OUT; SFP:1102; SCL:1; SRVR:DM6PR01MB5034; H:DM6PR01MB4825.prod.exchangelabs.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:0; received-spf: None (protection.outlook.com: os.amperecomputing.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: 8BNgOY5iQQpllBzgBViVXw9h3iwxQFd1XURENF8xir6plEMeXscdgP5lh+GKq4aMPyiE9rsF7rljYLoahqSEIAXAdovFnfSnWcjsHIt0GVIOJp62tRvBbLE2znKC5+nO+k39vXXlBVrWtMuR+fpTYUJjLhSduaa24gaCb0fgvJaeQiWzbOO8oP7IrzOUQMikju2TWecbwqh60V1+9w51+Mq/Wq0zKgwqCu2SBQXcCO4w2DOyJO2ouOur/9BYRnLFAoEGUBvbfsU+ZWDrympY6G4/WOMNa2dqbIu6XLXW+9i5bG5+EdS9Gj/g1fpIF+mGUqlkV90/EsZN7AgIrcgj+1OCHwG5CiA1OLSGA2Z8K04= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 07e7dcb4-8f5f-4f07-0ac5-08d6434fbee6 X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Nov 2018 18:51:50.5579 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR01MB5034 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.81.103 Subject: [Qemu-devel] [PATCH v7 01/12] migration: Add post_save function to VMStateDescription X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Spradling , Digant Desai , "qemu-devel@nongnu.org" , "Dr . David Alan Gilbert" , Aaron Lindsay , Aaron Lindsay Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP In some cases it may be helpful to modify state before saving it for migration, and then modify the state back after it has been saved. The existing pre_save function provides half of this functionality. This patch adds a post_save function to provide the second half. Signed-off-by: Aaron Lindsay Cc: Dr. David Alan Gilbert Reviewed-by: Peter Maydell Reviewed-by: Dr. David Alan Gilbert --- docs/devel/migration.rst | 9 +++++++-- include/migration/vmstate.h | 1 + migration/vmstate.c | 13 ++++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/docs/devel/migration.rst b/docs/devel/migration.rst index 687570754d..92fb521ad2 100644 --- a/docs/devel/migration.rst +++ b/docs/devel/migration.rst @@ -419,8 +419,13 @@ The functions to do that are inside a vmstate definition, and are called: This function is called before we save the state of one device. -Example: You can look at hpet.c, that uses the three function to -massage the state that is transferred. +- ``int (*post_save)(void *opaque);`` + + This function is called after we save the state of one device + (even upon failure, unless the call to pre_save returned an error). + +Example: You can look at hpet.c, that uses the first three functions +to massage the state that is transferred. The ``VMSTATE_WITH_TMP`` macro may be useful when the migration data doesn't match the stored device data well; it allows an diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 2b501d0466..9355d83056 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -185,6 +185,7 @@ struct VMStateDescription { int (*pre_load)(void *opaque); int (*post_load)(void *opaque, int version_id); int (*pre_save)(void *opaque); + int (*post_save)(void *opaque); bool (*needed)(void *opaque); VMStateField *fields; const VMStateDescription **subsections; diff --git a/migration/vmstate.c b/migration/vmstate.c index 0bc240a317..c15d75260a 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -387,6 +387,9 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd, if (ret) { error_report("Save of field %s/%s failed", vmsd->name, field->name); + if (vmsd->post_save) { + vmsd->post_save(opaque); + } return ret; } @@ -412,7 +415,15 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd, json_end_array(vmdesc); } - return vmstate_subsection_save(f, vmsd, opaque, vmdesc); + ret = vmstate_subsection_save(f, vmsd, opaque, vmdesc); + + if (vmsd->post_save) { + int ps_ret = vmsd->post_save(opaque); + if (!ret) { + ret = ps_ret; + } + } + return ret; } static const VMStateDescription * From patchwork Mon Nov 5 18:51:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Lindsay X-Patchwork-Id: 10668943 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F26B413BF for ; Mon, 5 Nov 2018 18:58:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CF8DA289F6 for ; Mon, 5 Nov 2018 18:58:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C113728989; Mon, 5 Nov 2018 18:58:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E2A7529AB4 for ; Mon, 5 Nov 2018 18:58:23 +0000 (UTC) Received: from localhost ([::1]:37144 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJk4s-00053C-VJ for patchwork-qemu-devel@patchwork.kernel.org; Mon, 05 Nov 2018 13:58:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46598) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJjyu-0004hj-OX for qemu-devel@nongnu.org; Mon, 05 Nov 2018 13:52:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gJjyn-0000Xq-5Y for qemu-devel@nongnu.org; Mon, 05 Nov 2018 13:52:10 -0500 Received: from mail-eopbgr810103.outbound.protection.outlook.com ([40.107.81.103]:6323 helo=NAM01-BY2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gJjye-0000MQ-EQ; Mon, 05 Nov 2018 13:51:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amperemail.onmicrosoft.com; s=selector1-os-amperecomputing-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5poua1UspXXeWQReAcmE7tmrWbde4Rdxrut2OkYJt9g=; b=RAkXWDb+eTSGzsfmGe/0UwlI+TmDcm2AeM9FgR5rfrn3uSGP97Fe0VuqPW4Tx1G63kOjTjw+Fike0u/RFYpAVHkQ3geN2AZTCM9/WvVjGKl00vywF1ekeBrhuu1SR2RS/5L+zuP7DWCcy2fPXutMOMeMnCndtN/IYV1JqDF8J90= Received: from DM6PR01MB4825.prod.exchangelabs.com (20.177.218.222) by DM6PR01MB5034.prod.exchangelabs.com (20.176.120.218) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.25; Mon, 5 Nov 2018 18:51:52 +0000 Received: from DM6PR01MB4825.prod.exchangelabs.com ([fe80::4cf7:c8dc:b673:ec66]) by DM6PR01MB4825.prod.exchangelabs.com ([fe80::4cf7:c8dc:b673:ec66%3]) with mapi id 15.20.1294.028; Mon, 5 Nov 2018 18:51:52 +0000 From: Aaron Lindsay To: "qemu-arm@nongnu.org" , Peter Maydell , Alistair Francis , Wei Huang , Peter Crosthwaite , Richard Henderson Thread-Topic: [PATCH v7 02/12] target/arm: Reorganize PMCCNTR accesses Thread-Index: AQHUdTidRQePjAMjaEK31x4b2nO99Q== Date: Mon, 5 Nov 2018 18:51:51 +0000 Message-ID: <20181105185046.2802-3-aaron@os.amperecomputing.com> References: <20181105185046.2802-1-aaron@os.amperecomputing.com> In-Reply-To: <20181105185046.2802-1-aaron@os.amperecomputing.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BN6PR20CA0070.namprd20.prod.outlook.com (2603:10b6:404:151::32) To DM6PR01MB4825.prod.exchangelabs.com (2603:10b6:5:6b::30) authentication-results: spf=none (sender IP is ) smtp.mailfrom=aaron@os.amperecomputing.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [216.85.170.153] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DM6PR01MB5034; 6:2ctoNbnCSyAuimZpr2RSHMBNRvac8y5J+vgO/XaDmxNTk1udWafLGRm61ZHIjuJArzaEhuxYF+lrU/wpH3f+RSRojLzA9BbVoEEJ/Z+HwW1kTwIyx7O/x1lrBvsH9NdGgVmKBe45V+VOsb0MYyivSzuKk9Unw7j1aUS8+FxHDAw/yvI+hXASA73WQmbbxND7DSo6tAIvCD6oEShlILn2MGicf3Qt+gNLhS3/ybDD18XZk7EwzNkE652vvok2F0iA+4MfBKJy8+Y3mYflp3SJ6CQ4ztQUiNARhiQRxykRslLCxXC/9zD8tygFROg4OesgLt1JiE5DZlxfHmanbAFG4rrvOIkxncM2BNufiKD0Ti1cEhs+TnE14xMr1nK0z5kRrQ3zfWk1MGYKJm4JFyhoehBtGnTdwv4LAuX/2FDkVpt+6yC04R8G4FtsPzzusOHHkbnXh8DCGLBOyMiNBr87vQ==; 5:vW5Ohjc2X19MkmJcp0J0KGAmsSQlln6VUcIk98pRtkoYVh5v5EbcZKrPqUdrJ8gOfFYrGJztxy9WLucxNoS44ogwZ08fLf3xtCQvAQquP8pRzoGMNW0NWq+LX+yi+tsaIwelKXBsmVxSCIuOEIKqm6e9+4GCOqSqRQyRwGl5tog=; 7:uYsVi+j2IF8yZfSRmfxwqvzI7efE4auL49odhl2v1cO5e32vVsZvMyJVmLrlgfqcV9bVIExpGM+BwlANo/m5ScHh5+QT+jp52HYSU+NaSxWBefXoJoDajbzULtbe3+HeKjIlhT1+V0mbdiXt85l+4Q== x-ms-office365-filtering-correlation-id: 796c0a26-60d0-4dc5-f477-08d6434fbf9e x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(5600074)(711020)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020); SRVR:DM6PR01MB5034; x-ms-traffictypediagnostic: DM6PR01MB5034: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(85827821059158); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(10201501046)(3002001)(93006095)(93001095)(3231382)(944501410)(52105095)(148016)(149066)(150057)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(20161123562045)(20161123558120)(201708071742011)(7699051)(76991095); SRVR:DM6PR01MB5034; BCL:0; PCL:0; RULEID:; SRVR:DM6PR01MB5034; x-forefront-prvs: 08476BC6EF x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(136003)(366004)(39840400004)(396003)(376002)(346002)(189003)(199004)(81166006)(52116002)(110136005)(105586002)(76176011)(1076002)(86362001)(8936002)(54906003)(68736007)(8676002)(81156014)(66066001)(102836004)(6512007)(14454004)(2900100001)(2906002)(53936002)(3846002)(6116002)(6506007)(386003)(7416002)(71200400001)(478600001)(14444005)(71190400001)(26005)(5660300001)(316002)(446003)(11346002)(6486002)(256004)(25786009)(106356001)(305945005)(99286004)(7736002)(39060400002)(476003)(2616005)(486006)(6436002)(97736004)(4326008)(2501003)(186003); DIR:OUT; SFP:1102; SCL:1; SRVR:DM6PR01MB5034; H:DM6PR01MB4825.prod.exchangelabs.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:0; received-spf: None (protection.outlook.com: os.amperecomputing.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: 9d5g9d7NnVaxxEV/SBGxtg6Z01rcqVAjW/p4/0DHHEoLhXzhlFCkZFDkY4aJ0CEP2ldtYj5SVL0lLyqxIQwkh5i1oi9CIJyK7ADf1isKXmHNkUn0cxY1cTykJKUlM3YM15JLew2VRY9iF0/PXueAhEkVyyIiO6PNYkKMr9UlsuaW5OT2LNznj7vU8GCv6SDsDJSIlURd3VFy37iyBZRqLRHW3dVb0rYZhdRb/xaGF4BWRQtHW0OQ3npfNDESPl5FGIHh/3zrmyljRZPDG2Z8wkB+HoMkSWgHY6URzPsluUpkPoUBLkZmr64wxhE3u1IGuybEUDreUTYIwrumy2hIBPRF+fEtdzNO4H4l18rGD/0= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 796c0a26-60d0-4dc5-f477-08d6434fbf9e X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Nov 2018 18:51:51.9639 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR01MB5034 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.81.103 Subject: [Qemu-devel] [PATCH v7 02/12] target/arm: Reorganize PMCCNTR accesses X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Spradling , Digant Desai , "qemu-devel@nongnu.org" , Aaron Lindsay , Aaron Lindsay Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP pmccntr_read and pmccntr_write contained duplicate code that was already being handled by pmccntr_sync. Consolidate the duplicated code into two functions: pmccntr_op_start and pmccntr_op_finish. Add a companion to c15_ccnt in CPUARMState so that we can simultaneously save both the architectural register value and the last underlying cycle count - this ensures time isn't lost and will also allow us to access the 'old' architectural register value in order to detect overflows in later patches. Signed-off-by: Aaron Lindsay Signed-off-by: Aaron Lindsay Reviewed-by: Peter Maydell --- target/arm/cpu.h | 38 +++++++++++---- target/arm/helper.c | 114 +++++++++++++++++++++++++++----------------- 2 files changed, 99 insertions(+), 53 deletions(-) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index b5eff79f73..50a0862c84 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -468,10 +468,20 @@ typedef struct CPUARMState { uint64_t oslsr_el1; /* OS Lock Status */ uint64_t mdcr_el2; uint64_t mdcr_el3; - /* If the counter is enabled, this stores the last time the counter - * was reset. Otherwise it stores the counter value + /* Stores the architectural value of the counter *the last time it was + * updated* by pmccntr_op_start. Accesses should always be surrounded + * by pmccntr_op_start/pmccntr_op_finish to guarantee the latest + * architecturally-correct value is being read/set. */ uint64_t c15_ccnt; + /* Stores the delta between the architectural value and the underlying + * cycle count during normal operation. It is used to update c15_ccnt + * to be the correct architectural value before accesses. During + * accesses, c15_ccnt_delta contains the underlying count being used + * for the access, after which it reverts to the delta value in + * pmccntr_op_finish. + */ + uint64_t c15_ccnt_delta; uint64_t pmccfiltr_el0; /* Performance Monitor Filter Register */ uint64_t vpidr_el2; /* Virtualization Processor ID Register */ uint64_t vmpidr_el2; /* Virtualization Multiprocessor ID Register */ @@ -953,15 +963,27 @@ int cpu_arm_signal_handler(int host_signum, void *pinfo, void *puc); /** - * pmccntr_sync + * pmccntr_op_start/finish + * @env: CPUARMState + * + * Convert the counter in the PMCCNTR between its delta form (the typical mode + * when it's enabled) and the guest-visible value. These two calls must always + * surround any action which might affect the counter. + */ +void pmccntr_op_start(CPUARMState *env); +void pmccntr_op_finish(CPUARMState *env); + +/** + * pmu_op_start/finish * @env: CPUARMState * - * Synchronises the counter in the PMCCNTR. This must always be called twice, - * once before any action that might affect the timer and again afterwards. - * The function is used to swap the state of the register if required. - * This only happens when not in user mode (!CONFIG_USER_ONLY) + * Convert all PMU counters between their delta form (the typical mode when + * they are enabled) and the guest-visible values. These two calls must + * surround any action which might affect the counters, and the return value + * from pmu_op_start must be supplied as the second argument to pmu_op_finish. */ -void pmccntr_sync(CPUARMState *env); +void pmu_op_start(CPUARMState *env); +void pmu_op_finish(CPUARMState *env); /* SCTLR bit meanings. Several bits have been reused in newer * versions of the architecture; in that case we define constants diff --git a/target/arm/helper.c b/target/arm/helper.c index 0ea95b0815..281bcff1da 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -1085,28 +1085,63 @@ static inline bool arm_ccnt_enabled(CPUARMState *env) return true; } - -void pmccntr_sync(CPUARMState *env) +/* + * Ensure c15_ccnt is the guest-visible count so that operations such as + * enabling/disabling the counter or filtering, modifying the count itself, + * etc. can be done logically. This is essentially a no-op if the counter is + * not enabled at the time of the call. + */ +void pmccntr_op_start(CPUARMState *env) { - uint64_t temp_ticks; - - temp_ticks = muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), + uint64_t cycles = 0; + cycles = muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), ARM_CPU_FREQ, NANOSECONDS_PER_SECOND); - if (env->cp15.c9_pmcr & PMCRD) { - /* Increment once every 64 processor clock cycles */ - temp_ticks /= 64; + if (arm_ccnt_enabled(env)) { + uint64_t eff_cycles = cycles; + if (env->cp15.c9_pmcr & PMCRD) { + /* Increment once every 64 processor clock cycles */ + eff_cycles /= 64; + } + + env->cp15.c15_ccnt = eff_cycles - env->cp15.c15_ccnt_delta; } + env->cp15.c15_ccnt_delta = cycles; +} +/* + * If PMCCNTR is enabled, recalculate the delta between the clock and the + * guest-visible count. A call to pmccntr_op_finish should follow every call to + * pmccntr_op_start. + */ +void pmccntr_op_finish(CPUARMState *env) +{ if (arm_ccnt_enabled(env)) { - env->cp15.c15_ccnt = temp_ticks - env->cp15.c15_ccnt; + uint64_t prev_cycles = env->cp15.c15_ccnt_delta; + + if (env->cp15.c9_pmcr & PMCRD) { + /* Increment once every 64 processor clock cycles */ + prev_cycles /= 64; + } + + env->cp15.c15_ccnt_delta = prev_cycles - env->cp15.c15_ccnt; } } +void pmu_op_start(CPUARMState *env) +{ + pmccntr_op_start(env); +} + +void pmu_op_finish(CPUARMState *env) +{ + pmccntr_op_finish(env); +} + static void pmcr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value) { - pmccntr_sync(env); + pmu_op_start(env); if (value & PMCRC) { /* The counter has been reset */ @@ -1117,26 +1152,16 @@ static void pmcr_write(CPUARMState *env, const ARMCPRegInfo *ri, env->cp15.c9_pmcr &= ~0x39; env->cp15.c9_pmcr |= (value & 0x39); - pmccntr_sync(env); + pmu_op_finish(env); } static uint64_t pmccntr_read(CPUARMState *env, const ARMCPRegInfo *ri) { - uint64_t total_ticks; - - if (!arm_ccnt_enabled(env)) { - /* Counter is disabled, do not change value */ - return env->cp15.c15_ccnt; - } - - total_ticks = muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), - ARM_CPU_FREQ, NANOSECONDS_PER_SECOND); - - if (env->cp15.c9_pmcr & PMCRD) { - /* Increment once every 64 processor clock cycles */ - total_ticks /= 64; - } - return total_ticks - env->cp15.c15_ccnt; + uint64_t ret; + pmccntr_op_start(env); + ret = env->cp15.c15_ccnt; + pmccntr_op_finish(env); + return ret; } static void pmselr_write(CPUARMState *env, const ARMCPRegInfo *ri, @@ -1153,22 +1178,9 @@ static void pmselr_write(CPUARMState *env, const ARMCPRegInfo *ri, static void pmccntr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value) { - uint64_t total_ticks; - - if (!arm_ccnt_enabled(env)) { - /* Counter is disabled, set the absolute value */ - env->cp15.c15_ccnt = value; - return; - } - - total_ticks = muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), - ARM_CPU_FREQ, NANOSECONDS_PER_SECOND); - - if (env->cp15.c9_pmcr & PMCRD) { - /* Increment once every 64 processor clock cycles */ - total_ticks /= 64; - } - env->cp15.c15_ccnt = total_ticks - value; + pmccntr_op_start(env); + env->cp15.c15_ccnt = value; + pmccntr_op_finish(env); } static void pmccntr_write32(CPUARMState *env, const ARMCPRegInfo *ri, @@ -1181,7 +1193,19 @@ static void pmccntr_write32(CPUARMState *env, const ARMCPRegInfo *ri, #else /* CONFIG_USER_ONLY */ -void pmccntr_sync(CPUARMState *env) +void pmccntr_op_start(CPUARMState *env) +{ +} + +void pmccntr_op_finish(CPUARMState *env) +{ +} + +void pmu_op_start(CPUARMState *env) +{ +} + +void pmu_op_finish(CPUARMState *env) { } @@ -1190,9 +1214,9 @@ void pmccntr_sync(CPUARMState *env) static void pmccfiltr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value) { - pmccntr_sync(env); + pmccntr_op_start(env); env->cp15.pmccfiltr_el0 = value & 0xfc000000; - pmccntr_sync(env); + pmccntr_op_finish(env); } static void pmcntenset_write(CPUARMState *env, const ARMCPRegInfo *ri, From patchwork Mon Nov 5 18:51:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Lindsay X-Patchwork-Id: 10668937 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 97D1A17D4 for ; Mon, 5 Nov 2018 18:56:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8786529973 for ; Mon, 5 Nov 2018 18:55:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7B71429AA9; Mon, 5 Nov 2018 18:55:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F1F1129973 for ; Mon, 5 Nov 2018 18:55:56 +0000 (UTC) Received: from localhost ([::1]:37132 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJk2W-0001bo-3o for patchwork-qemu-devel@patchwork.kernel.org; Mon, 05 Nov 2018 13:55:56 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46548) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJjyo-0004c1-Vh for qemu-devel@nongnu.org; Mon, 05 Nov 2018 13:52:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gJjyn-0000Xf-49 for qemu-devel@nongnu.org; Mon, 05 Nov 2018 13:52:06 -0500 Received: from mail-eopbgr740130.outbound.protection.outlook.com ([40.107.74.130]:9824 helo=NAM01-BN3-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gJjyc-0000P9-Jj; Mon, 05 Nov 2018 13:51:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amperemail.onmicrosoft.com; s=selector1-os-amperecomputing-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ORaQJUeT0vyQTTkbxyd2PfJWJ7jUjJbCv7U4/ltXssw=; b=WQkzMiKcFM4W4xd/jGeeQl3HnC1NBT9Tbih10iyHIM/TCIIKAUwIuKAq0OER3hol3GlA0O7Wf/XFA6k+8Sgy/iuOips9kgBztcXCXZmdMb6lwLkI7jHmzSkXbIK4AUmMWCHNEkK5YSKTLWjmcjN8kc2YYxLFS7V17vCFOWOAJIE= Received: from DM6PR01MB4825.prod.exchangelabs.com (20.177.218.222) by DM6PR01MB3673.prod.exchangelabs.com (20.176.64.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.26; Mon, 5 Nov 2018 18:51:53 +0000 Received: from DM6PR01MB4825.prod.exchangelabs.com ([fe80::4cf7:c8dc:b673:ec66]) by DM6PR01MB4825.prod.exchangelabs.com ([fe80::4cf7:c8dc:b673:ec66%3]) with mapi id 15.20.1294.028; Mon, 5 Nov 2018 18:51:53 +0000 From: Aaron Lindsay To: "qemu-arm@nongnu.org" , Peter Maydell , Alistair Francis , Wei Huang , Peter Crosthwaite , Richard Henderson Thread-Topic: [PATCH v7 03/12] target/arm: Swap PMU values before/after migrations Thread-Index: AQHUdTie+eZYbSFIzE2VUuP1qr4hfw== Date: Mon, 5 Nov 2018 18:51:53 +0000 Message-ID: <20181105185046.2802-4-aaron@os.amperecomputing.com> References: <20181105185046.2802-1-aaron@os.amperecomputing.com> In-Reply-To: <20181105185046.2802-1-aaron@os.amperecomputing.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BN6PR20CA0070.namprd20.prod.outlook.com (2603:10b6:404:151::32) To DM6PR01MB4825.prod.exchangelabs.com (2603:10b6:5:6b::30) authentication-results: spf=none (sender IP is ) smtp.mailfrom=aaron@os.amperecomputing.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [216.85.170.153] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DM6PR01MB3673; 6:7+WW/s5ZwgcZFrcbkvQ+OIetV/kuikCgGnBOAdl2i4LoIPKzq1Y6V81GQ+SneIcxK0VEXMH7ONjrlHj5fYxu1ipTqNxvoVoej43P/EJwJRzus4BCPfOJRsERestSocRgOItKIFGhXOxN219gGeHpvedMl+ZlX5zCrKIREs0f58sPnQeYUmur3qx56x5eLE+gpuYHpv2bTj+dlb9r2U0rD4tU+807KvjJWXhbwVaW2ZKSVJ9akSVMtZHLxRJ44TDrVH/etm6Yx4n+M6zXsb2X1Z2YTBMpj/WxY8Xx06Uj4giiwSR2k7irEkNIIJ4WGk1M0TNSbAiku2i9NjYFGtlvaXZKXKV8+eH1uwW4wdwdDS6IIbCfiR9agri41vmnOww9LCPhE34dPVeuoaTPJ4mMBDOaizkVzwvpjOpLnRoC1A4qRhgpXF3ddGCqSD29In7FfiIt4Rocj2nVz854hpS6lQ==; 5:DIMMyWmqHVc14rAWnqLiGcUuFT7pEX4l5ljyqgtYtS4LIsEnfIApfFXXOavvPDXdrf6dpVSVjQqjLmBZ9AK95A0kFy4sTt2lDzcCSqU9wO3SQnHld6hiqsUrWtwX5pJs3ghfEnHLERB+3eiGdTKsGyegShEvTrSHdZkm/pX4Jvs=; 7:8uLxUkjwXzPnyFXKTAcuIO0/whjnvr2kqTqPVaggCQ2ejJ0JEOlv7bzySTmHAeuo+nXUdG5PzVv1iT0Xn4GudDh1E7mWeLv41sK8VsZ91Da6yCFalEm6yfYUU+0PmZ+IxiUe6jBakM7fBVsrs8QY2g== x-ms-office365-filtering-correlation-id: 1e9983aa-fff3-456f-777c-08d6434fc06e x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(5600074)(711020)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020); SRVR:DM6PR01MB3673; x-ms-traffictypediagnostic: DM6PR01MB3673: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(85827821059158); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(10201501046)(3002001)(93006095)(93001095)(3231382)(944501410)(52105095)(148016)(149066)(150057)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(20161123562045)(20161123558120)(201708071742011)(7699051)(76991095); SRVR:DM6PR01MB3673; BCL:0; PCL:0; RULEID:; SRVR:DM6PR01MB3673; x-forefront-prvs: 08476BC6EF x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(39840400004)(396003)(136003)(366004)(346002)(376002)(199004)(189003)(476003)(76176011)(68736007)(446003)(14444005)(14454004)(186003)(7416002)(6436002)(3846002)(26005)(486006)(6116002)(478600001)(6486002)(2906002)(256004)(2900100001)(305945005)(7736002)(54906003)(8676002)(81166006)(66066001)(110136005)(316002)(81156014)(1076002)(6512007)(2616005)(11346002)(71190400001)(52116002)(102836004)(386003)(71200400001)(105586002)(106356001)(2501003)(8936002)(97736004)(5660300001)(575784001)(39060400002)(25786009)(6506007)(4326008)(53936002)(86362001)(99286004); DIR:OUT; SFP:1102; SCL:1; SRVR:DM6PR01MB3673; H:DM6PR01MB4825.prod.exchangelabs.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:0; MX:1; received-spf: None (protection.outlook.com: os.amperecomputing.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: nd8edYer/Os8EmbDBka/hCzWhCUtf/meGG+f0L/nW6EFcYBM0oTsJkclLFewY2GEpJzb7U80n/ZtVQ4zhkS2oJKY01efHcHP9zo0e+wh28syh3KLwIfN80PX0+cScQ5UyrKWCtNnLIC7Z3dj9dciSKoqSB4q+GE0OpuSWCay62aoawsgKvGEQGMZ9tz64pcCpX8WfxKLbAz47K99jCRYS1eOgze96MEQPqNI9vloW9zWHKt45Gb3xzyZvNFh37XiJnCombz0URRM1AnzcX0yqBxuNl/N5A7qQ4XqQNtYO+Ye5oTmh0PzQ3Ek/7JvbPGftaY7Im7CSeaTvwh+zoBoSDPw0vl7zQC9iX1r/kkwTxY= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1e9983aa-fff3-456f-777c-08d6434fc06e X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Nov 2018 18:51:53.0757 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR01MB3673 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.74.130 Subject: [Qemu-devel] [PATCH v7 03/12] target/arm: Swap PMU values before/after migrations X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Aaron Lindsay , Aaron Lindsay , Michael Spradling , "qemu-devel@nongnu.org" , Digant Desai Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Because of the PMU's design, many register accesses have side effects which are inter-related, meaning that the normal method of saving CP registers can result in inconsistent state. These side-effects are largely handled in pmu_op_start/finish functions which can be called before and after the state is saved/restored. By doing this and adding raw read/write functions for the affected registers, we avoid migration-related inconsistencies. Signed-off-by: Aaron Lindsay --- target/arm/helper.c | 6 ++++-- target/arm/machine.c | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/target/arm/helper.c b/target/arm/helper.c index 281bcff1da..5deff3d11f 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -1450,11 +1450,13 @@ static const ARMCPRegInfo v7_cp_reginfo[] = { .opc0 = 3, .opc1 = 3, .crn = 9, .crm = 13, .opc2 = 0, .access = PL0_RW, .accessfn = pmreg_access_ccntr, .type = ARM_CP_IO, - .readfn = pmccntr_read, .writefn = pmccntr_write, }, + .fieldoffset = offsetof(CPUARMState, cp15.c15_ccnt), + .readfn = pmccntr_read, .writefn = pmccntr_write, + .raw_readfn = raw_read, .raw_writefn = raw_write, }, #endif { .name = "PMCCFILTR_EL0", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 3, .crn = 14, .crm = 15, .opc2 = 7, - .writefn = pmccfiltr_write, + .writefn = pmccfiltr_write, .raw_writefn = raw_write, .access = PL0_RW, .accessfn = pmreg_access, .type = ARM_CP_IO, .fieldoffset = offsetof(CPUARMState, cp15.pmccfiltr_el0), diff --git a/target/arm/machine.c b/target/arm/machine.c index 239fe4e84d..6d14b08e0c 100644 --- a/target/arm/machine.c +++ b/target/arm/machine.c @@ -604,6 +604,8 @@ static int cpu_pre_save(void *opaque) { ARMCPU *cpu = opaque; + pmu_op_start(&cpu->env); + if (kvm_enabled()) { if (!write_kvmstate_to_list(cpu)) { /* This should never fail */ @@ -625,6 +627,20 @@ static int cpu_pre_save(void *opaque) return 0; } +static int cpu_post_save(void *opaque) +{ + ARMCPU *cpu = opaque; + pmu_op_finish(&cpu->env); + return 0; +} + +static int cpu_pre_load(void *opaque) +{ + ARMCPU *cpu = opaque; + pmu_op_start(&cpu->env); + return 0; +} + static int cpu_post_load(void *opaque, int version_id) { ARMCPU *cpu = opaque; @@ -672,6 +688,8 @@ static int cpu_post_load(void *opaque, int version_id) hw_breakpoint_update_all(cpu); hw_watchpoint_update_all(cpu); + pmu_op_finish(&cpu->env); + return 0; } @@ -680,6 +698,8 @@ const VMStateDescription vmstate_arm_cpu = { .version_id = 22, .minimum_version_id = 22, .pre_save = cpu_pre_save, + .post_save = cpu_post_save, + .pre_load = cpu_pre_load, .post_load = cpu_post_load, .fields = (VMStateField[]) { VMSTATE_UINT32_ARRAY(env.regs, ARMCPU, 16), From patchwork Mon Nov 5 18:51:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Lindsay X-Patchwork-Id: 10668933 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0A52417D4 for ; Mon, 5 Nov 2018 18:54:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE89129400 for ; Mon, 5 Nov 2018 18:54:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E1E1E29600; Mon, 5 Nov 2018 18:54:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2AB5829400 for ; Mon, 5 Nov 2018 18:54:04 +0000 (UTC) Received: from localhost ([::1]:37116 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJk0h-0008Rf-9K for patchwork-qemu-devel@patchwork.kernel.org; Mon, 05 Nov 2018 13:54:03 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46553) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJjyo-0004c6-WA for qemu-devel@nongnu.org; Mon, 05 Nov 2018 13:52:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gJjyn-0000YK-B8 for qemu-devel@nongnu.org; Mon, 05 Nov 2018 13:52:06 -0500 Received: from mail-eopbgr740130.outbound.protection.outlook.com ([40.107.74.130]:9824 helo=NAM01-BN3-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gJjye-0000P9-HQ; Mon, 05 Nov 2018 13:51:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amperemail.onmicrosoft.com; s=selector1-os-amperecomputing-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jsbB/4XqCLScggS3LvMlNAztUBRjTnuKSmmi7DK7Zi8=; b=O7fDY29llQsBcY5MYzkV3UbXQC0lq7kI+R48AEOwTMZVtTaJbz7kDo0H2iMGs6sNgOHOLkFpl/oyEb2/wfTFwX10a4/qN3gaeP7fTY7uvQjIJ6XDy0T51qMm5U7l7r2qkHLgrPyGBWVUApo+icYJBCFojZZZw/5w/z/fWpB1ito= Received: from DM6PR01MB4825.prod.exchangelabs.com (20.177.218.222) by DM6PR01MB3673.prod.exchangelabs.com (20.176.64.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.26; Mon, 5 Nov 2018 18:51:54 +0000 Received: from DM6PR01MB4825.prod.exchangelabs.com ([fe80::4cf7:c8dc:b673:ec66]) by DM6PR01MB4825.prod.exchangelabs.com ([fe80::4cf7:c8dc:b673:ec66%3]) with mapi id 15.20.1294.028; Mon, 5 Nov 2018 18:51:54 +0000 From: Aaron Lindsay To: "qemu-arm@nongnu.org" , Peter Maydell , Alistair Francis , Wei Huang , Peter Crosthwaite , Richard Henderson Thread-Topic: [PATCH v7 04/12] target/arm: Filter cycle counter based on PMCCFILTR_EL0 Thread-Index: AQHUdTiecjKFylwejkm/zbVAiocjhg== Date: Mon, 5 Nov 2018 18:51:54 +0000 Message-ID: <20181105185046.2802-5-aaron@os.amperecomputing.com> References: <20181105185046.2802-1-aaron@os.amperecomputing.com> In-Reply-To: <20181105185046.2802-1-aaron@os.amperecomputing.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BN6PR20CA0070.namprd20.prod.outlook.com (2603:10b6:404:151::32) To DM6PR01MB4825.prod.exchangelabs.com (2603:10b6:5:6b::30) authentication-results: spf=none (sender IP is ) smtp.mailfrom=aaron@os.amperecomputing.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [216.85.170.153] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DM6PR01MB3673; 6:yHIjEKXpnypDW8cSceiWOVjZcKvWKX+eJqbwaYU8A9WGHlZvbTPFO4XOjrkxr46bC9Y1Jm+boYZXmh6Xgr8NV/jrQgEni3h9K1bpYPmU6dzcJylrT0c02H1lSH6JuwdLy6hW7lIlhKRZGK9/RZJfhUQSmyZLbuwTR6IHA1EHDmK35ppFE5XEHSkc5FvxWYCLutIrwGl9SlxgT7tRT4K/SiUvQ3IHIObeLvtHtSp+VLUQF6i6dKX0l4nAPBOTFJS2EsG6QcqIk2/d9xC5tZEwfUeQL6rLpaficKH5122fLmyMYcQjm5fJc7a2J5g60c9ezbeWTaglp46oiL5ezslwSTLMvRlOIIixEGPkRcWhOzKM6rIPGRw2MZvohjjOG7kf+QcOn3jEvvWXZdmwjk+SpuIO62qgrw8ILijlbT+ZfcVv4jLMhYj06f6Gy2nCxTaq4e/jA4AKNFJ9PoW5M4eoLg==; 5:AevNfMBc/xuuoVHQoGioATK8Xsvs3wb3sLqz+SjlxmcqWVzr8HhqjJTZGfCqcYXkKqpMmT3olu2jhoQUwMbJ3dCxaUJNHPRHSFRM90jLbk2BopqesDelsLtdb81rLhPf+ApUUI5VjfkXzBoJpXozlzqEirIZrFd2t28B+JaTz+M=; 7:sg2OvwgViELzIS0tAVQJ11gDB8lOGQKLwg0OBDIpmvAEb8uxyw5rdy0Rqs/LqHBEg/OXHAh8jXPUqVqnmuOezNRrcyi9gT2cJF4f3ZcwxuEBqAFBiV4dtaYngAmKN44/IyiifEk33rcU9GmmlXVg1w== x-ms-office365-filtering-correlation-id: 410504af-8dde-4151-a19f-08d6434fc124 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(5600074)(711020)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020); SRVR:DM6PR01MB3673; x-ms-traffictypediagnostic: DM6PR01MB3673: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(192374486261705)(163750095850)(85827821059158); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(10201501046)(3002001)(93006095)(93001095)(3231382)(944501410)(52105095)(148016)(149066)(150057)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(20161123562045)(20161123558120)(201708071742011)(7699051)(76991095); SRVR:DM6PR01MB3673; BCL:0; PCL:0; RULEID:; SRVR:DM6PR01MB3673; x-forefront-prvs: 08476BC6EF x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(39840400004)(396003)(136003)(366004)(346002)(376002)(199004)(189003)(476003)(76176011)(68736007)(446003)(14444005)(14454004)(186003)(7416002)(6436002)(3846002)(26005)(486006)(6116002)(478600001)(6486002)(2906002)(256004)(2900100001)(305945005)(7736002)(54906003)(8676002)(81166006)(66066001)(110136005)(316002)(81156014)(1076002)(6512007)(2616005)(11346002)(71190400001)(52116002)(102836004)(386003)(71200400001)(105586002)(106356001)(2501003)(8936002)(97736004)(5660300001)(39060400002)(25786009)(6506007)(4326008)(53936002)(86362001)(99286004); DIR:OUT; SFP:1102; SCL:1; SRVR:DM6PR01MB3673; H:DM6PR01MB4825.prod.exchangelabs.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:0; MX:1; received-spf: None (protection.outlook.com: os.amperecomputing.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: H4JzFrDksR0krVNsGPee8rqT6364dMYDVeUmm4cN7By4qT1paYRzXLmcd13hprVpyXkFe/ojbFAfEjRwQWKOMmEFlpqHu71l4bUlqKkTeGSAaWTY2v2L/WrTFSlg83vaE3tITM0h2F5flUGT98imZwq9KakKjrGRsHIKmRPK5KdMv39z/qptTDt2muwfaH4ktEAPLPf3Z2DycqN8d3O/AdupPspr/Qs6FvHlXeNfYMFvxoEGXP28HfdsUByWWzj/0ex7fhipstBpQTv3CLxzxttbyY5+NArxuegduUy+/lyBsSluZNh9lIxAvqxiPIiG8rk+QU8j2XfbjuoTYvClvZ8NdjC8IrSSoi/iHyFPXYU= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 410504af-8dde-4151-a19f-08d6434fc124 X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Nov 2018 18:51:54.2805 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR01MB3673 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.74.130 Subject: [Qemu-devel] [PATCH v7 04/12] target/arm: Filter cycle counter based on PMCCFILTR_EL0 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Spradling , Digant Desai , "qemu-devel@nongnu.org" , Aaron Lindsay , Aaron Lindsay Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Rename arm_ccnt_enabled to pmu_counter_enabled, and add logic to only return 'true' if the specified counter is enabled and neither prohibited or filtered. Signed-off-by: Aaron Lindsay Signed-off-by: Aaron Lindsay Reviewed-by: Peter Maydell Reviewed-by: Richard Henderson --- target/arm/cpu.c | 3 ++ target/arm/cpu.h | 10 ++++- target/arm/helper.c | 96 +++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 101 insertions(+), 8 deletions(-) diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 784a4c2dfc..9e54c56379 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -957,6 +957,9 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) if (!cpu->has_pmu) { unset_feature(env, ARM_FEATURE_PMU); cpu->id_aa64dfr0 &= ~0xf00; + } else if (!kvm_enabled()) { + arm_register_pre_el_change_hook(cpu, &pmu_pre_el_change, 0); + arm_register_el_change_hook(cpu, &pmu_post_el_change, 0); } if (!arm_feature(env, ARM_FEATURE_EL2)) { diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 50a0862c84..92282cd976 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -985,6 +985,12 @@ void pmccntr_op_finish(CPUARMState *env); void pmu_op_start(CPUARMState *env); void pmu_op_finish(CPUARMState *env); +/** + * Functions to register as EL change hooks for PMU mode filtering + */ +void pmu_pre_el_change(ARMCPU *cpu, void *ignored); +void pmu_post_el_change(ARMCPU *cpu, void *ignored); + /* SCTLR bit meanings. Several bits have been reused in newer * versions of the architecture; in that case we define constants * for both old and new bit meanings. Code which tests against those @@ -1046,7 +1052,8 @@ void pmu_op_finish(CPUARMState *env); #define MDCR_EPMAD (1U << 21) #define MDCR_EDAD (1U << 20) -#define MDCR_SPME (1U << 17) +#define MDCR_SPME (1U << 17) /* MDCR_EL3 */ +#define MDCR_HPMD (1U << 17) /* MDCR_EL2 */ #define MDCR_SDD (1U << 16) #define MDCR_SPD (3U << 14) #define MDCR_TDRA (1U << 11) @@ -1056,6 +1063,7 @@ void pmu_op_finish(CPUARMState *env); #define MDCR_HPME (1U << 7) #define MDCR_TPM (1U << 6) #define MDCR_TPMCR (1U << 5) +#define MDCR_HPMN (0x1fU) /* Not all of the MDCR_EL3 bits are present in the 32-bit SDCR */ #define SDCR_VALID_MASK (MDCR_EPMAD | MDCR_EDAD | MDCR_SPME | MDCR_SPD) diff --git a/target/arm/helper.c b/target/arm/helper.c index 5deff3d11f..63d4e993f4 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -976,10 +976,24 @@ static const ARMCPRegInfo v6_cp_reginfo[] = { /* Definitions for the PMU registers */ #define PMCRN_MASK 0xf800 #define PMCRN_SHIFT 11 +#define PMCRDP 0x10 #define PMCRD 0x8 #define PMCRC 0x4 #define PMCRE 0x1 +#define PMXEVTYPER_P 0x80000000 +#define PMXEVTYPER_U 0x40000000 +#define PMXEVTYPER_NSK 0x20000000 +#define PMXEVTYPER_NSU 0x10000000 +#define PMXEVTYPER_NSH 0x08000000 +#define PMXEVTYPER_M 0x04000000 +#define PMXEVTYPER_MT 0x02000000 +#define PMXEVTYPER_EVTCOUNT 0x0000ffff +#define PMXEVTYPER_MASK (PMXEVTYPER_P | PMXEVTYPER_U | PMXEVTYPER_NSK | \ + PMXEVTYPER_NSU | PMXEVTYPER_NSH | \ + PMXEVTYPER_M | PMXEVTYPER_MT | \ + PMXEVTYPER_EVTCOUNT) + static inline uint32_t pmu_num_counters(CPUARMState *env) { return (env->cp15.c9_pmcr & PMCRN_MASK) >> PMCRN_SHIFT; @@ -1075,16 +1089,66 @@ static CPAccessResult pmreg_access_ccntr(CPUARMState *env, return pmreg_access(env, ri, isread); } -static inline bool arm_ccnt_enabled(CPUARMState *env) +/* Returns true if the counter (pass 31 for PMCCNTR) should count events using + * the current EL, security state, and register configuration. + */ +static bool pmu_counter_enabled(CPUARMState *env, uint8_t counter) { - /* This does not support checking PMCCFILTR_EL0 register */ + uint64_t filter; + bool e, p, u, nsk, nsu, nsh, m; + bool enabled, prohibited, filtered; + bool secure = arm_is_secure(env); + int el = arm_current_el(env); + uint8_t hpmn = env->cp15.mdcr_el2 & MDCR_HPMN; - if (!(env->cp15.c9_pmcr & PMCRE) || !(env->cp15.c9_pmcnten & (1 << 31))) { - return false; + if (!arm_feature(env, ARM_FEATURE_EL2) || + (counter < hpmn || counter == 31)) { + e = env->cp15.c9_pmcr & PMCRE; + } else { + e = env->cp15.mdcr_el2 & MDCR_HPME; } + enabled = e && (env->cp15.c9_pmcnten & (1 << counter)); - return true; + if (!secure) { + if (el == 2 && (counter < hpmn || counter == 31)) { + prohibited = env->cp15.mdcr_el2 & MDCR_HPMD; + } else { + prohibited = false; + } + } else { + prohibited = arm_feature(env, ARM_FEATURE_EL3) && + (env->cp15.mdcr_el3 & MDCR_SPME); + } + + if (prohibited && counter == 31) { + prohibited = env->cp15.c9_pmcr & PMCRDP; + } + + /* TODO Remove assert, set filter to correct PMEVTYPER */ + assert(counter == 31); + filter = env->cp15.pmccfiltr_el0; + + p = filter & PMXEVTYPER_P; + u = filter & PMXEVTYPER_U; + nsk = arm_feature(env, ARM_FEATURE_EL3) && (filter & PMXEVTYPER_NSK); + nsu = arm_feature(env, ARM_FEATURE_EL3) && (filter & PMXEVTYPER_NSU); + nsh = arm_feature(env, ARM_FEATURE_EL2) && (filter & PMXEVTYPER_NSH); + m = arm_el_is_aa64(env, 1) && + arm_feature(env, ARM_FEATURE_EL3) && (filter & PMXEVTYPER_M); + + if (el == 0) { + filtered = secure ? u : u != nsu; + } else if (el == 1) { + filtered = secure ? p : p != nsk; + } else if (el == 2) { + filtered = !nsh; + } else { /* EL3 */ + filtered = m != p; + } + + return enabled && !prohibited && !filtered; } + /* * Ensure c15_ccnt is the guest-visible count so that operations such as * enabling/disabling the counter or filtering, modifying the count itself, @@ -1097,7 +1161,7 @@ void pmccntr_op_start(CPUARMState *env) cycles = muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), ARM_CPU_FREQ, NANOSECONDS_PER_SECOND); - if (arm_ccnt_enabled(env)) { + if (pmu_counter_enabled(env, 31)) { uint64_t eff_cycles = cycles; if (env->cp15.c9_pmcr & PMCRD) { /* Increment once every 64 processor clock cycles */ @@ -1116,7 +1180,7 @@ void pmccntr_op_start(CPUARMState *env) */ void pmccntr_op_finish(CPUARMState *env) { - if (arm_ccnt_enabled(env)) { + if (pmu_counter_enabled(env, 31)) { uint64_t prev_cycles = env->cp15.c15_ccnt_delta; if (env->cp15.c9_pmcr & PMCRD) { @@ -1138,6 +1202,16 @@ void pmu_op_finish(CPUARMState *env) pmccntr_op_finish(env); } +void pmu_pre_el_change(ARMCPU *cpu, void *ignored) +{ + pmu_op_start(&cpu->env); +} + +void pmu_post_el_change(ARMCPU *cpu, void *ignored) +{ + pmu_op_finish(&cpu->env); +} + static void pmcr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value) { @@ -1209,6 +1283,14 @@ void pmu_op_finish(CPUARMState *env) { } +void pmu_pre_el_change(ARMCPU *cpu, void *ignored) +{ +} + +void pmu_post_el_change(ARMCPU *cpu, void *ignored) +{ +} + #endif static void pmccfiltr_write(CPUARMState *env, const ARMCPRegInfo *ri, From patchwork Mon Nov 5 18:51:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Lindsay X-Patchwork-Id: 10668939 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 04C8313BF for ; Mon, 5 Nov 2018 18:56:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E96C629973 for ; Mon, 5 Nov 2018 18:56:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DD85329AA9; Mon, 5 Nov 2018 18:56:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 57717299BF for ; Mon, 5 Nov 2018 18:56:17 +0000 (UTC) Received: from localhost ([::1]:37134 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJk2q-0001r6-J8 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 05 Nov 2018 13:56:16 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46550) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJjyo-0004c5-Vk for qemu-devel@nongnu.org; Mon, 05 Nov 2018 13:52:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gJjyn-0000Xe-48 for qemu-devel@nongnu.org; Mon, 05 Nov 2018 13:52:06 -0500 Received: from mail-eopbgr740130.outbound.protection.outlook.com ([40.107.74.130]:9824 helo=NAM01-BN3-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gJjyg-0000P9-LW; Mon, 05 Nov 2018 13:52:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amperemail.onmicrosoft.com; s=selector1-os-amperecomputing-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xr1uka41gh1Lvn5XkAnl2B9fwjoZets/wSBpA7k77Yo=; b=h5NAzjRvJ/mxIufy6KO0uJy3/XDGAHuLvRHYtp+3n+eVsW37K3qIZQP1tl3q/dW2v4JmkY9wNYGKRuhHrwSsPvNZKMsxpTUMEpE392j9Zf3GezL2lOiYtZQ9aqKlpjm8g4tvw7JOjcsKvgEcz8kKxxreU4/ARBo7ykGlculeC1s= Received: from DM6PR01MB4825.prod.exchangelabs.com (20.177.218.222) by DM6PR01MB3673.prod.exchangelabs.com (20.176.64.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.26; Mon, 5 Nov 2018 18:51:55 +0000 Received: from DM6PR01MB4825.prod.exchangelabs.com ([fe80::4cf7:c8dc:b673:ec66]) by DM6PR01MB4825.prod.exchangelabs.com ([fe80::4cf7:c8dc:b673:ec66%3]) with mapi id 15.20.1294.028; Mon, 5 Nov 2018 18:51:55 +0000 From: Aaron Lindsay To: "qemu-arm@nongnu.org" , Peter Maydell , Alistair Francis , Wei Huang , Peter Crosthwaite , Richard Henderson Thread-Topic: [PATCH v7 05/12] target/arm: Allow AArch32 access for PMCCFILTR Thread-Index: AQHUdTif3JbBpsFViE2iBtfPd5pQQA== Date: Mon, 5 Nov 2018 18:51:55 +0000 Message-ID: <20181105185046.2802-6-aaron@os.amperecomputing.com> References: <20181105185046.2802-1-aaron@os.amperecomputing.com> In-Reply-To: <20181105185046.2802-1-aaron@os.amperecomputing.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BN6PR20CA0070.namprd20.prod.outlook.com (2603:10b6:404:151::32) To DM6PR01MB4825.prod.exchangelabs.com (2603:10b6:5:6b::30) authentication-results: spf=none (sender IP is ) smtp.mailfrom=aaron@os.amperecomputing.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [216.85.170.153] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DM6PR01MB3673; 6:hT8wh5Mdi5OAD/C3UEQkPhjwaCOF9NuYp7xRzfL8Jpc0ULEaWM7oH6LRQwGmnmrl8gP/F6HK7csd63zfydcL/HTKonhhvkDS/JUinGerYTVg73/u/kgsurRbtSgnmpW29yQV3NQP5wZexr7FgKL2qoy8bw5TOMsTiLblkb+MzzJgog673Vdf0Tv77Wvll2jPTkrESPu+fGIC1lqt9OSayQD7d+kpter47YzveE6T69RJt+Wb22u4zoO2exManZjGKmjZwvMtcnP+2PK2/bdsVrOMsKFrxUeL1K7R/ocaBZmvMTj+3e8oso7xD/zOk2PUabexOFtw9C/sAVQqVCzzx0pxtpF881JdPnnahoJzVS6wlUMNOPu7x8+f/tv9p2DPHuqh9taRVOVpJDcPeMp6EaxhydwKOxUKA3sjMphVnA0YmCe5PtXWJ20nJ1cJLXep5fYUp2JeZhe3Jtjou25qKA==; 5:S8W8WEWYNjkQuB8Sq8gLaFc0l6OGsPNrVCzfSVSzfgrBu9rfmowdjaB0UTLL1cEc52dgKoGB17h7SSFZXiWh7zutGKBCN/r5uywLlMDa+CG/AAZ60LpgCtTOQ01DYWcrjAuqDF7sDBj8OIkAkzKv/6SFQ4HICOFYUdpP0RN/hr0=; 7:uqD+3YpFTdPrMPkci6L+NdUoUjvcx4X77r5WfeS/oG3INbjuSSpkkj0GepRHslnSnyUjmQ65RVDBF9SEHdZV8GiT03RuSgsF9tg8oid+5U+SjWijV+58XJom1EOEjQPLF4TbvG6NNE7k8lc+2BGaTw== x-ms-office365-filtering-correlation-id: 3bab5b65-fe24-4c54-ffd8-08d6434fc1c9 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(5600074)(711020)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020); SRVR:DM6PR01MB3673; x-ms-traffictypediagnostic: DM6PR01MB3673: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(10201501046)(3002001)(93006095)(93001095)(3231382)(944501410)(52105095)(148016)(149066)(150057)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(20161123562045)(20161123558120)(201708071742011)(7699051)(76991095); SRVR:DM6PR01MB3673; BCL:0; PCL:0; RULEID:; SRVR:DM6PR01MB3673; x-forefront-prvs: 08476BC6EF x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(39840400004)(396003)(136003)(366004)(346002)(376002)(199004)(189003)(476003)(76176011)(68736007)(446003)(14444005)(14454004)(186003)(7416002)(6436002)(3846002)(26005)(486006)(6116002)(478600001)(6486002)(2906002)(256004)(2900100001)(305945005)(7736002)(54906003)(8676002)(81166006)(66066001)(110136005)(316002)(81156014)(1076002)(6512007)(2616005)(11346002)(71190400001)(52116002)(102836004)(386003)(71200400001)(105586002)(106356001)(2501003)(8936002)(97736004)(5660300001)(39060400002)(25786009)(6506007)(4326008)(53936002)(86362001)(99286004); DIR:OUT; SFP:1102; SCL:1; SRVR:DM6PR01MB3673; H:DM6PR01MB4825.prod.exchangelabs.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:0; MX:1; received-spf: None (protection.outlook.com: os.amperecomputing.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: HiZ/f7uxry3Hi4xkzdfb/rhJAoSioo3P0yvgqO06fLTVEtdhrY6Z7xs6KzEElm1h7IABr6fxegKL+Xlrhucej9PsCk/o44/4wI9aF9MiTJfQENNEpoor85t6Itmcdezv1R/x762tn6ECTRkPyKriNr+m7spOYNI1x0sl49rt5jpw550zBwuaawsuRoGxbwD/hWA8dV79yBnNG9ls91QZMzBS9YDRFYp2BbuNmByO7iicdm0Etm3zj7uMZ43iM4lYABHZLBGoWhtzd3uf/Q6lcfLFqXB1Z+iNYHMzDcUEN8AwFwXnV3k45LoVaUdx67OSB/ypbF2JjnCWVLzeQ6hlQuUIOeuwEl0U5u1vBvwzE38= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3bab5b65-fe24-4c54-ffd8-08d6434fc1c9 X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Nov 2018 18:51:55.3823 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR01MB3673 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.74.130 Subject: [Qemu-devel] [PATCH v7 05/12] target/arm: Allow AArch32 access for PMCCFILTR X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Aaron Lindsay , Michael Spradling , "qemu-devel@nongnu.org" , Digant Desai Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Aaron Lindsay Reviewed-by: Peter Maydell Reviewed-by: Richard Henderson --- target/arm/helper.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/target/arm/helper.c b/target/arm/helper.c index 63d4e993f4..0522a606a4 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -994,6 +994,10 @@ static const ARMCPRegInfo v6_cp_reginfo[] = { PMXEVTYPER_M | PMXEVTYPER_MT | \ PMXEVTYPER_EVTCOUNT) +#define PMCCFILTR 0xf8000000 +#define PMCCFILTR_M PMXEVTYPER_M +#define PMCCFILTR_EL0 (PMCCFILTR | PMCCFILTR_M) + static inline uint32_t pmu_num_counters(CPUARMState *env) { return (env->cp15.c9_pmcr & PMCRN_MASK) >> PMCRN_SHIFT; @@ -1297,10 +1301,26 @@ static void pmccfiltr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value) { pmccntr_op_start(env); - env->cp15.pmccfiltr_el0 = value & 0xfc000000; + env->cp15.pmccfiltr_el0 = value & PMCCFILTR_EL0; + pmccntr_op_finish(env); +} + +static void pmccfiltr_write_a32(CPUARMState *env, const ARMCPRegInfo *ri, + uint64_t value) +{ + pmccntr_op_start(env); + /* M is not accessible from AArch32 */ + env->cp15.pmccfiltr_el0 = (env->cp15.pmccfiltr_el0 & PMCCFILTR_M) | + (value & PMCCFILTR); pmccntr_op_finish(env); } +static uint64_t pmccfiltr_read_a32(CPUARMState *env, const ARMCPRegInfo *ri) +{ + /* M is not visible in AArch32 */ + return env->cp15.pmccfiltr_el0 & PMCCFILTR; +} + static void pmcntenset_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value) { @@ -1536,6 +1556,11 @@ static const ARMCPRegInfo v7_cp_reginfo[] = { .readfn = pmccntr_read, .writefn = pmccntr_write, .raw_readfn = raw_read, .raw_writefn = raw_write, }, #endif + { .name = "PMCCFILTR", .cp = 15, .opc1 = 0, .crn = 14, .crm = 15, .opc2 = 7, + .writefn = pmccfiltr_write_a32, .readfn = pmccfiltr_read_a32, + .access = PL0_RW, .accessfn = pmreg_access, + .type = ARM_CP_ALIAS | ARM_CP_IO, + .resetvalue = 0, }, { .name = "PMCCFILTR_EL0", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 3, .crn = 14, .crm = 15, .opc2 = 7, .writefn = pmccfiltr_write, .raw_writefn = raw_write, From patchwork Mon Nov 5 18:51:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Lindsay X-Patchwork-Id: 10668941 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5595317D4 for ; Mon, 5 Nov 2018 18:56:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 47190299BF for ; Mon, 5 Nov 2018 18:56:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3A7C229AA9; Mon, 5 Nov 2018 18:56:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B153A29AB8 for ; Mon, 5 Nov 2018 18:56:31 +0000 (UTC) Received: from localhost ([::1]:37135 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJk35-00021c-0t for patchwork-qemu-devel@patchwork.kernel.org; Mon, 05 Nov 2018 13:56:31 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46650) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJjz7-0004tw-Ju for qemu-devel@nongnu.org; Mon, 05 Nov 2018 13:52:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gJjyx-0000iP-AC for qemu-devel@nongnu.org; Mon, 05 Nov 2018 13:52:17 -0500 Received: from mail-eopbgr740130.outbound.protection.outlook.com ([40.107.74.130]:9824 helo=NAM01-BN3-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gJjyl-0000P9-It; Mon, 05 Nov 2018 13:52:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amperemail.onmicrosoft.com; s=selector1-os-amperecomputing-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VPXd9MWghnIzR5xY8zDFivqOeaaw3nTLqLMlwfGeAI0=; b=Ee/qGTTG2j8Uqi3HonFd6nWEGNYV8gQYuvDxqIie0Abx5FaDYIk3BtIpNygZsb3gAbmTDBvo+4sdA7I8OeaflP0JTRnioc0v26vrzI8WjRrCS4rzfpdJX0OniVOE+0IHzdNAE9e7UAAWjFsxBtm6fRzcP0ssKeUwMd9htDcOWP4= Received: from DM6PR01MB4825.prod.exchangelabs.com (20.177.218.222) by DM6PR01MB3673.prod.exchangelabs.com (20.176.64.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.26; Mon, 5 Nov 2018 18:51:56 +0000 Received: from DM6PR01MB4825.prod.exchangelabs.com ([fe80::4cf7:c8dc:b673:ec66]) by DM6PR01MB4825.prod.exchangelabs.com ([fe80::4cf7:c8dc:b673:ec66%3]) with mapi id 15.20.1294.028; Mon, 5 Nov 2018 18:51:56 +0000 From: Aaron Lindsay To: "qemu-arm@nongnu.org" , Peter Maydell , Alistair Francis , Wei Huang , Peter Crosthwaite , Richard Henderson Thread-Topic: [PATCH v7 06/12] target/arm: Implement PMOVSSET Thread-Index: AQHUdTigfZ68J2Z5mEy9PN0mUl5ylg== Date: Mon, 5 Nov 2018 18:51:56 +0000 Message-ID: <20181105185046.2802-7-aaron@os.amperecomputing.com> References: <20181105185046.2802-1-aaron@os.amperecomputing.com> In-Reply-To: <20181105185046.2802-1-aaron@os.amperecomputing.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BN6PR20CA0070.namprd20.prod.outlook.com (2603:10b6:404:151::32) To DM6PR01MB4825.prod.exchangelabs.com (2603:10b6:5:6b::30) authentication-results: spf=none (sender IP is ) smtp.mailfrom=aaron@os.amperecomputing.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [216.85.170.153] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DM6PR01MB3673; 6:LPxtb98pNRjH+n2OtAktiZhRVvyVzWUUBoVZdPwYJY/23n/kAVarNm5KnxFDqdol5ZJa6N1g876MgFj8Dz47RQMCd0Bk7xTx5EBc8GE914jzuGQtetuclyZgr86Fi4lUwZ0UkRgF+LiJsHkznIYrwp/LMoM8uVRHVI8Z8kOFohFOxmQYuw8Ne4DSs5bLHoYG53gdWUiRsR7Fi3ptq8kEjPMAlFmKp/jmyd02Wj4UHIDs3HQA/OVB7B27z2eB+aJ3ZDu8zG1wEXrgpdPncu0fAebbgqfMIrTlv9nigncSoUgHUZbluGbBBNJFKhGt/cVaYb2C2jLrvqfPz41GX2c68+s5O0u5twmwro8hLqfjAvziYCh1DcryWsbRkFFGgKRsXBFMJ0mx5j1SG1FDASAYIqWJw+oYLH5eKMxOAaDk9yUgkmC3KsQB0RyFyYxC9kl1fRkh83YsMO/57DqQF4fEbQ==; 5:2L9Ss5SvNifzDK/vRrgBJg4U5mFlR3SWgIJF9XdjN7WaU4EsI2/QT787koz5rC2mw/UlUij9/q+Q1WiFdUcqDau/H2/k9MOXpom3APujmXzuCeT5Ze3LxNdEoURZT4wOzlk9asOLZjeq3Igk6PkYkIzNBf2XviGnMRke3Eqt3nY=; 7:tkRvyFc9Ol//iqn1Ze1sYQgjJlm69rNyKdYg5RaCwb1jDaro2uz5mX958WwZ+ZfaKwBo5qlSCPuA7zMZVldx2uXH7agdF8TwUKW2uHTqKGs562ySARcoKNXPOMvHtyNLhbPnHU0RVg9kK7lvX6MjbQ== x-ms-office365-filtering-correlation-id: 6f8e55e2-790b-4c39-79ad-08d6434fc275 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(5600074)(711020)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020); SRVR:DM6PR01MB3673; x-ms-traffictypediagnostic: DM6PR01MB3673: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(10201501046)(3002001)(93006095)(93001095)(3231382)(944501410)(52105095)(148016)(149066)(150057)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(20161123562045)(20161123558120)(201708071742011)(7699051)(76991095); SRVR:DM6PR01MB3673; BCL:0; PCL:0; RULEID:; SRVR:DM6PR01MB3673; x-forefront-prvs: 08476BC6EF x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(39840400004)(396003)(136003)(366004)(346002)(376002)(199004)(189003)(476003)(76176011)(68736007)(446003)(14444005)(14454004)(186003)(7416002)(6436002)(3846002)(26005)(486006)(6116002)(478600001)(6486002)(2906002)(256004)(2900100001)(305945005)(7736002)(54906003)(8676002)(81166006)(66066001)(110136005)(316002)(81156014)(1076002)(6512007)(2616005)(11346002)(71190400001)(52116002)(102836004)(386003)(71200400001)(105586002)(106356001)(2501003)(8936002)(97736004)(5660300001)(39060400002)(25786009)(6506007)(4326008)(53936002)(86362001)(99286004); DIR:OUT; SFP:1102; SCL:1; SRVR:DM6PR01MB3673; H:DM6PR01MB4825.prod.exchangelabs.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:0; MX:1; received-spf: None (protection.outlook.com: os.amperecomputing.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: 6BTXApQvmnflcbEAEg0tmeIzRxTeLEmfXckveAaYpjaHWWFw6xNOS92WzNt2beok2LqENMubwbZnK9ZTKZ0HjM4NdY6FoWYajvpCgQNwCwKkvyvl6myI8U0IeBDHmn22pIB1f7+LTXtsBdQCTaU9ZGAOcO0MfQ5LaE+Zz6vf4n8zkBQbv1RoHgvllELaVk6n3SJ8xFYJ0O9b4hycqWB9V8s0CeD96openg0uZghcZTOTB4+Qa985uzFL4fjMCCBRuZfby/sjxBtVGsNsmHCKDa/J/uNmIFzNsmglbdgKQ7dSG6a8jPe+2ojan26oXzQXgz3/O0kN8Bk7fnlYDhOYsOMFG+jSAZo+MF1isR8+t30= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6f8e55e2-790b-4c39-79ad-08d6434fc275 X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Nov 2018 18:51:56.6532 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR01MB3673 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.74.130 Subject: [Qemu-devel] [PATCH v7 06/12] target/arm: Implement PMOVSSET X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Aaron Lindsay , Michael Spradling , "qemu-devel@nongnu.org" , Digant Desai Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add an array for PMOVSSET so we only define it for v7ve+ platforms Signed-off-by: Aaron Lindsay Reviewed-by: Richard Henderson --- target/arm/helper.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/target/arm/helper.c b/target/arm/helper.c index 0522a606a4..6724d97346 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -1342,6 +1342,13 @@ static void pmovsr_write(CPUARMState *env, const ARMCPRegInfo *ri, env->cp15.c9_pmovsr &= ~value; } +static void pmovsset_write(CPUARMState *env, const ARMCPRegInfo *ri, + uint64_t value) +{ + value &= pmu_counter_mask(env); + env->cp15.c9_pmovsr |= value; +} + static void pmxevtyper_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value) { @@ -1709,6 +1716,24 @@ static const ARMCPRegInfo v7mp_cp_reginfo[] = { REGINFO_SENTINEL }; +static const ARMCPRegInfo pmovsset_cp_reginfo[] = { + /* PMOVSSET is not implemented in v7 before v7ve */ + { .name = "PMOVSSET", .cp = 15, .opc1 = 0, .crn = 9, .crm = 14, .opc2 = 3, + .access = PL0_RW, .accessfn = pmreg_access, + .type = ARM_CP_ALIAS, + .fieldoffset = offsetoflow32(CPUARMState, cp15.c9_pmovsr), + .writefn = pmovsset_write, + .raw_writefn = raw_write }, + { .name = "PMOVSSET_EL0", .state = ARM_CP_STATE_AA64, + .opc0 = 3, .opc1 = 3, .crn = 9, .crm = 14, .opc2 = 3, + .access = PL0_RW, .accessfn = pmreg_access, + .type = ARM_CP_ALIAS, + .fieldoffset = offsetof(CPUARMState, cp15.c9_pmovsr), + .writefn = pmovsset_write, + .raw_writefn = raw_write }, + REGINFO_SENTINEL +}; + static void teecr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value) { @@ -5212,6 +5237,9 @@ void register_cp_regs_for_features(ARMCPU *cpu) !arm_feature(env, ARM_FEATURE_PMSA)) { define_arm_cp_regs(cpu, v7mp_cp_reginfo); } + if (arm_feature(env, ARM_FEATURE_V7VE)) { + define_arm_cp_regs(cpu, pmovsset_cp_reginfo); + } if (arm_feature(env, ARM_FEATURE_V7)) { /* v7 performance monitor control register: same implementor * field as main ID register, and we implement only the cycle From patchwork Mon Nov 5 18:51:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Lindsay X-Patchwork-Id: 10668949 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E855A17D4 for ; Mon, 5 Nov 2018 19:01:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D91E229BD4 for ; Mon, 5 Nov 2018 19:01:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CCB3329B98; Mon, 5 Nov 2018 19:01:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1658F29BCA for ; Mon, 5 Nov 2018 19:01:29 +0000 (UTC) Received: from localhost ([::1]:37171 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJk7s-0007SB-6z for patchwork-qemu-devel@patchwork.kernel.org; Mon, 05 Nov 2018 14:01:28 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46679) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJjzI-00055q-Dr for qemu-devel@nongnu.org; Mon, 05 Nov 2018 13:52:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gJjz3-0000rH-G5 for qemu-devel@nongnu.org; Mon, 05 Nov 2018 13:52:32 -0500 Received: from mail-cys01nam02on0099.outbound.protection.outlook.com ([104.47.37.99]:43926 helo=NAM02-CY1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gJjyl-0000UT-Db; Mon, 05 Nov 2018 13:52:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amperemail.onmicrosoft.com; s=selector1-os-amperecomputing-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GkhnMjGrnkzszgC1O/yxKoBwoGluH73nLUlE9srhCwc=; b=ev2dju0QE36a33K2Qx/BOziUTjBvafKzOptIyeYxFZWVL7MDzHppcdrG6DJppTQRRqEUFCJCrLKiD74oUAnzQ4EQdJhgeRH+kD6kTfikyXSf/Yeqcfg+91c5/kADyN2pFHNfnJTxLBNMbEOOYolVdQzFB0e4hVajv0V7jksJXII= Received: from DM6PR01MB4825.prod.exchangelabs.com (20.177.218.222) by DM6PR01MB5194.prod.exchangelabs.com (20.176.122.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.21; Mon, 5 Nov 2018 18:51:57 +0000 Received: from DM6PR01MB4825.prod.exchangelabs.com ([fe80::4cf7:c8dc:b673:ec66]) by DM6PR01MB4825.prod.exchangelabs.com ([fe80::4cf7:c8dc:b673:ec66%3]) with mapi id 15.20.1294.028; Mon, 5 Nov 2018 18:51:57 +0000 From: Aaron Lindsay To: "qemu-arm@nongnu.org" , Peter Maydell , Alistair Francis , Wei Huang , Peter Crosthwaite , Richard Henderson Thread-Topic: [PATCH v7 07/12] target/arm: Add array for supported PMU events, generate PMCEID[01] Thread-Index: AQHUdTigFzoivX0Aakiay0YA2QVOXQ== Date: Mon, 5 Nov 2018 18:51:57 +0000 Message-ID: <20181105185046.2802-8-aaron@os.amperecomputing.com> References: <20181105185046.2802-1-aaron@os.amperecomputing.com> In-Reply-To: <20181105185046.2802-1-aaron@os.amperecomputing.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BN6PR20CA0070.namprd20.prod.outlook.com (2603:10b6:404:151::32) To DM6PR01MB4825.prod.exchangelabs.com (2603:10b6:5:6b::30) authentication-results: spf=none (sender IP is ) smtp.mailfrom=aaron@os.amperecomputing.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [216.85.170.153] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DM6PR01MB5194; 6:HfHjPMegfGnU5ksABEirtvjuDSf1dcz49z/3jWpn7OkirVylj4JFSTBtNfkSgExLrxUQ6v9Ew0hbZBxG9yyFvubtyqPqAoTDSD06lu1CAomEw7tq6ZOy4fNUcd4ORGHdsoDkHi/K8f81Gf7BM0YMp+iUjuu5nZbYyz62Z1Z1AXj8IZFRbKkuwStneW1238bsAqseJSUXN+xTPZs3RQUXHo9CIfKLVnFO3BedwiBFEIuO5L5kp+v/pT0qe1xcMCFmKU4hrWJE8O70DumrC3xfmsDti6SEecCTfOOVN2b+fXAGCHKFuYBeuG/o1NM9OKNFrO9O+MRQv3b1/gSnZr7zievtAsvwP2ucZweItAhMMzg0J+xNgbkdsSp/RhWiZ39iAGu3BxCfkVa5CWooNVYp8kByWoCfZlx3PppkY1Or/r0AmO/3HI/i9wXCxO9v3kURctnsJLCFWJl8Ug+bs11h0A==; 5:cRUsGoVsjeG4C6lHaPvYicMHZ/v+TeXobmAH9NdNB6KENlX5YA+NHCNA5yBAAJ0hssgtk0b0OM1rJZMax18qo3qeP76RNMZPQTz3DZi0JPlhjYYyiinDD0xtVVUIDz0JTvFOGzpH8chbTL9jV27bFOAO5NGk3Sp2PWjRQ2vt+AE=; 7:PXLY8F1MT4Up5d6FV2laAvVkl262627bqXFZdMeVEf7BE7FUArhYIPvlIwAZFrFU+sOTwyxlihj6WmXxEtuFsI8gLcB6e4LuiwL5espb3WVtNdJZY7dlT/xekLmMQ1cyp9VHPQZOLscZ2jVWAFBDDQ== x-ms-office365-filtering-correlation-id: c234dd27-5754-47d2-082b-08d6434fc33f x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020); SRVR:DM6PR01MB5194; x-ms-traffictypediagnostic: DM6PR01MB5194: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(10201501046)(3002001)(93006095)(93001095)(3231382)(944501410)(52105095)(148016)(149066)(150057)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(20161123562045)(20161123558120)(201708071742011)(7699051)(76991095); SRVR:DM6PR01MB5194; BCL:0; PCL:0; RULEID:; SRVR:DM6PR01MB5194; x-forefront-prvs: 08476BC6EF x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(396003)(346002)(136003)(39840400004)(376002)(366004)(189003)(199004)(81166006)(81156014)(53936002)(66066001)(6436002)(486006)(6486002)(6116002)(14444005)(110136005)(256004)(25786009)(4326008)(54906003)(14454004)(7736002)(305945005)(106356001)(26005)(105586002)(186003)(97736004)(39060400002)(102836004)(8936002)(2900100001)(2501003)(386003)(6506007)(8676002)(7416002)(476003)(316002)(52116002)(6512007)(2616005)(99286004)(76176011)(5660300001)(2906002)(86362001)(68736007)(71200400001)(71190400001)(3846002)(478600001)(446003)(1076002)(11346002); DIR:OUT; SFP:1102; SCL:1; SRVR:DM6PR01MB5194; H:DM6PR01MB4825.prod.exchangelabs.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:0; received-spf: None (protection.outlook.com: os.amperecomputing.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: HipKIp9xMnckmXmcGFSgKd2U58BrXwV71v3cXhv8Ewe/vS4WsfSvlFe3v2iXv3zeDK/vCKI/7LXPWX27FwCYl1ECp03DI06PP0VZs4QoMppjyZw2x9CBYCgOEuHJQZyQmtY4srk3YVAPxJpzfPy9ztIzruitjD6I17oQKAbqALA11SSWkrrnu3pp1pDz2KKAlqH0B/zmOC8J8WNuAaYBh0toWSB9465wctTw3dYVUC0pSWO/aKruXOTg04xF8w3GiYHpLJg7aCeLdbauBNQoTey1xbBhI4dxyxPvW2bxgv5VyMwFqJ7A11cznVnDbuBaxWX/JGcpCo9Lh+tC0hON9WnKJ0MPg831ZO+20W0l/Ic= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: c234dd27-5754-47d2-082b-08d6434fc33f X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Nov 2018 18:51:57.8390 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR01MB5194 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.37.99 Subject: [Qemu-devel] [PATCH v7 07/12] target/arm: Add array for supported PMU events, generate PMCEID[01] X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Aaron Lindsay , Michael Spradling , "qemu-devel@nongnu.org" , Digant Desai Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This commit doesn't add any supported events, but provides the framework for adding them. We store the pm_event structs in a simple array, and provide the mapping from the event numbers to array indexes in the supported_event_map array. Because the value of PMCEID[01] depends upon which events are supported at runtime, generate it dynamically. Signed-off-by: Aaron Lindsay --- target/arm/cpu.c | 20 +++++++++++++------- target/arm/cpu.h | 10 ++++++++++ target/arm/cpu64.c | 4 ---- target/arm/helper.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 11 deletions(-) diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 9e54c56379..d1c766d180 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -957,9 +957,19 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) if (!cpu->has_pmu) { unset_feature(env, ARM_FEATURE_PMU); cpu->id_aa64dfr0 &= ~0xf00; - } else if (!kvm_enabled()) { - arm_register_pre_el_change_hook(cpu, &pmu_pre_el_change, 0); - arm_register_el_change_hook(cpu, &pmu_post_el_change, 0); + } + if (arm_feature(env, ARM_FEATURE_PMU)) { + uint64_t pmceid = get_pmceid(&cpu->env); + cpu->pmceid0 = extract64(pmceid, 0, 32); + cpu->pmceid1 = extract64(pmceid, 32, 32); + + if (!kvm_enabled()) { + arm_register_pre_el_change_hook(cpu, &pmu_pre_el_change, 0); + arm_register_el_change_hook(cpu, &pmu_post_el_change, 0); + } + } else { + cpu->pmceid0 = 0x00000000; + cpu->pmceid1 = 0x00000000; } if (!arm_feature(env, ARM_FEATURE_EL2)) { @@ -1601,8 +1611,6 @@ static void cortex_a7_initfn(Object *obj) cpu->id_pfr0 = 0x00001131; cpu->id_pfr1 = 0x00011011; cpu->id_dfr0 = 0x02010555; - cpu->pmceid0 = 0x00000000; - cpu->pmceid1 = 0x00000000; cpu->id_afr0 = 0x00000000; cpu->id_mmfr0 = 0x10101105; cpu->id_mmfr1 = 0x40000000; @@ -1647,8 +1655,6 @@ static void cortex_a15_initfn(Object *obj) cpu->id_pfr0 = 0x00001131; cpu->id_pfr1 = 0x00011011; cpu->id_dfr0 = 0x02010555; - cpu->pmceid0 = 0x0000000; - cpu->pmceid1 = 0x00000000; cpu->id_afr0 = 0x00000000; cpu->id_mmfr0 = 0x10201105; cpu->id_mmfr1 = 0x20000000; diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 92282cd976..f991ff370e 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -991,6 +991,16 @@ void pmu_op_finish(CPUARMState *env); void pmu_pre_el_change(ARMCPU *cpu, void *ignored); void pmu_post_el_change(ARMCPU *cpu, void *ignored); +/* + * get_pmceid + * @env: CPUARMState + * + * Return the PMCEID[01] register values corresponding to the counters which + * are supported given the current configuration (0 is low 32, 1 is high 32 + * bits) + */ +uint64_t get_pmceid(CPUARMState *env); + /* SCTLR bit meanings. Several bits have been reused in newer * versions of the architecture; in that case we define constants * for both old and new bit meanings. Code which tests against those diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index 873f059bf2..a1aad772fa 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -138,8 +138,6 @@ static void aarch64_a57_initfn(Object *obj) cpu->isar.id_isar6 = 0; cpu->isar.id_aa64pfr0 = 0x00002222; cpu->id_aa64dfr0 = 0x10305106; - cpu->pmceid0 = 0x00000000; - cpu->pmceid1 = 0x00000000; cpu->isar.id_aa64isar0 = 0x00011120; cpu->id_aa64mmfr0 = 0x00001124; cpu->dbgdidr = 0x3516d000; @@ -246,8 +244,6 @@ static void aarch64_a72_initfn(Object *obj) cpu->isar.id_isar5 = 0x00011121; cpu->isar.id_aa64pfr0 = 0x00002222; cpu->id_aa64dfr0 = 0x10305106; - cpu->pmceid0 = 0x00000000; - cpu->pmceid1 = 0x00000000; cpu->isar.id_aa64isar0 = 0x00011120; cpu->id_aa64mmfr0 = 0x00001124; cpu->dbgdidr = 0x3516d000; diff --git a/target/arm/helper.c b/target/arm/helper.c index 6724d97346..b9d8441497 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -1009,6 +1009,48 @@ static inline uint64_t pmu_counter_mask(CPUARMState *env) return (1 << 31) | ((1 << pmu_num_counters(env)) - 1); } +typedef struct pm_event { + uint16_t number; /* PMEVTYPER.evtCount is 16 bits wide */ + /* If the event is supported on this CPU (used to generate PMCEID[01]) */ + bool (*supported)(CPUARMState *); + /* + * Retrieve the current count of the underlying event. The programmed + * counters hold a difference from the return value from this function + */ + uint64_t (*get_count)(CPUARMState *); +} pm_event; + +static const pm_event pm_events[] = { +}; +#define MAX_EVENT_ID 0x0 +#define UNSUPPORTED_EVENT UINT16_MAX +static uint16_t supported_event_map[MAX_EVENT_ID + 1]; + +/* + * Called upon initialization to build PMCEID0 (low 32 bits) and PMCEID1 (high + * 32). We also use it to build a map of ARM event numbers to indices in + * our pm_events array. + */ +uint64_t get_pmceid(CPUARMState *env) +{ + uint64_t pmceid = 0; + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(supported_event_map); i++) { + supported_event_map[i] = UNSUPPORTED_EVENT; + } + + for (i = 0; i < ARRAY_SIZE(pm_events); i++) { + const pm_event *cnt = &pm_events[i]; + assert(cnt->number <= MAX_EVENT_ID); + if (cnt->supported(env)) { + pmceid |= (1 << cnt->number); + supported_event_map[cnt->number] = i; + } + } + return pmceid; +} + static CPAccessResult pmreg_access(CPUARMState *env, const ARMCPRegInfo *ri, bool isread) { From patchwork Mon Nov 5 18:51:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Lindsay X-Patchwork-Id: 10668945 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F142D17D4 for ; Mon, 5 Nov 2018 18:58:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E09892992B for ; Mon, 5 Nov 2018 18:58:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D4CB729974; Mon, 5 Nov 2018 18:58:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B2B202992B for ; Mon, 5 Nov 2018 18:58:43 +0000 (UTC) Received: from localhost ([::1]:37146 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJk5C-0005LF-V7 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 05 Nov 2018 13:58:42 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46680) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJjzI-00055t-E5 for qemu-devel@nongnu.org; Mon, 05 Nov 2018 13:52:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gJjz3-0000rF-Fz for qemu-devel@nongnu.org; Mon, 05 Nov 2018 13:52:32 -0500 Received: from mail-cys01nam02on0099.outbound.protection.outlook.com ([104.47.37.99]:43926 helo=NAM02-CY1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gJjyn-0000UT-Er; Mon, 05 Nov 2018 13:52:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amperemail.onmicrosoft.com; s=selector1-os-amperecomputing-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=H2D6sw7M1tf0FGlfciFc1U7nQt5fwH39+wFUtf8S6oA=; b=idjQ1iS+WtptdTHmYn7RmYN8eSa7qM3JyfbYNVDRuoyj9XB03szKm5vCj8JbV3O+6Ha4McV3BSuJXGBjn3osDGq0V7DBRV32jG399T9Nzvsq6APNFWYegP3tZGDeJSNtkZjeBWdYWbLEBwr9vOgQbjzkr9HK3Q2IEPVU/CQ/LD4= Received: from DM6PR01MB4825.prod.exchangelabs.com (20.177.218.222) by DM6PR01MB5194.prod.exchangelabs.com (20.176.122.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.21; Mon, 5 Nov 2018 18:51:59 +0000 Received: from DM6PR01MB4825.prod.exchangelabs.com ([fe80::4cf7:c8dc:b673:ec66]) by DM6PR01MB4825.prod.exchangelabs.com ([fe80::4cf7:c8dc:b673:ec66%3]) with mapi id 15.20.1294.028; Mon, 5 Nov 2018 18:51:59 +0000 From: Aaron Lindsay To: "qemu-arm@nongnu.org" , Peter Maydell , Alistair Francis , Wei Huang , Peter Crosthwaite , Richard Henderson Thread-Topic: [PATCH v7 08/12] target/arm: Finish implementation of PM[X]EVCNTR and PM[X]EVTYPER Thread-Index: AQHUdTihBOOM77DBnUa0vIMauKNftw== Date: Mon, 5 Nov 2018 18:51:58 +0000 Message-ID: <20181105185046.2802-9-aaron@os.amperecomputing.com> References: <20181105185046.2802-1-aaron@os.amperecomputing.com> In-Reply-To: <20181105185046.2802-1-aaron@os.amperecomputing.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BN6PR20CA0070.namprd20.prod.outlook.com (2603:10b6:404:151::32) To DM6PR01MB4825.prod.exchangelabs.com (2603:10b6:5:6b::30) authentication-results: spf=none (sender IP is ) smtp.mailfrom=aaron@os.amperecomputing.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [216.85.170.153] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DM6PR01MB5194; 6:RqxiA0CoF6o0S4YUH8mAU5oyYRKYR50AcO5yp9LOBkwvabVqP0ktvEjmPVaclG0iCrG5i3rDMlVzgP+Idl1BZ9sXWTwo5zNMCdusSYS+LcUV6fZuKKIM9OeclITUheojloLTm09KXJlckMzB40Pr4r/6NeGt1yaKknkU9VHX5Reb7ZTSRHz5HFg2qYEMsyT05RbaiiFieAexpMIqNpMjkLpnZg9NmDeJ4LUPQ1kiSb/qAmO0/RGwEGhzpDrgP+iKKDprDE+76UJKMNvpGrLSJyPc1aHjgoJPh9MQzobcpk024sJZF0XrsjAdyzg+I16cwvFtq7I05RDrFeMLTW0D3PqfGw7WH7HgeUn6JE9OuXxQhISfYZnNGX2CcUHALQ1VBj4RMj1ePpbdLmWt5sDSH1NrPIZxgnGyX1n6Jhea3TsnwsW6JVWqorU4e/5jGRf9rDZz1T9/CQWjdZyfplke5A==; 5:Wngu6fnUB0qmpPw/7MZNDAMw230K9xW0V/2lfSkvnX67Wdxf5QNZCEHk4ejQmPjMwEfsPHRC1MNw7UnjioHYsu47hpk7fuqpEM3AAHF4Wdr+RL+BUYCsSVq9mPnonTIQUmap5qvoKXsTyc+suTIKWaiGdLRe1pDt4KhWRLYfm6w=; 7:e/vE5icGyOYQAvmfPObC66WQSW5sY1+1O5qNXNzbF7/J6bxyAPmWhl8k2/WABcrU8s/m12+h1IyzuRBI9HdAfmb4juDrHML99VTvcfy8k/FoV9bRMomHPn1ZIUUF2qQv47Mz7hD1SBoW4J112p3+WA== x-ms-office365-filtering-correlation-id: a6053a07-a7fc-4a53-4575-08d6434fc3eb x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020); SRVR:DM6PR01MB5194; x-ms-traffictypediagnostic: DM6PR01MB5194: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(163750095850); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(10201501046)(3002001)(93006095)(93001095)(3231382)(944501410)(52105095)(148016)(149066)(150057)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(20161123562045)(20161123558120)(201708071742011)(7699051)(76991095); SRVR:DM6PR01MB5194; BCL:0; PCL:0; RULEID:; SRVR:DM6PR01MB5194; x-forefront-prvs: 08476BC6EF x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(396003)(346002)(136003)(39840400004)(376002)(366004)(189003)(199004)(81166006)(81156014)(53936002)(53946003)(66066001)(6436002)(486006)(6486002)(6116002)(14444005)(110136005)(256004)(25786009)(4326008)(54906003)(14454004)(7736002)(305945005)(106356001)(26005)(105586002)(186003)(97736004)(39060400002)(102836004)(8936002)(2900100001)(2501003)(386003)(6506007)(8676002)(7416002)(476003)(316002)(52116002)(6512007)(2616005)(99286004)(76176011)(5660300001)(2906002)(86362001)(68736007)(71200400001)(71190400001)(3846002)(478600001)(4744004)(446003)(1076002)(11346002); DIR:OUT; SFP:1102; SCL:1; SRVR:DM6PR01MB5194; H:DM6PR01MB4825.prod.exchangelabs.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:0; received-spf: None (protection.outlook.com: os.amperecomputing.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: GB9RVSZucNkrzavHQBiUdsYG3+QcKMC4ToO/Mkf38LspIXq/CDsM+RMZ2yVDoSQKhq4K39Y4K714trLybaFD9lrTGcJo+RO/RX5qhKPfpzJqVwzB//7x7RG3be50nbDLXNFZa4yuL5OraFrnIwniF921t5ocrHQ6eo8TRF3BBV1Noe0wwXqetYXVgR7hZAPUD4wDyMTUa+bGHZomh8ol8RuSzy6OgiiOjobv/MJln+iFGn9m4aIhzWWMtdOWGnv459BewEt92ODAxQQD0GXBm5P0apjTY8cSRe2rMEiJXjZEi2Jq5Yxba8iZMTzhiaIBOlsumW+qhEV9JNDxuJQIg+DjxYLmDzR2f5tdNwyiScs= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: a6053a07-a7fc-4a53-4575-08d6434fc3eb X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Nov 2018 18:51:58.9618 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR01MB5194 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.37.99 Subject: [Qemu-devel] [PATCH v7 08/12] target/arm: Finish implementation of PM[X]EVCNTR and PM[X]EVTYPER X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Aaron Lindsay , Michael Spradling , "qemu-devel@nongnu.org" , Digant Desai Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add arrays to hold the registers, the definitions themselves, access functions, and logic to reset counters when PMCR.P is set. Update filtering code to support counters other than PMCCNTR. Support migration with raw read/write functions. Signed-off-by: Aaron Lindsay Signed-off-by: Aaron Lindsay Reviewed-by: Richard Henderson --- target/arm/cpu.h | 3 + target/arm/helper.c | 296 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 282 insertions(+), 17 deletions(-) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index f991ff370e..067f6efdb6 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -482,6 +482,9 @@ typedef struct CPUARMState { * pmccntr_op_finish. */ uint64_t c15_ccnt_delta; + uint64_t c14_pmevcntr[31]; + uint64_t c14_pmevcntr_delta[31]; + uint64_t c14_pmevtyper[31]; uint64_t pmccfiltr_el0; /* Performance Monitor Filter Register */ uint64_t vpidr_el2; /* Virtualization Processor ID Register */ uint64_t vmpidr_el2; /* Virtualization Multiprocessor ID Register */ diff --git a/target/arm/helper.c b/target/arm/helper.c index b9d8441497..b7297d72a8 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -979,6 +979,7 @@ static const ARMCPRegInfo v6_cp_reginfo[] = { #define PMCRDP 0x10 #define PMCRD 0x8 #define PMCRC 0x4 +#define PMCRP 0x2 #define PMCRE 0x1 #define PMXEVTYPER_P 0x80000000 @@ -1051,6 +1052,17 @@ uint64_t get_pmceid(CPUARMState *env) return pmceid; } +/* + * Check at runtime whether a PMU event is supported for the current machine + */ +static bool event_supported(uint16_t number) +{ + if (number > MAX_EVENT_ID) { + return false; + } + return supported_event_map[number] != UNSUPPORTED_EVENT; +} + static CPAccessResult pmreg_access(CPUARMState *env, const ARMCPRegInfo *ri, bool isread) { @@ -1170,9 +1182,11 @@ static bool pmu_counter_enabled(CPUARMState *env, uint8_t counter) prohibited = env->cp15.c9_pmcr & PMCRDP; } - /* TODO Remove assert, set filter to correct PMEVTYPER */ - assert(counter == 31); - filter = env->cp15.pmccfiltr_el0; + if (counter == 31) { + filter = env->cp15.pmccfiltr_el0; + } else { + filter = env->cp15.c14_pmevtyper[counter]; + } p = filter & PMXEVTYPER_P; u = filter & PMXEVTYPER_U; @@ -1192,6 +1206,17 @@ static bool pmu_counter_enabled(CPUARMState *env, uint8_t counter) filtered = m != p; } + if (counter != 31) { + /* + * If not checking PMCCNTR, ensure the counter is setup to an event we + * support + */ + uint16_t event = filter & PMXEVTYPER_EVTCOUNT; + if (!event_supported(event)) { + return false; + } + } + return enabled && !prohibited && !filtered; } @@ -1238,14 +1263,47 @@ void pmccntr_op_finish(CPUARMState *env) } } +static void pmevcntr_op_start(CPUARMState *env, uint8_t counter) +{ + + uint16_t event = env->cp15.c14_pmevtyper[counter] & PMXEVTYPER_EVTCOUNT; + uint64_t count = 0; + if (event_supported(event)) { + uint16_t event_idx = supported_event_map[event]; + count = pm_events[event_idx].get_count(env); + } + + if (pmu_counter_enabled(env, counter)) { + env->cp15.c14_pmevcntr[counter] = + count - env->cp15.c14_pmevcntr_delta[counter]; + } + env->cp15.c14_pmevcntr_delta[counter] = count; +} + +static void pmevcntr_op_finish(CPUARMState *env, uint8_t counter) +{ + if (pmu_counter_enabled(env, counter)) { + env->cp15.c14_pmevcntr_delta[counter] -= + env->cp15.c14_pmevcntr[counter]; + } +} + void pmu_op_start(CPUARMState *env) { + unsigned int i; pmccntr_op_start(env); + for (i = 0; i < pmu_num_counters(env); i++) { + pmevcntr_op_start(env, i); + } } void pmu_op_finish(CPUARMState *env) { + unsigned int i; pmccntr_op_finish(env); + for (i = 0; i < pmu_num_counters(env); i++) { + pmevcntr_op_finish(env, i); + } } void pmu_pre_el_change(ARMCPU *cpu, void *ignored) @@ -1268,6 +1326,13 @@ static void pmcr_write(CPUARMState *env, const ARMCPRegInfo *ri, env->cp15.c15_ccnt = 0; } + if (value & PMCRP) { + unsigned int i; + for (i = 0; i < pmu_num_counters(env); i++) { + env->cp15.c14_pmevcntr[i] = 0; + } + } + /* only the DP, X, D and E bits are writable */ env->cp15.c9_pmcr &= ~0x39; env->cp15.c9_pmcr |= (value & 0x39); @@ -1321,6 +1386,14 @@ void pmccntr_op_finish(CPUARMState *env) { } +void pmevcntr_op_start(CPUARMState *env, uint8_t i) +{ +} + +void pmevcntr_op_finish(CPUARMState *env, uint8_t i) +{ +} + void pmu_op_start(CPUARMState *env) { } @@ -1391,30 +1464,174 @@ static void pmovsset_write(CPUARMState *env, const ARMCPRegInfo *ri, env->cp15.c9_pmovsr |= value; } -static void pmxevtyper_write(CPUARMState *env, const ARMCPRegInfo *ri, - uint64_t value) +static void pmevtyper_write(CPUARMState *env, const ARMCPRegInfo *ri, + uint64_t value, const uint8_t counter) { + if (counter == 31) { + pmccfiltr_write(env, ri, value); + } else if (counter < pmu_num_counters(env)) { + pmevcntr_op_start(env, counter); + + /* + * If this counter's event type is changing, store the current + * underlying count for the new type in c14_pmevcntr_delta[counter] so + * pmevcntr_op_finish has the correct baseline when it converts back to + * a delta. + */ + uint16_t old_event = env->cp15.c14_pmevtyper[counter] & + PMXEVTYPER_EVTCOUNT; + uint16_t new_event = value & PMXEVTYPER_EVTCOUNT; + if (old_event != new_event) { + uint64_t count = 0; + if (event_supported(new_event)) { + uint16_t event_idx = supported_event_map[new_event]; + count = pm_events[event_idx].get_count(env); + } + env->cp15.c14_pmevcntr_delta[counter] = count; + } + + env->cp15.c14_pmevtyper[counter] = value & PMXEVTYPER_MASK; + pmevcntr_op_finish(env, counter); + } /* Attempts to access PMXEVTYPER are CONSTRAINED UNPREDICTABLE when * PMSELR value is equal to or greater than the number of implemented * counters, but not equal to 0x1f. We opt to behave as a RAZ/WI. */ - if (env->cp15.c9_pmselr == 0x1f) { - pmccfiltr_write(env, ri, value); +} + +static uint64_t pmevtyper_read(CPUARMState *env, const ARMCPRegInfo *ri, + const uint8_t counter) +{ + if (counter == 31) { + return env->cp15.pmccfiltr_el0; + } else if (counter < pmu_num_counters(env)) { + return env->cp15.c14_pmevtyper[counter]; + } else { + /* + * We opt to behave as a RAZ/WI when attempts to access PMXEVTYPER + * are CONSTRAINED UNPREDICTABLE. See comments in pmevtyper_write(). + */ + return 0; } } +static void pmevtyper_writefn(CPUARMState *env, const ARMCPRegInfo *ri, + uint64_t value) +{ + uint8_t counter = ((ri->crm & 3) << 3) | (ri->opc2 & 7); + pmevtyper_write(env, ri, value, counter); +} + +static void pmevtyper_rawwrite(CPUARMState *env, const ARMCPRegInfo *ri, + uint64_t value) +{ + uint8_t counter = ((ri->crm & 3) << 3) | (ri->opc2 & 7); + env->cp15.c14_pmevtyper[counter] = value; + + /* + * pmevtyper_rawwrite is called between a pair of pmu_op_start and + * pmu_op_finish calls when loading saved state for a migration. Because + * we're potentially updating the type of event here, the value written to + * c14_pmevcntr_delta by the preceeding pmu_op_start call may be for a + * different counter type. Therefore, we need to set this value to the + * current count for the counter type we're writing so that pmu_op_finish + * has the correct count for its calculation. + */ + uint16_t event = value & PMXEVTYPER_EVTCOUNT; + if (event_supported(event)) { + uint16_t event_idx = supported_event_map[event]; + env->cp15.c14_pmevcntr_delta[counter] = + pm_events[event_idx].get_count(env); + } +} + +static uint64_t pmevtyper_readfn(CPUARMState *env, const ARMCPRegInfo *ri) +{ + uint8_t counter = ((ri->crm & 3) << 3) | (ri->opc2 & 7); + return pmevtyper_read(env, ri, counter); +} + +static void pmxevtyper_write(CPUARMState *env, const ARMCPRegInfo *ri, + uint64_t value) +{ + pmevtyper_write(env, ri, value, env->cp15.c9_pmselr & 31); +} + static uint64_t pmxevtyper_read(CPUARMState *env, const ARMCPRegInfo *ri) { - /* We opt to behave as a RAZ/WI when attempts to access PMXEVTYPER - * are CONSTRAINED UNPREDICTABLE. See comments in pmxevtyper_write(). + return pmevtyper_read(env, ri, env->cp15.c9_pmselr & 31); +} + +static void pmevcntr_write(CPUARMState *env, const ARMCPRegInfo *ri, + uint64_t value, uint8_t counter) +{ + if (counter < pmu_num_counters(env)) { + pmevcntr_op_start(env, counter); + env->cp15.c14_pmevcntr[counter] = value; + pmevcntr_op_finish(env, counter); + } + /* + * We opt to behave as a RAZ/WI when attempts to access PM[X]EVCNTR + * are CONSTRAINED UNPREDICTABLE. */ - if (env->cp15.c9_pmselr == 0x1f) { - return env->cp15.pmccfiltr_el0; +} + +static uint64_t pmevcntr_read(CPUARMState *env, const ARMCPRegInfo *ri, + uint8_t counter) +{ + if (counter < pmu_num_counters(env)) { + uint64_t ret; + pmevcntr_op_start(env, counter); + ret = env->cp15.c14_pmevcntr[counter]; + pmevcntr_op_finish(env, counter); + return ret; } else { + /* We opt to behave as a RAZ/WI when attempts to access PM[X]EVCNTR + * are CONSTRAINED UNPREDICTABLE. */ return 0; } } +static void pmevcntr_writefn(CPUARMState *env, const ARMCPRegInfo *ri, + uint64_t value) +{ + uint8_t counter = ((ri->crm & 3) << 3) | (ri->opc2 & 7); + pmevcntr_write(env, ri, value, counter); +} + +static uint64_t pmevcntr_readfn(CPUARMState *env, const ARMCPRegInfo *ri) +{ + uint8_t counter = ((ri->crm & 3) << 3) | (ri->opc2 & 7); + return pmevcntr_read(env, ri, counter); +} + +static void pmevcntr_rawwrite(CPUARMState *env, const ARMCPRegInfo *ri, + uint64_t value) +{ + uint8_t counter = ((ri->crm & 3) << 3) | (ri->opc2 & 7); + assert(counter < pmu_num_counters(env)); + env->cp15.c14_pmevcntr[counter] = value; + pmevcntr_write(env, ri, value, counter); +} + +static uint64_t pmevcntr_rawread(CPUARMState *env, const ARMCPRegInfo *ri) +{ + uint8_t counter = ((ri->crm & 3) << 3) | (ri->opc2 & 7); + assert(counter < pmu_num_counters(env)); + return env->cp15.c14_pmevcntr[counter]; +} + +static void pmxevcntr_write(CPUARMState *env, const ARMCPRegInfo *ri, + uint64_t value) +{ + pmevcntr_write(env, ri, value, env->cp15.c9_pmselr & 31); +} + +static uint64_t pmxevcntr_read(CPUARMState *env, const ARMCPRegInfo *ri) +{ + return pmevcntr_read(env, ri, env->cp15.c9_pmselr & 31); +} + static void pmuserenr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value) { @@ -1618,16 +1835,23 @@ static const ARMCPRegInfo v7_cp_reginfo[] = { .fieldoffset = offsetof(CPUARMState, cp15.pmccfiltr_el0), .resetvalue = 0, }, { .name = "PMXEVTYPER", .cp = 15, .crn = 9, .crm = 13, .opc1 = 0, .opc2 = 1, - .access = PL0_RW, .type = ARM_CP_NO_RAW, .accessfn = pmreg_access, + .access = PL0_RW, .type = ARM_CP_NO_RAW | ARM_CP_IO, + .accessfn = pmreg_access, .writefn = pmxevtyper_write, .readfn = pmxevtyper_read }, { .name = "PMXEVTYPER_EL0", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 3, .crn = 9, .crm = 13, .opc2 = 1, - .access = PL0_RW, .type = ARM_CP_NO_RAW, .accessfn = pmreg_access, + .access = PL0_RW, .type = ARM_CP_NO_RAW | ARM_CP_IO, + .accessfn = pmreg_access, .writefn = pmxevtyper_write, .readfn = pmxevtyper_read }, - /* Unimplemented, RAZ/WI. */ { .name = "PMXEVCNTR", .cp = 15, .crn = 9, .crm = 13, .opc1 = 0, .opc2 = 2, - .access = PL0_RW, .type = ARM_CP_CONST, .resetvalue = 0, - .accessfn = pmreg_access_xevcntr }, + .access = PL0_RW, .type = ARM_CP_NO_RAW | ARM_CP_IO, + .accessfn = pmreg_access_xevcntr, + .writefn = pmxevcntr_write, .readfn = pmxevcntr_read }, + { .name = "PMXEVCNTR_EL0", .state = ARM_CP_STATE_AA64, + .opc0 = 3, .opc1 = 3, .crn = 9, .crm = 13, .opc2 = 2, + .access = PL0_RW, .type = ARM_CP_NO_RAW | ARM_CP_IO, + .accessfn = pmreg_access_xevcntr, + .writefn = pmxevcntr_write, .readfn = pmxevcntr_read }, { .name = "PMUSERENR", .cp = 15, .crn = 9, .crm = 14, .opc1 = 0, .opc2 = 0, .access = PL0_R | PL1_RW, .accessfn = access_tpm, .fieldoffset = offsetoflow32(CPUARMState, cp15.c9_pmuserenr), @@ -4435,7 +4659,7 @@ static const ARMCPRegInfo el2_cp_reginfo[] = { #endif /* The only field of MDCR_EL2 that has a defined architectural reset value * is MDCR_EL2.HPMN which should reset to the value of PMCR_EL0.N; but we - * don't impelment any PMU event counters, so using zero as a reset + * don't implement any PMU event counters, so using zero as a reset * value for MDCR_EL2 is okay */ { .name = "MDCR_EL2", .state = ARM_CP_STATE_BOTH, @@ -5287,6 +5511,7 @@ void register_cp_regs_for_features(ARMCPU *cpu) * field as main ID register, and we implement only the cycle * count register. */ + unsigned int i, pmcrn = 0; #ifndef CONFIG_USER_ONLY ARMCPRegInfo pmcr = { .name = "PMCR", .cp = 15, .crn = 9, .crm = 12, .opc1 = 0, .opc2 = 0, @@ -5307,6 +5532,43 @@ void register_cp_regs_for_features(ARMCPU *cpu) }; define_one_arm_cp_reg(cpu, &pmcr); define_one_arm_cp_reg(cpu, &pmcr64); + for (i = 0; i < pmcrn; i++) { + char *pmevcntr_name = g_strdup_printf("PMEVCNTR%d", i); + char *pmevcntr_el0_name = g_strdup_printf("PMEVCNTR%d_EL0", i); + char *pmevtyper_name = g_strdup_printf("PMEVTYPER%d", i); + char *pmevtyper_el0_name = g_strdup_printf("PMEVTYPER%d_EL0", i); + ARMCPRegInfo pmev_regs[] = { + { .name = pmevcntr_name, .cp = 15, .crn = 15, + .crm = 8 | (3 & (i >> 3)), .opc1 = 0, .opc2 = i & 7, + .access = PL0_RW, .type = ARM_CP_IO | ARM_CP_ALIAS, + .readfn = pmevcntr_readfn, .writefn = pmevcntr_writefn, + .accessfn = pmreg_access }, + { .name = pmevcntr_el0_name, .state = ARM_CP_STATE_AA64, + .opc0 = 3, .opc1 = 3, .crn = 15, .crm = 8 | (3 & (i >> 3)), + .opc2 = i & 7, .access = PL0_RW, .accessfn = pmreg_access, + .type = ARM_CP_IO, + .readfn = pmevcntr_readfn, .writefn = pmevcntr_writefn, + .raw_readfn = pmevcntr_rawread, + .raw_writefn = pmevcntr_rawwrite }, + { .name = pmevtyper_name, .cp = 15, .crn = 15, + .crm = 12 | (3 & (i >> 3)), .opc1 = 0, .opc2 = i & 7, + .access = PL0_RW, .type = ARM_CP_IO | ARM_CP_ALIAS, + .readfn = pmevtyper_readfn, .writefn = pmevtyper_writefn, + .accessfn = pmreg_access }, + { .name = pmevtyper_el0_name, .state = ARM_CP_STATE_AA64, + .opc0 = 3, .opc1 = 3, .crn = 15, .crm = 12 | (3 & (i >> 3)), + .opc2 = i & 7, .access = PL0_RW, .accessfn = pmreg_access, + .type = ARM_CP_IO, + .readfn = pmevtyper_readfn, .writefn = pmevtyper_writefn, + .raw_writefn = pmevtyper_rawwrite }, + REGINFO_SENTINEL + }; + define_arm_cp_regs(cpu, pmev_regs); + g_free(pmevcntr_name); + g_free(pmevcntr_el0_name); + g_free(pmevtyper_name); + g_free(pmevtyper_el0_name); + } #endif ARMCPRegInfo clidr = { .name = "CLIDR", .state = ARM_CP_STATE_BOTH, From patchwork Mon Nov 5 18:52:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Lindsay X-Patchwork-Id: 10668947 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DD6531751 for ; Mon, 5 Nov 2018 19:00:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD0F529B18 for ; Mon, 5 Nov 2018 19:00:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BEBDE29B5D; Mon, 5 Nov 2018 19:00:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1BA7429B18 for ; Mon, 5 Nov 2018 19:00:50 +0000 (UTC) Received: from localhost ([::1]:37163 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJk7G-00071M-6e for patchwork-qemu-devel@patchwork.kernel.org; Mon, 05 Nov 2018 14:00:50 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46729) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJjzO-0005Iw-4n for qemu-devel@nongnu.org; Mon, 05 Nov 2018 13:52:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gJjzH-000155-98 for qemu-devel@nongnu.org; Mon, 05 Nov 2018 13:52:40 -0500 Received: from mail-cys01nam02on0099.outbound.protection.outlook.com ([104.47.37.99]:43926 helo=NAM02-CY1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gJjyp-0000UT-5O; Mon, 05 Nov 2018 13:52:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amperemail.onmicrosoft.com; s=selector1-os-amperecomputing-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uLo29C5WwSfe5W+XJjUr82RwxgmDF4IKUMpCpSDkvQM=; b=bW1Tl8YrumtO3XmLb5UYZoOPipCliddjYepMY7QU9o7oq0MmIzqYqp7UI1RUbOBrVqw/wZH/Rs9JWWnWEHmaUsQaYkwdasL5c0E9oWFKIrxgdFQ/jy+ycRZqlCI4kv60ZzUFoRtkHjRc55qPRQ5bmeXKcmwIWRzl2dA0zeAmGVw= Received: from DM6PR01MB4825.prod.exchangelabs.com (20.177.218.222) by DM6PR01MB5194.prod.exchangelabs.com (20.176.122.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.21; Mon, 5 Nov 2018 18:52:00 +0000 Received: from DM6PR01MB4825.prod.exchangelabs.com ([fe80::4cf7:c8dc:b673:ec66]) by DM6PR01MB4825.prod.exchangelabs.com ([fe80::4cf7:c8dc:b673:ec66%3]) with mapi id 15.20.1294.028; Mon, 5 Nov 2018 18:52:00 +0000 From: Aaron Lindsay To: "qemu-arm@nongnu.org" , Peter Maydell , Alistair Francis , Wei Huang , Peter Crosthwaite , Richard Henderson Thread-Topic: [PATCH v7 09/12] target/arm: PMU: Add instruction and cycle events Thread-Index: AQHUdTiilPHLhD3lJUue9zfAQ/5ukw== Date: Mon, 5 Nov 2018 18:52:00 +0000 Message-ID: <20181105185046.2802-10-aaron@os.amperecomputing.com> References: <20181105185046.2802-1-aaron@os.amperecomputing.com> In-Reply-To: <20181105185046.2802-1-aaron@os.amperecomputing.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BN6PR20CA0070.namprd20.prod.outlook.com (2603:10b6:404:151::32) To DM6PR01MB4825.prod.exchangelabs.com (2603:10b6:5:6b::30) authentication-results: spf=none (sender IP is ) smtp.mailfrom=aaron@os.amperecomputing.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [216.85.170.153] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DM6PR01MB5194; 6:XJtv5j+Qd4ArWyL6p/8kRja4fLMkfGfoYTGncHfGtEh8AznX3F1WW4bUTe9ZaET91G31aaXIcPcYsVAykUZsUb95C7wv0ax7Zryj6ou0OI5kjhHTcWSMgSg4g/Ejpp4P+DDYaTMfRqflAbiOj4mE1bBogRXiDSIW+MQ12oPtdFp/yr9fXvII9A16aFurdLgvHufCIzbAqbNzJMEhwK1nsgk/M2deaRz+p62T81Fcg765XGDdFnrrHa5P0R7Z5x7wwSCcomUvVCLusj/YiSdhm21XELpPSTO0zacbqdXpn8/c+ueeMG5wDoQ+tOBUlMGHSv4n2GAcLjzXk2z55Kc0ZmVTfx27gyGABMnvbnOXsRs5hp9bwHHldS25RbmvSJwN0fKNFgOFdYP5Gy8LvY7YwNXyJZKffFWc8V2rtbh2MDraW6osUK1LBsOybuzmcfYjQq+S5RZEhZ+fK0+fFwYJ/g==; 5:iLFDn3J0RFOINtXNP1Z5/c0vM2PY9j9vyShIixi3D/wIf4Gz7AsSrwmQwMztST/UfmUfUkduKwnxHpgnMIEnicRbeGaA9Y/ERarI1XtN7+z7xALXZATPjE4UvfzU34USRZX454pKMbgX5gNvsTD5/e9uuI42IS2grSZW2kKdiu4=; 7:xyfQxCnI61leQdiomjimsxdw6H0uAv1QxjPIoNrT9fIIZPvt3RB3VO8cbMVMKyg8Vt1DNSwzZOloc7nIx9RXyi5BJ7pV0fH/yFVIgqz1qnhSfRs2zGB7cIQz1CLVmSq5GYVidQQk4Br1vxfCtKNbgw== x-ms-office365-filtering-correlation-id: 2ae41178-56f2-4b70-6d40-08d6434fc498 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020); SRVR:DM6PR01MB5194; x-ms-traffictypediagnostic: DM6PR01MB5194: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(10201501046)(3002001)(93006095)(93001095)(3231382)(944501410)(52105095)(148016)(149066)(150057)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(20161123562045)(20161123558120)(201708071742011)(7699051)(76991095); SRVR:DM6PR01MB5194; BCL:0; PCL:0; RULEID:; SRVR:DM6PR01MB5194; x-forefront-prvs: 08476BC6EF x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(396003)(346002)(136003)(39840400004)(376002)(366004)(189003)(199004)(81166006)(81156014)(53936002)(66066001)(6436002)(486006)(6486002)(6116002)(14444005)(110136005)(256004)(25786009)(4326008)(54906003)(14454004)(7736002)(305945005)(106356001)(26005)(105586002)(186003)(97736004)(39060400002)(102836004)(8936002)(2900100001)(2501003)(386003)(6506007)(8676002)(7416002)(476003)(316002)(52116002)(6512007)(2616005)(99286004)(76176011)(5660300001)(2906002)(86362001)(68736007)(71200400001)(71190400001)(3846002)(478600001)(446003)(1076002)(11346002); DIR:OUT; SFP:1102; SCL:1; SRVR:DM6PR01MB5194; H:DM6PR01MB4825.prod.exchangelabs.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:0; received-spf: None (protection.outlook.com: os.amperecomputing.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: HStrIneimGZ78737SBxIKgJ5VtaCa0MD+RzRdytbsmQUjA0r5kwoIGEwHx8AP++alB/T/wyD3p0p8/bhnADgvZp70wc6tp24dpXT74H40g2mJ4LxVHIeRNmLiltAk9ZaqxAsS4293WxiQhvL0Egi7rhWWAd5L2EevRi6/efrd83LeA6339/0mTvhe6wa6WZP+Nffieorurhkq4VMa18AzMRDq8VzsoIODoDfbRwVRR+KuDLdse2wLhfLYZejMmVXQ0U2qWSPf8t6oubyttEK/kPCXG6XIqb0Xh1RNBUpvGJCxHG0xnagalFr4Z+L2hBPcjuLl03R3G41xdhmztdm33N86u7YuEmufxe9AsjQUFo= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2ae41178-56f2-4b70-6d40-08d6434fc498 X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Nov 2018 18:52:00.0625 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR01MB5194 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.37.99 Subject: [Qemu-devel] [PATCH v7 09/12] target/arm: PMU: Add instruction and cycle events X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Aaron Lindsay , Michael Spradling , "qemu-devel@nongnu.org" , Digant Desai Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The instruction event is only enabled when icount is used, cycles are always supported. Always defining get_cycle_count (but altering its behavior depending on CONFIG_USER_ONLY) allows us to remove some CONFIG_USER_ONLY #defines throughout the rest of the code. Signed-off-by: Aaron Lindsay Signed-off-by: Aaron Lindsay Reviewed-by: Peter Maydell --- target/arm/helper.c | 90 ++++++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 46 deletions(-) diff --git a/target/arm/helper.c b/target/arm/helper.c index b7297d72a8..e3ec36490c 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -15,6 +15,7 @@ #include "arm_ldst.h" #include /* For crc32 */ #include "exec/semihost.h" +#include "sysemu/cpus.h" #include "sysemu/kvm.h" #include "fpu/softfloat.h" #include "qemu/range.h" @@ -1021,9 +1022,50 @@ typedef struct pm_event { uint64_t (*get_count)(CPUARMState *); } pm_event; +static bool event_always_supported(CPUARMState *env) +{ + return true; +} + +/* + * Return the underlying cycle count for the PMU cycle counters. If we're in + * usermode, simply return 0. + */ +static uint64_t cycles_get_count(CPUARMState *env) +{ +#ifndef CONFIG_USER_ONLY + return muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), + ARM_CPU_FREQ, NANOSECONDS_PER_SECOND); +#else + return cpu_get_host_ticks(); +#endif +} + +#ifndef CONFIG_USER_ONLY +static bool instructions_supported(CPUARMState *env) +{ + return use_icount == 1 /* Precise instruction counting */; +} + +static uint64_t instructions_get_count(CPUARMState *env) +{ + return (uint64_t)cpu_get_icount_raw(); +} +#endif + static const pm_event pm_events[] = { +#ifndef CONFIG_USER_ONLY + { .number = 0x008, /* INST_RETIRED, Instruction architecturally executed */ + .supported = instructions_supported, + .get_count = instructions_get_count, + }, + { .number = 0x011, /* CPU_CYCLES, Cycle */ + .supported = event_always_supported, + .get_count = cycles_get_count, + } +#endif }; -#define MAX_EVENT_ID 0x0 +#define MAX_EVENT_ID 0x11 #define UNSUPPORTED_EVENT UINT16_MAX static uint16_t supported_event_map[MAX_EVENT_ID + 1]; @@ -1116,8 +1158,6 @@ static CPAccessResult pmreg_access_swinc(CPUARMState *env, return pmreg_access(env, ri, isread); } -#ifndef CONFIG_USER_ONLY - static CPAccessResult pmreg_access_selr(CPUARMState *env, const ARMCPRegInfo *ri, bool isread) @@ -1228,9 +1268,7 @@ static bool pmu_counter_enabled(CPUARMState *env, uint8_t counter) */ void pmccntr_op_start(CPUARMState *env) { - uint64_t cycles = 0; - cycles = muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), - ARM_CPU_FREQ, NANOSECONDS_PER_SECOND); + uint64_t cycles = cycles_get_count(env); if (pmu_counter_enabled(env, 31)) { uint64_t eff_cycles = cycles; @@ -1376,42 +1414,6 @@ static void pmccntr_write32(CPUARMState *env, const ARMCPRegInfo *ri, pmccntr_write(env, ri, deposit64(cur_val, 0, 32, value)); } -#else /* CONFIG_USER_ONLY */ - -void pmccntr_op_start(CPUARMState *env) -{ -} - -void pmccntr_op_finish(CPUARMState *env) -{ -} - -void pmevcntr_op_start(CPUARMState *env, uint8_t i) -{ -} - -void pmevcntr_op_finish(CPUARMState *env, uint8_t i) -{ -} - -void pmu_op_start(CPUARMState *env) -{ -} - -void pmu_op_finish(CPUARMState *env) -{ -} - -void pmu_pre_el_change(ARMCPU *cpu, void *ignored) -{ -} - -void pmu_post_el_change(ARMCPU *cpu, void *ignored) -{ -} - -#endif - static void pmccfiltr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value) { @@ -1799,7 +1801,6 @@ static const ARMCPRegInfo v7_cp_reginfo[] = { /* Unimplemented so WI. */ { .name = "PMSWINC", .cp = 15, .crn = 9, .crm = 12, .opc1 = 0, .opc2 = 4, .access = PL0_W, .accessfn = pmreg_access_swinc, .type = ARM_CP_NOP }, -#ifndef CONFIG_USER_ONLY { .name = "PMSELR", .cp = 15, .crn = 9, .crm = 12, .opc1 = 0, .opc2 = 5, .access = PL0_RW, .type = ARM_CP_ALIAS, .fieldoffset = offsetoflow32(CPUARMState, cp15.c9_pmselr), @@ -1821,7 +1822,6 @@ static const ARMCPRegInfo v7_cp_reginfo[] = { .fieldoffset = offsetof(CPUARMState, cp15.c15_ccnt), .readfn = pmccntr_read, .writefn = pmccntr_write, .raw_readfn = raw_read, .raw_writefn = raw_write, }, -#endif { .name = "PMCCFILTR", .cp = 15, .opc1 = 0, .crn = 14, .crm = 15, .opc2 = 7, .writefn = pmccfiltr_write_a32, .readfn = pmccfiltr_read_a32, .access = PL0_RW, .accessfn = pmreg_access, @@ -5512,7 +5512,6 @@ void register_cp_regs_for_features(ARMCPU *cpu) * count register. */ unsigned int i, pmcrn = 0; -#ifndef CONFIG_USER_ONLY ARMCPRegInfo pmcr = { .name = "PMCR", .cp = 15, .crn = 9, .crm = 12, .opc1 = 0, .opc2 = 0, .access = PL0_RW, @@ -5569,7 +5568,6 @@ void register_cp_regs_for_features(ARMCPU *cpu) g_free(pmevtyper_name); g_free(pmevtyper_el0_name); } -#endif ARMCPRegInfo clidr = { .name = "CLIDR", .state = ARM_CP_STATE_BOTH, .opc0 = 3, .crn = 0, .crm = 0, .opc1 = 1, .opc2 = 1, From patchwork Mon Nov 5 18:52:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Lindsay X-Patchwork-Id: 10668953 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6D2AC1751 for ; Mon, 5 Nov 2018 19:04:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5A8E8291B7 for ; Mon, 5 Nov 2018 19:04:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4EA6B29261; Mon, 5 Nov 2018 19:04:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5F2F9291B7 for ; Mon, 5 Nov 2018 19:04:20 +0000 (UTC) Received: from localhost ([::1]:37183 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJkAd-0003hS-C3 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 05 Nov 2018 14:04:19 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46754) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJjzP-0005OW-Ih for qemu-devel@nongnu.org; Mon, 05 Nov 2018 13:52:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gJjzO-0001At-21 for qemu-devel@nongnu.org; Mon, 05 Nov 2018 13:52:43 -0500 Received: from mail-cys01nam02on0099.outbound.protection.outlook.com ([104.47.37.99]:43926 helo=NAM02-CY1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gJjyu-0000UT-TE; Mon, 05 Nov 2018 13:52:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amperemail.onmicrosoft.com; s=selector1-os-amperecomputing-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2CztuA3sL9gunx35yyGL0HAZd15Mu8hkkma3f+cUywk=; b=d29KVCLbsAw/OGl1JxM/6JHxhIwYev6Xj3xFdKSL8yN7V90yePYC8GJynpgVzKbFdMN7bwxjvOXxqgCVfBn+ErwNMXbXxxvV2RvD32iJ85B7YmjV8iKgUuqpv6IDMkxZ+cngTlWF8kupQZLbjonHeE5ETpI8f9qPxoTdAqnhDpQ= Received: from DM6PR01MB4825.prod.exchangelabs.com (20.177.218.222) by DM6PR01MB5194.prod.exchangelabs.com (20.176.122.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.21; Mon, 5 Nov 2018 18:52:01 +0000 Received: from DM6PR01MB4825.prod.exchangelabs.com ([fe80::4cf7:c8dc:b673:ec66]) by DM6PR01MB4825.prod.exchangelabs.com ([fe80::4cf7:c8dc:b673:ec66%3]) with mapi id 15.20.1294.028; Mon, 5 Nov 2018 18:52:01 +0000 From: Aaron Lindsay To: "qemu-arm@nongnu.org" , Peter Maydell , Alistair Francis , Wei Huang , Peter Crosthwaite , Richard Henderson Thread-Topic: [PATCH v7 10/12] target/arm: PMU: Set PMCR.N to 4 Thread-Index: AQHUdTiipmLYuvQQkUWlgSTv/s4ESQ== Date: Mon, 5 Nov 2018 18:52:01 +0000 Message-ID: <20181105185046.2802-11-aaron@os.amperecomputing.com> References: <20181105185046.2802-1-aaron@os.amperecomputing.com> In-Reply-To: <20181105185046.2802-1-aaron@os.amperecomputing.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BN6PR20CA0070.namprd20.prod.outlook.com (2603:10b6:404:151::32) To DM6PR01MB4825.prod.exchangelabs.com (2603:10b6:5:6b::30) authentication-results: spf=none (sender IP is ) smtp.mailfrom=aaron@os.amperecomputing.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [216.85.170.153] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DM6PR01MB5194; 6:R5eDJLG2TZusn5me92JM4Xz5ozmuhbF9AOhRxGuYLQ8vZMnLNg9pQF6DQjFJW/ver1oD2EMbPVMsaYux6zyNKHQtYg5hiHAL+9YthJTyDlrHKLhBRi/f52F1ozN6T9IjLeWUdD1eoIUOJhIaaKflfEZmawZ/rSxIBVFI7QOciBkjLYizgikwEziPylfOPfJXHqsT3TjwVHb/rjaqnBbitfICdcpAVSrYk9HaMjvruogNEiKPzC6J6UU79xQFyj2kQGZQ6yHkIEX52EIHkje1tcKTz7iyZwXOIDX9PfFfsG+ltu1/WjxEIWCia11pLx90VKlSJDHZBVaccbriZhtiSO7SZvNBEO386iyoH/qtVUw4tJsB0P7EsRWMPVfJMJ76j4P9n32W/GVFxz1r5xVDBEp6nai1Pz5N6OjQ8ZdnG+S9O8RW4A2NS/f+YAYyJMwl38EXQFvx/1zpXUVYHf2NZQ==; 5:lwEBzGft+rpm1m6g4/X7oyJ1PuZCg7na++lfh8Qti64B3R7/EDBGUquB+ih1GUOTZkfMwYDW7Mun+cLLPSRl/EqGOuspoyczU5nnLGMCN3NpeYEtQxLksJILNGjuWRkDvxrB22S49ZXfrl/sNBkETALzVvvV4gTLS3Rj3ed4Me8=; 7:5vggkWYAA4UEmYXycaZmwEcZuTIiFAYWMcJnzaX3r8GPa5206E635ZeZwr+x2ItfkkNuXSkU05aVlq3hEbKPHr9Iv7XZXX7vQ0cwSWWSbEovIb59rEQ3HViSK9DpM1XGVhKIE8ckWbN3PKb1BUdoTg== x-ms-office365-filtering-correlation-id: 35e15671-c31f-4e5a-8744-08d6434fc542 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020); SRVR:DM6PR01MB5194; x-ms-traffictypediagnostic: DM6PR01MB5194: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(10201501046)(3002001)(93006095)(93001095)(3231382)(944501410)(52105095)(148016)(149066)(150057)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(20161123562045)(20161123558120)(201708071742011)(7699051)(76991095); SRVR:DM6PR01MB5194; BCL:0; PCL:0; RULEID:; SRVR:DM6PR01MB5194; x-forefront-prvs: 08476BC6EF x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(979002)(396003)(346002)(136003)(39840400004)(376002)(366004)(189003)(199004)(81166006)(81156014)(53936002)(66066001)(6436002)(486006)(6486002)(6116002)(14444005)(110136005)(256004)(25786009)(4326008)(54906003)(14454004)(7736002)(305945005)(106356001)(26005)(105586002)(186003)(97736004)(39060400002)(102836004)(8936002)(2900100001)(2501003)(386003)(6506007)(8676002)(7416002)(476003)(316002)(52116002)(6512007)(2616005)(99286004)(76176011)(5660300001)(2906002)(86362001)(68736007)(71200400001)(71190400001)(3846002)(478600001)(446003)(1076002)(11346002)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1102; SCL:1; SRVR:DM6PR01MB5194; H:DM6PR01MB4825.prod.exchangelabs.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:0; received-spf: None (protection.outlook.com: os.amperecomputing.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: W5g0ouExxvtHLYr2vsx99LvvTGE97j/4jJHR5YLLSedjaBoLZBiSrWXNvPVoEEfI/oCCHvhUFBsBMQJ/KJySxNQDnutkO0DyGyn4HkuLCWfKqH62LkZqU/cib7t3syB+WgHNapN7Gw8zD9veKO3UNmqUqP5fDwQARL175d8wFuJKwptisNHhxHUrDX0e3dxyB9Yml6KoBathjSWHS0uyQgakTs6lqWx/5WQnMWXeRkLir7D/6B1JUiCdRIGlxAqj2s0kBJCUO1gzUg4F/Di1r/Ku0EZdEBrp4p+g8TqjY4HxJULFvTWUOvGRHAXoLJfeI3wXi/jgIz/eOIowYF15bBqP1BxvP3rmR0wNhdrGpw4= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 35e15671-c31f-4e5a-8744-08d6434fc542 X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Nov 2018 18:52:01.1943 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR01MB5194 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.37.99 Subject: [Qemu-devel] [PATCH v7 10/12] target/arm: PMU: Set PMCR.N to 4 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Aaron Lindsay , Michael Spradling , "qemu-devel@nongnu.org" , Digant Desai Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This both advertises that we support four counters and enables them because the pmu_num_counters() reads this value from PMCR. Signed-off-by: Aaron Lindsay Signed-off-by: Aaron Lindsay Reviewed-by: Peter Maydell --- target/arm/helper.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/target/arm/helper.c b/target/arm/helper.c index e3ec36490c..11eb62bdda 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -1753,7 +1753,7 @@ static const ARMCPRegInfo v7_cp_reginfo[] = { .access = PL1_W, .type = ARM_CP_NOP }, /* Performance monitors are implementation defined in v7, * but with an ARM recommended set of registers, which we - * follow (although we don't actually implement any counters) + * follow. * * Performance registers fall into three categories: * (a) always UNDEF in PL0, RW in PL1 (PMINTENSET, PMINTENCLR) @@ -5508,10 +5508,10 @@ void register_cp_regs_for_features(ARMCPU *cpu) } if (arm_feature(env, ARM_FEATURE_V7)) { /* v7 performance monitor control register: same implementor - * field as main ID register, and we implement only the cycle - * count register. + * field as main ID register, and we implement four counters in + * addition to the cycle count register. */ - unsigned int i, pmcrn = 0; + unsigned int i, pmcrn = 4; ARMCPRegInfo pmcr = { .name = "PMCR", .cp = 15, .crn = 9, .crm = 12, .opc1 = 0, .opc2 = 0, .access = PL0_RW, @@ -5526,7 +5526,7 @@ void register_cp_regs_for_features(ARMCPU *cpu) .access = PL0_RW, .accessfn = pmreg_access, .type = ARM_CP_IO, .fieldoffset = offsetof(CPUARMState, cp15.c9_pmcr), - .resetvalue = cpu->midr & 0xff000000, + .resetvalue = (cpu->midr & 0xff000000) | (pmcrn << PMCRN_SHIFT), .writefn = pmcr_write, .raw_writefn = raw_write, }; define_one_arm_cp_reg(cpu, &pmcr); From patchwork Mon Nov 5 18:52:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Lindsay X-Patchwork-Id: 10668979 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9B6DC17D4 for ; Mon, 5 Nov 2018 19:06:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A1D42926B for ; Mon, 5 Nov 2018 19:06:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7E4CD2929F; Mon, 5 Nov 2018 19:06:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0078B293C5 for ; Mon, 5 Nov 2018 19:06:44 +0000 (UTC) Received: from localhost ([::1]:37199 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJkCy-00052g-5f for patchwork-qemu-devel@patchwork.kernel.org; Mon, 05 Nov 2018 14:06:44 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46839) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJjzW-0005Y2-8w for qemu-devel@nongnu.org; Mon, 05 Nov 2018 13:52:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gJjzR-0001FE-WC for qemu-devel@nongnu.org; Mon, 05 Nov 2018 13:52:50 -0500 Received: from mail-cys01nam02on0099.outbound.protection.outlook.com ([104.47.37.99]:43926 helo=NAM02-CY1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gJjzK-0000UT-Jl; Mon, 05 Nov 2018 13:52:40 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amperemail.onmicrosoft.com; s=selector1-os-amperecomputing-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=63+xw/snbdhXxz2vaAWq6N4vc16BfG5qpDn4AjyIE+Q=; b=ktcOP0SC+xNC1Tce8zQCp1qFam9QBrzz+KvP1MGHaL5GDhGjRNAFwRs5f0QBpLvj9s1qQu6kP/XbsmOVaioG44WAuLZc8R58JGU0JK+A3CT9X4KptapMZjA+OG9AFAXY22VSdzza7MClz2PLDd4Po+l+Jz2GyzP7yyw3Toqf2Bg= Received: from DM6PR01MB4825.prod.exchangelabs.com (20.177.218.222) by DM6PR01MB5194.prod.exchangelabs.com (20.176.122.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.21; Mon, 5 Nov 2018 18:52:02 +0000 Received: from DM6PR01MB4825.prod.exchangelabs.com ([fe80::4cf7:c8dc:b673:ec66]) by DM6PR01MB4825.prod.exchangelabs.com ([fe80::4cf7:c8dc:b673:ec66%3]) with mapi id 15.20.1294.028; Mon, 5 Nov 2018 18:52:02 +0000 From: Aaron Lindsay To: "qemu-arm@nongnu.org" , Peter Maydell , Alistair Francis , Wei Huang , Peter Crosthwaite , Richard Henderson Thread-Topic: [PATCH v7 11/12] target/arm: Implement PMSWINC Thread-Index: AQHUdTij5yn19ob2O0CQknFPPUTjTA== Date: Mon, 5 Nov 2018 18:52:02 +0000 Message-ID: <20181105185046.2802-12-aaron@os.amperecomputing.com> References: <20181105185046.2802-1-aaron@os.amperecomputing.com> In-Reply-To: <20181105185046.2802-1-aaron@os.amperecomputing.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BN6PR20CA0070.namprd20.prod.outlook.com (2603:10b6:404:151::32) To DM6PR01MB4825.prod.exchangelabs.com (2603:10b6:5:6b::30) authentication-results: spf=none (sender IP is ) smtp.mailfrom=aaron@os.amperecomputing.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [216.85.170.153] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DM6PR01MB5194; 6:KdSKMYHnJgWxTgP6V7Zct5DTQxKix/exDEbXkiLGNhrPtIniPYHrXYvbmzTu87lymkzZikKmJZtr+BysgRojR89aAi8imRRx93pY7twHxSPtgMPvmw0TBdvgnOSj9AEAjhanJYAqlgpLpkDGNiCDUEjmeqzGzB5mCnhat3IqgaQlKntzggGR+oLI2wIUPs3mrMCjkkIvsoOoVszjL3z9yhazml5AqBc6VHc057ID95QFZ+qUpCNLzEHU5ULLgUyHKFf4/XYwQAFaDs8c94VszexczwZVAults+ZPEg9QNVd/VPmb9FtVNZ6NoeMNHP5zjUSulVDrttS0j6IB43WTgkRskA810ke2a6wKgBlgHbI+qSnpSnJwiJ0nDLxTg/Fl+0rWeHZdQF92e4yFZny+kF2Cmxe6IAg1Tw8t4Ao9OQ5ysTNEk38Ctr1fZk+jgP2NP5A0gS7jpg09qszFEh4abQ==; 5:IBum3DAft8CnHifGMGwzenVco7SW2TlTk5Ry7c/fBsghM7a2T8LrNylIt8GhD5eqWuodYrgmWtEe7wEE1f3lVziN96T1Mfe0WxD1S75fc6SyymPu2uq7xyEnto8Zcxc2sKNlVB3zW1zdbsS7pb79rDWjrJ1y6nNg2uSUCLNIuME=; 7:3qDsf5qjukDsWbm+NGypcxTOXSmh3uoYKw8kv09lZMFBlRIIdnLuAjB9mG4ccpyiqmPT7gAVOi526oseiLYSndopZJ0ymCs8sP6jYGxOkX6iTB8zWmeNGlFzR6JLi5UJEPstm8VAK0nRvDDWPSAooQ== x-ms-office365-filtering-correlation-id: 2d0ae81b-1f10-4a4a-a147-08d6434fc5ec x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020); SRVR:DM6PR01MB5194; x-ms-traffictypediagnostic: DM6PR01MB5194: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(10201501046)(3002001)(93006095)(93001095)(3231382)(944501410)(52105095)(148016)(149066)(150057)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(20161123562045)(20161123558120)(201708071742011)(7699051)(76991095); SRVR:DM6PR01MB5194; BCL:0; PCL:0; RULEID:; SRVR:DM6PR01MB5194; x-forefront-prvs: 08476BC6EF x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(396003)(346002)(136003)(39840400004)(376002)(366004)(189003)(199004)(81166006)(81156014)(53936002)(66066001)(6436002)(486006)(6486002)(6116002)(14444005)(110136005)(256004)(25786009)(4326008)(54906003)(14454004)(7736002)(305945005)(106356001)(26005)(105586002)(186003)(97736004)(39060400002)(102836004)(8936002)(2900100001)(2501003)(386003)(6506007)(8676002)(7416002)(476003)(316002)(52116002)(6512007)(2616005)(99286004)(76176011)(5660300001)(2906002)(86362001)(68736007)(71200400001)(71190400001)(3846002)(478600001)(446003)(1076002)(11346002); DIR:OUT; SFP:1102; SCL:1; SRVR:DM6PR01MB5194; H:DM6PR01MB4825.prod.exchangelabs.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:0; received-spf: None (protection.outlook.com: os.amperecomputing.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: TgyVnWujVZcPKCsGMMGllH5xG232F4CUhSzdCsg12dPHTyDjXx12/7bH++DYqm6Ol/J39MfcmXetEHtGzvL10wNVvFmDVR47QV6yZXAba1OSZZRpyYg3hWVYsUY8uruGCw6LDGkHezf8bCqhUXtC+qOYOiZ74evb822NBt7yHPs/76ptSmfKSKtmEojAlXW/AbJhmu52NuyK7eqRTGN0iqLFxJUw5EbfHUBpuiNaeobbMIyIryn7eUJoaYyCqCvzJ30ku93iRmmCj37gD9HDu1FziCzInK3MG9m7SPdRlSM8V+/RQ080VtZR90bj3aQ1QqGiQWz1YJCHMXisPVu2BIVIqWA4VVc7odtrXewop5k= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2d0ae81b-1f10-4a4a-a147-08d6434fc5ec X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Nov 2018 18:52:02.3852 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR01MB5194 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.37.99 Subject: [Qemu-devel] [PATCH v7 11/12] target/arm: Implement PMSWINC X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Aaron Lindsay , Michael Spradling , "qemu-devel@nongnu.org" , Digant Desai Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Aaron Lindsay Reviewed-by: Richard Henderson --- target/arm/helper.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/target/arm/helper.c b/target/arm/helper.c index 11eb62bdda..cff3a5a562 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -1027,6 +1027,15 @@ static bool event_always_supported(CPUARMState *env) return true; } +static uint64_t swinc_get_count(CPUARMState *env) +{ + /* + * SW_INCR events are written directly to the pmevcntr's by writes to + * PMSWINC, so there is no underlying count maintained by the PMU itself + */ + return 0; +} + /* * Return the underlying cycle count for the PMU cycle counters. If we're in * usermode, simply return 0. @@ -1054,6 +1063,10 @@ static uint64_t instructions_get_count(CPUARMState *env) #endif static const pm_event pm_events[] = { + { .number = 0x000, /* SW_INCR */ + .supported = event_always_supported, + .get_count = swinc_get_count, + }, #ifndef CONFIG_USER_ONLY { .number = 0x008, /* INST_RETIRED, Instruction architecturally executed */ .supported = instructions_supported, @@ -1378,6 +1391,24 @@ static void pmcr_write(CPUARMState *env, const ARMCPRegInfo *ri, pmu_op_finish(env); } +static void pmswinc_write(CPUARMState *env, const ARMCPRegInfo *ri, + uint64_t value) +{ + unsigned int i; + for (i = 0; i < pmu_num_counters(env); i++) { + /* Increment a counter's count iff: */ + if ((value & (1 << i)) && /* counter's bit is set */ + /* counter is enabled and not filtered */ + pmu_counter_enabled(env, i) && + /* counter is SW_INCR */ + (env->cp15.c14_pmevtyper[i] & PMXEVTYPER_EVTCOUNT) == 0x0) { + pmevcntr_op_start(env, i); + env->cp15.c14_pmevcntr[i]++; + pmevcntr_op_finish(env, i); + } + } +} + static uint64_t pmccntr_read(CPUARMState *env, const ARMCPRegInfo *ri) { uint64_t ret; @@ -1798,9 +1829,13 @@ static const ARMCPRegInfo v7_cp_reginfo[] = { .fieldoffset = offsetof(CPUARMState, cp15.c9_pmovsr), .writefn = pmovsr_write, .raw_writefn = raw_write }, - /* Unimplemented so WI. */ { .name = "PMSWINC", .cp = 15, .crn = 9, .crm = 12, .opc1 = 0, .opc2 = 4, - .access = PL0_W, .accessfn = pmreg_access_swinc, .type = ARM_CP_NOP }, + .access = PL0_W, .accessfn = pmreg_access_swinc, .type = ARM_CP_NO_RAW, + .writefn = pmswinc_write }, + { .name = "PMSWINC_EL0", .state = ARM_CP_STATE_AA64, + .opc0 = 3, .opc1 = 3, .crn = 9, .crm = 12, .opc2 = 4, + .access = PL0_W, .accessfn = pmreg_access_swinc, .type = ARM_CP_NO_RAW, + .writefn = pmswinc_write }, { .name = "PMSELR", .cp = 15, .crn = 9, .crm = 12, .opc1 = 0, .opc2 = 5, .access = PL0_RW, .type = ARM_CP_ALIAS, .fieldoffset = offsetoflow32(CPUARMState, cp15.c9_pmselr), From patchwork Mon Nov 5 18:52:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Lindsay X-Patchwork-Id: 10668951 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 264471751 for ; Mon, 5 Nov 2018 19:03:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1663029C45 for ; Mon, 5 Nov 2018 19:03:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0A56829C3F; Mon, 5 Nov 2018 19:03:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 09E7829C61 for ; Mon, 5 Nov 2018 19:03:05 +0000 (UTC) Received: from localhost ([::1]:37175 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJk9R-0001VG-2S for patchwork-qemu-devel@patchwork.kernel.org; Mon, 05 Nov 2018 14:03:05 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46858) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJjzX-0005ZR-Mj for qemu-devel@nongnu.org; Mon, 05 Nov 2018 13:52:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gJjzW-0001Sa-7r for qemu-devel@nongnu.org; Mon, 05 Nov 2018 13:52:51 -0500 Received: from mail-cys01nam02on0099.outbound.protection.outlook.com ([104.47.37.99]:43926 helo=NAM02-CY1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gJjzP-0000UT-F8; Mon, 05 Nov 2018 13:52:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amperemail.onmicrosoft.com; s=selector1-os-amperecomputing-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/CNyYYKQ2zHBGozh5/XI9kTs4hsJztEG8bskxDqUVUI=; b=RGKtrspSkmHm3ALbmFz9OQLrF5isoXmPPQhgQsKnskgdG+KuCcKrKwy/xInDwdUz8TeCdRCV2+WqVM8rOTXXFdvglxAKThDKZzgygCy8RZ5oRGUoWfUBJQoNYP1HhOK+hI7+sYzZWJ8nVJY419J76cLd+OZBi7hwGKL4sNjAUoo= Received: from DM6PR01MB4825.prod.exchangelabs.com (20.177.218.222) by DM6PR01MB5194.prod.exchangelabs.com (20.176.122.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.21; Mon, 5 Nov 2018 18:52:03 +0000 Received: from DM6PR01MB4825.prod.exchangelabs.com ([fe80::4cf7:c8dc:b673:ec66]) by DM6PR01MB4825.prod.exchangelabs.com ([fe80::4cf7:c8dc:b673:ec66%3]) with mapi id 15.20.1294.028; Mon, 5 Nov 2018 18:52:03 +0000 From: Aaron Lindsay To: "qemu-arm@nongnu.org" , Peter Maydell , Alistair Francis , Wei Huang , Peter Crosthwaite , Richard Henderson Thread-Topic: [PATCH v7 12/12] target/arm: Send interrupts on PMU counter overflow Thread-Index: AQHUdTikL9h6qRBa00SUiul/aHxLzg== Date: Mon, 5 Nov 2018 18:52:03 +0000 Message-ID: <20181105185046.2802-13-aaron@os.amperecomputing.com> References: <20181105185046.2802-1-aaron@os.amperecomputing.com> In-Reply-To: <20181105185046.2802-1-aaron@os.amperecomputing.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BN6PR20CA0070.namprd20.prod.outlook.com (2603:10b6:404:151::32) To DM6PR01MB4825.prod.exchangelabs.com (2603:10b6:5:6b::30) authentication-results: spf=none (sender IP is ) smtp.mailfrom=aaron@os.amperecomputing.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [216.85.170.153] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DM6PR01MB5194; 6:rxqLLKjaNa4u+i+6K/zs4/gYzqkGk/Atha2YnxI6+5u+YHM7FpDjyckdr9ked7UiNvgm+3+M8K12zlSfawXJpqqWAjeVI7/9ACeiAltiS9LV+gHmeVPnrj1E9oQUV3DhzPYbPiYIMmQugvsJklfhGeL5Ol9HnXaVMIpTm0Qy63RGslKy30i115zEX4jBYa1LEKgLE7mYh6lweVKqv8O2vknvTXrBIV3L8ID4bei9lUSK77ZIdCsVBnjNm3OfPbI1yJngiIfTp9WUfqWWsjbgKDUOu/2RCvPWW1dDTFVJS9ASFlXw9GMG/AT5jxhPDuCXsiM7KQbneRFuIiPvLFXLeMA/KXzS9YjyYQFhfKnDiQiOBbfRxElBFn3snyKh5/Z7UrSAWF1sRxpzLQ3Durz+7bjnN2zp/T2eYsaCOkVfpV1o9xhSDMQBn5FcHaTMXR3JnmR1xFRbvo/kloCKRhu6tg==; 5:FIxBpkCN/0BBC5/2kyqg9KDp8PUUrYYh1p6FubeLvxwlh+w2N+VBeBjAbkbUaiex7T2Z4Blf07EGgNmzzyE6reVYXhw9epnTCD3L8+M+DghmE5aUROJIkSlRb9Ap9ylF8z0cYh9ADmbJzMUUNrAtwBHmfbhjI/jIkKhIGurI2hU=; 7:Kp5eAGqfQXQMTiillTKKRmRF2S6P9G0OMBNZ8SXOjGn8/J29LJEnFIDTvr1k5Raoq79T8Omjq0QMObGHTL42TuePS9Xo4QPlb1AXUnE+1pMNMKLIGgsvmhdnNhQFMy0wi6EI4quNjE4/k77X6sSsNQ== x-ms-office365-filtering-correlation-id: 65b52f08-e488-4b4f-11e4-08d6434fc6a7 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020); SRVR:DM6PR01MB5194; x-ms-traffictypediagnostic: DM6PR01MB5194: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(10201501046)(3002001)(93006095)(93001095)(3231382)(944501410)(52105095)(148016)(149066)(150057)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(20161123562045)(20161123558120)(201708071742011)(7699051)(76991095); SRVR:DM6PR01MB5194; BCL:0; PCL:0; RULEID:; SRVR:DM6PR01MB5194; x-forefront-prvs: 08476BC6EF x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(396003)(346002)(136003)(39840400004)(376002)(366004)(189003)(199004)(81166006)(81156014)(53936002)(66066001)(6436002)(486006)(6486002)(6116002)(14444005)(110136005)(256004)(25786009)(4326008)(54906003)(14454004)(7736002)(305945005)(106356001)(26005)(105586002)(186003)(97736004)(39060400002)(102836004)(8936002)(2900100001)(2501003)(386003)(6506007)(8676002)(7416002)(476003)(316002)(52116002)(6512007)(2616005)(99286004)(76176011)(5660300001)(2906002)(86362001)(68736007)(71200400001)(71190400001)(575784001)(3846002)(478600001)(4744004)(446003)(1076002)(11346002); DIR:OUT; SFP:1102; SCL:1; SRVR:DM6PR01MB5194; H:DM6PR01MB4825.prod.exchangelabs.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:0; received-spf: None (protection.outlook.com: os.amperecomputing.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: U2IjCjKRgN9zqJMko/JJli+lQjqbc0AiTXkn7NQCRvNckpgS3QM3xPDZNBH5qDK5LRmbAe8vc+c2ekIf/SFJUJ92yuP/hPphKlXKkl/CmifIEi8EHGU5Wtdu75KBF4EMPwT72h3vdHYJGyBhUbe9UvS0Tcsyl4NZGBY+g16u6s5RkfIGCqlA9y8fNES2X4BKuLAgsJsq/27wO7l0BZV0hRbWcIPNhblSjs0aHwuOMeR9r/Jb9jiEVXRIryxfvBOB7ugcq4XZVRGKmbWMBxYiUv++q3yjRglJpq1EQRDEExofwKlwzbyPS9GYs/0Q7YagmsA6IkDC1W9DRrhCiSwT1lexcLH+VFAAu3TOuDxeE6M= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 65b52f08-e488-4b4f-11e4-08d6434fc6a7 X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Nov 2018 18:52:03.5250 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR01MB5194 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.37.99 Subject: [Qemu-devel] [PATCH v7 12/12] target/arm: Send interrupts on PMU counter overflow X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Aaron Lindsay , Michael Spradling , "qemu-devel@nongnu.org" , Digant Desai Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Setup a QEMUTimer to get a callback when we expect counters to next overflow and trigger an interrupt at that time. Signed-off-by: Aaron Lindsay --- target/arm/cpu.c | 11 ++++ target/arm/cpu.h | 7 +++ target/arm/helper.c | 126 +++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 138 insertions(+), 6 deletions(-) diff --git a/target/arm/cpu.c b/target/arm/cpu.c index d1c766d180..7cb6a76afb 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -764,6 +764,12 @@ static void arm_cpu_finalizefn(Object *obj) QLIST_REMOVE(hook, node); g_free(hook); } +#ifndef CONFIG_USER_ONLY + if (arm_feature(&cpu->env, ARM_FEATURE_PMU)) { + timer_deinit(cpu->pmu_timer); + timer_free(cpu->pmu_timer); + } +#endif } static void arm_cpu_realizefn(DeviceState *dev, Error **errp) @@ -967,6 +973,11 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) arm_register_pre_el_change_hook(cpu, &pmu_pre_el_change, 0); arm_register_el_change_hook(cpu, &pmu_post_el_change, 0); } + +#ifndef CONFIG_USER_ONLY + cpu->pmu_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, arm_pmu_timer_cb, + cpu); +#endif } else { cpu->pmceid0 = 0x00000000; cpu->pmceid1 = 0x00000000; diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 067f6efdb6..fa49dc4c47 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -730,6 +730,8 @@ struct ARMCPU { /* Timers used by the generic (architected) timer */ QEMUTimer *gt_timer[NUM_GTIMERS]; + /* Timer used by the PMU */ + QEMUTimer *pmu_timer; /* GPIO outputs for generic timer */ qemu_irq gt_timer_outputs[NUM_GTIMERS]; /* GPIO output for GICv3 maintenance interrupt signal */ @@ -988,6 +990,11 @@ void pmccntr_op_finish(CPUARMState *env); void pmu_op_start(CPUARMState *env); void pmu_op_finish(CPUARMState *env); +/** + * Called when a PMU counter is due to overflow + */ +void arm_pmu_timer_cb(void *opaque); + /** * Functions to register as EL change hooks for PMU mode filtering */ diff --git a/target/arm/helper.c b/target/arm/helper.c index cff3a5a562..6c3f997b0e 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -977,6 +977,7 @@ static const ARMCPRegInfo v6_cp_reginfo[] = { /* Definitions for the PMU registers */ #define PMCRN_MASK 0xf800 #define PMCRN_SHIFT 11 +#define PMCRLC 0x40 #define PMCRDP 0x10 #define PMCRD 0x8 #define PMCRC 0x4 @@ -996,6 +997,8 @@ static const ARMCPRegInfo v6_cp_reginfo[] = { PMXEVTYPER_M | PMXEVTYPER_MT | \ PMXEVTYPER_EVTCOUNT) +#define PMEVCNTR_OVERFLOW_MASK ((uint64_t)1 << 31) + #define PMCCFILTR 0xf8000000 #define PMCCFILTR_M PMXEVTYPER_M #define PMCCFILTR_EL0 (PMCCFILTR | PMCCFILTR_M) @@ -1020,6 +1023,11 @@ typedef struct pm_event { * counters hold a difference from the return value from this function */ uint64_t (*get_count)(CPUARMState *); + /* Return how many nanoseconds it will take (at a minimum) for count events + * to occur. A negative value indicates the counter will never overflow, or + * that the counter has otherwise arranged for the overflow bit to be set + * and the PMU interrupt to be raised on overflow. */ + int64_t (*ns_per_count)(uint64_t); } pm_event; static bool event_always_supported(CPUARMState *env) @@ -1036,6 +1044,11 @@ static uint64_t swinc_get_count(CPUARMState *env) return 0; } +static int64_t swinc_ns_per(uint64_t ignored) +{ + return -1; +} + /* * Return the underlying cycle count for the PMU cycle counters. If we're in * usermode, simply return 0. @@ -1051,6 +1064,11 @@ static uint64_t cycles_get_count(CPUARMState *env) } #ifndef CONFIG_USER_ONLY +static int64_t cycles_ns_per(uint64_t cycles) +{ + return (ARM_CPU_FREQ / NANOSECONDS_PER_SECOND) * cycles; +} + static bool instructions_supported(CPUARMState *env) { return use_icount == 1 /* Precise instruction counting */; @@ -1060,21 +1078,29 @@ static uint64_t instructions_get_count(CPUARMState *env) { return (uint64_t)cpu_get_icount_raw(); } + +static int64_t instructions_ns_per(uint64_t icount) +{ + return cpu_icount_to_ns((int64_t)icount); +} #endif static const pm_event pm_events[] = { { .number = 0x000, /* SW_INCR */ .supported = event_always_supported, .get_count = swinc_get_count, + .ns_per_count = swinc_ns_per, }, #ifndef CONFIG_USER_ONLY { .number = 0x008, /* INST_RETIRED, Instruction architecturally executed */ .supported = instructions_supported, .get_count = instructions_get_count, + .ns_per_count = instructions_ns_per, }, { .number = 0x011, /* CPU_CYCLES, Cycle */ .supported = event_always_supported, .get_count = cycles_get_count, + .ns_per_count = cycles_ns_per, } #endif }; @@ -1273,6 +1299,13 @@ static bool pmu_counter_enabled(CPUARMState *env, uint8_t counter) return enabled && !prohibited && !filtered; } +static void pmu_update_irq(CPUARMState *env) +{ + ARMCPU *cpu = arm_env_get_cpu(env); + qemu_set_irq(cpu->pmu_interrupt, (env->cp15.c9_pmcr & PMCRE) && + (env->cp15.c9_pminten & env->cp15.c9_pmovsr)); +} + /* * Ensure c15_ccnt is the guest-visible count so that operations such as * enabling/disabling the counter or filtering, modifying the count itself, @@ -1290,7 +1323,18 @@ void pmccntr_op_start(CPUARMState *env) eff_cycles /= 64; } - env->cp15.c15_ccnt = eff_cycles - env->cp15.c15_ccnt_delta; + uint64_t new_pmccntr = eff_cycles - env->cp15.c15_ccnt_delta; + + unsigned int overflow_bit = (env->cp15.c9_pmcr & PMCRLC) ? 63 : 31; + uint64_t overflow_mask = (uint64_t)1 << overflow_bit; + if (!(new_pmccntr & overflow_mask) && + (env->cp15.c15_ccnt & overflow_mask)) { + env->cp15.c9_pmovsr |= (1 << 31); + new_pmccntr &= ~overflow_mask; + pmu_update_irq(env); + } + + env->cp15.c15_ccnt = new_pmccntr; } env->cp15.c15_ccnt_delta = cycles; } @@ -1303,13 +1347,28 @@ void pmccntr_op_start(CPUARMState *env) void pmccntr_op_finish(CPUARMState *env) { if (pmu_counter_enabled(env, 31)) { - uint64_t prev_cycles = env->cp15.c15_ccnt_delta; +#ifndef CONFIG_USER_ONLY + uint64_t delta; + if (env->cp15.c9_pmcr & PMCRLC) { + delta = UINT64_MAX - env->cp15.c15_ccnt + 1; + } else { + delta = UINT32_MAX - (uint32_t)env->cp15.c15_ccnt + 1; + } + int64_t overflow_in = cycles_ns_per(delta); + + if (overflow_in > 0) { + int64_t overflow_at = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + + overflow_in; + ARMCPU *cpu = arm_env_get_cpu(env); + timer_mod_anticipate_ns(cpu->pmu_timer, overflow_at); + } +#endif + uint64_t prev_cycles = env->cp15.c15_ccnt_delta; if (env->cp15.c9_pmcr & PMCRD) { /* Increment once every 64 processor clock cycles */ prev_cycles /= 64; } - env->cp15.c15_ccnt_delta = prev_cycles - env->cp15.c15_ccnt; } } @@ -1325,8 +1384,15 @@ static void pmevcntr_op_start(CPUARMState *env, uint8_t counter) } if (pmu_counter_enabled(env, counter)) { - env->cp15.c14_pmevcntr[counter] = - count - env->cp15.c14_pmevcntr_delta[counter]; + uint64_t new_pmevcntr = count - env->cp15.c14_pmevcntr_delta[counter]; + + if (!(new_pmevcntr & PMEVCNTR_OVERFLOW_MASK) && + (env->cp15.c14_pmevcntr[counter] & PMEVCNTR_OVERFLOW_MASK)) { + env->cp15.c9_pmovsr |= (1 << counter); + new_pmevcntr &= ~PMEVCNTR_OVERFLOW_MASK; + pmu_update_irq(env); + } + env->cp15.c14_pmevcntr[counter] = new_pmevcntr; } env->cp15.c14_pmevcntr_delta[counter] = count; } @@ -1334,6 +1400,21 @@ static void pmevcntr_op_start(CPUARMState *env, uint8_t counter) static void pmevcntr_op_finish(CPUARMState *env, uint8_t counter) { if (pmu_counter_enabled(env, counter)) { +#ifndef CONFIG_USER_ONLY + uint16_t event = env->cp15.c14_pmevtyper[counter] & PMXEVTYPER_EVTCOUNT; + uint16_t event_idx = supported_event_map[event]; + uint64_t delta = UINT32_MAX - + (uint32_t)env->cp15.c14_pmevcntr[counter] + 1; + int64_t overflow_in = pm_events[event_idx].ns_per_count(delta); + + if (overflow_in > 0) { + int64_t overflow_at = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + + overflow_in; + ARMCPU *cpu = arm_env_get_cpu(env); + timer_mod_anticipate_ns(cpu->pmu_timer, overflow_at); + } +#endif + env->cp15.c14_pmevcntr_delta[counter] -= env->cp15.c14_pmevcntr[counter]; } @@ -1367,6 +1448,19 @@ void pmu_post_el_change(ARMCPU *cpu, void *ignored) pmu_op_finish(&cpu->env); } +void arm_pmu_timer_cb(void *opaque) +{ + ARMCPU *cpu = opaque; + + /* Update all the counter values based on the current underlying counts, + * triggering interrupts to be raised, if necessary. pmu_op_finish() also + * has the effect of setting the cpu->pmu_timer to the next earliest time a + * counter may expire. + */ + pmu_op_start(&cpu->env); + pmu_op_finish(&cpu->env); +} + static void pmcr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value) { @@ -1403,7 +1497,21 @@ static void pmswinc_write(CPUARMState *env, const ARMCPRegInfo *ri, /* counter is SW_INCR */ (env->cp15.c14_pmevtyper[i] & PMXEVTYPER_EVTCOUNT) == 0x0) { pmevcntr_op_start(env, i); - env->cp15.c14_pmevcntr[i]++; + + /* Detect if this write causes an overflow since we can't predict + * PMSWINC overflows like we can for other events + */ + uint64_t new_pmswinc = env->cp15.c14_pmevcntr[i] + 1; + + if (!(new_pmswinc & PMEVCNTR_OVERFLOW_MASK) && + (env->cp15.c14_pmevcntr[i] & PMEVCNTR_OVERFLOW_MASK)) { + env->cp15.c9_pmovsr |= (1 << i); + new_pmswinc &= ~PMEVCNTR_OVERFLOW_MASK; + pmu_update_irq(env); + } + + env->cp15.c14_pmevcntr[i] = new_pmswinc; + pmevcntr_op_finish(env, i); } } @@ -1474,6 +1582,7 @@ static void pmcntenset_write(CPUARMState *env, const ARMCPRegInfo *ri, { value &= pmu_counter_mask(env); env->cp15.c9_pmcnten |= value; + pmu_update_irq(env); } static void pmcntenclr_write(CPUARMState *env, const ARMCPRegInfo *ri, @@ -1481,6 +1590,7 @@ static void pmcntenclr_write(CPUARMState *env, const ARMCPRegInfo *ri, { value &= pmu_counter_mask(env); env->cp15.c9_pmcnten &= ~value; + pmu_update_irq(env); } static void pmovsr_write(CPUARMState *env, const ARMCPRegInfo *ri, @@ -1488,6 +1598,7 @@ static void pmovsr_write(CPUARMState *env, const ARMCPRegInfo *ri, { value &= pmu_counter_mask(env); env->cp15.c9_pmovsr &= ~value; + pmu_update_irq(env); } static void pmovsset_write(CPUARMState *env, const ARMCPRegInfo *ri, @@ -1495,6 +1606,7 @@ static void pmovsset_write(CPUARMState *env, const ARMCPRegInfo *ri, { value &= pmu_counter_mask(env); env->cp15.c9_pmovsr |= value; + pmu_update_irq(env); } static void pmevtyper_write(CPUARMState *env, const ARMCPRegInfo *ri, @@ -1681,6 +1793,7 @@ static void pmintenset_write(CPUARMState *env, const ARMCPRegInfo *ri, /* We have no event counters so only the C bit can be changed */ value &= pmu_counter_mask(env); env->cp15.c9_pminten |= value; + pmu_update_irq(env); } static void pmintenclr_write(CPUARMState *env, const ARMCPRegInfo *ri, @@ -1688,6 +1801,7 @@ static void pmintenclr_write(CPUARMState *env, const ARMCPRegInfo *ri, { value &= pmu_counter_mask(env); env->cp15.c9_pminten &= ~value; + pmu_update_irq(env); } static void vbar_write(CPUARMState *env, const ARMCPRegInfo *ri,