Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp1037466lqd; Thu, 25 Apr 2024 04:27:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWOP2SOnrpsuCYsx4ywJpgLIrf8fNX7N2mLWAUwzwVyDpPU3g5nWH7FGzW4DEbRwExFnG3lbz1MV/Ol34YgO+7CoMqC4X1uT/1gNcg90g== X-Google-Smtp-Source: AGHT+IG3DMNCXwGoQ5rYc7SyWkjNmVR9f/V39aHRiqVD9tm4qsy1QX3iRyWE1trytuh8pr3PwEM+ X-Received: by 2002:a50:d559:0:b0:568:8e22:4eff with SMTP id f25-20020a50d559000000b005688e224effmr3552769edj.37.1714044457310; Thu, 25 Apr 2024 04:27:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714044457; cv=pass; d=google.com; s=arc-20160816; b=hWNjankoAWXaASNGv9gtxpGQI6CWqQRcQRiF8c4MJGUNl/CbbaZ6R8cQzJ5/HCA8bS NXR5FySrT1w4O8AMna9Hagz+R3/a4De9WEQORvvRO4zKILGo18NB4OJ3RYCWoyvYsIz5 PyzB4LozROkXZURgV8UrMyW8zO8NE8S8FSVicFYitQ0kCx83mbDfmPumCGRX/uoa4zVo J3mIc6kZ2Rzs1jIvLntYjCHuwbEwy2IRDrM/yBiuMcfHASrDRy8ncm0THEAb6AhIptv7 RezsJvdHvLNbR/VHzub8Ic7FmAs/f572zT51pexpqF6k4Vh/DRpdbkJigl20d4AJ0KHy i7mg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=mxk2ne5hBdd7XprOHJCbm6CDJjWyjIChRrZSVoU76NU=; fh=7860an1VTW+vtjcv/V5SVxIxos/4vvGLAQEVi0DfjYY=; b=Dejov1365Nmo+i4Ai33tTKja8NK8CUxZBZcKCGQd2ogzfGAiFBwxy66CXMAHreEvrY 4eB6354lYYBBYEe/tePj+j2HRKuUTE1mB6Zb7oFWATnT6w5QcUyonkraFZOYmGpDUAgE eh1lisIML93HkAPnQhC2+EnT5w7lAEu3APrzJluV9euSkJfZxBp9p277+XKGcZQYvgtJ nz2AFfijXt1F0BxFQmXXJUq8Mib87g2wNbbaU7dXwe0fAu0vVpyl6XX52diDFIa66VXp Eezl7nNg0xELOv6p/zdAuxs5crLqpYsrZMvUxKB6GYIOHxkg7wc3wxRsYYSqRaJ59mxD PlTQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mRKJ93uq; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-158442-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158442-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id h22-20020a50cdd6000000b005701ea8d567si9365783edj.654.2024.04.25.04.27.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 04:27:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-158442-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mRKJ93uq; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-158442-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158442-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 am.mirrors.kernel.org (Postfix) with ESMTPS id 0A0191F22BC6 for ; Thu, 25 Apr 2024 11:27:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CE99212AAC7; Thu, 25 Apr 2024 11:27:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mRKJ93uq" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 011041DDCE; Thu, 25 Apr 2024 11:27:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714044446; cv=none; b=IKxpBP2L4JGfNXdxt9FGDUmKuyZ+rNykog+Qcdgtdk0miS/Jf2kthpZQv2ipsZnVx4LAm6qT7lDzWOwCOx+qR06Ttj7N1d/zjwqrSdEdeWTkmMtMaNi2Wmzn3koKzZY2Kvwa3wUnQ5Ma41Pzq64kfZLnploqmO5G0y2vwuKiC1s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714044446; c=relaxed/simple; bh=/xag3OkcGEyfkLOWbreP2qxcC/ujNSwQZVNR+WIcJbw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nWyj+P8h54o5JWwx2XYN4Z/FQCrwpUlYr+z78WJbh1XifDvlBwkWIWlu4m1p2OZuGCNPXX4BqTzYh2W6oSa8TdkxJrx+uzkAddPnuwM0jSx9Qpu9+7dqGyAUGuZu+6at1oAOTaAqwYgF2MlFJlXDtkX6pcDXw4l3QvkZDfpYuok= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mRKJ93uq; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 872C5C113CC; Thu, 25 Apr 2024 11:27:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714044445; bh=/xag3OkcGEyfkLOWbreP2qxcC/ujNSwQZVNR+WIcJbw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=mRKJ93uqcY3f24wDK0kXzBjcPBV39G7QObjuc4CmkQfRv5R+mMpJ1b6/J6H5u2HIm t3h5+32yZNa9AnoOJhEsPXOxE743fBO/ZLvaD3SlDtF8Xs+uMfOxHE4vQafUCmrTeS RauCHvdPX8zvNEuF1uoAtnZsVbEL6F3JQU4ITMpZeHMVpsbaStweISAUZ6NSPwqYK1 Bznvw3m7I67nKaMSLncnqLg+qkh3IpEMtvfeKnmZfr3+eXQJE4Y4h22qAAkj/prqE7 l7Z0jthgvYfF/3lWJ+ZN1Mj9l+O5eeFJL9TnW2NlZSe49x5nzyjc40EKQCg+px2KUW 1T6j/jrkd3wfw== Date: Thu, 25 Apr 2024 16:47:58 +0530 From: Naveen N Rao To: Gautam Menghani Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, aneesh.kumar@kernel.org, npiggin@gmail.com, Vaibhav Jain , linuxppc-dev@lists.ozlabs.org Subject: Re: [PATCH v5 RESEND] arch/powerpc/kvm: Add support for reading VPA counters for pseries guests Message-ID: References: <20240402070656.28441-1-gautam@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Wed, Apr 24, 2024 at 11:08:38AM +0530, Gautam Menghani wrote: > On Mon, Apr 22, 2024 at 09:15:02PM +0530, Naveen N Rao wrote: > > On Tue, Apr 02, 2024 at 12:36:54PM +0530, Gautam Menghani wrote: > > > static int kvmhv_vcpu_entry_nestedv2(struct kvm_vcpu *vcpu, u64 > > > time_limit, > > > unsigned long lpcr, u64 *tb) > > > { > > > @@ -4130,6 +4161,11 @@ static int kvmhv_vcpu_entry_nestedv2(struct kvm_vcpu *vcpu, u64 time_limit, > > > kvmppc_gse_put_u64(io->vcpu_run_input, KVMPPC_GSID_LPCR, lpcr); > > > > > > accumulate_time(vcpu, &vcpu->arch.in_guest); > > > + > > > + /* Enable the guest host context switch time tracking */ > > > + if (unlikely(trace_kvmppc_vcpu_exit_cs_time_enabled())) > > > + kvmhv_set_l2_accumul(1); > > > + > > > rc = plpar_guest_run_vcpu(0, vcpu->kvm->arch.lpid, vcpu->vcpu_id, > > > &trap, &i); > > > > > > @@ -4156,6 +4192,10 @@ static int kvmhv_vcpu_entry_nestedv2(struct kvm_vcpu *vcpu, u64 time_limit, > > > > > > timer_rearm_host_dec(*tb); > > > > > > + /* Record context switch and guest_run_time data */ > > > + if (kvmhv_get_l2_accumul()) > > > + do_trace_nested_cs_time(vcpu); > > > + > > > return trap; > > > } > > > > I'm assuming the counters in VPA are cumulative, since you are zero'ing > > them out on exit. If so, I think a better way to implement this is to > > use TRACE_EVENT_FN() and provide tracepoint registration and > > unregistration functions. You can then enable the counters once during > > registration and avoid repeated writes to the VPA area. With that, you > > also won't need to do anything before vcpu entry. If you maintain > > previous values, you can calculate the delta and emit the trace on vcpu > > exit. The values in VPA area can then serve as the cumulative values. > > > > This approach will have a problem. The context switch times are reported > in the L1 LPAR's CPU's VPA area. Consider the following scenario: > > 1. L1 has 2 cpus, and L2 has 1 cpu > 2. L2 runs on L1's cpu0 for a few seconds, and the counter values go to > 1 million > 3. We are maintaining a copy of values of VPA in separate variables, so > those variables also have 1 million. > 4. Now if L2's vcpu is migrated to another L1 cpu, that L1 cpu's VPA > counters will start from 0, so if we try to get delta value, we will end > up doing 0 - 1 million, which would be wrong. I'm assuming you mean migrating the task. If we maintain the previous readings in paca, it should work I think. > > The aggregation logic in this patch works as we zero out the VPA after > every switch, and maintain aggregation in a vcpu->arch Are the cumulative values of the VPA counters of no significance? We lose those with this approach. Not sure if we care. - Naveen