From patchwork Tue Jul 18 12:09:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 9848209 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 34E98602C8 for ; Tue, 18 Jul 2017 12:10:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 21CA3205FC for ; Tue, 18 Jul 2017 12:10:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 159DF269DA; Tue, 18 Jul 2017 12:10:06 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D3A4205FC for ; Tue, 18 Jul 2017 12:10:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751411AbdGRMKD (ORCPT ); Tue, 18 Jul 2017 08:10:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37504 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751336AbdGRMKC (ORCPT ); Tue, 18 Jul 2017 08:10:02 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D5AD07F6B1; Tue, 18 Jul 2017 12:10:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D5AD07F6B1 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=drjones@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com D5AD07F6B1 Received: from kamzik.brq.redhat.com (unknown [10.43.2.160]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E90FC5C88F; Tue, 18 Jul 2017 12:09:59 +0000 (UTC) Date: Tue, 18 Jul 2017 14:09:57 +0200 From: Andrew Jones To: Christoffer Dall Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Alexander Graf , Paolo Bonzini , Radim =?utf-8?B?S3LEjW3DocWZ?= , Jintack Lim , Marc Zyngier Subject: Re: [PATCH kvm-unit-tests 3/3] arm64: timer: Add support for phys timer testing Message-ID: <20170718120957.uvxb546eqpj5oxbp@kamzik.brq.redhat.com> References: <20170713192009.10069-1-cdall@linaro.org> <20170713192009.10069-4-cdall@linaro.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20170713192009.10069-4-cdall@linaro.org> User-Agent: Mutt/1.6.0.1 (2016-04-01) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 18 Jul 2017 12:10:02 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Thu, Jul 13, 2017 at 09:20:09PM +0200, Christoffer Dall wrote: > Rearrange the code to be able to reuse as much as posible and add > support for testing the physical timer as well. > > Also change the default unittests configuration to run a separate vtimer > and ptimer test so that older kernels without ptimer support just show a > failure. We could run tests for both the ptimer and vtimer in a single execution, rather than splitting them and requiring the input, because the read of cntp_ctl_el0 will predictably cause an UNKNOWN exception. Also, by applying the errata framework we can ensure that if we expect the read to work, i.e. the host kernel is recent enough, then, if we still get an UNKNOWN exception, we can report FAIL instead of SKIP. Below is an add on patch that makes the conversion. Let me know what you think. Thanks, drew diff --git a/arm/timer.c b/arm/timer.c index 33dfc6facc190..d0ba1e9a3bafa 100644 --- a/arm/timer.c +++ b/arm/timer.c @@ -7,6 +7,7 @@ */ #include #include +#include #include #include #include @@ -16,6 +17,27 @@ #define ARCH_TIMER_CTL_ISTATUS (1 << 2) static void *gic_ispendr; +static bool ptimer_unsupported; + +static void ptimer_unsupported_handler(struct pt_regs *regs, unsigned int esr) +{ + ptimer_unsupported = true; + regs->pc += 4; +} + +static void set_ptimer_unsupported(void) +{ + install_exception_handler(EL1H_SYNC, ESR_EL1_EC_UNKNOWN, ptimer_unsupported_handler); + read_sysreg(cntp_ctl_el0); + install_exception_handler(EL1H_SYNC, ESR_EL1_EC_UNKNOWN, NULL); + + if (ptimer_unsupported && !ERRATA(7b6b46311a85)) { + report_skip("Skipping ptimer tests. Set ERRATA_7b6b46311a85=y to enable."); + } else if (ptimer_unsupported) { + report("ptimer: read CNTP_CTL_EL0", false); + report_info("ptimer: skipping remaining tests"); + } +} static u64 read_vtimer_counter(void) { @@ -159,7 +181,6 @@ static void test_timer(struct timer_info *info) u64 time_10s = read_sysreg(cntfrq_el0) * 10; u64 later = now + time_10s; - /* Enable the timer, but schedule it for much later*/ info->write_cval(later); isb(); @@ -182,6 +203,9 @@ static void test_vtimer(void) static void test_ptimer(void) { + if (ptimer_unsupported) + return; + report_prefix_push("ptimer-busy-loop"); test_timer(&ptimer_info); report_prefix_pop(); @@ -226,52 +250,27 @@ static void test_init(void) local_irq_enable(); } -static void print_vtimer_info(void) +static void print_timer_info(void) { printf("CNTFRQ_EL0 : 0x%016lx\n", read_sysreg(cntfrq_el0)); + + if (!ptimer_unsupported) { + printf("CNTPCT_EL0 : 0x%016lx\n", read_sysreg(cntpct_el0)); + printf("CNTP_CTL_EL0 : 0x%016lx\n", read_sysreg(cntp_ctl_el0)); + printf("CNTP_CVAL_EL0: 0x%016lx\n", read_sysreg(cntp_cval_el0)); + } + printf("CNTVCT_EL0 : 0x%016lx\n", read_sysreg(cntvct_el0)); printf("CNTV_CTL_EL0 : 0x%016lx\n", read_sysreg(cntv_ctl_el0)); printf("CNTV_CVAL_EL0: 0x%016lx\n", read_sysreg(cntv_cval_el0)); } -static void print_ptimer_info(void) -{ - printf("CNTPCT_EL0 : 0x%016lx\n", read_sysreg(cntpct_el0)); - printf("CNTP_CTL_EL0 : 0x%016lx\n", read_sysreg(cntp_ctl_el0)); - printf("CNTP_CVAL_EL0: 0x%016lx\n", read_sysreg(cntp_cval_el0)); -} - - int main(int argc, char **argv) { - bool run_ptimer_test = false; - bool run_vtimer_test = false; - - /* Check if we should also check the physical timer */ - if (argc > 1) { - if (strcmp(argv[1], "vtimer") == 0) { - run_vtimer_test = true; - } else if (strcmp(argv[1], "ptimer") == 0) { - run_ptimer_test = true; - } else { - report_abort("Unknown option '%s'", argv[1]); - } - } else { - run_vtimer_test = true; - } - - if (run_vtimer_test) - print_vtimer_info(); - else if (run_ptimer_test) - print_ptimer_info(); - + set_ptimer_unsupported(); + print_timer_info(); test_init(); - - if (run_vtimer_test) - test_vtimer(); - else if (run_ptimer_test) - test_ptimer(); - - + test_ptimer(); + test_vtimer(); return report_summary(); } diff --git a/arm/unittests.cfg b/arm/unittests.cfg index d55e52e1a4c4f..bdfedf86b01cb 100644 --- a/arm/unittests.cfg +++ b/arm/unittests.cfg @@ -111,14 +111,7 @@ smp = $MAX_SMP groups = psci # Timer tests -[vtimer] +[timer] file = timer.flat -extra_params = -append 'vtimer' -groups = timer -timeout = 2s - -[ptimer] -file = timer.flat -extra_params = -append 'ptimer' groups = timer timeout = 2s