diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2011-11-07 13:13:52 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-11-07 13:13:52 -0500 |
commit | 3c00303206c3a1ccd86579efdc90bc35f140962e (patch) | |
tree | 66170c84b5ddaeb102aea3530517a26657b6ea29 /drivers/acpi/processor_idle.c | |
parent | 83dbb15e9cd78a3619e3db36777e2f81d09b2914 (diff) | |
parent | efb90582c575084723cc14302c1300cb26c7e01f (diff) |
Merge branch 'release' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux
* 'release' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux:
cpuidle: Single/Global registration of idle states
cpuidle: Split cpuidle_state structure and move per-cpu statistics fields
cpuidle: Remove CPUIDLE_FLAG_IGNORE and dev->prepare()
cpuidle: Move dev->last_residency update to driver enter routine; remove dev->last_state
ACPI: Fix CONFIG_ACPI_DOCK=n compiler warning
ACPI: Export FADT pm_profile integer value to userspace
thermal: Prevent polling from happening during system suspend
ACPI: Drop ACPI_NO_HARDWARE_INIT
ACPI atomicio: Convert width in bits to bytes in __acpi_ioremap_fast()
PNPACPI: Simplify disabled resource registration
ACPI: Fix possible recursive locking in hwregs.c
ACPI: use kstrdup()
mrst pmu: update comment
tools/power turbostat: less verbose debugging
Diffstat (limited to 'drivers/acpi/processor_idle.c')
-rw-r--r-- | drivers/acpi/processor_idle.c | 251 |
1 files changed, 207 insertions, 44 deletions
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c index 9b88f9828d8c..73b2909dddfe 100644 --- a/drivers/acpi/processor_idle.c +++ b/drivers/acpi/processor_idle.c | |||
@@ -741,22 +741,25 @@ static inline void acpi_idle_do_entry(struct acpi_processor_cx *cx) | |||
741 | /** | 741 | /** |
742 | * acpi_idle_enter_c1 - enters an ACPI C1 state-type | 742 | * acpi_idle_enter_c1 - enters an ACPI C1 state-type |
743 | * @dev: the target CPU | 743 | * @dev: the target CPU |
744 | * @state: the state data | 744 | * @drv: cpuidle driver containing cpuidle state info |
745 | * @index: index of target state | ||
745 | * | 746 | * |
746 | * This is equivalent to the HALT instruction. | 747 | * This is equivalent to the HALT instruction. |
747 | */ | 748 | */ |
748 | static int acpi_idle_enter_c1(struct cpuidle_device *dev, | 749 | static int acpi_idle_enter_c1(struct cpuidle_device *dev, |
749 | struct cpuidle_state *state) | 750 | struct cpuidle_driver *drv, int index) |
750 | { | 751 | { |
751 | ktime_t kt1, kt2; | 752 | ktime_t kt1, kt2; |
752 | s64 idle_time; | 753 | s64 idle_time; |
753 | struct acpi_processor *pr; | 754 | struct acpi_processor *pr; |
754 | struct acpi_processor_cx *cx = cpuidle_get_statedata(state); | 755 | struct cpuidle_state_usage *state_usage = &dev->states_usage[index]; |
756 | struct acpi_processor_cx *cx = cpuidle_get_statedata(state_usage); | ||
755 | 757 | ||
756 | pr = __this_cpu_read(processors); | 758 | pr = __this_cpu_read(processors); |
759 | dev->last_residency = 0; | ||
757 | 760 | ||
758 | if (unlikely(!pr)) | 761 | if (unlikely(!pr)) |
759 | return 0; | 762 | return -EINVAL; |
760 | 763 | ||
761 | local_irq_disable(); | 764 | local_irq_disable(); |
762 | 765 | ||
@@ -764,7 +767,7 @@ static int acpi_idle_enter_c1(struct cpuidle_device *dev, | |||
764 | if (acpi_idle_suspend) { | 767 | if (acpi_idle_suspend) { |
765 | local_irq_enable(); | 768 | local_irq_enable(); |
766 | cpu_relax(); | 769 | cpu_relax(); |
767 | return 0; | 770 | return -EINVAL; |
768 | } | 771 | } |
769 | 772 | ||
770 | lapic_timer_state_broadcast(pr, cx, 1); | 773 | lapic_timer_state_broadcast(pr, cx, 1); |
@@ -773,37 +776,47 @@ static int acpi_idle_enter_c1(struct cpuidle_device *dev, | |||
773 | kt2 = ktime_get_real(); | 776 | kt2 = ktime_get_real(); |
774 | idle_time = ktime_to_us(ktime_sub(kt2, kt1)); | 777 | idle_time = ktime_to_us(ktime_sub(kt2, kt1)); |
775 | 778 | ||
779 | /* Update device last_residency*/ | ||
780 | dev->last_residency = (int)idle_time; | ||
781 | |||
776 | local_irq_enable(); | 782 | local_irq_enable(); |
777 | cx->usage++; | 783 | cx->usage++; |
778 | lapic_timer_state_broadcast(pr, cx, 0); | 784 | lapic_timer_state_broadcast(pr, cx, 0); |
779 | 785 | ||
780 | return idle_time; | 786 | return index; |
781 | } | 787 | } |
782 | 788 | ||
783 | /** | 789 | /** |
784 | * acpi_idle_enter_simple - enters an ACPI state without BM handling | 790 | * acpi_idle_enter_simple - enters an ACPI state without BM handling |
785 | * @dev: the target CPU | 791 | * @dev: the target CPU |
786 | * @state: the state data | 792 | * @drv: cpuidle driver with cpuidle state information |
793 | * @index: the index of suggested state | ||
787 | */ | 794 | */ |
788 | static int acpi_idle_enter_simple(struct cpuidle_device *dev, | 795 | static int acpi_idle_enter_simple(struct cpuidle_device *dev, |
789 | struct cpuidle_state *state) | 796 | struct cpuidle_driver *drv, int index) |
790 | { | 797 | { |
791 | struct acpi_processor *pr; | 798 | struct acpi_processor *pr; |
792 | struct acpi_processor_cx *cx = cpuidle_get_statedata(state); | 799 | struct cpuidle_state_usage *state_usage = &dev->states_usage[index]; |
800 | struct acpi_processor_cx *cx = cpuidle_get_statedata(state_usage); | ||
793 | ktime_t kt1, kt2; | 801 | ktime_t kt1, kt2; |
794 | s64 idle_time_ns; | 802 | s64 idle_time_ns; |
795 | s64 idle_time; | 803 | s64 idle_time; |
796 | 804 | ||
797 | pr = __this_cpu_read(processors); | 805 | pr = __this_cpu_read(processors); |
806 | dev->last_residency = 0; | ||
798 | 807 | ||
799 | if (unlikely(!pr)) | 808 | if (unlikely(!pr)) |
800 | return 0; | 809 | return -EINVAL; |
801 | |||
802 | if (acpi_idle_suspend) | ||
803 | return(acpi_idle_enter_c1(dev, state)); | ||
804 | 810 | ||
805 | local_irq_disable(); | 811 | local_irq_disable(); |
806 | 812 | ||
813 | if (acpi_idle_suspend) { | ||
814 | local_irq_enable(); | ||
815 | cpu_relax(); | ||
816 | return -EINVAL; | ||
817 | } | ||
818 | |||
819 | |||
807 | if (cx->entry_method != ACPI_CSTATE_FFH) { | 820 | if (cx->entry_method != ACPI_CSTATE_FFH) { |
808 | current_thread_info()->status &= ~TS_POLLING; | 821 | current_thread_info()->status &= ~TS_POLLING; |
809 | /* | 822 | /* |
@@ -815,7 +828,7 @@ static int acpi_idle_enter_simple(struct cpuidle_device *dev, | |||
815 | if (unlikely(need_resched())) { | 828 | if (unlikely(need_resched())) { |
816 | current_thread_info()->status |= TS_POLLING; | 829 | current_thread_info()->status |= TS_POLLING; |
817 | local_irq_enable(); | 830 | local_irq_enable(); |
818 | return 0; | 831 | return -EINVAL; |
819 | } | 832 | } |
820 | } | 833 | } |
821 | 834 | ||
@@ -837,6 +850,9 @@ static int acpi_idle_enter_simple(struct cpuidle_device *dev, | |||
837 | idle_time = idle_time_ns; | 850 | idle_time = idle_time_ns; |
838 | do_div(idle_time, NSEC_PER_USEC); | 851 | do_div(idle_time, NSEC_PER_USEC); |
839 | 852 | ||
853 | /* Update device last_residency*/ | ||
854 | dev->last_residency = (int)idle_time; | ||
855 | |||
840 | /* Tell the scheduler how much we idled: */ | 856 | /* Tell the scheduler how much we idled: */ |
841 | sched_clock_idle_wakeup_event(idle_time_ns); | 857 | sched_clock_idle_wakeup_event(idle_time_ns); |
842 | 858 | ||
@@ -848,7 +864,7 @@ static int acpi_idle_enter_simple(struct cpuidle_device *dev, | |||
848 | 864 | ||
849 | lapic_timer_state_broadcast(pr, cx, 0); | 865 | lapic_timer_state_broadcast(pr, cx, 0); |
850 | cx->time += idle_time; | 866 | cx->time += idle_time; |
851 | return idle_time; | 867 | return index; |
852 | } | 868 | } |
853 | 869 | ||
854 | static int c3_cpu_count; | 870 | static int c3_cpu_count; |
@@ -857,37 +873,43 @@ static DEFINE_RAW_SPINLOCK(c3_lock); | |||
857 | /** | 873 | /** |
858 | * acpi_idle_enter_bm - enters C3 with proper BM handling | 874 | * acpi_idle_enter_bm - enters C3 with proper BM handling |
859 | * @dev: the target CPU | 875 | * @dev: the target CPU |
860 | * @state: the state data | 876 | * @drv: cpuidle driver containing state data |
877 | * @index: the index of suggested state | ||
861 | * | 878 | * |
862 | * If BM is detected, the deepest non-C3 idle state is entered instead. | 879 | * If BM is detected, the deepest non-C3 idle state is entered instead. |
863 | */ | 880 | */ |
864 | static int acpi_idle_enter_bm(struct cpuidle_device *dev, | 881 | static int acpi_idle_enter_bm(struct cpuidle_device *dev, |
865 | struct cpuidle_state *state) | 882 | struct cpuidle_driver *drv, int index) |
866 | { | 883 | { |
867 | struct acpi_processor *pr; | 884 | struct acpi_processor *pr; |
868 | struct acpi_processor_cx *cx = cpuidle_get_statedata(state); | 885 | struct cpuidle_state_usage *state_usage = &dev->states_usage[index]; |
886 | struct acpi_processor_cx *cx = cpuidle_get_statedata(state_usage); | ||
869 | ktime_t kt1, kt2; | 887 | ktime_t kt1, kt2; |
870 | s64 idle_time_ns; | 888 | s64 idle_time_ns; |
871 | s64 idle_time; | 889 | s64 idle_time; |
872 | 890 | ||
873 | 891 | ||
874 | pr = __this_cpu_read(processors); | 892 | pr = __this_cpu_read(processors); |
893 | dev->last_residency = 0; | ||
875 | 894 | ||
876 | if (unlikely(!pr)) | 895 | if (unlikely(!pr)) |
877 | return 0; | 896 | return -EINVAL; |
897 | |||
878 | 898 | ||
879 | if (acpi_idle_suspend) | 899 | if (acpi_idle_suspend) { |
880 | return(acpi_idle_enter_c1(dev, state)); | 900 | cpu_relax(); |
901 | return -EINVAL; | ||
902 | } | ||
881 | 903 | ||
882 | if (!cx->bm_sts_skip && acpi_idle_bm_check()) { | 904 | if (!cx->bm_sts_skip && acpi_idle_bm_check()) { |
883 | if (dev->safe_state) { | 905 | if (drv->safe_state_index >= 0) { |
884 | dev->last_state = dev->safe_state; | 906 | return drv->states[drv->safe_state_index].enter(dev, |
885 | return dev->safe_state->enter(dev, dev->safe_state); | 907 | drv, drv->safe_state_index); |
886 | } else { | 908 | } else { |
887 | local_irq_disable(); | 909 | local_irq_disable(); |
888 | acpi_safe_halt(); | 910 | acpi_safe_halt(); |
889 | local_irq_enable(); | 911 | local_irq_enable(); |
890 | return 0; | 912 | return -EINVAL; |
891 | } | 913 | } |
892 | } | 914 | } |
893 | 915 | ||
@@ -904,7 +926,7 @@ static int acpi_idle_enter_bm(struct cpuidle_device *dev, | |||
904 | if (unlikely(need_resched())) { | 926 | if (unlikely(need_resched())) { |
905 | current_thread_info()->status |= TS_POLLING; | 927 | current_thread_info()->status |= TS_POLLING; |
906 | local_irq_enable(); | 928 | local_irq_enable(); |
907 | return 0; | 929 | return -EINVAL; |
908 | } | 930 | } |
909 | } | 931 | } |
910 | 932 | ||
@@ -954,6 +976,9 @@ static int acpi_idle_enter_bm(struct cpuidle_device *dev, | |||
954 | idle_time = idle_time_ns; | 976 | idle_time = idle_time_ns; |
955 | do_div(idle_time, NSEC_PER_USEC); | 977 | do_div(idle_time, NSEC_PER_USEC); |
956 | 978 | ||
979 | /* Update device last_residency*/ | ||
980 | dev->last_residency = (int)idle_time; | ||
981 | |||
957 | /* Tell the scheduler how much we idled: */ | 982 | /* Tell the scheduler how much we idled: */ |
958 | sched_clock_idle_wakeup_event(idle_time_ns); | 983 | sched_clock_idle_wakeup_event(idle_time_ns); |
959 | 984 | ||
@@ -965,7 +990,7 @@ static int acpi_idle_enter_bm(struct cpuidle_device *dev, | |||
965 | 990 | ||
966 | lapic_timer_state_broadcast(pr, cx, 0); | 991 | lapic_timer_state_broadcast(pr, cx, 0); |
967 | cx->time += idle_time; | 992 | cx->time += idle_time; |
968 | return idle_time; | 993 | return index; |
969 | } | 994 | } |
970 | 995 | ||
971 | struct cpuidle_driver acpi_idle_driver = { | 996 | struct cpuidle_driver acpi_idle_driver = { |
@@ -974,14 +999,16 @@ struct cpuidle_driver acpi_idle_driver = { | |||
974 | }; | 999 | }; |
975 | 1000 | ||
976 | /** | 1001 | /** |
977 | * 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 | * | ||
978 | * @pr: the ACPI processor | 1005 | * @pr: the ACPI processor |
979 | */ | 1006 | */ |
980 | static int acpi_processor_setup_cpuidle(struct acpi_processor *pr) | 1007 | static int acpi_processor_setup_cpuidle_cx(struct acpi_processor *pr) |
981 | { | 1008 | { |
982 | int i, count = CPUIDLE_DRIVER_STATE_START; | 1009 | int i, count = CPUIDLE_DRIVER_STATE_START; |
983 | struct acpi_processor_cx *cx; | 1010 | struct acpi_processor_cx *cx; |
984 | struct cpuidle_state *state; | 1011 | struct cpuidle_state_usage *state_usage; |
985 | struct cpuidle_device *dev = &pr->power.dev; | 1012 | struct cpuidle_device *dev = &pr->power.dev; |
986 | 1013 | ||
987 | if (!pr->flags.power_setup_done) | 1014 | if (!pr->flags.power_setup_done) |
@@ -992,9 +1019,62 @@ static int acpi_processor_setup_cpuidle(struct acpi_processor *pr) | |||
992 | } | 1019 | } |
993 | 1020 | ||
994 | dev->cpu = pr->id; | 1021 | dev->cpu = pr->id; |
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]; | ||
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 | |||
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 | */ | ||
1061 | static 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; | ||
995 | for (i = 0; i < CPUIDLE_STATE_MAX; i++) { | 1075 | for (i = 0; i < CPUIDLE_STATE_MAX; i++) { |
996 | dev->states[i].name[0] = '\0'; | 1076 | drv->states[i].name[0] = '\0'; |
997 | dev->states[i].desc[0] = '\0'; | 1077 | drv->states[i].desc[0] = '\0'; |
998 | } | 1078 | } |
999 | 1079 | ||
1000 | if (max_cstate == 0) | 1080 | if (max_cstate == 0) |
@@ -1002,7 +1082,6 @@ static int acpi_processor_setup_cpuidle(struct acpi_processor *pr) | |||
1002 | 1082 | ||
1003 | for (i = 1; i < ACPI_PROCESSOR_MAX_POWER && i <= max_cstate; i++) { | 1083 | for (i = 1; i < ACPI_PROCESSOR_MAX_POWER && i <= max_cstate; i++) { |
1004 | cx = &pr->power.states[i]; | 1084 | cx = &pr->power.states[i]; |
1005 | state = &dev->states[count]; | ||
1006 | 1085 | ||
1007 | if (!cx->valid) | 1086 | if (!cx->valid) |
1008 | continue; | 1087 | continue; |
@@ -1013,8 +1092,8 @@ static int acpi_processor_setup_cpuidle(struct acpi_processor *pr) | |||
1013 | !(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED)) | 1092 | !(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED)) |
1014 | continue; | 1093 | continue; |
1015 | #endif | 1094 | #endif |
1016 | cpuidle_set_statedata(state, cx); | ||
1017 | 1095 | ||
1096 | state = &drv->states[count]; | ||
1018 | snprintf(state->name, CPUIDLE_NAME_LEN, "C%d", i); | 1097 | snprintf(state->name, CPUIDLE_NAME_LEN, "C%d", i); |
1019 | strncpy(state->desc, cx->desc, CPUIDLE_DESC_LEN); | 1098 | strncpy(state->desc, cx->desc, CPUIDLE_DESC_LEN); |
1020 | state->exit_latency = cx->latency; | 1099 | state->exit_latency = cx->latency; |
@@ -1027,13 +1106,13 @@ static int acpi_processor_setup_cpuidle(struct acpi_processor *pr) | |||
1027 | state->flags |= CPUIDLE_FLAG_TIME_VALID; | 1106 | state->flags |= CPUIDLE_FLAG_TIME_VALID; |
1028 | 1107 | ||
1029 | state->enter = acpi_idle_enter_c1; | 1108 | state->enter = acpi_idle_enter_c1; |
1030 | dev->safe_state = state; | 1109 | drv->safe_state_index = count; |
1031 | break; | 1110 | break; |
1032 | 1111 | ||
1033 | case ACPI_STATE_C2: | 1112 | case ACPI_STATE_C2: |
1034 | state->flags |= CPUIDLE_FLAG_TIME_VALID; | 1113 | state->flags |= CPUIDLE_FLAG_TIME_VALID; |
1035 | state->enter = acpi_idle_enter_simple; | 1114 | state->enter = acpi_idle_enter_simple; |
1036 | dev->safe_state = state; | 1115 | drv->safe_state_index = count; |
1037 | break; | 1116 | break; |
1038 | 1117 | ||
1039 | case ACPI_STATE_C3: | 1118 | case ACPI_STATE_C3: |
@@ -1049,7 +1128,7 @@ static int acpi_processor_setup_cpuidle(struct acpi_processor *pr) | |||
1049 | break; | 1128 | break; |
1050 | } | 1129 | } |
1051 | 1130 | ||
1052 | dev->state_count = count; | 1131 | drv->state_count = count; |
1053 | 1132 | ||
1054 | if (!count) | 1133 | if (!count) |
1055 | return -EINVAL; | 1134 | return -EINVAL; |
@@ -1057,7 +1136,7 @@ static int acpi_processor_setup_cpuidle(struct acpi_processor *pr) | |||
1057 | return 0; | 1136 | return 0; |
1058 | } | 1137 | } |
1059 | 1138 | ||
1060 | int acpi_processor_cst_has_changed(struct acpi_processor *pr) | 1139 | int acpi_processor_hotplug(struct acpi_processor *pr) |
1061 | { | 1140 | { |
1062 | int ret = 0; | 1141 | int ret = 0; |
1063 | 1142 | ||
@@ -1078,7 +1157,7 @@ int acpi_processor_cst_has_changed(struct acpi_processor *pr) | |||
1078 | cpuidle_disable_device(&pr->power.dev); | 1157 | cpuidle_disable_device(&pr->power.dev); |
1079 | acpi_processor_get_power_info(pr); | 1158 | acpi_processor_get_power_info(pr); |
1080 | if (pr->flags.power) { | 1159 | if (pr->flags.power) { |
1081 | acpi_processor_setup_cpuidle(pr); | 1160 | acpi_processor_setup_cpuidle_cx(pr); |
1082 | ret = cpuidle_enable_device(&pr->power.dev); | 1161 | ret = cpuidle_enable_device(&pr->power.dev); |
1083 | } | 1162 | } |
1084 | cpuidle_resume_and_unlock(); | 1163 | cpuidle_resume_and_unlock(); |
@@ -1086,10 +1165,72 @@ int acpi_processor_cst_has_changed(struct acpi_processor *pr) | |||
1086 | return ret; | 1165 | return ret; |
1087 | } | 1166 | } |
1088 | 1167 | ||
1168 | int 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 | |||
1227 | static int acpi_processor_registered; | ||
1228 | |||
1089 | int __cpuinit acpi_processor_power_init(struct acpi_processor *pr, | 1229 | int __cpuinit acpi_processor_power_init(struct acpi_processor *pr, |
1090 | struct acpi_device *device) | 1230 | struct acpi_device *device) |
1091 | { | 1231 | { |
1092 | acpi_status status = 0; | 1232 | acpi_status status = 0; |
1233 | int retval; | ||
1093 | static int first_run; | 1234 | static int first_run; |
1094 | 1235 | ||
1095 | if (disabled_by_idle_boot_param()) | 1236 | if (disabled_by_idle_boot_param()) |
@@ -1126,9 +1267,26 @@ int __cpuinit acpi_processor_power_init(struct acpi_processor *pr, | |||
1126 | * platforms that only support C1. | 1267 | * platforms that only support C1. |
1127 | */ | 1268 | */ |
1128 | if (pr->flags.power) { | 1269 | if (pr->flags.power) { |
1129 | acpi_processor_setup_cpuidle(pr); | 1270 | /* Register acpi_idle_driver if not already registered */ |
1130 | if (cpuidle_register_device(&pr->power.dev)) | 1271 | if (!acpi_processor_registered) { |
1131 | return -EIO; | 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++; | ||
1132 | } | 1290 | } |
1133 | return 0; | 1291 | return 0; |
1134 | } | 1292 | } |
@@ -1139,8 +1297,13 @@ int acpi_processor_power_exit(struct acpi_processor *pr, | |||
1139 | if (disabled_by_idle_boot_param()) | 1297 | if (disabled_by_idle_boot_param()) |
1140 | return 0; | 1298 | return 0; |
1141 | 1299 | ||
1142 | cpuidle_unregister_device(&pr->power.dev); | 1300 | if (pr->flags.power) { |
1143 | pr->flags.power_setup_done = 0; | 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 | } | ||
1144 | 1306 | ||
1307 | pr->flags.power_setup_done = 0; | ||
1145 | return 0; | 1308 | return 0; |
1146 | } | 1309 | } |