From nobody Sat Apr 27 10:23:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1575655544; cv=none; d=zohomail.com; s=zohoarc; b=iaQX8i0SF6bCPJZ/eyauYGqP8D05kCKTeaodZI6Zn2v7iJ/nfHNYcZLSKTZIvyJtsY6EmwSFlG9WyOFuWuyIdMpgKg5gNVxuG0CjQagYwlftCTH6Qv5vmy3I6nlDQqlwkcLyyvP5cdWEtrbYjlkhTzki7WwSThtX+Nqybr3aObA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575655544; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=82q1ODmkZ7c1oPzZoGIi16jb3fC0s7ZgyAm8HyUNG/k=; b=KUb3syskmvnTMlXRBdXvfX0P/YKbdbnu97MxbJz4T6NcDQ3rzY6gwigKe1HC4vrR1jYk9A7qFcTrYV5xzoLvjCtxDXnB8DMKZOHBUITKYPNj36h6DqoT5vq4QVNzCAdoZrcdoaMR1bJ7nm97r9YeZFDVp1Y2SzLu5wVfgP73gK0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 157565554458547.11245143679969; Fri, 6 Dec 2019 10:05:44 -0800 (PST) Received: from localhost ([::1]:42914 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1idHz5-0003Wt-7P for importer@patchew.org; Fri, 06 Dec 2019 13:05:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43808) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1idHOO-0001c6-UC for qemu-devel@nongnu.org; Fri, 06 Dec 2019 12:27:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1idHOM-00034f-MY for qemu-devel@nongnu.org; Fri, 06 Dec 2019 12:27:48 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:58536 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1idHOM-000301-2k for qemu-devel@nongnu.org; Fri, 06 Dec 2019 12:27:46 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-139-am3fbLFtNLK_jb0VJtV8MA-1; Fri, 06 Dec 2019 12:27:40 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1CBB3800580; Fri, 6 Dec 2019 17:27:39 +0000 (UTC) Received: from laptop.redhat.com (ovpn-116-117.ams2.redhat.com [10.36.116.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3E9436CE40; Fri, 6 Dec 2019 17:27:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575653262; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=82q1ODmkZ7c1oPzZoGIi16jb3fC0s7ZgyAm8HyUNG/k=; b=GqWKDFaN1Wm9fSEJbCykqP9EPZCrn/NTMaKlhErAReFctSzaePjnd1kyiNftswvAukaybB kX0s8W6I391/vTmlXTeMx6Bb06EyfGP5X7c5b6PMNru1hGfiEoXWwEVnk50+nC/SATJx82 iJLGUYnxO2W0RFEoaDbi2dQZdX92jGI= From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, maz@kernel.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, qemu-devel@nongnu.org, qemu-arm@nongnu.org Subject: [kvm-unit-tests RFC 01/10] arm64: Provide read/write_sysreg_s Date: Fri, 6 Dec 2019 18:27:15 +0100 Message-Id: <20191206172724.947-2-eric.auger@redhat.com> In-Reply-To: <20191206172724.947-1-eric.auger@redhat.com> References: <20191206172724.947-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: am3fbLFtNLK_jb0VJtV8MA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, andrew.murray@arm.com, drjones@redhat.com, andre.przywara@arm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Andrew Jones Sometimes we need to test access to system registers which are missing assembler mnemonics. Signed-off-by: Andrew Jones Reviewed-by: Alexandru Elisei --- lib/arm64/asm/sysreg.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/arm64/asm/sysreg.h b/lib/arm64/asm/sysreg.h index a03830b..a45eebd 100644 --- a/lib/arm64/asm/sysreg.h +++ b/lib/arm64/asm/sysreg.h @@ -38,6 +38,17 @@ asm volatile("msr " xstr(r) ", %x0" : : "rZ" (__val)); \ } while (0) =20 +#define read_sysreg_s(r) ({ \ + u64 __val; \ + asm volatile("mrs_s %0, " xstr(r) : "=3Dr" (__val)); \ + __val; \ +}) + +#define write_sysreg_s(v, r) do { \ + u64 __val =3D (u64)v; \ + asm volatile("msr_s " xstr(r) ", %x0" : : "rZ" (__val));\ +} while (0) + asm( " .irp num,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,2= 4,25,26,27,28,29,30\n" " .equ .L__reg_num_x\\num, \\num\n" --=20 2.20.1 From nobody Sat Apr 27 10:23:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1575655704; cv=none; d=zohomail.com; s=zohoarc; b=ne7FuIpNRKg1Ljbgz/WwUzs/u25qyGnftdsmjaDxtCuToJqk3JMIYHJfa64ttFFRPmkwMNZ/dp9ENKoro43c0KTZInZYqHrviJIm52vI9QmECFdQxeXhlz6h8ceelhaTtkxndt3M6mcLtecpGfh1Et9HnmzjXTkZLx6vEb3dF94= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575655704; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=lZIWyVz0mXJm3WKdFFZ/MDv4wbAF4ZdIGNT+t+b1NIM=; b=fzxhZtUHqyz3BCSXjTvUIEkFLF53iWkYZEWrz48pWc6FG0SR67f+EzCiqmbjqqK7HMG08chGqD9utsczgAMcgB5neLjW35LbzCt6Kkof6Y9wIZliW4akNFd69qZZxnztn0gAo11gsMwp/IuQdmxVsa5LIRvnY6HvQ5vfq/vgPw0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1575655704574626.5848885444913; Fri, 6 Dec 2019 10:08:24 -0800 (PST) Received: from localhost ([::1]:42972 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1idI1f-0006YE-B9 for importer@patchew.org; Fri, 06 Dec 2019 13:08:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44024) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1idHOQ-0001ee-BG for qemu-devel@nongnu.org; Fri, 06 Dec 2019 12:27:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1idHOO-00037N-Pl for qemu-devel@nongnu.org; Fri, 06 Dec 2019 12:27:50 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:25135 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1idHON-00033Y-Rd for qemu-devel@nongnu.org; Fri, 06 Dec 2019 12:27:48 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-393-D71sZqEuNFWfvlreylC4FA-1; Fri, 06 Dec 2019 12:27:43 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F0DC9107ACC9; Fri, 6 Dec 2019 17:27:41 +0000 (UTC) Received: from laptop.redhat.com (ovpn-116-117.ams2.redhat.com [10.36.116.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id 73DC86CE40; Fri, 6 Dec 2019 17:27:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575653265; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lZIWyVz0mXJm3WKdFFZ/MDv4wbAF4ZdIGNT+t+b1NIM=; b=gDxL6DE/1IjAi8VzFP4328+FXyLjs1PkxQMtPLyTulAm4D5a+n6lJMX0vtji190ALhfULQ oSZuMVyfE1Yf56EiNOvH4hG2m65WGl9LnY6qshrPDnErh+jr4VSkd1CEWjNBzfUyob0cTh FNxtOcIx8HD2ULoU7GSAyPDr7MJAa7c= From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, maz@kernel.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, qemu-devel@nongnu.org, qemu-arm@nongnu.org Subject: [kvm-unit-tests RFC 02/10] pmu: Let pmu tests take a sub-test parameter Date: Fri, 6 Dec 2019 18:27:16 +0100 Message-Id: <20191206172724.947-3-eric.auger@redhat.com> In-Reply-To: <20191206172724.947-1-eric.auger@redhat.com> References: <20191206172724.947-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: D71sZqEuNFWfvlreylC4FA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, andrew.murray@arm.com, drjones@redhat.com, andre.przywara@arm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" As we intend to introduce more PMU tests, let's add a sub-test parameter that will allow to categorize them. Existing tests are in the cycle-counter category. Signed-off-by: Eric Auger --- arm/pmu.c | 22 ++++++++++++++-------- arm/unittests.cfg | 7 ++++--- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/arm/pmu.c b/arm/pmu.c index 1de7d77..2ad6469 100644 --- a/arm/pmu.c +++ b/arm/pmu.c @@ -287,21 +287,27 @@ int main(int argc, char *argv[]) { int cpi =3D 0; =20 - if (argc > 1) - cpi =3D atol(argv[1]); - if (!pmu_probe()) { printf("No PMU found, test skipped...\n"); return report_summary(); } =20 + if (argc < 2) + report_abort("no test specified"); + report_prefix_push("pmu"); =20 - report("Control register", check_pmcr()); - report("Monotonically increasing cycle count", check_cycles_increase()); - report("Cycle/instruction ratio", check_cpi(cpi)); - - pmccntr64_test(); + if (strcmp(argv[1], "cycle-counter") =3D=3D 0) { + report_prefix_push(argv[1]); + if (argc > 2) + cpi =3D atol(argv[2]); + report("Control register", check_pmcr()); + report("Monotonically increasing cycle count", check_cycles_increase()); + report("Cycle/instruction ratio", check_cpi(cpi)); + pmccntr64_test(); + } else { + report_abort("Unknown subtest '%s'", argv[1]); + } =20 return report_summary(); } diff --git a/arm/unittests.cfg b/arm/unittests.cfg index daeb5a0..79f0d7a 100644 --- a/arm/unittests.cfg +++ b/arm/unittests.cfg @@ -61,21 +61,22 @@ file =3D pci-test.flat groups =3D pci =20 # Test PMU support -[pmu] +[pmu-cycle-counter] file =3D pmu.flat groups =3D pmu +extra_params =3D -append 'cycle-counter 0' =20 # Test PMU support (TCG) with -icount IPC=3D1 #[pmu-tcg-icount-1] #file =3D pmu.flat -#extra_params =3D -icount 0 -append '1' +#extra_params =3D -icount 0 -append 'cycle-counter 1' #groups =3D pmu #accel =3D tcg =20 # Test PMU support (TCG) with -icount IPC=3D256 #[pmu-tcg-icount-256] #file =3D pmu.flat -#extra_params =3D -icount 8 -append '256' +#extra_params =3D -icount 8 -append 'cycle-counter 256' #groups =3D pmu #accel =3D tcg =20 --=20 2.20.1 From nobody Sat Apr 27 10:23:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1575654755; cv=none; d=zohomail.com; s=zohoarc; b=lTw5fdMu83fzHip+yhKQsUc9yrW79R8t0lI/z4k+8I67PLOfQn9xbSH/28aDsA52Vln4IEVJ5FgykiXzry1CoDv5f49+vAyQ3D8fYcD6OdShTn+iI3UEMrECWDp4tKViyvpoWVYyztyuu3T9mHkhq8Toy4G3pqPYQ6kFSU/7O04= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575654755; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yqTunPkxwrcyQFOxDUNzfOp1hv1TJYsH7F1IJZPhTJo=; b=cMPQ3c0jtDUQJhEUifVgDctqgour/LhaGBVneAjSqT/2nJTuPvWvGDRhM6byXU/fCovaTDeoMBNK51Zmvy0utjJ/+yyoM3UxO6bbDSZv6+CAMNvYPJyoi3Yraolp1LFN9vyi/rEurH8ncWqQxywk+sXcpXa7MugpUFEQDNu9nVg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1575654755160818.8881952300947; Fri, 6 Dec 2019 09:52:35 -0800 (PST) Received: from localhost ([::1]:42591 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1idHmL-0004Kl-5S for importer@patchew.org; Fri, 06 Dec 2019 12:52:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44453) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1idHOU-0001j6-RR for qemu-devel@nongnu.org; Fri, 06 Dec 2019 12:27:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1idHOT-0003JT-M7 for qemu-devel@nongnu.org; Fri, 06 Dec 2019 12:27:54 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:39011 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1idHOT-0003H3-Dc for qemu-devel@nongnu.org; Fri, 06 Dec 2019 12:27:53 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-64-RwGInhliOwmo9mMSBC3FqA-1; Fri, 06 Dec 2019 12:27:48 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 35E9A1005502; Fri, 6 Dec 2019 17:27:47 +0000 (UTC) Received: from laptop.redhat.com (ovpn-116-117.ams2.redhat.com [10.36.116.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id 540D86CE40; Fri, 6 Dec 2019 17:27:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575653272; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yqTunPkxwrcyQFOxDUNzfOp1hv1TJYsH7F1IJZPhTJo=; b=GUPCMfIKF/NWK5pNJR+nw4t8tI35nE0kVEHbQBwq3GIctmI2xGM1ydTOAYXVFGOXu7Lkan 4F6NA3RqJTvSWP41bQqzaW5Jw2O2Ym/jyBsUmDCFPNaeJ4T4jiY9YQeFz5DzzjmgQLNsGY WHzQc/CIyfBYdiU/9dXuX33hG0tAtMw= From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, maz@kernel.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, qemu-devel@nongnu.org, qemu-arm@nongnu.org Subject: [kvm-unit-tests RFC 03/10] pmu: Add a pmu struct Date: Fri, 6 Dec 2019 18:27:17 +0100 Message-Id: <20191206172724.947-4-eric.auger@redhat.com> In-Reply-To: <20191206172724.947-1-eric.auger@redhat.com> References: <20191206172724.947-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: RwGInhliOwmo9mMSBC3FqA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, andrew.murray@arm.com, drjones@redhat.com, andre.przywara@arm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This struct aims at storing information potentially used by all tests such as the pmu version, the read-only part of the PMCR, the number of implemented event counters, ... Signed-off-by: Eric Auger --- arm/pmu.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/arm/pmu.c b/arm/pmu.c index 2ad6469..8e95251 100644 --- a/arm/pmu.c +++ b/arm/pmu.c @@ -33,7 +33,15 @@ =20 #define NR_SAMPLES 10 =20 -static unsigned int pmu_version; +struct pmu { + unsigned int version; + unsigned int nb_implemented_counters; + uint32_t pmcr_ro; +}; + +static struct pmu pmu; + + #if defined(__arm__) #define ID_DFR0_PERFMON_SHIFT 24 #define ID_DFR0_PERFMON_MASK 0xf @@ -265,7 +273,7 @@ static bool check_cpi(int cpi) static void pmccntr64_test(void) { #ifdef __arm__ - if (pmu_version =3D=3D 0x3) { + if (pmu.version =3D=3D 0x3) { if (ERRATA(9e3f7a296940)) { write_sysreg(0xdead, PMCCNTR64); report("pmccntr64", read_sysreg(PMCCNTR64) =3D=3D 0xdead); @@ -278,9 +286,20 @@ static void pmccntr64_test(void) /* Return FALSE if no PMU found, otherwise return TRUE */ static bool pmu_probe(void) { - pmu_version =3D get_pmu_version(); - report_info("PMU version: %d", pmu_version); - return pmu_version !=3D 0 && pmu_version !=3D 0xf; + uint32_t pmcr; + + pmu.version =3D get_pmu_version(); + report_info("PMU version: %d", pmu.version); + + if (pmu.version =3D=3D 0 || pmu.version =3D=3D 0xF) + return false; + + pmcr =3D get_pmcr(); + pmu.pmcr_ro =3D pmcr & 0xFFFFFF80; + pmu.nb_implemented_counters =3D (pmcr >> PMU_PMCR_N_SHIFT) & PMU_PMCR_N_M= ASK; + report_info("Implements %d event counters", pmu.nb_implemented_counters); + + return true; } =20 int main(int argc, char *argv[]) --=20 2.20.1 From nobody Sat Apr 27 10:23:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1575655836; cv=none; d=zohomail.com; s=zohoarc; b=j4S4foQfuxYJZKyzGe81ecsagHSiH3ZkLgvwKjW2PCXkWYp4L0lVTJGzfABmOdWreJ3BueLnqVZeZpzW43Mnx9byv3m5PiXGe9KLJCazBc0nQizuxJDJGvVS7A4BAXUshPWxYP3zeyuCcGKlopkjiPmCX69TyAvImGBxj9LaDYk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575655836; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=WMQUa3khr5jsekFu/skIEP0pnlonAM+9sITcAnn0lGM=; b=ciPe4ajL/idyGPUbl9s+aD79LMD8zKOXYjWorYFUNuC73l7JglErmD/zmynKwtUb+VFcUZEtJZv670Tcxt/cVEf2B6sLW8/RJdh+2gjbydDMcM9lm+qcZBkaidopJIDJaeuZsw80+9nNQUdwHPhTXMGMrujLMY8/Z5Qi4qEucOE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1575655836621580.2718349990611; Fri, 6 Dec 2019 10:10:36 -0800 (PST) Received: from localhost ([::1]:43028 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1idI3n-0001E6-B5 for importer@patchew.org; Fri, 06 Dec 2019 13:10:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45425) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1idHOa-0001rp-R4 for qemu-devel@nongnu.org; Fri, 06 Dec 2019 12:28:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1idHOY-0003ZE-9w for qemu-devel@nongnu.org; Fri, 06 Dec 2019 12:28:00 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:31025 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1idHOY-0003Xb-1b for qemu-devel@nongnu.org; Fri, 06 Dec 2019 12:27:58 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-188-bNevScXFNg-cmD5S24rlpg-1; Fri, 06 Dec 2019 12:27:56 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CE4C31005502; Fri, 6 Dec 2019 17:27:54 +0000 (UTC) Received: from laptop.redhat.com (ovpn-116-117.ams2.redhat.com [10.36.116.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8CC286CE40; Fri, 6 Dec 2019 17:27:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575653277; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WMQUa3khr5jsekFu/skIEP0pnlonAM+9sITcAnn0lGM=; b=hwmvMYDlKP+dCIybQFNTsOzW/N6tFV5lvnPlml7BU0mdo4Dy6N6sx8qpernl4xT0EF8mpv iGlpGBNNO/P3tRUsaQKW9/TH314jRwqZEsb6PwyowxMPITKBSdGWnBoS3KpOmU1Xl+hoOm H2o9EKDEorbwv+34UtSRgkoTcPY4uYY= From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, maz@kernel.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, qemu-devel@nongnu.org, qemu-arm@nongnu.org Subject: [kvm-unit-tests RFC 04/10] pmu: Check Required Event Support Date: Fri, 6 Dec 2019 18:27:18 +0100 Message-Id: <20191206172724.947-5-eric.auger@redhat.com> In-Reply-To: <20191206172724.947-1-eric.auger@redhat.com> References: <20191206172724.947-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: bNevScXFNg-cmD5S24rlpg-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, andrew.murray@arm.com, drjones@redhat.com, andre.przywara@arm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" If event counters are implemented check the common events required by the PMUv3 are implemented. Some are unconditionally required (SW_INCR, CPU_CYCLES, either INST_RETIRED or INST_SPEC). Some others only are required if the implementation implements some other features. Check those wich are unconditionally required. This test currently fails on TCG as neither INST_RETIRED or INST_SPEC are supported. Signed-off-by: Eric Auger --- arm/pmu.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++ arm/unittests.cfg | 6 ++++ 2 files changed, 76 insertions(+) diff --git a/arm/pmu.c b/arm/pmu.c index 8e95251..f78c43f 100644 --- a/arm/pmu.c +++ b/arm/pmu.c @@ -102,6 +102,10 @@ static inline void precise_instrs_loop(int loop, uint3= 2_t pmcr) : [pmcr] "r" (pmcr), [z] "r" (0) : "cc"); } + +/* event counter tests only implemented for aarch64 */ +static void test_event_introspection(void) {} + #elif defined(__aarch64__) #define ID_AA64DFR0_PERFMON_SHIFT 8 #define ID_AA64DFR0_PERFMON_MASK 0xf @@ -140,6 +144,69 @@ static inline void precise_instrs_loop(int loop, uint3= 2_t pmcr) : [pmcr] "r" (pmcr) : "cc"); } + +#define PMCEID1_EL0 sys_reg(11, 3, 9, 12, 7) + +static bool is_event_supported(uint32_t n, bool warn) +{ + uint64_t pmceid0 =3D read_sysreg(pmceid0_el0); + uint64_t pmceid1 =3D read_sysreg_s(PMCEID1_EL0); + bool supported; + uint32_t reg; + + if (n >=3D 0x0 && n <=3D 0x1F) { + reg =3D pmceid0 & 0xFFFFFFFF; + } else if (n >=3D 0x4000 && n <=3D 0x401F) { + reg =3D pmceid0 >> 32; + } else if (n >=3D 0x20 && n <=3D 0x3F) { + reg =3D pmceid1 & 0xFFFFFFFF; + } else if (n >=3D 0x4020 && n <=3D 0x403F) { + reg =3D pmceid1 >> 32; + } else { + abort(); + } + supported =3D reg & (1 << n); + if (!supported && warn) + report_info("event %d is not supported", n); + return supported; +} + +static void test_event_introspection(void) +{ + bool required_events; + + if (!pmu.nb_implemented_counters) { + report_skip("No event counter, skip ..."); + return; + } + if (pmu.nb_implemented_counters < 2) + report_info("%d event counters are implemented. " + "ARM recommends to implement at least 2", + pmu.nb_implemented_counters); + + /* PMUv3 requires an implementation includes some common events */ + required_events =3D is_event_supported(0x0, true) /* SW_INCR */ && + is_event_supported(0x11, true) /* CPU_CYCLES */ && + (is_event_supported(0x8, true) /* INST_RETIRED */ || + is_event_supported(0x1B, true) /* INST_PREC */); + if (!is_event_supported(0x8, false)) + report_info("ARM strongly recomments INST_RETIRED (0x8) event " + "to be implemented"); + + if (pmu.version =3D=3D 0x4) { + /* ARMv8.1 PMU: STALL_FRONTEND and STALL_BACKEND are required */ + required_events =3D required_events || + is_event_supported(0x23, true) || + is_event_supported(0x24, true); + } + + /* L1D_CACHE_REFILL(0x3) and L1D_CACHE(0x4) are only required if + L1 data / unified cache. BR_MIS_PRED(0x10), BR_PRED(0x12) are only + required if program-flow prediction is implemented. */ + + report("Check required events are implemented", required_events); +} + #endif =20 /* @@ -324,6 +391,9 @@ int main(int argc, char *argv[]) report("Monotonically increasing cycle count", check_cycles_increase()); report("Cycle/instruction ratio", check_cpi(cpi)); pmccntr64_test(); + } else if (strcmp(argv[1], "event-introspection") =3D=3D 0) { + report_prefix_push(argv[1]); + test_event_introspection(); } else { report_abort("Unknown subtest '%s'", argv[1]); } diff --git a/arm/unittests.cfg b/arm/unittests.cfg index 79f0d7a..4433ef3 100644 --- a/arm/unittests.cfg +++ b/arm/unittests.cfg @@ -66,6 +66,12 @@ file =3D pmu.flat groups =3D pmu extra_params =3D -append 'cycle-counter 0' =20 +[pmu-event-introspection] +file =3D pmu.flat +groups =3D pmu +arch =3D arm64 +extra_params =3D -append 'event-introspection' + # Test PMU support (TCG) with -icount IPC=3D1 #[pmu-tcg-icount-1] #file =3D pmu.flat --=20 2.20.1 From nobody Sat Apr 27 10:23:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1575655335; cv=none; d=zohomail.com; s=zohoarc; b=kvRYBeVEZuy29AjdKDjaTN2ocfINFAz8b4aKJc8fNKKoDipl5MEmtFIERD+KfaFC2ZpVmJtbEyx8edNnVit4sdTFOADYGpUPFJyxC6dbBiLipDxdJgUeMD2m9NbJlgK0jmbEjWzT9ZXBEyiNnoqL1qfUuN63VoiWTwaYkSWd1jg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575655335; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=05gJo/iDZRpCh33ff7JxVNxihlf01laZ3I+XStrtiS8=; b=XQa9oB9Dv1Y16R9zMIVPBUbJNaU39omGCP1nvF1O+GK3dnwth6b9P/X+U/VLSyWzym+YMwx8V8/94ZSOai7oL6NNZlI+DZNIjDYhc33JtQKFwdFqj0Wt7GDSYiSQ7kefyShQd1slY//rLoSi8FJKZgI88Q7CLEtV/jcBEam5Uis= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1575655335041818.1271534633104; Fri, 6 Dec 2019 10:02:15 -0800 (PST) Received: from localhost ([::1]:42844 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1idHvh-0007s4-Bq for importer@patchew.org; Fri, 06 Dec 2019 13:02:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45909) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1idHOd-0001w7-Io for qemu-devel@nongnu.org; Fri, 06 Dec 2019 12:28:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1idHOb-0003je-G4 for qemu-devel@nongnu.org; Fri, 06 Dec 2019 12:28:03 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:33226 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1idHOb-0003hR-AD for qemu-devel@nongnu.org; Fri, 06 Dec 2019 12:28:01 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-431-cZUedAMGMjSY8CBp_wrjmw-1; Fri, 06 Dec 2019 12:27:59 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B0943800C7B; Fri, 6 Dec 2019 17:27:57 +0000 (UTC) Received: from laptop.redhat.com (ovpn-116-117.ams2.redhat.com [10.36.116.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id 31D1060BF4; Fri, 6 Dec 2019 17:27:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575653280; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=05gJo/iDZRpCh33ff7JxVNxihlf01laZ3I+XStrtiS8=; b=AGFs9sLEQ6dh04N8M8SW1i7C/5Q7rFwChxycMqc+QRKS126HPEDnOt8d3UTZL1nB0Eo9Ds ThjD/VlU8fU4w7C/A1hiIS/U9t45CRiU0E1RQtlwhyyN7WQV568kEltyLxtVrivCkCbg+l ZTjt2G+WlWE2t8AUgTQLX+8KVixRlrM= From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, maz@kernel.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, qemu-devel@nongnu.org, qemu-arm@nongnu.org Subject: [kvm-unit-tests RFC 05/10] pmu: Basic event counter Tests Date: Fri, 6 Dec 2019 18:27:19 +0100 Message-Id: <20191206172724.947-6-eric.auger@redhat.com> In-Reply-To: <20191206172724.947-1-eric.auger@redhat.com> References: <20191206172724.947-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: cZUedAMGMjSY8CBp_wrjmw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, andrew.murray@arm.com, drjones@redhat.com, andre.przywara@arm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Adds the following tests: - event-counter-config: test event counter configuration - basic-event-count: - programs counters #0 and #1 to count 2 required events (resp. CPU_CYCLES and INST_RETIRED). Counter #0 is preset to a value close enough to the 32b overflow limit so that we check the overflow bit is set after the execution of the asm loop. - mem-access: counts MEM_ACCESS event on counters #0 and #1 with and without 32-bit overflow. Signed-off-by: Eric Auger --- arm/pmu.c | 254 ++++++++++++++++++++++++++++++++++++++++++++++ arm/unittests.cfg | 18 ++++ 2 files changed, 272 insertions(+) diff --git a/arm/pmu.c b/arm/pmu.c index f78c43f..8ffeb93 100644 --- a/arm/pmu.c +++ b/arm/pmu.c @@ -18,9 +18,15 @@ #include "asm/barrier.h" #include "asm/sysreg.h" #include "asm/processor.h" +#include +#include =20 #define PMU_PMCR_E (1 << 0) +#define PMU_PMCR_P (1 << 1) #define PMU_PMCR_C (1 << 2) +#define PMU_PMCR_D (1 << 3) +#define PMU_PMCR_X (1 << 4) +#define PMU_PMCR_DP (1 << 5) #define PMU_PMCR_LC (1 << 6) #define PMU_PMCR_N_SHIFT 11 #define PMU_PMCR_N_MASK 0x1f @@ -105,6 +111,9 @@ static inline void precise_instrs_loop(int loop, uint32= _t pmcr) =20 /* event counter tests only implemented for aarch64 */ static void test_event_introspection(void) {} +static void test_event_counter_config(void) {} +static void test_basic_event_count(void) {} +static void test_mem_access(void) {} =20 #elif defined(__aarch64__) #define ID_AA64DFR0_PERFMON_SHIFT 8 @@ -146,6 +155,32 @@ static inline void precise_instrs_loop(int loop, uint3= 2_t pmcr) } =20 #define PMCEID1_EL0 sys_reg(11, 3, 9, 12, 7) +#define PMCNTENSET_EL0 sys_reg(11, 3, 9, 12, 1) +#define PMCNTENCLR_EL0 sys_reg(11, 3, 9, 12, 2) + +#define PMEVTYPER_EXCLUDE_EL1 (1 << 31) +#define PMEVTYPER_EXCLUDE_EL0 (1 << 30) + +#define regn_el0(__reg, __n) __reg ## __n ## _el0 +#define write_regn(__reg, __n, __val) \ + write_sysreg((__val), __reg ## __n ## _el0) + +#define read_regn(__reg, __n) \ + read_sysreg(__reg ## __n ## _el0) + +#define print_pmevtyper(__s , __n) do { \ + uint32_t val; \ + val =3D read_regn(pmevtyper, __n);\ + report_info("%s pmevtyper%d=3D0x%x, eventcount=3D0x%x (p=3D%ld, u=3D%ld n= sk=3D%ld, nsu=3D%ld, nsh=3D%ld m=3D%ld, mt=3D%ld)", \ + (__s), (__n), val, val & 0xFFFF, \ + (BIT_MASK(31) & val) >> 31, \ + (BIT_MASK(30) & val) >> 30, \ + (BIT_MASK(29) & val) >> 29, \ + (BIT_MASK(28) & val) >> 28, \ + (BIT_MASK(27) & val) >> 27, \ + (BIT_MASK(26) & val) >> 26, \ + (BIT_MASK(25) & val) >> 25); \ + } while (0) =20 static bool is_event_supported(uint32_t n, bool warn) { @@ -207,6 +242,216 @@ static void test_event_introspection(void) report("Check required events are implemented", required_events); } =20 +static inline void mem_access_loop(void *addr, int loop, uint32_t pmcr) +{ +asm volatile( + " msr pmcr_el0, %[pmcr]\n" + " isb\n" + " mov x10, %[loop]\n" + "1: sub x10, x10, #1\n" + " mov x8, %[addr]\n" + " ldr x9, [x8]\n" + " cmp x10, #0x0\n" + " b.gt 1b\n" + " msr pmcr_el0, xzr\n" + " isb\n" + : + : [addr] "r" (addr), [pmcr] "r" (pmcr), [loop] "r" (loop) + : ); +} + + +static void pmu_reset(void) +{ + /* reset all counters, counting disabled at PMCR level*/ + set_pmcr(pmu.pmcr_ro | PMU_PMCR_LC | PMU_PMCR_C | PMU_PMCR_P); + /* Disable all counters */ + write_sysreg_s(0xFFFFFFFF, PMCNTENCLR_EL0); + /* clear overflow reg */ + write_sysreg(0xFFFFFFFF, pmovsclr_el0); + /* disable overflow interrupts on all counters */ + write_sysreg(0xFFFFFFFF, pmintenclr_el1); + isb(); +} + +static void test_event_counter_config(void) { + int i; + + if (!pmu.nb_implemented_counters) { + report_skip("No event counter, skip ..."); + return; + } + + pmu_reset(); + + /* Test setting through PMESELR/PMXEVTYPER and PMEVTYPERn read */ + /* select counter 0 */ + write_sysreg(1, PMSELR_EL0); + /* program this counter to count unsupported event */ + write_sysreg(0xEA, PMXEVTYPER_EL0); + write_sysreg(0xdeadbeef, PMXEVCNTR_EL0); + report("PMESELR/PMXEVTYPER/PMEVTYPERn", + (read_regn(pmevtyper, 1) & 0xFFF) =3D=3D 0xEA); + report("PMESELR/PMXEVCNTR/PMEVCNTRn", + (read_regn(pmevcntr, 1) =3D=3D 0xdeadbeef)); + + /* try configure an unsupported event within the range [0x0, 0x3F] */ + for (i =3D 0; i <=3D 0x3F; i++) { + if (!is_event_supported(i, false)) + goto test_unsupported; + } + report_skip("pmevtyper: all events within [0x0, 0x3F] are supported"); + +test_unsupported: + /* select counter 0 */ + write_sysreg(0, PMSELR_EL0); + /* program this counter to count unsupported event */ + write_sysreg(i, PMXEVCNTR_EL0); + /* read the counter value */ + read_sysreg(PMXEVCNTR_EL0); + report("read of a counter programmed with unsupported event", read_sysreg= (PMXEVCNTR_EL0) =3D=3D i); + +} + +static bool satisfy_prerequisites(uint32_t *events, unsigned int nb_events) +{ + int i; + + if (pmu.nb_implemented_counters < nb_events) { + report_skip("Skip test as number of counters is too small (%d)", + pmu.nb_implemented_counters); + return false; + } + + for (i =3D 0; i < nb_events; i++) { + if (!is_event_supported(events[i], false)) { + report_skip("Skip test as event %d is not supported", + events[i]); + return false; + } + } =09 + return true; +} + +static void test_basic_event_count(void) +{ + uint32_t implemented_counter_mask, non_implemented_counter_mask; + uint32_t counter_mask; + uint32_t events[] =3D { + 0x11, /* CPU_CYCLES */ + 0x8, /* INST_RETIRED */ + }; + + if (!satisfy_prerequisites(events, ARRAY_SIZE(events))) + return; + + implemented_counter_mask =3D (1 << pmu.nb_implemented_counters) - 1; + non_implemented_counter_mask =3D ~((1 << 31) | implemented_counter_mask); + counter_mask =3D implemented_counter_mask | non_implemented_counter_mask; + + write_regn(pmevtyper, 0, events[0] | PMEVTYPER_EXCLUDE_EL0); + write_regn(pmevtyper, 1, events[1] | PMEVTYPER_EXCLUDE_EL0); + + /* disable all counters */ + write_sysreg_s(0xFFFFFFFF, PMCNTENCLR_EL0); + report("pmcntenclr: disable all counters", + !read_sysreg_s(PMCNTENCLR_EL0) && !read_sysreg_s(PMCNTENSET_EL0)); + + /* + * clear cycle and all event counters and allow counter enablement + * through PMCNTENSET. LC is RES1. + */ + set_pmcr(pmu.pmcr_ro | PMU_PMCR_LC | PMU_PMCR_C | PMU_PMCR_P); + isb();=09 + report("pmcr: reset counters", get_pmcr() =3D=3D (pmu.pmcr_ro | PMU_PMCR_= LC)); + + /* Preset counter #0 to 0xFFFFFFF0 to trigger an overflow interrupt */ + write_regn(pmevcntr, 0, 0xFFFFFFF0); + report("counter #0 preset to 0xFFFFFFF0", + read_regn(pmevcntr, 0) =3D=3D 0xFFFFFFF0); + report("counter #1 is 0", !read_regn(pmevcntr, 1)); + + /* + * Enable all implemented counters and also attempt to enable + * not supported counters. Counting still is disabled by !PMCR.E + */ + write_sysreg_s(counter_mask, PMCNTENSET_EL0); + + /* check only those implemented are enabled */ + report("pmcntenset: enabled implemented_counters", + (read_sysreg_s(PMCNTENSET_EL0) =3D=3D read_sysreg_s(PMCNTENCLR_EL0= )) && + (read_sysreg_s(PMCNTENSET_EL0) =3D=3D implemented_counter_mask)); + + /* Disable all counters but counters #0 and #1 */ + write_sysreg_s(~0x3, PMCNTENCLR_EL0); + report("pmcntenset: just enabled #0 and #1", + (read_sysreg_s(PMCNTENSET_EL0) =3D=3D read_sysreg_s(PMCNTENCLR_EL0= )) && + (read_sysreg_s(PMCNTENSET_EL0) =3D=3D 0x3)); + + /* clear overflow register */ + write_sysreg(0xFFFFFFFF, pmovsclr_el0); + report("check overflow reg is 0", !read_sysreg(pmovsclr_el0)); + + /* disable overflow interrupts on all counters*/ + write_sysreg(0xFFFFFFFF, pmintenclr_el1); + report("pmintenclr_el1=3D0, all interrupts disabled", + !read_sysreg(pmintenclr_el1)); + + /* enable overflow interrupts on all event counters */ + write_sysreg(implemented_counter_mask | non_implemented_counter_mask, + pmintenset_el1); + report("overflow interrupts enabled on all implemented counters", + read_sysreg(pmintenset_el1) =3D=3D implemented_counter_mask); + + /* Set PMCR.E, execute asm code and unset PMCR.E */ + precise_instrs_loop(20, pmu.pmcr_ro | PMU_PMCR_E); + + report_info("counter #0 is 0x%lx (CPU_CYCLES)", read_regn(pmevcntr, 0)); + report_info("counter #1 is 0x%lx (INST_RETIRED)", read_regn(pmevcntr, 1)); + + report_info("overflow reg =3D 0x%lx", read_sysreg(pmovsclr_el0) ); + report("check overflow happened on #0 only", read_sysreg(pmovsclr_el0) & = 0x1); +} + +static void test_mem_access(void) +{ + void *addr =3D malloc(PAGE_SIZE); + uint32_t events[] =3D { + 0x13, /* MEM_ACCESS */ + 0x13, /* MEM_ACCESS */ + }; + + if (!satisfy_prerequisites(events, ARRAY_SIZE(events))) + return; + + pmu_reset(); + + write_regn(pmevtyper, 0, events[0] | PMEVTYPER_EXCLUDE_EL0); + write_regn(pmevtyper, 1, events[1] | PMEVTYPER_EXCLUDE_EL0); + write_sysreg_s(0x3, PMCNTENSET_EL0); + isb(); + mem_access_loop(addr, 20, pmu.pmcr_ro | PMU_PMCR_E); + report_info("counter #0 is %ld (MEM_ACCESS)", read_regn(pmevcntr, 0)); + report_info("counter #1 is %ld (MEM_ACCESS)", read_regn(pmevcntr, 1)); + /* We may not measure exactly 20 mem access, this depends on the platform= */ + report("Ran 20 mem accesses", + (read_regn(pmevcntr, 0) =3D=3D read_regn(pmevcntr, 1)) && + (read_regn(pmevcntr, 0) >=3D 20) && !read_sysreg(pmovsclr_el0)); + + pmu_reset(); + + write_regn(pmevcntr, 0, 0xFFFFFFFA); + write_regn(pmevcntr, 1, 0xFFFFFFF0); + write_sysreg_s(0x3, PMCNTENSET_EL0); + isb(); + mem_access_loop(addr, 20, pmu.pmcr_ro | PMU_PMCR_E); + report("Ran 20 mem accesses with expected overflows on both counters", + read_sysreg(pmovsclr_el0) =3D=3D 0x3); + report_info("cnt#0 =3D %ld cnt#1=3D%ld overflow=3D0x%lx", + read_regn(pmevcntr, 0), read_regn(pmevcntr, 1), + read_sysreg(pmovsclr_el0)); +} + #endif =20 /* @@ -394,6 +639,15 @@ int main(int argc, char *argv[]) } else if (strcmp(argv[1], "event-introspection") =3D=3D 0) { report_prefix_push(argv[1]); test_event_introspection(); + } else if (strcmp(argv[1], "event-counter-config") =3D=3D 0) { + report_prefix_push(argv[1]); + test_event_counter_config(); + } else if (strcmp(argv[1], "basic-event-count") =3D=3D 0) { + report_prefix_push(argv[1]); + test_basic_event_count(); + } else if (strcmp(argv[1], "mem-access") =3D=3D 0) { + report_prefix_push(argv[1]); + test_mem_access(); } else { report_abort("Unknown subtest '%s'", argv[1]); } diff --git a/arm/unittests.cfg b/arm/unittests.cfg index 4433ef3..7a59403 100644 --- a/arm/unittests.cfg +++ b/arm/unittests.cfg @@ -72,6 +72,24 @@ groups =3D pmu arch =3D arm64 extra_params =3D -append 'event-introspection' =20 +[pmu-event-counter-config] +file =3D pmu.flat +groups =3D pmu +arch =3D arm64 +extra_params =3D -append 'event-counter-config' + +[pmu-basic-event-count] +file =3D pmu.flat +groups =3D pmu +arch =3D arm64 +extra_params =3D -append 'basic-event-count' + +[pmu-mem-access] +file =3D pmu.flat +groups =3D pmu +arch =3D arm64 +extra_params =3D -append 'mem-access' + # Test PMU support (TCG) with -icount IPC=3D1 #[pmu-tcg-icount-1] #file =3D pmu.flat --=20 2.20.1 From nobody Sat Apr 27 10:23:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1575655487; cv=none; d=zohomail.com; s=zohoarc; b=cpwxvtIQulEPvBpUTljT18y04lptxWeBjad9vB5P9GuJYF6xwry/Ubv+qu5xfmS+iYqUDQVY8DLRrABt2CHInuva43+EPwlzXGfu62FG5G2PbGp84oLZ4FdA1zbdV5u+6xnOo9QZbKRMsvdV3zQXG4k7/byeg3l+d4pjlmN/N7c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575655487; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=cSQq/C7pHCzkPl8tiWZuEBhfZM9PZ9tXND49zKMJFso=; b=F1g1qIVyQAvFm9Y0/vKIUylWyrS0ApGaiSXKdY8YRw9Qje46MH4UrO+4lSUaB6KQtoVyULhaIY01B+1EFxyP/eon1N41BC1jsv2egKeP3IC0yo7KJ/n3hhojyXGPdO2iu7DTD+SeXlgkS4TLNNxCZ12tGbZDBsXnxsrMWttbr4U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1575655487247521.5705113241816; Fri, 6 Dec 2019 10:04:47 -0800 (PST) Received: from localhost ([::1]:42908 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1idHy9-0002bX-Ev for importer@patchew.org; Fri, 06 Dec 2019 13:04:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46185) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1idHOf-0001yr-7O for qemu-devel@nongnu.org; Fri, 06 Dec 2019 12:28:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1idHOd-0003r8-Md for qemu-devel@nongnu.org; Fri, 06 Dec 2019 12:28:05 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:60560 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1idHOd-0003pV-Id for qemu-devel@nongnu.org; Fri, 06 Dec 2019 12:28:03 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-308-8c5GEJRsMwWaBaD1nzgbAw-1; Fri, 06 Dec 2019 12:28:02 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8EB4F107ACC7; Fri, 6 Dec 2019 17:28:00 +0000 (UTC) Received: from laptop.redhat.com (ovpn-116-117.ams2.redhat.com [10.36.116.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1101760BF4; Fri, 6 Dec 2019 17:27:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575653283; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cSQq/C7pHCzkPl8tiWZuEBhfZM9PZ9tXND49zKMJFso=; b=auC4eH5FY42YDKcpTP9ic8ih/NWuoeIT4++bCj/B7CsjltpeCjbK272R3QRCFRD0CC4qBP DAcYPRhoJmJnbvto7InlVI/gGQxZicOArVnXnMwNI2eTiSS11BV+gDfegQEsaAMVnGykLq Uvow8soO1ZMexvJVaqi4kgi6eysEMn0= From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, maz@kernel.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, qemu-devel@nongnu.org, qemu-arm@nongnu.org Subject: [kvm-unit-tests RFC 06/10] pmu: Test chained counter Date: Fri, 6 Dec 2019 18:27:20 +0100 Message-Id: <20191206172724.947-7-eric.auger@redhat.com> In-Reply-To: <20191206172724.947-1-eric.auger@redhat.com> References: <20191206172724.947-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: 8c5GEJRsMwWaBaD1nzgbAw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, andrew.murray@arm.com, drjones@redhat.com, andre.przywara@arm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Add 2 tests exercising chained counters. The first one uses CPU_CYCLES and the second one uses SW_INCR. Signed-off-by: Eric Auger --- arm/pmu.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++ arm/unittests.cfg | 12 +++++ 2 files changed, 137 insertions(+) diff --git a/arm/pmu.c b/arm/pmu.c index 8ffeb93..e185809 100644 --- a/arm/pmu.c +++ b/arm/pmu.c @@ -114,6 +114,8 @@ static void test_event_introspection(void) {} static void test_event_counter_config(void) {} static void test_basic_event_count(void) {} static void test_mem_access(void) {} +static void test_chained_counters(void) {} +static void test_chained_sw_incr(void) {} =20 #elif defined(__aarch64__) #define ID_AA64DFR0_PERFMON_SHIFT 8 @@ -452,6 +454,123 @@ static void test_mem_access(void) read_sysreg(pmovsclr_el0)); } =20 +static void test_chained_counters(void) +{ + uint32_t events[] =3D { 0x11 /* CPU_CYCLES */, 0x1E /* CHAIN */}; + + if (!satisfy_prerequisites(events, ARRAY_SIZE(events))) + return; + + pmu_reset(); + + write_regn(pmevtyper, 0, events[0] | PMEVTYPER_EXCLUDE_EL0); + write_regn(pmevtyper, 1, events[1] | PMEVTYPER_EXCLUDE_EL0); + /* enable counters #0 and #1 */ + write_sysreg_s(0x3, PMCNTENSET_EL0); + /* preset counter #0 at 0xFFFFFFF0 */ + write_regn(pmevcntr, 0, 0xFFFFFFF0); + + precise_instrs_loop(22, pmu.pmcr_ro | PMU_PMCR_E); + + report("CHAIN counter #1 incremented", read_regn(pmevcntr, 1) =3D=3D 1);=20 + report("check no overflow is recorded", !read_sysreg(pmovsclr_el0)); + + /* test 64b overflow */ + + pmu_reset(); + write_sysreg_s(0x3, PMCNTENSET_EL0); + + write_regn(pmevcntr, 0, 0xFFFFFFF0); + write_regn(pmevcntr, 1, 0x1); + precise_instrs_loop(22, pmu.pmcr_ro | PMU_PMCR_E); + report_info("overflow reg =3D 0x%lx", read_sysreg(pmovsclr_el0)); + report("CHAIN counter #1 incremented", read_regn(pmevcntr, 1) =3D=3D 2);=20 + report("check no overflow is recorded", !read_sysreg(pmovsclr_el0)); + + write_regn(pmevcntr, 0, 0xFFFFFFF0); + write_regn(pmevcntr, 1, 0xFFFFFFFF); + + precise_instrs_loop(22, pmu.pmcr_ro | PMU_PMCR_E); + report_info("overflow reg =3D 0x%lx", read_sysreg(pmovsclr_el0)); + report("CHAIN counter #1 wrapped", !read_regn(pmevcntr, 1));=20 + report("check no overflow is recorded", read_sysreg(pmovsclr_el0) =3D=3D = 0x2); +} + +static void test_chained_sw_incr(void) +{ + uint32_t events[] =3D { 0x0 /* SW_INCR */, 0x0 /* SW_INCR */}; + int i; + + if (!satisfy_prerequisites(events, ARRAY_SIZE(events))) + return; + + pmu_reset(); + + write_regn(pmevtyper, 0, events[0] | PMEVTYPER_EXCLUDE_EL0); + write_regn(pmevtyper, 1, events[1] | PMEVTYPER_EXCLUDE_EL0); + /* enable counters #0 and #1 */ + write_sysreg_s(0x3, PMCNTENSET_EL0); + + /* preset counter #0 at 0xFFFFFFF0 */ + write_regn(pmevcntr, 0, 0xFFFFFFF0); + + for (i =3D 0; i < 100; i++) { + write_sysreg(0x1, pmswinc_el0); + } + report_info("SW_INCR counter #0 has value %ld", read_regn(pmevcntr, 0));=20 + report("PWSYNC does not increment if PMCR.E is unset", + read_regn(pmevcntr, 0) =3D=3D 0xFFFFFFF0); + + pmu_reset(); + + write_regn(pmevcntr, 0, 0xFFFFFFF0); + write_sysreg_s(0x3, PMCNTENSET_EL0); + set_pmcr(pmu.pmcr_ro | PMU_PMCR_E); + + for (i =3D 0; i < 100; i++) { + write_sysreg(0x3, pmswinc_el0); + } + report("counter #1 after + 100 SW_INCR", read_regn(pmevcntr, 0) =3D=3D 8= 4); + report("counter #0 after + 100 SW_INCR", read_regn(pmevcntr, 1) =3D=3D 1= 00); + report_info(" counter values after 100 SW_INCR #0=3D%ld #1=3D%ld", + read_regn(pmevcntr, 0), read_regn(pmevcntr, 1)); + report("overflow reg after 100 SW_INCR", read_sysreg(pmovsclr_el0) =3D=3D= 0x1); + + /* 64b SW_INCR */ + pmu_reset(); + + events[1] =3D 0x1E /* CHAIN */; + write_regn(pmevtyper, 1, events[1] | PMEVTYPER_EXCLUDE_EL0); + write_regn(pmevcntr, 0, 0xFFFFFFF0); + write_sysreg_s(0x3, PMCNTENSET_EL0); + set_pmcr(pmu.pmcr_ro | PMU_PMCR_E); + for (i =3D 0; i < 100; i++) { + write_sysreg(0x3, pmswinc_el0); + } + report("overflow reg after 100 SW_INCR/CHAIN", + !read_sysreg(pmovsclr_el0) && (read_regn(pmevcntr, 1) =3D=3D 1)); + report_info("overflow=3D0x%lx, #0=3D%ld #1=3D%ld", read_sysreg(pmovsclr_e= l0), + read_regn(pmevcntr, 0), read_regn(pmevcntr, 1)); + + /* 64b SW_INCR and overflow on CHAIN counter*/ + pmu_reset(); + + write_regn(pmevtyper, 1, events[1] | PMEVTYPER_EXCLUDE_EL0); + write_regn(pmevcntr, 0, 0xFFFFFFF0); + write_regn(pmevcntr, 1, 0xFFFFFFFF); + write_sysreg_s(0x3, PMCNTENSET_EL0); + set_pmcr(pmu.pmcr_ro | PMU_PMCR_E); + for (i =3D 0; i < 100; i++) { + write_sysreg(0x3, pmswinc_el0); + } + report("overflow reg after 100 SW_INCR/CHAIN", + (read_sysreg(pmovsclr_el0) =3D=3D 0x2) && + (read_regn(pmevcntr, 1) =3D=3D 0) && + (read_regn(pmevcntr, 0) =3D=3D 84)); + report_info("overflow=3D0x%lx, #0=3D%ld #1=3D%ld", read_sysreg(pmovsclr_e= l0), + read_regn(pmevcntr, 0), read_regn(pmevcntr, 1)); +} + #endif =20 /* @@ -648,6 +767,12 @@ int main(int argc, char *argv[]) } else if (strcmp(argv[1], "mem-access") =3D=3D 0) { report_prefix_push(argv[1]); test_mem_access(); + } else if (strcmp(argv[1], "chained-counters") =3D=3D 0) { + report_prefix_push(argv[1]); + test_chained_counters(); + } else if (strcmp(argv[1], "chained-sw-incr") =3D=3D 0) { + report_prefix_push(argv[1]); + test_chained_sw_incr(); } else { report_abort("Unknown subtest '%s'", argv[1]); } diff --git a/arm/unittests.cfg b/arm/unittests.cfg index 7a59403..1bd4319 100644 --- a/arm/unittests.cfg +++ b/arm/unittests.cfg @@ -90,6 +90,18 @@ groups =3D pmu arch =3D arm64 extra_params =3D -append 'mem-access' =20 +[pmu-chained-counters] +file =3D pmu.flat +groups =3D pmu +arch =3D arm64 +extra_params =3D -append 'chained-counters' + +[pmu-chained-sw-incr] +file =3D pmu.flat +groups =3D pmu +arch =3D arm64 +extra_params =3D -append 'chained-sw-incr' + # Test PMU support (TCG) with -icount IPC=3D1 #[pmu-tcg-icount-1] #file =3D pmu.flat --=20 2.20.1 From nobody Sat Apr 27 10:23:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1575655949; cv=none; d=zohomail.com; s=zohoarc; b=JOqIogFrDm7z1gL9iTDK+X0qvfgPYwnBtmk3v1I/QIwHZAuIW+zoVrbpF5sSH1xUNNFA89FnBntLS0/6gHVXbezPkKPwX4UzFEJq1v9F2HlAu3n9BqFeceO8Ci80aehfZknDKBkbcOi4DEW+Uehb1ykuBVnREAX5U8QrMf+WGlg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575655949; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ws3xaERf1779J4gNkymE+bAzmPMolefs3O1wIlcUpJo=; b=iIsTbPPkhuAazUIRSJGaS0KUUsIooC5Avsaiha9weOoKCLo23uyjm6R7ZHtxEFlPWi6dW08UhvJaNegMSPRKxa/V1i2RPyvSWvci+nOVSFdiwECDmG0+xRigwR5ec6OyVrji1kUZoPqJAAObxdHVC1mzTi/8J5mDfTUVQRtXfng= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 15756559497520.6326747616379862; Fri, 6 Dec 2019 10:12:29 -0800 (PST) Received: from localhost ([::1]:43060 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1idI5c-0002kw-DF for importer@patchew.org; Fri, 06 Dec 2019 13:12:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46746) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1idHOi-00025O-Hi for qemu-devel@nongnu.org; Fri, 06 Dec 2019 12:28:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1idHOh-00043U-4q for qemu-devel@nongnu.org; Fri, 06 Dec 2019 12:28:08 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:41412 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1idHOg-00041s-V7 for qemu-devel@nongnu.org; Fri, 06 Dec 2019 12:28:07 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-103-F-9tv1RVOcePy6CWYZVclw-1; Fri, 06 Dec 2019 12:28:05 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 697F7107ACC4; Fri, 6 Dec 2019 17:28:03 +0000 (UTC) Received: from laptop.redhat.com (ovpn-116-117.ams2.redhat.com [10.36.116.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id E3D7160BF4; Fri, 6 Dec 2019 17:28:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575653286; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ws3xaERf1779J4gNkymE+bAzmPMolefs3O1wIlcUpJo=; b=Z+c9/k5WUxFlrmhMZtZIT+HdTL9dU7irnnTOFtvHyN5hxLOWZSJio+BU8Uo02k4z86vHkV +qSjZOH+EIgGUKwz6ebGJKUAeVwX2SoBs7AjVV92lzEMUcoVnIiUCD5etKDnanq2qhkie/ ZEy/ZyTItvVVdR19edkVaNBuNjlnrLE= From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, maz@kernel.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, qemu-devel@nongnu.org, qemu-arm@nongnu.org Subject: [kvm-unit-tests RFC 07/10] arm: pmu: test 32-bit <-> 64-bit transitions Date: Fri, 6 Dec 2019 18:27:21 +0100 Message-Id: <20191206172724.947-8-eric.auger@redhat.com> In-Reply-To: <20191206172724.947-1-eric.auger@redhat.com> References: <20191206172724.947-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: F-9tv1RVOcePy6CWYZVclw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, andrew.murray@arm.com, drjones@redhat.com, andre.przywara@arm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" --- arm/pmu.c | 125 +++++++++++++++++++++++++++++++++++++++++++++- arm/unittests.cfg | 6 +++ 2 files changed, 130 insertions(+), 1 deletion(-) diff --git a/arm/pmu.c b/arm/pmu.c index e185809..47d46a2 100644 --- a/arm/pmu.c +++ b/arm/pmu.c @@ -116,6 +116,7 @@ static void test_basic_event_count(void) {} static void test_mem_access(void) {} static void test_chained_counters(void) {} static void test_chained_sw_incr(void) {} +static void test_chain_promotion(void) {} =20 #elif defined(__aarch64__) #define ID_AA64DFR0_PERFMON_SHIFT 8 @@ -262,7 +263,6 @@ asm volatile( : ); } =20 - static void pmu_reset(void) { /* reset all counters, counting disabled at PMCR level*/ @@ -571,6 +571,126 @@ static void test_chained_sw_incr(void) read_regn(pmevcntr, 0), read_regn(pmevcntr, 1)); } =20 +static void test_chain_promotion(void) +{ + uint32_t events[] =3D { 0x13 /* MEM_ACCESS */, 0x1E /* CHAIN */}; + void *addr =3D malloc(PAGE_SIZE); + + if (!satisfy_prerequisites(events, ARRAY_SIZE(events))) + return; + + /* Only enable CHAIN counter */ + pmu_reset(); + write_regn(pmevtyper, 0, events[0] | PMEVTYPER_EXCLUDE_EL0); + write_regn(pmevtyper, 1, events[1] | PMEVTYPER_EXCLUDE_EL0); + write_sysreg_s(0x2, PMCNTENSET_EL0); + isb(); + + mem_access_loop(addr, 20, pmu.pmcr_ro | PMU_PMCR_E); + report("chain counter not counting if even counter is disabled", + !read_regn(pmevcntr, 0)); + + /* Only enable even counter */ + pmu_reset(); + write_regn(pmevcntr, 0, 0xFFFFFFF0); + write_sysreg_s(0x1, PMCNTENSET_EL0); + isb(); + + mem_access_loop(addr, 20, pmu.pmcr_ro | PMU_PMCR_E); + report("odd counter did not increment on overflow if disabled", + !read_regn(pmevcntr, 1) && (read_sysreg(pmovsclr_el0) =3D=3D 0x1)); + report_info("MEM_ACCESS counter #0 has value %ld", read_regn(pmevcntr, 0)= );=20 + report_info("CHAIN counter #1 has value %ld", read_regn(pmevcntr, 1));=20 + report_info("overflow counter %ld", read_sysreg(pmovsclr_el0)); + + /* start at 0xFFFFFFDC, +20 with CHAIN enabled, +20 with CHAIN disabled */ + pmu_reset(); + write_sysreg_s(0x3, PMCNTENSET_EL0); + write_regn(pmevcntr, 0, 0xFFFFFFDC); + isb(); + + mem_access_loop(addr, 20, pmu.pmcr_ro | PMU_PMCR_E); + report_info("MEM_ACCESS counter #0 has value 0x%lx", read_regn(pmevcntr, = 0));=20 + + /* disable the CHAIN event */ + write_sysreg_s(0x2, PMCNTENCLR_EL0); + mem_access_loop(addr, 20, pmu.pmcr_ro | PMU_PMCR_E); + report_info("MEM_ACCESS counter #0 has value 0x%lx", read_regn(pmevcntr, = 0));=20 + report("should have triggered an overflow on #0", read_sysreg(pmovsclr_el= 0) =3D=3D 0x1); + report("CHAIN counter #1 shouldn't have incremented", !read_regn(pmevcntr= , 1)); + + /* start at 0xFFFFFFDC, +20 with CHAIN disabled, +20 with CHAIN enabled */ + + pmu_reset(); + write_sysreg_s(0x1, PMCNTENSET_EL0); + write_regn(pmevcntr, 0, 0xFFFFFFDC); + isb(); + report_info("counter #0 =3D 0x%lx, counter #1 =3D 0x%lx overflow=3D0x%lx", + read_regn(pmevcntr, 0), read_regn(pmevcntr, 1), + read_sysreg(pmovsclr_el0)); + + mem_access_loop(addr, 20, pmu.pmcr_ro | PMU_PMCR_E); + report_info("MEM_ACCESS counter #0 has value 0x%lx", read_regn(pmevcntr, = 0));=20 + + /* enable the CHAIN event */ + write_sysreg_s(0x3, PMCNTENSET_EL0); + isb(); + mem_access_loop(addr, 20, pmu.pmcr_ro | PMU_PMCR_E); + report_info("MEM_ACCESS counter #0 has value 0x%lx", read_regn(pmevcntr, = 0));=20 + + report("CHAIN counter #1 should have incremented and no overflow expected= ", + (read_regn(pmevcntr, 1) =3D=3D 1) && !read_sysreg(pmovsclr_el0)); + + report_info("CHAIN counter #1 =3D 0x%lx, overflow=3D0x%lx", + read_regn(pmevcntr, 1), read_sysreg(pmovsclr_el0)); + + /* start as MEM_ACCESS/CPU_CYCLES and move to CHAIN/MEM_ACCESS */ + pmu_reset(); + write_regn(pmevtyper, 0, 0x13 /* MEM_ACCESS */ | PMEVTYPER_EXCLUDE= _EL0); + write_regn(pmevtyper, 1, 0x11 /* CPU_CYCLES */ | PMEVTYPER_EXCLUDE= _EL0); + write_sysreg_s(0x3, PMCNTENSET_EL0); + write_regn(pmevcntr, 0, 0xFFFFFFDC); + isb(); + + mem_access_loop(addr, 20, pmu.pmcr_ro | PMU_PMCR_E); + report_info("MEM_ACCESS counter #0 has value 0x%lx", read_regn(pmevcntr, = 0));=20 + + /* 0 becomes CHAINED */ + write_sysreg_s(0x0, PMCNTENSET_EL0); + write_regn(pmevtyper, 1, 0x1E /* CHAIN */ | PMEVTYPER_EXCLUDE_EL0); + write_sysreg_s(0x3, PMCNTENSET_EL0); + + mem_access_loop(addr, 20, pmu.pmcr_ro | PMU_PMCR_E); + report_info("MEM_ACCESS counter #0 has value 0x%lx", read_regn(pmevcntr, = 0));=20 + + report("CHAIN counter #1 should have incremented and no overflow expected= ", + (read_regn(pmevcntr, 1) =3D=3D 1) && !read_sysreg(pmovsclr_el0)); + + report_info("CHAIN counter #1 =3D 0x%lx, overflow=3D0x%lx", + read_regn(pmevcntr, 1), read_sysreg(pmovsclr_el0)); + + /* start as CHAIN/MEM_ACCESS and move to MEM_ACCESS/CPU_CYCLES */ + pmu_reset(); + write_regn(pmevtyper, 0, 0x13 /* MEM_ACCESS */ | PMEVTYPER_EXCLUDE= _EL0); + write_regn(pmevtyper, 1, 0x1E /* CHAIN */ | PMEVTYPER_EXCLUDE_EL0); + write_regn(pmevcntr, 0, 0xFFFFFFDC); + write_sysreg_s(0x3, PMCNTENSET_EL0); + + mem_access_loop(addr, 20, pmu.pmcr_ro | PMU_PMCR_E); + report_info("counter #0=3D0x%lx, counter #1=3D0x%lx", + read_regn(pmevcntr, 0), read_regn(pmevcntr, 1)); + + write_sysreg_s(0x0, PMCNTENSET_EL0); + write_regn(pmevtyper, 1, 0x11 /* CPU_CYCLES */ | PMEVTYPER_EXCLUDE= _EL0); + write_sysreg_s(0x3, PMCNTENSET_EL0); + + mem_access_loop(addr, 20, pmu.pmcr_ro | PMU_PMCR_E); + report("overflow is expected on counter 0", read_sysreg(pmovsclr_el0) =3D= =3D 1); + report_info("counter #0=3D0x%lx, counter #1=3D0x%lx overflow=3D0x%lx", + read_regn(pmevcntr, 0), read_regn(pmevcntr, 1), + read_sysreg(pmovsclr_el0)); +} + #endif =20 /* @@ -773,6 +893,9 @@ int main(int argc, char *argv[]) } else if (strcmp(argv[1], "chained-sw-incr") =3D=3D 0) { report_prefix_push(argv[1]); test_chained_sw_incr(); + } else if (strcmp(argv[1], "chain-promotion") =3D=3D 0) { + report_prefix_push(argv[1]); + test_chain_promotion(); } else { report_abort("Unknown subtest '%s'", argv[1]); } diff --git a/arm/unittests.cfg b/arm/unittests.cfg index 1bd4319..eb6e87e 100644 --- a/arm/unittests.cfg +++ b/arm/unittests.cfg @@ -102,6 +102,12 @@ groups =3D pmu arch =3D arm64 extra_params =3D -append 'chained-sw-incr' =20 +[pmu-chain-promotion] +file =3D pmu.flat +groups =3D pmu +arch =3D arm64 +extra_params =3D -append 'chain-promotion' + # Test PMU support (TCG) with -icount IPC=3D1 #[pmu-tcg-icount-1] #file =3D pmu.flat --=20 2.20.1 From nobody Sat Apr 27 10:23:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1575656049; cv=none; d=zohomail.com; s=zohoarc; b=TkB/4fQmbwZtw5NjJH2HGdK1/PY5zbbTPbRb4ayC06MlO4olcCD6whN4J7r3gQWpnAoiyZPiCUvgE2RosbRpNmf5HmNxU8ORlSG+EX0fwP+Rqrf/38/JHpM0grHzqzKYQ5LMYakxCsSXhdaMsAs3JP8O6uWbSqAkgDsyiiVR98M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575656049; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=lX67DIL+lZaCTnHkDq82inRHfTC6JJtSh3OkkISzfmY=; b=jrpZurHI5de1eo75BZM7l8opJdsuazxS2brqK9lhqxVN53d7XpF1RAn5BKHcROxCyUBK6KcucKLV+ZixywnB9WJhv3Vc2sxcyG/c7XEQF3iPao3Tr0prf1GY/d4o7k0ZNBIdmlAV8sA/jV3sZzfQ7Ke18nX8e09rbd/AF94I5YM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1575656049293590.117445282565; Fri, 6 Dec 2019 10:14:09 -0800 (PST) Received: from localhost ([::1]:43066 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1idI7E-000473-5p for importer@patchew.org; Fri, 06 Dec 2019 13:14:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47153) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1idHOm-00028P-Kh for qemu-devel@nongnu.org; Fri, 06 Dec 2019 12:28:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1idHOk-0004D2-Ew for qemu-devel@nongnu.org; Fri, 06 Dec 2019 12:28:12 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:49336 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1idHOk-0004B0-3t for qemu-devel@nongnu.org; Fri, 06 Dec 2019 12:28:10 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-165-ZjMCxGmWPFqGGTt0nhH_nA-1; Fri, 06 Dec 2019 12:28:08 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4A79D107ACC4; Fri, 6 Dec 2019 17:28:06 +0000 (UTC) Received: from laptop.redhat.com (ovpn-116-117.ams2.redhat.com [10.36.116.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id C04AC60BF4; Fri, 6 Dec 2019 17:28:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575653289; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lX67DIL+lZaCTnHkDq82inRHfTC6JJtSh3OkkISzfmY=; b=TCuLAlb3qiZZwH0YHSf/UdIwo2UnTKom8PX3jNxaCPdKhwz5QTndRSJF1ewCf/LJI8j18J ZdJI6vXY3kFvTwt5wA77Ttwqvmm+Vh10pXvT4RP51M/uDkrE1DieX5DqwRsLkVpK/SiPmX YUuaDG5CT+68qD3Q0YKhJ0ddA7Zn6FM= From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, maz@kernel.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, qemu-devel@nongnu.org, qemu-arm@nongnu.org Subject: [kvm-unit-tests RFC 08/10] arm: gic: Provide per-IRQ helper functions Date: Fri, 6 Dec 2019 18:27:22 +0100 Message-Id: <20191206172724.947-9-eric.auger@redhat.com> In-Reply-To: <20191206172724.947-1-eric.auger@redhat.com> References: <20191206172724.947-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: ZjMCxGmWPFqGGTt0nhH_nA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, andrew.murray@arm.com, drjones@redhat.com, andre.przywara@arm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Andre Przywara A common theme when accessing per-IRQ parameters in the GIC distributor is to set fields of a certain bit width in a range of MMIO registers. Examples are the enabled status (one bit per IRQ), the level/edge configuration (2 bits per IRQ) or the priority (8 bits per IRQ). Add a generic helper function which is able to mask and set the respective number of bits, given the IRQ number and the MMIO offset. Provide wrappers using this function to easily allow configuring an IRQ. For now assume that private IRQ numbers always refer to the current CPU. In a GICv2 accessing the "other" private IRQs is not easily doable (the registers are banked per CPU on the same MMIO address), so we impose the same limitation on GICv3, even though those registers are not banked there anymore. Signed-off-by: Andre Przywara --- initialize reg --- lib/arm/asm/gic-v3.h | 2 + lib/arm/asm/gic.h | 9 +++++ lib/arm/gic.c | 90 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+) diff --git a/lib/arm/asm/gic-v3.h b/lib/arm/asm/gic-v3.h index 347be2f..4a445a5 100644 --- a/lib/arm/asm/gic-v3.h +++ b/lib/arm/asm/gic-v3.h @@ -23,6 +23,8 @@ #define GICD_CTLR_ENABLE_G1A (1U << 1) #define GICD_CTLR_ENABLE_G1 (1U << 0) =20 +#define GICD_IROUTER 0x6000 + /* Re-Distributor registers, offsets from RD_base */ #define GICR_TYPER 0x0008 =20 diff --git a/lib/arm/asm/gic.h b/lib/arm/asm/gic.h index 1fc10a0..21cdb58 100644 --- a/lib/arm/asm/gic.h +++ b/lib/arm/asm/gic.h @@ -15,6 +15,7 @@ #define GICD_IIDR 0x0008 #define GICD_IGROUPR 0x0080 #define GICD_ISENABLER 0x0100 +#define GICD_ICENABLER 0x0180 #define GICD_ISPENDR 0x0200 #define GICD_ICPENDR 0x0280 #define GICD_ISACTIVER 0x0300 @@ -73,5 +74,13 @@ extern void gic_write_eoir(u32 irqstat); extern void gic_ipi_send_single(int irq, int cpu); extern void gic_ipi_send_mask(int irq, const cpumask_t *dest); =20 +void gic_set_irq_bit(int irq, int offset); +void gic_enable_irq(int irq); +void gic_disable_irq(int irq); +void gic_set_irq_priority(int irq, u8 prio); +void gic_set_irq_target(int irq, int cpu); +void gic_set_irq_group(int irq, int group); +int gic_get_irq_group(int irq); + #endif /* !__ASSEMBLY__ */ #endif /* _ASMARM_GIC_H_ */ diff --git a/lib/arm/gic.c b/lib/arm/gic.c index 9430116..aa9cb86 100644 --- a/lib/arm/gic.c +++ b/lib/arm/gic.c @@ -146,3 +146,93 @@ void gic_ipi_send_mask(int irq, const cpumask_t *dest) assert(gic_common_ops && gic_common_ops->ipi_send_mask); gic_common_ops->ipi_send_mask(irq, dest); } + +enum gic_bit_access { + ACCESS_READ, + ACCESS_SET, + ACCESS_RMW +}; + +static u8 gic_masked_irq_bits(int irq, int offset, int bits, u8 value, + enum gic_bit_access access) +{ + void *base; + int split =3D 32 / bits; + int shift =3D (irq % split) * bits; + u32 reg =3D 0, mask =3D ((1U << bits) - 1) << shift; + + switch (gic_version()) { + case 2: + base =3D gicv2_dist_base(); + break; + case 3: + if (irq < 32) + base =3D gicv3_sgi_base(); + else + base =3D gicv3_dist_base(); + break; + default: + return 0; + } + base +=3D offset + (irq / split) * 4; + + switch (access) { + case ACCESS_READ: + return (readl(base) & mask) >> shift; + case ACCESS_SET: + reg =3D 0; + break; + case ACCESS_RMW: + reg =3D readl(base) & ~mask; + break; + } + + writel(reg | ((u32)value << shift), base); + + return 0; +} + +void gic_set_irq_bit(int irq, int offset) +{ + gic_masked_irq_bits(irq, offset, 1, 1, ACCESS_SET); +} + +void gic_enable_irq(int irq) +{ + gic_set_irq_bit(irq, GICD_ISENABLER); +} + +void gic_disable_irq(int irq) +{ + gic_set_irq_bit(irq, GICD_ICENABLER); +} + +void gic_set_irq_priority(int irq, u8 prio) +{ + gic_masked_irq_bits(irq, GICD_IPRIORITYR, 8, prio, ACCESS_RMW); +} + +void gic_set_irq_target(int irq, int cpu) +{ + if (irq < 32) + return; + + if (gic_version() =3D=3D 2) { + gic_masked_irq_bits(irq, GICD_ITARGETSR, 8, 1U << cpu, + ACCESS_RMW); + + return; + } + + writeq(cpus[cpu], gicv3_dist_base() + GICD_IROUTER + irq * 8); +} + +void gic_set_irq_group(int irq, int group) +{ + gic_masked_irq_bits(irq, GICD_IGROUPR, 1, group, ACCESS_RMW); +} + +int gic_get_irq_group(int irq) +{ + return gic_masked_irq_bits(irq, GICD_IGROUPR, 1, 0, ACCESS_READ); +} --=20 2.20.1 From nobody Sat Apr 27 10:23:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1575657642; cv=none; d=zohomail.com; s=zohoarc; b=c6shki0JChIWU1d273rzzpdvCmyEnsOC0fNmw5iIEKIYP4ZALaQzW0Sdnwlc/oVBxieyqux8cILGlBruBdmH+caiyCcn4DWoYONkWdKVxj58EgVpusDlRnJF3zxT4NxVSba1RpySN0/kpExA8upPrJ9h+N1YKbvN+2puOpitslo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575657642; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=19yQ4vp56OlBsL/0IrWKby5/zs2yahEC4NVwVl09/bk=; b=IdVhcLf5GpB5Q9NMikvXIKm76yn10RI31xfDZ6+/Za9JymYVaD9MbIjccrosUedqGw1Mhv7I+bwwS2KWlbOuzzEFLOdBfhw2qjbm3dl8izUbrH/OzLHPfHwobUiY5CuIfgeM9vb8rkl2dXHpCbl6n0ay7zHI3ixEkqxT4OZ7ezY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1575657642020659.3767282189092; Fri, 6 Dec 2019 10:40:42 -0800 (PST) Received: from localhost ([::1]:43724 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1idIWu-0006yu-US for importer@patchew.org; Fri, 06 Dec 2019 13:40:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47570) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1idHOr-0002Cr-0g for qemu-devel@nongnu.org; Fri, 06 Dec 2019 12:28:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1idHOp-0004Ms-LU for qemu-devel@nongnu.org; Fri, 06 Dec 2019 12:28:16 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:54529 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1idHOp-0004KP-E0 for qemu-devel@nongnu.org; Fri, 06 Dec 2019 12:28:15 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-103-K79uiRAXONuXvi2zOw0w7Q-1; Fri, 06 Dec 2019 12:28:14 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B301B1005502; Fri, 6 Dec 2019 17:28:11 +0000 (UTC) Received: from laptop.redhat.com (ovpn-116-117.ams2.redhat.com [10.36.116.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id A0C1E60BF4; Fri, 6 Dec 2019 17:28:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575653295; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=19yQ4vp56OlBsL/0IrWKby5/zs2yahEC4NVwVl09/bk=; b=G3UfLBzYqlCXsU0y1w7G3tsyPap1TergDLakD7weNcp8zgYg1Do9nWfUNWWeOQtugi1xD1 w4/Os6hTZ4+WF/9uLYo0DlTrQSeZ4AT43qyS86KAOTua0CTpetsFGOECA9RzSejZW488nn kgLdSQugQ6zs28CdteQv+C/zn85jjI8= From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, maz@kernel.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, qemu-devel@nongnu.org, qemu-arm@nongnu.org Subject: [kvm-unit-tests RFC 09/10] arm/arm64: gic: Introduce setup_irq() helper Date: Fri, 6 Dec 2019 18:27:23 +0100 Message-Id: <20191206172724.947-10-eric.auger@redhat.com> In-Reply-To: <20191206172724.947-1-eric.auger@redhat.com> References: <20191206172724.947-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: K79uiRAXONuXvi2zOw0w7Q-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, andrew.murray@arm.com, drjones@redhat.com, andre.przywara@arm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" ipi_enable() code would be reusable for other interrupts than IPI. Let's rename it setup_irq() and pass an interrupt handler pointer. We also export it to use it in other tests such as the PMU's one. Signed-off-by: Eric Auger --- arm/gic.c | 24 +++--------------------- lib/arm/asm/gic.h | 3 +++ lib/arm/gic.c | 11 +++++++++++ 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/arm/gic.c b/arm/gic.c index adb6aa4..04919ae 100644 --- a/arm/gic.c +++ b/arm/gic.c @@ -215,20 +215,9 @@ static void ipi_test_smp(void) report_prefix_pop(); } =20 -static void ipi_enable(void) -{ - gic_enable_defaults(); -#ifdef __arm__ - install_exception_handler(EXCPTN_IRQ, ipi_handler); -#else - install_irq_handler(EL1H_IRQ, ipi_handler); -#endif - local_irq_enable(); -} - static void ipi_send(void) { - ipi_enable(); + setup_irq(ipi_handler); wait_on_ready(); ipi_test_self(); ipi_test_smp(); @@ -238,7 +227,7 @@ static void ipi_send(void) =20 static void ipi_recv(void) { - ipi_enable(); + setup_irq(ipi_handler); cpumask_set_cpu(smp_processor_id(), &ready); while (1) wfi(); @@ -295,14 +284,7 @@ static void ipi_clear_active_handler(struct pt_regs *r= egs __unused) static void run_active_clear_test(void) { report_prefix_push("active"); - gic_enable_defaults(); -#ifdef __arm__ - install_exception_handler(EXCPTN_IRQ, ipi_clear_active_handler); -#else - install_irq_handler(EL1H_IRQ, ipi_clear_active_handler); -#endif - local_irq_enable(); - + setup_irq(ipi_clear_active_handler); ipi_test_self(); report_prefix_pop(); } diff --git a/lib/arm/asm/gic.h b/lib/arm/asm/gic.h index 21cdb58..55dd84b 100644 --- a/lib/arm/asm/gic.h +++ b/lib/arm/asm/gic.h @@ -82,5 +82,8 @@ void gic_set_irq_target(int irq, int cpu); void gic_set_irq_group(int irq, int group); int gic_get_irq_group(int irq); =20 +typedef void (*handler_t)(struct pt_regs *regs __unused); +extern void setup_irq(handler_t handler); + #endif /* !__ASSEMBLY__ */ #endif /* _ASMARM_GIC_H_ */ diff --git a/lib/arm/gic.c b/lib/arm/gic.c index aa9cb86..0c5511f 100644 --- a/lib/arm/gic.c +++ b/lib/arm/gic.c @@ -236,3 +236,14 @@ int gic_get_irq_group(int irq) { return gic_masked_irq_bits(irq, GICD_IGROUPR, 1, 0, ACCESS_READ); } + +void setup_irq(handler_t handler) +{ + gic_enable_defaults(); +#ifdef __arm__ + install_exception_handler(EXCPTN_IRQ, handler); +#else + install_irq_handler(EL1H_IRQ, handler); +#endif + local_irq_enable(); +} --=20 2.20.1 From nobody Sat Apr 27 10:23:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1575657845; cv=none; d=zohomail.com; s=zohoarc; b=FymVWcza+RjV3lPA1gpqcK8upOuZHcP6UBEK17CdA0tNrfUkkAneLzp5YMzXj8udDZmJmGlKGnRXk8OmMz/1Lg0S7LSmnoW7wln+8ZcPXd/VSA1WEG0fkxpAIYdu+zSZR/1CTsWCfJgx5TLGKnr7pRrMYLSdkZt/4ZVheosdj9c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575657845; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=uHy6JtDFNgRRZUOE/EOkjvVUEne6jqUvFOy591Cbfrs=; b=I3Ipy6CTL1qsFNY5IVjcDLzHiQCMO6TxyPE6xkI1jx3/85lWQUUeu+xc4ml/V1ZQxRcW2B+DtG8TQaa6WIyWWvuZigYksvS0ahYZgAtiVVZVJ9kmvkJYAW5crB9o20seYJIOSPHIV3eOAahmjMN7CurL2vNQkKfoFju8/Qrf46I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1575657845012414.9917666037795; Fri, 6 Dec 2019 10:44:05 -0800 (PST) Received: from localhost ([::1]:43772 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1idIaB-0001Ad-F2 for importer@patchew.org; Fri, 06 Dec 2019 13:44:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47982) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1idHOt-0002GY-B9 for qemu-devel@nongnu.org; Fri, 06 Dec 2019 12:28:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1idHOr-0004VV-Ql for qemu-devel@nongnu.org; Fri, 06 Dec 2019 12:28:19 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:24198 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1idHOr-0004TQ-Lo for qemu-devel@nongnu.org; Fri, 06 Dec 2019 12:28:17 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-155-BOXZZEcbPF-QJRXfsfQH8w-1; Fri, 06 Dec 2019 12:28:16 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 925BC800EB9; Fri, 6 Dec 2019 17:28:14 +0000 (UTC) Received: from laptop.redhat.com (ovpn-116-117.ams2.redhat.com [10.36.116.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id 15F6560BF4; Fri, 6 Dec 2019 17:28:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575653297; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uHy6JtDFNgRRZUOE/EOkjvVUEne6jqUvFOy591Cbfrs=; b=h47tVp+4Tc3SrZw+tDX0LUm6aXF0pOMfmv17POB1nphloPJPl8RyvKxB8UgODdFdMl/157 b7UPOFIeD/Mdkuy1hL51B7TskLoDapmRfJEMmseKXOjVsi5NzfbtJjNfibPj0yZZ+5vkXX XB+fId0uzLRbyYM3xHahohw5dTrvnQY= From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, maz@kernel.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, qemu-devel@nongnu.org, qemu-arm@nongnu.org Subject: [kvm-unit-tests RFC 10/10] pmu: Test overflow interrupts Date: Fri, 6 Dec 2019 18:27:24 +0100 Message-Id: <20191206172724.947-11-eric.auger@redhat.com> In-Reply-To: <20191206172724.947-1-eric.auger@redhat.com> References: <20191206172724.947-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: BOXZZEcbPF-QJRXfsfQH8w-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, andrew.murray@arm.com, drjones@redhat.com, andre.przywara@arm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Test overflows for MEM_ACESS and SW_INCR events. Also tests overflows with 64-bit events. Signed-off-by: Eric Auger --- arm/pmu.c | 133 +++++++++++++++++++++++++++++++++++++++++++++- arm/unittests.cfg | 6 +++ 2 files changed, 138 insertions(+), 1 deletion(-) diff --git a/arm/pmu.c b/arm/pmu.c index 47d46a2..a63b93e 100644 --- a/arm/pmu.c +++ b/arm/pmu.c @@ -45,8 +45,12 @@ struct pmu { uint32_t pmcr_ro; }; =20 -static struct pmu pmu; +struct pmu_stats { + unsigned long bitmap; + uint32_t interrupts[32]; +}; =20 +static struct pmu pmu; =20 #if defined(__arm__) #define ID_DFR0_PERFMON_SHIFT 24 @@ -117,6 +121,7 @@ static void test_mem_access(void) {} static void test_chained_counters(void) {} static void test_chained_sw_incr(void) {} static void test_chain_promotion(void) {} +static void test_overflow_interrupt(void) {} =20 #elif defined(__aarch64__) #define ID_AA64DFR0_PERFMON_SHIFT 8 @@ -263,6 +268,43 @@ asm volatile( : ); } =20 +static struct pmu_stats pmu_stats; + +static void irq_handler(struct pt_regs *regs) +{ + uint32_t irqstat, irqnr; + + irqstat =3D gic_read_iar(); + irqnr =3D gic_iar_irqnr(irqstat); + gic_write_eoir(irqstat); + + if (irqnr =3D=3D 23) { + unsigned long overflows =3D read_sysreg(pmovsclr_el0); + int i; + + report_info("--> PMU overflow interrupt %d (counter bitmas= k 0x%lx)", irqnr, overflows); + for (i =3D 0; i < 32; i++) { + if (test_and_clear_bit(i, &overflows)) { + pmu_stats.interrupts[i]++; + pmu_stats.bitmap |=3D 1 << i; + } + } + write_sysreg(0xFFFFFFFF, pmovsclr_el0); + } else { + report_info("Unexpected interrupt: %d\n", irqnr); + } +} + +static void pmu_reset_stats(void) +{ + int i; + + for (i =3D 0; i < 32; i++) { + pmu_stats.interrupts[i] =3D 0; + } + pmu_stats.bitmap =3D 0; +} + static void pmu_reset(void) { /* reset all counters, counting disabled at PMCR level*/ @@ -273,6 +315,7 @@ static void pmu_reset(void) write_sysreg(0xFFFFFFFF, pmovsclr_el0); /* disable overflow interrupts on all counters */ write_sysreg(0xFFFFFFFF, pmintenclr_el1); + pmu_reset_stats(); isb(); } =20 @@ -691,8 +734,93 @@ static void test_chain_promotion(void) read_sysreg(pmovsclr_el0)); } =20 +static bool expect_interrupts(uint32_t bitmap) +{ + int i; + + if (pmu_stats.bitmap ^ bitmap) + return false; + + for (i =3D 0; i < 32; i++) { + if (test_and_clear_bit(i, &pmu_stats.bitmap)) + if (pmu_stats.interrupts[i] !=3D 1) + return false; + } + return true; +} + +static void test_overflow_interrupt(void) +{ + uint32_t events[] =3D { 0x13 /* MEM_ACCESS */, 0x00 /* SW_INCR */}; + void *addr =3D malloc(PAGE_SIZE); + int i; + + if (!satisfy_prerequisites(events, ARRAY_SIZE(events))) + return; + + setup_irq(irq_handler); + gic_enable_irq(23); + + pmu_reset(); + + write_regn(pmevtyper, 0, events[0] | PMEVTYPER_EXCLUDE_EL0); + write_regn(pmevtyper, 1, events[1] | PMEVTYPER_EXCLUDE_EL0); + write_sysreg_s(0x3, PMCNTENSET_EL0); + write_regn(pmevcntr, 0, 0xFFFFFFF0); + write_regn(pmevcntr, 1, 0xFFFFFFF0); + isb(); + + /* interrupts are disabled */ + + mem_access_loop(addr, 200, pmu.pmcr_ro | PMU_PMCR_E); + report("no overflow interrupt received", expect_interrupts(0)); + + set_pmcr(pmu.pmcr_ro | PMU_PMCR_E); + for (i =3D 0; i < 100; i++) { + write_sysreg(0x2, pmswinc_el0); + } + set_pmcr(pmu.pmcr_ro); + report("no overflow interrupt received", expect_interrupts(0)); + + /* enable interrupts */ + + pmu_reset_stats(); + + write_regn(pmevcntr, 0, 0xFFFFFFF0); + write_regn(pmevcntr, 1, 0xFFFFFFF0); + write_sysreg(0xFFFFFFFF, pmintenset_el1); + isb(); + + mem_access_loop(addr, 200, pmu.pmcr_ro | PMU_PMCR_E); + for (i =3D 0; i < 100; i++) { + write_sysreg(0x3, pmswinc_el0); + } + mem_access_loop(addr, 200, pmu.pmcr_ro); + report_info("overflow=3D0x%lx", read_sysreg(pmovsclr_el0)); + report("overflow interrupts expected on #0 and #1", expect_interrupts(0x3= )); + + /* promote to 64-b */ + + pmu_reset_stats(); + + events[1] =3D 0x1E /* CHAIN */; + write_regn(pmevtyper, 1, events[1] | PMEVTYPER_EXCLUDE_EL0); + write_regn(pmevcntr, 0, 0xFFFFFFF0); + isb(); + mem_access_loop(addr, 200, pmu.pmcr_ro | PMU_PMCR_E); + report("no overflow interrupt expected on 32b boundary", expect_interrupt= s(0)); + + /* overflow on odd counter */ + pmu_reset_stats(); + write_regn(pmevcntr, 0, 0xFFFFFFF0); + write_regn(pmevcntr, 1, 0xFFFFFFFF); + isb(); + mem_access_loop(addr, 200, pmu.pmcr_ro | PMU_PMCR_E); + report("expect overflow interrupt on odd counter", expect_interrupts(0x2)= ); +} #endif =20 + /* * 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 @@ -896,6 +1024,9 @@ int main(int argc, char *argv[]) } else if (strcmp(argv[1], "chain-promotion") =3D=3D 0) { report_prefix_push(argv[1]); test_chain_promotion(); + } else if (strcmp(argv[1], "overflow-interrupt") =3D=3D 0) { + report_prefix_push(argv[1]); + test_overflow_interrupt(); } else { report_abort("Unknown subtest '%s'", argv[1]); } diff --git a/arm/unittests.cfg b/arm/unittests.cfg index eb6e87e..31b4c7a 100644 --- a/arm/unittests.cfg +++ b/arm/unittests.cfg @@ -108,6 +108,12 @@ groups =3D pmu arch =3D arm64 extra_params =3D -append 'chain-promotion' =20 +[pmu-chain-promotion] +file =3D pmu.flat +groups =3D pmu +arch =3D arm64 +extra_params =3D -append 'overflow-interrupt' + # Test PMU support (TCG) with -icount IPC=3D1 #[pmu-tcg-icount-1] #file =3D pmu.flat --=20 2.20.1