Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3341370imu; Sun, 23 Dec 2018 23:22:05 -0800 (PST) X-Google-Smtp-Source: ALg8bN4IeDIS6yOJHqDMW7RS8Wyj3sA6sEjWpbTfZ93vgxT26UPug+Gu1NQ9qT+qE49znrrWbUq/ X-Received: by 2002:a17:902:24a2:: with SMTP id w31mr11842505pla.216.1545636125713; Sun, 23 Dec 2018 23:22:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545636125; cv=none; d=google.com; s=arc-20160816; b=vQ8VLUt0Lb2+t8a+3j8PCpS6wo2nlGfote30W3h4qhH+DDTXlGicxVSyEcR7n9k5kM +a9HLuDqETg/l/hpHbKz5mzuBUj9QydLJkXK64a71mcC0zg7miv6l6yi9WcgBNyY4Atg W3XEIlERV+j0VQT5U45SEuDSIv7Mz/gu9E0teM8WN4+BLTDEqPASk+bDJ3vwVGy7CQzz QMxw/add9qYB9HaJpI15zBUFFYSs9Cf5WRWX6/OlwxDsD0JzbIpjlcZ7XrRtK+B/96+K wgcnGw+iDBmA7EorCYezf0ESooostniBuKe2GYOR3cRlEFbUgy6O55CSUkXnrKWNOHkc Y1Mw== 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=Ma4E/NceizBXROgl9m2eANowcP2GvdqKT7QLoRwUUbg=; b=cElQmOuj/hoEnqKJHUQmYBIQj599fZvS5HPcaQ9M7RmvaVmMuJlvpHPdtMQo42XEqL 5xcbgN+KXP/PDgfhkHkb6MXO9j2ZuJ3lF6nxoFCdbCtxzfOkIqPbvfG9SI4Hy7/Ipj2j lmi8zydVmuOIZ8DY5a44NbAgX4+LZ7H2fqtIQFPZYKekzfU/lbK2DUXCXqtRC7eQ61PO vSCUnanb4elH+KtmboRT8GiNFAGIPR6QW4OQPe1nymTk8amr0OlkId6os9ll2o4NUFuf S1SLd/D9PiyUja22jex82dEX1SUdFPIr9kFCBA45ThckOmrmYmslksh9qwdljNJcj3UX 9wqg== 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 v14si29452072pfc.76.2018.12.23.23.21.50; Sun, 23 Dec 2018 23:22:05 -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 S1726770AbeLXHUY (ORCPT + 99 others); Mon, 24 Dec 2018 02:20:24 -0500 Received: from sci-ig2.spreadtrum.com ([222.66.158.135]:64224 "EHLO SHSQR01.unisoc.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1725946AbeLXHUY (ORCPT ); Mon, 24 Dec 2018 02:20:24 -0500 X-Greylist: delayed 1055 seconds by postgrey-1.27 at vger.kernel.org; Mon, 24 Dec 2018 02:20:23 EST Received: from SHSQR01.spreadtrum.com (localhost [127.0.0.2] (may be forged)) by SHSQR01.unisoc.com with ESMTP id wBO71huB079215 for ; Mon, 24 Dec 2018 15:01:43 +0800 (CST) (envelope-from Chunyan.Zhang@unisoc.com) Received: from ig2.spreadtrum.com (bjmbx01.spreadtrum.com [10.0.64.7]) by SHSQR01.spreadtrum.com with ESMTPS id wBO6wpej070222 (version=TLSv1 cipher=AES256-SHA bits=256 verify=NO); Mon, 24 Dec 2018 14:58:51 +0800 (CST) (envelope-from Chunyan.Zhang@unisoc.com) Received: from localhost (10.0.93.106) by BJMBX01.spreadtrum.com (10.0.64.7) with Microsoft SMTP Server (TLS) id 15.0.847.32; Mon, 24 Dec 2018 14:59:54 +0800 From: Chunyan Zhang To: Ingo Molnar , Peter Zijlstra CC: Vincent Wang , , Chunyan Zhang , Chunyan Zhang Subject: [PATCH] sched/cpufreq: calculate util / max firstly in get_next_freq() Date: Mon, 24 Dec 2018 14:59:07 +0800 Message-ID: <1545634747-22401-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: SHCAS02.spreadtrum.com (10.0.1.202) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL: SHSQR01.spreadtrum.com wBO6wpej070222 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 max, which are parameters used in get_next_freq(), will be cpu frequency, instead of cpu util or 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 / max; This patch will fix this overflow risk by calulating util / max firstly, whether they be frequency or util. Signed-off-by: Vincent Wang Signed-off-by: Chunyan Zhang --- kernel/sched/cpufreq_schedutil.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c index 3fffad3..7c372db1 100644 --- a/kernel/sched/cpufreq_schedutil.c +++ b/kernel/sched/cpufreq_schedutil.c @@ -166,8 +166,9 @@ static unsigned int get_next_freq(struct sugov_policy *sg_policy, struct cpufreq_policy *policy = sg_policy->policy; unsigned int freq = arch_scale_freq_invariant() ? policy->cpuinfo.max_freq : policy->cur; + unsigned int ratio = util * 100 / max; - freq = (freq + (freq >> 2)) * util / max; + freq = (freq + (freq >> 2)) * ratio / 100; if (freq == sg_policy->cached_raw_freq && !sg_policy->need_freq_update) return sg_policy->next_freq; -- 2.7.4