From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (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 37CEB3B5E15 for ; Fri, 19 Jun 2026 15:43:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781883842; cv=none; b=YFLucUjgBcLHh+M9w2BfHJf3ZtllysUTBWnbk+ejVo5x96UiXWiZ8NvWiMfB6xbnU+PxEem9Ki4rNU4ZnZKxKn9xmnBDS1/JP4RI+/3Bc0CEmBF0wnYjG/EBZ138dB5p0fOUerIRTlbE/WfdKGFwruvGKJakzvScEZY90DM0DX0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781883842; c=relaxed/simple; bh=C4yYazntPWDzseRjzv95bID1jrYEwNZptGnvCAlQJM8=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=hrqJH/wfxXnM31ulBDV2nFRQxFbl8n9/38m7wPo+cGZb1xoD565C3l+/fwhqy3P+N3e2zFrMa+6fuCuhjuMBZKGa23LRWOU85koGj82z4RsJlvwhHIh3z7u599myU6U89hgcL1fYNkTl59XW9rJCDP9whARSyCfIF/P85yNrbds= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=cgL2uDCJ; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=FskXvHt/; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="cgL2uDCJ"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="FskXvHt/" Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 65JD9vR5210027 for ; Fri, 19 Jun 2026 15:43:56 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= ugdUMkC7tuaLPVYYlU/o8v7Jtmi3r69VxCdHHq6dOtU=; b=cgL2uDCJ2W3egRcW 95nueD3feuhoLZDvet4UYdoVG98B8s6nOsM+VND7jjNKxG2Mb/Mrmuzg2/rDqZcs BUudLgan7QmtuEmwQDlHAOV3998FppeqBAZ6DccZz4bamFTEuRAqvVOqmcAzMLbX NV0BNG6fN9vuH36VI54ITvHyBK+0YB4v8eAGCPZ/DcEhLEvr0Gaitm9obmKWNCU9 HphqRkjierVm9sBG+bnXDypqYDMLyBFmC/7hTxMgiaEMAKWhFkzpM4KM/5wmo9DA uz+gTul7GaU3zIxElXs2wiH9xeA3X812tt0S1G+O1hIuLEzvn74vaLIH64utiA2n lqv+zA== Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4evy72hu30-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Fri, 19 Jun 2026 15:43:56 +0000 (GMT) Received: by mail-pg1-f197.google.com with SMTP id 41be03b00d2f7-c8a247a74b7so1069621a12.2 for ; Fri, 19 Jun 2026 08:43:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1781883835; x=1782488635; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=ugdUMkC7tuaLPVYYlU/o8v7Jtmi3r69VxCdHHq6dOtU=; b=FskXvHt/mNgGTLaeN89Qx02zk7O2A93CYRgYOmwFU97E7YQfclwnEo5j27M+kYbRXa r0uuOrM/0LTBGR66DMvZaEScf+luFNMp6AJZuLs2u8MB1/ZKlfJxMOkk54uHZTZOHK2M C7JuyVpaFHAGOZV5RhaBuCsPeOS1b0WawhsTQBtVHhqFvFQ8SawRd6bBoBDDIbGejETz P9kvcmOmCbMJcb2t6BUbhdvNYWIuZiZpPGlzl0u8sWxMq6Z6Jpl1BsgHKGL23pH+9H7m JpNwLooq+p5PaLhpTcYU45wluFDGEOBM95A+DSgv/Cp02VA7qWLnMHtcT74Hy+NZKoC3 1hSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781883835; x=1782488635; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ugdUMkC7tuaLPVYYlU/o8v7Jtmi3r69VxCdHHq6dOtU=; b=XQ992ea1yQnJbVbRWDmC2b0tcR0ogPuFJxqNkTLk9Cogv6f6fNfHcSFeoyLWcSgD7K vKD7vt2qO2H4MzpDXJmH6IooGg1aExNlCzKhJTWA3zmXtrnNwjTRjeS2O9QdXIj+1S+/ CeH5/+hAOcCMbfPRMYdkibnwMrDJjr92LyCs4Us015zWeEj5L8Q/KGb62IdIjd/1uX+Q tJSSpD0Ft2YN+VK8rvB5uKalw68NamExtbNEbsBSGWU5bLbBBcmGciUm1YIr5cvJC86X 27TRNAu1ZeYPtJDfqgWgG/wMMs23p0SGQoONtxwMUhZ37ke2xX5jQAbqQbOdAEvdWyt6 Ub6Q== X-Gm-Message-State: AOJu0YwzOWGXHosebq3A2MaoH5Aqg5txGrQhSHDujK7NI6r8FsyDQcao MTQN7WGKTT+/t9aguruZ10OAnPR9MoZxF628qq+l6QuhwI36v4QGIEAX/X/rnwC9E6hP6gq4JlB pPe2ltfGsz8HmOlFZWWKRXiJKsWBcdvyADGLiSb2T2jzVvx80t9nmTpdMSvZ/5IBtYug= X-Gm-Gg: AfdE7cnnt/VjNR62I25hu8VCVotK8MUP1XtjQZerCz7oeZvPOT8c3JZIYs3z8PVDJP/ vvycBYnXm99OaKN+LCyefSEwIEe4Vwa2PsldsczWEqo09PulefdjSBA6FiGuuQNCJOoxBFJ0TxA dypkxA4sACMN8UohBNz9u7AKd5VJbb7SY6nN6c9UP3lDHwzxLeS7aWKEIxpy+mg4T4MK4AiqH1P 36kVdTaQsuKkSraj/K1z6K2pXnT+QFSXbae54ogJp8lMXNp4CiePEp279SuRSDE5TEDESwhZPgO PyF0rgQiDalIkGYaK30fNajHZFmPor24rXQEMa1/733SJtIlPcmAl/mu0a380oMZ9U/U5AtTLUe QEv2AUn1J7R4iTh1eZriHGv794FQGyE5xScR1kIAa4P7p68fDN8W9/7lOJzsd4JXmWMNHR2eQ+r MEe7g+Edo= X-Received: by 2002:a05:6a20:6a21:b0:3b2:86c9:baa5 with SMTP id adf61e73a8af0-3bb6c4644e7mr3759781637.38.1781883835297; Fri, 19 Jun 2026 08:43:55 -0700 (PDT) X-Received: by 2002:a05:6a20:6a21:b0:3b2:86c9:baa5 with SMTP id adf61e73a8af0-3bb6c4644e7mr3759741637.38.1781883834782; Fri, 19 Jun 2026 08:43:54 -0700 (PDT) Received: from [10.133.33.106] (tpe-colo-wan-fw-bordernet.qualcomm.com. [103.229.16.4]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c8bc2c8f0a7sm159393a12.7.2026.06.19.08.43.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 19 Jun 2026 08:43:54 -0700 (PDT) Message-ID: <56a6b35a-407f-4529-b655-27d6cde5e595@oss.qualcomm.com> Date: Fri, 19 Jun 2026 23:43:49 +0800 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 v2] cpufreq: intel_pstate: Adjust the .adjust_perf() driver callback To: "Rafael J. Wysocki" , Linux PM Cc: LKML , Viresh Kumar , Srinivas Pandruvada , Christian Loehle , Peter Zijlstra , Vincent Guittot , Mario Limonciello , zhongqiu.han@oss.qualcomm.com References: <6277654.lOV4Wx5bFT@rafael.j.wysocki> Content-Language: en-US From: Zhongqiu Han In-Reply-To: <6277654.lOV4Wx5bFT@rafael.j.wysocki> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNjE5MDE0OSBTYWx0ZWRfX2Q+wZr+3ivuG Lfttieg1aQenQMzLqBAMnRZmcgmFn6NGn23SZ7GyJPZ9UVfTM53EehXdDyYwSwjCXGJjkURP+he un5UplnU4TWlfMOiCsHrw/ilrTKfbLz1qFuDWKpP86C04oLHiRkEo7SIWxIBtLMDe3Hw4FdBk3A 1ugWAJN+x407ZukjM3Usy+V58YkMOtUnHkWsm+IsSWQiQYOkOYwFbdgLtjcath2ZYrwuxllaecY 2n9ES6jBhP7tMcXvR8vV+0WRHwpNZQx032ksrSTHYJt+4y6Gy2ACqb021tB6UoKWoWlqdXttRpl /qZ+FuTgcb+J8225v3khCRoFzedgbd+04t5WrJZlrOaLY12u43p+w2PE1yy2siD0oD44QH0fsmL wFo4J1OP7DwWB09kds0Y5nSh4MoZXnVm/MWZFq8sseLIFHPfPKQ13rJH0bLnB2xmwzM+dKRscIx o6YMVADmYgQ0FdVYbkw== X-Proofpoint-Spam-Info: AW1haW4tMjYwNjE5MDE0OSBTYWx0ZWRfX4eTOQSKtXF0z gi1gS6nqhJv3QgbivjS8Hce+WE7aIyhKalDwWi9Cksl6U+HrrNQ84pBJekwvJssdAKogRiudf0X FLlcrK0ZX2Z4y3zJZrvUL71qcO3K4H4= X-Authority-Analysis: v=2.4 cv=I75Vgtgg c=1 sm=1 tr=0 ts=6a3563bc cx=c_pps a=rz3CxIlbcmazkYymdCej/Q==:117 a=nuhDOHQX5FNHPW3J6Bj6AA==:17 a=IkcTkHD0fZMA:10 a=FelO9ux0wxsA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=DJpcGTmdVt4CTyJn9g5Z:22 a=VwQbUJbxAAAA:8 a=QyXUC8HyAAAA:8 a=KKAkSRfTAAAA:8 a=EUspDBNiAAAA:8 a=d4jfqAhGOrdBWL2RbNwA:9 a=QEXdDO2ut3YA:10 a=bFCP_H2QrGi7Okbo017w:22 a=cvBusfyB2V15izCimMoJ:22 X-Proofpoint-ORIG-GUID: DXa7Qb8HyaXGi1NW0o1ylRsvDJTUrULx X-Proofpoint-GUID: DXa7Qb8HyaXGi1NW0o1ylRsvDJTUrULx X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.125,FMLib:17.12.100.49 definitions=2026-06-19_03,2026-06-18_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 adultscore=0 impostorscore=0 phishscore=0 spamscore=0 clxscore=1015 priorityscore=1501 suspectscore=0 bulkscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2606190149 On 6/19/2026 10:52 PM, Rafael J. Wysocki wrote: > From: Rafael J. Wysocki > > In some cases, the processor may not actually stick to the "desired" > performance level programmed through the driver's .adjust_perf() > callback and may go above it, which may not be desirable (for instance, > there may be a UCLAMP_MAX limit set for the task currently running on > the given CPU which should be respected). > > Address that by adjusting the .adjust_perf() callback to take an > additional argument, max_perf, representing the maximum allowed > performance level of the CPU and update the intel_pstate driver to > take that argument into account as appropriate. > > Accordingly, adjust cpufreq_driver_adjust_perf() and the other existing > user of .adjust_perf(), which is the amd-pstate driver (but the behavior > of that driver is not changed). > > While at it, also update the cpufreq_driver_adjust_perf() > documentation to reflect this change and some previous code > changes that have not been taken into account in it. > > Signed-off-by: Rafael J. Wysocki > Acked-by: Viresh Kumar Looks good to me. Thanks Reviewed-by: Zhongqiu Han > --- > > This is an update of > > https://lore.kernel.org/linux-pm/14060154.uLZWGnKmhe@rafael.j.wysocki/ > > sent mainly because the v1 did not update the Rust bindings by > omission. It also fixes a few typos present in the v1. > > Thanks! > > --- > drivers/cpufreq/amd-pstate.c | 1 + > drivers/cpufreq/cpufreq.c | 14 +++++++++----- > drivers/cpufreq/intel_pstate.c | 9 ++++++++- > include/linux/cpufreq.h | 2 ++ > kernel/sched/cpufreq_schedutil.c | 4 +++- > rust/kernel/cpufreq.rs | 6 ++++-- > 6 files changed, 27 insertions(+), 9 deletions(-) > > --- a/drivers/cpufreq/amd-pstate.c > +++ b/drivers/cpufreq/amd-pstate.c > @@ -781,6 +781,7 @@ static unsigned int amd_pstate_fast_swit > static void amd_pstate_adjust_perf(struct cpufreq_policy *policy, > unsigned long _min_perf, > unsigned long target_perf, > + unsigned long _max_perf, > unsigned long capacity) > { > u8 max_perf, min_perf, des_perf, cap_perf; > --- a/drivers/cpufreq/cpufreq.c > +++ b/drivers/cpufreq/cpufreq.c > @@ -2252,14 +2252,17 @@ EXPORT_SYMBOL_GPL(cpufreq_driver_fast_sw > * @policy: cpufreq policy object of the target CPU. > * @min_perf: Minimum (required) performance level (units of @capacity). > * @target_perf: Target (desired) performance level (units of @capacity). > + * @max_perf: Maximum (allowed) performance level (units of @capacity). > * @capacity: Capacity of the target CPU. > * > - * Carry out a fast performance level switch of @cpu without sleeping. > + * Carry out a fast performance level adjustment for the CPU represented by > + * @policy without sleeping. > * > * The driver's ->adjust_perf() callback invoked by this function must be > - * suitable for being called from within RCU-sched read-side critical sections > - * and it is expected to select a suitable performance level equal to or above > - * @min_perf and preferably equal to or below @target_perf. > + * suitable for calling from within RCU-sched read-side critical sections and > + * it is expected to program the processor to select suitable performance > + * levels between @min_perf and @max_perf inclusive and preferably close to > + * @target_perf going forward for the CPU represented by @policy. > * > * This function must not be called if policy->fast_switch_enabled is unset. > * > @@ -2271,9 +2274,10 @@ EXPORT_SYMBOL_GPL(cpufreq_driver_fast_sw > void cpufreq_driver_adjust_perf(struct cpufreq_policy *policy, > unsigned long min_perf, > unsigned long target_perf, > + unsigned long max_perf, > unsigned long capacity) > { > - cpufreq_driver->adjust_perf(policy, min_perf, target_perf, capacity); > + cpufreq_driver->adjust_perf(policy, min_perf, target_perf, max_perf, capacity); > } > > /** > --- a/drivers/cpufreq/intel_pstate.c > +++ b/drivers/cpufreq/intel_pstate.c > @@ -3241,6 +3241,7 @@ static unsigned int intel_cpufreq_fast_s > static void intel_cpufreq_adjust_perf(struct cpufreq_policy *policy, > unsigned long min_perf, > unsigned long target_perf, > + unsigned long max_perf, > unsigned long capacity) > { > struct cpudata *cpu = all_cpu_data[policy->cpu]; > @@ -3271,7 +3272,13 @@ static void intel_cpufreq_adjust_perf(st > if (min_pstate > cpu->max_perf_ratio) > min_pstate = cpu->max_perf_ratio; > > - max_pstate = min(cap_pstate, cpu->max_perf_ratio); > + max_pstate = cap_pstate; > + if (max_perf < capacity) > + max_pstate = DIV_ROUND_UP(cap_pstate * max_perf, capacity); > + > + if (max_pstate > cpu->max_perf_ratio) > + max_pstate = cpu->max_perf_ratio; > + > if (max_pstate < min_pstate) > max_pstate = min_pstate; > > --- a/include/linux/cpufreq.h > +++ b/include/linux/cpufreq.h > @@ -379,6 +379,7 @@ struct cpufreq_driver { > void (*adjust_perf)(struct cpufreq_policy *policy, > unsigned long min_perf, > unsigned long target_perf, > + unsigned long max_perf, > unsigned long capacity); > > /* > @@ -624,6 +625,7 @@ unsigned int cpufreq_driver_fast_switch( > void cpufreq_driver_adjust_perf(struct cpufreq_policy *policy, > unsigned long min_perf, > unsigned long target_perf, > + unsigned long max_perf, > unsigned long capacity); > bool cpufreq_driver_has_adjust_perf(void); > int cpufreq_driver_target(struct cpufreq_policy *policy, > --- a/kernel/sched/cpufreq_schedutil.c > +++ b/kernel/sched/cpufreq_schedutil.c > @@ -50,6 +50,7 @@ struct sugov_cpu { > > unsigned long util; > unsigned long bw_min; > + unsigned long bw_max; > > /* The field below is for single-CPU policies only: */ > #ifdef CONFIG_NO_HZ_COMMON > @@ -232,6 +233,7 @@ static void sugov_get_util(struct sugov_ > util = effective_cpu_util(sg_cpu->cpu, util, &min, &max); > util = max(util, boost); > sg_cpu->bw_min = min; > + sg_cpu->bw_max = max; > sg_cpu->util = sugov_effective_cpu_perf(sg_cpu->cpu, util, min, max); > } > > @@ -484,7 +486,7 @@ static void sugov_update_single_perf(str > sg_cpu->util = prev_util; > > cpufreq_driver_adjust_perf(sg_policy->policy, sg_cpu->bw_min, > - sg_cpu->util, max_cap); > + sg_cpu->util, sg_cpu->bw_max, max_cap); > > sg_policy->last_freq_update_time = time; > } > --- a/rust/kernel/cpufreq.rs > +++ b/rust/kernel/cpufreq.rs > @@ -792,7 +792,8 @@ pub trait Driver { > } > > /// Driver's `adjust_perf` callback. > - fn adjust_perf(_policy: &mut Policy, _min_perf: usize, _target_perf: usize, _capacity: usize) { > + fn adjust_perf(_policy: &mut Policy, _min_perf: usize, _target_perf: usize, > + _max_perf: usize, _capacity: usize) { > build_error!(VTABLE_DEFAULT_ERROR) > } > > @@ -1262,12 +1263,13 @@ impl Registration { > ptr: *mut bindings::cpufreq_policy, > min_perf: c_ulong, > target_perf: c_ulong, > + max_perf: c_ulong, > capacity: c_ulong, > ) { > // SAFETY: The `ptr` is guaranteed to be valid by the contract with the C code for the > // lifetime of `policy`. > let policy = unsafe { Policy::from_raw_mut(ptr) }; > - T::adjust_perf(policy, min_perf, target_perf, capacity); > + T::adjust_perf(policy, min_perf, target_perf, max_perf, capacity); > } > > /// Driver's `get_intermediate` callback. > > > -- Thx and BRs, Zhongqiu Han