ACPI : Add T-state event notifier function
authorZhao Yakui <yakui.zhao@intel.com>
Mon, 28 Jan 2008 05:54:46 +0000 (13:54 +0800)
committerLen Brown <len.brown@intel.com>
Sat, 2 Feb 2008 07:30:21 +0000 (02:30 -0500)
The t-state coordination should be considered when T-state for one cpu
is changed.It means that OSPM should select one proper target T-state for
the all affected cpus before updating T-state.

So the function of acpi_processor_throttling_notifier is added.
Before updating T-state it can be called for all  the affected cpus to get
the proper target T-state, which can meet the requirement of thermal, user and
_TPC. After updating T-state, it can be called to update T-state flag.

Signed-off-by: Zhao Yakui <yakui.zhao@intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>
drivers/acpi/processor_throttling.c

index d6780f41d28c5f4cdb703a198b2e3d4b28528296..18a873a5525667ed4be1fa4e30de49aee3f8dc61 100644 (file)
 #define _COMPONENT              ACPI_PROCESSOR_COMPONENT
 ACPI_MODULE_NAME("processor_throttling");
 
+struct throttling_tstate {
+       unsigned int cpu;               /* cpu nr */
+       int target_state;               /* target T-state */
+};
+
+#define THROTTLING_PRECHANGE       (1)
+#define THROTTLING_POSTCHANGE      (2)
+
 static int acpi_processor_get_throttling(struct acpi_processor *pr);
 int acpi_processor_set_throttling(struct acpi_processor *pr, int state);
 
@@ -196,6 +204,70 @@ void acpi_processor_throttling_init(void)
        return;
 }
 
+static int acpi_processor_throttling_notifier(unsigned long event, void *data)
+{
+       struct throttling_tstate *p_tstate = data;
+       struct acpi_processor *pr;
+       unsigned int cpu ;
+       int target_state;
+       struct acpi_processor_limit *p_limit;
+       struct acpi_processor_throttling *p_throttling;
+
+       cpu = p_tstate->cpu;
+       pr = processors[cpu];
+       if (!pr) {
+               ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Invalid pr pointer\n"));
+               return 0;
+       }
+       if (!pr->flags.throttling) {
+               ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Throttling control is "
+                               "unsupported on CPU %d\n", cpu));
+               return 0;
+       }
+       target_state = p_tstate->target_state;
+       p_throttling = &(pr->throttling);
+       switch (event) {
+       case THROTTLING_PRECHANGE:
+               /*
+                * Prechange event is used to choose one proper t-state,
+                * which meets the limits of thermal, user and _TPC.
+                */
+               p_limit = &pr->limit;
+               if (p_limit->thermal.tx > target_state)
+                       target_state = p_limit->thermal.tx;
+               if (p_limit->user.tx > target_state)
+                       target_state = p_limit->user.tx;
+               if (pr->throttling_platform_limit > target_state)
+                       target_state = pr->throttling_platform_limit;
+               if (target_state >= p_throttling->state_count) {
+                       printk(KERN_WARNING
+                               "Exceed the limit of T-state \n");
+                       target_state = p_throttling->state_count - 1;
+               }
+               p_tstate->target_state = target_state;
+               ACPI_DEBUG_PRINT((ACPI_DB_INFO, "PreChange Event:"
+                               "target T-state of CPU %d is T%d\n",
+                               cpu, target_state));
+               break;
+       case THROTTLING_POSTCHANGE:
+               /*
+                * Postchange event is only used to update the
+                * T-state flag of acpi_processor_throttling.
+                */
+               p_throttling->state = target_state;
+               ACPI_DEBUG_PRINT((ACPI_DB_INFO, "PostChange Event:"
+                               "CPU %d is switched to T%d\n",
+                               cpu, target_state));
+               break;
+       default:
+               printk(KERN_WARNING
+                       "Unsupported Throttling notifier event\n");
+               break;
+       }
+
+       return 0;
+}
+
 /*
  * _TPC - Throttling Present Capabilities
  */