From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A72BC17BDD; Mon, 15 Jan 2024 16:58:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 855CD2F4; Mon, 15 Jan 2024 08:59:27 -0800 (PST) Received: from [10.57.7.100] (unknown [10.57.7.100]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 25DA93F5A1; Mon, 15 Jan 2024 08:58:38 -0800 (PST) Message-ID: Date: Mon, 15 Jan 2024 16:58:36 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 2/2] cpufreq: add virtual-cpufreq driver Content-Language: en-US To: David Dai , "Rafael J. Wysocki" , Viresh Kumar , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Sudeep Holla , Saravana Kannan Cc: Quentin Perret , Masami Hiramatsu , Will Deacon , Peter Zijlstra , Vincent Guittot , Marc Zyngier , Oliver Upton , Dietmar Eggemann , Pavan Kondeti , Gupta Pankaj , Mel Gorman , kernel-team@android.com, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org References: <20231111014933.1934562-1-davidai@google.com> <20231111014933.1934562-3-davidai@google.com> From: Hongyan Xia In-Reply-To: <20231111014933.1934562-3-davidai@google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 11/11/2023 01:49, David Dai wrote: > [...] > diff --git a/drivers/cpufreq/Makefile b/drivers/cpufreq/Makefile > index 8d141c71b016..eb72ecdc24db 100644 > --- a/drivers/cpufreq/Makefile > +++ b/drivers/cpufreq/Makefile > @@ -16,6 +16,7 @@ obj-$(CONFIG_CPU_FREQ_GOV_ATTR_SET) += cpufreq_governor_attr_set.o > > obj-$(CONFIG_CPUFREQ_DT) += cpufreq-dt.o > obj-$(CONFIG_CPUFREQ_DT_PLATDEV) += cpufreq-dt-platdev.o > +obj-$(CONFIG_CPUFREQ_VIRT) += virtual-cpufreq.o > > # Traces > CFLAGS_amd-pstate-trace.o := -I$(src) > diff --git a/drivers/cpufreq/virtual-cpufreq.c b/drivers/cpufreq/virtual-cpufreq.c > new file mode 100644 > index 000000000000..f828d3345a68 > --- /dev/null > +++ b/drivers/cpufreq/virtual-cpufreq.c > @@ -0,0 +1,201 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +/* > + * Copyright (C) 2023 Google LLC > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define REG_CUR_FREQ_KHZ_OFFSET 0x0 > +#define REG_SET_FREQ_KHZ_OFFSET 0x4 > +#define PER_CPU_OFFSET 0x8 > + > +static void __iomem *base; > + > +static void virt_scale_freq_tick(void) > +{ > + int cpu = smp_processor_id(); > + u32 max_freq = (u32)cpufreq_get_hw_max_freq(cpu); > + u64 cur_freq; > + unsigned long scale; > + > + cur_freq = (u64)readl_relaxed(base + cpu * PER_CPU_OFFSET > + + REG_CUR_FREQ_KHZ_OFFSET); > + > + cur_freq <<= SCHED_CAPACITY_SHIFT; > + scale = (unsigned long)div_u64(cur_freq, max_freq); > + scale = min(scale, SCHED_CAPACITY_SCALE); > + > + this_cpu_write(arch_freq_scale, scale); > +} Here we update the scaling factor in the guest, but is there any way to let the guest know when the host dequeues the vCPU so that the guest PELT signal doesn't appear larger than it actually is? Is this a known limitation and is there a way to mitigate it? > [...]