Received: by 2002:a05:7412:8d11:b0:fa:4934:9f with SMTP id bj17csp648129rdb; Mon, 15 Jan 2024 08:58:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IFx5+VejgFxuFpVRW2y1FAzsT5XKx6alE3L8EQOop/M5d+Ku0tX1onnjB0m5MgmsO/AeEhA X-Received: by 2002:a05:600c:2046:b0:40e:66ec:49 with SMTP id p6-20020a05600c204600b0040e66ec0049mr2559252wmg.123.1705337936888; Mon, 15 Jan 2024 08:58:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705337936; cv=none; d=google.com; s=arc-20160816; b=UHG17SDazUNKNyLXybbrP72vPn6vhg3mbG7AHXFrAOwanJtHcgZlBGiNnGLn65lq2m GPcitk7Fk+NJGrSAgvHG48WqtIX+0ii8LM4lvpsNEIuEGaYNe+GBkicW+VInGskTknjB IrFNOmD9Qs1hGVXuns4LqpiXyjSCv/EQeDzuyR3Y5QNFpidakB/4/D4srkmJ/iLkWPnO zA6mU5qcB/mWntvAOJYRC/0iuyXWw7AwnxZFpgOK2vdi/BlQbwjkI3WXE8JvO4ZeUZ1z IFizOG2AUKjjjp2cjZ+ZBdLm00wSGGWCtrlxtbSD1en11T8CNOutEGd0UsMmUctpS+HX p3JA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=+sky+dN0N83XZOkqrQIytiRpw6s7V+tQBaTUTZeEYIQ=; fh=TXfLgedSgLDO+mwPbwXkkZBdKyk9gV6Sk5P+Gd5XLts=; b=1K+TbhNc4McMQ973PbaEbd3rDEFWm98gbCXOcwfPr3BSmup0UIXwsbPbVbjrBRcZqi 7Skf/ozwk276Rg9Z2OortG9IlD5XueGOI+oCWO5D0TwTcwzPRjuFWHqTAtgmX1jqT90k lxLwNhAwo395DJohVF0jM5FX9dXxklIZj+xc3sZjg75AHA9gO2J0idfiOWlCPMu4XjQ8 6u0AXuOlSp7POSC1d00u1c54HsOGRMhm+voNi0I20UA0Q3Q6lW692DXgIG+QkuLVBt4y 6bwsQHDv4cGm0RffzOilt6gikPQiGFD/mTDtFS5DSIo26o5BftKPPLX/G6t1Cdky0yTb EREw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-26284-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26284-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id l11-20020a056402124b00b005578f1af1c1si4108908edw.689.2024.01.15.08.58.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 08:58:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-26284-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-26284-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26284-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.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 am.mirrors.kernel.org (Postfix) with ESMTPS id A1ED61F22A95 for ; Mon, 15 Jan 2024 16:58:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6BA2617C73; Mon, 15 Jan 2024 16:58:44 +0000 (UTC) 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? > [...]