Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3557277imw; Mon, 18 Jul 2022 10:10:06 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uskXtEh7oyByKfhKRB/zUqFENi1jZrS8oFXPjFXSs4G9n9hTJ4ptn1TmSVsGmLxz/Jdj95 X-Received: by 2002:a17:906:974c:b0:72b:8cea:95c2 with SMTP id o12-20020a170906974c00b0072b8cea95c2mr27072363ejy.65.1658164206599; Mon, 18 Jul 2022 10:10:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658164206; cv=none; d=google.com; s=arc-20160816; b=b0aCihPRO9J7+HvjXVzyegrl2b7nBfqMdWDZn883AGutr8AOdtYRyVaxZ/DxlAVhRI nboQxrHcN1+IdygA1syz7hYtRxDzS8nVzWm+8L7uiS8Foa26mok9m8Z0nWaaEaGB0APD fTCimY3Be6pMHYmtSa9K4p8dB9LbT+PS5G0IyiONG0Ky9IKtYFKeTm1X4zGPuGHMvjDB nhGmh6Ek8ZGh356s7oY3xYkELn9xwssukf7m2gi0kSiHePct2Lft44kuE6AM01t1F/Ag 3AISwKZ+1BSWNQ/9MzbliekRRRDKehgsVFeBsW9/R2Xvu0hKDMv5Q7c6mYQ5wRR5L4Ts KqwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=CGesJ3xfjvEZZZT4415xoctAQUbMYAHu9Vlt5BYorCE=; b=z7rfFfuWwPuIegzEoTm04lplhXb84Z44UpRtyjFIg6JLoSVy2shRuAzkGgAiwgXMj3 7I4vKlKAePhCNVb6gBUTdgL/1TUm23xt6uO58hI0/HD3zra1hlzqp1dT+BvwDHe6opiz Xz/Tk+g7+iN9qNXdgHC0BZ969dJPNZdlEExuLZMcMKLHsMYFAmTTHMAlUe/Bx1MXyGMC /UAW6gDSocBHs+oVBNFYcsGXTOBiSXmSZIVBOlw3lxCu+FkntJXUcVjBKjAPgF3vbsLK kP2P/g3lhP5gVBaCXeZLfF0FjYGg8Tz3Ipjx5M+hqh6xZ3vmsoPcG0ngzRPOiku/sugu XOGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=5JFtYGgl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sd3-20020a1709076e0300b00726d06852besi15087069ejc.148.2022.07.18.10.09.41; Mon, 18 Jul 2022 10:10:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=5JFtYGgl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235692AbiGRRFq (ORCPT + 99 others); Mon, 18 Jul 2022 13:05:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235629AbiGRRFp (ORCPT ); Mon, 18 Jul 2022 13:05:45 -0400 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CC742BB05 for ; Mon, 18 Jul 2022 10:05:44 -0700 (PDT) Received: by mail-pg1-x52d.google.com with SMTP id f11so11136841pgj.7 for ; Mon, 18 Jul 2022 10:05:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=CGesJ3xfjvEZZZT4415xoctAQUbMYAHu9Vlt5BYorCE=; b=5JFtYGglR01I9DhQBYCwoYAMeOZTQ5L8KPmhPGIJtyk5rPeYbL3lmjLJsSbb84p7uH NNS434TKXVpsr10GmlK9T3Z57kMKBnRmYmC3RQ7etjgeeoGxZrfyeK8pexveK+5N1GOx GIe8eJafDVIRnMXuS2j5QcA92rrI0+7uI387VUsYMNRW3zIJedYiPPzwTlk8uH7x0RhM TuDiDsc8jvK3gz191+wq+q6khGXydS2lBedj0NvL1gTMN0vWumOn7hfcv7bAsv7uTHoz AQpvXVxFPnNxDCMIOoNVnf6r+YTqCpUro5bxYrH6KGilcyXIAtvAHifx/QmJpX2/QgKV Id5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=CGesJ3xfjvEZZZT4415xoctAQUbMYAHu9Vlt5BYorCE=; b=jg9XTp+aYfm54ZPM95ksRli1cCuR321AL8/QFY901XzSUF+Emuy9DJWyVsnIrexgEv 09gxCRGU+8XvyebZ1VPn6Lf8KNwAbaFasnqvlUK6sqOyRasLN6cMc4O+OqwAx6/shkwD kgVPRL3ARmoMctOrAJLyWrRwN5Aj+m0gU022ZLWS3+KLsqxdSYqIIxTyglQHFhIb5rIs zPAThKknXwelPCvYZ7fKJeVIgXewqWQjdBVaO26eRCgfmfmo9hE6rv0IeR+uuyku+WMA 0DF6GsvL5DV7DxPALoH1leF/Xidm/b3BOVRGXK8fwO6gPYk7PzZzfHsxJUeK7JSF18QR +T5w== X-Gm-Message-State: AJIora/rZrmXE9w78/p5mIK+PXkEXX+Eh+CRuaKqCwWSOdnD/R+czAO8 D0/6Tv+9zx4QFN5aONCogwQnVuerrzNQfA== X-Received: by 2002:a65:4906:0:b0:40d:dd28:448a with SMTP id p6-20020a654906000000b0040ddd28448amr24126209pgs.567.1658163943502; Mon, 18 Jul 2022 10:05:43 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id r10-20020a170902be0a00b0016bc947c5b7sm9733402pls.38.2022.07.18.10.05.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jul 2022 10:05:42 -0700 (PDT) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Albert Ou , Anup Patel , Atish Patra , Guo Ren , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Palmer Dabbelt , Paul Walmsley , Will Deacon Subject: [RFC 0/9] KVM perf support Date: Mon, 18 Jul 2022 10:01:56 -0700 Message-Id: <20220718170205.2972215-1-atishp@rivosinc.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This series extends perf support for KVM. The KVM implementation relies on the SBI PMU extension and trap n emulation of hpmcounter CSRs. The KVM implementation exposes the virtual counters to the guest and internally manage the counters using kernel perf counters. This series doesn't support the counter overflow as the Sscofpmf extension doesn't allow trap & emulation mechanism of scountovf CSR yet. The required changes to allow that are being under discussions. Supporting overflow interrupt also requires AIA support which is not frozen either. This series can be found at github[1] as well. It depends Anup's CSR emulation framework[1] series. perf stat works in kvm guests with this series. Here is example of running perf stat in a guest running in KVM. =========================================================================== / # /host/apps/perf stat -e instructions -e cycles -e r8000000000000005 \ > -e r8000000000000006 -e r8000000000000007 -e r8000000000000008 \ > -e r800000000000000a perf bench sched messaging -g 5 -l 15 # Running 'sched/messaging' benchmark: # 20 sender and receiver processes per group # 5 groups == 200 processes run Total time: 5.210 [sec] Performance counter stats for 'perf bench sched messaging -g 5 -l 15': 37209585734 instructions # 1.00 insn per cycle 37177435570 cycles 2740 r8000000000000005 3727 r8000000000000006 3655 r8000000000000007 10 r8000000000000008 0 r800000000000000a 5.863014800 seconds time elapsed 0.569373000 seconds user 10.771533000 seconds sys [1] https://github.com/atishp04/linux/tree/kvm_perf_rfc [2] https://lkml.org/lkml/2022/6/15/389 Atish Patra (9): RISC-V: Define a helper function to probe number of hardware counters RISC-V: Define a helper function to return counter width RISC-V: KVM: Define a probe function for SBI extension data structures RISC-V: KVM: Improve privilege mode filtering for perf RISC-V: KVM: Add skeleton support for perf RISC-V: KVM: Add SBI PMU extension support RISC-V: KVM: Implement trap & emulate for hpmcounters RISC-V: KVM: Implement perf support RISC-V: KVM: Implement firmware events arch/riscv/include/asm/kvm_host.h | 3 + arch/riscv/include/asm/kvm_vcpu_pmu.h | 102 +++++ arch/riscv/include/asm/kvm_vcpu_sbi.h | 3 + arch/riscv/include/asm/sbi.h | 2 +- arch/riscv/kvm/Makefile | 1 + arch/riscv/kvm/main.c | 3 +- arch/riscv/kvm/tlb.c | 6 +- arch/riscv/kvm/vcpu.c | 5 + arch/riscv/kvm/vcpu_insn.c | 4 +- arch/riscv/kvm/vcpu_pmu.c | 517 ++++++++++++++++++++++++++ arch/riscv/kvm/vcpu_sbi.c | 11 + arch/riscv/kvm/vcpu_sbi_base.c | 13 +- arch/riscv/kvm/vcpu_sbi_pmu.c | 81 ++++ arch/riscv/kvm/vcpu_sbi_replace.c | 7 + drivers/perf/riscv_pmu_sbi.c | 75 +++- include/linux/perf/riscv_pmu.h | 7 + 16 files changed, 823 insertions(+), 17 deletions(-) create mode 100644 arch/riscv/include/asm/kvm_vcpu_pmu.h create mode 100644 arch/riscv/kvm/vcpu_pmu.c create mode 100644 arch/riscv/kvm/vcpu_sbi_pmu.c -- 2.25.1