From patchwork Wed Jul 5 08:58:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juri Lelli X-Patchwork-Id: 107046 Delivered-To: patch@linaro.org Received: by 10.182.135.102 with SMTP id pr6csp565700obb; Wed, 5 Jul 2017 02:00:33 -0700 (PDT) X-Received: by 10.99.45.6 with SMTP id t6mr19506100pgt.209.1499245233080; Wed, 05 Jul 2017 02:00:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499245233; cv=none; d=google.com; s=arc-20160816; b=kbTDIDGO2JA8HDOdFtW1BwJ/Gfs5hunvCZP1qaPLknkboiIVbU+O/BrdYOBAouEikZ zbFeiEeES3LJzVtmc72DZNyPCgvFjROgINS8uvIUCxNv7kUlFkXnMClvx0QMP7e7PGvS xPk5y40Cc98/bP9/WdTcCi+x3o+EisZ+Gpj49jqDs/sqQc141xCJbuJlODRfnozTxMZ1 5uogKR1LFETTVnq6s1Ir4bspcG0YbBwJCY9iERj9rZps25Vt9t7RSn8sXdUx+TQymT9k yJp7CoigcsZbCsk0OnAjeMwaYyVF3gSioMnQgUuVMLmyPSdaz+UfTPzAYmsvGZAxlvG/ FeOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=YjPt89uT47ZNR393kQ1RdkViVMuuiLw67DxXNDgiE60=; b=EgGA0S55ILpbdgZf00tkx+UZd73Q2JWMNgOtxkP1zHdqOdh89homxQyiZzRZ5rwxZE ZPi9KsBD21X89lkTaZRko7QLYj/C1YY68mtZZGQ2RT5pA+BR7dLVpGGFMIICJRBNvY/K 0F13DmrigmE405JkgioyeArq8ritsj8Ln8qdiGUqszUej5TZaTm6du26T3lLTyKJ/855 IPn9TzNKatHgcTVWkWeskZtzEFgDNeLJ/wdkh7TDe92tcjsNhJoootEtpJB8X7Ifvtkl jvIlysM1m2+hocKAy7/60E+J1IqFkMqlcpRTfR8HQI0sY0U5w/SAdEIXmFiP4A7BCQt2 igsA== 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 e86si16522770pfl.428.2017.07.05.02.00.32; Wed, 05 Jul 2017 02:00:33 -0700 (PDT) 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 S1752556AbdGEJA3 (ORCPT + 25 others); Wed, 5 Jul 2017 05:00:29 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:53482 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752431AbdGEJA0 (ORCPT ); Wed, 5 Jul 2017 05:00:26 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 53E3D15BE; Wed, 5 Jul 2017 02:00:16 -0700 (PDT) Received: from cam-smtp0.cambridge.arm.com (e106622-lin.cambridge.arm.com [10.1.211.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E721C3F581; Wed, 5 Jul 2017 02:00:12 -0700 (PDT) From: Juri Lelli To: peterz@infradead.org, mingo@redhat.com, rjw@rjwysocki.net, viresh.kumar@linaro.org Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, tglx@linutronix.de, vincent.guittot@linaro.org, rostedt@goodmis.org, luca.abeni@santannapisa.it, claudio@evidence.eu.com, tommaso.cucinotta@santannapisa.it, bristot@redhat.com, mathieu.poirier@linaro.org, tkjos@android.com, joelaf@google.com, andresoportus@google.com, morten.rasmussen@arm.com, dietmar.eggemann@arm.com, patrick.bellasi@arm.com, juri.lelli@arm.com, Ingo Molnar , "Rafael J . Wysocki" Subject: [RFC PATCH v1 1/8] sched/cpufreq_schedutil: make use of DEADLINE utilization signal Date: Wed, 5 Jul 2017 09:58:58 +0100 Message-Id: <20170705085905.6558-2-juri.lelli@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170705085905.6558-1-juri.lelli@arm.com> References: <20170705085905.6558-1-juri.lelli@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org SCHED_DEADLINE tracks active utilization signal with a per dl_rq variable named running_bw. Make use of that to drive cpu frequency selection: add up FAIR and DEADLINE contribution to get the required CPU capacity to handle both requirements (while RT still selects max frequency). Co-authored-by: Claudio Scordino Signed-off-by: Juri Lelli Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Rafael J. Wysocki Cc: Viresh Kumar Cc: Luca Abeni --- Changes from RFCv0: - use BW_SHIFT (Peter) - add comment about guaranteed and requested freq (Peter) - modify comment about go to max behaviour (Claudio) --- include/linux/sched/cpufreq.h | 2 -- kernel/sched/cpufreq_schedutil.c | 25 +++++++++++++++---------- 2 files changed, 15 insertions(+), 12 deletions(-) -- 2.11.0 Acked-by: Viresh Kumar diff --git a/include/linux/sched/cpufreq.h b/include/linux/sched/cpufreq.h index d2be2ccbb372..39640bb3a8ee 100644 --- a/include/linux/sched/cpufreq.h +++ b/include/linux/sched/cpufreq.h @@ -11,8 +11,6 @@ #define SCHED_CPUFREQ_DL (1U << 1) #define SCHED_CPUFREQ_IOWAIT (1U << 2) -#define SCHED_CPUFREQ_RT_DL (SCHED_CPUFREQ_RT | SCHED_CPUFREQ_DL) - #ifdef CONFIG_CPU_FREQ struct update_util_data { void (*func)(struct update_util_data *data, u64 time, unsigned int flags); diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c index 076a2e31951c..f2494d1fc8ef 100644 --- a/kernel/sched/cpufreq_schedutil.c +++ b/kernel/sched/cpufreq_schedutil.c @@ -157,12 +157,17 @@ static unsigned int get_next_freq(struct sugov_policy *sg_policy, static void sugov_get_util(unsigned long *util, unsigned long *max) { struct rq *rq = this_rq(); - unsigned long cfs_max; + unsigned long dl_util = (rq->dl.running_bw * SCHED_CAPACITY_SCALE) + >> BW_SHIFT; - cfs_max = arch_scale_cpu_capacity(NULL, smp_processor_id()); + *max = arch_scale_cpu_capacity(NULL, smp_processor_id()); - *util = min(rq->cfs.avg.util_avg, cfs_max); - *max = cfs_max; + /* + * Ideally we would like to set util_dl as min/guaranteed freq and + * util_cfs + util_dl as requested freq. However, cpufreq is not yet + * ready for such an interface. So, we only do the latter for now. + */ + *util = min(rq->cfs.avg.util_avg + dl_util, *max); } static void sugov_set_iowait_boost(struct sugov_cpu *sg_cpu, u64 time, @@ -226,7 +231,7 @@ static void sugov_update_single(struct update_util_data *hook, u64 time, busy = sugov_cpu_is_busy(sg_cpu); - if (flags & SCHED_CPUFREQ_RT_DL) { + if (flags & SCHED_CPUFREQ_RT) { next_f = policy->cpuinfo.max_freq; } else { sugov_get_util(&util, &max); @@ -266,7 +271,7 @@ static unsigned int sugov_next_freq_shared(struct sugov_cpu *sg_cpu, u64 time) j_sg_cpu->iowait_boost = 0; continue; } - if (j_sg_cpu->flags & SCHED_CPUFREQ_RT_DL) + if (j_sg_cpu->flags & SCHED_CPUFREQ_RT) return policy->cpuinfo.max_freq; j_util = j_sg_cpu->util; @@ -302,7 +307,7 @@ static void sugov_update_shared(struct update_util_data *hook, u64 time, sg_cpu->last_update = time; if (sugov_should_update_freq(sg_policy, time)) { - if (flags & SCHED_CPUFREQ_RT_DL) + if (flags & SCHED_CPUFREQ_RT) next_f = sg_policy->policy->cpuinfo.max_freq; else next_f = sugov_next_freq_shared(sg_cpu, time); @@ -332,9 +337,9 @@ static void sugov_irq_work(struct irq_work *irq_work) sg_policy = container_of(irq_work, struct sugov_policy, irq_work); /* - * For RT and deadline tasks, the schedutil governor shoots the - * frequency to maximum. Special care must be taken to ensure that this - * kthread doesn't result in the same behavior. + * For RT tasks, the schedutil governor shoots the frequency to maximum. + * Special care must be taken to ensure that this kthread doesn't result + * in the same behavior. * * This is (mostly) guaranteed by the work_in_progress flag. The flag is * updated only at the end of the sugov_work() function and before that From patchwork Wed Jul 5 08:58:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juri Lelli X-Patchwork-Id: 107045 Delivered-To: patch@linaro.org Received: by 10.182.135.102 with SMTP id pr6csp565684obb; Wed, 5 Jul 2017 02:00:32 -0700 (PDT) X-Received: by 10.84.231.194 with SMTP id g2mr21019169pln.5.1499245232601; Wed, 05 Jul 2017 02:00:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499245232; cv=none; d=google.com; s=arc-20160816; b=eYiClvxJToO+jbuI93E2nqy7Q8EviAzNuWtbLYRdOWl3znqqC67p3wqaI1hvQA7tvR FrDdXydiFkWsi/jROy6W5KfRQTxSBYwkvfVYtCx7jeo79KCY8p7/RDTIERoi5y02pYTb r+PF2mbu3V6gyKxoZyRO6WCXTmbNmET6O7EnXFqDf5L/nOvcu5QRhY8j6q+CmiW2ylrm Z2WbrOAxeG9cfgxsJs1NT8o+qj7Q3qLzFBdergJB4kQ7Ed7int4UyNHgGD87AxYVnbJu vHiT5J0M1lhEmqV15fp7JK7hXT712bbbIzuqAw1sMtnwmYxxRgK7g1SE5eRnRgWbzxk/ tU9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=LaSdjjTTLVXBR1ts4GJjb+IL326JYCAq8NlwFIBQ/VI=; b=BR7eykQI3z8RGVn49rewPywMG6QLNWPYgEaXZnBY5DrGCGZY6ugkZpnOPgw/4goiKe DPk6nWuASuuLziMrUMiA0I+Fzyqu/BsbJYC2L/ponJYXDmDIfKW50D2s2gIRlp6+88XG H3sZXOaeYy02WJLGsnWLKXKtpPB139qjW8eQUFX/lprwqDB+w5cAr4bYpnvbcmKDynHl Tw/smGRpkv+LY4f+vnoB9sXeRAZKCED+pGNI4mir1eQYhwvBTfRjPIDcWJkzjYSEItZt yBlYJ6C6+eTU91Yd6xNUz5uqC3wElVSTw9TvB7S7qbIDBpJmJwUqOcDS+CyJ2OxE1FbT nNJw== 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 e86si16522770pfl.428.2017.07.05.02.00.32; Wed, 05 Jul 2017 02:00:32 -0700 (PDT) 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 S1752512AbdGEJAW (ORCPT + 25 others); Wed, 5 Jul 2017 05:00:22 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:53516 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752426AbdGEJAU (ORCPT ); Wed, 5 Jul 2017 05:00:20 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id F1A3D15AD; Wed, 5 Jul 2017 02:00:19 -0700 (PDT) Received: from cam-smtp0.cambridge.arm.com (e106622-lin.cambridge.arm.com [10.1.211.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 908933F581; Wed, 5 Jul 2017 02:00:16 -0700 (PDT) From: Juri Lelli To: peterz@infradead.org, mingo@redhat.com, rjw@rjwysocki.net, viresh.kumar@linaro.org Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, tglx@linutronix.de, vincent.guittot@linaro.org, rostedt@goodmis.org, luca.abeni@santannapisa.it, claudio@evidence.eu.com, tommaso.cucinotta@santannapisa.it, bristot@redhat.com, mathieu.poirier@linaro.org, tkjos@android.com, joelaf@google.com, andresoportus@google.com, morten.rasmussen@arm.com, dietmar.eggemann@arm.com, patrick.bellasi@arm.com, juri.lelli@arm.com, Ingo Molnar , "Rafael J . Wysocki" Subject: [RFC PATCH v1 2/8] sched/deadline: move cpu frequency selection triggering points Date: Wed, 5 Jul 2017 09:58:59 +0100 Message-Id: <20170705085905.6558-3-juri.lelli@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170705085905.6558-1-juri.lelli@arm.com> References: <20170705085905.6558-1-juri.lelli@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since SCHED_DEADLINE doesn't track utilization signal (but reserves a fraction of CPU bandwidth to tasks admitted to the system), there is no point in evaluating frequency changes during each tick event. Move frequency selection triggering points to where running_bw changes. Co-authored-by: Claudio Scordino Signed-off-by: Juri Lelli Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Rafael J. Wysocki Cc: Viresh Kumar Cc: Luca Abeni --- Changes from RFCv0: - modify comment regarding periodic RT updates (Claudio) --- kernel/sched/deadline.c | 7 ++++--- kernel/sched/sched.h | 12 ++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) -- 2.11.0 diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c index a84299f44b5d..6912f7f35f9b 100644 --- a/kernel/sched/deadline.c +++ b/kernel/sched/deadline.c @@ -85,6 +85,8 @@ void add_running_bw(u64 dl_bw, struct dl_rq *dl_rq) dl_rq->running_bw += dl_bw; SCHED_WARN_ON(dl_rq->running_bw < old); /* overflow */ SCHED_WARN_ON(dl_rq->running_bw > dl_rq->this_bw); + /* kick cpufreq (see the comment in kernel/sched/sched.h). */ + cpufreq_update_this_cpu(rq_of_dl_rq(dl_rq), SCHED_CPUFREQ_DL); } static inline @@ -97,6 +99,8 @@ void sub_running_bw(u64 dl_bw, struct dl_rq *dl_rq) SCHED_WARN_ON(dl_rq->running_bw > old); /* underflow */ if (dl_rq->running_bw > old) dl_rq->running_bw = 0; + /* kick cpufreq (see the comment in kernel/sched/sched.h). */ + cpufreq_update_this_cpu(rq_of_dl_rq(dl_rq), SCHED_CPUFREQ_DL); } static inline @@ -1135,9 +1139,6 @@ static void update_curr_dl(struct rq *rq) return; } - /* kick cpufreq (see the comment in kernel/sched/sched.h). */ - cpufreq_update_this_cpu(rq, SCHED_CPUFREQ_DL); - schedstat_set(curr->se.statistics.exec_max, max(curr->se.statistics.exec_max, delta_exec)); diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index eeef1a3086d1..d8798bb54ace 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -2057,14 +2057,14 @@ DECLARE_PER_CPU(struct update_util_data *, cpufreq_update_util_data); * The way cpufreq is currently arranged requires it to evaluate the CPU * performance state (frequency/voltage) on a regular basis to prevent it from * being stuck in a completely inadequate performance level for too long. - * That is not guaranteed to happen if the updates are only triggered from CFS, - * though, because they may not be coming in if RT or deadline tasks are active - * all the time (or there are RT and DL tasks only). + * That is not guaranteed to happen if the updates are only triggered from CFS + * and DL, though, because they may not be coming in if only RT tasks are + * active all the time (or there are RT tasks only). * - * As a workaround for that issue, this function is called by the RT and DL - * sched classes to trigger extra cpufreq updates to prevent it from stalling, + * As a workaround for that issue, this function is called periodically by the + * RT sched class to trigger extra cpufreq updates to prevent it from stalling, * but that really is a band-aid. Going forward it should be replaced with - * solutions targeted more specifically at RT and DL tasks. + * solutions targeted more specifically at RT tasks. */ static inline void cpufreq_update_util(struct rq *rq, unsigned int flags) { From patchwork Wed Jul 5 08:59:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juri Lelli X-Patchwork-Id: 107047 Delivered-To: patch@linaro.org Received: by 10.182.135.102 with SMTP id pr6csp565921obb; Wed, 5 Jul 2017 02:00:43 -0700 (PDT) X-Received: by 10.98.77.6 with SMTP id a6mr19602180pfb.221.1499245243374; Wed, 05 Jul 2017 02:00:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499245243; cv=none; d=google.com; s=arc-20160816; b=WnhS6a58wN40QVacb3dnFu8ebW0zuiA1YBQk9EpB72ii3yp2EcmfZMLon/jz6BeR/K Zqo0Y245u6kO2WdseC/ZXPU8fmm9Wj5mMi/Rdrhv8YaGzcrh5gmpIoXAanq07bw8i9rO lWGUozORy46vb/CxnBCBT+u7ua1so+af8bM3X7eiEKiSKud10pJehG8xiq4iJXtEItf7 mS0gSkuV+gRjac93f0xQ3ZXgKdDYks/VTaY022qQsPwjZREBs3p+rvONfkOTOxkrfPXy K2EsGhKEYKT42IQ7/amfA22v7YPS5W54q2bP7fElkFRKktZAGKWGnJG95UbO0VaKwjfO KeOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=a70Gd6OadXBxUrEJJ9sotyFk64rrFzfJ3rx3tTyIcfU=; b=qw8vvQj8A60cXjt6Ezql99dQtaTtU0pD8NLz4BA4yRIlBlJD33+w1OtL6gqqFlLD1y Slc8PqpORQVpeAUAhZ3KCBaIRIZQonC1zYdcPQVRO64pIqx+ZEetinl4XxHebqIb8jj6 gOGeDRAb3yGBNEtE7w4FixLdgPbdEOYfHxyeg0H0d33Mkyx9yCTp2JeAgLOTfzLWRtzf cXjY1fyEzS/g8T3jbsCle5lnjYASUVZdKAsg0lCqp8/TKf0+shkZyIOvnX8X/zKK925w M7lxFISLLq+HbP4PWOLVCfaL1JT2XG0+I+TJn7+X/jbRcbNyBakLQm2LEu8UX16w19y/ Xmrw== 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 g2si17671927plk.487.2017.07.05.02.00.42; Wed, 05 Jul 2017 02:00:43 -0700 (PDT) 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 S1752599AbdGEJAb (ORCPT + 25 others); Wed, 5 Jul 2017 05:00:31 -0400 Received: from foss.arm.com ([217.140.101.70]:53526 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752431AbdGEJA3 (ORCPT ); Wed, 5 Jul 2017 05:00:29 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E792F15BF; Wed, 5 Jul 2017 02:00:23 -0700 (PDT) Received: from cam-smtp0.cambridge.arm.com (e106622-lin.cambridge.arm.com [10.1.211.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 3C6913F581; Wed, 5 Jul 2017 02:00:20 -0700 (PDT) From: Juri Lelli To: peterz@infradead.org, mingo@redhat.com, rjw@rjwysocki.net, viresh.kumar@linaro.org Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, tglx@linutronix.de, vincent.guittot@linaro.org, rostedt@goodmis.org, luca.abeni@santannapisa.it, claudio@evidence.eu.com, tommaso.cucinotta@santannapisa.it, bristot@redhat.com, mathieu.poirier@linaro.org, tkjos@android.com, joelaf@google.com, andresoportus@google.com, morten.rasmussen@arm.com, dietmar.eggemann@arm.com, patrick.bellasi@arm.com, juri.lelli@arm.com, Ingo Molnar , "Rafael J . Wysocki" Subject: [RFC PATCH v1 3/8] sched/cpufreq_schedutil: make worker kthread be SCHED_DEADLINE Date: Wed, 5 Jul 2017 09:59:00 +0100 Message-Id: <20170705085905.6558-4-juri.lelli@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170705085905.6558-1-juri.lelli@arm.com> References: <20170705085905.6558-1-juri.lelli@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Worker kthread needs to be able to change frequency for all other threads. Make it special, just under STOP class. Signed-off-by: Juri Lelli Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Rafael J. Wysocki Cc: Viresh Kumar Cc: Luca Abeni Cc: Claudio Scordino --- Changes from RFCv0: - use a high bit of sched_flags and don't expose the new flag to userspace (also add derisory comments) (Peter) --- include/linux/sched.h | 1 + kernel/sched/core.c | 15 +++++++++++++-- kernel/sched/cpufreq_schedutil.c | 15 ++++++++++++--- kernel/sched/deadline.c | 13 +++++++++++++ kernel/sched/sched.h | 20 +++++++++++++++++++- 5 files changed, 58 insertions(+), 6 deletions(-) -- 2.11.0 diff --git a/include/linux/sched.h b/include/linux/sched.h index 1f0f427e0292..0ba767fdedae 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1359,6 +1359,7 @@ extern int idle_cpu(int cpu); extern int sched_setscheduler(struct task_struct *, int, const struct sched_param *); extern int sched_setscheduler_nocheck(struct task_struct *, int, const struct sched_param *); extern int sched_setattr(struct task_struct *, const struct sched_attr *); +extern int sched_setattr_nocheck(struct task_struct *, const struct sched_attr *); extern struct task_struct *idle_task(int cpu); /** diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 5186797908dc..0e40c7ff2bf4 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -3998,7 +3998,9 @@ static int __sched_setscheduler(struct task_struct *p, } if (attr->sched_flags & - ~(SCHED_FLAG_RESET_ON_FORK | SCHED_FLAG_RECLAIM)) + ~(SCHED_FLAG_RESET_ON_FORK | + SCHED_FLAG_RECLAIM | + SCHED_FLAG_SPECIAL)) return -EINVAL; /* @@ -4065,6 +4067,9 @@ static int __sched_setscheduler(struct task_struct *p, } if (user) { + if (attr->sched_flags & SCHED_FLAG_SPECIAL) + return -EPERM; + retval = security_task_setscheduler(p); if (retval) return retval; @@ -4120,7 +4125,8 @@ static int __sched_setscheduler(struct task_struct *p, } #endif #ifdef CONFIG_SMP - if (dl_bandwidth_enabled() && dl_policy(policy)) { + if (dl_bandwidth_enabled() && dl_policy(policy) && + !(attr->sched_flags & SCHED_FLAG_SPECIAL)) { cpumask_t *span = rq->rd->span; /* @@ -4250,6 +4256,11 @@ int sched_setattr(struct task_struct *p, const struct sched_attr *attr) } EXPORT_SYMBOL_GPL(sched_setattr); +int sched_setattr_nocheck(struct task_struct *p, const struct sched_attr *attr) +{ + return __sched_setscheduler(p, attr, false, true); +} + /** * sched_setscheduler_nocheck - change the scheduling policy and/or RT priority of a thread from kernelspace. * @p: the task in question. diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c index f2494d1fc8ef..ba6227625f24 100644 --- a/kernel/sched/cpufreq_schedutil.c +++ b/kernel/sched/cpufreq_schedutil.c @@ -424,7 +424,16 @@ static void sugov_policy_free(struct sugov_policy *sg_policy) static int sugov_kthread_create(struct sugov_policy *sg_policy) { struct task_struct *thread; - struct sched_param param = { .sched_priority = MAX_USER_RT_PRIO / 2 }; + struct sched_attr attr = { + .size = sizeof(struct sched_attr), + .sched_policy = SCHED_DEADLINE, + .sched_flags = SCHED_FLAG_SPECIAL, + .sched_nice = 0, + .sched_priority = 0, + .sched_runtime = 0, + .sched_deadline = 0, + .sched_period = 0, + }; struct cpufreq_policy *policy = sg_policy->policy; int ret; @@ -442,10 +451,10 @@ static int sugov_kthread_create(struct sugov_policy *sg_policy) return PTR_ERR(thread); } - ret = sched_setscheduler_nocheck(thread, SCHED_FIFO, ¶m); + ret = sched_setattr_nocheck(thread, &attr); if (ret) { kthread_stop(thread); - pr_warn("%s: failed to set SCHED_FIFO\n", __func__); + pr_warn("%s: failed to set SCHED_DEADLINE\n", __func__); return ret; } diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c index 6912f7f35f9b..4ec82fa56b04 100644 --- a/kernel/sched/deadline.c +++ b/kernel/sched/deadline.c @@ -220,6 +220,9 @@ static void task_non_contending(struct task_struct *p) if (dl_se->dl_runtime == 0) return; + if (unlikely(dl_entity_is_special(dl_se))) + return; + WARN_ON(hrtimer_active(&dl_se->inactive_timer)); WARN_ON(dl_se->dl_non_contending); @@ -1150,6 +1153,9 @@ static void update_curr_dl(struct rq *rq) sched_rt_avg_update(rq, delta_exec); + if (unlikely(dl_entity_is_special(dl_se))) + return; + if (unlikely(dl_se->flags & SCHED_FLAG_RECLAIM)) delta_exec = grub_reclaim(delta_exec, rq, &curr->dl); dl_se->runtime -= delta_exec; @@ -2447,6 +2453,9 @@ int sched_dl_overflow(struct task_struct *p, int policy, u64 new_bw = dl_policy(policy) ? to_ratio(period, runtime) : 0; int cpus, err = -1; + if (attr->sched_flags & SCHED_FLAG_SPECIAL) + return 0; + /* !deadline task may carry old deadline bandwidth */ if (new_bw == p->dl.dl_bw && task_has_dl_policy(p)) return 0; @@ -2533,6 +2542,10 @@ void __getparam_dl(struct task_struct *p, struct sched_attr *attr) */ bool __checkparam_dl(const struct sched_attr *attr) { + /* special dl tasks don't actually use any parameter */ + if (attr->sched_flags & SCHED_FLAG_SPECIAL) + return true; + /* deadline != 0 */ if (attr->sched_deadline == 0) return false; diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index d8798bb54ace..1be5dac728a4 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -156,12 +156,30 @@ static inline int task_has_dl_policy(struct task_struct *p) } /* + * !! For sched_setattr_nocheck() (kernel) only !! + * + * This is actually gross. :( + * + * It is used to make schedutil kworker(s) higher priority than SCHED_DEADLINE + * tasks, but still be able to sleep. We need this on platforms that cannot + * atomically change clock frequency. Remove once fast switching will be + * available on such platforms. + */ +#define SCHED_FLAG_SPECIAL 0x10000000 + +static inline int dl_entity_is_special(struct sched_dl_entity *dl_se) +{ + return dl_se->flags & SCHED_FLAG_SPECIAL; +} + +/* * Tells if entity @a should preempt entity @b. */ static inline bool dl_entity_preempt(struct sched_dl_entity *a, struct sched_dl_entity *b) { - return dl_time_before(a->deadline, b->deadline); + return dl_entity_is_special(a) || + dl_time_before(a->deadline, b->deadline); } /* From patchwork Wed Jul 5 08:59:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juri Lelli X-Patchwork-Id: 107052 Delivered-To: patch@linaro.org Received: by 10.182.135.102 with SMTP id pr6csp567708obb; Wed, 5 Jul 2017 02:02:06 -0700 (PDT) X-Received: by 10.84.232.7 with SMTP id h7mr21382063plk.193.1499245326714; Wed, 05 Jul 2017 02:02:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499245326; cv=none; d=google.com; s=arc-20160816; b=t9TOryWB8toi8VKz67CW83eNjaiVQKbmSRMN4n36kI6j5mLVm6gumBMvrxCK+WOTMr iWD2jNAs+h4gF/EeJDs2PFxmb09ltE/DWPQc+H2GhKjNZjcVhjKyoSUbV4hTVfXMGLru cc1JUkrwsj6+VLMqXKV8m1pZJwoDGuIVaGjDw3S/oVGLGlhCFGzNRP+BOI/+QFNNG72I ULVCkTt3kPy0Mfh/rxp4o3X6Lnv6e7YYUEpFzEMCRDRSUm3DyzaZmCw6gKiZ33U37PKH zOzkqXyJ8Htbwe8+vO+x4v3Fh5hyZxnpmWbhkY9B5qGwuMQEyysusjiPAWIdE2Le3Qcw SJnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=ICKkrjVnZDiwA53XTAExyVyfH0Kx2jsvdj3APwh+Hy0=; b=ksiD88f9jazLvfZEykwwXjjBS4MvBjpsjn6KvKIKsMKj7XAlrkmQYXDWvQJ5wu6TUe elOxSIiOVNBc74C8NOaUoIPDGmvuEEOv6t5Wokm8KnYfyG2emX8yF8v4n0b3BCBRoH5X B/PbK3QzDEx18p9wO1idCz+1YOFfU9+y5ytjX3RvlzhVk4IyDLsoMcRXWKlNaePs4QHy DkIoiFsJ3SOj5gQhA17GJHkqh3sGxmXXU1KGodWF5cbQ4/A3IppjJqoWxqrzF68qmHZZ H2V2fpMXi79gTsKdyqDiYFuuPhjijd5bZGIQEADMXMnLWNo9ZmrriLD2mQDgksJhIQ6z Z2+A== 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 h11si11364328pln.264.2017.07.05.02.02.06; Wed, 05 Jul 2017 02:02:06 -0700 (PDT) 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 S1752728AbdGEJBu (ORCPT + 25 others); Wed, 5 Jul 2017 05:01:50 -0400 Received: from foss.arm.com ([217.140.101.70]:53572 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752486AbdGEJA2 (ORCPT ); Wed, 5 Jul 2017 05:00:28 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 92352164F; Wed, 5 Jul 2017 02:00:27 -0700 (PDT) Received: from cam-smtp0.cambridge.arm.com (e106622-lin.cambridge.arm.com [10.1.211.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 3152A3F581; Wed, 5 Jul 2017 02:00:24 -0700 (PDT) From: Juri Lelli To: peterz@infradead.org, mingo@redhat.com, rjw@rjwysocki.net, viresh.kumar@linaro.org Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, tglx@linutronix.de, vincent.guittot@linaro.org, rostedt@goodmis.org, luca.abeni@santannapisa.it, claudio@evidence.eu.com, tommaso.cucinotta@santannapisa.it, bristot@redhat.com, mathieu.poirier@linaro.org, tkjos@android.com, joelaf@google.com, andresoportus@google.com, morten.rasmussen@arm.com, dietmar.eggemann@arm.com, patrick.bellasi@arm.com, juri.lelli@arm.com, Ingo Molnar , "Rafael J . Wysocki" Subject: [RFC PATCH v1 4/8] sched/cpufreq_schedutil: split utilization signals Date: Wed, 5 Jul 2017 09:59:01 +0100 Message-Id: <20170705085905.6558-5-juri.lelli@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170705085905.6558-1-juri.lelli@arm.com> References: <20170705085905.6558-1-juri.lelli@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To be able to treat utilization signals of different scheduling classes in different ways (e.g., CFS signal might be stale while DEADLINE signal is never stale by design) we need to split sugov_cpu::util signal in two: util_cfs and util_dl. This patch does that by also changing sugov_get_util() parameter list. After this change, aggregation of the different signals has to be performed by sugov_get_util() users (so that they can decide what to do with the different signals). Suggested-by: Rafael J. Wysocki Signed-off-by: Juri Lelli Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Rafael J. Wysocki Cc: Viresh Kumar Cc: Luca Abeni Cc: Claudio Scordino --- Changes from RFCv0: - refactor aggregation of utilization in sugov_aggregate_util() --- kernel/sched/cpufreq_schedutil.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) -- 2.11.0 diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c index ba6227625f24..e835fa886225 100644 --- a/kernel/sched/cpufreq_schedutil.c +++ b/kernel/sched/cpufreq_schedutil.c @@ -58,7 +58,8 @@ struct sugov_cpu { u64 last_update; /* The fields below are only needed when sharing a policy. */ - unsigned long util; + unsigned long util_cfs; + unsigned long util_dl; unsigned long max; unsigned int flags; @@ -154,20 +155,24 @@ static unsigned int get_next_freq(struct sugov_policy *sg_policy, return cpufreq_driver_resolve_freq(policy, freq); } -static void sugov_get_util(unsigned long *util, unsigned long *max) +static void sugov_get_util(struct sugov_cpu *sg_cpu) { struct rq *rq = this_rq(); - unsigned long dl_util = (rq->dl.running_bw * SCHED_CAPACITY_SCALE) - >> BW_SHIFT; - *max = arch_scale_cpu_capacity(NULL, smp_processor_id()); + sg_cpu->max = arch_scale_cpu_capacity(NULL, smp_processor_id()); + sg_cpu->util_cfs = rq->cfs.avg.util_avg; + sg_cpu->util_dl = (rq->dl.running_bw * SCHED_CAPACITY_SCALE) + >> BW_SHIFT; +} +static unsigned long sugov_aggregate_util(struct sugov_cpu *sg_cpu) +{ /* * Ideally we would like to set util_dl as min/guaranteed freq and * util_cfs + util_dl as requested freq. However, cpufreq is not yet * ready for such an interface. So, we only do the latter for now. */ - *util = min(rq->cfs.avg.util_avg + dl_util, *max); + return min(sg_cpu->util_cfs + sg_cpu->util_dl, sg_cpu->max); } static void sugov_set_iowait_boost(struct sugov_cpu *sg_cpu, u64 time, @@ -234,7 +239,9 @@ static void sugov_update_single(struct update_util_data *hook, u64 time, if (flags & SCHED_CPUFREQ_RT) { next_f = policy->cpuinfo.max_freq; } else { - sugov_get_util(&util, &max); + sugov_get_util(sg_cpu); + max = sg_cpu->max; + util = sugov_aggregate_util(sg_cpu); sugov_iowait_boost(sg_cpu, &util, &max); next_f = get_next_freq(sg_policy, util, max); /* @@ -274,8 +281,8 @@ static unsigned int sugov_next_freq_shared(struct sugov_cpu *sg_cpu, u64 time) if (j_sg_cpu->flags & SCHED_CPUFREQ_RT) return policy->cpuinfo.max_freq; - j_util = j_sg_cpu->util; j_max = j_sg_cpu->max; + j_util = sugov_aggregate_util(j_sg_cpu); if (j_util * max > j_max * util) { util = j_util; max = j_max; @@ -292,15 +299,12 @@ static void sugov_update_shared(struct update_util_data *hook, u64 time, { struct sugov_cpu *sg_cpu = container_of(hook, struct sugov_cpu, update_util); struct sugov_policy *sg_policy = sg_cpu->sg_policy; - unsigned long util, max; unsigned int next_f; - sugov_get_util(&util, &max); raw_spin_lock(&sg_policy->update_lock); - sg_cpu->util = util; - sg_cpu->max = max; + sugov_get_util(sg_cpu); sg_cpu->flags = flags; sugov_set_iowait_boost(sg_cpu, time, flags); From patchwork Wed Jul 5 08:59:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juri Lelli X-Patchwork-Id: 107049 Delivered-To: patch@linaro.org Received: by 10.182.135.102 with SMTP id pr6csp566250obb; Wed, 5 Jul 2017 02:00:58 -0700 (PDT) X-Received: by 10.98.201.75 with SMTP id k72mr14381240pfg.99.1499245258351; Wed, 05 Jul 2017 02:00:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499245258; cv=none; d=google.com; s=arc-20160816; b=CeRVU5GEmSOaFhs7C+Fly/RTwvhWpIS8XnKmMyPXP7d3DVekIa5BYa88U7i8X72ciJ zdAKGTSaUWRN8rOVvxm8buov4CKUAktfx4jruW2uIYqrcxLIVi/HyO2ROHA6I59soh++ UD7DjC+BrqlaC85mGTtu4cNd5Q8OYN7rdN0o+DT8IWwFyJfP2Le6rgatBwy7y1BViChl ho9cd1Bx1ik6Jia3yH3RUuusakfwuzZcASWm+6+r1944c/799vDc9iCPaMq7yuWNH5Fx IfALHxoQXzMsVG5+pl9FiCudVP+SVwK3oA9RLJ80TJBM5JRAG90ILkzhqAfHmAhqoTd3 WO4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=r96NKbIl98pJCrLnpmSP7PwqYWBiTea+YMDrxSk0ixU=; b=BVPrQPVR7kvFtpaOrqdTfVAbV1JNmssOVWD2BZFZGMDvLypW9NxwAZj/AWrDdDeoU8 O/u9Ztje5J988TTzcJ2jhvbEAhpcsTSJWHRpvEd2jVfoLq749M27yhUXCD84wzjjNuh5 0htZoCp6v2noR8LrHC4MZTzGIE4VByrTMat30YGP+nampz+qvwoIch9iukTHd20izSgo Cb50fZBYpW0/T2CqD4cTmTvXAjig6D2XtC/OD3E9v91YRWHLcRNATBHjjp3t/72sR2fI +mJbX65ShkkGOTr6SI9fd14sFfB2akA+ILzdEus6fajm1W1bN6htwxQdxTny8RRhmSif CInQ== 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 o29si10018563pgn.537.2017.07.05.02.00.58; Wed, 05 Jul 2017 02:00:58 -0700 (PDT) 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 S1752645AbdGEJAo (ORCPT + 25 others); Wed, 5 Jul 2017 05:00:44 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:53582 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752431AbdGEJAm (ORCPT ); Wed, 5 Jul 2017 05:00:42 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 856A61650; Wed, 5 Jul 2017 02:00:31 -0700 (PDT) Received: from cam-smtp0.cambridge.arm.com (e106622-lin.cambridge.arm.com [10.1.211.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D0C733F581; Wed, 5 Jul 2017 02:00:27 -0700 (PDT) From: Juri Lelli To: peterz@infradead.org, mingo@redhat.com, rjw@rjwysocki.net, viresh.kumar@linaro.org Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, tglx@linutronix.de, vincent.guittot@linaro.org, rostedt@goodmis.org, luca.abeni@santannapisa.it, claudio@evidence.eu.com, tommaso.cucinotta@santannapisa.it, bristot@redhat.com, mathieu.poirier@linaro.org, tkjos@android.com, joelaf@google.com, andresoportus@google.com, morten.rasmussen@arm.com, dietmar.eggemann@arm.com, patrick.bellasi@arm.com, juri.lelli@arm.com, Ingo Molnar , "Rafael J . Wysocki" Subject: [RFC PATCH v1 5/8] sched/cpufreq_schedutil: always consider all CPUs when deciding next freq Date: Wed, 5 Jul 2017 09:59:02 +0100 Message-Id: <20170705085905.6558-6-juri.lelli@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170705085905.6558-1-juri.lelli@arm.com> References: <20170705085905.6558-1-juri.lelli@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org No assumption can be made upon the rate at which frequency updates get triggered, as there are scheduling policies (like SCHED_DEADLINE) which don't trigger them so frequently. Remove such assumption from the code, by always considering SCHED_DEADLINE utilization signal as not stale. Signed-off-by: Juri Lelli Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Rafael J. Wysocki Cc: Viresh Kumar Cc: Luca Abeni Cc: Claudio Scordino --- kernel/sched/cpufreq_schedutil.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) -- 2.11.0 diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c index e835fa886225..066b876d81e7 100644 --- a/kernel/sched/cpufreq_schedutil.c +++ b/kernel/sched/cpufreq_schedutil.c @@ -267,17 +267,22 @@ static unsigned int sugov_next_freq_shared(struct sugov_cpu *sg_cpu, u64 time) s64 delta_ns; /* - * If the CPU utilization was last updated before the previous - * frequency update and the time elapsed between the last update - * of the CPU utilization and the last frequency update is long - * enough, don't take the CPU into account as it probably is - * idle now (and clear iowait_boost for it). + * If the CFS CPU utilization was last updated before the + * previous frequency update and the time elapsed between the + * last update of the CPU utilization and the last frequency + * update is long enough, reset iowait_boost and util_cfs, as + * they are now probably stale. However, still consider the + * CPU contribution if it has some DEADLINE utilization + * (util_dl). */ delta_ns = time - j_sg_cpu->last_update; if (delta_ns > TICK_NSEC) { j_sg_cpu->iowait_boost = 0; - continue; + j_sg_cpu->util_cfs = 0; + if (j_sg_cpu->util_dl == 0) + continue; } + if (j_sg_cpu->flags & SCHED_CPUFREQ_RT) return policy->cpuinfo.max_freq; From patchwork Wed Jul 5 08:59:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juri Lelli X-Patchwork-Id: 107048 Delivered-To: patch@linaro.org Received: by 10.182.135.102 with SMTP id pr6csp565932obb; Wed, 5 Jul 2017 02:00:43 -0700 (PDT) X-Received: by 10.84.218.71 with SMTP id f7mr20632467plm.282.1499245243780; Wed, 05 Jul 2017 02:00:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499245243; cv=none; d=google.com; s=arc-20160816; b=JRLesi9WdFkMVg0poDeUXvA4eJU1TDA2YqwdBifKK8yT/IQD4krkKsbboWlX2Lc5XH jAt8f+MnvDSj1ljCAZhk685d7QsNAVH1QFBcYBNOROnxZ6qFiCr0cYOIlgkoEvKFTAPP OE96dj6uqOfBYXokcIAd3f+6jhTZfUKgbV3FUr6oB4/ciQPxqr4+/isAALPvOuAd5C3O qEEe0XF4TeK1GgfLpLMrbNtmydPaAN75+Wq7gCFET6m/3m1zxb3vKQth170oGmYqBKGq DI7CGbwHDw1kHfYHWdt76oVZ+UFxd8Q/+lD6RqVIZ0gpGmD/nY3XQiNCRI77psQq3GGQ tguA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=8II4iFVVEPMXw6+xStuANYLtb7rnEyhVbXFJs4A7Qfc=; b=TxRhhsLVajIEyNJD8dK44Whdxj7BxydecGBvQkEhJsW6N1cPu6jqDRBgOY35xmgxDN GDnHWO1qH/iKMnzkpdgj6BxXj5IREMnD7fTjh04H+4tDOzneYof27v9Y+PCtZKxOVeLr GN++eNDusOgPlrpgN5o3O/2rw3vBQeq3aq5TD8kt3bATg8/ZPXOYQ6cmhoSGcKzuRKDY 2O/WPri9jYdE5YyxWHF/r8rdhxoTAr5/mb4BEBY5cDBX3yrK4HjjSvhCkudqzidE0rGO STmyuk0rdAbGTWVganZOf1MYpWTJeQrFFMKOZJN3NDfGchfn9uDOZxmu9sh8XFjpafM3 YtKw== 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 g2si17671927plk.487.2017.07.05.02.00.43; Wed, 05 Jul 2017 02:00:43 -0700 (PDT) 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 S1752619AbdGEJAh (ORCPT + 25 others); Wed, 5 Jul 2017 05:00:37 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:53606 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752431AbdGEJAf (ORCPT ); Wed, 5 Jul 2017 05:00:35 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0CBF3165D; Wed, 5 Jul 2017 02:00:35 -0700 (PDT) Received: from cam-smtp0.cambridge.arm.com (e106622-lin.cambridge.arm.com [10.1.211.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C36C33F581; Wed, 5 Jul 2017 02:00:31 -0700 (PDT) From: Juri Lelli To: peterz@infradead.org, mingo@redhat.com, rjw@rjwysocki.net, viresh.kumar@linaro.org Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, tglx@linutronix.de, vincent.guittot@linaro.org, rostedt@goodmis.org, luca.abeni@santannapisa.it, claudio@evidence.eu.com, tommaso.cucinotta@santannapisa.it, bristot@redhat.com, mathieu.poirier@linaro.org, tkjos@android.com, joelaf@google.com, andresoportus@google.com, morten.rasmussen@arm.com, dietmar.eggemann@arm.com, patrick.bellasi@arm.com, juri.lelli@arm.com, Ingo Molnar Subject: [RFC PATCH v1 6/8] sched/sched.h: remove sd arch_scale_freq_capacity parameter Date: Wed, 5 Jul 2017 09:59:03 +0100 Message-Id: <20170705085905.6558-7-juri.lelli@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170705085905.6558-1-juri.lelli@arm.com> References: <20170705085905.6558-1-juri.lelli@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org sd parameter is never used in arch_scale_freq_capacity (and it's hard to see where information coming from scheduling domains might help doing frequency invariance scaling). Remove it; also in anticipation of moving arch_scale_freq_capacity outside CONFIG_SMP. Signed-off-by: Juri Lelli Cc: Peter Zijlstra Cc: Ingo Molnar --- kernel/sched/fair.c | 2 +- kernel/sched/sched.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) -- 2.11.0 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 008c514dc241..97bd5aae285d 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -2875,7 +2875,7 @@ accumulate_sum(u64 delta, int cpu, struct sched_avg *sa, u32 contrib = (u32)delta; /* p == 0 -> delta < 1024 */ u64 periods; - scale_freq = arch_scale_freq_capacity(NULL, cpu); + scale_freq = arch_scale_freq_capacity(cpu); scale_cpu = arch_scale_cpu_capacity(NULL, cpu); delta += sa->period_contrib; diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 1be5dac728a4..ec5769288927 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -1673,7 +1673,7 @@ extern void sched_avg_update(struct rq *rq); #ifndef arch_scale_freq_capacity static __always_inline -unsigned long arch_scale_freq_capacity(struct sched_domain *sd, int cpu) +unsigned long arch_scale_freq_capacity(int cpu) { return SCHED_CAPACITY_SCALE; } @@ -1692,7 +1692,7 @@ unsigned long arch_scale_cpu_capacity(struct sched_domain *sd, int cpu) static inline void sched_rt_avg_update(struct rq *rq, u64 rt_delta) { - rq->rt_avg += rt_delta * arch_scale_freq_capacity(NULL, cpu_of(rq)); + rq->rt_avg += rt_delta * arch_scale_freq_capacity(cpu_of(rq)); sched_avg_update(rq); } #else From patchwork Wed Jul 5 08:59:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juri Lelli X-Patchwork-Id: 107050 Delivered-To: patch@linaro.org Received: by 10.182.135.102 with SMTP id pr6csp566262obb; Wed, 5 Jul 2017 02:00:58 -0700 (PDT) X-Received: by 10.84.217.30 with SMTP id o30mr21222490pli.184.1499245258782; Wed, 05 Jul 2017 02:00:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499245258; cv=none; d=google.com; s=arc-20160816; b=Frek+eg4bbexXaQYbe6f5ficdDnIla4yCi0Wp18i12YRvlaBNZfSQv3bPMoAOYKYI+ K9Mr4cDOAHUY8jLDYY7/PV66kikh5McJhfD/14jn8M20XyMzbzFeb5X15hPTc3OoU2WX Tz0p4zI5Zu1XeXD7iaN21SQaZC/vXCrOa9g7AWqLguj0qr2fG1d+NU1vxGznCxbpj9zF 367iIwNS03lZKCQ2avsWnN6vFmF7d/m38KTcif/MVukvCBQMW3sE9ZDtqwH/PmLs/SiJ 6R2TcppuvUFzIMSocTJfo4od2YVGClxL+2JMdGOPVLh57WBvCxptZbSTKZe4hT+/8DuS is2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=/WxLeoqWiuk45TQpAVrbg+ndKqs6QweLBPq1LMxcK94=; b=E/csAjO82Y8fiq8H5NqmM8OuG0z7KrgLCCo2z98t0HcSFph3Xqa24ORZ5diVKteUaU nUbhV8Z/Mk4QSjLqGuH/QdAfL7HoAEhYdwgseeP2heM0xbCglxs26tGc5esv1fLQLRP0 dFoaTAmJkQ2UC8Kjnmq2jVXm99y3/djIaHeEXDKJ31ApUWzj41NWtJzrLH/GiTFKDizK F+IUtBuVYZ4g8NN0j5IhEo7g2XAKeerQIR5sVg2HY1XTSkfW3I/5KDpvE9hjXxR3y4Hq xo+hF5SiM68utyckF9HdEt8i0kGwy0VyawrR2nH3xsM8h08EROwdpoUR7sZMbo1LlOuU wbVA== 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 o29si10018563pgn.537.2017.07.05.02.00.58; Wed, 05 Jul 2017 02:00:58 -0700 (PDT) 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 S1752681AbdGEJAv (ORCPT + 25 others); Wed, 5 Jul 2017 05:00:51 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:53648 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752431AbdGEJAt (ORCPT ); Wed, 5 Jul 2017 05:00:49 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8612880D; Wed, 5 Jul 2017 02:00:38 -0700 (PDT) Received: from cam-smtp0.cambridge.arm.com (e106622-lin.cambridge.arm.com [10.1.211.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 4AC933F581; Wed, 5 Jul 2017 02:00:35 -0700 (PDT) From: Juri Lelli To: peterz@infradead.org, mingo@redhat.com, rjw@rjwysocki.net, viresh.kumar@linaro.org Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, tglx@linutronix.de, vincent.guittot@linaro.org, rostedt@goodmis.org, luca.abeni@santannapisa.it, claudio@evidence.eu.com, tommaso.cucinotta@santannapisa.it, bristot@redhat.com, mathieu.poirier@linaro.org, tkjos@android.com, joelaf@google.com, andresoportus@google.com, morten.rasmussen@arm.com, dietmar.eggemann@arm.com, patrick.bellasi@arm.com, juri.lelli@arm.com, Ingo Molnar Subject: [RFC PATCH v1 7/8] sched/sched.h: move arch_scale_{freq, cpu}_capacity outside CONFIG_SMP Date: Wed, 5 Jul 2017 09:59:04 +0100 Message-Id: <20170705085905.6558-8-juri.lelli@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170705085905.6558-1-juri.lelli@arm.com> References: <20170705085905.6558-1-juri.lelli@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, frequency and cpu capacity scaling is only performed on CONFIG_SMP systems (as CFS PELT signals are only present for such systems). However, other scheduling classes want to do freq/cpu scaling, and for !CONFIG_SMP configurations as well. arch_scale_freq_capacity is useful to implement frequency scaling even on !CONFIG_SMP platforms, so we simply move it outside CONFIG_SMP ifdeffery. Even if arch_scale_cpu_capacity is not useful on !CONFIG_SMP platforms, we make a default implementation available for such configurations anyway to simplify scheduler code doing CPU scale invariance. Signed-off-by: Juri Lelli Cc: Peter Zijlstra Cc: Ingo Molnar --- include/linux/sched/topology.h | 12 ++++++------ kernel/sched/sched.h | 13 ++++++++++--- 2 files changed, 16 insertions(+), 9 deletions(-) -- 2.11.0 diff --git a/include/linux/sched/topology.h b/include/linux/sched/topology.h index 7d065abc7a47..953cf4f889ec 100644 --- a/include/linux/sched/topology.h +++ b/include/linux/sched/topology.h @@ -6,6 +6,12 @@ #include /* + * Increase resolution of cpu_capacity calculations + */ +#define SCHED_CAPACITY_SHIFT SCHED_FIXEDPOINT_SHIFT +#define SCHED_CAPACITY_SCALE (1L << SCHED_CAPACITY_SHIFT) + +/* * sched-domains (multiprocessor balancing) declarations: */ #ifdef CONFIG_SMP @@ -26,12 +32,6 @@ #define SD_OVERLAP 0x2000 /* sched_domains of this level overlap */ #define SD_NUMA 0x4000 /* cross-node balancing */ -/* - * Increase resolution of cpu_capacity calculations - */ -#define SCHED_CAPACITY_SHIFT SCHED_FIXEDPOINT_SHIFT -#define SCHED_CAPACITY_SCALE (1L << SCHED_CAPACITY_SHIFT) - #ifdef CONFIG_SCHED_SMT static inline int cpu_smt_flags(void) { diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index ec5769288927..178f4a5df2fa 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -1668,9 +1668,6 @@ static inline int hrtick_enabled(struct rq *rq) #endif /* CONFIG_SCHED_HRTICK */ -#ifdef CONFIG_SMP -extern void sched_avg_update(struct rq *rq); - #ifndef arch_scale_freq_capacity static __always_inline unsigned long arch_scale_freq_capacity(int cpu) @@ -1679,6 +1676,9 @@ unsigned long arch_scale_freq_capacity(int cpu) } #endif +#ifdef CONFIG_SMP +extern void sched_avg_update(struct rq *rq); + #ifndef arch_scale_cpu_capacity static __always_inline unsigned long arch_scale_cpu_capacity(struct sched_domain *sd, int cpu) @@ -1696,6 +1696,13 @@ static inline void sched_rt_avg_update(struct rq *rq, u64 rt_delta) sched_avg_update(rq); } #else +#ifndef arch_scale_cpu_capacity +static __always_inline +unsigned long arch_scale_cpu_capacity(void __always_unused *sd, int cpu) +{ + return SCHED_CAPACITY_SCALE; +} +#endif static inline void sched_rt_avg_update(struct rq *rq, u64 rt_delta) { } static inline void sched_avg_update(struct rq *rq) { } #endif From patchwork Wed Jul 5 08:59:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juri Lelli X-Patchwork-Id: 107051 Delivered-To: patch@linaro.org Received: by 10.182.135.102 with SMTP id pr6csp567065obb; Wed, 5 Jul 2017 02:01:35 -0700 (PDT) X-Received: by 10.99.2.213 with SMTP id 204mr19735793pgc.180.1499245295884; Wed, 05 Jul 2017 02:01:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499245295; cv=none; d=google.com; s=arc-20160816; b=xHn94EemD2nywapSAqaTrPptifmKwZIH0PXIQyH6azZLQpB6IVzVvMsr/IEWjJ0b8V 3ZtKfMDDZ8NwfeSInLBcr0DtX3N3avnzic+1Csv/IAChNOqCPvFLl84tdnDiIKlMThRZ 4f3MBApocD0B7XWAaJZPhkB4Kg2/kAcs8wYDqjNi6h8kkx4aZDDNNrte3zxKMT0HhuL6 MMc+K+6KmzDi234g+C0Gcl4qW3gF77WJYkk3AuDahiZqsEDs+boYUtx9akitHFFW1SUa qRw+b2vHYXpKjUx5yWMTl5fBqFg6TbCveQ5rBHqtwY7wogEYvC6CJ9401p4cD8EhnMyq At4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=kCVlSW2rPJVCDpWM07iF1x3RUtTK7P46m+/AJ8O95BI=; b=lr9iw1nOW+ZhIleXmfqo0CUq3PDPlWFdmtR88TqlNEUbhOBI+3UROQfooJnEpOz2qc Aynr3FosEroNG6jed6NiXlbwMgYYclJpKnM+ihOD5RRprPY56PLXV2dA2d+iv2vThaFE 0nyvqxeizpsQTMx76Hn780uAissVjZYi3Ec0edfF3ut+lTksxUmgWhh+hQC1mbEA9sy6 FViphkqG30Wbja2N3vyGVOzmpMtahUBC0aIq8Nzvj6ZyBB7URzv6lmnXXYTjEp7V5bjm C2dJ8Jj6XZcWZ2SkEaGaNJbyvh9eCqqvoFGEiYUb8YpXTt7YDMg5rN7f9eQW2tMGmbQj yIog== 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 q20si16413839pgn.21.2017.07.05.02.01.35; Wed, 05 Jul 2017 02:01:35 -0700 (PDT) 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 S1752702AbdGEJBD (ORCPT + 25 others); Wed, 5 Jul 2017 05:01:03 -0400 Received: from foss.arm.com ([217.140.101.70]:53678 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752431AbdGEJBB (ORCPT ); Wed, 5 Jul 2017 05:01:01 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2D06C15AD; Wed, 5 Jul 2017 02:00:42 -0700 (PDT) Received: from cam-smtp0.cambridge.arm.com (e106622-lin.cambridge.arm.com [10.1.211.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C43CE3F581; Wed, 5 Jul 2017 02:00:38 -0700 (PDT) From: Juri Lelli To: peterz@infradead.org, mingo@redhat.com, rjw@rjwysocki.net, viresh.kumar@linaro.org Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, tglx@linutronix.de, vincent.guittot@linaro.org, rostedt@goodmis.org, luca.abeni@santannapisa.it, claudio@evidence.eu.com, tommaso.cucinotta@santannapisa.it, bristot@redhat.com, mathieu.poirier@linaro.org, tkjos@android.com, joelaf@google.com, andresoportus@google.com, morten.rasmussen@arm.com, dietmar.eggemann@arm.com, patrick.bellasi@arm.com, juri.lelli@arm.com, Ingo Molnar , "Rafael J . Wysocki" Subject: [RFC PATCH v1 8/8] sched/deadline: make bandwidth enforcement scale-invariant Date: Wed, 5 Jul 2017 09:59:05 +0100 Message-Id: <20170705085905.6558-9-juri.lelli@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170705085905.6558-1-juri.lelli@arm.com> References: <20170705085905.6558-1-juri.lelli@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Apply frequency and cpu scale-invariance correction factor to bandwidth enforcement (similar to what we already do to fair utilization tracking). Each delta_exec gets scaled considering current frequency and maximum cpu capacity; which means that the reservation runtime parameter (that need to be specified profiling the task execution at max frequency on biggest capacity core) gets thus scaled accordingly. Signed-off-by: Juri Lelli Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Rafael J. Wysocki Cc: Viresh Kumar Cc: Luca Abeni Cc: Claudio Scordino --- kernel/sched/deadline.c | 26 ++++++++++++++++++++++---- kernel/sched/fair.c | 2 -- kernel/sched/sched.h | 2 ++ 3 files changed, 24 insertions(+), 6 deletions(-) -- 2.11.0 diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c index 4ec82fa56b04..5bed1a2fae06 100644 --- a/kernel/sched/deadline.c +++ b/kernel/sched/deadline.c @@ -1122,7 +1122,8 @@ static void update_curr_dl(struct rq *rq) { struct task_struct *curr = rq->curr; struct sched_dl_entity *dl_se = &curr->dl; - u64 delta_exec; + u64 delta_exec, scaled_delta_exec; + int cpu = cpu_of(rq); if (!dl_task(curr) || !on_dl_rq(dl_se)) return; @@ -1156,9 +1157,26 @@ static void update_curr_dl(struct rq *rq) if (unlikely(dl_entity_is_special(dl_se))) return; - if (unlikely(dl_se->flags & SCHED_FLAG_RECLAIM)) - delta_exec = grub_reclaim(delta_exec, rq, &curr->dl); - dl_se->runtime -= delta_exec; + /* + * For tasks that participate in GRUB, we implement GRUB-PA: the + * spare reclaimed bandwidth is used to clock down frequency. + * + * For the others, we still need to scale reservation parameters + * according to current frequency and CPU maximum capacity. + */ + if (unlikely(dl_se->flags & SCHED_FLAG_RECLAIM)) { + scaled_delta_exec = grub_reclaim(delta_exec, + rq, + &curr->dl); + } else { + unsigned long scale_freq = arch_scale_freq_capacity(cpu); + unsigned long scale_cpu = arch_scale_cpu_capacity(NULL, cpu); + + scaled_delta_exec = cap_scale(delta_exec, scale_freq); + scaled_delta_exec = cap_scale(scaled_delta_exec, scale_cpu); + } + + dl_se->runtime -= scaled_delta_exec; throttle: if (dl_runtime_exceeded(dl_se) || dl_se->dl_yielded) { diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 97bd5aae285d..a6e8a4f5786f 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -2844,8 +2844,6 @@ static u32 __accumulate_pelt_segments(u64 periods, u32 d1, u32 d3) return c1 + c2 + c3; } -#define cap_scale(v, s) ((v)*(s) >> SCHED_CAPACITY_SHIFT) - /* * Accumulate the three separate parts of the sum; d1 the remainder * of the last (incomplete) period, d2 the span of full periods and d3 diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 178f4a5df2fa..688185761eaf 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -155,6 +155,8 @@ static inline int task_has_dl_policy(struct task_struct *p) return dl_policy(p->policy); } +#define cap_scale(v, s) ((v)*(s) >> SCHED_CAPACITY_SHIFT) + /* * !! For sched_setattr_nocheck() (kernel) only !! *