From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.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 7A9B33B14B8 for ; Fri, 21 Aug 2026 08:54:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787302452; cv=none; b=CjbrchqQVO68XGtnVorzDvyh4uXzXmbTr47BFFFQdc+7kA6p7E/rdjaOuhriNytfF0nk7peDbr9EOC0DF6zNlZWB4AYPyecC47AF+MVI9J6eeDR7PdvDk2JIoe1+zn5YjiwVi4d20Ak5dvsyv8GHEX4rBdZ/JszNMEqURENN7aY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787302452; c=relaxed/simple; bh=YoxTsBu/fJRi+jVK2pRw9v3Av+hAI9x69B6UIBkZg90=; h=Message-ID:Date:MIME-Version:Subject:To:References:Cc:From: In-Reply-To:Content-Type; b=fTloqlA4JXKNTAjJmh02wwqZ91MxNbmnPUOsEQuv/5FNXOV6X3+Cv5D8wi3XYCU4x1E5C8qj+ec78z4A1ksEo/cz0NkYQ0WF0Pp7AFwTR/5vrgMXmnbrS3gxhBxK0dRmx6QGAk0xf0oz4xUFj0l/f3bZuTDGdWBVlvLrY1yxn+s= 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=Du65s8YI; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=bVdnKUtb; arc=none smtp.client-ip=205.220.180.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="Du65s8YI"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="bVdnKUtb" Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 67L8WGgY1785154 for ; Fri, 21 Aug 2026 08:54:10 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= aVzm8sO0NG4UUDGzojl/Qyf2ZqcZXs17qL4O2s8RJ54=; b=Du65s8YIGo7zKonb OH10HrIgoNej1BmTDOzWBqKBC5qc3GqosATs3L0xGfsYk7FmXwGUgoEK9AoeYlFz fEQzuqfKhRYq23N42Dj7zk9BpiLjeGq5J8eNGHJqTmmibVh3+XSyPHutWY5H1jGm wR1gFQ7uACpI3uSAh9/uvwViJCRWikE++EZRprXm579gVgiISGanqRtgiBAg2gQA 0mg7SZUz6unmtdjFAf96jP+bBYgocarpHPUgPuA3KOGtOLbdEuBrrjakKb5087kM gHcP4Vg8KsIx+zuCUHDhrUDrMVlzi2nT0glDauudc4Nht2d1ByWW1Pl8d95rld8b Z5kMrg== Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4g6gdn8sbc-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Fri, 21 Aug 2026 08:54:10 +0000 (GMT) Received: by mail-pf1-f198.google.com with SMTP id d2e1a72fcca58-84f0d3ab2f4so580575b3a.1 for ; Fri, 21 Aug 2026 01:54:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1787302449; x=1787907249; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from:cc :content-language:references:to:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to:content-type; bh=aVzm8sO0NG4UUDGzojl/Qyf2ZqcZXs17qL4O2s8RJ54=; b=bVdnKUtbvtVO7YucitczM2caRo2rPc0EJGeuQiFZm8DHQQArd7tqcI9daSEAve/vev PIsqkKuu9kYVOtg5dBjEH4gGQpPaGvGZ8JbgtrLFT3SosoaL1+c2CBlv5bMo09kfqCgP 6nWsw76UpA4EMGdu5a1A84SlzkhTqMYtDDF2hnl3oipBJGXJlI2qYPCtNd+vj0TMq6Tc gWHScHnETyceU+FkounklfDiumiC6FZy4c0G19l+PC9KrzLPei4L7gNmTDMXwnc0Yb/c sF3FGDdr6ccwZb1Tx+d3imH37dhEMdqIbzTvEMMHuP+JdOuv2YCKZP0KopvKLEw4C1r7 hQGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787302449; x=1787907249; h=content-transfer-encoding:content-type:in-reply-to:from:cc :content-language:references: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:content-type; bh=aVzm8sO0NG4UUDGzojl/Qyf2ZqcZXs17qL4O2s8RJ54=; b=sQZDcDrr5VvH4dKPOXbyLjQJgeXkSREkmL41EkesmMQPec7hEarQcxEYdYJde+BvId ZeltW7+FY9WN/+XctiNusD+WsBXuCF2lr5tVwpRIm8jlNni+toYkhDW/xToUZ/n/GN1c 77hnJ8vB1Vuw+Vn/NtsKML3ejTFLw8DFQXgzXQokb8ItYPyXr7NoqrvVh5SGXJ6Ow4z7 iA78EiyF0RTiLwC3qWxwgqQQl4Gd8v4cXo1yJbnNRI6CvI/A8P4HGh/ym2ELJrHX9ufy w+vzmqU5/JIXj+PvV1U8WInLfupZDA7PsupdrLDhiqbnwKPN0PMh9YeZDmr/4sx+gxpM BvGQ== X-Forwarded-Encrypted: i=1; AHgh+RpbF/EqdDqW/5jVN4GsCoYvT+v1Q4B/VT8CaAgZ9eR8+FugVUk+ocTFUcfeAhcRFSwLaKfxYDBwi+QJvNg=@vger.kernel.org X-Gm-Message-State: AFuF++m7kHtrst2M+SuIl5ujJBcDxmFLNguK1YWs++CuKo48f4dA3RxC 0qzekmU8bNyMzQRrV0hN48T31pq6esmotw4IdUFHHrMBzompuv4HFM0zOt+KzynEG1tQu0Nlqc8 UyegNpMHHRYbo5A+pGg1aByxQe6z4KuTb9lMy4lTHvU2d3gXvYLT9xORh9omqqbtLkMw= X-Gm-Gg: AR+sD11qjMaXt+T+BEXAQQlOG1PfWN2GGuL4ZQsFlHNgbOHJlE36qbDXLWyKV+BrSak WJmSnEpTRMDkX/uAwBjX2unfhRmsxHlQtpn1lYpBBg0oTvxb2hXZ2EWmcxH0zjjY4FHV97eItVC RcJQk+No2DtON11UAMRNS8H5GdnvIeXQwCF+6czKQjqXtSmUlekYizVb7jGlHeAMlC7MYyYasxZ UY9rzRjUkwAHXpiwPhhIGYvflHx1hfASpAJluXy76t+rQRXHFOGzE7MydIoP6pUzjj4tnCQtibM GX2QS4h2uH/1WWxRURxwJdnUJrIk3LrI2kRQJctijMNPCJKuoDxoTnbZijHjZT9ATfi6tRe/5Ks R+FaXNqyJjeMYZsjgzihCcsNX7aC0dKK1wMoZSz90rK+m3Tt9BUovY/rlim8g0066OVu5C4s= X-Received: by 2002:a05:6a00:1c86:b0:846:de21:3da4 with SMTP id d2e1a72fcca58-851f9cc6dfemr8284603b3a.3.1787302449206; Fri, 21 Aug 2026 01:54:09 -0700 (PDT) X-Received: by 2002:a05:6a00:1c86:b0:846:de21:3da4 with SMTP id d2e1a72fcca58-851f9cc6dfemr8284540b3a.3.1787302448740; Fri, 21 Aug 2026 01:54:08 -0700 (PDT) Received: from [10.133.33.51] (tpe-colo-wan-fw-bordernet.qualcomm.com. [103.229.16.4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-851d3362cf8sm2755115b3a.4.2026.08.21.01.54.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 21 Aug 2026 01:54:08 -0700 (PDT) Message-ID: Date: Fri, 21 Aug 2026 16:54:05 +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 v3 2/2] cpufreq: acpi-cpufreq: fix P-state index mismatch in get_cur_freq_on_cpu() To: lirongqing , "Rafael J . Wysocki" , Viresh Kumar , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org References: <20260820020715.2344-1-lirongqing@baidu.com> <20260820020715.2344-3-lirongqing@baidu.com> Content-Language: en-US Cc: zhongqiu.han@oss.qualcomm.com From: Zhongqiu Han In-Reply-To: <20260820020715.2344-3-lirongqing@baidu.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODIxMDA2NCBTYWx0ZWRfX2Z3GBhFQvEU9 IaKOTjsHn8dT2CuWfgjbC9i11ee3pE+kIUgK2ku6K28hr+l2q10hLOpDj7hCIJXoUDd5AaIG+0B bMaNRCdt8jyzieQqLw51MAv5Y38ps1Mop8j1jypjms5/6y6hTluLdy4NTAFc+sriGJWFBV6lG5h MZL4FLV5YvECIBlRNRUKLXYBIy05GkqEIa4hadH4wVaPyWHBb8GLeoMckJMmWBGDL8DXVqtsoal h6dIX3X2A1urr8PeyIyaC7LfoZEsx3dHd+9uhjW84jcUVP+1wpzPryXrATAnUBlUmcNOeLQ19d3 uZX0eVfnC+zXjaWgFndXHtxHm2Bv7im5TvCO4M3ERaBGyc/gZwxG/E/uiPyK2aq7BdVwbEA3GjT pPHHW29iXfqJTnWzyNtLBrmBJFOU2F8XQDHo8QLQMvd+K8Nujcwn0Urn3rToLAfH3P+dBRB3a+V g/7Lm4yukqo3+I6heJQ== X-Proofpoint-Spam-Info: AW1haW4tMjYwODIxMDA2NCBTYWx0ZWRfX8NJ3fKeiGAtS L3FkT/6/tXO6Rxq2FVjQDvM+Lo/LLJHQtPa3vDQedowTMDVycd4Fjtd9UmcUc4cFcn8wfa+B5f2 CU+0a0GRW+EE5XFxIwab8te364f23mA= X-Proofpoint-ORIG-GUID: GUjVWTo_zYk0hUOTbdp79WOQaIV4tYnb X-Authority-Analysis: v=2.4 cv=BJyDalQG c=1 sm=1 tr=0 ts=6a881232 cx=c_pps a=m5Vt/hrsBiPMCU0y4gIsQw==:117 a=nuhDOHQX5FNHPW3J6Bj6AA==:17 a=IkcTkHD0fZMA:10 a=Sv0fKeRqtYgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=rJkE3RaqiGZ5pbrm-msn:22 a=zuLzuavZAAAA:8 a=EUspDBNiAAAA:8 a=X-4reRNKfApO1qCbSG0A:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=IoOABgeZipijB_acs4fv:22 X-Proofpoint-GUID: GUjVWTo_zYk0hUOTbdp79WOQaIV4tYnb X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-08-21_02,2026-08-21_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 malwarescore=0 bulkscore=0 clxscore=1015 impostorscore=0 adultscore=0 phishscore=0 priorityscore=1501 suspectscore=0 lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608210064 On 8/20/2026 10:07 AM, lirongqing wrote: > From: Li RongQing > > get_cur_freq_on_cpu() uses perf->state, which is an index into > perf->states[], to index policy->freq_table[]. However, freq_table[] > is built by filtering _PSS entries with duplicate frequencies, so its To be precise for applying if needed. "However, freq_table[] is built by filtering _PSS entries with duplicate frequencies" --> "However, freq_table[] is built by filtering _PSS entries that are not lower in frequency than the previous one." > index space no longer matches perf->states[]. The original P-state > index for each remaining freq_table entry is stored in driver_data. > > Once an entry has been skipped, using perf->state as an index into > freq_table[] can therefore select the frequency of a different > P-state. > > The reported current frequency itself remains correct because it is > obtained from extract_freq(). The mismatch only affects the cached > frequency used by get_cur_freq_on_cpu() to detect a firmware frequency > change behind our back, through data->resume. Just for applying if needed, deleting "through data->resume." > > If the wrong table entry contains a frequency different from the one > the CPU is actually running at, the check falsely detects a frequency > change and sets data->resume. The next ->target() call then performs a > redundant control-register write even if the requested P-state is > already the current P-state. > > Conversely, if the wrong table entry happens to contain the frequency > to which firmware has changed the CPU, the frequency change is missed > and data->resume remains clear. A subsequent ->target() call for the > P-state that the cpufreq core believes to be current can then > short-circuit without rewriting the control register, leaving the CPU > at the firmware-selected frequency until a different P-state is > requested. > > Fix this by taking the cached frequency directly from > perf->states[perf->state].core_frequency. perf->state and > perf->states[] use the same P-state index space, and converting > core_frequency to kHz yields the same value stored in the corresponding > freq_table entry during initialization. > > Fixes: e56a727b023d ("[CPUFREQ] Make acpi-cpufreq more robust against BIOS freq changes behind our back.") > Reported-by: Zhongqiu Han > Suggested-by: Zhongqiu Han > Signed-off-by: Li RongQing Reviewed-by: Zhongqiu Han > --- > drivers/cpufreq/acpi-cpufreq.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c > index a797bb2..3313c74 100644 > --- a/drivers/cpufreq/acpi-cpufreq.c > +++ b/drivers/cpufreq/acpi-cpufreq.c > @@ -353,6 +353,7 @@ static u32 get_cur_val(const struct cpumask *mask, struct acpi_cpufreq_data *dat > > static unsigned int get_cur_freq_on_cpu(unsigned int cpu) > { > + struct acpi_processor_performance *perf; > struct acpi_cpufreq_data *data; > struct cpufreq_policy *policy; > unsigned int freq; > @@ -368,7 +369,9 @@ static unsigned int get_cur_freq_on_cpu(unsigned int cpu) > if (unlikely(!data || !policy->freq_table)) > return 0; > > - cached_freq = policy->freq_table[to_perf_data(data)->state].frequency; > + perf = to_perf_data(data); > + cached_freq = perf->states[perf->state].core_frequency * 1000; > + > freq = extract_freq(policy, get_cur_val(cpumask_of(cpu), data)); > if (freq != cached_freq) { > /* -- Thx and BRs, Zhongqiu Han