linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] ACPI / cpuidle: More code complexity/duplication reduction
@ 2015-02-03 21:14 Rafael J. Wysocki
  2015-02-03 21:15 ` [PATCH 1/2] ACPI / cpuidle: Merge acpi_idle_enter_c1() and acpi_idle_enter_simple() Rafael J. Wysocki
  2015-02-03 21:15 ` [PATCH 2/2] ACPI / cpuidle: Common callback routine for entering states Rafael J. Wysocki
  0 siblings, 2 replies; 3+ messages in thread
From: Rafael J. Wysocki @ 2015-02-03 21:14 UTC (permalink / raw)
  To: Linux PM list
  Cc: Linux Kernel Mailing List, ACPI Devel Maling List, Len Brown,
	Peter Zijlstra

Hi,

Two more ACPI cpuidle patches on top of the ones I sent a few days ago:

https://lkml.org/lkml/2015/1/29/779

They don't break anything for me and preserve the original logic AFAICS,
but please holler if you see any problems with them.

Thanks!


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] ACPI / cpuidle: Merge acpi_idle_enter_c1() and acpi_idle_enter_simple()
  2015-02-03 21:14 [PATCH 0/2] ACPI / cpuidle: More code complexity/duplication reduction Rafael J. Wysocki
@ 2015-02-03 21:15 ` Rafael J. Wysocki
  2015-02-03 21:15 ` [PATCH 2/2] ACPI / cpuidle: Common callback routine for entering states Rafael J. Wysocki
  1 sibling, 0 replies; 3+ messages in thread
From: Rafael J. Wysocki @ 2015-02-03 21:15 UTC (permalink / raw)
  To: Linux PM list
  Cc: Linux Kernel Mailing List, ACPI Devel Maling List, Len Brown,
	Peter Zijlstra

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

acpi_idle_enter_c1() and acpi_idle_enter_simple() are close enough to
each other that they can be merged into one function which reduces
duplication of code quite a bit.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/acpi/processor_idle.c |   43 +++++-------------------------------------
 1 file changed, 6 insertions(+), 37 deletions(-)

