From patchwork Tue Jan 9 13:53:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 123962 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp4047830qgn; Tue, 9 Jan 2018 05:54:11 -0800 (PST) X-Google-Smtp-Source: ACJfBotYpxxN3dFvlDM0XyLWDDEWColQ+lBBmuUgPp+5OJoA1xcA/GhS+ZtzDTcm0ktk+Qh9p8A2 X-Received: by 10.84.128.74 with SMTP id 68mr5897035pla.228.1515506051236; Tue, 09 Jan 2018 05:54:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515506051; cv=none; d=google.com; s=arc-20160816; b=sy0I4eBad8dmghHQWoFWh2KzsD1ikmCPZxnmzKBFJvNKs/2QRxIUVqODqn8gZRTNND taTKSNJEFR1+WsAi2Bh8BHNKgBqjUInjWeSzYL9MrKlI6WGr2xkXQiPQ2yHg9jmpAB/1 Hk8R0kXlfcTA+Z5eX+R7AwuJu98LNLCsC8CiJMVglzu0DdZlyNo5TruOBQ4GQYButnA6 9n5FeX482qotCQSWnYiGMy+0qkfQHOygM6TuAflgJj+cbkLv7STChlo46tImcm6bCfdp +x+R1X2NWLW0kQHry/gxWNMtj1aV9p5LMVVxaKbJq/EqG8D+ax/K8NYqKMl9++nbLyq3 0hQA== 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=5+s+8sTwMQVSPlVy9iMynL2IG5jJA2tkCOxOzC9yL9g=; b=FGVpUpk/SfUH+PJiuMkOOuEYc47ys8ItPunVUCViK5ZbviO4WFhkpufypSAYqN89qX Cen0ShN62yiM9wkUwc82Ro2I2fji6hB4Zd1bKwtcx/rc9NPPbu1Vuf8k3VR3tR+cRUny 8kUWH3VvfVRDcdkMDBnDtnW7GLmJu6OlvzoVrWcbSiZcgAFV/W+mfhQm+XdUf8u42rys zRpSo1pypgnIaJa9+yPooQ7129gH59mhOOE6DhldlQB1UBuuY+PwiA3qg4AehG/qkUwY /BU3P3jFxQkmSCgRlVFDwbxw0ipWoTojVMMY1TSPbG3BdMKdy/ps/NhFYkHJvycNNxas XsAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=K49/QOHM; 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 u5si9042745pgp.237.2018.01.09.05.54.10; Tue, 09 Jan 2018 05:54:11 -0800 (PST) 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 header.s=google header.b=K49/QOHM; 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 S1758205AbeAINyJ (ORCPT + 28 others); Tue, 9 Jan 2018 08:54:09 -0500 Received: from mail-wr0-f195.google.com ([209.85.128.195]:39615 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750786AbeAINxT (ORCPT ); Tue, 9 Jan 2018 08:53:19 -0500 Received: by mail-wr0-f195.google.com with SMTP id z48so8461466wrz.6 for ; Tue, 09 Jan 2018 05:53:19 -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; bh=5+s+8sTwMQVSPlVy9iMynL2IG5jJA2tkCOxOzC9yL9g=; b=K49/QOHMnSlLkgCdPerRMab88tKqFGKyM6qW2d0KOwQYB5+4y7V7yRKB0nZ++azJhW sBD8kQaVf6D9MgfYbXxaVZT5EtU0yZmlIHfqDssX3OvxssSt92WmR73XLhSbIYtzqskj XFe9dVh7YGpdZw1fcMlMLTstA7fO6m+2aO3ms= 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=5+s+8sTwMQVSPlVy9iMynL2IG5jJA2tkCOxOzC9yL9g=; b=DCmAUc3pMwvdPB4TiPPwGBgtrTDdHW/ZGHmueff9FnuIhxCP5+Yba6EFRdItJCsT7S t5KBKG+QGfUB9sJGT/+1EYe6NqpKvK8w/QE+XdUTZKl2okpJdvG4BqDnyOpK2Y9810fr 0X9g7t53aHrMmMfg5oHJPfj2dNKjLRTlSzLbRIBadyAhx7Bx6TC2kv2u0cc6f+3Jyj7V EYrZqSUpdCa3xruzXeGCXudyU7C3eOVGCfh1F/KAAtEPelfnX7XvGKSO2fvnKfJZQ4WX ARpWlB/vKgJJPedCmzANIbjL3NEZNHmSb8joCJ3XiyWbfgLq6V6WvZpjDa6uTE1+gSWM iWlg== X-Gm-Message-State: AKGB3mLmz8iYA6+AwBz8Y3TafNk1lOYV5AoY9v6SxCOcQHHDKeVDWwTh HEm/tJ1EjWjK92olZqMRLss/qw== X-Received: by 10.223.195.197 with SMTP id d5mr13856425wrg.86.1515505998148; Tue, 09 Jan 2018 05:53:18 -0800 (PST) Received: from localhost.localdomain ([2a01:e0a:f:6020:f51d:768f:aab1:18e6]) by smtp.gmail.com with ESMTPSA id e7sm15070597wrd.82.2018.01.09.05.53.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 09 Jan 2018 05:53:16 -0800 (PST) From: Vincent Guittot To: peterz@infradead.org, mingo@kernel.org, linux-kernel@vger.kernel.org, rjw@rjwysocki.net Cc: juri.lelli@arm.com, dietmar.eggemann@arm.com, Morten.Rasmussen@arm.com, viresh.kumar@linaro.org, Vincent Guittot Subject: [PATCH RESEND v3 2/3] sched/rt: add rt_rq utilization tracking Date: Tue, 9 Jan 2018 14:53:05 +0100 Message-Id: <1515505986-21997-3-git-send-email-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515505986-21997-1-git-send-email-vincent.guittot@linaro.org> References: <1515505986-21997-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 task but not what cfs want to use. In such case, schedutil can select a lower OPP 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 "stolen" by RT tasks. Signed-off-by: Vincent Guittot --- kernel/sched/fair.c | 2 ++ kernel/sched/pelt.c | 23 +++++++++++++++++++++++ kernel/sched/pelt.h | 7 +++++++ kernel/sched/rt.c | 8 ++++++++ kernel/sched/sched.h | 1 + 5 files changed, 41 insertions(+) -- 2.7.4 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 1abcf6e..6844fb7 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -7072,6 +7072,7 @@ 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); } @@ -7131,6 +7132,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); + update_rt_rq_load_avg(rq_clock_task(rq), cpu, &rq->rt, 0); rq_unlock_irqrestore(rq, &rf); } diff --git a/kernel/sched/pelt.c b/kernel/sched/pelt.c index da6d84f..ac09b69 100644 --- a/kernel/sched/pelt.c +++ b/kernel/sched/pelt.c @@ -306,3 +306,26 @@ int __update_load_avg_cfs_rq(u64 now, int cpu, struct cfs_rq *cfs_rq) return 0; } + +/* + * rt_rq: + * + * util_sum = \Sum se->avg.util_sum but se->avg.util_sum is not tracked + * util_sum = cpu_scale * load_sum + * runnable_load_sum = load_sum + * + */ + +int update_rt_rq_load_avg(u64 now, int cpu, struct rt_rq *rt_rq, int running) +{ + if (___update_load_sum(now, cpu, &rt_rq->avg, + running, + running, + running)) { + + ___update_load_avg(&rt_rq->avg, 1, 1); + return 1; + } + + return 0; +} diff --git a/kernel/sched/pelt.h b/kernel/sched/pelt.h index c312d8c..78a2107 100644 --- a/kernel/sched/pelt.h +++ b/kernel/sched/pelt.h @@ -3,6 +3,7 @@ int __update_load_avg_blocked_se(u64 now, int cpu, struct sched_entity *se); int __update_load_avg_se(u64 now, int cpu, struct cfs_rq *cfs_rq, struct sched_entity *se); int __update_load_avg_cfs_rq(u64 now, int cpu, struct cfs_rq *cfs_rq); +int update_rt_rq_load_avg(u64 now, int cpu, struct rt_rq *rt_rq, int running); #else @@ -12,6 +13,12 @@ update_cfs_rq_load_avg(u64 now, struct cfs_rq *cfs_rq) return 0; } +static inline int +update_rt_rq_load_avg(u64 now, int cpu, struct rt_rq *rt_rq, int running) +{ + return 0; +} + #endif diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c index 4056c19..09c2616 100644 --- a/kernel/sched/rt.c +++ b/kernel/sched/rt.c @@ -9,6 +9,8 @@ #include #include +#include "pelt.h" + int sched_rr_timeslice = RR_TIMESLICE; int sysctl_sched_rr_timeslice = (MSEC_PER_SEC / HZ) * RR_TIMESLICE; @@ -1569,6 +1571,9 @@ pick_next_task_rt(struct rq *rq, struct task_struct *prev, struct rq_flags *rf) queue_push_tasks(rq); + update_rt_rq_load_avg(rq_clock_task(rq), cpu_of(rq), rt_rq, + rq->curr->sched_class == &rt_sched_class); + return p; } @@ -1576,6 +1581,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 @@ -2283,6 +2290,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 9c56e73..7eaa103 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -529,6 +529,7 @@ struct rt_rq { int overloaded; struct plist_head pushable_tasks; + struct sched_avg avg; #endif /* CONFIG_SMP */ int rt_queued;