From patchwork Tue Oct 6 17:49:25 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Covington X-Patchwork-Id: 7338861 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 66717BF90C for ; Tue, 6 Oct 2015 17:50:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8BFC620718 for ; Tue, 6 Oct 2015 17:50:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5FBBD20615 for ; Tue, 6 Oct 2015 17:50:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752127AbbJFRuI (ORCPT ); Tue, 6 Oct 2015 13:50:08 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:39270 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751204AbbJFRuH (ORCPT ); Tue, 6 Oct 2015 13:50:07 -0400 Received: from smtp.codeaurora.org (localhost [127.0.0.1]) by smtp.codeaurora.org (Postfix) with ESMTP id CD1A01418D5; Tue, 6 Oct 2015 17:50:06 +0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 486) id BCF811418E2; Tue, 6 Oct 2015 17:50:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from keeshans.qualcomm.com (rrcs-67-52-130-30.west.biz.rr.com [67.52.130.30]) (using TLSv1.1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: cov@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 5EF041418DA; Tue, 6 Oct 2015 17:50:05 +0000 (UTC) From: Christopher Covington To: drjones@redhat.com, qemu-devel@nongnu.org, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, wei@redhat.com Cc: shannon.zhao@linaro.org, alistair.francis@xilinx.com, croberts@codeaurora.org, alindsay@codeaurora.org, Christopher Covington Subject: [kvm-unit-tests PATCHv3 2/3] arm: pmu: Check cycle count increases Date: Tue, 6 Oct 2015 13:49:25 -0400 Message-Id: <1444153766-12532-3-git-send-email-cov@codeaurora.org> X-Mailer: git-send-email 1.8.1.1 In-Reply-To: <1444153766-12532-1-git-send-email-cov@codeaurora.org> References: <5612EDA5.9010506@redhat.com> <1444153766-12532-1-git-send-email-cov@codeaurora.org> X-Virus-Scanned: ClamAV using ClamSMTP Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Ensure that reads of the PMCCNTR_EL0 are monotonically increasing, even for the smallest delta of two subsequent reads. Signed-off-by: Christopher Covington --- arm/pmu.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/arm/pmu.c b/arm/pmu.c index 91a3688..589e605 100644 --- a/arm/pmu.c +++ b/arm/pmu.c @@ -33,6 +33,8 @@ struct pmu_data { }; }; +static const int samples = 10; + /* As a simple sanity check on the PMCR_EL0, ensure the implementer field isn't * null. Also print out a couple other interesting fields for diagnostic * purposes. For example, as of fall 2015, QEMU TCG mode doesn't implement @@ -56,11 +58,38 @@ static bool check_pmcr(void) return false; } +/* Ensure that the cycle counter progresses between back-to-back reads. + */ +static bool check_cycles_increase(void) +{ + struct pmu_data pmcr; + + pmcr.enable = 1; + asm volatile("msr pmcr_el0, %0" : : "r" (pmcr)); + + for (int i = 0; i < samples; i++) { + int a, b; + + asm volatile( + "mrs %[a], pmccntr_el0\n" + "mrs %[b], pmccntr_el0\n" + : [a] "=r" (a), [b] "=r" (b)); + + if (a >= b) { + printf("Read %d then %d.\n", a, b); + return false; + } + } + + return true; +} + int main(void) { report_prefix_push("pmu"); report("Control register", check_pmcr()); + report("Monotonically increasing cycle count", check_cycles_increase()); return report_summary(); }