Index: linux-pm/drivers/acpi/processor_idle.c
===================================================================
--- linux-pm.orig/drivers/acpi/processor_idle.c
+++ linux-pm/drivers/acpi/processor_idle.c
@@ -704,34 +704,6 @@ static void acpi_idle_do_entry(struct ac
 }
 
 /**
- * acpi_idle_enter_c1 - enters an ACPI C1 state-type
- * @dev: the target CPU
- * @drv: cpuidle driver containing cpuidle state info
- * @index: index of target state
- *
- * This is equivalent to the HALT instruction.
- */
-static int acpi_idle_enter_c1(struct cpuidle_device *dev,
-		struct cpuidle_driver *drv, int index)
-{
-	struct acpi_processor *pr;
-	struct acpi_processor_cx *cx = per_cpu(acpi_cstate[index], dev->cpu);
-
-	pr = __this_cpu_read(processors);
-
-	if (unlikely(!pr))
-		return -EINVAL;
-
-	lapic_timer_state_broadcast(pr, cx, 1);
-	acpi_idle_do_entry(cx);
-
-	lapic_timer_state_broadcast(pr, cx, 0);
-
-	return index;
-}
-
-
-/**
  * acpi_idle_play_dead - enters an ACPI state for long-term idle (i.e. off-lining)
  * @dev: the target CPU
  * @index: the index of suggested state
@@ -766,7 +738,7 @@ static bool acpi_idle_fallback_to_c1(str
 }
 
 /**
- * acpi_idle_enter_simple - enters an ACPI state without BM handling
+ * acpi_idle_enter_simple - enters a CPU idle state without BM handling
  * @dev: the target CPU
  * @drv: cpuidle driver with cpuidle state information
  * @index: the index of suggested state
@@ -782,8 +754,10 @@ static int acpi_idle_enter_simple(struct
 	if (unlikely(!pr))
 		return -EINVAL;
 
-	if (acpi_idle_fallback_to_c1(pr))
-		return acpi_idle_enter_c1(dev, drv, CPUIDLE_DRIVER_STATE_START);
+	if (cx->type != ACPI_STATE_C1 && acpi_idle_fallback_to_c1(pr)) {
+		index = CPUIDLE_DRIVER_STATE_START;
+		cx = per_cpu(acpi_cstate[index], dev->cpu);
+	}
 
 	lapic_timer_state_broadcast(pr, cx, 1);
 
@@ -819,7 +793,7 @@ static int acpi_idle_enter_bm(struct cpu
 		return -EINVAL;
 
 	if (acpi_idle_fallback_to_c1(pr))
-		return acpi_idle_enter_c1(dev, drv, CPUIDLE_DRIVER_STATE_START);
+		return acpi_idle_enter_simple(dev, drv, CPUIDLE_DRIVER_STATE_START);
 
 	if (!cx->bm_sts_skip && acpi_idle_bm_check()) {
 		if (drv->safe_state_index >= 0) {
@@ -967,11 +941,6 @@ static int acpi_processor_setup_cpuidle_
 		switch (cx->type) {
 
 		case ACPI_STATE_C1:
-			state->enter = acpi_idle_enter_c1;
-			state->enter_dead = acpi_idle_play_dead;
-			drv->safe_state_index = count;
-			break;
-
 		case ACPI_STATE_C2:
 			state->enter = acpi_idle_enter_simple;
 			state->enter_dead = acpi_idle_play_dead;


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] ACPI / cpuidle: Common callback routine for entering states
  2015-02-03 21:14 [PATCH 0/2] ACPI / cpuidle: More code complexity/duplication reduction Rafael J. Wysocki
  2015-02-03 21:15 ` [PATCH 1/2] ACPI / cpuidle: Merge acpi_idle_enter_c1() and acpi_idle_enter_simple() Rafael J. Wysocki
@ 2015-02-03 21:15 ` Rafael J. Wysocki
  1 sibling, 0 replies; 3+ messages in thread
From: Rafael J. Wysocki @ 2015-02-03 21:15 UTC (permalink / raw)
  To: Linux PM list
  Cc: Linux Kernel Mailing List, ACPI Devel Maling List, Len Brown,
	Peter Zijlstra

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Introduce a common ->enter callback routine for the ACPI cpuidle
driver, acpi_idle_enter(), which helps to reduce code complexity,
size and duplication and prevents theoretically possible failues that
an incorrect routine may be run to enter the given idle state due to
a firmware bug (eg. when _CST returns a different set of states for
each processor).

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/acpi/processor_idle.c |  118 ++++++++++++++++--------------------------
 1 file changed, 45 insertions(+), 73 deletions(-)

Index: linux-pm/drivers/acpi/processor_idle.c
===================================================================
--- linux-pm.orig/drivers/acpi/processor_idle.c
+++ linux-pm/drivers/acpi/processor_idle.c
@@ -737,74 +737,17 @@ static bool acpi_idle_fallback_to_c1(str
 		!pr->flags.has_cst;
 }
 
-/**
- * acpi_idle_enter_simple - enters a CPU idle state without BM handling
- * @dev: the target CPU
- * @drv: cpuidle driver with cpuidle state information
- * @index: the index of suggested state
- */
-static int acpi_idle_enter_simple(struct cpuidle_device *dev,
-		struct cpuidle_driver *drv, int index)
-{
-	struct acpi_processor *pr;
-	struct acpi_processor_cx *cx = per_cpu(acpi_cstate[index], dev->cpu);
-
-	pr = __this_cpu_read(processors);
-
-	if (unlikely(!pr))
-		return -EINVAL;
-
-	if (cx->type != ACPI_STATE_C1 && acpi_idle_fallback_to_c1(pr)) {
-		index = CPUIDLE_DRIVER_STATE_START;
-		cx = per_cpu(acpi_cstate[index], dev->cpu);
-	}
-
-	lapic_timer_state_broadcast(pr, cx, 1);
-
-	if (cx->type == ACPI_STATE_C3)
-		ACPI_FLUSH_CPU_CACHE();
-
-	acpi_idle_do_entry(cx);
-
-	lapic_timer_state_broadcast(pr, cx, 0);
-	return index;
-}
-
 static int c3_cpu_count;
 static DEFINE_RAW_SPINLOCK(c3_lock);
 
 /**
  * acpi_idle_enter_bm - enters C3 with proper BM handling
- * @dev: the target CPU
- * @drv: cpuidle driver containing state data
- * @index: the index of suggested state
- *
- * If BM is detected, the deepest non-C3 idle state is entered instead.
+ * @pr: Target processor
+ * @cx: Target state context
  */
