Linux ACPI
 help / color / mirror / Atom feed
* [PATCH 1/2] ACPI: Check the returned value of set_cpus_allowed_ptr before T-state operation
@ 2011-01-10  8:35 yakui.zhao
  2011-01-10  8:35 ` [PATCH 2/2] ACPI: Reevaluate whether the T-state is supported or not after cpu is online/offline yakui.zhao
  2011-01-10 17:35 ` [PATCH 1/2] ACPI: Check the returned value of set_cpus_allowed_ptr before T-state operation Len Brown
  0 siblings, 2 replies; 4+ messages in thread
From: yakui.zhao @ 2011-01-10  8:35 UTC (permalink / raw)
  To: lenb; +Cc: linux-acpi, Zhao Yakui

From: Zhao Yakui <yakui.zhao@intel.com>

Now before it executes the T-state operation on one CPU, it will try to
migrate to the target CPU. Especially this is required on the system that
uses the MSR_IA32_THERMAL_CONTROL register to switch T-state.
But unfortunately it doesn't check whether the migration is successful or not.
In such case we will get/set the incorrect T-state on the offline CPU as
it fails in the migration to the offline CPU.

Signed-off-by: Zhao Yakui <yakui.zhao@intel.com>
---
 drivers/acpi/processor_throttling.c |   24 +++++++++++++++++++++---
 1 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/drivers/acpi/processor_throttling.c b/drivers/acpi/processor_throttling.c
index ff36327..ffc859c 100644
--- a/drivers/acpi/processor_throttling.c
+++ b/drivers/acpi/processor_throttling.c
@@ -876,7 +876,11 @@ static int acpi_processor_get_throttling(struct acpi_processor *pr)
 	 */
 	cpumask_copy(saved_mask, &current->cpus_allowed);
 	/* FIXME: use work_on_cpu() */
-	set_cpus_allowed_ptr(current, cpumask_of(pr->id));
+	if (set_cpus_allowed_ptr(current, cpumask_of(pr->id))) {
+		/* Can't migrate to the target pr->id CPU. Exit */
+		free_cpumask_var(saved_mask);
+		return -ENODEV;
+	}
 	ret = pr->throttling.acpi_processor_get_throttling(pr);
 	/* restore the previous state */
 	set_cpus_allowed_ptr(current, saved_mask);
@@ -1051,6 +1055,14 @@ int acpi_processor_set_throttling(struct acpi_processor *pr,
 		return -ENOMEM;
 	}
 
+	if (cpu_is_offline(pr->id)) {
+		/*
+		 * the cpu pointed by pr->id is offline. Unnecessary to change
+		 * the throttling state any more.
+		 */
+		return -ENODEV;
+	}
+
 	cpumask_copy(saved_mask, &current->cpus_allowed);
 	t_state.target_state = state;
 	p_throttling = &(pr->throttling);
