Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp696889pxb; Thu, 5 Nov 2020 10:30:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJwFocniZOPtszZ8bbfVvHhKGcqR4H/K7kXdDii75CeTOf8nCgWE1mSBw8RQ/dcBpRYm8Eu3 X-Received: by 2002:a50:b062:: with SMTP id i89mr3984964edd.248.1604601010253; Thu, 05 Nov 2020 10:30:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604601010; cv=none; d=google.com; s=arc-20160816; b=NKeWkd6cwfMyAND3scr7SpJeBKhej7sXaLERTN9yYEH/q2ol79QFrbF9VqjmKjJv5s 5sOYWyvGjxdF69OXiQLKXY48gUW+JHgUahfGuFmkhJv3sh95PeE3gHk+aIsHSD6BIbYN HvxWWZzDrXWBQVVFSOm3XqaCHk9DCH3yU5qJH7DR0ox+CYqrg88bhHZS2+2h4yZeMuPD XLOCKNR035VakFaO1s7Oyh2ydycvWk3KyvwHlumLqfH1MElFl0i0koE4ikfNev04moAf s/D/sxA36O0vRiKTN1pblsP93KQMmqfgP3gZg4b/Z2+OIGhUoWw1VDEO8dGwRKmTHIeo 9PXg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=NT8s5Ee6MGshB5pJyVXwOUU0A7+C+hueqiPooodmlDY=; b=aQzLGQvO92nt0lSe8Df0o3+IXRs++G2Uqc7TpIsJ0/mRpyV1OuSvNZgEogZYcBNTSo ifnwIqH6+9SjX5LchhPkxs7qCXUlF1o43JDwAOYdohq3ZG9M7iBHV7hBypubnmZj5TMK 63m4rlkFoVmyHqiLI9+h8lXzfB9/da95maOg3sk7HEMq/rL873VhHh+SJoJ9QqOe4/lx 2aacoPqZhOroUVst+ScKxX6KVdh1O4qDrnP73waP+GNeelzkAGIaIusBJ8ZIw0aFeskV Jz3UnJPBQJypq5B7qvZjDCNJfakGNmQ2yUC6yYhwW6Fg/uuFQDWpng0tt6nfmcHUl0SG pwwQ== 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 b24si1776115edu.147.2020.11.05.10.29.46; Thu, 05 Nov 2020 10:30:10 -0800 (PST) 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 S1731779AbgKESZX (ORCPT + 99 others); Thu, 5 Nov 2020 13:25:23 -0500 Received: from cloudserver094114.home.pl ([79.96.170.134]:44024 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726729AbgKESZW (ORCPT ); Thu, 5 Nov 2020 13:25:22 -0500 Received: from 89-64-88-191.dynamic.chello.pl (89.64.88.191) (HELO kreacher.localnet) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83.514) id eb3d0aa0ebe85b20; Thu, 5 Nov 2020 19:25:19 +0100 From: "Rafael J. Wysocki" To: Linux PM Cc: "Rafael J. Wysocki" , Viresh Kumar , Srinivas Pandruvada , Zhang Rui , LKML Subject: [PATCH 1/2] cpufreq: Introduce target min and max frequency hints Date: Thu, 05 Nov 2020 19:23:34 +0100 Message-ID: <2233690.N3OVLkotou@kreacher> In-Reply-To: <7417968.Ghue05m4RV@kreacher> References: <7417968.Ghue05m4RV@kreacher> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rafael J. Wysocki Some cpufreq drivers, like intel_pstate (in the passive mode with HWP enabled) or the CPPC driver, take the "target frequency" coming from the governor as a hint to pass to the hardware rather than the exact value to apply. Then, the hardware may choose to run at whatever performance point it regards as appropriate, given the hint and some other data available to it. Of course, the performance point chosen by the hardware should stay within the policy min and max limits, but in some cases it may be necessary to request the hardware to limit the range of performance points to consider beyond that. For example, if the powersave governor is in use, it attempts to make the hardware run at the policy min frequency, but that may not actually work if the hardware thinks that it has a reason to run faster and the policy max limit is above the policy min. In those cases, it is useful to pass additional information to the driver to indicate that it should tell the hardware to consider a narrower range of performance points, so add two new fields, target_min and target_max, to struct cpufreq_policy for this purpose and make the powersave and performance governors set them to indicate that the CPU is expected to run exactly at the given frequency (the policy min or max, respectively). Signed-off-by: Rafael J. Wysocki --- drivers/cpufreq/cpufreq.c | 3 +++ drivers/cpufreq/cpufreq_performance.c | 4 ++++ drivers/cpufreq/cpufreq_powersave.c | 4 ++++ include/linux/cpufreq.h | 16 ++++++++++++++++ 4 files changed, 27 insertions(+) Index: linux-pm/include/linux/cpufreq.h =================================================================== --- linux-pm.orig/include/linux/cpufreq.h +++ linux-pm/include/linux/cpufreq.h @@ -63,6 +63,8 @@ struct cpufreq_policy { unsigned int min; /* in kHz */ unsigned int max; /* in kHz */ + unsigned int target_min; /* in kHz */ + unsigned int target_max; /* in kHz */ unsigned int cur; /* in kHz, only needed if cpufreq * governors are used */ unsigned int suspend_freq; /* freq to set during suspend */ Index: linux-pm/drivers/cpufreq/cpufreq.c =================================================================== --- linux-pm.orig/drivers/cpufreq/cpufreq.c +++ linux-pm/drivers/cpufreq/cpufreq.c @@ -2272,6 +2272,9 @@ static int cpufreq_init_governor(struct pr_debug("%s: for CPU %u\n", __func__, policy->cpu); + policy->target_min = policy->cpuinfo.min_freq; + policy->target_max = policy->cpuinfo.max_freq; + if (policy->governor->init) { ret = policy->governor->init(policy); if (ret) { Index: linux-pm/drivers/cpufreq/cpufreq_performance.c =================================================================== --- linux-pm.orig/drivers/cpufreq/cpufreq_performance.c +++ linux-pm/drivers/cpufreq/cpufreq_performance.c @@ -14,6 +14,10 @@ static void cpufreq_gov_performance_limits(struct cpufreq_policy *policy) { pr_debug("setting to %u kHz\n", policy->max); + + policy->target_min = policy->max; + policy->target_max = policy->max; + __cpufreq_driver_target(policy, policy->max, CPUFREQ_RELATION_H); } Index: linux-pm/drivers/cpufreq/cpufreq_powersave.c =================================================================== --- linux-pm.orig/drivers/cpufreq/cpufreq_powersave.c +++ linux-pm/drivers/cpufreq/cpufreq_powersave.c @@ -14,6 +14,10 @@ static void cpufreq_gov_powersave_limits(struct cpufreq_policy *policy) { pr_debug("setting to %u kHz\n", policy->min); + + policy->target_min = policy->min; + policy->target_max = policy->min; + __cpufreq_driver_target(policy, policy->min, CPUFREQ_RELATION_L); }