From patchwork Tue Nov 24 06:26:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 331373 Delivered-To: patch@linaro.org Received: by 2002:a92:5e16:0:0:0:0:0 with SMTP id s22csp270075ilb; Mon, 23 Nov 2020 22:27:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJyHZvdW0qiqhQa11kYJ20AESD/Nv2/PgTXMHoJclCKKVeNLmaGp21jc+jVMScKCqdZFGyqD X-Received: by 2002:aa7:d8c4:: with SMTP id k4mr2459149eds.248.1606199277956; Mon, 23 Nov 2020 22:27:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606199277; cv=none; d=google.com; s=arc-20160816; b=EfZEtiImrYeqYG9v6lRZ2r/h7Ohl0j7xIC/D+IhVKUGG2S81kd2lb9ABzxWsJtK0x9 USrl5zkbwNFJYBKoXdlBUmhc796z6Ae/Sy5iRqL/xXOCcAWEznonGfBYiOwWUW6ouw6k PWWyOrfgHsT7SGAsuwre/MmXHlKE8xXbVLQaEtwck+cXSXmVh7rwC3WrwR31m+A0hBvR Los2fBaMaBCps7vnnAHwq/zkw9qTQTZ8CzhNk6bAJ9n1nQne9jVl/e8NaKiDCu1Z/l/7 5l3Pmyggq5Ea93UE9SSrsWhb31JhCL2RPSMcPm4tfU+cQ1w38BOFoXggMmMufcvCTmG6 ITNw== 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=qNtM0MaukWKLeykgjeC5xsgWS0X78S8oFPhzD7Rh5OM=; b=YOeB3thGCWA1ZS8XcFMPZI2DHgS9nPgKufTdkbcWtA0VPtuVrDNAMThQ9xGDoceiWI 2qoKfhysQSgSnvIKgxgvCLGqOLeuiSsw4rbkaCgJ35NLHrATniwwkC1n8K8hjWfqkQoI Nx19z29etZQS+1d151rmZ3EIENtblTHt3QUgGuEEEYBPsvDsFAvvKLXQVpEUllsq4yGv z4iDmjpKAvRKvMSPEPfkPzF7AkGKo2ek1vLhORvk4e/Eq1tbRN8kLRdKOrU1/LsxUqQa D75HJG6CuQJ7H6mzbUeq6yEKK5+LsPx1VpRVQm2VjRD2eMn3aR6iv3Q/EIS3C8lgLzWv Ip7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qpwXt+1Q; 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 y5si8044503ede.457.2020.11.23.22.27.57; Mon, 23 Nov 2020 22:27:57 -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=qpwXt+1Q; 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 S1728965AbgKXG0b (ORCPT + 8 others); Tue, 24 Nov 2020 01:26:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729700AbgKXG0a (ORCPT ); Tue, 24 Nov 2020 01:26:30 -0500 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A76D1C0613CF for ; Mon, 23 Nov 2020 22:26:29 -0800 (PST) Received: by mail-pf1-x441.google.com with SMTP id n137so7437376pfd.3 for ; Mon, 23 Nov 2020 22:26:29 -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=qNtM0MaukWKLeykgjeC5xsgWS0X78S8oFPhzD7Rh5OM=; b=qpwXt+1QC2Ho8ePpan7K4yqGgIkQru3q8ErF9OyRl0suCRvMvfeUYF328TZ/vm5BCk fSmpv7eYRnbriUuEcqBUjn1WnbjO2P+6jUxSAuNnQZl6613pBpS1uH+Y5gjrwI0Wqy/n s5JtLRBe9AyyqYSyfjOXx4/ECnJxovAzq37weRR+wNo903yxXgnkc9QZ2PLaeG0R/4jJ dRM0bh+t31PJ5L6nAd95QDs1pQAtsx0b0Aa5umx5cPYQOlj13KCY80l5LqjRi1eZU/1D 6uOKCuN6PoPgnAIVQO9WKcLM3kNz1JxSPp/BQ5v8NiljQVP8xdXqqv1nBRchIU4s2SzB xYLQ== 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=qNtM0MaukWKLeykgjeC5xsgWS0X78S8oFPhzD7Rh5OM=; b=i2G+HpyCsyk+StbCYGvqJAQAKCZx1s6VHyxlyilHlrkgKV5NpHFLqS9MT+y+BGIWqE z0azSFrnUk7DJhOYgehK4QmAIOOZiV+XQ7L1YcxOBz3vfPKgeFNt5IQjrtoqHoK9FoCq +4lw0FXCCXCgBfsORIIAe8JGIIdfnGwtCBkVx8sbaJ8w6FF91DPj8AvzCjid6/BJIpzc SA/LJDitrIexfFk5si8VCF3dtA9KopYL5QGIE0X0sn2YvDfkAvv3c6yfaUL5TAHrANjR 9shXbUMktlg2TNi0GvcDWXl4qON8zkdGG5f1CuvG9kL/V2F1Zp7YR2e84qc/FcJnPK0G Xf0A== X-Gm-Message-State: AOAM530MUGuF01KzHbcZdPFgkcLKJQwgI8Rpl+wl3YL9PYT+dIsJQjyt BFcVGVSxc+go0Uu6uf9MnJojzg== X-Received: by 2002:a17:90a:ead2:: with SMTP id ev18mr3088956pjb.91.1606199189204; Mon, 23 Nov 2020 22:26:29 -0800 (PST) Received: from localhost ([122.172.12.172]) by smtp.gmail.com with ESMTPSA id s26sm12632501pgv.93.2020.11.23.22.26.28 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Nov 2020 22:26:28 -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 , linux-pm@vger.kernel.org Subject: [PATCH V4 2/3] sched/core: Rename schedutil_cpu_util() and allow rest of the kernel to use it Date: Tue, 24 Nov 2020 11:56:15 +0530 Message-Id: <9a5442b916f9667e714dd84fe4e3fc26f8bcc887.1606198885.git.viresh.kumar@linaro.org> 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). Signed-off-by: Viresh Kumar --- include/linux/sched.h | 21 +++++++++++++++++++++ kernel/sched/core.c | 11 +++++++++-- kernel/sched/cpufreq_schedutil.c | 2 +- kernel/sched/fair.c | 6 +++--- kernel/sched/sched.h | 19 ++----------------- 5 files changed, 36 insertions(+), 23 deletions(-) -- 2.25.0.rc1.19.g042ed3e048af Acked-by: Rafael J. Wysocki diff --git a/include/linux/sched.h b/include/linux/sched.h index 063cd120b459..926b944dae5e 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1926,6 +1926,27 @@ extern long sched_getaffinity(pid_t pid, struct cpumask *mask); #define TASK_SIZE_OF(tsk) TASK_SIZE #endif +#ifdef CONFIG_SMP +/** + * 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 sched_cpu_util() to differentiate the types of + * utilization expected by the callers, and adjust the aggregation accordingly. + */ +enum cpu_util_type { + FREQUENCY_UTIL, + ENERGY_UTIL, +}; + +/* Returns effective CPU utilization, as seen by the scheduler */ +unsigned long sched_cpu_util(int cpu, enum cpu_util_type type, + unsigned long max); +#endif /* CONFIG_SMP */ + #ifdef CONFIG_RSEQ /* diff --git a/kernel/sched/core.c b/kernel/sched/core.c index b81265aec4a0..845c976ccd53 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,13 @@ unsigned long schedutil_cpu_util(int cpu, unsigned long util_cfs, return min(max, util); } + +unsigned long sched_cpu_util(int cpu, enum cpu_util_type type, + unsigned long max) +{ + return effective_cpu_util(cpu, cpu_util_cfs(cpu_rq(cpu)), max, type, + 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..4fab3b930ace 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -2485,23 +2485,8 @@ static inline unsigned long capacity_orig_of(int cpu) return cpu_rq(cpu)->cpu_capacity_orig; } -/** - * enum schedutil_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 - * utilization expected by the callers, and adjust the aggregation accordingly. - */ -enum schedutil_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)