linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Julius Werner <jwerner@chromium.org>
To: linux-kernel@vger.kernel.org
Cc: len.brown@intel.com, khilman@ti.com, rjw@sisk.pl,
	deepthi@linux.vnet.ibm.com, akpm@linux-foundation.org,
	daniel.lezcano@linaro.org, g.trinabh@gmail.com,
	snanda@chromium.org, Julius Werner <jwerner@chromium.org>
Subject: [PATCH] cpuidle: reinitialize power_usage values when adding/removing C-states
Date: Tue, 16 Oct 2012 15:39:44 -0700	[thread overview]
Message-ID: <1350427184-11684-1-git-send-email-jwerner@chromium.org> (raw)

When cpuidle drivers do not supply explicit power_usage values,
cpuidle/driver.c inserts dummy values instead. When a running processor
dynamically gains new C-states (e.g. after ACPI events), the power_usage
values of those states will stay uninitialized, and cpuidle governors
will never choose to enter them.

This patch moves the dummy value initialization from
cpuidle_register_driver to cpuidle_enable_device, which drivers such as
acpi/processor_idle.c will call again when they add or remove C-states.
Tested and verified on an Acer AC700 Chromebook, which supports the C3
state only when it switches from AC to battery power.

Signed-off-by: Julius Werner <jwerner@chromium.org>
---
 drivers/cpuidle/cpuidle.c |   24 ++++++++++++++++++++++++
 drivers/cpuidle/driver.c  |   25 -------------------------
 2 files changed, 24 insertions(+), 25 deletions(-)

diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
index 7f15b85..bef3a31 100644
--- a/drivers/cpuidle/cpuidle.c
+++ b/drivers/cpuidle/cpuidle.c
@@ -298,6 +298,28 @@ static void poll_idle_init(struct cpuidle_driver *drv)
 static void poll_idle_init(struct cpuidle_driver *drv) {}
 #endif /* CONFIG_ARCH_HAS_CPU_RELAX */
 
+static void set_power_states(struct cpuidle_driver *drv)
+{
+	int i;
+
+	/*
+	 * cpuidle driver should set the drv->power_specified bit
+	 * before registering if the driver provides
+	 * power_usage numbers.
+	 *
+	 * If power_specified is not set,
+	 * we fill in power_usage with decreasing values as the
+	 * cpuidle code has an implicit assumption that state Cn
+	 * uses less power than C(n-1).
+	 *
+	 * With CONFIG_ARCH_HAS_CPU_RELAX, C0 is already assigned
+	 * an power value of -1.  So we use -2, -3, etc, for other
+	 * c-states.
+	 */
+	for (i = CPUIDLE_DRIVER_STATE_START; i < drv->state_count; i++)
+		drv->states[i].power_usage = -1 - i;
+}
+
 /**
  * cpuidle_enable_device - enables idle PM for a CPU
  * @dev: the CPU
@@ -330,6 +352,8 @@ int cpuidle_enable_device(struct cpuidle_device *dev)
 		cpuidle_enter_tk : cpuidle_enter;
 
 	poll_idle_init(drv);
+	if (!drv->power_specified)
+		set_power_states(drv);
 
 	if ((ret = cpuidle_add_state_sysfs(dev)))
 		return ret;
diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
index 87db387..caaed27 100644
--- a/drivers/cpuidle/driver.c
+++ b/drivers/cpuidle/driver.c
@@ -18,28 +18,6 @@ static struct cpuidle_driver *cpuidle_curr_driver;
 DEFINE_SPINLOCK(cpuidle_driver_lock);
 int cpuidle_driver_refcount;
 
-static void set_power_states(struct cpuidle_driver *drv)
-{
-	int i;
-
-	/*
-	 * cpuidle driver should set the drv->power_specified bit
-	 * before registering if the driver provides
-	 * power_usage numbers.
-	 *
-	 * If power_specified is not set,
-	 * we fill in power_usage with decreasing values as the
-	 * cpuidle code has an implicit assumption that state Cn
-	 * uses less power than C(n-1).
-	 *
-	 * With CONFIG_ARCH_HAS_CPU_RELAX, C0 is already assigned
-	 * an power value of -1.  So we use -2, -3, etc, for other
-	 * c-states.
-	 */
-	for (i = CPUIDLE_DRIVER_STATE_START; i < drv->state_count; i++)
-		drv->states[i].power_usage = -1 - i;
-}
-
 /**
  * cpuidle_register_driver - registers a driver
  * @drv: the driver
@@ -58,9 +36,6 @@ int cpuidle_register_driver(struct cpuidle_driver *drv)
 		return -EBUSY;
 	}
 
-	if (!drv->power_specified)
-		set_power_states(drv);
-
 	cpuidle_curr_driver = drv;
 
 	spin_unlock(&cpuidle_driver_lock);
-- 
1.7.8.6


             reply	other threads:[~2012-10-16 22:40 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-16 22:39 Julius Werner [this message]
2012-10-17 10:31 ` [PATCH] cpuidle: reinitialize power_usage values when adding/removing C-states Daniel Lezcano
2012-10-17 10:44   ` Daniel Lezcano
2012-10-17 18:43   ` Julius Werner
2012-10-18  8:21     ` Daniel Lezcano
2012-10-19 21:50       ` [PATCH] acpi/cpuidle: " Julius Werner
2012-10-20 21:50         ` Daniel Lezcano
2012-10-22 17:13           ` Julius Werner
2012-10-22 17:21             ` Daniel Lezcano
2012-11-12 20:26           ` [RFC] cpuidle - remove the power_specified field in the driver Daniel Lezcano
2012-11-12 21:09             ` Julius Werner
2012-11-12 22:08               ` Daniel Lezcano
2012-11-18  8:40             ` Francesco Lavra
2012-11-18  9:17               ` Daniel Lezcano
2012-12-10 19:09                 ` Julius Werner
2012-12-10 22:41                   ` Rafael J. Wysocki
2012-12-11  9:46                   ` Daniel Lezcano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1350427184-11684-1-git-send-email-jwerner@chromium.org \
    --to=jwerner@chromium.org \
    --cc=akpm@linux-foundation.org \
    --cc=daniel.lezcano@linaro.org \
    --cc=deepthi@linux.vnet.ibm.com \
    --cc=g.trinabh@gmail.com \
    --cc=khilman@ti.com \
    --cc=len.brown@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rjw@sisk.pl \
    --cc=snanda@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).