Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp3444290ybk; Tue, 19 May 2020 04:59:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzM1G8BO7OQQxnrZog0MyAFDNKeD96oxYwpKZFDoK/OuGgrWwNDFlK5eo98zXVyq2wwMHNr X-Received: by 2002:a17:906:c7d1:: with SMTP id dc17mr18145509ejb.166.1589889573286; Tue, 19 May 2020 04:59:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589889573; cv=none; d=google.com; s=arc-20160816; b=zJrKCWvLdZTvZp+Gn9cCxwXCf1T+xVWkpZ1fKr3CEt4ok0UR2G8wWZ2A0KEKXaAs5t RjwnANE/sIbGQCQ9Lp0PVQpSZIpvwRM82aEopRt/gxCkWCKLV4G2sNeXJo/GwDP9yI20 iM8OweeapA1lIRSvrQxJMB9Pe4Qw6m/sfr91zrCapfqlLj3CqFjqxy2AYSNktnyUva92 j2OxHtQSdvBYRvjsXsWgCv2mA1u2p+cEZQpY3T+rEZ/xS+0g3eq6k+I4R5oCVj8Zh1+r hpg7eiwV+kFPucWFtQqd4TnVTFLqfMOz0aQGsd5aSUJgm/Cp/8Zcsr+YMGdmyA9S5hSr HyxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=lDUr1tmaEtE1sB33J9knWAEW27HprNlIHtMBPfVyen8=; b=RFM5tGtzTADNsLzGw5pX5bWZ0pHh3TzjW3pvnvur3koo2HETqAMgDTe3i64/LMz5Yk CMfAWaUiCmgmR9qs2rtT4xkToQAB4+KTp6a3rDb2fqBgu6WYDMUg6Ok9IqtdpuytEZiU 36LV4h/BiI/IH5v2DplaktbTB4i64exsMoaMifv+c0aTNe0w/uAPE2PtW9N6C/c6FJVX F6e+E83X7inaGffiHZdg3b1mB+QF2yGh3h0qxatnxaSlNzGjGQcO1ISvsNNRU8DzFiNw QTetr4HgTi1Eo4MkjoyFDZwBUp+tWOYhN3dJNyWMPk4oHKjsaJGYpUU1bv69hUSqc6QY 97Cg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id aq3si8451367ejc.439.2020.05.19.04.59.10; Tue, 19 May 2020 04:59:33 -0700 (PDT) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728745AbgESL52 (ORCPT + 99 others); Tue, 19 May 2020 07:57:28 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:4815 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726949AbgESL52 (ORCPT ); Tue, 19 May 2020 07:57:28 -0400 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id B53B34391CBB79186702; Tue, 19 May 2020 19:57:25 +0800 (CST) Received: from [127.0.0.1] (10.166.215.101) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.487.0; Tue, 19 May 2020 19:57:17 +0800 Subject: Re: [RFC PATCH v3 1/2] cpufreq: change '.set_boost' to act on only one policy To: , , , CC: , , , , , References: <1589888489-13828-1-git-send-email-wangxiongfeng2@huawei.com> <1589888489-13828-2-git-send-email-wangxiongfeng2@huawei.com> From: Xiongfeng Wang Message-ID: <060a79bb-00d0-982a-4e4b-1cf4511ccce2@huawei.com> Date: Tue, 19 May 2020 19:57:16 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: <1589888489-13828-2-git-send-email-wangxiongfeng2@huawei.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.166.215.101] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020/5/19 19:41, Xiongfeng Wang wrote: > Macro 'for_each_active_policy()' is defined internally. To avoid some > cpufreq driver needing this macro to iterate over all the policies in > '.set_boost' callback, we redefine '.set_boost' to act on only one > policy and pass the policy as an argument. > 'cpufreq_boost_trigger_state()' iterate over all the policies to set > boost for the system. This is preparation for adding SW BOOST support > for CPPC. > > Signed-off-by: Xiongfeng Wang > --- > drivers/cpufreq/acpi-cpufreq.c | 4 ++-- > drivers/cpufreq/cpufreq.c | 53 +++++++++++++++++++++--------------------- > include/linux/cpufreq.h | 2 +- > 3 files changed, 30 insertions(+), 29 deletions(-) > > diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c > index 289e8ce..b0a9eb5 100644 > --- a/drivers/cpufreq/acpi-cpufreq.c > +++ b/drivers/cpufreq/acpi-cpufreq.c > @@ -126,7 +126,7 @@ static void boost_set_msr_each(void *p_en) > boost_set_msr(enable); > } > > -static int set_boost(int val) > +static int set_boost(struct cpufreq_policy *policy, int val) > { > get_online_cpus(); > on_each_cpu(boost_set_msr_each, (void *)(long)val, 1); > @@ -162,7 +162,7 @@ static ssize_t store_cpb(struct cpufreq_policy *policy, const char *buf, > if (ret || val > 1) > return -EINVAL; > > - set_boost(val); > + set_boost(policy, val); > > return count; > } My original thought is as below. Since '/sys/devices/system/cpu/cpufreq/boost' can be used to set boost for the system. The file 'cpb' below each policy can be used to set boost for the policy. But this will change the existing logic. --- a/drivers/cpufreq/acpi-cpufreq.c +++ b/drivers/cpufreq/acpi-cpufreq.c @@ -126,12 +126,14 @@ static void boost_set_msr_each(void *p_en) boost_set_msr(enable); } -static int set_boost(int val) +static int set_boost(struct cpufreq_policy *policy, int val) { get_online_cpus(); - on_each_cpu(boost_set_msr_each, (void *)(long)val, 1); + on_each_cpu_mask(policy->cpus, boost_set_msr_each, + (void *)(long)val, 1); put_online_cpus(); - pr_debug("Core Boosting %sabled.\n", val ? "en" : "dis"); + pr_debug("CPU %*pbl: Core Boosting %sabled.\n", + cpumask_pr_args(policy->cpus), val ? "en" : "dis"); return 0; } @@ -162,7 +164,7 @@ static ssize_t store_cpb(struct cpufreq_policy *policy, const char *buf, if (ret || val > 1) return -EINVAL; - set_boost(val); + set_boost(policy, val); return count; } > diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c > index d03f250..d0d86b1 100644 > --- a/drivers/cpufreq/cpufreq.c > +++ b/drivers/cpufreq/cpufreq.c > > int cpufreq_boost_trigger_state(int state) > { > + struct cpufreq_policy *policy; > unsigned long flags; > int ret = 0; > > @@ -2570,16 +2565,22 @@ int cpufreq_boost_trigger_state(int state) > cpufreq_driver->boost_enabled = state; > write_unlock_irqrestore(&cpufreq_driver_lock, flags); > > - ret = cpufreq_driver->set_boost(state); > - if (ret) { > - write_lock_irqsave(&cpufreq_driver_lock, flags); > - cpufreq_driver->boost_enabled = !state; > - write_unlock_irqrestore(&cpufreq_driver_lock, flags); > - > - pr_err("%s: Cannot %s BOOST\n", > - __func__, state ? "enable" : "disable"); > + for_each_active_policy(policy) { > + ret = cpufreq_driver->set_boost(policy, state); > + if (ret) > + goto err_reset_state; > } > > + return 0; > + > +err_reset_state: > + write_lock_irqsave(&cpufreq_driver_lock, flags); > + cpufreq_driver->boost_enabled = !state; > + write_unlock_irqrestore(&cpufreq_driver_lock, flags); > + > + pr_err("%s: Cannot %s BOOST\n", > + __func__, state ? "enable" : "disable"); > + > return ret; > } Is it better to set 'boost_enabled' after set boost successfully rather than setting it in the begining and resetting it if setting boost failed. Thanks, Xiongfeng > > diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h > index 67d5950..3494f67 100644 > --- a/include/linux/cpufreq.h > +++ b/include/linux/cpufreq.h > @@ -367,7 +367,7 @@ struct cpufreq_driver { > > /* platform specific boost support code */ > bool boost_enabled; > - int (*set_boost)(int state); > + int (*set_boost)(struct cpufreq_policy *policy, int state); > }; > > /* flags */ >