@@ -1074,7 +1086,11 @@ int acpi_processor_set_throttling(struct acpi_processor *pr,
 	 */
 	if (p_throttling->shared_type == DOMAIN_COORD_TYPE_SW_ANY) {
 		/* FIXME: use work_on_cpu() */
-		set_cpus_allowed_ptr(current, cpumask_of(pr->id));
+		if (set_cpus_allowed_ptr(current, cpumask_of(pr->id))) {
+			/* Can't migrate to the pr->id CPU. Exit */
+			ret = -ENODEV;
+			goto exit;
+		}
 		ret = p_throttling->acpi_processor_set_throttling(pr,
 						t_state.target_state, force);
 	} else {
@@ -1106,7 +1122,8 @@ int acpi_processor_set_throttling(struct acpi_processor *pr,
 			}
 			t_state.cpu = i;
 			/* FIXME: use work_on_cpu() */
-			set_cpus_allowed_ptr(current, cpumask_of(i));
+			if (set_cpus_allowed_ptr(current, cpumask_of(i)))
+				continue;
 			ret = match_pr->throttling.
 				acpi_processor_set_throttling(
 				match_pr, t_state.target_state, force);
@@ -1126,6 +1143,7 @@ int acpi_processor_set_throttling(struct acpi_processor *pr,
 	/* restore the previous state */
 	/* FIXME: use work_on_cpu() */
 	set_cpus_allowed_ptr(current, saved_mask);
+exit:
 	free_cpumask_var(online_throttling_cpus);
 	free_cpumask_var(saved_mask);
 	return ret;
-- 
1.5.4.5


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

* [PATCH 2/2] ACPI: Reevaluate whether the T-state is supported or not after cpu is online/offline
  2011-01-10  8:35 [PATCH 1/2] ACPI: Check the returned value of set_cpus_allowed_ptr before T-state operation yakui.zhao
@ 2011-01-10  8:35 ` yakui.zhao
  2011-01-10 17:36   ` Len Brown
  2011-01-10 17:35 ` [PATCH 1/2] ACPI: Check the returned value of set_cpus_allowed_ptr before T-state operation Len Brown
  1 sibling, 1 reply; 4+ messages in thread
From: yakui.zhao @ 2011-01-10  8:35 UTC (permalink / raw)
  To: lenb; +Cc: linux-acpi, Zhao Yakui

From: Zhao Yakui <yakui.zhao@intel.com>

After one CPU is offlined, it is unnecessary to switch T-state for it. 
So it will be better that the throttling is disabled after the cpu
is offline. 
At the same time after one cpu is online, we should check whether
the T-state is supported and then set the corresponding T-state
flag.


Signed-off-by: Zhao Yakui <yakui.zhao@intel.com>
---
 drivers/acpi/processor_driver.c     |    5 +++
 drivers/acpi/processor_throttling.c |   52 +++++++++++++++++++++++++++++++++++
 include/acpi/processor.h            |    6 ++++
 3 files changed, 63 insertions(+), 0 deletions(-)

diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
index 85e4804..c8a0ca2 100644
--- a/drivers/acpi/processor_driver.c
+++ b/drivers/acpi/processor_driver.c
@@ -478,8 +478,13 @@ static int acpi_cpu_soft_notify(struct notifier_block *nfb,
 	if (action == CPU_ONLINE && pr) {
 		acpi_processor_ppc_has_changed(pr, 0);
 		acpi_processor_cst_has_changed(pr);
+		acpi_processor_reevaluate_tstate(pr, action);
 		acpi_processor_tstate_has_changed(pr);
 	}
+	if (action == CPU_DEAD && pr) {
+		/* invalidate the flag.throttling after one CPU is offline */
+		acpi_processor_reevaluate_tstate(pr, action);
+	}
 	return NOTIFY_OK;
 }
 
diff --git a/drivers/acpi/processor_throttling.c b/drivers/acpi/processor_throttling.c
index ffc859c..4305d56 100644
--- a/drivers/acpi/processor_throttling.c
+++ b/drivers/acpi/processor_throttling.c
@@ -370,6 +370,58 @@ int acpi_processor_tstate_has_changed(struct acpi_processor *pr)
 }
 
 /*
+ * This function is used to reevaluate whether the T-state is valid
+ * after one CPU is onlined/offlined.
+ * It is noted that it won't reevaluate the following properties for
+ * the T-state.
+ *	1. Control method.
+ *	2. the number of supported T-state
+ *	3. TSD domain
+ */
+void acpi_processor_reevaluate_tstate(struct acpi_processor *pr,
+					unsigned long action)
+{
+	int result = 0;
+
+	if (action == CPU_DEAD) {
+		/* When one CPU is offline, the T-state throttling
+		 * will be invalidated.
+		 */
+		pr->flags.throttling = 0;
+		return;
+	}
+	/* the following is to recheck whether the T-state is valid for
+	 * the online CPU
+	 */
+	if (!pr->throttling.state_count) {
+		/* If the number of T-state is invalid, it is
+		 * invalidated.
+		 */
+		pr->flags.throttling = 0;
+		return;
+	}
+	pr->flags.throttling = 1;
+
+	/* Disable throttling (if enabled).  We'll let subsequent
+	 * policy (e.g.thermal) decide to lower performance if it
+	 * so chooses, but for now we'll crank up the speed.
+	 */
+
+	result = acpi_processor_get_throttling(pr);
+	if (result)
+		goto end;
+
+	if (pr->throttling.state) {
+		result = acpi_processor_set_throttling(pr, 0, false);
+		if (result)
+			goto end;
+	}
+
+end:
+	if (result)
+		pr->flags.throttling = 0;
+}
+/*
  * _PTC - Processor Throttling Control (and status) register location
  */
 static int acpi_processor_get_throttling_control(struct acpi_processor *pr)
diff --git a/include/acpi/processor.h b/include/acpi/processor.h
index 1b62102..55192ac 100644
--- a/include/acpi/processor.h
+++ b/include/acpi/processor.h
@@ -324,6 +324,12 @@ int acpi_processor_tstate_has_changed(struct acpi_processor *pr);
 int acpi_processor_get_throttling_info(struct acpi_processor *pr);
 extern int acpi_processor_set_throttling(struct acpi_processor *pr,
 					 int state, bool force);
+/*
+ * Reevaluate whether the T-state is invalid after one cpu is
+ * onlined/offlined. In such case the flags.throttling will be updated.
+ */
+extern void acpi_processor_reevaluate_tstate(struct acpi_processor *pr,
+			unsigned long action);
 extern const struct file_operations acpi_processor_throttling_fops;
 extern void acpi_processor_throttling_init(void);
 /* in processor_idle.c */
-- 
1.5.4.5


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

* Re: [PATCH 1/2] ACPI: Check the returned value of set_cpus_allowed_ptr before T-state operation
  2011-01-10  8:35 [PATCH 1/2] ACPI: Check the returned value of set_cpus_allowed_ptr before T-state operation yakui.zhao
  2011-01-10  8:35 ` [PATCH 2/2] ACPI: Reevaluate whether the T-state is supported or not after cpu is online/offline yakui.zhao
@ 2011-01-10 17:35 ` Len Brown
  1 sibling, 0 replies; 4+ messages in thread
From: Len Brown @ 2011-01-10 17:35 UTC (permalink / raw)
  To: Zhao Yakui; +Cc: linux-acpi

applied to acpi-test

thanks,
Len Brown, Intel Open Source Technology Center


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

* Re: [PATCH 2/2] ACPI: Reevaluate whether the T-state is supported or not after cpu is online/offline
  2011-01-10  8:35 ` [PATCH 2/2] ACPI: Reevaluate whether the T-state is supported or not after cpu is online/offline yakui.zhao
@ 2011-01-10 17:36   ` Len Brown
  0 siblings, 0 replies; 4+ messages in thread
From: Len Brown @ 2011-01-10 17:36 UTC (permalink / raw)
  To: Zhao Yakui; +Cc: linux-acpi

applied to acpi-test

BTW. At some point I think we should consider removing the _TSD support,
since BIOS support for it is guaranteed to be broken.

thanks,
Len Brown, Intel Open Source Technology Center

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

end of thread, other threads:[~2011-01-10 17:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-10  8:35 [PATCH 1/2] ACPI: Check the returned value of set_cpus_allowed_ptr before T-state operation yakui.zhao
2011-01-10  8:35 ` [PATCH 2/2] ACPI: Reevaluate whether the T-state is supported or not after cpu is online/offline yakui.zhao
2011-01-10 17:36   ` Len Brown
2011-01-10 17:35 ` [PATCH 1/2] ACPI: Check the returned value of set_cpus_allowed_ptr before T-state operation Len Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox