Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp1397439imp; Fri, 22 Feb 2019 02:41:01 -0800 (PST) X-Google-Smtp-Source: AHgI3IbEml+7blCsNbgO6ZtR8272bfN2qnZwNvLFiS/opOUhDR0u14DgEFS/V2U4I/Mr+9WwP/es X-Received: by 2002:a62:528e:: with SMTP id g136mr3646383pfb.111.1550832061213; Fri, 22 Feb 2019 02:41:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550832061; cv=none; d=google.com; s=arc-20160816; b=XUqr7V7Z8vByPDuAY4xfZBDrOMDaWtuwa1GrkHDzViauwiiFJfzmEiAowfLyFqeBTQ 4c2DA4BT8o6pX9lgRPBvL+aU9aCfV1wziao+/ZEpa1whCfN7A4DK+5ErvaiYj8RljIzH BdkpVc60jC4kI+9UMFhdo+AbUEWNROkP0Ok8VKHUDCNq7ffnQkexT1N7B8Swg2uPJv7F vUZsIWVYhzhbzK1DUg+BxFTTZtPfPMtFFNcL+sqwi6PPzWztA0AWPIVb0jaCN/UdaJHE s54aleSKRn2vDR3HIgkCgFaltnXEuCGT+0qV0WEY48dDjFJjLG6hFFMSTcJc0yLqLYQp qNyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=tfMhT3geLNsgIwFRs1sNvpakFiuD9RKWr9zwZP00paQ=; b=zCEXUo//+T9IzqT35F/B3ulNwSjJgxQh4D1a8BOeojmY7XH1WnDLwIBdjBHZ2Q9vS6 iKE+6chp/t/e2Szd52WNSvx8omnNbjNf4KZFelp/YDrERA3vXj9UOSq+DiQaEaZy6if9 oFM9fg1gaUEg5Vy2gF1/1j97+Gwwo/U6HQhUxUemKXoQD2yrnv2H6khP1LWaXpuRm8NC Z9X+o1QwAAWt4OnNRO3oIACQDCduem5637VReGWlOY54eyTQm3p9zR+otyQcyfqYxlJ5 KcX+mzokqqOsJN8uCP0Lzl5NjO+pCmge706k25zLQEbuLb2P1pJUdgocJfk2TYjQY3x+ AbGA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u2si1061066pgo.544.2019.02.22.02.40.45; Fri, 22 Feb 2019 02:41:01 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726971AbfBVKjv (ORCPT + 99 others); Fri, 22 Feb 2019 05:39:51 -0500 Received: from sci-ig2.spreadtrum.com ([222.66.158.135]:31988 "EHLO SHSQR01.spreadtrum.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1726184AbfBVKjv (ORCPT ); Fri, 22 Feb 2019 05:39:51 -0500 Received: from ig2.spreadtrum.com (bjmbx02.spreadtrum.com [10.0.64.8]) by SHSQR01.spreadtrum.com with ESMTPS id x1MAbiPf021828 (version=TLSv1 cipher=AES256-SHA bits=256 verify=NO); Fri, 22 Feb 2019 18:37:45 +0800 (CST) (envelope-from Chunyan.Zhang@unisoc.com) Received: from localhost (10.0.93.106) by BJMBX02.spreadtrum.com (10.0.64.8) with Microsoft SMTP Server (TLS) id 15.0.847.32; Fri, 22 Feb 2019 18:38:26 +0800 From: Chunyan Zhang To: Ingo Molnar , Peter Zijlstra CC: Vincent Wang , Quentin Perret , , Chunyan Zhang , Chunyan Zhang Subject: [PATCH V4] sched/cpufreq: initialize iowait_boost_max and iowait_boost with cpu capacity Date: Fri, 22 Feb 2019 18:37:46 +0800 Message-ID: <1550831866-32749-1-git-send-email-chunyan.zhang@unisoc.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.0.93.106] X-ClientProxiedBy: SHCAS01.spreadtrum.com (10.0.1.201) To BJMBX02.spreadtrum.com (10.0.64.8) X-MAIL: SHSQR01.spreadtrum.com x1MAbiPf021828 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vincent Wang When a task that is in_iowait state is enqueued, cpufreq_update_util() will be invoked with SCHED_CPUFREQ_IOWAIT flag. In this case,the value of util and cap, which are parameters used in map_util_freq(), may be cpu frequency, instead of cpu util and capactiy. For some 32bit architectures, the size of unsigned long is 32. When calculating freq, there may be an overflow error in this expression: freq = (freq + (freq >> 2)) * util / cap; To fix the issus, a new member min is added into the struct sg_cpu to store the capacity of policy's min frequency. iowait_boost and iowait_boost_max will be initialized with capacity instead of frequency. Signed-off-by: Vincent Wang Signed-off-by: Chunyan Zhang --- Changes from V3 (https://lkml.org/lkml/2019/1/29/346): * Switch to a new method that will not lead in more calculation. Changes from v2 (https://lkml.org/lkml/2019/1/9/1227): * Fix for 32bit architectures only. Changes from V1 (https://lkml.org/lkml/2018/12/24/22): * Rebased onto v5.0-rc1; * Addressed comments from Quentin Perret. --- kernel/sched/cpufreq_schedutil.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c index 033ec7c45f13..04eb44a9b550 100644 --- a/kernel/sched/cpufreq_schedutil.c +++ b/kernel/sched/cpufreq_schedutil.c @@ -53,6 +53,7 @@ struct sugov_cpu { unsigned long bw_dl; unsigned long max; + unsigned long min; /* The field below is for single-CPU policies only: */ #ifdef CONFIG_NO_HZ_COMMON @@ -275,12 +276,11 @@ static unsigned long sugov_get_util(struct sugov_cpu *sg_cpu) { struct rq *rq = cpu_rq(sg_cpu->cpu); unsigned long util = cpu_util_cfs(rq); - unsigned long max = arch_scale_cpu_capacity(NULL, sg_cpu->cpu); - sg_cpu->max = max; sg_cpu->bw_dl = cpu_bw_dl(rq); - return schedutil_freq_util(sg_cpu->cpu, util, max, FREQUENCY_UTIL); + return schedutil_freq_util(sg_cpu->cpu, util, sg_cpu->max, + FREQUENCY_UTIL); } /** @@ -304,7 +304,7 @@ static bool sugov_iowait_reset(struct sugov_cpu *sg_cpu, u64 time, return false; sg_cpu->iowait_boost = set_iowait_boost - ? sg_cpu->sg_policy->policy->min : 0; + ? sg_cpu->min : 0; sg_cpu->iowait_boost_pending = set_iowait_boost; return true; @@ -351,7 +351,7 @@ static void sugov_iowait_boost(struct sugov_cpu *sg_cpu, u64 time, } /* First wakeup after IO: start with minimum boost */ - sg_cpu->iowait_boost = sg_cpu->sg_policy->policy->min; + sg_cpu->iowait_boost = sg_cpu->min; } /** @@ -398,7 +398,7 @@ static void sugov_iowait_apply(struct sugov_cpu *sg_cpu, u64 time, * reach the minimum. */ sg_cpu->iowait_boost >>= 1; - if (sg_cpu->iowait_boost < sg_cpu->sg_policy->policy->min) { + if (sg_cpu->iowait_boost < sg_cpu->min) { sg_cpu->iowait_boost = 0; return; } @@ -823,6 +823,8 @@ static int sugov_start(struct cpufreq_policy *policy) { struct sugov_policy *sg_policy = policy->governor_data; unsigned int cpu; + unsigned long max_cap = arch_scale_cpu_capacity(NULL, policy->cpu); + unsigned long min_cap = max_cap * policy->min / policy->cpuinfo.max_freq; sg_policy->freq_update_delay_ns = sg_policy->tunables->rate_limit_us * NSEC_PER_USEC; sg_policy->last_freq_update_time = 0; @@ -837,7 +839,9 @@ static int sugov_start(struct cpufreq_policy *policy) memset(sg_cpu, 0, sizeof(*sg_cpu)); sg_cpu->cpu = cpu; sg_cpu->sg_policy = sg_policy; - sg_cpu->iowait_boost_max = policy->cpuinfo.max_freq; + sg_cpu->max = max_cap; + sg_cpu->min = min_cap; + sg_cpu->iowait_boost_max = max_cap; } for_each_cpu(cpu, policy->cpus) { -- 2.17.1