Message ID | 20230127182558.2416400-1-atishp@rivosinc.com |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp980356wrn; Fri, 27 Jan 2023 10:28:02 -0800 (PST) X-Google-Smtp-Source: AK7set915k9GZ1RlUCVdSN77Zk2/GZtpruGYuhSCvA5z0r58skEh1D+yWh5HZxkblbb3MKTG1Bdi X-Received: by 2002:a05:6a20:8415:b0:bc:33b1:bfda with SMTP id c21-20020a056a20841500b000bc33b1bfdamr4598129pzd.1.1674844081902; Fri, 27 Jan 2023 10:28:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674844081; cv=none; d=google.com; s=arc-20160816; b=yxxlFP5LXt73LMyg9six81Q17Khc5y9YM2OkBhqpwhfgrdGb7H/o3I5hnTWupBYEwz 1hxSFGtoOxQI50uiL3WWVQiB6eMm0fsMCCZdHpQhiw5CdNYVg7QrxIHSQ5x1Djfuu1gs IJ/wn9QPTNxcLE+pdZNo471JuSMrElxrt5OU3oNZYb31/kFegOobTayD1S3Ty4ZiJAcJ DCW0REDoHbe7NoV8eHs5LqICCrnI0YQh9rkJFfS70X7jKg2lpQJdNTVJ4caUcom6RSS9 4VSn5mQ9GRWXe39sTax84FoyY7YRVB2cMtYWRokcthu8WjWLXBcniyNa65AwOFvtSt7Z 7tOA== 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=zsftkojp5OXA0h6KtHV2q16vdLIZZMWoH0UyNcPXsv0=; b=Qj7KRh4m7LBKmfIkv44B0x9oRvUn0N2+ZL9T0HLoxKmIFgGHTfARy2CIvYj6LKhaBA JAeG/gFMCpDv29xcTbCyV+ljeFWejBK+/zsoUDzeZXJsonm8AmTbYJWxIufjhDInC5GO 035P8AVEiUNISVvvfbM88P4RUGipWY3gsIv/JmKCPrNp8zwsLUjLTD5pwsy2TjQrqSWm Pux92teTWGv1083hPha72JNaWoOuwsy9aqzAkyue+6tU84SdwrtlOhgNeJtWZWZDJKBB 65bnM/1GhTsFpIbcDyg9JjahZ5B7ABfWNfkos327u8CbD454cmikHJKfs056giiCljdl 5M9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=tsBPO9VA; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g8-20020a056a0023c800b00589c467f33fsi6125776pfc.55.2023.01.27.10.27.36; Fri, 27 Jan 2023 10:28:01 -0800 (PST) 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=tsBPO9VA; 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 S235240AbjA0S0R (ORCPT <rfc822;lekhanya01809@gmail.com> + 99 others); Fri, 27 Jan 2023 13:26:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232940AbjA0S0Q (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 27 Jan 2023 13:26:16 -0500 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79EF97BBC8 for <linux-kernel@vger.kernel.org>; Fri, 27 Jan 2023 10:26:14 -0800 (PST) Received: by mail-pj1-x102e.google.com with SMTP id z1-20020a17090a66c100b00226f05b9595so5562991pjl.0 for <linux-kernel@vger.kernel.org>; Fri, 27 Jan 2023 10:26:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=zsftkojp5OXA0h6KtHV2q16vdLIZZMWoH0UyNcPXsv0=; b=tsBPO9VAaqsZisDSonZd6v6hy07NN4UbbIBWkgD0TSZIq1Joh7A9ADhF9Jl7mk6CK/ 0n/usPnqbrZQpvKHTk3GCZkIdNWIoK70ZiucBN5PGZiXNkp7BinDUg0Ml81xbycIfbng uL5lEvnVlxiXPddALd9L9yMrF+EztuZJPeC0YseiJr91O4qdBOCCBOs7uWRl8LUnOJzF yw3rgSEWO9YEltz6i00/h3UP37QhnncYlVD/mtDiCbrPccZ8qqft/ZQZYuUuNmpRldQN xkvgMptsr2EBcIh4RcustE/+CjnrgGL07Dmt+aDPX6TluPxfvl6JqG9Tr1kNxpJR+hWb RpTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=zsftkojp5OXA0h6KtHV2q16vdLIZZMWoH0UyNcPXsv0=; b=6vI2AVJ+wnQNtea9BHtIHDAqWZm0fTv1mxN68kOnc3gaP6UNzv/2LWV2/aswY/5BKb sEWNIRMir5nafYN02oIPiBxIpkm//Vi5h4+sOkmXjzcXlhMwJJSokznXzauzHl+JaXTF BwAoY3vIZdLPg7RccDP3Q6EONBfgpq80m//tYyIjdly6m8ioSiY6EOS+193F2/nbUvot chv2x8uWajEGnk2iT9tbd8SjXCV38Fh0Upedfe/PxUsmQMBU8C2qb+9tpLfTGwn2J7Mh 9QJeyV8U9VKQXRoC83PrZi7wqcsZqbDAKemilXzuMqcKO8GSDNZXumxdEKETKosFp+sZ x/aw== X-Gm-Message-State: AFqh2kp5SMscEU3nTIu8UY4m3Kyk+8C76oXdA/gzL5hQlYYOxM7fwqTq h4fNLO8hl5hSr1C1KT0IzvoGD0FGlWJucSyY X-Received: by 2002:a17:902:e882:b0:195:e9d4:5380 with SMTP id w2-20020a170902e88200b00195e9d45380mr32563156plg.56.1674843973701; Fri, 27 Jan 2023 10:26:13 -0800 (PST) Received: from atishp.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id jc5-20020a17090325c500b00189d4c666c8sm3195219plb.153.2023.01.27.10.26.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 10:26:13 -0800 (PST) From: Atish Patra <atishp@rivosinc.com> To: linux-kernel@vger.kernel.org Cc: Atish Patra <atishp@rivosinc.com>, Andrew Jones <ajones@ventanamicro.com>, Anup Patel <anup@brainfault.org>, Atish Patra <atishp@atishpatra.org>, Guo Ren <guoren@kernel.org>, Heiko Stuebner <heiko@sntech.de>, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland <mark.rutland@arm.com>, Palmer Dabbelt <palmer@dabbelt.com>, Paul Walmsley <paul.walmsley@sifive.com>, Sergey Matyukevich <sergey.matyukevich@syntacore.com>, Will Deacon <will@kernel.org> Subject: [PATCH v3 00/14] KVM perf support Date: Fri, 27 Jan 2023 10:25:44 -0800 Message-Id: <20230127182558.2416400-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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756201307886134731?= X-GMAIL-MSGID: =?utf-8?q?1756201307886134731?= |
Series |
KVM perf support
|
|
Message
Atish Patra
Jan. 27, 2023, 6:25 p.m. UTC
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 interrupt filtering support. 1. PATCH 1-5 are generic KVM/PMU driver improvements. 2. PATCH 9 disables hpmcounter for now. It will be enabled to maintain ABI requirement once the ONE reg interface is settled. 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 10 -l 10 # Running 'sched/messaging' benchmark: # 20 sender and receiver processes per group # 10 groups == 400 processes run Total time: 7.769 [sec] Performance counter stats for 'perf bench sched messaging -g 10 -l 10': 73556259604 cycles 73387266056 instructions # 1.00 insn per cycle 0 dTLB-store-misses 0 iTLB-load-misses 0 r8000000000000005 2595 r8000000000000006 2272 r8000000000000007 10 r8000000000000008 0 r800000000000000a 12.173720400 seconds time elapsed 1.002716000 seconds user 21.931047000 seconds sys Note: The SBI_PMU_FW_SET_TIMER (eventid : r8000000000000005) is zero as kvm guest supports sstc now. This series can be found here as well. https://github.com/atishp04/linux/tree/kvm_perf_v3 TODO: 1. Add sscofpmf support. 2. Add One reg interface for the following operations: 1. Enable/Disable PMU (should it at VM level rather than vcpu ?) 2. Number of hpmcounter and width of the counters 3. Init PMU 4. Allow guest user to access cycle & instret without trapping Changes v2->v3: 1. Changed the exported functions to GPL only export. 2. Addressed all the nit comments on v2. 3. Split non-kvm related changes into separate patches. 4. Reorgainze the PATCH 11 and 10 based on Drew's suggestions. Changes from v1->v2: 1. Addressed comments from Andrew. 2. Removed kvpmu sanity check. 3. Added a kvm pmu init flag and the sanity check to probe function. 4. Improved the linux vs sbi error code handling. Atish Patra (14): perf: RISC-V: Define helper functions expose hpm counter width and count perf: RISC-V: Improve privilege mode filtering for perf RISC-V: Improve SBI PMU extension related definitions RISC-V: KVM: Define a probe function for SBI extension data structures RISC-V: KVM: Return correct code for hsm stop function RISC-V: KVM: Modify SBI extension handler to return SBI error code RISC-V: KVM: Add skeleton support for perf RISC-V: KVM: Add SBI PMU extension support RISC-V: KVM: Make PMU functionality depend on Sscofpmf RISC-V: KVM: Disable all hpmcounter access for VS/VU mode RISC-V: KVM: Implement trap & emulate for hpmcounters RISC-V: KVM: Implement perf support without sampling RISC-V: KVM: Support firmware events RISC-V: KVM: Increment firmware pmu events arch/riscv/include/asm/kvm_host.h | 3 + arch/riscv/include/asm/kvm_vcpu_pmu.h | 108 +++++ arch/riscv/include/asm/kvm_vcpu_sbi.h | 13 +- arch/riscv/include/asm/sbi.h | 5 +- arch/riscv/kvm/Makefile | 1 + arch/riscv/kvm/main.c | 3 +- arch/riscv/kvm/tlb.c | 4 + arch/riscv/kvm/vcpu.c | 5 + arch/riscv/kvm/vcpu_insn.c | 4 +- arch/riscv/kvm/vcpu_pmu.c | 622 ++++++++++++++++++++++++++ arch/riscv/kvm/vcpu_sbi.c | 57 ++- arch/riscv/kvm/vcpu_sbi_base.c | 45 +- arch/riscv/kvm/vcpu_sbi_hsm.c | 29 +- arch/riscv/kvm/vcpu_sbi_pmu.c | 86 ++++ arch/riscv/kvm/vcpu_sbi_replace.c | 54 ++- arch/riscv/kvm/vcpu_sbi_v01.c | 11 +- drivers/perf/riscv_pmu_sbi.c | 64 ++- include/linux/perf/riscv_pmu.h | 5 + 18 files changed, 1013 insertions(+), 106 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