-static int acpi_idle_enter_bm(struct cpuidle_device *dev,
-		struct cpuidle_driver *drv, int index)
+static void acpi_idle_enter_bm(struct acpi_processor *pr,
+			       struct acpi_processor_cx *cx)
 {
-	struct acpi_processor *pr;
-	struct acpi_processor_cx *cx = per_cpu(acpi_cstate[index], dev->cpu);
-
-	pr = __this_cpu_read(processors);
-
-	if (unlikely(!pr))
-		return -EINVAL;
-
-	if (acpi_idle_fallback_to_c1(pr))
-		return acpi_idle_enter_simple(dev, drv, CPUIDLE_DRIVER_STATE_START);
-
-	if (!cx->bm_sts_skip && acpi_idle_bm_check()) {
-		if (drv->safe_state_index >= 0) {
-			return drv->states[drv->safe_state_index].enter(dev,
-						drv, drv->safe_state_index);
-		} else {
-			acpi_safe_halt();
-			return -EBUSY;
-		}
-	}
-
 	acpi_unlazy_tlb(smp_processor_id());
 
 	/*
@@ -842,6 +785,45 @@ static int acpi_idle_enter_bm(struct cpu
 	}
 
 	lapic_timer_state_broadcast(pr, cx, 0);
+}
+
+static int acpi_idle_enter(struct cpuidle_device *dev,
+			   struct cpuidle_driver *drv, int index)
+{
+	struct acpi_processor_cx *cx = per_cpu(acpi_cstate[index], dev->cpu);
+	struct acpi_processor *pr;
+
+	pr = __this_cpu_read(processors);
+	if (unlikely(!pr))
+		return -EINVAL;
+
+	if (cx->type != ACPI_STATE_C1) {
+		if (acpi_idle_fallback_to_c1(pr)) {
+			index = CPUIDLE_DRIVER_STATE_START;
+			cx = per_cpu(acpi_cstate[index], dev->cpu);
+		} else if (cx->type == ACPI_STATE_C3 && pr->flags.bm_check) {
+			if (cx->bm_sts_skip || !acpi_idle_bm_check()) {
+				acpi_idle_enter_bm(pr, cx);
+				return index;
+			} else if (drv->safe_state_index >= 0) {
+				index = drv->safe_state_index;
+				cx = per_cpu(acpi_cstate[index], dev->cpu);
+			} else {
+				acpi_safe_halt();
+				return -EBUSY;
+			}
+		}
+	}
+
+	lapic_timer_state_broadcast(pr, cx, 1);
+
+	if (cx->type == ACPI_STATE_C3)
+		ACPI_FLUSH_CPU_CACHE();
+
+	acpi_idle_do_entry(cx);
+
+	lapic_timer_state_broadcast(pr, cx, 0);
+
 	return index;
 }
 
@@ -936,22 +918,12 @@ static int acpi_processor_setup_cpuidle_
 		strncpy(state->desc, cx->desc, CPUIDLE_DESC_LEN);
 		state->exit_latency = cx->latency;
 		state->target_residency = cx->latency * latency_factor;
+		state->enter = acpi_idle_enter;
 
 		state->flags = 0;
-		switch (cx->type) {
-
-		case ACPI_STATE_C1:
-		case ACPI_STATE_C2:
-			state->enter = acpi_idle_enter_simple;
+		if (cx->type == ACPI_STATE_C1 || cx->type == ACPI_STATE_C2) {
 			state->enter_dead = acpi_idle_play_dead;
 			drv->safe_state_index = count;
-			break;
-
-		case ACPI_STATE_C3:
-			state->enter = pr->flags.bm_check ?
-					acpi_idle_enter_bm :
-					acpi_idle_enter_simple;
-			break;
 		}
 
 		count++;


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-02-03 20:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-03 21:14 [PATCH 0/2] ACPI / cpuidle: More code complexity/duplication reduction Rafael J. Wysocki
2015-02-03 21:15 ` [PATCH 1/2] ACPI / cpuidle: Merge acpi_idle_enter_c1() and acpi_idle_enter_simple() Rafael J. Wysocki
2015-02-03 21:15 ` [PATCH 2/2] ACPI / cpuidle: Common callback routine for entering states Rafael J. Wysocki

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).