From patchwork Mon Jul 24 07:58:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Zhan X-Patchwork-Id: 124691 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp1658565vqg; Mon, 24 Jul 2023 01:41:35 -0700 (PDT) X-Google-Smtp-Source: APBJJlHdemEF1TOTbIQ/l79DWnCIdZHYgFiuv2i+L5/MWzfJQ75owk+p71OSt/t6x8hermS+AbJ3 X-Received: by 2002:a05:6a00:a24:b0:668:7325:e184 with SMTP id p36-20020a056a000a2400b006687325e184mr10481169pfh.16.1690188095448; Mon, 24 Jul 2023 01:41:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690188095; cv=none; d=google.com; s=arc-20160816; b=ccCor7RoqqHStt2+y6V7ME5BM7UZ+oZTGR571gww8I5ok+qcPpcp6HrM2txJlYDOOx IZuWRWWnK7LgD78zsxkwfVvtI12sVpNRm/TbYPfYMlHPFsbr43k9QGb81RY2Yt2wI9z+ BQJTtnUFtIL4IFrBA7Bf0qkkNsE1pcB2zpU+ZVABKxPnmC0fAufycudvrNqKAPAIZe+k YSelX1XUzKqAjxAVXFTb2D4NbAk53gxHJHsrSLlZet4IOgn06SriRDr1qcYcCbdg5pvP KymWf1la0iwJPzwZtRVQeo2AH3PuQq7r/cydShqLvkjehJkUloJky0c4/3PCbPagVgBO j3Tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=DnyqO8OFTjETv1myCrd+y/tcfOIWX7ICWO8Sqm6CPjM=; fh=quKEYhqt8Xk4LI7PTV8yd6b9flULUDw4jVgTIxbnnvM=; b=RLLNrWLeFim8H8ERBpDZGOJ10d7YcJ4zn3U8ERBYyrfdgTuisSp/MRxKv1J3g927XJ /bGpW+144XDw7aM2ZjJaf5q2p+Vsvwq74bLLrcTLuA1w89Wg2lwnP2yv3xcufCJ9CqsP bfZXNWbpMiOoX+6jBWMPtXa2diGm2Tx8Cw7kCsc2ebI+rI6K/YWlR9N5Z/BhfdLt6vKW uI3kxIA0w+ixdBG08UigOdJkZu+41Hnt+LRnthDiCNQY9ZhcFVNI9U/u+XlyfGsfnW5b zngZ/ge/ryoqNEw9k+KszhKvulk4Mc2Sr9Hc8amzN2mhcEQQGdAFkhcei2hpPc3N/+iG /uFQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=hisilicon.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y11-20020a056a001c8b00b0065dfb27ee3fsi8417281pfw.246.2023.07.24.01.41.21; Mon, 24 Jul 2023 01:41:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=hisilicon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231152AbjGXIBP (ORCPT + 99 others); Mon, 24 Jul 2023 04:01:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230496AbjGXIBG (ORCPT ); Mon, 24 Jul 2023 04:01:06 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B876FA; Mon, 24 Jul 2023 01:01:03 -0700 (PDT) Received: from dggpeml500019.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4R8Xcd2kB4zVjnx; Mon, 24 Jul 2023 15:59:29 +0800 (CST) Received: from localhost.localdomain (10.67.165.2) by dggpeml500019.china.huawei.com (7.185.36.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Mon, 24 Jul 2023 16:01:00 +0800 From: Jie Zhan To: , CC: , , , , , , , Subject: [RFC PATCH] cpufreq: Support per-policy performance boost Date: Mon, 24 Jul 2023 15:58:27 +0800 Message-ID: <20230724075827.4160512-1-zhanjie9@hisilicon.com> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpeml500019.china.huawei.com (7.185.36.137) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772290672121960807 X-GMAIL-MSGID: 1772290672121960807 The boost control currently applies to the whole system. However, users may prefer to boost a subset of cores in order to provide prioritized performance to workloads running on the boosted cores. Enable per-policy boost by adding a 'local_boost' sysfs interface. This can be found at: /sys/devices/system/cpu/cpufreq/policy<*>/local_boost Same to the global boost switch, writing 1/0 to 'local_boost' enables/disables boost on a cpufreq policy respectively. The user view of global and local boost controls should be: 1. Enabling global boost initially enables local boost on all policies, and local boost can then be enabled or disabled individually on each policy, given that the platform does support so. 2. Disabling global boost makes enabling local boost illegal, while writing 0 to 'local_boost' is fine but takes no effect. A possible question could be: why not just limiting 'scaling_max_freq'? Well, the fundamental difference is that 'local_boost' could be more user-friendly. When global boost is enabled, it is not straightforward to figure out the base frequency for setting 'scaling_max_freq' to a non-boost value. Also, this is supposed to take effect on the physical upper frequency limit, reflected through 'cpuinfo_max_freq'. Signed-off-by: Jie Zhan Reviewed-by: Wei Xu --- drivers/cpufreq/cpufreq.c | 33 +++++++++++++++++++++++++++++++++ include/linux/cpufreq.h | 3 +++ 2 files changed, 36 insertions(+) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 6b52ebe5a890..14579c59f7ba 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -621,6 +621,35 @@ static ssize_t store_boost(struct kobject *kobj, struct kobj_attribute *attr, } define_one_global_rw(boost); +static ssize_t show_local_boost(struct cpufreq_policy *policy, char *buf) +{ + return sysfs_emit(buf, "%d\n", policy->local_boost_enabled); +} + +static ssize_t store_local_boost(struct cpufreq_policy *policy, + const char *buf, size_t count) +{ + int ret, enable; + + ret = kstrtoint(buf, 10, &enable); + if (ret || enable < 0 || enable > 1) + return -EINVAL; + + if (enable && !cpufreq_driver->boost_enabled) + return -EINVAL; + + cpus_read_lock(); + ret = cpufreq_driver->set_boost(policy, enable); + cpus_read_unlock(); + + if (ret) + return ret; + + policy->local_boost_enabled = enable; + + return count; +} + static struct cpufreq_governor *find_governor(const char *str_governor) { struct cpufreq_governor *t; @@ -931,6 +960,7 @@ cpufreq_freq_attr_rw(scaling_min_freq); cpufreq_freq_attr_rw(scaling_max_freq); cpufreq_freq_attr_rw(scaling_governor); cpufreq_freq_attr_rw(scaling_setspeed); +cpufreq_freq_attr_rw(local_boost); static struct attribute *cpufreq_attrs[] = { &cpuinfo_min_freq.attr, @@ -944,6 +974,7 @@ static struct attribute *cpufreq_attrs[] = { &scaling_driver.attr, &scaling_available_governors.attr, &scaling_setspeed.attr, + &local_boost.attr, NULL }; ATTRIBUTE_GROUPS(cpufreq); @@ -2716,6 +2747,8 @@ int cpufreq_boost_trigger_state(int state) ret = cpufreq_driver->set_boost(policy, state); if (ret) goto err_reset_state; + + policy->local_boost_enabled = state; } cpus_read_unlock(); diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index 26e2eb399484..a99a48ac9fdb 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -140,6 +140,9 @@ struct cpufreq_policy { */ bool dvfs_possible_from_any_cpu; + /* Per policy boost enabled flag. */ + bool local_boost_enabled; + /* Cached frequency lookup from cpufreq_driver_resolve_freq. */ unsigned int cached_target_freq; unsigned int cached_resolved_idx;