Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp203822lqg; Fri, 1 Mar 2024 02:41:37 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU4jwgwOy9vSXX/HSLZIluUuhW6ChDoYjR4fB+p3bRrNpQgPEnKw9xgbBTWLuwVq7i8V7wGhEmE/AXk8l0/SfSbXkik0UAJEzdoSfnsVQ== X-Google-Smtp-Source: AGHT+IG6bhKHSP8a04i/tQJPDdvLZpuDt+ndJND6klN5o/WQx1fWCmIoAByn14m65/gzKEP6Z3y6 X-Received: by 2002:a17:906:cecc:b0:a44:a9cf:5567 with SMTP id si12-20020a170906cecc00b00a44a9cf5567mr303855ejb.34.1709289697265; Fri, 01 Mar 2024 02:41:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709289697; cv=pass; d=google.com; s=arc-20160816; b=QDZIwwsyi4NCDJc6DrHBTMkAInVATjKN4rgs8c/Whvq9MfyG3yypLZkWCjZ5e1kosa 2VBp4LFG6oYAdPjbPEGH6v+yeG/c2avZKZBUnNdaJdDdm1BlPsd5KX0N/L4MBOupW5NH O3x9Isnt6mMZkIEZuRjYMxotHWnrtaDvjLxlwcICoF/ta54IIV+E7INoV8WT5xCermRV WAU0YmyaMugNerBB2JIous0gfueT5CX2ZG7+yjIWl99m+6lCf+POuzvv9plrOkS4b132 GujwhDpF5oHcNgguvMIZLKmQj2yzFFqwD0l9ODCClMZDjgQH2oIqfZ+O6wgbYbwQ8OBx ib1Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=AyczRoc8zwOC9hsxzaj2db9K2Y/ZvntkudwAJJn92Yc=; fh=nM5LGLPjxW/gsteNR6nga6cfpclY55uRvyUqtC2yPeo=; b=GDSpaJ+91z6He1rQjebonLUHhItAhBG0iObskWuGkYQaqEUQQh8cKm7jQ+8SdLeEql J/wpKaEtYEZJx3mXqMlrLCoYKwr9mZjjMOQrUmtJLM2gZ4Kn4iJ+a69zHHtaaQSXEngd 272DsFGHHXeNoyoEw07NxBXqXpQNJapWYfbgNdNuFmiC9JtNMsJ87iZiZ9BijsBZ2Jg7 aNjIHfQnPn4OlhUNTrfnPND/XIty/rBFUDThdg/SF4L6V3WQtm1vvTcdCKjjDGt6V6Ru hdYYb0Rvnkayb54Lj49SHUyvVRHxWiwSJj1TEpPOl1Rl2mkZx6ONxLu27Yui40OIJ9W9 lkZg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@brainfault-org.20230601.gappssmtp.com header.s=20230601 header.b=ZkMfrrtp; arc=pass (i=1 dkim=pass dkdomain=brainfault-org.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-87895-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87895-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id u17-20020a170906069100b00a449fe3d7bfsi190321ejb.34.2024.03.01.02.41.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 02:41:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-87895-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@brainfault-org.20230601.gappssmtp.com header.s=20230601 header.b=ZkMfrrtp; arc=pass (i=1 dkim=pass dkdomain=brainfault-org.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-87895-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87895-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 81C211F24CFB for ; Fri, 1 Mar 2024 04:44:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BFC4A50271; Fri, 1 Mar 2024 04:43:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=brainfault-org.20230601.gappssmtp.com header.i=@brainfault-org.20230601.gappssmtp.com header.b="ZkMfrrtp" Received: from mail-il1-f175.google.com (mail-il1-f175.google.com [209.85.166.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 577D11DFCF for ; Fri, 1 Mar 2024 04:43:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709268226; cv=none; b=og94vuSoJlEUhcIq2tRA+Vg5ZfxwkxT6h5Q8BrfI+6poonHuIUjdygtnB8/lS0tkGbE/7IM4u0mMXJ8XR4/bAQWCRE6aoEEIw/T5opB+5/RLr5LAMQXfp06Rbcdum9+8DCljukKIctRWFdLGrHVgHMzwnm82gSLfW5KZnfHLWAg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709268226; c=relaxed/simple; bh=xyHAs22Xo3Cq+1aeu1IEMp8xwYTqfcFhrG7ehR+YQQw=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=kSP04AIHlQzuW1bkYR8/LHWmbzlXOEUfVLUvVmWPpzQIiC9lxOLBTKcy23Z5QfrB43EQ3oWYU+HvA9f7Kcpmdusem50HkA1oTvtO/OVJTlGQoDoM6KrbJiWdu1LkSA4d2mBlUAgcpI+Nx6Xonh6LRsx2sg4B0cBOtZNAvLeB6p4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=brainfault.org; spf=none smtp.mailfrom=brainfault.org; dkim=pass (2048-bit key) header.d=brainfault-org.20230601.gappssmtp.com header.i=@brainfault-org.20230601.gappssmtp.com header.b=ZkMfrrtp; arc=none smtp.client-ip=209.85.166.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=brainfault.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=brainfault.org Received: by mail-il1-f175.google.com with SMTP id e9e14a558f8ab-365138d9635so6198915ab.3 for ; Thu, 29 Feb 2024 20:43:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20230601.gappssmtp.com; s=20230601; t=1709268223; x=1709873023; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=AyczRoc8zwOC9hsxzaj2db9K2Y/ZvntkudwAJJn92Yc=; b=ZkMfrrtp3CcwJrFf0CALYH3z7bn8xMOznlip5vnSJ1HbhqWzR5hbzOB0QmN2t4OP40 gc4Mz8XpgL+pfuIXH7/nn2DmTuToawrwa8lhdCEt8/BRniFf/YcZ/TTsK90dEbzCeZs2 86YHjOfOI5G3w0TrqE1NuUoATRYItFeLb1wemnmfoV514sDTGRKGgJ8PnOJ0eoIIkAt5 zPzdqyFLUl+MQjzhjNqlEDAQihf3KsY5qDtyX0TN44WFIrrsvJRjGMb1BrgE1nWOr90k /d2luxTSE5XriolOlMRYKBr5KmFfNhbbUhLsdIJE/o1VP/IA0qPZItUbaW1H88bwIUkB l8+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709268223; x=1709873023; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AyczRoc8zwOC9hsxzaj2db9K2Y/ZvntkudwAJJn92Yc=; b=K6XOkxC2KstGmteB5eVEbUzmLpKmEiMjU9QC8BHrG7Q7S2l6r7pLdBBNxeUQJaKsap z6dAYmbehIIAOIsvohwwglf/GNDEbG8AZy13sZ0V/Cv2s35Wm6ApZXmvhfXc1vsZ6iQI tM6nQULdVuZaQZHEHCTqaF0LwMDVmsuR1hrji3+ArLZn/sf8foaoSn40nRlBYap857tj Wt8jAzXb9UJQPJffj5EJQsV/sjPzOzeEyn4VvhfkctE3/W9jcThQ/W2oXOHGThOzqITJ hH7t4ipBXu1tIVkHkvIfO7sYYadMMISNjDnQh8DqgASiYb6S88d/RRnsAxpgX1r8eakI 7RnA== X-Gm-Message-State: AOJu0Yw9XYrQV4i4vqEdZv/7vPMeleeIb3CKIJazNyep80sr5VPxt6jV MGy694R3MmDDTFZGmQH14VV1ZayYbtQKcHH79I8/XEiqX3Evusoz9RG5uayfndzw8bk3YNVLnWT a4zRMUMK6YYpwtvR+TxKJLj0wMw1T63NFLaEGPR+YIpP/M+CvAwk= X-Received: by 2002:a05:6e02:190f:b0:365:10dd:d1aa with SMTP id w15-20020a056e02190f00b0036510ddd1aamr868808ilu.16.1709268223495; Thu, 29 Feb 2024 20:43:43 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240229010130.1380926-1-atishp@rivosinc.com> <20240229010130.1380926-13-atishp@rivosinc.com> In-Reply-To: <20240229010130.1380926-13-atishp@rivosinc.com> From: Anup Patel Date: Fri, 1 Mar 2024 10:13:33 +0530 Message-ID: Subject: Re: [PATCH v4 12/15] KVM: riscv: selftests: Add SBI PMU extension definitions To: Atish Patra Cc: linux-kernel@vger.kernel.org, Albert Ou , Alexandre Ghiti , Andrew Jones , Atish Patra , Conor Dooley , Guo Ren , Icenowy Zheng , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Palmer Dabbelt , Paolo Bonzini , Paul Walmsley , Shuah Khan , Will Deacon Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Feb 29, 2024 at 6:32=E2=80=AFAM Atish Patra w= rote: > > The SBI PMU extension definition is required for upcoming SBI PMU > selftests. > > Signed-off-by: Atish Patra LGTM. Reviewed-by: Anup Patel Regards, Anup > --- > .../selftests/kvm/include/riscv/processor.h | 67 +++++++++++++++++++ > 1 file changed, 67 insertions(+) > > diff --git a/tools/testing/selftests/kvm/include/riscv/processor.h b/tool= s/testing/selftests/kvm/include/riscv/processor.h > index f75c381fa35a..a49a39c8e8d4 100644 > --- a/tools/testing/selftests/kvm/include/riscv/processor.h > +++ b/tools/testing/selftests/kvm/include/riscv/processor.h > @@ -169,17 +169,84 @@ void vm_install_exception_handler(struct kvm_vm *vm= , int vector, exception_handl > enum sbi_ext_id { > SBI_EXT_BASE =3D 0x10, > SBI_EXT_STA =3D 0x535441, > + SBI_EXT_PMU =3D 0x504D55, > }; > > enum sbi_ext_base_fid { > SBI_EXT_BASE_PROBE_EXT =3D 3, > }; > > +enum sbi_ext_pmu_fid { > + SBI_EXT_PMU_NUM_COUNTERS =3D 0, > + SBI_EXT_PMU_COUNTER_GET_INFO, > + SBI_EXT_PMU_COUNTER_CFG_MATCH, > + SBI_EXT_PMU_COUNTER_START, > + SBI_EXT_PMU_COUNTER_STOP, > + SBI_EXT_PMU_COUNTER_FW_READ, > + SBI_EXT_PMU_COUNTER_FW_READ_HI, > + SBI_EXT_PMU_SNAPSHOT_SET_SHMEM, > +}; > + > +union sbi_pmu_ctr_info { > + unsigned long value; > + struct { > + unsigned long csr:12; > + unsigned long width:6; > +#if __riscv_xlen =3D=3D 32 > + unsigned long reserved:13; > +#else > + unsigned long reserved:45; > +#endif > + unsigned long type:1; > + }; > +}; > + > struct sbiret { > long error; > long value; > }; > > +/** General pmu event codes specified in SBI PMU extension */ > +enum sbi_pmu_hw_generic_events_t { > + SBI_PMU_HW_NO_EVENT =3D 0, > + SBI_PMU_HW_CPU_CYCLES =3D 1, > + SBI_PMU_HW_INSTRUCTIONS =3D 2, > + SBI_PMU_HW_CACHE_REFERENCES =3D 3, > + SBI_PMU_HW_CACHE_MISSES =3D 4, > + SBI_PMU_HW_BRANCH_INSTRUCTIONS =3D 5, > + SBI_PMU_HW_BRANCH_MISSES =3D 6, > + SBI_PMU_HW_BUS_CYCLES =3D 7, > + SBI_PMU_HW_STALLED_CYCLES_FRONTEND =3D 8, > + SBI_PMU_HW_STALLED_CYCLES_BACKEND =3D 9, > + SBI_PMU_HW_REF_CPU_CYCLES =3D 10, > + > + SBI_PMU_HW_GENERAL_MAX, > +}; > + > +/* SBI PMU counter types */ > +enum sbi_pmu_ctr_type { > + SBI_PMU_CTR_TYPE_HW =3D 0x0, > + SBI_PMU_CTR_TYPE_FW, > +}; > + > +/* Flags defined for config matching function */ > +#define SBI_PMU_CFG_FLAG_SKIP_MATCH (1 << 0) > +#define SBI_PMU_CFG_FLAG_CLEAR_VALUE (1 << 1) > +#define SBI_PMU_CFG_FLAG_AUTO_START (1 << 2) > +#define SBI_PMU_CFG_FLAG_SET_VUINH (1 << 3) > +#define SBI_PMU_CFG_FLAG_SET_VSINH (1 << 4) > +#define SBI_PMU_CFG_FLAG_SET_UINH (1 << 5) > +#define SBI_PMU_CFG_FLAG_SET_SINH (1 << 6) > +#define SBI_PMU_CFG_FLAG_SET_MINH (1 << 7) > + > +/* Flags defined for counter start function */ > +#define SBI_PMU_START_FLAG_SET_INIT_VALUE (1 << 0) > +#define SBI_PMU_START_FLAG_INIT_FROM_SNAPSHOT BIT(1) > + > +/* Flags defined for counter stop function */ > +#define SBI_PMU_STOP_FLAG_RESET (1 << 0) > +#define SBI_PMU_STOP_FLAG_TAKE_SNAPSHOT BIT(1) > + > struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, > unsigned long arg1, unsigned long arg2, > unsigned long arg3, unsigned long arg4, > -- > 2.34.1 >