From patchwork Thu Nov 30 11:47:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Bellasi X-Patchwork-Id: 120143 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp558722qgn; Thu, 30 Nov 2017 03:47:56 -0800 (PST) X-Google-Smtp-Source: AGs4zMYNZkLePc1HINxvIY0FJ3c99nzpVfvWEVFq7x5kStnImAqiyzd9ZnEoP2VJNpNaxQuigtZ9 X-Received: by 10.99.96.147 with SMTP id u141mr2156421pgb.342.1512042475961; Thu, 30 Nov 2017 03:47:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512042475; cv=none; d=google.com; s=arc-20160816; b=v0ct/6c2ej2lkgPZkix6AbHFJWk0NOmVyONsg0EP2G61REyVJ/V9dZCHB0D7x7UlJG OMN0rPsEDO/ca+aLjN1oVMiHEtf4Va6EtwB/eKAlaBu2sRjn4sOpgUGSPRQJ8nDz4fhl s829OjVoQYf96VEjbSYufbBiNPUKhuGBCWEFqMA3QhG4GTULBL8oDD3tRJGmg/vk2foi 9JhgPcAQNj7mkUaW+lZrT6qGFkIjFQfW4HXgha6sbKL43pe0c19oQolVxlxoQsaoQlvE vRZSWjPAhPCm6gaKkG5myKjt7mmJcWWgQBYBLnyWuWQ4/RloK3fFYq0fFY4D7pEe/iM1 QNxg== 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=N8OrKQzHRfoDqUnDAv/zbIktL1JUHgthctBSuzfXP7E=; b=aptR9UQjCAOIqkLdHbAoh8wX5NH6qGObtHrtnBU9cYbgWrTWopyoCmneUBoUVQHHu6 JkUHL1oxDdB7whdYIv7KAFwZRUkJHXR4rVnqWK3ypzSzeJ5DLPU26fir9sbGfuKWOffw Csu2z/JTkeWSnLuYZG9jYxXVvrNjIcaz8aT61h8n/Byqk6DJTs+hQ7u3m1Enev34DlMo 2+mwVQpVJsc9lynd+3Y9GKTdSOwHxt43GcFNs6zG9V8htRYbenOI3+6qa+5aKCz8mh9B QFlFo+2kJO9a1uT6jehs/xMjuXEO2Du2HRLJxtV4DTjmuDW4mBc8U1LyOytAWkhE/nRq 2U4w== 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 d3si2949363pll.329.2017.11.30.03.47.55; Thu, 30 Nov 2017 03:47:55 -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 S1752494AbdK3Lrx (ORCPT + 26 others); Thu, 30 Nov 2017 06:47:53 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:51258 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751513AbdK3Lru (ORCPT ); Thu, 30 Nov 2017 06:47:50 -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 00CDF1596; Thu, 30 Nov 2017 03:47:50 -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 BEA883F236; Thu, 30 Nov 2017 03:47:47 -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 Subject: [PATCH v3 1/6] cpufreq: schedutil: reset sg_cpus's flags at IDLE enter Date: Thu, 30 Nov 2017 11:47:18 +0000 Message-Id: <20171130114723.29210-2-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 Currently, sg_cpu's flags are set to the value defined by the last call of the cpufreq_update_util(); for RT/DL classes this corresponds to the SCHED_CPUFREQ_{RT/DL} flags always being set. When multiple CPUs share the same frequency domain it might happen that a CPU which executed an RT task, right before entering IDLE, has one of the SCHED_CPUFREQ_RT_DL flags set, permanently, until it exits IDLE. Although such an idle CPU is _going to be_ ignored by the sugov_next_freq_shared(): 1. this kind of "useless RT requests" are ignored only if more then TICK_NSEC have elapsed since the last update 2. we can still potentially trigger an already too late switch to MAX, which starts also a new throttling interval 3. the internal state machine is not consistent with what the scheduler knows, i.e. the CPU is now actually idle Thus, in sugov_next_freq_shared(), where utilisation and flags are aggregated across all the CPUs of a frequency domain, it can turn out that all the CPUs of that domain can run unnecessary at the maximum OPP until another event happens in the idle CPU, which eventually clears the SCHED_CPUFREQ_{RT/DL} flag, or the IDLE CPUs gets ignored after TICK_NSEC [ns] since the CPU entering IDLE. Such a behaviour can harm the energy efficiency of systems where RT workloads are not so frequent and other CPUs in the same frequency domain are running small utilisation workloads, which is a quite common scenario in mobile embedded systems. This patch proposes a solution which is aligned with the current principle to update the flags each time a scheduling event happens. The scheduling of the idle_task on a CPU is considered one of such meaningful events. That's why when the idle_task is selected for execution we poke the schedutil policy to reset the flags for that CPU. No frequency transitions are activated at that point, which is fair in case the RT workload should come back in the future. However, this still allows other CPUs in the same frequency domain to scale down the frequency in case that should be possible. Signed-off-by: Patrick Bellasi Reviewed-by: Dietmar Eggemann Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Rafael J. Wysocki Cc: Viresh Kumar Cc: linux-kernel@vger.kernel.org Cc: linux-pm@vger.kernel.org --- Changes from v2: - use cpufreq_update_util() instead of cpufreq_update_this_cpu() - rebased on v4.15-rc1 Changes from v1: - added "unlikely()" around the statement (SteveR) Change-Id: I1192ca9a3acb767cb3a745967a7a23a17e1af7b7 --- include/linux/sched/cpufreq.h | 1 + kernel/sched/cpufreq_schedutil.c | 7 +++++++ kernel/sched/idle_task.c | 4 ++++ 3 files changed, 12 insertions(+) -- 2.14.1 diff --git a/include/linux/sched/cpufreq.h b/include/linux/sched/cpufreq.h index d1ad3d825561..bb5f778db023 100644 --- a/include/linux/sched/cpufreq.h +++ b/include/linux/sched/cpufreq.h @@ -11,6 +11,7 @@ #define SCHED_CPUFREQ_RT (1U << 0) #define SCHED_CPUFREQ_DL (1U << 1) #define SCHED_CPUFREQ_IOWAIT (1U << 2) +#define SCHED_CPUFREQ_IDLE (1U << 3) #define SCHED_CPUFREQ_RT_DL (SCHED_CPUFREQ_RT | SCHED_CPUFREQ_DL) diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c index 2f52ec0f1539..67339ccb5595 100644 --- a/kernel/sched/cpufreq_schedutil.c +++ b/kernel/sched/cpufreq_schedutil.c @@ -347,6 +347,12 @@ static void sugov_update_shared(struct update_util_data *hook, u64 time, sg_cpu->util = util; sg_cpu->max = max; + + /* CPU is entering IDLE, reset flags without triggering an update */ + if (unlikely(flags & SCHED_CPUFREQ_IDLE)) { + sg_cpu->flags = 0; + goto done; + } sg_cpu->flags = flags; sugov_set_iowait_boost(sg_cpu, time, flags); @@ -361,6 +367,7 @@ static void sugov_update_shared(struct update_util_data *hook, u64 time, sugov_update_commit(sg_policy, time, next_f); } +done: raw_spin_unlock(&sg_policy->update_lock); } diff --git a/kernel/sched/idle_task.c b/kernel/sched/idle_task.c index d518664cce4f..6e8ae2aa7a13 100644 --- a/kernel/sched/idle_task.c +++ b/kernel/sched/idle_task.c @@ -30,6 +30,10 @@ pick_next_task_idle(struct rq *rq, struct task_struct *prev, struct rq_flags *rf put_prev_task(rq, prev); update_idle_core(rq); schedstat_inc(rq->sched_goidle); + + /* kick cpufreq (see the comment in kernel/sched/sched.h). */ + cpufreq_update_util(rq, SCHED_CPUFREQ_IDLE); + return rq->idle; } 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); } From patchwork Thu Nov 30 11:47:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Bellasi X-Patchwork-Id: 120145 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp558816qgn; Thu, 30 Nov 2017 03:48:02 -0800 (PST) X-Google-Smtp-Source: AGs4zMb2Po8w6XdEjcFpRnWXlyxGHWMq+6h6pp3EOJv0rSinBV/D+A3RdjqHKIWJuwJohWJGJCsF X-Received: by 10.99.2.23 with SMTP id 23mr2058388pgc.99.1512042481891; Thu, 30 Nov 2017 03:48:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512042481; cv=none; d=google.com; s=arc-20160816; b=Z1Ts85cy2x7mQPyKnbgth+ydCqS2L8/Z86kgGYPBqyxdXxpSPQPOjS9efmLTwxGEgZ UtR3bOrjzacBYrHjCxAamknHqflDLhhu+Xh+fwiIJnL3scS4IK2nmoyifIShywjsOvbQ /+Q+s1gTV/sca0ohJi9F8fFHjjyL5X9hpfYHEbFR70qHzbwBQHQJYVGM0FMHQgeOQYZI e8YAKcjjeiQNmJO5wcoh0XhwoCP2oa3LZKm/0bCwDVNtsDwxljKBt6wdlmOoOTG9wENf deIFaJqoxbzPFoQ678I5Y+5Z5x9KmBALUibnCKQlCTWQ9KGVSdddnbowu0oBcamyWsvn 7X4A== 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=byrhcP4bLcxcFVGa5jRArDC5Hi0yLcrdvJf1Ge7lHNc=; b=oP+sHAxS4OMaPUj4P7jbBurHSapLQRcaol088LIMelM4JvVxXM/O7SqFiKOOkpJYhj 38nJzaowClzJ5MR6If+i5uhS1oiO6G34Zmch7Swb2bfVgPGzYCc+pllUcb4fUu1mMg/T YdkQ2kFC/b2Vzb0HGB/HllLePBtpFB7SLqTP3Qm643ReFsE9sFfvZm380iJhdBcCk9kQ wLgctIwWitsjxmmI9aPZLe5bwD/ccI/8d5qW/6TXRKck4/f5xvawi4Kf26iCnDyLY9/2 JR9LVVljK7X9TES9SiwCVY5ReFxDewADHRt/PP7iJm4clCdGsX3bzg43SjnAXzrdc2bu BbtQ== 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.48.01; Thu, 30 Nov 2017 03:48:01 -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 S1752609AbdK3Lr7 (ORCPT + 26 others); Thu, 30 Nov 2017 06:47:59 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:51280 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752550AbdK3Lr4 (ORCPT ); Thu, 30 Nov 2017 06:47:56 -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 9753A15BE; Thu, 30 Nov 2017 03:47:56 -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 60E923F236; Thu, 30 Nov 2017 03:47:54 -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 Subject: [PATCH v3 3/6] cpufreq: schedutil: update CFS util only if used Date: Thu, 30 Nov 2017 11:47:20 +0000 Message-Id: <20171130114723.29210-4-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 Currently the utilization of the FAIR class is collected before locking the policy. Although that should not be a big issue for most cases, we also don't really know how much latency there can be between the utilization reading and its usage. Let's get the FAIR utilization right before its usage to be better in sync with the current status of a CPU. Signed-off-by: Patrick Bellasi Reviewed-by: Dietmar Eggemann Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Rafael J. Wysocki Cc: Viresh Kumar Cc: linux-kernel@vger.kernel.org Cc: linux-pm@vger.kernel.org --- Changes from v2: - rebased on v4.15-rc1 Change-Id: I9291a560bcad7db76894e3f0fcdb917511d0479e --- kernel/sched/cpufreq_schedutil.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) -- 2.14.1 Reviewed-by: Juri Lelli diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c index 448f49de5335..40521d59630b 100644 --- a/kernel/sched/cpufreq_schedutil.c +++ b/kernel/sched/cpufreq_schedutil.c @@ -351,10 +351,9 @@ static void sugov_update_shared(struct update_util_data *hook, u64 time, unsigned int next_f; bool rt_mode; - sugov_get_util(&util, &max, sg_cpu->cpu); - raw_spin_lock(&sg_policy->update_lock); + sugov_get_util(&util, &max, sg_cpu->cpu); sg_cpu->util = util; sg_cpu->max = max; From patchwork Thu Nov 30 11:47:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Bellasi X-Patchwork-Id: 120146 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp558905qgn; Thu, 30 Nov 2017 03:48:07 -0800 (PST) X-Google-Smtp-Source: AGs4zMb9sW5JgiOnWqiotdYCbii/WKOuS4DiIphfcmMbH6byjzzyKGb8UQDNUTzg6S0VSdYm1c3S X-Received: by 10.101.98.131 with SMTP id f3mr2109011pgv.366.1512042487219; Thu, 30 Nov 2017 03:48:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512042487; cv=none; d=google.com; s=arc-20160816; b=spCO6cj9Z0GlR1T67KYbPM/wlCrVqQw6ghTod0AsgPeIPLmoQkZzCduPIV4/C7NAe+ eYh33HjyVnPjlXBSqzw+7mnwi4p1MJsWv/9aLFVdhWpCnoGmYtYsaN4Wa2ZaxdIDd4ou pzkOQ+mMbG3sgxz792eZDZUd3i+W2KhT/u7AGJvxKgq7w4iOxXFuNiCOQlxhL4X6DwhW w8M4JpOAI9DgOlFgwJU258RUAosPNSJYc/zg/jR/J1n0FyK/ZH46qrUWwwDizBVVLoTP Nrqjc2EM+FZXxCpqM2fDLXpapOKKcuBn3v0bPjXchnxkEO8QNU2pieG4edeCMZHfGALt nYCg== 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=UcuvBk3Agozojw9x1RDUVG5jZ73tvgsKTGWzlC7gSUk=; b=avr2/+v5vzn5jCWuGErKFedxYICj7NR1Syj8tYlXb0Vy5jG2EUFfDJJG7V1LK7YY0L EAy+wshaK6kdqQIZpKXMbGDcZbsKzcEpoZvJelvCF09RK8l6hnlUwfr5flE6dAiwFLUa Z2sU268WKvFGDHoJIK0kaB1Vnkghi0E9LmwUa+Vll2bK2LyZkZGvXEVDSdMjQjN3hn90 +D69+ofIXyGhVsxj5nqNCoLLm+7IQMHz8qyilNrukWKc9Sm8qh3PHeYZdUqVjvt5RE/P zg/bE8nDJ3FZhxOP7Bs/Runp1/5Hm1M9POmsacgYmLTClF0SZUXejgOeStOFyNVMR07U KuiA== 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 w11si3130892pfk.209.2017.11.30.03.48.06; Thu, 30 Nov 2017 03:48:07 -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 S1752676AbdK3LsD (ORCPT + 26 others); Thu, 30 Nov 2017 06:48:03 -0500 Received: from foss.arm.com ([217.140.101.70]:51310 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752550AbdK3LsA (ORCPT ); Thu, 30 Nov 2017 06:48:00 -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 B0B2A1610; Thu, 30 Nov 2017 03:47:59 -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 7A4C43F236; Thu, 30 Nov 2017 03:47:57 -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 Subject: [PATCH v3 4/6] sched/rt: fast switch to maximum frequency when RT tasks are scheduled Date: Thu, 30 Nov 2017 11:47:21 +0000 Message-Id: <20171130114723.29210-5-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 Currently schedutil updates are triggered for the RT class using a single call place, which is part of the rt::update_curr_rt() used in: - dequeue_task_rt: but it does not make sense to set the schedutil's SCHED_CPUFREQ_RT in case the next task should not be an RT one - put_prev_task_rt: likewise, we set the SCHED_CPUFREQ_RT flag without knowing if required by the next task - pick_next_task_rt: likewise, the schedutil's SCHED_CPUFREQ_RT is set in case the prev task was RT, while we don't yet know if the next will be RT - task_tick_rt: that's the only really useful call, which can ramp up the frequency in case a RT task started its execution without a chance to order a frequency switch (e.g. because of the schedutil ratelimit) Apart from the last call in task_tick_rt, the others are at least useless. Thus, although being a simple solution, not all the call sites of that update_curr_rt() are interesting to trigger a frequency switch as well as some of the most interesting points are not covered by that call. For example, a task set to RT has to wait the next tick to get the frequency boost. This patch fixes these issues by placing explicitly the schedutils update calls in the only sensible places, which are: - when an RT task wakes up and it's enqueued in a CPU - when we actually pick a RT task for execution - at each tick time - when a task is set to be RT Signed-off-by: Patrick Bellasi Reviewed-by: Dietmar Eggemann Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Rafael J. Wysocki Cc: Viresh Kumar Cc: linux-kernel@vger.kernel.org Cc: linux-pm@vger.kernel.org --- Changes from v2: - rebased on v4.15-rc1 - use cpufreq_update_util() instead of cpufreq_update_this_cpu() Change-Id: I3794615819270fe175cb118eef3f7edd61f602ba --- kernel/sched/rt.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) -- 2.14.1 diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c index 4056c19ca3f0..6984032598a6 100644 --- a/kernel/sched/rt.c +++ b/kernel/sched/rt.c @@ -959,9 +959,6 @@ static void update_curr_rt(struct rq *rq) if (unlikely((s64)delta_exec <= 0)) return; - /* Kick cpufreq (see the comment in kernel/sched/sched.h). */ - cpufreq_update_util(rq, SCHED_CPUFREQ_RT); - schedstat_set(curr->se.statistics.exec_max, max(curr->se.statistics.exec_max, delta_exec)); @@ -1327,6 +1324,9 @@ enqueue_task_rt(struct rq *rq, struct task_struct *p, int flags) if (!task_current(rq, p) && p->nr_cpus_allowed > 1) enqueue_pushable_task(rq, p); + + /* Kick cpufreq (see the comment in kernel/sched/sched.h). */ + cpufreq_update_util(rq, SCHED_CPUFREQ_RT); } static void dequeue_task_rt(struct rq *rq, struct task_struct *p, int flags) @@ -1564,6 +1564,9 @@ pick_next_task_rt(struct rq *rq, struct task_struct *prev, struct rq_flags *rf) p = _pick_next_task_rt(rq); + /* Kick cpufreq (see the comment in kernel/sched/sched.h). */ + cpufreq_update_util(rq, SCHED_CPUFREQ_RT); + /* The running task is never eligible for pushing */ dequeue_pushable_task(rq, p); @@ -2282,6 +2285,9 @@ static void task_tick_rt(struct rq *rq, struct task_struct *p, int queued) { struct sched_rt_entity *rt_se = &p->rt; + /* Kick cpufreq (see the comment in kernel/sched/sched.h). */ + cpufreq_update_util(rq, SCHED_CPUFREQ_RT); + update_curr_rt(rq); watchdog(rq, p); @@ -2317,6 +2323,9 @@ static void set_curr_task_rt(struct rq *rq) p->se.exec_start = rq_clock_task(rq); + /* Kick cpufreq (see the comment in kernel/sched/sched.h). */ + cpufreq_update_util(rq, SCHED_CPUFREQ_RT); + /* The running task is never eligible for pushing */ dequeue_pushable_task(rq, p); } From patchwork Thu Nov 30 11:47:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Bellasi X-Patchwork-Id: 120147 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp558954qgn; Thu, 30 Nov 2017 03:48:09 -0800 (PST) X-Google-Smtp-Source: AGs4zMaWgoH3aisVpk+WwsgiL59Ts1IRZ8zBh8bi0lyKpx0H8EeASEyLOYdiG3K4xJW6fYeRe7Vl X-Received: by 10.99.98.194 with SMTP id w185mr2130630pgb.396.1512042489617; Thu, 30 Nov 2017 03:48:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512042489; cv=none; d=google.com; s=arc-20160816; b=eQGfdhDhR+AXdpw08DO5sPUl2A81oCPuP4LvH7R2wQVyGgt8x0MweoKDBIo72DPtNr KqRmR7dDES/1gTVphq5wjex5qqLhjFSS6S5w6ZCcIaQ0W+UpmU6viUbv2UfnwAAE/m9a Oxxb14O7u59pF+VHmV2Rl1PsMwIhkrU/1ZZMyog3MUL9LmAEmPzsJY6Lbct/eT/HCQ3T RnXjMHLW6u1ZDOQZZr4sZNhOUjL3texWBfOjZPtq9PCVcB0UL79WuuRKP0tdlMYFtiSG Ri9xsmFLNx+B8JsPNXFF1tCK7apW9PNK9tLaZtUPd8y9EbvDDv+a3RAaxqDZ2priWFdJ AS5g== 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=BjJ8oB3JRB/NIRazP3uG8YmC0FTuQg55RQQyDhFyESY=; b=TdVo+QEPvKmLiYxo3IEfIiCM39wdCu+fIb82uwO0ghxZAakhWaAn3WSBXD6gK3ebjy yHMV9jLEdnJ5npwqAqaCiq616QlcIvKzGZ6wPJoXLKg2r4barYLXCGJgFmJRvPe4rKGk nWm/6S30y52EOR7FX3jG6aSoCu3h/vC4XqbVIdpYJgvGWB5sLMEwbrKyLzaAuJrr+cE3 Y6tVarUqUqUobYqaCctmkr1vFPLlde+4WzUzph763JWVupdGBdxPpWa4a+EIPqhcTmcA zQQDu97SL41gJemtf6nLt2xTfawUppsaqg3QmPBvVn6AKtFwrDT1w7X8G4u4UDE2IVwi OaWQ== 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 y16si2890133pgc.589.2017.11.30.03.48.09; Thu, 30 Nov 2017 03:48:09 -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 S1752726AbdK3LsH (ORCPT + 26 others); Thu, 30 Nov 2017 06:48:07 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:51314 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752659AbdK3LsD (ORCPT ); Thu, 30 Nov 2017 06:48:03 -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 D0114164F; Thu, 30 Nov 2017 03:48:02 -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 998893F236; Thu, 30 Nov 2017 03:48:00 -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 Subject: [PATCH v3 5/6] cpufreq: schedutil: relax rate-limiting while running RT/DL tasks Date: Thu, 30 Nov 2017 11:47:22 +0000 Message-Id: <20171130114723.29210-6-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 is still enforcing a frequency switch rate limiting when these tasks are running. This is potentially working against the goal to switch to the maximum OPP when RT tasks are running. In certain unfortunate cases it can also happen that a RT task almost completes its activation at a lower OPP. This patch overrides on purpose the rate limiting configuration to better serve RT/DL tasks. As long as a frequency scaling operation is not in progress, a frequency switch is always authorized when running in "rt_mode", i.e. the current task in a CPU belongs to the RT/DL class. Signed-off-by: Patrick Bellasi Reviewed-by: Dietmar Eggemann Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Rafael J. Wysocki Cc: Viresh Kumar Cc: linux-kernel@vger.kernel.org Cc: linux-pm@vger.kernel.org --- Changes from v2: - rebased on v4.15-rc1 Change-Id: I733d47b9e265cebb2e3e5e71a3cd468e9be002d1 --- kernel/sched/cpufreq_schedutil.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) -- 2.14.1 Reviewed-by: Juri Lelli diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c index 40521d59630b..3eea8884e61b 100644 --- a/kernel/sched/cpufreq_schedutil.c +++ b/kernel/sched/cpufreq_schedutil.c @@ -74,7 +74,8 @@ static DEFINE_PER_CPU(struct sugov_cpu, sugov_cpu); /************************ Governor internals ***********************/ -static bool sugov_should_update_freq(struct sugov_policy *sg_policy, u64 time) +static bool sugov_should_update_freq(struct sugov_policy *sg_policy, + u64 time, bool rt_mode) { s64 delta_ns; @@ -111,6 +112,10 @@ static bool sugov_should_update_freq(struct sugov_policy *sg_policy, u64 time) return true; } + /* Always update if a RT/DL task is running */ + if (rt_mode) + return true; + delta_ns = time - sg_policy->last_freq_update_time; return delta_ns >= sg_policy->freq_update_delay_ns; } @@ -268,11 +273,6 @@ static void sugov_update_single(struct update_util_data *hook, u64 time, sugov_set_iowait_boost(sg_cpu, time, flags); sg_cpu->last_update = time; - if (!sugov_should_update_freq(sg_policy, time)) - return; - - busy = sugov_cpu_is_busy(sg_cpu); - /* * While RT/DL tasks are running we do not want FAIR tasks to * overvrite this CPU's flags, still we can update utilization and @@ -281,6 +281,11 @@ static void sugov_update_single(struct update_util_data *hook, u64 time, rt_mode = task_has_dl_policy(current) || task_has_rt_policy(current) || (flags & SCHED_CPUFREQ_RT_DL); + if (!sugov_should_update_freq(sg_policy, time, rt_mode)) + return; + + busy = sugov_cpu_is_busy(sg_cpu); + if (rt_mode) { next_f = policy->cpuinfo.max_freq; } else { @@ -379,7 +384,7 @@ static void sugov_update_shared(struct update_util_data *hook, u64 time, sugov_set_iowait_boost(sg_cpu, time, flags); sg_cpu->last_update = time; - if (sugov_should_update_freq(sg_policy, time)) { + if (sugov_should_update_freq(sg_policy, time, rt_mode)) { next_f = rt_mode ? sg_policy->policy->cpuinfo.max_freq : sugov_next_freq_shared(sg_cpu, time); From patchwork Thu Nov 30 11:47:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Bellasi X-Patchwork-Id: 120148 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp559128qgn; Thu, 30 Nov 2017 03:48:18 -0800 (PST) X-Google-Smtp-Source: AGs4zMYQ/5WoSybFZDJyzeVPRUJxAFnhXmdPOCg00aSPfChL9meNfr0/km24yROCayqONAgxuhj1 X-Received: by 10.159.194.1 with SMTP id x1mr2407694pln.48.1512042498892; Thu, 30 Nov 2017 03:48:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512042498; cv=none; d=google.com; s=arc-20160816; b=jZvR31mDu/0bvHe5A/KO30QTwYCAl9xdI7EFeLj4QkxBPU+X68T81l5R7nvD1BdfZD x9n2M0Ntd5/HCVbnqP43A1ffIU2T8Fgjbgfq60NvRqq/ZMTIRoenzjtrNvHO5Gu8SV6Q yFYUyST9znsK463CBrmiK4vlTV92wvcSEttwets5d82YY64h3t9n8bY+JG8lI7l3mEjt 1xfZHnsWwg9GelcB9bkqTcfFzh0xCx12ojb7nBPRLXkSBfOQYBfRhkus5tqAxrbd+N3w lKYDhNsEqmhLgr6JyFJCPYua7c9KChvymr83w+CH36oJ4IyoUlmHU9xXgsRhKum1knir ZCPg== 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=x18R921SGaIWHdwmFCuSjHzp43HDkAY77VjknIw5ZCM=; b=qNDhY/RGER8p0UIT8fb6gAgyB8KQUw8ENyfDq2h26tjpNEyf+Cua9PyJHgEdZSXsZ3 3MK3t9NqzmEmOHtYPFxumY48dqCSqRtxjLLNlj4tNBaSCPtjwa2acFy73cGFBuiATUkn 3DjB5imlyPsAdmi9aAS/7RJiS3pinsceQwWRV/ZuCBB7yzsdxYB1sOobpKKJCMoRHVLQ vOhdjIOLVAcebMWVaHqnoeazC+MIHJJHV8bcTVcW74K5dh32Idc51DqzVzw1zHS1l9GZ GbMy4pcMv1TEM0sejnOLFySazO+ZxkBX6cUycbSeTAF2DSw9NtkvC9eiwFUz+Eqbgtjt dkkQ== 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 y16si2890133pgc.589.2017.11.30.03.48.18; Thu, 30 Nov 2017 03:48:18 -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 S1752749AbdK3LsR (ORCPT + 26 others); Thu, 30 Nov 2017 06:48:17 -0500 Received: from foss.arm.com ([217.140.101.70]:51326 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752684AbdK3LsG (ORCPT ); Thu, 30 Nov 2017 06:48:06 -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 06E8E165C; Thu, 30 Nov 2017 03:48:06 -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 C47B43F236; Thu, 30 Nov 2017 03:48:03 -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 Subject: [PATCH v3 6/6] cpufreq: schedutil: ignore sugov kthreads Date: Thu, 30 Nov 2017 11:47:23 +0000 Message-Id: <20171130114723.29210-7-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 In system where multiple CPUs shares the same frequency domain a small workload on a CPU can still be subject to frequency spikes, generated by the activation of the sugov's kthread. Since the sugov kthread is a special RT task, which goal is just that to activate a frequency transition, it does not make sense for it to bias the schedutil's frequency selection policy. This patch exploits the information related to the current task to silently ignore cpufreq_update_this_cpu() calls, coming from the RT scheduler, while the sugov kthread is running. Signed-off-by: Patrick Bellasi Reviewed-by: Dietmar Eggemann Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Rafael J. Wysocki Cc: Viresh Kumar Cc: linux-kernel@vger.kernel.org Cc: linux-pm@vger.kernel.org --- Changes from v2: - rebased on v4.15-rc1 - moved at the end of the stack since considered more controversial Changes from v1: - move check before policy spinlock (JuriL) Change-Id: I4d749458229b6496dd24a8c357be42cd35a739fd --- kernel/sched/cpufreq_schedutil.c | 8 ++++++++ 1 file changed, 8 insertions(+) -- 2.14.1 Reviewed-by: Juri Lelli diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c index 3eea8884e61b..a93ad5b0c40d 100644 --- a/kernel/sched/cpufreq_schedutil.c +++ b/kernel/sched/cpufreq_schedutil.c @@ -270,6 +270,10 @@ static void sugov_update_single(struct update_util_data *hook, u64 time, bool rt_mode; bool busy; + /* Skip updates generated by sugov kthreads */ + if (unlikely(current == sg_policy->thread)) + return; + sugov_set_iowait_boost(sg_cpu, time, flags); sg_cpu->last_update = time; @@ -356,6 +360,10 @@ static void sugov_update_shared(struct update_util_data *hook, u64 time, unsigned int next_f; bool rt_mode; + /* Skip updates generated by sugov kthreads */ + if (unlikely(current == sg_policy->thread)) + return; + raw_spin_lock(&sg_policy->update_lock); sugov_get_util(&util, &max, sg_cpu->cpu);