From patchwork Tue Dec 8 04:16:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 339692 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp3368044jai; Mon, 7 Dec 2020 20:18:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJyPS1BNL4LBvda5yW2hou0mVyuvjcpqzwZiZLgF3dNkkGQxp+9SYOPoKrAvso2k/uWnlURl X-Received: by 2002:a17:906:fa88:: with SMTP id lt8mr21904314ejb.408.1607401132321; Mon, 07 Dec 2020 20:18:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607401132; cv=none; d=google.com; s=arc-20160816; b=XgKcTv99hjH5L7R5kvx0SVWcrl7tACJAQcvIYMpM/3QFPfJ2X/FoAWx9npFP3Fy911 BItT6/r5Cd36wSvsxl0MH9rRutadQQqo3L7Ixi1BwMw8YxZ/OFetg2GTUqcbf0rFIxhw 7okBU9TomZxfVhUZhvNF+CyNiOWJs0Wdef+dIEVq7HEve4IuvtxByHXmlxVGRP5FyEz2 f1FatoOgoETrbW9nBN1vjIboCaIPHBddBpoFwnOGmMdRfoHIbgmhBwN2wDQPYQ6CCZ9r J/ReQDMlQu4RBtIJPEuJmpcyLwN7P65tKLgapRoqfZKVe51kc53R0x5qUQxR4UasyhVx q8HQ== 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 :dkim-signature; bh=BgroMCzBx2iJ+H86ym6L2CJTtyoziwkrOuTzWQtpDQI=; b=gpHRopPCW0he4P5JE71oFpniNYAkdwGT1A9EB76R9ezq0LqtQABH54sgKlfyNp+Dme 757B0hKvsD7cbuoNCnNsgGbHLJDrAu43KPZZXGadSJbOYKI6C+ZwpgNRwLjUV3WqyGQu N0QtlNaQOndU4HusrDmtC7IxoELwz5o/B3fHdc2S8HXkqlm/0hd9lmFfTV631erEUPDd aDmVJsJE/zYNQX8YmI6Lxe/WqRusMOBJdpUJhXAB31hnxNqN0PSeCMCBOXO6mJHxPvRQ hiC4/Fl+OpdLTlgIxbb8BPxG6ZQrXuHEB6GrZTPvo8KuaQsNRdDe4yjou7PQNsPE0j7Z 4ptQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uQtBmECu; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id pw18si4674329ejb.163.2020.12.07.20.18.52; Mon, 07 Dec 2020 20:18:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uQtBmECu; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726779AbgLHESY (ORCPT + 8 others); Mon, 7 Dec 2020 23:18:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726794AbgLHESY (ORCPT ); Mon, 7 Dec 2020 23:18:24 -0500 Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A14EC0617A6 for ; Mon, 7 Dec 2020 20:17:10 -0800 (PST) Received: by mail-pl1-x643.google.com with SMTP id t6so757879plq.1 for ; Mon, 07 Dec 2020 20:17:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BgroMCzBx2iJ+H86ym6L2CJTtyoziwkrOuTzWQtpDQI=; b=uQtBmECumfix2CVr91vbg+9llcJiypEeUz0345IueFtDzmXZlPAjtJyohrI28xhdRP jRrbaOGvoUJY7kqpFCK3qB+vjR5NxuMl9GocAKXYLkVTtsr0bnewBp31OGYx/DpxvV24 NX9Y26SZAanZhM4fSLvXgyhslSULTS+xX0YktbEWQV3MwOx5h+NI1H+PgrNKOZhYJAFL hK2/U/2UVpZ3Wd5Bf3OW8/E/jSVRf98I+1nsusXozTrJ0P3evMaU10teFpxOeOe9tGuS N9FTQVfI2x/wOK6XO9Zk6x1X7FTj9cU3+nrQrQwFlcDPdMvSd7gW5SmCffbVFf1Kx1tJ jaBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BgroMCzBx2iJ+H86ym6L2CJTtyoziwkrOuTzWQtpDQI=; b=lTsvBgqT/z9xpqIajtbvGUaV4/CNqgQcqCbiH3Na1PEC+HbEP6glFBoqtJ7hN3PcZ1 j034Rgpg+WPuva+Okm9iMbs9XMSj03cSCWzk7wYl43XgYijiOmIeM4WXWT6iyVq1us27 2KiKC8FNsHhXCE99CpoFgG888D8SpgR1OkGIhHuCRXRTEiVco/Oy60F1/T7xA/DHvb+V B1oSFL2WTft0Y5DHMhy200LhLdPZrxy7hlWJr+VG2DjvkVVIFAsCH+DiCxZyYwcFe//O bbUjG/Z+0UVOCSeWLFoWlGQgCeY/tegULlPk8KHmVU9uHWK2XqS0Ye8DG41lEr4YAhu0 XEIg== X-Gm-Message-State: AOAM530BVW6tltNXWCALN3R/qqvC/8RtTwm/fiSrENniFMitoMzQPnU1 c/yeu/VmO2hC2oTbzH5wznDPbg== X-Received: by 2002:a17:902:bb92:b029:d9:e9bf:b775 with SMTP id m18-20020a170902bb92b02900d9e9bfb775mr19582388pls.24.1607401030082; Mon, 07 Dec 2020 20:17:10 -0800 (PST) Received: from localhost ([122.172.136.109]) by smtp.gmail.com with ESMTPSA id x128sm16035595pfx.52.2020.12.07.20.17.09 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Dec 2020 20:17:09 -0800 (PST) From: Viresh Kumar To: Ingo Molnar , Peter Zijlstra , Vincent Guittot , Juri Lelli , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , "Rafael J. Wysocki" , Viresh Kumar Cc: linux-kernel@vger.kernel.org, Quentin Perret , Lukasz Luba , "Rafael J . Wysocki" , linux-pm@vger.kernel.org Subject: [PATCH V5 2/3] sched/core: Rename schedutil_cpu_util() and allow rest of the kernel to use it Date: Tue, 8 Dec 2020 09:46:56 +0530 Message-Id: X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org There is nothing schedutil specific in schedutil_cpu_util(), rename it to effective_cpu_util(). Also create and expose another wrapper sched_cpu_util() which can be used by other parts of the kernel, like thermal core (that will be done in a later commit). Acked-by: Rafael J. Wysocki Signed-off-by: Viresh Kumar --- include/linux/sched.h | 5 +++++ kernel/sched/core.c | 10 ++++++++-- kernel/sched/cpufreq_schedutil.c | 2 +- kernel/sched/fair.c | 6 +++--- kernel/sched/sched.h | 10 +++++----- 5 files changed, 22 insertions(+), 11 deletions(-) -- 2.25.0.rc1.19.g042ed3e048af diff --git a/include/linux/sched.h b/include/linux/sched.h index 063cd120b459..3a2fe4fe6155 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1926,6 +1926,11 @@ extern long sched_getaffinity(pid_t pid, struct cpumask *mask); #define TASK_SIZE_OF(tsk) TASK_SIZE #endif +#ifdef CONFIG_SMP +/* Returns effective CPU energy utilization, as seen by the scheduler */ +unsigned long sched_cpu_util(int cpu, unsigned long max); +#endif /* CONFIG_SMP */ + #ifdef CONFIG_RSEQ /* diff --git a/kernel/sched/core.c b/kernel/sched/core.c index b81265aec4a0..0a24b93dd7f3 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -5138,8 +5138,8 @@ struct task_struct *idle_task(int cpu) * based on the task model parameters and gives the minimal utilization * required to meet deadlines. */ -unsigned long schedutil_cpu_util(int cpu, unsigned long util_cfs, - unsigned long max, enum schedutil_type type, +unsigned long effective_cpu_util(int cpu, unsigned long util_cfs, + unsigned long max, enum cpu_util_type type, struct task_struct *p) { unsigned long dl_util, util, irq; @@ -5223,6 +5223,12 @@ unsigned long schedutil_cpu_util(int cpu, unsigned long util_cfs, return min(max, util); } + +unsigned long sched_cpu_util(int cpu, unsigned long max) +{ + return effective_cpu_util(cpu, cpu_util_cfs(cpu_rq(cpu)), max, + ENERGY_UTIL, NULL); +} #endif /* CONFIG_SMP */ /** diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c index 2d44befb322b..e71627a3792b 100644 --- a/kernel/sched/cpufreq_schedutil.c +++ b/kernel/sched/cpufreq_schedutil.c @@ -178,7 +178,7 @@ static unsigned long sugov_get_util(struct sugov_cpu *sg_cpu) sg_cpu->max = max; sg_cpu->bw_dl = cpu_bw_dl(rq); - return schedutil_cpu_util(sg_cpu->cpu, util, max, FREQUENCY_UTIL, NULL); + return effective_cpu_util(sg_cpu->cpu, util, max, FREQUENCY_UTIL, NULL); } /** diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 290f9e38378c..0e1c8eb7ad53 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -6499,7 +6499,7 @@ compute_energy(struct task_struct *p, int dst_cpu, struct perf_domain *pd) * is already enough to scale the EM reported power * consumption at the (eventually clamped) cpu_capacity. */ - sum_util += schedutil_cpu_util(cpu, util_cfs, cpu_cap, + sum_util += effective_cpu_util(cpu, util_cfs, cpu_cap, ENERGY_UTIL, NULL); /* @@ -6509,7 +6509,7 @@ compute_energy(struct task_struct *p, int dst_cpu, struct perf_domain *pd) * NOTE: in case RT tasks are running, by default the * FREQUENCY_UTIL's utilization can be max OPP. */ - cpu_util = schedutil_cpu_util(cpu, util_cfs, cpu_cap, + cpu_util = effective_cpu_util(cpu, util_cfs, cpu_cap, FREQUENCY_UTIL, tsk); max_util = max(max_util, cpu_util); } @@ -6607,7 +6607,7 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) * IOW, placing the task there would make the CPU * overutilized. Take uclamp into account to see how * much capacity we can get out of the CPU; this is - * aligned with schedutil_cpu_util(). + * aligned with sched_cpu_util(). */ util = uclamp_rq_util_with(cpu_rq(cpu), util, p); if (!fits_capacity(util, cpu_cap)) diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 0db6bcf0881f..495e7ea278ce 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -2486,22 +2486,22 @@ static inline unsigned long capacity_orig_of(int cpu) } /** - * enum schedutil_type - CPU utilization type + * enum cpu_util_type - CPU utilization type * @FREQUENCY_UTIL: Utilization used to select frequency * @ENERGY_UTIL: Utilization used during energy calculation * * The utilization signals of all scheduling classes (CFS/RT/DL) and IRQ time * need to be aggregated differently depending on the usage made of them. This - * enum is used within schedutil_freq_util() to differentiate the types of + * enum is used within effective_cpu_util() to differentiate the types of * utilization expected by the callers, and adjust the aggregation accordingly. */ -enum schedutil_type { +enum cpu_util_type { FREQUENCY_UTIL, ENERGY_UTIL, }; -unsigned long schedutil_cpu_util(int cpu, unsigned long util_cfs, - unsigned long max, enum schedutil_type type, +unsigned long effective_cpu_util(int cpu, unsigned long util_cfs, + unsigned long max, enum cpu_util_type type, struct task_struct *p); static inline unsigned long cpu_bw_dl(struct rq *rq)