From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=205.220.180.131 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793690096; b=ZA2c+OFPNEq0K+uBvMJ6VNPtIQucBudKUOtDj9qGYbq0TnzZUNFKX73i1dDuoBSQjuWs GHnFSMb/00tWF/4eUehouhW2kmbJmUR5r9mgocnFsIiWloyBWtkAary8KhGDuYuWus8AS tWWR1NM43UxlDfznp2RDpTNSNNOFxUeUN2GgKK2X+2awxyVwI5GspgV5wnLfjUzUKCd8C 5Qjhw2cechaz/b7sn/XKRWCXrb/a0blH3f24ep0xRxBvNIGy9bmt5ZmAcdpUtEIZb31uK d3gQ30EDbfCJE9afdDRNzJhmEyTDgdJrRbaY5xvbNOckBKTMZpgwFwvPu9NBdWs1LVg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793690096; h=DMARC-Filter:Received:DKIM-Signature:Received:Received: DKIM-Signature:X-Google-DKIM-Signature:X-Forwarded-Encrypted: X-Gm-Message-State:X-Gm-Gg:X-Received:X-Received:Received:Message-ID: Date:MIME-Version:User-Agent:Subject:To:Cc:References: Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding:X-Proofpoint-Spam-Info:X-Authority-Analysis: X-Proofpoint-Spam-Details-Enc:X-Proofpoint-ORIG-GUID: X-Proofpoint-GUID:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=Taq3TN1TspoSEDGf5Bcuf48IU/BFZ1ywMHPrwJaGDAk=; b=NgAJgDgpIu+xmvXENqfSttAH/eAgt4wtJX6TDfLgMiWn8+UQhQVLzF1o39CjdngggaiE F6n7RdPSMFphMo82RQTWpSI3a14f0YCkwN2isrXoLag5kZ0Z5NehpL+jnKrbHiPOvxYRq y9inYQErEahG4xbJI9cjxCZr2uoCUiCjjIQKeQy0PgJWUwbp550DLtixTlM6SSCp38CLY 04d342Sk2K97kq7rjZkg84LtPnjWTzRHscyT10BhiajD6VDQWafHvyNQZZp5b5alnYWmF P0dlHlw2NbRRbvV1PywkR1W5TLFNaOtFRzD6psXMbwqyMzwC8VMkxVidPVneT5JqIGQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=o7KY7mfd; dkim=pass header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=TrZp8kOX; arc=none smtp.remote-ip=205.220.180.131 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1AEED606A329 for ; Tue, 3 Nov 2026 07:14:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1AEED606A329 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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, unprotected) header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=o7KY7mfd; dkim=pass (2048-bit key, unprotected) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=TrZp8kOX Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6A31eM8s1431345 for ; Tue, 3 Nov 2026 07:14:55 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= Taq3TN1TspoSEDGf5Bcuf48IU/BFZ1ywMHPrwJaGDAk=; b=o7KY7mfdWExlqrsy hfRAiBB20+ysutQzW9p+7J4NgJW2oLKpFF3d2+I/UNc7DjjdlNTyXJEP0U8GQy7W LncvODbdiu66JA7sc6K3ALEYaE2ByPZL3H1r/gqJJbEZbDMzWAuUnU3jmz35sQAD P4cM/TVW0EwXTNfT/UI1luTyuwUYX6JDN8EyMtnyl83ePiQMh8gCUCIRM7gDWD+n 3GuCYtR9RhJOFDSoK7vKSHwDiSSOvFX9rmHWLV7+OnHAj5LWurCXVr7lRezBBnp/ /O/NT4T9V3TLjDpSHUSgMjVHei54fYdRrP6Z7/om1XH7RhmvXuoILzgGiCf4YtVP XNcaMA== Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4hq0872f6t-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 03 Nov 2026 07:14:54 +0000 (GMT) Received: by mail-pf1-f197.google.com with SMTP id d2e1a72fcca58-8a05b68f851so351393b3a.1 for ; Mon, 02 Nov 2026 23:14:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1793690094; x=1794294894; darn=vger.kernel.org; h=content-transfer-encoding:content-type: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 :content-type; bh=Taq3TN1TspoSEDGf5Bcuf48IU/BFZ1ywMHPrwJaGDAk=; b=TrZp8kOXONA2HN/zJz7buaC7jkdTJE+iJ9meotTFdZGJnHktulrAASprG7s4nqNgJ4 8DXIO5iz6ZMQE2skjEu6g1cD0lBJ4jQ93tpkAWrdLYuag+zobSEag2SWTUQZNroyPOHY +sEBO8BfDP5upitri2uuVr9jm2yNv7gIVBsLKzCaxeEQPsiCfMDPUFUeZk93dw1d1Ase c162vfs12OJlLjiD2F7+KHRoloPKOyBq0uIvQ/kJVpa/IK2SIiXmdVjY8qp3xN9QuBrB NrSHLe7awBXT1kwHU/fV4Vq4XwZhNuMipWaeFxGliN+JR3D1UncMxgj5odAsWSbqRcoW 7B5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793690094; x=1794294894; h=content-transfer-encoding:content-type: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:content-type; bh=Taq3TN1TspoSEDGf5Bcuf48IU/BFZ1ywMHPrwJaGDAk=; b=iJ0eG3z10hDptm4WdWoOpe75OSrdqVoDdoFO1VY4cwfEk/2SuF5lddXmAk3BoWnj8Y UNxMtWDfbZjcyA51bXfJo09fpjkGHKW6RaQtwtbhdeUO6hcWBb+DZMaxGInNiTCqA8j7 Vmgi1Sf7UWKtavuQx/kzdgU/Xqt1I8350gnmigmVILA3FByCszctGrGbIqCcbsGjNrI3 /XMFT0fKQluP6FU6bvazPbsXL5VkM9JVjSrLfOc+lLtkLtc6lIqDGVLCqG0psX34sJsA mutJxd4TOFNRS1ROYAud0gGouxO78Vb3kWo+Tt6ztUm4URnncIP96lWI8L69+wzYNwrd NEFw== X-Forwarded-Encrypted: i=1; AKwUvBxB0WRB4dtr82GJf1p6trHxzObmraK4a1oOVJntWwoGdS+DM7w7oj8N48RWDReMhBgSaDVooGha6YpwF1Y=@vger.kernel.org X-Gm-Message-State: APuU4Z8xyZxvKrJRlK3qxqvJqE06q3U+JRqvBfNrww6LIKzEDx3V6VKu DcQ8lEHZIKweWD4f+4Tvl1psxgp/TNTsrXREu3QIgdG3wWxQKwB8h9EeYTPaSOC8Q3xpd5EZ2fN +XYqewpvP6kmhFbptg+OFfr/uurDW1B0bhjgb19CWJXoPL7P2Uxq64rcD6tRuh1R1U9A= X-Gm-Gg: AYBFou1vxZfjnAZ/nvMjyBEaK4nFTNx//RGMeb1OjHcrazaqSE6i+EoTzxURLIcl0HS yPy/beCaEE1a+jFJN0P6xebvoofVSAJiAdPczvfLS1hATeV4nblQ0iaIHwo3aWDPEZe3k821PMX jD7lWCpFpLO3dozgoMASVrQMPs7d01tUThxTOvABjP01/jeVxVatTF4P19ki0cAJaUnQfqrnZO+ vj3eOy6B/UfbxURALjm7S3ZSzXG4ptVzDDEZ5THLMMBeRcz5MoURMqTLfEBBzdq/JcJo7bjLNNX IOSSIounot7SrVUjuTYEuC80JgZWoOgYuSvVLtMIdYbNyACspEeakAqDC7zVEGDklMnIpL7W2Mh VkEZfInJVgoL+3Yx+p9Ohhee3MOxfrJevxnXyAXSgKrZc2JRfPuW6m/0B2oTkgpiFRtERCQ== X-Received: by 2002:a05:6a20:2d24:b0:3dd:a196:ffcf with SMTP id adf61e73a8af0-3e9289dc08emr6711096637.31.1793690093814; Mon, 02 Nov 2026 23:14:53 -0800 (PST) X-Received: by 2002:a05:6a20:2d24:b0:3dd:a196:ffcf with SMTP id adf61e73a8af0-3e9289dc08emr6711079637.31.1793690093203; Mon, 02 Nov 2026 23:14:53 -0800 (PST) Received: from [10.64.69.121] ([114.94.8.21]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-cdb364480a3sm835913a12.9.2026.11.02.23.14.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 02 Nov 2026 23:14:52 -0800 (PST) Message-ID: Date: Tue, 3 Nov 2026 15:14:45 +0800 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] PM: EM: Rank boost and non-boost frequencies separately To: Lukasz Luba Cc: "Rafael J . Wysocki" , Matthias Kaehlcke , Vincent Donnefort , Len Brown , Viresh Kumar , "Rafael J . Wysocki" , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, xin.liu@oss.qualcomm.com, aiqun.yu@oss.qualcomm.com, tengfei.fan@oss.qualcomm.com, tingwei.zhang@oss.qualcomm.com, Pavel Machek References: <20261030-em-rank-boost-separately-v1-1-238a6b2bb888@oss.qualcomm.com> <3ed2a68b-d066-4a3a-b3ed-30a5ca00ae38@arm.com> Content-Language: en-US From: Guo Chen In-Reply-To: <3ed2a68b-d066-4a3a-b3ed-30a5ca00ae38@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Proofpoint-Spam-Info: AW1haW4tMjYxMTAzMDAyOCBTYWx0ZWRfX2kzXZMgRjfqF 994nRJ2/oPbaVLrTIQrJvlqB9B4GwTfoRRID+mdvvFG10cjfWEIbXT/5EgyXNv+0NlrNY2rRlp2 cOwlBt0cL4ZXBZuMqfrej2YV43y1iDI= X-Authority-Analysis: v=2.4 cv=K9m3jCWI c=1 sm=1 tr=0 ts=6ae989ee cx=c_pps a=rEQLjTOiSrHUhVqRoksmgQ==:117 a=Uz3yg00KUFJ2y2WijEJ4bw==:17 a=IkcTkHD0fZMA:10 a=zJRp6_cAMcgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=gowsoOTTUOVcmtlkKump:22 a=EUspDBNiAAAA:8 a=VwQbUJbxAAAA:8 a=mce2Jbv03V5EqRZ6POQA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=2VI0MkxyNR6bbpdq8BZq:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTAzMDAyOCBTYWx0ZWRfX+M2FZzbR143R VTRqYPf7IVuSUJF1JiUQCindPE78Uz+7eQG45sltxRxRGVbJjxs9RV5wQ9YMN98jtVT6XViUjjR fFcRP8PQSFCxujc9wASLOSUu1L71my4CcqQI+65cgJBMrjAwxBWcCxP0Gkx2XS61cY1saPWfx9K LynpMjR/Xh43d5lVqvvGGqftpzvy06Ae0ZTXOl3ho3Fo5zU5LPlzssIfb7pI4HR/jDY/RAuKXEj iC8Q1Hl4YmLwIYTMK9aVLizveN+3aMFxs8Am0P43r8mQ5RwOmjQWraSBk06HKcMAOrPap3nQWyT I+Kypp4aelREOPCZoOmL9haLuZJWI4HHef8LZStOOf4I2Z8nvxd7152+hGZnGu5CthiCZMKw582 J2AjNkv8mUC2wWQog5yFPi87WPVOqQesN5Ljlo5MVNJZ4d0NnNfSa4uh9R0yiRDMWuxe0mqALWu X34x0hiqaCBO2ZJH7QA== X-Proofpoint-ORIG-GUID: H7miPdhah0tUXQGfiVk3vtEEtqtI3807 X-Proofpoint-GUID: H7miPdhah0tUXQGfiVk3vtEEtqtI3807 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-11-03_01,2026-11-02_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 lowpriorityscore=0 clxscore=1015 malwarescore=0 bulkscore=0 adultscore=0 spamscore=0 suspectscore=0 phishscore=0 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610300000 definitions=main-2611030028 On 11/2/2026 11:28 PM, Lukasz Luba wrote: > > > On 10/30/26 08:10, Guo Chen wrote: >> em_compute_costs() ranks all the frequencies of the table, boost ones >> included. A non-boost frequency can be marked inefficient only because >> a faster boost frequency has a lower or equal cost, e.g. >> >>    3.9 GHz  4.0 GHz (cost C)  4.1 GHz (boost, cost C) >> >> With boost disabled 4.1 GHz cannot be selected, but 4.0 GHz is still >> skipped by governors rounding down to efficient frequencies (e.g. >> ondemand with CPUFREQ_RELATION_HE), which land on 3.9 GHz instead of >> the best selectable frequency. Several frequencies can be affected. >> >> Rank boost and non-boost frequencies separately in em_compute_costs(), >> using the highest non-boost frequency of the CPUFreq table, returned by >> the new helper cpufreq_table_max_nonboost_freq(), as the boundary. >> >> Fixes: c8ed99533dbc ("PM: EM: Mark inefficient states") >> Signed-off-by: Guo Chen >> --- >>   include/linux/cpufreq.h     | 24 ++++++++++++++++++++++++ >>   kernel/power/energy_model.c | 15 +++++++++++++++ >>   2 files changed, 39 insertions(+) >> >> diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h >> index d3d0d9d02aa4..c93316141a11 100644 >> --- a/include/linux/cpufreq.h >> +++ b/include/linux/cpufreq.h >> @@ -1155,6 +1155,24 @@ cpufreq_table_set_inefficient(struct >> cpufreq_policy *policy, >>       return -EINVAL; >>   } >>   +static inline unsigned int >> +cpufreq_table_max_nonboost_freq(struct cpufreq_policy *policy) >> +{ >> +    struct cpufreq_frequency_table *pos; >> +    unsigned int max = 0; >> + >> +    if (!policy->freq_table) >> +        return 0; >> + >> +    /* The table may be unsorted, scan all of it for the highest >> one. */ >> +    cpufreq_for_each_valid_entry(pos, policy->freq_table) { >> +        if (!(pos->flags & CPUFREQ_BOOST_FREQ) && pos->frequency > max) >> +            max = pos->frequency; >> +    } >> + >> +    return max; >> +} >> + >>   static inline int parse_perf_domain(int cpu, const char *list_name, >>                       const char *cell_name, >>                       struct of_phandle_args *args) >> @@ -1219,6 +1237,12 @@ cpufreq_table_set_inefficient(struct >> cpufreq_policy *policy, >>       return -EINVAL; >>   } >>   +static inline unsigned int >> +cpufreq_table_max_nonboost_freq(struct cpufreq_policy *policy) >> +{ >> +    return 0; >> +} >> + >>   static inline int of_perf_domain_get_sharing_cpumask(int pcpu, >> const char *list_name, >>                                const char *cell_name, struct cpumask >> *cpumask, >>                                struct of_phandle_args *pargs) >> diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c >> index d19a65461ae8..253c53ca6a74 100644 >> --- a/kernel/power/energy_model.c >> +++ b/kernel/power/energy_model.c >> @@ -255,15 +255,30 @@ static int em_compute_costs(struct device *dev, >> struct em_perf_state *table, >>                   unsigned long flags) >>   { >>       unsigned long prev_cost = ULONG_MAX; >> +    struct cpufreq_policy *policy; >> +    unsigned int max_nonboost = 0; >> +    bool prev_boost = false; >>       int i, ret; >>         /* This is needed only for CPUs and EAS skip other devices */ >>       if (!_is_cpu_device(dev)) >>           return 0; >>   +    policy = cpufreq_cpu_get(dev->id); >> +    if (policy) { >> +        max_nonboost = cpufreq_table_max_nonboost_freq(policy); >> +        cpufreq_cpu_put(policy); >> +    } >> + >>       /* Compute the cost of each performance state. */ >>       for (i = nr_states - 1; i >= 0; i--) { >>           unsigned long power_res, cost; >> +        bool boost = table[i].frequency > max_nonboost; >> + >> +        if (boost != prev_boost) { > > We expect in EM fwk that the frequencies are sorted ascending > and we return error during setup if the driver callback fails > to provide that. > Therefore, in this code we don't have to deal with random > 'boost' labels with gaps between. > Hi Lukasz, Thanks for the review. You are right. The boundary is derived from the highest non-boost frequency, so with an ascending table the boost states always form a contiguous top segment, and prev_boost is redundant. > Let's make all OPPs which are 'boost' equally possible > to reach (at least in theory), so label them as > 'efficient'. I think this is fair in 'boosting' case scenario > and energy has not that importance in it. > > So simply something like, would be enough IMHO: > > if (boost) >     prev_cost = ULONG_MAX; > Agreed, this is simpler and gives the same result for the non-boost states. Boost states are no longer compared with each other, which is also a sensible semantic. I will drop prev_boost and use the above in v2. Thanks, Guo > >> +            prev_boost = boost; >> +            prev_cost = ULONG_MAX; >> +        } >>             if ((flags & EM_PERF_DOMAIN_ARTIFICIAL) && cb->get_cost) { >>               ret = cb->get_cost(dev, table[i].frequency, &cost); >> >> --- >> base-commit: f1ac44c32cba88ad65dcecd4a279661d14e93651 >> base-tree: >> git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master >> change-id: 20261029-em-rank-boost-separately-a7e7c7d78058 >> >> Best regards, >> -- >> Guo Chen >