Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1070pxb; Mon, 8 Nov 2021 08:50:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJxsUedWtIbfKOfc9Jv2O+jy8SAZDdycDZtPC4heGGyN8L0t9aXqUzbMu6TTcyCjYkT8kR5s X-Received: by 2002:a05:6402:1d50:: with SMTP id dz16mr606320edb.191.1636390205244; Mon, 08 Nov 2021 08:50:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636390205; cv=none; d=google.com; s=arc-20160816; b=a0UwXPMIk/jOTjnAuDeUloo0ZDfpj0yKeSZkxWZBDTCxkkV62xJNJEiPy+/E93FylT R6s5b2u16+ynx+bNa2zH0n82wD88++I0b+2Hk11V5jX245m/2qlHrDaPQRtNnKsVNASQ +ZnvsLqpfYa9nheYwhqN2n15x7DO9coIFDX/32I1o1pXoEDBh+81Nn3Bi+EvA1aQom3I rLYe0t6dPNuSa9NfnfVsvN3IB36jyThomWKMdKn+ItwOs56He6XgXDVlNTNBdHzbbd2J PLEDk+RIryVkGqoXhlztA29q9xO0tWOIXefozC8UMp3stP2K/OAFhwlxQ/J7UjoUwy/7 Cffg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=1jVz43zqSfz6IM7RqGI5zvOw5QLzsfoz6c/dwbC8Ijw=; b=fi//JHylLohTdSM1JlhdViw+fO480wEB9CBIFzMMY3jbWJ0tjHKWz/q8YX19nnn3hP TUVSueIMGNJyk45ljxeIILTgScKiNzW4POMh+tHoXGFhXzWzGEfk5719apkNO41XQwsM IEY2NYXVYkaK96DdKZ/PhA/B1uCTQuV8RnNtGy9KUyPseASZn9THo1xkpqM899a6EOEr 0/QEt16F/NODR2UDFRbT36KhIJ9Y34OcpkCRBEy7ApeK7rbq58ToqPIVVOQ8pW5I6PUi vk5P+lxLDohMn+Qkty5FieqRgPtFZQtAuFk1TEQyAmxa65J3tSnmC4bpCfCoq27MmtCd NjYA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w5si11030201edc.69.2021.11.08.08.49.04; Mon, 08 Nov 2021 08:50:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239011AbhKHOPU (ORCPT + 99 others); Mon, 8 Nov 2021 09:15:20 -0500 Received: from foss.arm.com ([217.140.110.172]:50700 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238977AbhKHOPU (ORCPT ); Mon, 8 Nov 2021 09:15:20 -0500 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 5B7B9D6E; Mon, 8 Nov 2021 06:12:35 -0800 (PST) Received: from [10.57.27.158] (unknown [10.57.27.158]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 57B173F718; Mon, 8 Nov 2021 06:12:31 -0800 (PST) Subject: Re: [PATCH v3 4/5] cpufreq: qcom-cpufreq-hw: Use new thermal pressure update function To: Thara Gopinath Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, sudeep.holla@arm.com, will@kernel.org, catalin.marinas@arm.com, linux@armlinux.org.uk, gregkh@linuxfoundation.org, rafael@kernel.org, viresh.kumar@linaro.org, amitk@kernel.org, daniel.lezcano@linaro.org, amit.kachhap@gmail.com, bjorn.andersson@linaro.org, agross@kernel.org, Steev Klimaszewski References: <20211103161020.26714-1-lukasz.luba@arm.com> <20211103161020.26714-5-lukasz.luba@arm.com> From: Lukasz Luba Message-ID: <02468805-f626-1f61-7f7f-73ed7dfad034@arm.com> Date: Mon, 8 Nov 2021 14:12:29 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Thara, +CC Steev, who discovered this issue with boost frequency On 11/5/21 7:12 PM, Thara Gopinath wrote: > Hi Lukasz, > > > On 11/3/21 12:10 PM, Lukasz Luba wrote: >> Thermal pressure provides a new API, which allows to use CPU frequency >> as an argument. That removes the need of local conversion to capacity. >> Use this new API and remove old local conversion code. >> >> Signed-off-by: Lukasz Luba >> --- >>   drivers/cpufreq/qcom-cpufreq-hw.c | 15 +++++---------- >>   1 file changed, 5 insertions(+), 10 deletions(-) >> >> diff --git a/drivers/cpufreq/qcom-cpufreq-hw.c >> b/drivers/cpufreq/qcom-cpufreq-hw.c >> index 0138b2ec406d..425f351450ad 100644 >> --- a/drivers/cpufreq/qcom-cpufreq-hw.c >> +++ b/drivers/cpufreq/qcom-cpufreq-hw.c >> @@ -275,10 +275,10 @@ static unsigned int >> qcom_lmh_get_throttle_freq(struct qcom_cpufreq_data *data) >>   static void qcom_lmh_dcvs_notify(struct qcom_cpufreq_data *data) >>   { >> -    unsigned long max_capacity, capacity, freq_hz, throttled_freq; >>       struct cpufreq_policy *policy = data->policy; >>       int cpu = cpumask_first(policy->cpus); >>       struct device *dev = get_cpu_device(cpu); >> +    unsigned long freq_hz, throttled_freq; >>       struct dev_pm_opp *opp; >>       unsigned int freq; >> @@ -295,17 +295,12 @@ static void qcom_lmh_dcvs_notify(struct >> qcom_cpufreq_data *data) >>       throttled_freq = freq_hz / HZ_PER_KHZ; >> -    /* Update thermal pressure */ >> - >> -    max_capacity = arch_scale_cpu_capacity(cpu); >> -    capacity = mult_frac(max_capacity, throttled_freq, >> policy->cpuinfo.max_freq); >> - >>       /* Don't pass boost capacity to scheduler */ >> -    if (capacity > max_capacity) >> -        capacity = max_capacity; > > So, I think this should go into the common > topology_update_thermal_pressure in lieu of > > +    if (WARN_ON(max_freq < capped_freq)) > +        return; > > This will fix the issue Steev Klimaszewski has been reporting > https://lore.kernel.org/linux-arm-kernel/3cba148a-7077-7b6b-f131-dc65045aa348@arm.com/ > > > Well, I think the issue is broader. Look at the code which calculate this 'capacity'. It's just a multiplication & division: max_capacity = arch_scale_cpu_capacity(cpu); // =1024 in our case capacity = mult_frac(max_capacity, throttled_freq, policy->cpuinfo.max_freq); In the reported by Steev output from sysfs cpufreq we know that the value of 'policy->cpuinfo.max_freq' is: /sys/devices/system/cpu/cpu5/cpufreq/cpuinfo_max_freq:2956800 so when we put the values to the equation we get: capacity = 1024 * 2956800 / 2956800; // =1024 The 'capacity' will be always <= 1024 and this check won't be triggered: /* Don't pass boost capacity to scheduler */ if (capacity > max_capacity) capacity = max_capacity; IIUC you original code, you don't want to have this boost frequency to be treated as 1024 capacity. The reason is because the whole capacity machinery in arch_topology.c is calculated based on max freq value = 2841600, so the max capacity 1024 would be pinned to that frequency (according to Steeve's log: [ 22.552273] THERMAL_PRESSURE: max_freq(2841) < capped_freq(2956) for CPUs [4-7] ) Having all this in mind, the multiplication and division in your original code should be done: capacity = 1024 * 2956800 / 2841600; // = 1065 then clamped to 1024 value. My change just unveiled this division issue. With that in mind, I tend to agree that I should have not rely on passed boost freq value and try to apply your suggestion check. Let me experiment with that... Regards, Lukasz