From patchwork Wed Jun 28 05:00:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pranith Kumar X-Patchwork-Id: 9813473 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 421D060383 for ; Wed, 28 Jun 2017 05:01:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3847D223C7 for ; Wed, 28 Jun 2017 05:01:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2CB432679B; Wed, 28 Jun 2017 05:01: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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 C6A85223C7 for ; Wed, 28 Jun 2017 05:01:31 +0000 (UTC) Received: from localhost ([::1]:59216 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQ56Y-0002ca-Pb for patchwork-qemu-devel@patchwork.kernel.org; Wed, 28 Jun 2017 01:01:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57443) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQ55b-0002bv-Ua for qemu-devel@nongnu.org; Wed, 28 Jun 2017 01:00:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQ55X-0004ip-6G for qemu-devel@nongnu.org; Wed, 28 Jun 2017 01:00:32 -0400 Received: from mail-yw0-x242.google.com ([2607:f8b0:4002:c05::242]:35172) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dQ55X-0004iG-2G for qemu-devel@nongnu.org; Wed, 28 Jun 2017 01:00:27 -0400 Received: by mail-yw0-x242.google.com with SMTP id z21so2779536ywz.2 for ; Tue, 27 Jun 2017 22:00:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ujQKbM5GLyl+UJnaL6EjwtfHJdRYGciCHU1Ajpe+13M=; b=Ek8e7mf5GCBIZbNbIQqoWDDA4J0fXSj+KYYWaXfyewkrw3FsZKDAzCpdbHfhsngHF7 BB5hb0Ur7+j854z615VuL4yW8NVfKBQ2Mx5dNg6OoGmUGaaYAgYthsOB1H5MYmPILjpu VPbOLCuQChv8ELT0z410GX+WkuM7Ld6wwTqmjD+4fted/S+6rJkZAqCFRzJ1ESg3/szQ q2A0e4cJFGde4INjjdxylgRzeLKKk2BHMpdl+/ZN81+G1YJ4FboROw+irBYtv13iigpT 8jyKZUMGTCjYtT3O4uZbjTfn+AOJ7yNv3GWQOmmPklglBx4p2vMe5IeGMR5uqtFuy3D7 Bw9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ujQKbM5GLyl+UJnaL6EjwtfHJdRYGciCHU1Ajpe+13M=; b=aEqXWj8jJK5l/HPLSDRI7lFmzhBnexR8kEL/QiiK/qvY7w56GYnaglb58QZ7n7PWo7 7AxnByBG7U6BBnNinMkE8Ac1zoUVkPcDER0UxZdiccW4mAWzrBJLbQurhdlVVSKiTd7g njh1jTZ3QjtwfCnsCIURD6ptXs3IuJ/jlJYz1N8HUMw3I1j5o7KgBtk8wr4QELh+g6ep QtSkHnOAQfgHPI2lot/fqKA67ZcLM8scMEwj4kg9ZzCO+DLqgBrvIJ/WSBI9RswybcCn d5BkBc8GhrdfJzp+XNDhIm4cWCL4nnNmpFSxq/jpQC+sTgCCekU6560bFzdHKRCdPi7/ Idkw== X-Gm-Message-State: AKS2vOz4HNy10bKrQiGOYynqtfSQfpa2XSW+Hh2DlrbuAWz7oHEZ5kjk b3BUoPt/jL2pw8KPaIw= X-Received: by 10.129.39.149 with SMTP id n143mr6467192ywn.189.1498626024951; Tue, 27 Jun 2017 22:00:24 -0700 (PDT) Received: from localhost.localdomain (c-73-207-178-95.hsd1.ga.comcast.net. [73.207.178.95]) by smtp.gmail.com with ESMTPSA id d2sm521898ywb.53.2017.06.27.22.00.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Jun 2017 22:00:24 -0700 (PDT) From: Pranith Kumar To: alex.bennee@linaro.org Date: Wed, 28 Jun 2017 01:00:02 -0400 Message-Id: <20170628050003.1809-2-bobby.prani@gmail.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170628050003.1809-1-bobby.prani@gmail.com> References: <20170628050003.1809-1-bobby.prani@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4002:c05::242 Subject: [Qemu-devel] [PATCH 1/2] [TEST] aarch64: Use pmuserenr_el0 register for instrumentation 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: qemu-devel@nongnu.org, rth@twiddle.net Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP We need a way for the benchmark running in the guest to indicate us to start/stop our instrumentation. On x86, we could use the 'cpuid' instruction along with an appropriately populated 'eax' register. However, no such dummy instruction exists for aarch64. So we modify the permission bits for 'pmuserenr_el0' register and tap that to instrument the guest code. You can use the following annotations on your region-of-interest to instrument the code. #define magic_enable() \ asm volatile ("msr pmuserenr_el0, %0" :: "r" (0xaaaaaaaa)); #define magic_disable() \ asm volatile ("msr pmuserenr_el0, %0" :: "r" (0xfa11dead)); Signed-off-by: Pranith Kumar --- target/arm/helper.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/target/arm/helper.c b/target/arm/helper.c index 2594faa9b8..dfbf03676c 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -1124,9 +1124,24 @@ static uint64_t pmxevtyper_read(CPUARMState *env, const ARMCPRegInfo *ri) } } +bool enable_instrumentation; + static void pmuserenr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value) { + ARMCPU *cpu = arm_env_get_cpu(env); + CPUState *cs = CPU(cpu); + + if (value == 0xaaaaaaaa) { + printf("Enabling instrumentation\n"); + enable_instrumentation = true; + tb_flush(cs); + } else if (value == 0xfa11dead) { + printf("Disabling instrumentation\n"); + enable_instrumentation = false; + tb_flush(cs); + } + if (arm_feature(env, ARM_FEATURE_V8)) { env->cp15.c9_pmuserenr = value & 0xf; } else { @@ -1316,13 +1331,13 @@ static const ARMCPRegInfo v7_cp_reginfo[] = { .access = PL0_RW, .type = ARM_CP_CONST, .resetvalue = 0, .accessfn = pmreg_access_xevcntr }, { .name = "PMUSERENR", .cp = 15, .crn = 9, .crm = 14, .opc1 = 0, .opc2 = 0, - .access = PL0_R | PL1_RW, .accessfn = access_tpm, + .access = PL0_RW | PL1_RW, .accessfn = access_tpm, .fieldoffset = offsetof(CPUARMState, cp15.c9_pmuserenr), .resetvalue = 0, .writefn = pmuserenr_write, .raw_writefn = raw_write }, { .name = "PMUSERENR_EL0", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 3, .crn = 9, .crm = 14, .opc2 = 0, - .access = PL0_R | PL1_RW, .accessfn = access_tpm, .type = ARM_CP_ALIAS, + .access = PL0_RW | PL1_RW, .accessfn = access_tpm, .type = ARM_CP_ALIAS, .fieldoffset = offsetof(CPUARMState, cp15.c9_pmuserenr), .resetvalue = 0, .writefn = pmuserenr_write, .raw_writefn = raw_write },