Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1976590rdb; Thu, 7 Dec 2023 14:29:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IGBr1AMtUIE6mHRDab6OekqP/17xbT7Y70DonnpJOQ7rpA/WP6GCZPx9r7OBoaqgbYrNNji X-Received: by 2002:a05:6a20:5482:b0:17a:4871:63fd with SMTP id i2-20020a056a20548200b0017a487163fdmr4754963pzk.0.1701988142378; Thu, 07 Dec 2023 14:29:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701988142; cv=none; d=google.com; s=arc-20160816; b=KjYBLAuWZDjtPeq4CjEvOlR5wL+ILLsLBuQtAiz5Uia4G789PX9+89qw6/BIB8/b3x 5CAhSy2P+QVUuihqeoBNReFnRQ8MAQaVxO6TPoYLSP+7s6rAHzkYuQMs4EXZ2DQPpE6o apT70y9/Xv0AIr8xLtcY8v3/sct3CaeO8VerTsHYrfBWM4DjZJAoHU++qo38MhQvZP2a B+DsOEaYwoLNRip7IAdwQz5DidmDXA5T10Quya7m1UsJRFzXjeRrRW0iYnr7k3pZHcsp jEPGNwbfokHOSzwrR9Pc1EZtvuG8MN05yOIXvI2w+/tWcF7IXiqDjFwn3xBw1biZzF2h eIoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=F7X6vTFqWb09Hl26abSc3iWrCQ3sx3FODL4PuiNVTps=; fh=lz5uT8MnTQyovOvOftLhlXwBFSD6XoOQUuxXL4BX9G8=; b=PlFmFSGNivaZnWDcRXPYJzQfFbvdKaWLrj/AWAm8uH+Y23XcU55f7oerUAhdSQ1pS7 WRcMaq3JzysNrjYYqtcVeyDnJMeA4DDIsCnYQTDOhx+V2gA+7Slhir/OeAa1MOqVl04t T6GrMOSwxaXkeOlvUvhLhDY/jWMxdssQCLP0Vm/1o+up7D4PiEyxx+/2ww8f/44W9LVh iJ/AsgOEaamR+LjmLfRUB5LV9pY0NO72bmtafnpsKxnq+e/WPeLopvm+zSOvHnS8hIV+ pWOXYfgeMB1UEJeh0c8rIYUBdnxYQjs6qR7/DyA5Bm6Pqot5I2kflHMZtNJKhPl0uGTy yaDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="qwvQgD/k"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id w16-20020a056a0014d000b006b4231ba465si393368pfu.85.2023.12.07.14.29.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 14:29:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="qwvQgD/k"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 521BB8526820; Thu, 7 Dec 2023 14:28:59 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232144AbjLGW2m (ORCPT + 99 others); Thu, 7 Dec 2023 17:28:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231950AbjLGW23 (ORCPT ); Thu, 7 Dec 2023 17:28:29 -0500 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3495A172A for ; Thu, 7 Dec 2023 14:28:35 -0800 (PST) Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-50be10acaf9so1306116e87.1 for ; Thu, 07 Dec 2023 14:28:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1701988113; x=1702592913; 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=F7X6vTFqWb09Hl26abSc3iWrCQ3sx3FODL4PuiNVTps=; b=qwvQgD/k5SqjXaqCLOFfY5Vgj+s5ig5xf04vC7RV8K0TKdYo4CZlsbpaKb5XTCGqPC l8KDBxF8dhnxOg7UT8zlXppkMUgv61J0S/sETV+AsKPZ4d3Y9TEaRgEvTbLs7TYLWl2X CeY+HXrsCTrP6fqfn+pYPR0F+Il0sL+haHTUYGMflMauBSUUSuKe0s1ssRVPhBzm9o3i OKeuTVxTM4E0kX4s/J/yLWhLrcUyi/mKFcFYg8EnIavQY4L9nh4N+WKpcvGtK3+NhNn4 F7n51FobRuWE9CzIuK1NBzAz1J5EdSBuEY7tWygez8zFUpA7K2nFrqmIedt5/CUmKTjn 5z+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701988113; x=1702592913; 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=F7X6vTFqWb09Hl26abSc3iWrCQ3sx3FODL4PuiNVTps=; b=Ku/znXgwOWuq3oc91KB9/tUOQBb0VrJNS8B+NhUzRsrJb58T2exwmFG54dC3EZuPje sBnQUnrh0+K3FbeT71mcsQn2GRmw2Xitpf7qjZm1FaWE/f3nfXYTZ7tXgnKHmnEGUG4x 5DCfYhUlSiCPDxw2Ss790safiHHmvzRosF6H+N/v6ys4CuyobmhapTfD8SMn53R6HXLr UoW4I+tYU/ZRc89SDGhSi1PPPkebiu5v4mTgdc/LTZuiUrQaaoO/3ZCzevsMC6LOyaUC Jptg9tG5qMaOM3/3lZSNfeDzCNjV1hoBWeD2VlNamMl2ghTmAKOCmM9HhWzGKxptnGdA bN0g== X-Gm-Message-State: AOJu0YypWgHczDPSGYX/SuMvNE8bkPJye0owR/usvIT7b+2WSqJ2og1A ILKoyGBjSWR2BZQo5494eYYngK+0AzoLvn6MiouKUWGrfUO0MLmd X-Received: by 2002:a05:6512:2203:b0:50b:f88d:f848 with SMTP id h3-20020a056512220300b0050bf88df848mr3898378lfu.23.1701988113187; Thu, 07 Dec 2023 14:28:33 -0800 (PST) MIME-Version: 1.0 References: <20231205024310.1593100-1-atishp@rivosinc.com> <20231207-affiliate-state-c4a20ea7e8de@wendy> In-Reply-To: <20231207-affiliate-state-c4a20ea7e8de@wendy> From: Atish Kumar Patra Date: Thu, 7 Dec 2023 14:28:22 -0800 Message-ID: Subject: Re: [RFC 0/9] RISC-V SBI v2.0 PMU improvements and Perf sampling in KVM guest To: Conor Dooley Cc: linux-kernel@vger.kernel.org, Alexandre Ghiti , Andrew Jones , Anup Patel , Atish Patra , Guo Ren , Icenowy Zheng , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Palmer Dabbelt , Paul Walmsley , Will Deacon Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 07 Dec 2023 14:28:59 -0800 (PST) On Thu, Dec 7, 2023 at 4:03=E2=80=AFAM Conor Dooley wrote: > > Hey Atish, > > On Mon, Dec 04, 2023 at 06:43:01PM -0800, Atish Patra wrote: > > This series implements SBI PMU improvements done in SBI v2.0[1] i.e. PM= U snapshot > > and fw_read_hi() functions. > > I don't see any commentary in this cover letter as to why the series is > an RFC. v2.0 is a frozen spec per the Releases tab on GitHub, so that > has ruled out the usual reason for spec related things being RFCs. > > What is it about the series that you are not yet willing to stand over? > Nothing. It's just my script where I tag any first version of a feature series as RFC :). I am planning to send the next one with a version tag this week as I got some feedback. Thanks for reviewing the patches :). > Cheers, > Conor. > > > SBI v2.0 introduced PMU snapshot feature which allows the SBI implement= ation > > to provide counter information (i.e. values/overlfow status) via a shar= ed > > memory between the SBI implementation and supervisor OS. This allows to= minimize > > the number of traps in when perf being used inside a kvm guest as it re= lies on > > SBI PMU + trap/emulation of the counters. > > > > The current set of ratified RISC-V specification also doesn't allow sco= untovf > > to be trap/emulated by the hypervisor. The SBI PMU snapshot bridges the= gap > > in ISA as well and enables perf sampling in the guest. However, LCOFI i= n the > > guest only works via IRQ filtering in AIA specification. That's why, AI= A > > has to be enabled in the hardware (at least the Ssaia extension) in ord= er to > > use the sampling support in the perf. > > > > Here are the patch wise implementation details. > > > > PATCH 1-2 : Generic cleanups/improvements. > > PATCH 3,4,9 : FW_READ_HI function implementation > > PATCH 5-6: Add PMU snapshot feature in sbi pmu driver > > PATCH 7-8: KVM implementation for snapshot and sampling in kvm guests > > > > The series is based on v6.70-rc3 and is available at: > > > > https://github.com/atishp04/linux/tree/kvm_pmu_snapshot_v1 > > > > The kvmtool patch is also available at: > > https://github.com/atishp04/kvmtool/tree/sscofpmf > > > > It also requires Ssaia ISA extension to be present in the hardware in o= rder to > > get perf sampling support in the guest. In Qemu virt machine, it can be= done > > by the following config. > > > > ``` > > -cpu rv64,sscofpmf=3Dtrue,x-ssaia=3Dtrue > > ``` > > > > There is no other dependancies on AIA apart from that. Thus, Ssaia must= be disabled > > for the guest if AIA patches are not available. Here is the example com= mand. > > > > ``` > > ./lkvm-static run -m 256 -c2 --console serial -p "console=3DttyS0 early= con" --disable-ssaia -k ./Image --debug > > ``` > > > > The series has been tested only in Qemu. > > Here is the snippet of the perf running inside a kvm guest. > > > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D > > # perf record -e cycles -e instructions perf bench sched messaging -g 5 > > ... > > # Running 'sched/messaging' benchmark: > > ... > > [ 45.928723] perf_duration_warn: 2 callbacks suppressed > > [ 45.929000] perf: interrupt took too long (484426 > 483186), lowerin= g kernel.perf_event_max_sample_rate to 250 > > # 20 sender and receiver processes per group > > # 5 groups =3D=3D 200 processes run > > > > Total time: 14.220 [sec] > > [ perf record: Woken up 1 times to write data ] > > [ perf record: Captured and wrote 0.117 MB perf.data (1942 samples) ] > > # perf report --stdio > > # To display the perf.data header info, please use --header/--header-on= ly optio> > > # > > # > > # Total Lost Samples: 0 > > # > > # Samples: 943 of event 'cycles' > > # Event count (approx.): 5128976844 > > # > > # Overhead Command Shared Object Symbol = > > > # ........ ............... ........................... .............= ........> > > # > > 7.59% sched-messaging [kernel.kallsyms] [k] memcpy > > 5.48% sched-messaging [kernel.kallsyms] [k] percpu_co= unter_ad> > > 5.24% sched-messaging [kernel.kallsyms] [k] __sbi_rfe= nce_v02_> > > 4.00% sched-messaging [kernel.kallsyms] [k] _raw_spin= _unlock_> > > 3.79% sched-messaging [kernel.kallsyms] [k] set_pte_r= ange > > 3.72% sched-messaging [kernel.kallsyms] [k] next_upto= date_fol> > > 3.46% sched-messaging [kernel.kallsyms] [k] filemap_m= ap_pages > > 3.31% sched-messaging [kernel.kallsyms] [k] handle_mm= _fault > > 3.20% sched-messaging [kernel.kallsyms] [k] finish_ta= sk_switc> > > 3.16% sched-messaging [kernel.kallsyms] [k] clear_pag= e > > 3.03% sched-messaging [kernel.kallsyms] [k] mtree_ran= ge_walk > > 2.42% sched-messaging [kernel.kallsyms] [k] flush_ica= che_pte > > > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D > > > > [1] https://github.com/riscv-non-isa/riscv-sbi-doc > > > > Atish Patra (9): > > RISC-V: Fix the typo in Scountovf CSR name > > drivers/perf: riscv: Add a flag to indicate SBI v2.0 support > > RISC-V: Add FIRMWARE_READ_HI definition > > drivers/perf: riscv: Read upper bits of a firmware counter > > RISC-V: Add SBI PMU snapshot definitions > > drivers/perf: riscv: Implement SBI PMU snapshot function > > RISC-V: KVM: Implement SBI PMU Snapshot feature > > RISC-V: KVM: Add perf sampling support for guests > > RISC-V: KVM: Support 64 bit firmware counters on RV32 > > > > arch/riscv/include/asm/csr.h | 5 +- > > arch/riscv/include/asm/errata_list.h | 2 +- > > arch/riscv/include/asm/kvm_vcpu_pmu.h | 16 +- > > arch/riscv/include/asm/sbi.h | 11 ++ > > arch/riscv/include/uapi/asm/kvm.h | 1 + > > arch/riscv/kvm/main.c | 1 + > > arch/riscv/kvm/vcpu.c | 8 +- > > arch/riscv/kvm/vcpu_onereg.c | 1 + > > arch/riscv/kvm/vcpu_pmu.c | 232 ++++++++++++++++++++++++-- > > arch/riscv/kvm/vcpu_sbi_pmu.c | 10 ++ > > drivers/perf/riscv_pmu.c | 1 + > > drivers/perf/riscv_pmu_sbi.c | 219 ++++++++++++++++++++++-- > > include/linux/perf/riscv_pmu.h | 6 + > > 13 files changed, 478 insertions(+), 35 deletions(-) > > > > -- > > 2.34.1 > >