Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp132692lqd; Tue, 23 Apr 2024 18:07:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU9JlWp4Y4FcBIK+lB7hjA6iLXSJrXbc1XlWusjz98yr5TRBlMrh6B3kFyUJqklOaC560/80llZIhXM5ZwJN1e/A0DB64M7/6aSnWAIAw== X-Google-Smtp-Source: AGHT+IFT3IntFbwIxhtXPGJkF3e6W1jSfKJkSRQ/2T62FD0amrrrbNf7toA3QFVWYvrZzUkQTRHx X-Received: by 2002:a0c:f906:0:b0:6a0:943d:6be with SMTP id v6-20020a0cf906000000b006a0943d06bemr559487qvn.1.1713920840541; Tue, 23 Apr 2024 18:07:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713920840; cv=pass; d=google.com; s=arc-20160816; b=EYCZFUH4KYF6/z/WWXVUGxbFvkGsLV65oU4eUn+J8kXPhlGwuyDrUFX74wnm/D7PP2 ajn4W4DZr0Ju9duhW381+BlJujQQk10nMusk6tYCaoGDzOq9w5y7rCQErTw6j1lzq2O+ IMBQjdn3Zx/7Gvgf7+YAHSSTps0nQLCJkvpMrjbQ8/pkodZKmeHVUesGOuxJItWp4Wgu ou2pPFhVJuMbkV4XhgOZWnwymwPCCEz8+Kn+7KY+U18rbPEbJem31mvkLfBI4WTuwsmL fhUvKXmGzXN+Ks+TYvhc5kkX/bSuAxVKzQWhp+CDMnR1yViQFfWb/F3GLsD40lWcfFoC A0fQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-language:in-reply-to:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:user-agent:date :message-id:from:references:cc:to:subject; bh=7KQsulS1PP0hy6ee+JfMo4APm8akMmXLRJGQx2vyDPY=; fh=++pvY+JnPYsLrsRvkRkFbn1M6MOWiRKt8Eu9j3Zxck8=; b=iML+OgGNfj1HM391GCaIT5w+JzXrlxT9JT9+uXa2ksPIgDGoRdVp1v75veAMLJtUuv vMSZ9iCCGd22x0LXlWfYW2DKlx9cgoTJ/kaX1PnzPqM+kgjB3tdDd7zeDqVEXNLSLS2P GlDFpXZdKHWBLULEXPeuV1KUVvehU+QRQWS9ND3s5ZbJAxC/xgNUI97Cvk8pY/zBD05C WjFOOzq/A+4fCbYDgC+dh2juq2AnSvV80pbtLMyV9Kz+0ehvMp5N3RfPhvL9IqTIzJLU Id2vZhjlBQNQNX1E/nbnwBxi5xchQFxHm1M4B6iarK8z121WTYwAVfO06nBlWvqJnL/P jskQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=loongson.cn); spf=pass (google.com: domain of linux-kernel+bounces-156073-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-156073-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id jv15-20020a05621429ef00b0069eb725bf87si13951922qvb.158.2024.04.23.18.07.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 18:07:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-156073-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=loongson.cn); spf=pass (google.com: domain of linux-kernel+bounces-156073-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-156073-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 48B731C223AD for ; Wed, 24 Apr 2024 01:07:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E846D568A; Wed, 24 Apr 2024 01:07:11 +0000 (UTC) Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D572F4405; Wed, 24 Apr 2024 01:07:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.242.206.163 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713920831; cv=none; b=Lmu2eDHs7veRuUbqD0ag+kTR33XgaupjYXpa6W1ca0Xz47G/ffk+aSTui3fqxFcqMANWcJAysQ2zgB+faQYVUrgjc2Yt2OyaAoDgYXvgOrYWZqgaVuTGM7eoLHx6BZEVRMxAP4rqdhU3bng5Mefb+Bg+Zlw0FhhyfCSTA43+9WM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713920831; c=relaxed/simple; bh=XfXXMQt8Cl+rmsVBbFAJBYBZoxRvVkARuTYt10dpAPI=; h=Subject:To:Cc:References:From:Message-ID:Date:MIME-Version: In-Reply-To:Content-Type; b=BKZqkqPnEwNGujFqBy9uk4qJfFKioEQTbDGkz4f3sA5LfDyIuqOAerpzpCR1pP0qtkjfgV3G+Erlrd31ryI3imUZTihucyi42xvJhWNYyqftJBGISn0EXbnsifqgXoYysofoskWt9g2AsuKnnESy+tN4BsXUnPLGdLVO3kSIQNQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn; spf=pass smtp.mailfrom=loongson.cn; arc=none smtp.client-ip=114.242.206.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [10.20.42.173]) by gateway (Coremail) with SMTP id _____8BxmPA4Wyhm37EBAA--.9705S3; Wed, 24 Apr 2024 09:07:04 +0800 (CST) Received: from [10.20.42.173] (unknown [10.20.42.173]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Cxjd41Wyhm_tkCAA--.12211S3; Wed, 24 Apr 2024 09:07:04 +0800 (CST) Subject: Re: [RFC PATCH 23/41] KVM: x86/pmu: Implement the save/restore of PMU state for Intel CPU To: Mingwei Zhang Cc: "Mi, Dapeng" , Sean Christopherson , Xiong Zhang , pbonzini@redhat.com, peterz@infradead.org, kan.liang@intel.com, zhenyuw@linux.intel.com, jmattson@google.com, kvm@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, zhiyuan.lv@intel.com, eranian@google.com, irogers@google.com, samantha.alt@intel.com, like.xu.linux@gmail.com, chao.gao@intel.com References: <18b19dd4-6d76-4ed8-b784-32436ab93d06@linux.intel.com> <4c47b975-ad30-4be9-a0a9-f0989d1fa395@linux.intel.com> <737f0c66-2237-4ed3-8999-19fe9cca9ecc@linux.intel.com> <4d60384a-11e0-2f2b-a568-517b40c91b25@loongson.cn> <1ec7a21c-71d0-4f3e-9fa3-3de8ca0f7315@linux.intel.com> <5279eabc-ca46-ee1b-b80d-9a511ba90a36@loongson.cn> From: maobibo Message-ID: Date: Wed, 24 Apr 2024 09:07:01 +0800 User-Agent: Mozilla/5.0 (X11; Linux loongarch64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-CM-TRANSID:AQAAf8Cxjd41Wyhm_tkCAA--.12211S3 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBj93XoW7WF4xZw1UAw18Jr15AF4rCrX_yoW8XFyxpF WjqFyrur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JrUvcSsGvfC2KfnxnUUI43ZEXa7IU8qXdUUUUU U== On 2024/4/24 上午1:02, Mingwei Zhang wrote: >>> >>> Maybe, (just maybe), it is possible to do PMU context switch at vcpu >>> boundary normally, but doing it at VM Enter/Exit boundary when host is >>> profiling KVM kernel module. So, dynamically adjusting PMU context >>> switch location could be an option. >> If there are two VMs with pmu enabled both, however host PMU is not >> enabled. PMU context switch should be done in vcpu thread sched-out path. >> >> If host pmu is used also, we can choose whether PMU switch should be >> done in vm exit path or vcpu thread sched-out path. >> > > host PMU is always enabled, ie., Linux currently does not support KVM > PMU running standalone. I guess what you mean is there are no active > perf_events on the host side. Allowing a PMU context switch drifting > from vm-enter/exit boundary to vcpu loop boundary by checking host > side events might be a good option. We can keep the discussion, but I > won't propose that in v2. > > I guess we are off topic. Sean's suggestion is that we should put > "perf" and "kvm" together while doing the context switch. I think this > is quite reasonable regardless of the PMU context switch location. > > To execute this, I am thinking about adding a parameter or return > value to perf_guest_enter() so that once it returns back to KVM, KVM > gets to know which counters are active/inactive/cleared from the host > side. Knowing that, KVM can do the context switch more efficiently. yeap, that sounds great. Regards Bibo Mao > > Thanks. > -Mingwei >