From patchwork Thu Jun 29 05:26:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 9815997 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A231660365 for ; Thu, 29 Jun 2017 05:28:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9742A28520 for ; Thu, 29 Jun 2017 05:28:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8AF4C28564; Thu, 29 Jun 2017 05:28:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D91A528520 for ; Thu, 29 Jun 2017 05:28:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751747AbdF2F2e (ORCPT ); Thu, 29 Jun 2017 01:28:34 -0400 Received: from mail-pf0-f169.google.com ([209.85.192.169]:35337 "EHLO mail-pf0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751850AbdF2F15 (ORCPT ); Thu, 29 Jun 2017 01:27:57 -0400 Received: by mail-pf0-f169.google.com with SMTP id c73so44560181pfk.2 for ; Wed, 28 Jun 2017 22:27:57 -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 :in-reply-to:references; bh=wmP5Q5X+JSJ0vDsGUnlfJGfRlwEng18Xv9V32BkrYps=; b=W1TJvEdfhNRKlFrqqik9sAuSOZHPmhoLlNp6uWEL+SIVDItXCgLWI0Z4jeh2cxKSwX sC6prRZpKP4LG7NAYDn3/Sqnk09Jz6aQsvCNBZvy8H2xfefDFxQ8rDU8KwYcwo8CoNyU c0qeDrTc4iWCEqYNXhna6g3dOc659Rd0242Ss= 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:in-reply-to:references; bh=wmP5Q5X+JSJ0vDsGUnlfJGfRlwEng18Xv9V32BkrYps=; b=fRfU0rY6RqIc7FnBCFlfh5aZhB8wmBpXmMh/9/KEyukG8wo79cnmx28ONQjq8J+9jq PnglES66GIKJLpGHRkEz8JQa0FAr1R8YJtrGv8DimyXNfvHDapOIYZCKZ5fmmIy8aCY5 B2ikEidxpVd/Txwoh1pbP2Xi2Eqg/HYUE9NQpqRB2lG/msw/M9+g8jhP/g6HfjeLN7Qt +bpwpGC1oAbxXdgqW0xGijRUADlYopynJ7L4HMKtXBRm+117wEDwBopkJhxc1Kij4iVu AjmsCA+I9J55bdjj5Y02ifFD6f3dxw5SD/XLsY0Q0HWhpGwrNfSZm1LDw42+Tt4WYS6U joQg== X-Gm-Message-State: AKS2vOxfRRdPZXCR5YM+u0R21DYF2Ndl8CCfFQo0x2YprD+yxx58GdLM rxDKoVuKwuXrFlUg X-Received: by 10.84.233.204 with SMTP id m12mr15921007pln.292.1498714076534; Wed, 28 Jun 2017 22:27:56 -0700 (PDT) Received: from localhost ([122.171.238.149]) by smtp.gmail.com with ESMTPSA id l63sm9183933pfc.132.2017.06.28.22.27.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Jun 2017 22:27:56 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , Ingo Molnar , Peter Zijlstra Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , linux-kernel@vger.kernel.org, smuckle.linux@gmail.com, juri.lelli@arm.com, Morten.Rasmussen@arm.com, patrick.bellasi@arm.com, eas-dev@lists.linaro.org Subject: [PATCH V2 1/4] cpufreq: schedutil: Process remote callback for shared policies Date: Thu, 29 Jun 2017 10:56:30 +0530 Message-Id: <643fe4ad707e3b02336ecf069e7f022d770bec98.1498712046.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.13.0.71.gd7076ec9c9cb In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch updates the schedutil governor to process cpufreq utilization update hooks called for remote CPUs (i.e. For updates to the runqueue of other non-local CPUs). For now, we only support remote callbacks for CPUs which share their cpufreq policy with the local CPU. It may not be worth allowing remote callbacks in other cases, as we wouldn't be able to update the frequency on local CPU in that case. The schedutil governor already has proper locking in place for shared policy update hooks. This also adds a new field "cpu" in "struct update_util_data", to identify the remote CPU. Based on initial work from Steve Muckle. Signed-off-by: Steve Muckle Signed-off-by: Viresh Kumar --- include/linux/sched/cpufreq.h | 1 + kernel/sched/cpufreq.c | 1 + kernel/sched/cpufreq_schedutil.c | 19 ++++++++++++++----- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/include/linux/sched/cpufreq.h b/include/linux/sched/cpufreq.h index d2be2ccbb372..8256a8f35f22 100644 --- a/include/linux/sched/cpufreq.h +++ b/include/linux/sched/cpufreq.h @@ -16,6 +16,7 @@ #ifdef CONFIG_CPU_FREQ struct update_util_data { void (*func)(struct update_util_data *data, u64 time, unsigned int flags); + unsigned int cpu; }; void cpufreq_add_update_util_hook(int cpu, struct update_util_data *data, diff --git a/kernel/sched/cpufreq.c b/kernel/sched/cpufreq.c index dbc51442ecbc..ee4c596b71b4 100644 --- a/kernel/sched/cpufreq.c +++ b/kernel/sched/cpufreq.c @@ -42,6 +42,7 @@ void cpufreq_add_update_util_hook(int cpu, struct update_util_data *data, return; data->func = func; + data->cpu = cpu; rcu_assign_pointer(per_cpu(cpufreq_update_util_data, cpu), data); } EXPORT_SYMBOL_GPL(cpufreq_add_update_util_hook); diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c index 076a2e31951c..3f9cae9ab326 100644 --- a/kernel/sched/cpufreq_schedutil.c +++ b/kernel/sched/cpufreq_schedutil.c @@ -154,12 +154,12 @@ 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(unsigned long *util, unsigned long *max, int cpu) { - struct rq *rq = this_rq(); + struct rq *rq = cpu_rq(cpu); unsigned long cfs_max; - cfs_max = arch_scale_cpu_capacity(NULL, smp_processor_id()); + cfs_max = arch_scale_cpu_capacity(NULL, cpu); *util = min(rq->cfs.avg.util_avg, cfs_max); *max = cfs_max; @@ -218,6 +218,10 @@ static void sugov_update_single(struct update_util_data *hook, u64 time, unsigned int next_f; bool busy; + /* Remote callbacks aren't allowed for policies which aren't shared */ + if (smp_processor_id() != hook->cpu) + return; + sugov_set_iowait_boost(sg_cpu, time, flags); sg_cpu->last_update = time; @@ -229,7 +233,7 @@ static void sugov_update_single(struct update_util_data *hook, u64 time, if (flags & SCHED_CPUFREQ_RT_DL) { next_f = policy->cpuinfo.max_freq; } else { - sugov_get_util(&util, &max); + sugov_get_util(&util, &max, hook->cpu); sugov_iowait_boost(sg_cpu, &util, &max); next_f = get_next_freq(sg_policy, util, max); /* @@ -287,10 +291,15 @@ 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; + struct cpufreq_policy *policy = sg_policy->policy; unsigned long util, max; unsigned int next_f; - sugov_get_util(&util, &max); + /* Allow remote callbacks only on the CPUs sharing cpufreq policy */ + if (!cpumask_test_cpu(smp_processor_id(), policy->cpus)) + return; + + sugov_get_util(&util, &max, hook->cpu); raw_spin_lock(&sg_policy->update_lock);