From patchwork Wed May 24 09:00:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 100422 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp177757qge; Wed, 24 May 2017 02:05:06 -0700 (PDT) X-Received: by 10.84.175.132 with SMTP id t4mr42251048plb.180.1495616706424; Wed, 24 May 2017 02:05:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1495616706; cv=none; d=google.com; s=arc-20160816; b=zUFapjHkHD/0A27crY+FWK+sbLAZgUgfR+XcLIfxt4kRzYwTiXGcvKywbszhyAnytr ZZrRSw1oLXkfwaxj9hmrI4DkqyrO/xsPoNTxi6KsqE9jRPj1Qc3wzBLTKwjyn7v0R1CO XKXAomFcOAz2Whvy5XbV+Gd4saVu7exUVGZs8L01ja1e+CBtF+VcTnw+DySSCgZJwMA3 t8HW8Y4J133DsOKfQdrMvYWJlWLDndnGayDLs1QkM2sqlAGLxMKKuiLcYID+GXFJyFQN 8N8Sy2fAxtbomYjNv3gMO7C1bS3WUjRFnJoeUMioMC6MV2dzxvqvHxearmG6TeJOYb5t FKPg== 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:dkim-signature:arc-authentication-results; bh=99deOVtV1p0smmBNKir5ZH6szb3c4jccWhYYPJ1HsLM=; b=NxUyUatQHvEdP3OUfgr4T60AhOxx1n6yxZLHRSKxfQQJPX4YYl0G1MP6aD7sytT2sg j5KHs1r7KdzNBzJaJG6MHVoMmcZXSOTiSMPjBC9Z06Mr86aAm2r64Mdt14aN8Nrd8SNk PV6YwQvdTzhT4LRP6Onay0ijCoNBsU/bbVRs8Q6Bo5W5bOpUYQ64q7yLBcfT4PIWnBYf nCMNteZuZeHtVwkj+jUcbc3qbnWFqu+MckELPT9WtuP1lGxQ/d9ciPrMg8ckNuI3Vto2 Xekc4FivWaj4qetP8Fz1OUbMv4QoMKJtwGRDkGZHiPz3aHqg9OeJ7tpYtB7Cjo2Tv1Ap w/LQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a9si10310664pgf.76.2017.05.24.02.05.06; Wed, 24 May 2017 02:05: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; dkim=pass header.i=@linaro.org; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1163093AbdEXJEs (ORCPT + 25 others); Wed, 24 May 2017 05:04:48 -0400 Received: from mail-wm0-f44.google.com ([74.125.82.44]:35151 "EHLO mail-wm0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161586AbdEXJBA (ORCPT ); Wed, 24 May 2017 05:01:00 -0400 Received: by mail-wm0-f44.google.com with SMTP id b84so56360003wmh.0 for ; Wed, 24 May 2017 02:01:00 -0700 (PDT) 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; bh=99deOVtV1p0smmBNKir5ZH6szb3c4jccWhYYPJ1HsLM=; b=VFXUXs1FU4cXxyXrIcS9QnSA4eSvKKWrDJI0tsbv4YmbtkKrM39JeoFYINsBj076Vg DLsW4/aoFfOY8zBixB7+dRhYyYd6BnSUdcFKWseQVYBgBNGpR3g735UMkDiNMDsUkEwG 21SvFp32ZbtuHWefE60hmEi+buA7OFCJWKfow= 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; bh=99deOVtV1p0smmBNKir5ZH6szb3c4jccWhYYPJ1HsLM=; b=rYav0IbvXzVHyccPSmH7ML8SlybEyhOYbBVgR8pZzXLkjmpRZcOBX4/Bg6RgMWGGFl NM61ctVxRQFm42Nz/sal9jQFLqVZ/jHOXfVKI4S2fkD+hbPa00bS0H5I9ZlkJ7oDLJqa yWijJMIlBbJzJtiFf00U/3Hfx3BJZ25TiXcdcH149uxDGUeJHJNqH2n92/cUOIwG0dHV juUmUkEwVQr3nGuzlmNU17LFS8ZtJBktuqn+cxNOOA7lHkRDLCm6hnHtcTz0T9Y7hXRm bZBlnL4gB4EbL2mfzfaXTD/Byhbw4PrwU/SpGo0Ndw3keTQr36VpBxKc/rs9ezKV65yH 2jsg== X-Gm-Message-State: AODbwcACnuIeVqfju7isc7Yd0BRqgve4dt6L+LVNNisxL8uYtgkXEk5v 8mJq5W1JRqC6sFRZXIq5xw== X-Received: by 10.223.161.70 with SMTP id r6mr17934490wrr.65.1495616459178; Wed, 24 May 2017 02:00:59 -0700 (PDT) Received: from localhost.localdomain ([2a01:e0a:f:6020:90ff:f881:739b:af16]) by smtp.gmail.com with ESMTPSA id w96sm4552076wrc.14.2017.05.24.02.00.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 24 May 2017 02:00:58 -0700 (PDT) From: Vincent Guittot To: peterz@infradead.org, mingo@kernel.org, linux-kernel@vger.kernel.org Cc: rjw@rjwysocki.net, juri.lelli@arm.com, dietmar.eggemann@arm.com, Morten.Rasmussen@arm.com, Vincent Guittot Subject: [RFC PATCH 1/2] sched/rt: add utilization tracking Date: Wed, 24 May 2017 11:00:51 +0200 Message-Id: <1495616452-7582-2-git-send-email-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1495616452-7582-1-git-send-email-vincent.guittot@linaro.org> References: <1495616452-7582-1-git-send-email-vincent.guittot@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org schedutil governor relies on cfs_rq's util_avg to choose the OPP when cfs tasks are running. When the CPU is overloaded by cfs and rt tasks, cfs tasks are preempted by rt tasks and in this case util_avg reflects the remaining capacity that is used by cfs tasks but not what cfs tasks want to use. In such case, schedutil can select a lower OPP when cfs task runs whereas the CPU is overloaded. In order to have a more accurate view of the utilization of the CPU, we track the utilization that is used by RT tasks. DL tasks are not taken into account as they have their own utilization tracking mecanism. We don't use rt_avg which doesn't have the same dynamic as PELT and which can include IRQ time that are also accounted in cfs task utilization Signed-off-by: Vincent Guittot --- If the changes are reasonnable, it might worth moving the PELT function in a dedicated pelt.c file and the ugly extern int update_rt_rq_load_avg(u64 now, int cpu, struct rt_rq *rt_rq, int running); in a pelt.h header kernel/sched/fair.c | 21 +++++++++++++++++++++ kernel/sched/rt.c | 9 +++++++++ kernel/sched/sched.h | 3 +++ 3 files changed, 33 insertions(+) -- 2.7.4 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 47a0c55..0d7698b 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -2950,6 +2950,17 @@ __update_load_avg_cfs_rq(u64 now, int cpu, struct cfs_rq *cfs_rq) cfs_rq->curr != NULL, cfs_rq); } +int update_rt_rq_load_avg(u64 now, int cpu, struct rt_rq *rt_rq, int running) +{ + int ret; + + ret = ___update_load_avg(now, cpu, &rt_rq->avg, 0, running, NULL); + + + return ret; +} + + /* * Signed add and clamp on underflow. * @@ -3478,6 +3489,11 @@ update_cfs_rq_load_avg(u64 now, struct cfs_rq *cfs_rq, bool update_freq) return 0; } +int update_rt_rq_load_avg(u64 now, int cpu, struct rt_rq *rt_rq, int running) +{ + return 0; +} + #define UPDATE_TG 0x0 #define SKIP_AGE_LOAD 0x0 @@ -7008,6 +7024,10 @@ static void update_blocked_averages(int cpu) if (cfs_rq_is_decayed(cfs_rq)) list_del_leaf_cfs_rq(cfs_rq); } + + update_rt_rq_load_avg(rq_clock_task(rq), cpu, &rq->rt, 0); + + rq_unlock_irqrestore(rq, &rf); } @@ -7067,6 +7087,7 @@ static inline void update_blocked_averages(int cpu) rq_lock_irqsave(rq, &rf); update_rq_clock(rq); update_cfs_rq_load_avg(cfs_rq_clock_task(cfs_rq), cfs_rq, true); + update_rt_rq_load_avg(rq_clock_task(rq), cpu, &rq->rt, 0); rq_unlock_irqrestore(rq, &rf); } diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c index 581d5c7..09293fa 100644 --- a/kernel/sched/rt.c +++ b/kernel/sched/rt.c @@ -1534,6 +1534,8 @@ static struct task_struct *_pick_next_task_rt(struct rq *rq) return p; } +extern int update_rt_rq_load_avg(u64 now, int cpu, struct rt_rq *rt_rq, int running); + static struct task_struct * pick_next_task_rt(struct rq *rq, struct task_struct *prev, struct rq_flags *rf) { @@ -1579,6 +1581,10 @@ pick_next_task_rt(struct rq *rq, struct task_struct *prev, struct rq_flags *rf) queue_push_tasks(rq); + if (p) + update_rt_rq_load_avg(rq_clock_task(rq), cpu_of(rq), rt_rq, + rq->curr->sched_class == &rt_sched_class); + return p; } @@ -1586,6 +1592,8 @@ static void put_prev_task_rt(struct rq *rq, struct task_struct *p) { update_curr_rt(rq); + update_rt_rq_load_avg(rq_clock_task(rq), cpu_of(rq), &rq->rt, 1); + /* * The previous task needs to be made eligible for pushing * if it is still active @@ -2368,6 +2376,7 @@ static void task_tick_rt(struct rq *rq, struct task_struct *p, int queued) struct sched_rt_entity *rt_se = &p->rt; update_curr_rt(rq); + update_rt_rq_load_avg(rq_clock_task(rq), cpu_of(rq), &rq->rt, 1); watchdog(rq, p); diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index f8cf1d8..75b17ff 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -502,6 +502,9 @@ struct rt_rq { unsigned long rt_nr_total; int overloaded; struct plist_head pushable_tasks; + + struct sched_avg avg; + #ifdef HAVE_RT_PUSH_IPI int push_flags; int push_cpu; From patchwork Wed May 24 09:00:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 100421 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp177657qge; Wed, 24 May 2017 02:04:48 -0700 (PDT) X-Received: by 10.98.57.212 with SMTP id u81mr37547886pfj.9.1495616688775; Wed, 24 May 2017 02:04:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1495616688; cv=none; d=google.com; s=arc-20160816; b=XY6PFd1qxpO1Vl72IhjZozelaXo3IKhT2MrHzEF4XEexEqCw9cz3kxc3C2hFvWW14M elGDot2OoJH0pUWzaOY3aSXa5lKyxjStB/jITbX3449UBmEmBAL/3j+O38hoFHzDtIaV runKZHWzUIXver3dRlkTo6lukDv8JLZvd+/7UDx/TuzD4gkxZhXK/z83lutWmUVdL1bJ TGk8xWWL+cT8kdQ+uCCZRHVwsTZckSpbcdyplK2nq2KY4eLWYT8qccrRZ6pIsBgSPrMT AqZ97WOHnLEYQFy5OSKCnExO4ZMh66LHNQCBxCbD2oFinRo2yyC6LAyY2qPyc/DI61vg QFfg== 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:dkim-signature:arc-authentication-results; bh=AjSPiEScNaXHfSdPL8Qfj8QO0uCQA4cWYnO3sR67+ss=; b=gp+xLABCO6g+ANXnmC3pnLc+q3NeEEl6QPnLcBAiwHt1vLvon2pR8mMFxwvNZAe4us CwmVIPA52SLudETrVaKg9lN40l+OJCcrhhxftPQaG0tpS3KKSjmeFtqjOn7G35Fee0c4 J4X+lGPgg9+CH/70QkScBO/aiX3P1jO1KGjeHq2XnlybxXv/012UabKmdFBL/j8HJ/nR WDApOXT0nP+AoLUKuz2L1edljAVguXY2xjRZZIcJOOb8fXCQHP9muZ8ncqk52K1Xs5Ba Uq5jKdex23dLHLYgWLjI4aKhFX8DwSxybsYivYyAEdmaW0t8QtXcG4TCh8y9TlY2EtcT 8qGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p71si2081461pfa.29.2017.05.24.02.04.48; Wed, 24 May 2017 02:04:48 -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; dkim=pass header.i=@linaro.org; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967208AbdEXJEq (ORCPT + 25 others); Wed, 24 May 2017 05:04:46 -0400 Received: from mail-wm0-f52.google.com ([74.125.82.52]:35877 "EHLO mail-wm0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161972AbdEXJBB (ORCPT ); Wed, 24 May 2017 05:01:01 -0400 Received: by mail-wm0-f52.google.com with SMTP id 7so55763954wmo.1 for ; Wed, 24 May 2017 02:01:01 -0700 (PDT) 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; bh=AjSPiEScNaXHfSdPL8Qfj8QO0uCQA4cWYnO3sR67+ss=; b=O6I3Ju17j6LoN8uNVSWUTfAbTR4N38aibE7F8YZcbiWjYivuO8gmyK5WMlg2DZHq2z Xe6mF3sIpvp64gztvrgKusnpVl/x8r5sp0zhhN5oOuQpWBJ1DIUIigEUK0BOf+8N4Cjt zWARhRdUXB2xEWlQei72/Qo3lgAOzH9J14jyI= 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; bh=AjSPiEScNaXHfSdPL8Qfj8QO0uCQA4cWYnO3sR67+ss=; b=SAwTEv7aeIhu425fz5d5ZdBVqNkAfYXKWlmaxGNaK6BNlL7nakD+MbYt+I/cNg99rQ rOdHJxRIS8NRY+soFHF2FNAZCM8zl4zY6byfLDdmVlyb7oKkMOEVJv/9Wenc0Hb2M72j WLKcCCEnqw4AHgCUJmhnVV7budrCI4aW9bEL+wUjcA7X0VJlwYmonsF88MDZCSPxgKKM 6YIpt6NhVKjb3zolB0AR7XhWg5osv0cXcg5z8kybV8+g/nOfAbgcxKCdTTexhIkWpdfw 7mLcisdjVYq3iQmCXA38db5Jgj8XhFaMefXFbj+cqmQtVCoCYHewQNTtnUZSfQvPdTYq fZKA== X-Gm-Message-State: AODbwcAEfphGzhRDhmm6OlxESfAPge8JazVrOkfz2rGvwPiUam1hoxNJ sg2kZs7Ltk6zVxmD X-Received: by 10.223.134.80 with SMTP id 16mr22151803wrw.62.1495616460451; Wed, 24 May 2017 02:01:00 -0700 (PDT) Received: from localhost.localdomain ([2a01:e0a:f:6020:90ff:f881:739b:af16]) by smtp.gmail.com with ESMTPSA id w96sm4552076wrc.14.2017.05.24.02.00.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 24 May 2017 02:00:59 -0700 (PDT) From: Vincent Guittot To: peterz@infradead.org, mingo@kernel.org, linux-kernel@vger.kernel.org Cc: rjw@rjwysocki.net, juri.lelli@arm.com, dietmar.eggemann@arm.com, Morten.Rasmussen@arm.com, Vincent Guittot Subject: [PATCH 2/2] cpufreq/schedutil: add rt utilization tracking Date: Wed, 24 May 2017 11:00:52 +0200 Message-Id: <1495616452-7582-3-git-send-email-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1495616452-7582-1-git-send-email-vincent.guittot@linaro.org> References: <1495616452-7582-1-git-send-email-vincent.guittot@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add both cfs_rq and rt_rq's utilization when selecting an OPP for cfs task as rt task can preempt and steal cfs's running time. This prevent frequency drops when rt tasks steal running time to cfs tasks which appear lower than they are. Signed-off-by: Vincent Guittot --- kernel/sched/cpufreq_schedutil.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.7.4 diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c index 622eed1..bc292b92 100644 --- a/kernel/sched/cpufreq_schedutil.c +++ b/kernel/sched/cpufreq_schedutil.c @@ -164,7 +164,7 @@ static void sugov_get_util(unsigned long *util, unsigned long *max) cfs_max = arch_scale_cpu_capacity(NULL, smp_processor_id()); - *util = min(rq->cfs.avg.util_avg, cfs_max); + *util = min(rq->cfs.avg.util_avg + rq->rt.avg.util_avg, cfs_max); *max = cfs_max; }