Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp3104140lqt; Tue, 23 Apr 2024 10:20:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV2vSB/plLJ3/4CVAxAn5oq4tNuqUHY7oNre2Syx5YD3GCDQs73qRSkCUZkYgzjrYvj6kZeVEBCqSEtp5JlVMMDJV4hhrDF1B52pgxuIw== X-Google-Smtp-Source: AGHT+IHtNzMFcqCAeGw182k7iMGlvVx+hU5MO/42aKCmuRR8HrCEKlIrvztOiZ2KkZ1JBGAxDR0h X-Received: by 2002:a17:90a:ee82:b0:2ac:7bd6:cc6a with SMTP id i2-20020a17090aee8200b002ac7bd6cc6amr203132pjz.0.1713892816505; Tue, 23 Apr 2024 10:20:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713892816; cv=pass; d=google.com; s=arc-20160816; b=NNDk7YyW4Bpg1gLSdHM9A4fY7ieLk4FYPudta9uR2pBhDx4OJcXH2Or7juuWgD4QCu I432r9OsUk2yUKxPivKa/8ODmoNn/pPzf/aN+y2uA4wuvVlsv4erO2I95MtSYMm0EyBD pmArliR18hDAv0eXO4aWYUgpQql1QuhrJg3iW+Fc5UTQ6JPBvJl2pyh44AjxZhoNSOnW PzdDN4EvStOUQuGw7BdJLEgLoXQKfoD/d9vrmoHar15B9sR1BGrjezcQKY3saspK8Fpo KsCndfIG0jPaiyKrqtcu90JOVWttPS5FE9PMJcjuwH5eQslhn8dvg/r7argqR0gJECQa wmqQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=o9xoixdzamHVwV+JAQwhz22rzk+JkW3wBRWHkz/cgYY=; fh=Gp6CMd7n6QNzproTJPOnBvVuj/QXFYNtIf+VX1SXMaY=; b=XOpXsCJ10wmwppOKsUOTtBGvT2zc4/Y/9o/sxcCU8hzrLEqXSf9BEtK1SqJilb3ISc e5ZqN2b8YCu9xN3cn2S/i4zUtKUzQKWzyQ5yDQROlnb6fs3sK9lukx8vtLkRANY+sziy m6qyslAJCHkU+kcl8NSZw55E7tHwPQHoGMyUPpT6xvI7Z9vZSvJdqqr5SyimWrKajxwr d0ue+Oysort3Kr9nVcLQfkqpFNjfIVmo77+HBonGQ324F2sLPZ7XlQGLJguhRLRRhk1J /DsIovQB18/79GdveHuR2oaz8mykwXhDSUdqLMjQed35XYh3Vqr8xz4PGqADn3/e+I5L q8DA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="F9A9Z/82"; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-155617-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-155617-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id na5-20020a17090b4c0500b002ae3d9b7f97si2994712pjb.32.2024.04.23.10.20.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 10:20:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-155617-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="F9A9Z/82"; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-155617-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-155617-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id C5F32B241E7 for ; Tue, 23 Apr 2024 17:03:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6B84F13DBAC; Tue, 23 Apr 2024 17:03:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="F9A9Z/82" Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (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 1D5E613D625 for ; Tue, 23 Apr 2024 17:03:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713891816; cv=none; b=ROba/UjsQ/+gKnT5j1PjZIiK/iDTrIJoIhoqerStGnzdeiKgs9nRAN0P3x2e+BTP6lL+pYWEzY0a/5FzxP0Ny49I6nD7xp3h+evm/ll4iWNCDpueEAk/1/xXuiKp2YjBcRc+Tz65S4QH8fzac4OGgap4m4KRjY56puWHd9eKWnQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713891816; c=relaxed/simple; bh=o9xoixdzamHVwV+JAQwhz22rzk+JkW3wBRWHkz/cgYY=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=DBRroVd9rp6ZKMrzlQzRlPDInROUu5w13y8i6/svRUv6EIxwaf0KrZK+xBSGY4RPZwAwy9XkK5e6eJw3sn6DgbYc0M69giXGQ1bdelr5XwPIe/9CnSe4meGLB4pyoFpPFvZwU1xT8NDehSz38LAeOOBbGGlqkPQs3K7No53oU9g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=F9A9Z/82; arc=none smtp.client-ip=209.85.221.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-3499f1bed15so28474f8f.1 for ; Tue, 23 Apr 2024 10:03:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713891813; x=1714496613; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=o9xoixdzamHVwV+JAQwhz22rzk+JkW3wBRWHkz/cgYY=; b=F9A9Z/82E+grWEq1Nbf+8OMZjwQPTDJz/AYZNtK+RcIGQn5NWlKChbu/dP+1y0MDCA 09n1XTTjTKQHJ7XWfhG0MQN2HcCXwZZVtudRzNUQ/VWrBLoIMGY3n9sCYTZ+/HoBf9t7 NsZbJcaD9ze4giTdDqgikcFjMZxAOXRvtcsNb81WEQJO/3dipBhwTOh0jBTMK/hj6lBH A6Ipe9F2hBtepfYsG5MCoCjSRONxPkTz5eeT7QTC1RyyGtCigStC2wMcnw4gnxm6KJuf oV5nOXK1TpSf/7svQ5y3cpA5ZD2H4N9qPfAUNv5+FDX13IWLbUIn+rx52FBIJm1TRvpg kOYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713891813; x=1714496613; h=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=o9xoixdzamHVwV+JAQwhz22rzk+JkW3wBRWHkz/cgYY=; b=TXqPip4XY7QqJKuZzF1HwYVCbVhGejjNZYkM0ES+/35IojyDhbUmTQPfiovDj+YhvZ wfUCUwPlyZCvoSxuvcu8Kfjx8lBUG76kgmVQ5jwRuKJh5qPXyazHyCaepJgTrQB3IjsQ LK6tznd78PrkGcD0O/wTfu9C1G1ghWRKxUDzMuwVZDjnmW/ZE0CLkTRkBbn1DSuHz0U3 +oOv2V9m4fUl1/VL/eS2OZp0otytw7s+B/xMFxNFHbOWAJt1j3n1rxfYWM418cMAb8w6 RLXgFGtrxApgdaF+woDboz9nTL6rbUOOdLiKKTOYK4ZY8dubkMiKuI0WYGnXlYIxX8/8 0KnA== X-Forwarded-Encrypted: i=1; AJvYcCX+a3ROMBiuFAeJ5RDdc03bjdxgdnphuy8xVLyuUcaWe7GKZvoiaboKmFstfEqxzxpDCuFZR01A543JAUuYaeZuag3IbnxLCDcgTpnd X-Gm-Message-State: AOJu0YwrMZ7RgiZLF0714GJt27In9i4rHkFC5z6pKLwW7KWQEuJBr4Sk lb3KE1p2pqucsjZikLOvGqAn7TIbLsnW3jIbexzFEzc0/OVAw2/HWG0k4l2KzgVh7G6Z7JzXVDO h4KbLm9gSrxotbev50ivjk6sziCm2dXISm/Il X-Received: by 2002:a5d:5188:0:b0:34b:3e51:fe38 with SMTP id k8-20020a5d5188000000b0034b3e51fe38mr33455wrv.23.1713891813220; Tue, 23 Apr 2024 10:03:33 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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> In-Reply-To: From: Mingwei Zhang Date: Tue, 23 Apr 2024 10:02:55 -0700 Message-ID: Subject: Re: [RFC PATCH 23/41] KVM: x86/pmu: Implement the save/restore of PMU state for Intel CPU To: maobibo 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 Content-Type: text/plain; charset="UTF-8" > > > > 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. Thanks. -Mingwei