processor_idle.c (4202735e8ab6ecfb0381631a0d0b58fefe0bd4e2) processor_idle.c (46bcfad7a819bd17ac4e831b04405152d59784ab)
1/*
2 * processor_idle - idle state submodule to the ACPI processor driver
3 *
4 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
5 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
6 * Copyright (C) 2004, 2005 Dominik Brodowski <linux@brodo.de>
7 * Copyright (C) 2004 Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
8 * - Added processor hotplug support

--- 727 unchanged lines hidden (view full) ---

736 inl(acpi_gbl_FADT.xpm_timer_block.address);
737 }
738 start_critical_timings();
739}
740
741/**
742 * acpi_idle_enter_c1 - enters an ACPI C1 state-type
743 * @dev: the target CPU
1/*
2 * processor_idle - idle state submodule to the ACPI processor driver
3 *
4 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
5 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
6 * Copyright (C) 2004, 2005 Dominik Brodowski <linux@brodo.de>
7 * Copyright (C) 2004 Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
8 * - Added processor hotplug support

--- 727 unchanged lines hidden (view full) ---

736 inl(acpi_gbl_FADT.xpm_timer_block.address);
737 }
738 start_critical_timings();
739}
740
741/**
742 * acpi_idle_enter_c1 - enters an ACPI C1 state-type
743 * @dev: the target CPU
744 * @drv: cpuidle driver containing cpuidle state info
744 * @index: index of target state
745 *
746 * This is equivalent to the HALT instruction.
747 */
745 * @index: index of target state
746 *
747 * This is equivalent to the HALT instruction.
748 */
748static int acpi_idle_enter_c1(struct cpuidle_device *dev, int index)
749static int acpi_idle_enter_c1(struct cpuidle_device *dev,
750 struct cpuidle_driver *drv, int index)
749{
750 ktime_t kt1, kt2;
751 s64 idle_time;
752 struct acpi_processor *pr;
753 struct cpuidle_state_usage *state_usage = &dev->states_usage[index];
754 struct acpi_processor_cx *cx = cpuidle_get_statedata(state_usage);
755
756 pr = __this_cpu_read(processors);

--- 25 unchanged lines hidden (view full) ---

782 lapic_timer_state_broadcast(pr, cx, 0);
783
784 return index;
785}
786
787/**
788 * acpi_idle_enter_simple - enters an ACPI state without BM handling
789 * @dev: the target CPU
751{
752 ktime_t kt1, kt2;
753 s64 idle_time;
754 struct acpi_processor *pr;
755 struct cpuidle_state_usage *state_usage = &dev->states_usage[index];
756 struct acpi_processor_cx *cx = cpuidle_get_statedata(state_usage);
757
758 pr = __this_cpu_read(processors);

--- 25 unchanged lines hidden (view full) ---

784 lapic_timer_state_broadcast(pr, cx, 0);
785
786 return index;
787}
788
789/**
790 * acpi_idle_enter_simple - enters an ACPI state without BM handling
791 * @dev: the target CPU
792 * @drv: cpuidle driver with cpuidle state information
790 * @index: the index of suggested state
791 */
793 * @index: the index of suggested state
794 */
792static int acpi_idle_enter_simple(struct cpuidle_device *dev, int index)
795static int acpi_idle_enter_simple(struct cpuidle_device *dev,
796 struct cpuidle_driver *drv, int index)
793{
794 struct acpi_processor *pr;
795 struct cpuidle_state_usage *state_usage = &dev->states_usage[index];
796 struct acpi_processor_cx *cx = cpuidle_get_statedata(state_usage);
797 ktime_t kt1, kt2;
798 s64 idle_time_ns;
799 s64 idle_time;
800

--- 63 unchanged lines hidden (view full) ---

864}
865
866static int c3_cpu_count;
867static DEFINE_SPINLOCK(c3_lock);
868
869/**
870 * acpi_idle_enter_bm - enters C3 with proper BM handling
871 * @dev: the target CPU
797{
798 struct acpi_processor *pr;
799 struct cpuidle_state_usage *state_usage = &dev->states_usage[index];
800 struct acpi_processor_cx *cx = cpuidle_get_statedata(state_usage);
801 ktime_t kt1, kt2;
802 s64 idle_time_ns;
803 s64 idle_time;
804

--- 63 unchanged lines hidden (view full) ---

868}
869
870static int c3_cpu_count;
871static DEFINE_SPINLOCK(c3_lock);
872
873/**
874 * acpi_idle_enter_bm - enters C3 with proper BM handling
875 * @dev: the target CPU
876 * @drv: cpuidle driver containing state data
872 * @index: the index of suggested state
873 *
874 * If BM is detected, the deepest non-C3 idle state is entered instead.
875 */
877 * @index: the index of suggested state
878 *
879 * If BM is detected, the deepest non-C3 idle state is entered instead.
880 */
876static int acpi_idle_enter_bm(struct cpuidle_device *dev, int index)
881static int acpi_idle_enter_bm(struct cpuidle_device *dev,
882 struct cpuidle_driver *drv, int index)
877{
878 struct acpi_processor *pr;
879 struct cpuidle_state_usage *state_usage = &dev->states_usage[index];
880 struct acpi_processor_cx *cx = cpuidle_get_statedata(state_usage);
881 ktime_t kt1, kt2;
882 s64 idle_time_ns;
883 s64 idle_time;
884

--- 6 unchanged lines hidden (view full) ---

891
892
893 if (acpi_idle_suspend) {
894 cpu_relax();
895 return -EINVAL;
896 }
897
898 if (!cx->bm_sts_skip && acpi_idle_bm_check()) {
883{
884 struct acpi_processor *pr;
885 struct cpuidle_state_usage *state_usage = &dev->states_usage[index];
886 struct acpi_processor_cx *cx = cpuidle_get_statedata(state_usage);
887 ktime_t kt1, kt2;
888 s64 idle_time_ns;
889 s64 idle_time;
890

--- 6 unchanged lines hidden (view full) ---

897
898
899 if (acpi_idle_suspend) {
900 cpu_relax();
901 return -EINVAL;
902 }
903
904 if (!cx->bm_sts_skip && acpi_idle_bm_check()) {
899 if (dev->safe_state_index >= 0) {
900 return dev->states[dev->safe_state_index].enter(dev,
901 dev->safe_state_index);
905 if (drv->safe_state_index >= 0) {
906 return drv->states[drv->safe_state_index].enter(dev,
907 drv, drv->safe_state_index);
902 } else {
903 local_irq_disable();
904 acpi_safe_halt();
905 local_irq_enable();
906 return -EINVAL;
907 }
908 }
909

--- 78 unchanged lines hidden (view full) ---

988}
989
990struct cpuidle_driver acpi_idle_driver = {
991 .name = "acpi_idle",
992 .owner = THIS_MODULE,
993};
994
995/**
908 } else {
909 local_irq_disable();
910 acpi_safe_halt();
911 local_irq_enable();
912 return -EINVAL;
913 }
914 }
915

--- 78 unchanged lines hidden (view full) ---

994}
995
996struct cpuidle_driver acpi_idle_driver = {
997 .name = "acpi_idle",
998 .owner = THIS_MODULE,
999};
1000
1001/**
996 * acpi_processor_setup_cpuidle - prepares and configures CPUIDLE
1002 * acpi_processor_setup_cpuidle_cx - prepares and configures CPUIDLE
1003 * device i.e. per-cpu data
1004 *
997 * @pr: the ACPI processor
998 */
1005 * @pr: the ACPI processor
1006 */
999static int acpi_processor_setup_cpuidle(struct acpi_processor *pr)
1007static int acpi_processor_setup_cpuidle_cx(struct acpi_processor *pr)
1000{
1001 int i, count = CPUIDLE_DRIVER_STATE_START;
1002 struct acpi_processor_cx *cx;
1008{
1009 int i, count = CPUIDLE_DRIVER_STATE_START;
1010 struct acpi_processor_cx *cx;
1003 struct cpuidle_state *state;
1004 struct cpuidle_state_usage *state_usage;
1005 struct cpuidle_device *dev = &pr->power.dev;
1006
1007 if (!pr->flags.power_setup_done)
1008 return -EINVAL;
1009
1010 if (pr->flags.power == 0) {
1011 return -EINVAL;
1012 }
1013
1014 dev->cpu = pr->id;
1011 struct cpuidle_state_usage *state_usage;
1012 struct cpuidle_device *dev = &pr->power.dev;
1013
1014 if (!pr->flags.power_setup_done)
1015 return -EINVAL;
1016
1017 if (pr->flags.power == 0) {
1018 return -EINVAL;
1019 }
1020
1021 dev->cpu = pr->id;
1015 dev->safe_state_index = -1;
1016 for (i = 0; i < CPUIDLE_STATE_MAX; i++) {
1017 dev->states[i].name[0] = '\0';
1018 dev->states[i].desc[0] = '\0';
1019 }
1020
1021 if (max_cstate == 0)
1022 max_cstate = 1;
1023
1024 for (i = 1; i < ACPI_PROCESSOR_MAX_POWER && i <= max_cstate; i++) {
1025 cx = &pr->power.states[i];
1022
1023 if (max_cstate == 0)
1024 max_cstate = 1;
1025
1026 for (i = 1; i < ACPI_PROCESSOR_MAX_POWER && i <= max_cstate; i++) {
1027 cx = &pr->power.states[i];
1026 state = &dev->states[count];
1027 state_usage = &dev->states_usage[count];
1028
1029 if (!cx->valid)
1030 continue;
1031
1032#ifdef CONFIG_HOTPLUG_CPU
1033 if ((cx->type != ACPI_STATE_C1) && (num_online_cpus() > 1) &&
1034 !pr->flags.has_cst &&
1035 !(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED))
1036 continue;
1037#endif
1028 state_usage = &dev->states_usage[count];
1029
1030 if (!cx->valid)
1031 continue;
1032
1033#ifdef CONFIG_HOTPLUG_CPU
1034 if ((cx->type != ACPI_STATE_C1) && (num_online_cpus() > 1) &&
1035 !pr->flags.has_cst &&
1036 !(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED))
1037 continue;
1038#endif
1039
1038 cpuidle_set_statedata(state_usage, cx);
1039
1040 cpuidle_set_statedata(state_usage, cx);
1041
1042 count++;
1043 if (count == CPUIDLE_STATE_MAX)
1044 break;
1045 }
1046
1047 dev->state_count = count;
1048
1049 if (!count)
1050 return -EINVAL;
1051
1052 return 0;
1053}
1054
1055/**
1056 * acpi_processor_setup_cpuidle states- prepares and configures cpuidle
1057 * global state data i.e. idle routines
1058 *
1059 * @pr: the ACPI processor
1060 */
1061static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
1062{
1063 int i, count = CPUIDLE_DRIVER_STATE_START;
1064 struct acpi_processor_cx *cx;
1065 struct cpuidle_state *state;
1066 struct cpuidle_driver *drv = &acpi_idle_driver;
1067
1068 if (!pr->flags.power_setup_done)
1069 return -EINVAL;
1070
1071 if (pr->flags.power == 0)
1072 return -EINVAL;
1073
1074 drv->safe_state_index = -1;
1075 for (i = 0; i < CPUIDLE_STATE_MAX; i++) {
1076 drv->states[i].name[0] = '\0';
1077 drv->states[i].desc[0] = '\0';
1078 }
1079
1080 if (max_cstate == 0)
1081 max_cstate = 1;
1082
1083 for (i = 1; i < ACPI_PROCESSOR_MAX_POWER && i <= max_cstate; i++) {
1084 cx = &pr->power.states[i];
1085
1086 if (!cx->valid)
1087 continue;
1088
1089#ifdef CONFIG_HOTPLUG_CPU
1090 if ((cx->type != ACPI_STATE_C1) && (num_online_cpus() > 1) &&
1091 !pr->flags.has_cst &&
1092 !(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED))
1093 continue;
1094#endif
1095
1096 state = &drv->states[count];
1040 snprintf(state->name, CPUIDLE_NAME_LEN, "C%d", i);
1041 strncpy(state->desc, cx->desc, CPUIDLE_DESC_LEN);
1042 state->exit_latency = cx->latency;
1043 state->target_residency = cx->latency * latency_factor;
1044
1045 state->flags = 0;
1046 switch (cx->type) {
1047 case ACPI_STATE_C1:
1048 if (cx->entry_method == ACPI_CSTATE_FFH)
1049 state->flags |= CPUIDLE_FLAG_TIME_VALID;
1050
1051 state->enter = acpi_idle_enter_c1;
1097 snprintf(state->name, CPUIDLE_NAME_LEN, "C%d", i);
1098 strncpy(state->desc, cx->desc, CPUIDLE_DESC_LEN);
1099 state->exit_latency = cx->latency;
1100 state->target_residency = cx->latency * latency_factor;
1101
1102 state->flags = 0;
1103 switch (cx->type) {
1104 case ACPI_STATE_C1:
1105 if (cx->entry_method == ACPI_CSTATE_FFH)
1106 state->flags |= CPUIDLE_FLAG_TIME_VALID;
1107
1108 state->enter = acpi_idle_enter_c1;
1052 dev->safe_state_index = count;
1109 drv->safe_state_index = count;
1053 break;
1054
1055 case ACPI_STATE_C2:
1056 state->flags |= CPUIDLE_FLAG_TIME_VALID;
1057 state->enter = acpi_idle_enter_simple;
1110 break;
1111
1112 case ACPI_STATE_C2:
1113 state->flags |= CPUIDLE_FLAG_TIME_VALID;
1114 state->enter = acpi_idle_enter_simple;
1058 dev->safe_state_index = count;
1115 drv->safe_state_index = count;
1059 break;
1060
1061 case ACPI_STATE_C3:
1062 state->flags |= CPUIDLE_FLAG_TIME_VALID;
1063 state->enter = pr->flags.bm_check ?
1064 acpi_idle_enter_bm :
1065 acpi_idle_enter_simple;
1066 break;
1067 }
1068
1069 count++;
1070 if (count == CPUIDLE_STATE_MAX)
1071 break;
1072 }
1073
1116 break;
1117
1118 case ACPI_STATE_C3:
1119 state->flags |= CPUIDLE_FLAG_TIME_VALID;
1120 state->enter = pr->flags.bm_check ?
1121 acpi_idle_enter_bm :
1122 acpi_idle_enter_simple;
1123 break;
1124 }
1125
1126 count++;
1127 if (count == CPUIDLE_STATE_MAX)
1128 break;
1129 }
1130
1074 dev->state_count = count;
1131 drv->state_count = count;
1075
1076 if (!count)
1077 return -EINVAL;
1078
1079 return 0;
1080}
1081
1132
1133 if (!count)
1134 return -EINVAL;
1135
1136 return 0;
1137}
1138
1082int acpi_processor_cst_has_changed(struct acpi_processor *pr)
1139int acpi_processor_hotplug(struct acpi_processor *pr)
1083{
1084 int ret = 0;
1085
1086 if (disabled_by_idle_boot_param())
1087 return 0;
1088
1089 if (!pr)
1090 return -EINVAL;

--- 4 unchanged lines hidden (view full) ---

1095
1096 if (!pr->flags.power_setup_done)
1097 return -ENODEV;
1098
1099 cpuidle_pause_and_lock();
1100 cpuidle_disable_device(&pr->power.dev);
1101 acpi_processor_get_power_info(pr);
1102 if (pr->flags.power) {
1140{
1141 int ret = 0;
1142
1143 if (disabled_by_idle_boot_param())
1144 return 0;
1145
1146 if (!pr)
1147 return -EINVAL;

--- 4 unchanged lines hidden (view full) ---

1152
1153 if (!pr->flags.power_setup_done)
1154 return -ENODEV;
1155
1156 cpuidle_pause_and_lock();
1157 cpuidle_disable_device(&pr->power.dev);
1158 acpi_processor_get_power_info(pr);
1159 if (pr->flags.power) {
1103 acpi_processor_setup_cpuidle(pr);
1160 acpi_processor_setup_cpuidle_cx(pr);
1104 ret = cpuidle_enable_device(&pr->power.dev);
1105 }
1106 cpuidle_resume_and_unlock();
1107
1108 return ret;
1109}
1110
1161 ret = cpuidle_enable_device(&pr->power.dev);
1162 }
1163 cpuidle_resume_and_unlock();
1164
1165 return ret;
1166}
1167
1168int acpi_processor_cst_has_changed(struct acpi_processor *pr)
1169{
1170 int cpu;
1171 struct acpi_processor *_pr;
1172
1173 if (disabled_by_idle_boot_param())
1174 return 0;
1175
1176 if (!pr)
1177 return -EINVAL;
1178
1179 if (nocst)
1180 return -ENODEV;
1181
1182 if (!pr->flags.power_setup_done)
1183 return -ENODEV;
1184
1185 /*
1186 * FIXME: Design the ACPI notification to make it once per
1187 * system instead of once per-cpu. This condition is a hack
1188 * to make the code that updates C-States be called once.
1189 */
1190
1191 if (smp_processor_id() == 0 &&
1192 cpuidle_get_driver() == &acpi_idle_driver) {
1193
1194 cpuidle_pause_and_lock();
1195 /* Protect against cpu-hotplug */
1196 get_online_cpus();
1197
1198 /* Disable all cpuidle devices */
1199 for_each_online_cpu(cpu) {
1200 _pr = per_cpu(processors, cpu);
1201 if (!_pr || !_pr->flags.power_setup_done)
1202 continue;
1203 cpuidle_disable_device(&_pr->power.dev);
1204 }
1205
1206 /* Populate Updated C-state information */
1207 acpi_processor_setup_cpuidle_states(pr);
1208
1209 /* Enable all cpuidle devices */
1210 for_each_online_cpu(cpu) {
1211 _pr = per_cpu(processors, cpu);
1212 if (!_pr || !_pr->flags.power_setup_done)
1213 continue;
1214 acpi_processor_get_power_info(_pr);
1215 if (_pr->flags.power) {
1216 acpi_processor_setup_cpuidle_cx(_pr);
1217 cpuidle_enable_device(&_pr->power.dev);
1218 }
1219 }
1220 put_online_cpus();
1221 cpuidle_resume_and_unlock();
1222 }
1223
1224 return 0;
1225}
1226
1227static int acpi_processor_registered;
1228
1111int __cpuinit acpi_processor_power_init(struct acpi_processor *pr,
1112 struct acpi_device *device)
1113{
1114 acpi_status status = 0;
1229int __cpuinit acpi_processor_power_init(struct acpi_processor *pr,
1230 struct acpi_device *device)
1231{
1232 acpi_status status = 0;
1233 int retval;
1115 static int first_run;
1116
1117 if (disabled_by_idle_boot_param())
1118 return 0;
1119
1120 if (!first_run) {
1121 dmi_check_system(processor_power_dmi_table);
1122 max_cstate = acpi_processor_cstate_check(max_cstate);

--- 20 unchanged lines hidden (view full) ---

1143 pr->flags.power_setup_done = 1;
1144
1145 /*
1146 * Install the idle handler if processor power management is supported.
1147 * Note that we use previously set idle handler will be used on
1148 * platforms that only support C1.
1149 */
1150 if (pr->flags.power) {
1234 static int first_run;
1235
1236 if (disabled_by_idle_boot_param())
1237 return 0;
1238
1239 if (!first_run) {
1240 dmi_check_system(processor_power_dmi_table);
1241 max_cstate = acpi_processor_cstate_check(max_cstate);

--- 20 unchanged lines hidden (view full) ---

1262 pr->flags.power_setup_done = 1;
1263
1264 /*
1265 * Install the idle handler if processor power management is supported.
1266 * Note that we use previously set idle handler will be used on
1267 * platforms that only support C1.
1268 */
1269 if (pr->flags.power) {
1151 acpi_processor_setup_cpuidle(pr);
1152 if (cpuidle_register_device(&pr->power.dev))
1153 return -EIO;
1270 /* Register acpi_idle_driver if not already registered */
1271 if (!acpi_processor_registered) {
1272 acpi_processor_setup_cpuidle_states(pr);
1273 retval = cpuidle_register_driver(&acpi_idle_driver);
1274 if (retval)
1275 return retval;
1276 printk(KERN_DEBUG "ACPI: %s registered with cpuidle\n",
1277 acpi_idle_driver.name);
1278 }
1279 /* Register per-cpu cpuidle_device. Cpuidle driver
1280 * must already be registered before registering device
1281 */
1282 acpi_processor_setup_cpuidle_cx(pr);
1283 retval = cpuidle_register_device(&pr->power.dev);
1284 if (retval) {
1285 if (acpi_processor_registered == 0)
1286 cpuidle_unregister_driver(&acpi_idle_driver);
1287 return retval;
1288 }
1289 acpi_processor_registered++;
1154 }
1155 return 0;
1156}
1157
1158int acpi_processor_power_exit(struct acpi_processor *pr,
1159 struct acpi_device *device)
1160{
1161 if (disabled_by_idle_boot_param())
1162 return 0;
1163
1290 }
1291 return 0;
1292}
1293
1294int acpi_processor_power_exit(struct acpi_processor *pr,
1295 struct acpi_device *device)
1296{
1297 if (disabled_by_idle_boot_param())
1298 return 0;
1299
1164 cpuidle_unregister_device(&pr->power.dev);
1165 pr->flags.power_setup_done = 0;
1300 if (pr->flags.power) {
1301 cpuidle_unregister_device(&pr->power.dev);
1302 acpi_processor_registered--;
1303 if (acpi_processor_registered == 0)
1304 cpuidle_unregister_driver(&acpi_idle_driver);
1305 }
1166
1306
1307 pr->flags.power_setup_done = 0;
1167 return 0;
1168}
1308 return 0;
1309}