Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp854860rdb; Fri, 23 Feb 2024 02:01:36 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW0JkFK4mj1NYbPtYv797nWazNCOJkUJBrYGJ1aeUC/XV+5IDC6bv12eTBsHYUIF/Jmd5b3SyYF9zuJabaAko/1E9BqCu3cInx57p/4CA== X-Google-Smtp-Source: AGHT+IHlk9HACkXi7vW1uPm9aHawjsOb86S7K0dcZ+ipHnEuBLvvawk+tlhwURgus/SQ863MO8Jd X-Received: by 2002:a05:6a20:a127:b0:1a0:ddbb:777 with SMTP id q39-20020a056a20a12700b001a0ddbb0777mr3604356pzk.24.1708682496441; Fri, 23 Feb 2024 02:01:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708682496; cv=pass; d=google.com; s=arc-20160816; b=HGhS/o4xMsUy0i/b21NIoZQLbGoONwYcFP1NEyNdd2o8FwUdUQV3wMGNI58CS0maJb ZkJlBxHF3dt8lEAT1DRrNq7B6mT6srbuhiIpzLYp3zIUMSsyNj8QSsHIPeVWRxvGZaHr pzHF7K7xF+87VrvcpGAfY+T8Wa5mbnWjlUGHAtjVKxcf7KSLGciMpFo8tw3DFaoiwGFM HPBPI8C0owKDaDG/CKopnTy4vDUG3rEsJ9BDjqpfIU4dI3HUEFs0jzh8qxgoFMBFD1QK bx2YtVtbvslMqSBOW67aJzxbYK+fq8BT0gI8u/JCSNa6Xh95p6F9Ufl5BQ9RDqBbSXCM mk4w== ARC-Message-Signature: i=2; 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=8qAjmPayebE3gVXawatTcTKUxs0k6zzTqniVPIfd+rA=; fh=0baRL+x8Kk7pOzfVHV5/pF6HdelUY0kl5vAsJK7+4XU=; b=G9GXLoQCrwHRYqrf8MVjE4arme9CZBextTNZ1GkMrE2Aby8Nk0UVWk34qIlaS8gAlP yw+2shcGE+RVF7hiKw8MJtj77zd3QVtIBKhkr6hucNWh95wp0TRqyJirzSpSYaxy91Wk WPl92OYZczf4ic2fQtkgqWw9qF7KSfVIjzUmxDTM1lVoWqGO1cHbIL0rW77iGnKkq7SY cguElb/M8OAF7+lKIa+76bDR8OneE2V6z6jSMZqlQLp4mnIx37JzfimTfgR/tCS0MF3g F9vgvxt0n0I6PqRk9oiAGipZM+CFGF6ObasaM8zKU5c0p4rlTxuX8frBhw+i7UGVinjB ATwg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-78074-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78074-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id u25-20020a656719000000b005cdf89f64ffsi11715370pgf.482.2024.02.23.02.01.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 02:01:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-78074-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; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-78074-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78074-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id B803FB28010 for ; Fri, 23 Feb 2024 09:51:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5EBEF5D724; Fri, 23 Feb 2024 09:48:56 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D7EFC5D471; Fri, 23 Feb 2024 09:48:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708681735; cv=none; b=YnthpCRAsUgB1ShvPqTRKBg0CWcd+KuXZzNhp+ccyZ5gfgKL5mLw2DHNveHMuAv5+j/TLmWX8PCqWUmjAkEhTNTZsD0vWTVQK0soL0n83CiCs3xxx5JFIRnVw1lnOs2LQlUvxiqBCQWnWoIi/a6nsRgtaagZfLojcsn/xrrw/Vk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708681735; c=relaxed/simple; bh=nRLPoamuIA2shnoR1FKakvBvVXEWTXJdoH6Txg+Qw14=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=prLllwhhXNBhizY52vgX2Y42v5eWU3QKft2yLshK/ikPdnW6JRukdYckvdKevZvgY/d3WYMbvQFG5tOofbxoyKbs0uWcFtd7jzV978S++782+TaM/+IgG9KclHuJB1mBfSKJiGF69vK6Gm1z2G0MOgtANw2XC1if64XoVenVlD8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 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 B22E81596; Fri, 23 Feb 2024 01:49:29 -0800 (PST) Received: from [192.168.1.13] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 096983F766; Fri, 23 Feb 2024 01:48:48 -0800 (PST) Message-ID: Date: Fri, 23 Feb 2024 10:48:48 +0100 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] cpufreq: Change default transition delay to 2ms Content-Language: en-US To: Qais Yousef Cc: "Rafael J. Wysocki" , Viresh Kumar , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Ingo Molnar , Peter Zijlstra , Vincent Guittot , Dietmar Eggemann , Christian.Loehle@arm.com References: <20240205022500.2232124-1-qyousef@layalina.io> <20240205074514.kiolurpounokalum@vireshk-i7> <20240220135037.qriyapwrznz2wdni@airbuntu> <20240222115557.blnm4uulkxnorrl4@airbuntu> <20240222233947.sl435tvhhpe5iqzw@airbuntu> From: Pierre Gondois In-Reply-To: <20240222233947.sl435tvhhpe5iqzw@airbuntu> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2/23/24 00:39, Qais Yousef wrote: > On 02/22/24 16:15, Pierre Gondois wrote: > >>> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c >>> index 66cef33c4ec7..68a5ba24a5e0 100644 >>> --- a/drivers/cpufreq/cpufreq.c >>> +++ b/drivers/cpufreq/cpufreq.c >>> @@ -576,6 +576,15 @@ unsigned int cpufreq_policy_transition_delay_us(struct cpufreq_policy *policy) >>> >>> latency = policy->cpuinfo.transition_latency / NSEC_PER_USEC; >>> if (latency) { >>> + unsigned int max_delay_us = 2 * MSEC_PER_SEC;; >>> + >>> + /* >>> + * If the platform already has high transition_latency, use it >>> + * as-is. >>> + */ >>> + if (latency > max_delay_us) >> [1] return min(latency, 10ms); >>> + return latency; >>> + >>> /* >>> * For platforms that can change the frequency very fast (< 10 >>> * us), the above formula gives a decent transition delay. But >>> @@ -586,7 +595,7 @@ unsigned int cpufreq_policy_transition_delay_us(struct cpufreq_policy *policy) >>> * a reasonable amount of time after which we should reevaluate >>> * the frequency. >>> */ >>> - return min(latency * LATENCY_MULTIPLIER, (unsigned int)(2 * MSEC_PER_SEC)); >>> + return min(latency * LATENCY_MULTIPLIER, max_delay_us); >>> } >>> >>> return LATENCY_MULTIPLIER; >>> >> >> A policy with these values: >> - transition_delay_us = 0 >> - transition_latency = 30ms >> would get a transition_delay of 30ms I think. >> >> Maybe it would be better to default to the old value in this case [1]. > > Hmm. I think it wouldn't make sense to have 2 levels of capping. It's either we > cap to 2ms, or honour the transition latency from the driver if it is higher > and let it lower it if it can truly handle smaller values? > > Rafael, should I send a new version of the patch, a new patch on top or would > you like to take a fixup if you can amend the commit? If you and Viresh think > the two levels of capping make sense as suggested above let me know. I think > better to delegate to the drivers if they report transition_latency higher than > 2ms. The latency can be computed by dev_pm_opp_get_max_transition_latency() and one of its component comes from `clock-latency-ns` DT binding. The maximum value I saw is 10ms, so it seems it should be ok not to add: `min(latency, 10ms)` > > -->8-- > > diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c > index 66cef33c4ec7..668263c53810 100644 > --- a/drivers/cpufreq/cpufreq.c > +++ b/drivers/cpufreq/cpufreq.c > @@ -576,8 +576,17 @@ unsigned int cpufreq_policy_transition_delay_us(struct cpufreq_policy *policy) > > latency = policy->cpuinfo.transition_latency / NSEC_PER_USEC; > if (latency) { > + unsigned int max_delay_us = 2 * MSEC_PER_SEC;; > + > + /* > + * If the platform already has high transition_latency, use it > + * as-is. > + */ > + if (latency > max_delay_us) > + return latency; > + > /* > - * For platforms that can change the frequency very fast (< 10 > + * For platforms that can change the frequency very fast (< 20 I think it should be 10->2us as we do: min(latency * 1000, 2ms) > * us), the above formula gives a decent transition delay. But > * for platforms where transition_latency is in milliseconds, it > * ends up giving unrealistic values. > @@ -586,7 +595,7 @@ unsigned int cpufreq_policy_transition_delay_us(struct cpufreq_policy *policy) > * a reasonable amount of time after which we should reevaluate > * the frequency. > */ > - return min(latency * LATENCY_MULTIPLIER, (unsigned int)(2 * MSEC_PER_SEC)); > + return min(latency * LATENCY_MULTIPLIER, max_delay_us); > } > > return LATENCY_MULTIPLIER; > > -->8-- > >> >> --- >> >> Also a note that on the Pixel6 I have, transition_latency=5ms, >> so the platform's policies would end up with transition_delay=5ms > > Yes I know. But at this stage it's a driver issue. I think this value is not > correct and there's a typo. > >> >> >>>> >>>> >>>> 2. >>>> There are references to the 10ms values at other places in the code: >>>> >>>> include/linux/cpufreq.h >>>> * ondemand governor will work on any processor with transition latency <= 10ms, >>> >>> Not sure this one needs updating. Especially with the change above which means >>> 10ms could theoretically happen. But if there are suggestions happy to take >>> them. >> >> a. >> LATENCY_MULTIPLIER introduction: >> 112124ab0a9f ("[CPUFREQ] ondemand/conservative: sanitize sampling_rate restrictions") >> >> b. >> max_transition_latency removal: >> ed4676e25463 ("cpufreq: Replace "max_transition_latency" with "dynamic_switching"") >> >> c. >> dynamic_switching removal: >> 9a2a9ebc0a75 ("cpufreq: Introduce governor flags") >> >> The value could be removed independently from this patch indeed, as this is not >> related to cpufreq_policy_transition_delay_us() since b. > > Thanks for sending the patch. > >> >> >>> >>>> >>>> drivers/cpufreq/cpufreq.c >>>> * For platforms that can change the frequency very fast (< 10 >>>> * us), the above formula gives a decent transition delay. But >>>> -> the 10us value matches 10ms = 10us * LATENCY_MULTIPLIER >>> >>> I can't find this one. >> >> It's in cpufreq_policy_transition_delay_us(), >> "the 10us value matches 10ms = 10us * LATENCY_MULTIPLIER" >> is a sentence I wrote, the comment to modify would be: >> """ >> * For platforms that can change the frequency very fast (< 10 >> * us), the above formula gives a decent transition delay. But >> """ > > Ah you were referring to s/10/20/. Done. > >> >>> >>>> >>>> Documentation/admin-guide/pm/cpufreq.rst >>>> Typically, it is set to values of the order of 10000 (10 ms). Its >>>> default value is equal to the value of ``cpuinfo_transition_latency`` >>> >>> I am not sure about this one. It refers to cpuinfo_transition_latency not the >>> delay and uses a formula to calculate it based on that. >>> >>> Seems the paragraph needs updating in general to reflect other changes? >> >> aa7519af450d ("cpufreq: Use transition_delay_us for legacy governors as well") >> >> The cpufreq_policy_transition_delay_us() was introduced there and integrates the >> 10ms value related to this paragraph. >> >> --- >> >> I assume that if we keep the 10ms value in the code, it should be ok to let >> the comment as is. I'll send a patch to remove the first one as it can be >> done independently. > > Thanks! > > -- > Qais Yousef