From patchwork Thu Nov 30 11:47:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Bellasi X-Patchwork-Id: 120144 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp558781qgn; Thu, 30 Nov 2017 03:47:59 -0800 (PST) X-Google-Smtp-Source: AGs4zMZFUUz9/GWM8FcLWoJiDj6MdbaT1vdnwluFEnBe7w3j9b+4YB7chCky7ahSAndGWYqcaT7l X-Received: by 10.84.204.8 with SMTP id a8mr2316868ple.399.1512042479171; Thu, 30 Nov 2017 03:47:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512042479; cv=none; d=google.com; s=arc-20160816; b=EWSFU1yYQg3n3ozoRy3SdqSsRB1zblI3mRbOF4bdQfgcfdFk0/vjlTOz67LOXlnTYD ipuHEMS34HBbqZjJlU0GLYlr6WIESdm1ohgoxuY6fbkesTQJNmFkNwPAQzhUdYmNzTW+ I7qlFmRL9LmL2UJeK3orf1BaNCZBJ0jYmGN5Jlg4hWNWFqcatU00FeSAA3GHSiCQPf1O iQ9eOfYhOqdWm4qCnnD2sxhGaXei7Ousw6Ff/nIUMpVWFWYeuZfkaJmmbA+woaHBQ0Pa chZ8RpOAEOHoDLGJ9o8k6V5qGlz64Mz1Wfa7oMYvrga2TCZ4bSGSAx3J6eshZb8k6qDt FXjQ== 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=3GJAzXp2jDWZgkwqEstJA6cEnSU/itIU9k8ThYgDgZk=; b=julG5NlFTcCkgJxuap0ckpohh56UgDxKlciTahXibtvDg7gJrkhnNDJfXATO1qLu64 XQD8rdHcvixiBfjmdKf29K/ZHhBqzBcdF7u24mpvcm7hbJ8oV3pGPB+HxMKIHikAX6wO 8NweJEZjPu1dwn992WfXtxxVZeXoGAA1V3sduiw7/t7qfEXBqZf9dnUfMSDwfWnUJ6r6 xHpAriunTgAn3VMtljNNLDsb+4ZUwmtuyDmGAaaAFn7lYOQA0U7Rox6BTLLN+b9lV2ot 0Cd2PGGcTKRjDt1OK/URBvK+ANRDa/zYpFLiM+1SBWp3rFD/ZrrkzZEx/idoxR5Ari96 yRLg== 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 y20si3150041pfa.158.2017.11.30.03.47.58; Thu, 30 Nov 2017 03:47:59 -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; 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 S1752554AbdK3Lr4 (ORCPT + 26 others); Thu, 30 Nov 2017 06:47:56 -0500 Received: from foss.arm.com ([217.140.101.70]:51262 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752495AbdK3Lrx (ORCPT ); Thu, 30 Nov 2017 06:47:53 -0500 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 6A89715A2; Thu, 30 Nov 2017 03:47:53 -0800 (PST) Received: from e110439-lin.cambridge.arm.com (e110439-lin.cambridge.arm.com [10.1.210.68]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 10D1D3F236; Thu, 30 Nov 2017 03:47:50 -0800 (PST) From: Patrick Bellasi To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Cc: Ingo Molnar , Peter Zijlstra , "Rafael J . Wysocki" , Viresh Kumar , Vincent Guittot , Dietmar Eggemann , Morten Rasmussen , Juri Lelli , Todd Kjos , Joel Fernandes , Steve Muckle Subject: [PATCH v3 2/6] cpufreq: schedutil: ensure max frequency while running RT/DL tasks Date: Thu, 30 Nov 2017 11:47:19 +0000 Message-Id: <20171130114723.29210-3-patrick.bellasi@arm.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171130114723.29210-1-patrick.bellasi@arm.com> References: <20171130114723.29210-1-patrick.bellasi@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The policy in use for RT/DL tasks sets the maximum frequency when a task in these classes calls for a cpufreq_update_util(). However, the current implementation might cause a frequency drop while a RT/DL task is still running, just because for example a FAIR task wakes up and it's enqueued in the same CPU. This issue is due to the sg_cpu's flags being overwritten at each call of sugov_update_*. Thus, the wakeup of a FAIR task resets the flags and can trigger a frequency update thus affecting the currently running RT/DL task. This can be fixed, in shared frequency domains, by ORing (instead of overwriting) the new flag before triggering a frequency update. This grants to stay at least at the frequency requested by the RT/DL class, which is the maximum one for the time being. This patch does the flags aggregation in the schedutil governor, where it's easy to verify if we currently have RT/DL workload on a CPU. This approach is aligned with the current schedutil API design where the core scheduler does not interact directly with schedutil, while instead are the scheduling classes which call directly into the policy via cpufreq_update_util. Thus, it makes more sense to have flags aggregation in the schedutil code instead of the core scheduler. Signed-off-by: Patrick Bellasi Reviewed-by: Dietmar Eggemann Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Rafael J. Wysocki Cc: Viresh Kumar Cc: Steve Muckle Cc: linux-kernel@vger.kernel.org Cc: linux-pm@vger.kernel.org --- Changes from v2: - rebased on v4.15-rc1 Changes from v1: - use "current" to check for RT/DL tasks (PeterZ) Change-Id: Ia4bd6ae09ae034a954d37cd38ffea86396ac1257 --- kernel/sched/cpufreq_schedutil.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) -- 2.14.1 diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c index 67339ccb5595..448f49de5335 100644 --- a/kernel/sched/cpufreq_schedutil.c +++ b/kernel/sched/cpufreq_schedutil.c @@ -262,6 +262,7 @@ static void sugov_update_single(struct update_util_data *hook, u64 time, struct cpufreq_policy *policy = sg_policy->policy; unsigned long util, max; unsigned int next_f; + bool rt_mode; bool busy; sugov_set_iowait_boost(sg_cpu, time, flags); @@ -272,7 +273,15 @@ 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) { + /* + * While RT/DL tasks are running we do not want FAIR tasks to + * overvrite this CPU's flags, still we can update utilization and + * frequency (if required/possible) to be fair with these tasks. + */ + rt_mode = task_has_dl_policy(current) || + task_has_rt_policy(current) || + (flags & SCHED_CPUFREQ_RT_DL); + if (rt_mode) { next_f = policy->cpuinfo.max_freq; } else { sugov_get_util(&util, &max, sg_cpu->cpu); @@ -340,6 +349,7 @@ static void sugov_update_shared(struct update_util_data *hook, u64 time, struct sugov_policy *sg_policy = sg_cpu->sg_policy; unsigned long util, max; unsigned int next_f; + bool rt_mode; sugov_get_util(&util, &max, sg_cpu->cpu); @@ -353,17 +363,27 @@ static void sugov_update_shared(struct update_util_data *hook, u64 time, sg_cpu->flags = 0; goto done; } - sg_cpu->flags = flags; + + /* + * While RT/DL tasks are running we do not want FAIR tasks to + * overwrite this CPU's flags, still we can update utilization and + * frequency (if required/possible) to be fair with these tasks. + */ + rt_mode = task_has_dl_policy(current) || + task_has_rt_policy(current) || + (flags & SCHED_CPUFREQ_RT_DL); + if (rt_mode) + sg_cpu->flags |= flags; + else + sg_cpu->flags = flags; sugov_set_iowait_boost(sg_cpu, time, flags); sg_cpu->last_update = time; if (sugov_should_update_freq(sg_policy, time)) { - if (flags & SCHED_CPUFREQ_RT_DL) - next_f = sg_policy->policy->cpuinfo.max_freq; - else - next_f = sugov_next_freq_shared(sg_cpu, time); - + next_f = rt_mode + ? sg_policy->policy->cpuinfo.max_freq + : sugov_next_freq_shared(sg_cpu, time); sugov_update_commit(sg_policy, time, next_f); }