From patchwork Thu Apr 24 12:24:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 28960 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f71.google.com (mail-yh0-f71.google.com [209.85.213.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 33AF3203AC for ; Thu, 24 Apr 2014 12:24:41 +0000 (UTC) Received: by mail-yh0-f71.google.com with SMTP id a41sf9462832yho.10 for ; Thu, 24 Apr 2014 05:24:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=yGS0+rzrFP0axE593g4oxkKEkBUDlZPsUIavRuWHe10=; b=IDbHJAVHjuI0MxjSVfSzF5+JTdyoksk7uRj8Y/oqby5KoRo4eyxvLmqEMDiUuKQUbq MPcdFZXWx8tzigYe5W7//9HH+R75TuMubMHosg6ZPuctJf1C6InNP8gP4PSW7UkwJ9KH EFGs0ArtMQnX5KFS+f2XEUPQvfjahQ0fFpXKLaVDffCUGdiljHpCGc5zn6Z9M/bZWuDY GsvcsjAldEC0DDvEwxoiZdFQVn/0zPYi8BJp955p6b5RIyIthOi6epemsKjzZ74in1+x RokjxzuCdmlRscHLXxIzlL+TSuhV5Jq14rmuRLE7M4DsbzvCPZW/XpD+LQkzXNJsXP2o hJSA== X-Gm-Message-State: ALoCoQk1Itni4Ch2L/TavZRy+YO5swXCz3vM3+iHHXgtkDVk/N1uaQ4AC6A6WLpW/RdxdCFWAERR X-Received: by 10.236.216.39 with SMTP id f37mr9157320yhp.57.1398342280850; Thu, 24 Apr 2014 05:24:40 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.101.4 with SMTP id t4ls1064787qge.1.gmail; Thu, 24 Apr 2014 05:24:40 -0700 (PDT) X-Received: by 10.52.170.237 with SMTP id ap13mr32441vdc.74.1398342280711; Thu, 24 Apr 2014 05:24:40 -0700 (PDT) Received: from mail-ve0-f177.google.com (mail-ve0-f177.google.com [209.85.128.177]) by mx.google.com with ESMTPS id b7si874630vev.148.2014.04.24.05.24.40 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 24 Apr 2014 05:24:40 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.128.177; Received: by mail-ve0-f177.google.com with SMTP id sa20so2775711veb.36 for ; Thu, 24 Apr 2014 05:24:40 -0700 (PDT) X-Received: by 10.221.62.131 with SMTP id xa3mr1034159vcb.13.1398342280600; Thu, 24 Apr 2014 05:24:40 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp11627vcb; Thu, 24 Apr 2014 05:24:40 -0700 (PDT) X-Received: by 10.68.113.5 with SMTP id iu5mr2975024pbb.60.1398342279791; Thu, 24 Apr 2014 05:24:39 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id xf3si2571915pab.261.2014.04.24.05.24.39; Thu, 24 Apr 2014 05:24:39 -0700 (PDT) Received-SPF: none (google.com: linux-pm-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755368AbaDXMYg (ORCPT + 12 others); Thu, 24 Apr 2014 08:24:36 -0400 Received: from mail-wg0-f43.google.com ([74.125.82.43]:64019 "EHLO mail-wg0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755884AbaDXMY3 (ORCPT ); Thu, 24 Apr 2014 08:24:29 -0400 Received: by mail-wg0-f43.google.com with SMTP id x13so2187535wgg.14 for ; Thu, 24 Apr 2014 05:24:28 -0700 (PDT) X-Received: by 10.180.95.4 with SMTP id dg4mr2602427wib.9.1398342268087; Thu, 24 Apr 2014 05:24:28 -0700 (PDT) Received: from localhost.localdomain (AToulouse-654-1-448-67.w83-205.abo.wanadoo.fr. [83.205.199.67]) by mx.google.com with ESMTPSA id wl6sm6008074wjb.3.2014.04.24.05.24.26 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 24 Apr 2014 05:24:27 -0700 (PDT) From: Daniel Lezcano To: peterz@infradead.org, mingo@elte.hu Cc: linux-kernel@vger.kernel.org, rjw@rjwysocki.net, linux-pm@vger.kernel.org, alex.shi@linaro.org, vincent.guittot@linaro.org, morten.rasmussen@arm.com, linaro-kernel@lists.linaro.org Subject: [PATCH 2/3] sched: idle: Add sched balance option Date: Thu, 24 Apr 2014 14:24:50 +0200 Message-Id: <1398342291-16322-3-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1398342291-16322-1-git-send-email-daniel.lezcano@linaro.org> References: <1398342291-16322-1-git-send-email-daniel.lezcano@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: daniel.lezcano@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This patch adds a sysctl schedule balance option to choose against: * auto (0) * performance (1) * power (2) It relies on the recently added notifier to monitor the power supply changes. If the scheduler balance option is set to 'auto', then when the system switches to battery, the balance option change to 'power' and when it goes back to AC, it switches to 'performance'. The default value is 'auto'. If the kernel is compiled without the CONFIG_POWER_SUPPLY option, then any call to the 'auto' option will fail and the scheduler will use the 'performance' option as default. Signed-off-by: Daniel Lezcano --- include/linux/sched/sysctl.h | 14 +++++++ kernel/sched/fair.c | 92 +++++++++++++++++++++++++++++++++++++++++- kernel/sysctl.c | 11 +++++ 3 files changed, 115 insertions(+), 2 deletions(-) diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h index 8045a55..f8507bf 100644 --- a/include/linux/sched/sysctl.h +++ b/include/linux/sched/sysctl.h @@ -44,6 +44,20 @@ enum sched_tunable_scaling { }; extern enum sched_tunable_scaling sysctl_sched_tunable_scaling; +#ifdef CONFIG_SMP +enum sched_balance_option { + SCHED_BALANCE_OPTION_PERFORMANCE, + SCHED_BALANCE_OPTION_POWER, + SCHED_BALANCE_OPTION_AUTO, + SCHED_BALANCE_OPTION_END, +}; +extern enum sched_balance_option sysctl_sched_balance_option; + +int sched_proc_balance_option_handler(struct ctl_table *table, int write, + void __user *buffer, size_t *length, + loff_t *ppos); +#endif + extern unsigned int sysctl_numa_balancing_scan_delay; extern unsigned int sysctl_numa_balancing_scan_period_min; extern unsigned int sysctl_numa_balancing_scan_period_max; diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 7570dd9..7b8e93d 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -29,7 +29,7 @@ #include #include #include - +#include #include #include "sched.h" @@ -61,6 +61,24 @@ unsigned int normalized_sysctl_sched_latency = 6000000ULL; enum sched_tunable_scaling sysctl_sched_tunable_scaling = SCHED_TUNABLESCALING_LOG; +#ifdef CONFIG_SMP +/* + * Scheduler balancing policy: + * + * Options are: + * SCHED_BALANCE_OPTION_PERFORMANCE - full performance + * SCHED_BALANCE_OPTION_POWER - power saving aggressive + * SCHED_BALANCE_OPTION_AUTO - switches to 'performance' when plugged + * on or 'power' on battery + */ +enum sched_balance_option sysctl_sched_balance_option + = SCHED_BALANCE_OPTION_AUTO; + +static int sched_current_balance_option + = SCHED_BALANCE_OPTION_PERFORMANCE; + +#endif + /* * Minimal preemption granularity for CPU-bound tasks: * (default: 0.75 msec * (1 + ilog(ncpus)), units: nanoseconds) @@ -555,6 +573,76 @@ static struct sched_entity *__pick_next_entity(struct sched_entity *se) return rb_entry(next, struct sched_entity, run_node); } +#ifdef CONFIG_SMP +static int sched_balance_option_update(void) +{ + int ret; + + /* + * Copy the current balance option + */ + if (sysctl_sched_balance_option != SCHED_BALANCE_OPTION_AUTO) { + sched_current_balance_option = sysctl_sched_balance_option; + return 0; + } + + /* + * This call may fail if the kernel is not compiled with + * the POWER_SUPPLY option. + */ + ret = power_supply_is_system_supplied(); + if (ret < 0) { + sysctl_sched_balance_option = sched_current_balance_option; + return ret; + } + + /* + * When in 'auto' mode, switch to 'performance if the system + * is plugged on the wall, to 'power' if we are on battery + */ + sched_current_balance_option = ret ? + SCHED_BALANCE_OPTION_PERFORMANCE : + SCHED_BALANCE_OPTION_POWER; + + return 0; +} + +int sched_proc_balance_option_handler(struct ctl_table *table, int write, + void __user *buffer, size_t *length, + loff_t *ppos) +{ + int ret; + + ret = proc_dointvec_minmax(table, write, buffer, length, ppos); + if (ret) + return ret; + + return sched_balance_option_update(); +} + +static int sched_power_supply_notifier(struct notifier_block *b, + unsigned long l, void *v) +{ + sched_balance_option_update(); + return NOTIFY_OK; +} + +static struct notifier_block power_supply_notifier_nb = { + .notifier_call = sched_power_supply_notifier, +}; + +static int sched_balance_option_init(void) +{ + int ret; + + ret = sched_balance_option_update(); + if (ret) + return ret; + + return power_supply_reg_notifier(&power_supply_notifier_nb); +} +#endif + #ifdef CONFIG_SCHED_DEBUG struct sched_entity *__pick_last_entity(struct cfs_rq *cfs_rq) { @@ -7695,7 +7783,7 @@ __init void init_sched_fair_class(void) { #ifdef CONFIG_SMP open_softirq(SCHED_SOFTIRQ, run_rebalance_domains); - + sched_balance_option_init(); #ifdef CONFIG_NO_HZ_COMMON nohz.next_balance = jiffies; zalloc_cpumask_var(&nohz.idle_cpus_mask, GFP_NOWAIT); diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 74f5b58..e4ecc7d 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -282,6 +282,17 @@ static struct ctl_table kern_table[] = { .mode = 0644, .proc_handler = proc_dointvec, }, +#ifdef CONFIG_SMP + { + .procname = "sched_balance_option", + .data = &sysctl_sched_balance_option, + .maxlen = sizeof(enum sched_balance_option), + .mode = 0644, + .proc_handler = sched_proc_balance_option_handler, + .extra1 = &zero, /* SCHED_BALANCE_OPTION_AUTO */ + .extra2 = &two, /* SCHED_BALANCE_OPTION_POWER */ + }, +#endif #ifdef CONFIG_SCHED_DEBUG { .procname = "sched_min_granularity_ns",