From patchwork Tue Nov 24 06:26:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 331374 Delivered-To: patch@linaro.org Received: by 2002:a92:5e16:0:0:0:0:0 with SMTP id s22csp270069ilb; Mon, 23 Nov 2020 22:27:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJzXZvNl2TfiVS0rOU78aylGLeNOnef0qTuZS7sA7XbvIzuA60yt+o5z8uMKyD4GLSOsw9WB X-Received: by 2002:a17:906:ee2:: with SMTP id x2mr2914780eji.326.1606199277511; 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=RsNP3288odj50nVfPk5sEJDykvq96I5q961lUAWeEaHPLx1qii5OwJ2zyB1PLyAjKv A0cESZo87VpIPNeNf0U88gua11eyaikiWOaaUYMEhKFtfvwNDk1Hp3GC+ofI+Irz5Ygc S9aNApBUEjLEtONY8KuBx7p7HMhM0OY9o+glyxvpfwC+6Fyn1VP9EXEThFnJyXzqujcs 3tWM/ds7qaI44YCKhBUrhdnEK9fAFx0INg54PRxx9sshLhRb3bTPaD45GOfweWUAu1+E J+66OSUC6YLJ5pgcTRbZ9eTvTtjm2UX0m8L3+MarByPzttUcdaI2sDscBOVA7D5NvUYK LOag== 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=+97LgEscNYSrtbk3WYtj7uo7a8C61/n23cCotlpS30k=; b=mIN0HKaBwlR6G7jByNDMCdRKMhzE7lswW+a9JuPzMSpGDeBS/LgGArhVh9pwDlhXEC Rop2bellP4lUJ5aEIMXCWBFxQrl5V6TszDiNgCkDedb+EofLmIsx6E1VIEf+kmX5GjaV dfPiBPL2PXWoyH8Qowejo1KhCPCRIZdTW1c23i7X6aghk9WRVwwMFMFBcCcIzO5+E4/h OTPwhT5DJMKRzQeKchQqcYy/m+DOwKxsS0cPhgv5vaIR4dLykpxACjpBm8L8kGk6vZu7 IYZsdEvIjcxZkEMeaXLzn7DCv2Tn8so6mYsKD9iSWXz2ElCH2dL1i5pYNePaafUyj6Qi NQxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=N+cINADS; 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=N+cINADS; 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 S1728358AbgKXG00 (ORCPT + 8 others); Tue, 24 Nov 2020 01:26:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729304AbgKXG00 (ORCPT ); Tue, 24 Nov 2020 01:26:26 -0500 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 007DDC0613D6 for ; Mon, 23 Nov 2020 22:26:25 -0800 (PST) Received: by mail-pg1-x543.google.com with SMTP id 62so16539918pgg.12 for ; Mon, 23 Nov 2020 22:26:25 -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=+97LgEscNYSrtbk3WYtj7uo7a8C61/n23cCotlpS30k=; b=N+cINADShT8YraSqlTdZta+rOmsbeQZDkjE937B0CTomLJn9rQY9tCPNqm0xIkpBbG oBs41DYIIrVRZ+Qy0l+FCxXmySQ4Xa1BddBgXehCcs76FAAtkfK4HH9sv2VvdItMx1vC BkABZ8OaPo6PZ+hlBdFZp+4CmdzVYGHFx2oHeOImqsuAm0Ghnd2lRlTd+okA7sRn74By u4ewCQxcB2GXUisBEvunMwBm2LWcxVTyjVw/Pf13vOVYr9kCxIN6y+ApNgnyFHdUf7Gk qrYHzQ0VfQQLEExJZQ9bHn3KXQ7tUc+Eh9QqHUDGZaC7BWTVTH2mzr+K7LQ6F9duj42e K+FQ== 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=+97LgEscNYSrtbk3WYtj7uo7a8C61/n23cCotlpS30k=; b=h/OEMqoNnS+NVSJ+bLyPxF0gTTetSTahUqe00FnzvIPTvNAGODpyEnWXtWmwXaaATC yVnrKF4LoGapl1RAHqa4ud5O5dVS385ODDwUo8kRSIbd5h6NQ3RC6g2vea6ZpebtdYzX foBa2RkQ08y6JRan6eAXuafzO2gHlY1OfaFBSXY1SeLha9NyIo3KO0dQLjPhBdDkxdD1 /SPiIzKaY/NWzduTYqp9WSr2ccAVx46HcOpb5bJc1XbikVWtwXrx+vdjqGJjYnRgJbWE iFzgghcb2pu0rV6P8XhiE51Tz1If/hYgcSICV+qhY/gJCxnqW9dgxwq8pKi5HVBIzGKt 5a/Q== X-Gm-Message-State: AOAM532k8oZvdh2LEGyMa4HrZ96nsoWocojyD6lgSRg58FHbdlUPRte3 0wz2TqBNq/AV/jYwvGsW1oZIHw== X-Received: by 2002:a17:90a:5d8c:: with SMTP id t12mr3300114pji.156.1606199185442; Mon, 23 Nov 2020 22:26:25 -0800 (PST) Received: from localhost ([122.172.12.172]) by smtp.gmail.com with ESMTPSA id 138sm13083011pfy.88.2020.11.23.22.26.24 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Nov 2020 22:26:24 -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 1/3] sched/core: Move schedutil_cpu_util() to core.c Date: Tue, 24 Nov 2020 11:56:14 +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(), move it to core.c and define it only for CONFIG_SMP. Signed-off-by: Viresh Kumar --- kernel/sched/core.c | 108 +++++++++++++++++++++++++++++++ kernel/sched/cpufreq_schedutil.c | 106 ------------------------------ kernel/sched/sched.h | 12 +--- 3 files changed, 109 insertions(+), 117 deletions(-) -- 2.25.0.rc1.19.g042ed3e048af Acked-by: Rafael J. Wysocki diff --git a/kernel/sched/core.c b/kernel/sched/core.c index d2003a7d5ab5..b81265aec4a0 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -5117,6 +5117,114 @@ struct task_struct *idle_task(int cpu) return cpu_rq(cpu)->idle; } +#ifdef CONFIG_SMP +/* + * This function computes an effective utilization for the given CPU, to be + * used for frequency selection given the linear relation: f = u * f_max. + * + * The scheduler tracks the following metrics: + * + * cpu_util_{cfs,rt,dl,irq}() + * cpu_bw_dl() + * + * Where the cfs,rt and dl util numbers are tracked with the same metric and + * synchronized windows and are thus directly comparable. + * + * The cfs,rt,dl utilization are the running times measured with rq->clock_task + * which excludes things like IRQ and steal-time. These latter are then accrued + * in the irq utilization. + * + * The DL bandwidth number otoh is not a measured metric but a value computed + * 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, + struct task_struct *p) +{ + unsigned long dl_util, util, irq; + struct rq *rq = cpu_rq(cpu); + + if (!uclamp_is_used() && + type == FREQUENCY_UTIL && rt_rq_is_runnable(&rq->rt)) { + return max; + } + + /* + * Early check to see if IRQ/steal time saturates the CPU, can be + * because of inaccuracies in how we track these -- see + * update_irq_load_avg(). + */ + irq = cpu_util_irq(rq); + if (unlikely(irq >= max)) + return max; + + /* + * Because the time spend on RT/DL tasks is visible as 'lost' time to + * CFS tasks and we use the same metric to track the effective + * utilization (PELT windows are synchronized) we can directly add them + * to obtain the CPU's actual utilization. + * + * CFS and RT utilization can be boosted or capped, depending on + * utilization clamp constraints requested by currently RUNNABLE + * tasks. + * When there are no CFS RUNNABLE tasks, clamps are released and + * frequency will be gracefully reduced with the utilization decay. + */ + util = util_cfs + cpu_util_rt(rq); + if (type == FREQUENCY_UTIL) + util = uclamp_rq_util_with(rq, util, p); + + dl_util = cpu_util_dl(rq); + + /* + * For frequency selection we do not make cpu_util_dl() a permanent part + * of this sum because we want to use cpu_bw_dl() later on, but we need + * to check if the CFS+RT+DL sum is saturated (ie. no idle time) such + * that we select f_max when there is no idle time. + * + * NOTE: numerical errors or stop class might cause us to not quite hit + * saturation when we should -- something for later. + */ + if (util + dl_util >= max) + return max; + + /* + * OTOH, for energy computation we need the estimated running time, so + * include util_dl and ignore dl_bw. + */ + if (type == ENERGY_UTIL) + util += dl_util; + + /* + * There is still idle time; further improve the number by using the + * irq metric. Because IRQ/steal time is hidden from the task clock we + * need to scale the task numbers: + * + * max - irq + * U' = irq + --------- * U + * max + */ + util = scale_irq_capacity(util, irq, max); + util += irq; + + /* + * Bandwidth required by DEADLINE must always be granted while, for + * FAIR and RT, we use blocked utilization of IDLE CPUs as a mechanism + * to gracefully reduce the frequency when no tasks show up for longer + * periods of time. + * + * Ideally we would like to set bw_dl as min/guaranteed freq and util + + * bw_dl as requested freq. However, cpufreq is not yet ready for such + * an interface. So, we only do the latter for now. + */ + if (type == FREQUENCY_UTIL) + util += cpu_bw_dl(rq); + + return min(max, util); +} +#endif /* CONFIG_SMP */ + /** * find_process_by_pid - find a process with a matching PID value. * @pid: the pid in question. diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c index e254745a82cb..2d44befb322b 100644 --- a/kernel/sched/cpufreq_schedutil.c +++ b/kernel/sched/cpufreq_schedutil.c @@ -169,112 +169,6 @@ static unsigned int get_next_freq(struct sugov_policy *sg_policy, return cpufreq_driver_resolve_freq(policy, freq); } -/* - * This function computes an effective utilization for the given CPU, to be - * used for frequency selection given the linear relation: f = u * f_max. - * - * The scheduler tracks the following metrics: - * - * cpu_util_{cfs,rt,dl,irq}() - * cpu_bw_dl() - * - * Where the cfs,rt and dl util numbers are tracked with the same metric and - * synchronized windows and are thus directly comparable. - * - * The cfs,rt,dl utilization are the running times measured with rq->clock_task - * which excludes things like IRQ and steal-time. These latter are then accrued - * in the irq utilization. - * - * The DL bandwidth number otoh is not a measured metric but a value computed - * 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, - struct task_struct *p) -{ - unsigned long dl_util, util, irq; - struct rq *rq = cpu_rq(cpu); - - if (!uclamp_is_used() && - type == FREQUENCY_UTIL && rt_rq_is_runnable(&rq->rt)) { - return max; - } - - /* - * Early check to see if IRQ/steal time saturates the CPU, can be - * because of inaccuracies in how we track these -- see - * update_irq_load_avg(). - */ - irq = cpu_util_irq(rq); - if (unlikely(irq >= max)) - return max; - - /* - * Because the time spend on RT/DL tasks is visible as 'lost' time to - * CFS tasks and we use the same metric to track the effective - * utilization (PELT windows are synchronized) we can directly add them - * to obtain the CPU's actual utilization. - * - * CFS and RT utilization can be boosted or capped, depending on - * utilization clamp constraints requested by currently RUNNABLE - * tasks. - * When there are no CFS RUNNABLE tasks, clamps are released and - * frequency will be gracefully reduced with the utilization decay. - */ - util = util_cfs + cpu_util_rt(rq); - if (type == FREQUENCY_UTIL) - util = uclamp_rq_util_with(rq, util, p); - - dl_util = cpu_util_dl(rq); - - /* - * For frequency selection we do not make cpu_util_dl() a permanent part - * of this sum because we want to use cpu_bw_dl() later on, but we need - * to check if the CFS+RT+DL sum is saturated (ie. no idle time) such - * that we select f_max when there is no idle time. - * - * NOTE: numerical errors or stop class might cause us to not quite hit - * saturation when we should -- something for later. - */ - if (util + dl_util >= max) - return max; - - /* - * OTOH, for energy computation we need the estimated running time, so - * include util_dl and ignore dl_bw. - */ - if (type == ENERGY_UTIL) - util += dl_util; - - /* - * There is still idle time; further improve the number by using the - * irq metric. Because IRQ/steal time is hidden from the task clock we - * need to scale the task numbers: - * - * max - irq - * U' = irq + --------- * U - * max - */ - util = scale_irq_capacity(util, irq, max); - util += irq; - - /* - * Bandwidth required by DEADLINE must always be granted while, for - * FAIR and RT, we use blocked utilization of IDLE CPUs as a mechanism - * to gracefully reduce the frequency when no tasks show up for longer - * periods of time. - * - * Ideally we would like to set bw_dl as min/guaranteed freq and util + - * bw_dl as requested freq. However, cpufreq is not yet ready for such - * an interface. So, we only do the latter for now. - */ - if (type == FREQUENCY_UTIL) - util += cpu_bw_dl(rq); - - return min(max, util); -} - static unsigned long sugov_get_util(struct sugov_cpu *sg_cpu) { struct rq *rq = cpu_rq(sg_cpu->cpu); diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index df80bfcea92e..0db6bcf0881f 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -2484,7 +2484,6 @@ static inline unsigned long capacity_orig_of(int cpu) { return cpu_rq(cpu)->cpu_capacity_orig; } -#endif /** * enum schedutil_type - CPU utilization type @@ -2501,8 +2500,6 @@ enum schedutil_type { ENERGY_UTIL, }; -#ifdef CONFIG_CPU_FREQ_GOV_SCHEDUTIL - unsigned long schedutil_cpu_util(int cpu, unsigned long util_cfs, unsigned long max, enum schedutil_type type, struct task_struct *p); @@ -2533,14 +2530,7 @@ static inline unsigned long cpu_util_rt(struct rq *rq) { return READ_ONCE(rq->avg_rt.util_avg); } -#else /* CONFIG_CPU_FREQ_GOV_SCHEDUTIL */ -static inline unsigned long schedutil_cpu_util(int cpu, unsigned long util_cfs, - unsigned long max, enum schedutil_type type, - struct task_struct *p) -{ - return 0; -} -#endif /* CONFIG_CPU_FREQ_GOV_SCHEDUTIL */ +#endif #ifdef CONFIG_HAVE_SCHED_AVG_IRQ static inline unsigned long cpu_util_irq(struct rq *rq)