From patchwork Wed Aug 3 18:23:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Koller X-Patchwork-Id: 12935847 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3AD0EC19F2A for ; Wed, 3 Aug 2022 18:23:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237985AbiHCSXh (ORCPT ); Wed, 3 Aug 2022 14:23:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237313AbiHCSXf (ORCPT ); Wed, 3 Aug 2022 14:23:35 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9E101A384 for ; Wed, 3 Aug 2022 11:23:33 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id d66-20020a636845000000b0040a88edd9c1so7133419pgc.13 for ; Wed, 03 Aug 2022 11:23:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc; bh=2RN8WdnxLDMPgrvxgN2wYqtVPlMrXXuTUXGTj1+65DM=; b=QVEFwIOwZt8R5Z8q4bkJEMoWSqkNWKnjuIBWbf0GrikPC5oX3OYokBN2IGEJTf3jPp 04MHsJwDP2SRwknw+mZhprV/X1CXzPU/tjMvofFVcAi3FpOObNVpYGp0pkToIfT74V3b JphBTOGpWSXb2HoI2JAMa1IW6z+06u8Y3HrVtdd7KQcosMRdUJ1mJrH9E8gIY6PT0lTW sdQDndeGmazVzrCop1YXz7QfRTaCuc74vOf02BJXDlhBlPEq5QQvpygPa4tWihsBnhgr F0OeUdv8OmmAXdxrC2vCNje08dpzKltX7zc7KoU5NS3zRmGU4A3e7PB6IsBNrFX3iVpQ uKvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc; bh=2RN8WdnxLDMPgrvxgN2wYqtVPlMrXXuTUXGTj1+65DM=; b=lJr5XzLJwMdIBZBOrw/6aFeuLzUY4HBgkWIiv+wq0Ytd8hGFlax2vIdsJnHsVfs73f VpgT6kuwLzMN7iMZdg94coDrPBJb+ucO3QXyJYxLtHkac+SCxPpmB56hVql5TztmJvTF WrHgwCz+Ra2ccEW+4acGL4c1Eod8COZ0E47kYkrwCYHVSWPmuipOYjqrmXIyZzmeN5OR ZVgjvIHEHridelUnHSO9HDxK5hdERFWFXgLxsfqwo47FtkQBPZF4FbxeZnnpD5SNIgXQ 5WKeLTbDWqtrVS4X4U13f+Ru/22fKbxayjrV+1hNXgCYO9lTXV8/jjoZa7Kh2s1Svdgv 7Jaw== X-Gm-Message-State: ACgBeo2dz1QuB1BqyYcPmIQCuSMwDfuJJG0JFfE88xpH5gZ/2eUhq84u JrOUQzVPuszHAvxCrET06ugztgUMs2Fs2jrrqCTQ4JFR35P2rnP+F2KyrCUJ0tiiVrgRyBOTEAH fAp/JHP+SziCVFh6GjjPIaXVHWqIqNkct3Aq8QiOWd6VW65iEmUACSCMru2cStjU= X-Google-Smtp-Source: AA6agR6dgkGBDlh0rvSP6cHQDe4O2i9+BqdkG6d3wGniU9eAQv65BzuHTVRI5h1dCXl855yekQ7KvJtk8rs5+Q== X-Received: from ricarkol2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:62fe]) (user=ricarkol job=sendgmr) by 2002:aa7:8892:0:b0:52e:14cb:7e67 with SMTP id z18-20020aa78892000000b0052e14cb7e67mr5053053pfe.35.1659551013353; Wed, 03 Aug 2022 11:23:33 -0700 (PDT) Date: Wed, 3 Aug 2022 11:23:26 -0700 In-Reply-To: <20220803182328.2438598-1-ricarkol@google.com> Message-Id: <20220803182328.2438598-2-ricarkol@google.com> Mime-Version: 1.0 References: <20220803182328.2438598-1-ricarkol@google.com> X-Mailer: git-send-email 2.37.1.455.g008518b4e5-goog Subject: [kvm-unit-tests PATCH v2 1/3] arm: pmu: Add missing isb()'s after sys register writing From: Ricardo Koller To: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, andrew.jones@linux.dev Cc: maz@kernel.org, alexandru.elisei@arm.com, eric.auger@redhat.com, oliver.upton@linux.dev, reijiw@google.com, Ricardo Koller Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org There are various pmu tests that require an isb() between enabling counting and the actual counting. This can lead to count registers reporting less events than expected; the actual enabling happens after some events have happened. For example, some missing isb()'s in the pmu-sw-incr test lead to the following errors on bare-metal: INFO: pmu: pmu-sw-incr: SW_INCR counter #0 has value 4294967280 PASS: pmu: pmu-sw-incr: PWSYNC does not increment if PMCR.E is unset FAIL: pmu: pmu-sw-incr: counter #1 after + 100 SW_INCR FAIL: pmu: pmu-sw-incr: counter #0 after + 100 SW_INCR INFO: pmu: pmu-sw-incr: counter values after 100 SW_INCR #0=82 #1=98 PASS: pmu: pmu-sw-incr: overflow on counter #0 after 100 SW_INCR SUMMARY: 4 tests, 2 unexpected failures Add the missing isb()'s on all failing tests, plus some others that seem required: - after clearing the overflow signal in the IRQ handler to avoid spurious interrupts. - after direct writes to PMSWINC_EL0 for software to read the correct value for PMEVNCTR0_EL0 (from ARM DDI 0487H.a, page D13-5237). Signed-off-by: Ricardo Koller --- arm/pmu.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/arm/pmu.c b/arm/pmu.c index 15c542a2..76156f78 100644 --- a/arm/pmu.c +++ b/arm/pmu.c @@ -307,6 +307,7 @@ static void irq_handler(struct pt_regs *regs) } } write_sysreg(ALL_SET, pmovsclr_el0); + isb(); } else { pmu_stats.unexpected = true; } @@ -534,10 +535,12 @@ static void test_sw_incr(void) write_sysreg_s(0x3, PMCNTENSET_EL0); write_regn_el0(pmevcntr, 0, PRE_OVERFLOW); + isb(); for (i = 0; i < 100; i++) write_sysreg(0x1, pmswinc_el0); + isb(); report_info("SW_INCR counter #0 has value %ld", read_regn_el0(pmevcntr, 0)); report(read_regn_el0(pmevcntr, 0) == PRE_OVERFLOW, "PWSYNC does not increment if PMCR.E is unset"); @@ -547,10 +550,12 @@ static void test_sw_incr(void) write_regn_el0(pmevcntr, 0, PRE_OVERFLOW); write_sysreg_s(0x3, PMCNTENSET_EL0); set_pmcr(pmu.pmcr_ro | PMU_PMCR_E); + isb(); for (i = 0; i < 100; i++) write_sysreg(0x3, pmswinc_el0); + isb(); report(read_regn_el0(pmevcntr, 0) == 84, "counter #1 after + 100 SW_INCR"); report(read_regn_el0(pmevcntr, 1) == 100, "counter #0 after + 100 SW_INCR"); @@ -618,9 +623,12 @@ static void test_chained_sw_incr(void) write_regn_el0(pmevcntr, 0, PRE_OVERFLOW); set_pmcr(pmu.pmcr_ro | PMU_PMCR_E); + isb(); + for (i = 0; i < 100; i++) write_sysreg(0x1, pmswinc_el0); + isb(); report(!read_sysreg(pmovsclr_el0) && (read_regn_el0(pmevcntr, 1) == 1), "no overflow and chain counter incremented after 100 SW_INCR/CHAIN"); report_info("overflow=0x%lx, #0=%ld #1=%ld", read_sysreg(pmovsclr_el0), @@ -634,9 +642,12 @@ static void test_chained_sw_incr(void) write_regn_el0(pmevcntr, 1, ALL_SET); write_sysreg_s(0x3, PMCNTENSET_EL0); set_pmcr(pmu.pmcr_ro | PMU_PMCR_E); + isb(); + for (i = 0; i < 100; i++) write_sysreg(0x1, pmswinc_el0); + isb(); report((read_sysreg(pmovsclr_el0) == 0x2) && (read_regn_el0(pmevcntr, 1) == 0) && (read_regn_el0(pmevcntr, 0) == 84), @@ -821,10 +832,13 @@ static void test_overflow_interrupt(void) report(expect_interrupts(0), "no overflow interrupt after preset"); set_pmcr(pmu.pmcr_ro | PMU_PMCR_E); + isb(); + for (i = 0; i < 100; i++) write_sysreg(0x2, pmswinc_el0); set_pmcr(pmu.pmcr_ro); + isb(); report(expect_interrupts(0), "no overflow interrupt after counting"); /* enable interrupts */ @@ -879,6 +893,7 @@ static bool check_cycles_increase(void) set_pmccfiltr(0); /* count cycles in EL0, EL1, but not EL2 */ set_pmcr(get_pmcr() | PMU_PMCR_LC | PMU_PMCR_C | PMU_PMCR_E); + isb(); for (int i = 0; i < NR_SAMPLES; i++) { uint64_t a, b; @@ -894,6 +909,7 @@ static bool check_cycles_increase(void) } set_pmcr(get_pmcr() & ~PMU_PMCR_E); + isb(); return success; } From patchwork Wed Aug 3 18:23:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Koller X-Patchwork-Id: 12935846 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EDFABC19F2D for ; Wed, 3 Aug 2022 18:23:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237997AbiHCSXi (ORCPT ); Wed, 3 Aug 2022 14:23:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237919AbiHCSXh (ORCPT ); Wed, 3 Aug 2022 14:23:37 -0400 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F1F36402 for ; Wed, 3 Aug 2022 11:23:36 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id a17-20020a17090abe1100b001f320df2e97so1497566pjs.0 for ; Wed, 03 Aug 2022 11:23:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc; bh=NCd9pZ1nHReYqpUxat1aRffhr9vnDsLXOgqhJFAxey4=; b=llw0yKtpNQpehkZ+QVXavGRSEMpGWCvk1V9rOY5p84zXQGCRh6aQK15QyIrz5fRQYV ksahlTxNw7rqH0KRxKGXwXS96EGD+yah7tZeI/ct+R/DdMRNGSg+FdmU7E5sYsy+JG83 9mcTe5poTVEoB0PKjZePir/IDp8WBUPJJNmIZpzLeGA214xtAefmg8ZZenL+cI3KEgar ASOnLz344uqMuVY9bfA6e+s8b5I1QHmff5jNqpeShQMXEr3jprDSfi4gbDqk50KvPNqM BRwue+UlTPA1Z5h2X1RlWRJRThjGTPo+sHGsWYZOtk2iGvPk72aQcADalmF45dBqk2HK Zmtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc; bh=NCd9pZ1nHReYqpUxat1aRffhr9vnDsLXOgqhJFAxey4=; b=aDauTpk0Vg3Di0uyc0t2bvsx+UZ3QzBDWkNF1S5zkp+vxePK5O1XLcKb5PYffiLDbH JGVE63UqgbtNJLgYHiUCoLR775OQ5Vxjd87+3MDHFVpBPnQF7oCPfTmZUIqEdMHwRtTE dAhtwEcXrUtb6JgCAgIQNxr+nR/ezQZFpSR/SAJC802etsCEFGssI/1b45TEEf8gFfng PKOeM6kt6RWfTosY5fbb1CCPaMlZAeqAcwwNtDGx8dT7BlpNpQ30B1oczsEAXzICvC7r dfoAWreLelEKYal9G+1O9lYV9ev8RDyh90LpQCwKm9FmEBV6dsY2+4OFvfHGhsmuafhA pp3g== X-Gm-Message-State: ACgBeo3N6phXVueFjkdLF8C7+po3ccWXkAWaqGrzrDV3Le8JVGVIguYq tbAfA+2kjYt0p3b1pBy1ggRDPkfk0417NyV2LVLJmcO8hJCXyWLhMCD4DwnnrGXDj+h4tMR9DCz 2AQcXylLCUz46f7W7bt5ssi5BHq8KxXMHVWiLo9JltOstUENPEmf/eyJFdszkJDQ= X-Google-Smtp-Source: AA6agR46+fS5xqb633nq44y0Z/Fa4yZf37XU33PssxOX+2ZsgstmTBevMRPV9uxYjBsBsCd1m35M1FfY2MCy0g== X-Received: from ricarkol2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:62fe]) (user=ricarkol job=sendgmr) by 2002:a17:90a:df03:b0:1f3:396c:dd94 with SMTP id gp3-20020a17090adf0300b001f3396cdd94mr435102pjb.1.1659551015065; Wed, 03 Aug 2022 11:23:35 -0700 (PDT) Date: Wed, 3 Aug 2022 11:23:27 -0700 In-Reply-To: <20220803182328.2438598-1-ricarkol@google.com> Message-Id: <20220803182328.2438598-3-ricarkol@google.com> Mime-Version: 1.0 References: <20220803182328.2438598-1-ricarkol@google.com> X-Mailer: git-send-email 2.37.1.455.g008518b4e5-goog Subject: [kvm-unit-tests PATCH v2 2/3] arm: pmu: Reset the pmu registers before starting some tests From: Ricardo Koller To: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, andrew.jones@linux.dev Cc: maz@kernel.org, alexandru.elisei@arm.com, eric.auger@redhat.com, oliver.upton@linux.dev, reijiw@google.com, Ricardo Koller Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Some registers like the PMOVS reset to an architecturally UNKNOWN value. Most tests expect them to be reset (mostly zeroed) using pmu_reset(). Add a pmu_reset() on all the tests that need one. As a bonus, fix a couple of comments related to the register state before a sub-test. Signed-off-by: Ricardo Koller Reviewed-by: Eric Auger --- arm/pmu.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arm/pmu.c b/arm/pmu.c index 76156f78..7c5bc259 100644 --- a/arm/pmu.c +++ b/arm/pmu.c @@ -826,7 +826,7 @@ static void test_overflow_interrupt(void) write_regn_el0(pmevcntr, 1, PRE_OVERFLOW); isb(); - /* interrupts are disabled */ + /* interrupts are disabled (PMINTENSET_EL1 == 0) */ mem_access_loop(addr, 200, pmu.pmcr_ro | PMU_PMCR_E); report(expect_interrupts(0), "no overflow interrupt after preset"); @@ -841,7 +841,7 @@ static void test_overflow_interrupt(void) isb(); report(expect_interrupts(0), "no overflow interrupt after counting"); - /* enable interrupts */ + /* enable interrupts (PMINTENSET_EL1 <= ALL_SET) */ pmu_reset_stats(); @@ -889,6 +889,7 @@ static bool check_cycles_increase(void) bool success = true; /* init before event access, this test only cares about cycle count */ + pmu_reset(); set_pmcntenset(1 << PMU_CYCLE_IDX); set_pmccfiltr(0); /* count cycles in EL0, EL1, but not EL2 */ @@ -943,6 +944,7 @@ static bool check_cpi(int cpi) uint32_t pmcr = get_pmcr() | PMU_PMCR_LC | PMU_PMCR_C | PMU_PMCR_E; /* init before event access, this test only cares about cycle count */ + pmu_reset(); set_pmcntenset(1 << PMU_CYCLE_IDX); set_pmccfiltr(0); /* count cycles in EL0, EL1, but not EL2 */ From patchwork Wed Aug 3 18:23:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Koller X-Patchwork-Id: 12935848 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D52B3C19F28 for ; Wed, 3 Aug 2022 18:23:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238004AbiHCSXj (ORCPT ); Wed, 3 Aug 2022 14:23:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237919AbiHCSXi (ORCPT ); Wed, 3 Aug 2022 14:23:38 -0400 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9EA346402 for ; Wed, 3 Aug 2022 11:23:37 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id i2-20020a17090a650200b001f4f79056a6so1464494pjj.9 for ; Wed, 03 Aug 2022 11:23:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc; bh=FVFMELFSTgopXdyyg1vAr05TDgaRRWOAIMCURi85wlQ=; b=RtdafaWt5jSum8MWA8bEOoevkPgTvqI1vZC+MJDEhJ/RnPS8JdhJa26Q7Xvv4cPmdN SyMabGpPCWDv/S+zvgNjuHQZbtdg1nuTXIdWePy0kTY8JBRgZPwrHvGvL320nDTmM/ZA 7fZS3ZVMSRFDrdLM/5jj9WtRYhH7vXlsZgio7CVArJzbW+4iNl9FYrA3OLP8cozl8vwU y2THh7EkNPsB/0SZKGKCgCv9voRZd1U4YjCIsgx9G8dHPZ9TFW9VVb0kPbuJa49cUjGD cQLUiNzJfMaKhr5UhuMJTKMrDSAnlGysFbYsAT73m5eBVJRgVIAC1Th/oTJ/mEKhVVnF 7L8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc; bh=FVFMELFSTgopXdyyg1vAr05TDgaRRWOAIMCURi85wlQ=; b=DD7SdBWRIQgXHnGvP2qoAxRkaxMMElRzFhqd5d1w4sgQxRn4tMgyjnrZZojTSl1x4H 699lk8mLWtR+ryo3J+gfTDC/idKBhP/Ed7VaTqmrHeYov37rICbIKSSIcCil2K2xeeH1 JWQ4bd9pss+TQ4XxcmFIjbbWIBA9ocS/IADrz3VKdmJxofsra/rDyABrCQeiXspLx0E3 n7745CT+22I29VFiqAm1U383r915B1YIoatViGsi7O7+6VdcVfOks439uCjePvLreoOG L8DPlk+a54NIifk6vWevZdUXTWUe1habmVgec6DCafUHp0Kyijgbh7maryjR/ILxuezV RVYQ== X-Gm-Message-State: ACgBeo2vXwGbZkbA3Jh5EE5Y1yf13lyg9shn4qyKpVqie8JQjTohIagh HusSenH9NIBNml4OJr1wmyjd5QwnSoLN5o0GHVO95RGRVupN3ilc6C/+1lRI3wiMEQmtiPl0+i2 1QWUkB8TqJbfNAofB5c5q+irrm6VyxuNAVgUcnPcHXZ8+9Ekrx3CdNdkKiKoGAhs= X-Google-Smtp-Source: AA6agR7/j0qVYNg+PlMvNx4NVrtY/qJXCWsd5FcNscQ/kFRjr7TFokSdqFREl5h9gdtDyNh/kW+JJOpzN/Y6MQ== X-Received: from ricarkol2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:62fe]) (user=ricarkol job=sendgmr) by 2002:a17:903:1207:b0:16a:7e87:dad3 with SMTP id l7-20020a170903120700b0016a7e87dad3mr27763996plh.99.1659551017145; Wed, 03 Aug 2022 11:23:37 -0700 (PDT) Date: Wed, 3 Aug 2022 11:23:28 -0700 In-Reply-To: <20220803182328.2438598-1-ricarkol@google.com> Message-Id: <20220803182328.2438598-4-ricarkol@google.com> Mime-Version: 1.0 References: <20220803182328.2438598-1-ricarkol@google.com> X-Mailer: git-send-email 2.37.1.455.g008518b4e5-goog Subject: [kvm-unit-tests PATCH v2 3/3] arm: pmu: Check for overflow in the low counter in chained counters tests From: Ricardo Koller To: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, andrew.jones@linux.dev Cc: maz@kernel.org, alexandru.elisei@arm.com, eric.auger@redhat.com, oliver.upton@linux.dev, reijiw@google.com, Ricardo Koller Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org A chained event overflowing on the low counter can set the overflow flag in PMOVS. KVM does not set it, but real HW and the fast-model seem to. Moreover, the AArch64.IncrementEventCounter() pseudocode in the ARM ARM (DDI 0487H.a, J1.1.1 "aarch64/debug") also sets the PMOVS bit on overflow. The pmu chain tests fail on bare metal when checking the overflow flag of the low counter _not_ being set on overflow. Fix by checking for overflow. Note that this test fails in KVM without the respective fix. Signed-off-by: Ricardo Koller Reviewed-by: Eric Auger --- arm/pmu.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/arm/pmu.c b/arm/pmu.c index 7c5bc259..258780f4 100644 --- a/arm/pmu.c +++ b/arm/pmu.c @@ -583,7 +583,7 @@ static void test_chained_counters(void) precise_instrs_loop(22, pmu.pmcr_ro | PMU_PMCR_E); report(read_regn_el0(pmevcntr, 1) == 1, "CHAIN counter #1 incremented"); - report(!read_sysreg(pmovsclr_el0), "no overflow recorded for chained incr #1"); + report(read_sysreg(pmovsclr_el0) == 0x1, "overflow recorded for chained incr #1"); /* test 64b overflow */ @@ -595,7 +595,7 @@ static void test_chained_counters(void) precise_instrs_loop(22, pmu.pmcr_ro | PMU_PMCR_E); report_info("overflow reg = 0x%lx", read_sysreg(pmovsclr_el0)); report(read_regn_el0(pmevcntr, 1) == 2, "CHAIN counter #1 set to 2"); - report(!read_sysreg(pmovsclr_el0), "no overflow recorded for chained incr #2"); + report(read_sysreg(pmovsclr_el0) == 0x1, "overflow recorded for chained incr #2"); write_regn_el0(pmevcntr, 0, PRE_OVERFLOW); write_regn_el0(pmevcntr, 1, ALL_SET); @@ -603,7 +603,7 @@ static void test_chained_counters(void) precise_instrs_loop(22, pmu.pmcr_ro | PMU_PMCR_E); report_info("overflow reg = 0x%lx", read_sysreg(pmovsclr_el0)); report(!read_regn_el0(pmevcntr, 1), "CHAIN counter #1 wrapped"); - report(read_sysreg(pmovsclr_el0) == 0x2, "overflow on chain counter"); + report(read_sysreg(pmovsclr_el0) == 0x3, "overflow on even and odd counters"); } static void test_chained_sw_incr(void) @@ -629,8 +629,9 @@ static void test_chained_sw_incr(void) write_sysreg(0x1, pmswinc_el0); isb(); - report(!read_sysreg(pmovsclr_el0) && (read_regn_el0(pmevcntr, 1) == 1), - "no overflow and chain counter incremented after 100 SW_INCR/CHAIN"); + report((read_sysreg(pmovsclr_el0) == 0x1) && + (read_regn_el0(pmevcntr, 1) == 1), + "overflow and chain counter incremented after 100 SW_INCR/CHAIN"); report_info("overflow=0x%lx, #0=%ld #1=%ld", read_sysreg(pmovsclr_el0), read_regn_el0(pmevcntr, 0), read_regn_el0(pmevcntr, 1)); @@ -648,10 +649,10 @@ static void test_chained_sw_incr(void) write_sysreg(0x1, pmswinc_el0); isb(); - report((read_sysreg(pmovsclr_el0) == 0x2) && + report((read_sysreg(pmovsclr_el0) == 0x3) && (read_regn_el0(pmevcntr, 1) == 0) && (read_regn_el0(pmevcntr, 0) == 84), - "overflow on chain counter and expected values after 100 SW_INCR/CHAIN"); + "overflow on even and odd counters, and expected values after 100 SW_INCR/CHAIN"); report_info("overflow=0x%lx, #0=%ld #1=%ld", read_sysreg(pmovsclr_el0), read_regn_el0(pmevcntr, 0), read_regn_el0(pmevcntr, 1)); } @@ -731,8 +732,9 @@ static void test_chain_promotion(void) report_info("MEM_ACCESS counter #0 has value 0x%lx", read_regn_el0(pmevcntr, 0)); - report((read_regn_el0(pmevcntr, 1) == 1) && !read_sysreg(pmovsclr_el0), - "CHAIN counter enabled: CHAIN counter was incremented and no overflow"); + report((read_regn_el0(pmevcntr, 1) == 1) && + (read_sysreg(pmovsclr_el0) == 0x1), + "CHAIN counter enabled: CHAIN counter was incremented and overflow"); report_info("CHAIN counter #1 = 0x%lx, overflow=0x%lx", read_regn_el0(pmevcntr, 1), read_sysreg(pmovsclr_el0)); @@ -759,8 +761,9 @@ static void test_chain_promotion(void) report_info("MEM_ACCESS counter #0 has value 0x%lx", read_regn_el0(pmevcntr, 0)); - report((read_regn_el0(pmevcntr, 1) == 1) && !read_sysreg(pmovsclr_el0), - "32b->64b: CHAIN counter incremented and no overflow"); + report((read_regn_el0(pmevcntr, 1) == 1) && + (read_sysreg(pmovsclr_el0) == 0x1), + "32b->64b: CHAIN counter incremented and overflow"); report_info("CHAIN counter #1 = 0x%lx, overflow=0x%lx", read_regn_el0(pmevcntr, 1), read_sysreg(pmovsclr_el0)); @@ -867,8 +870,8 @@ static void test_overflow_interrupt(void) write_regn_el0(pmevcntr, 0, PRE_OVERFLOW); isb(); mem_access_loop(addr, 200, pmu.pmcr_ro | PMU_PMCR_E); - report(expect_interrupts(0), - "no overflow interrupt expected on 32b boundary"); + report(expect_interrupts(0x1), + "expect overflow interrupt on 32b boundary"); /* overflow on odd counter */ pmu_reset_stats(); @@ -876,8 +879,8 @@ static void test_overflow_interrupt(void) write_regn_el0(pmevcntr, 1, ALL_SET); isb(); mem_access_loop(addr, 400, pmu.pmcr_ro | PMU_PMCR_E); - report(expect_interrupts(0x2), - "expect overflow interrupt on odd counter"); + report(expect_interrupts(0x3), + "expect overflow interrupt on even and odd counter"); } #endif