diff options
| -rw-r--r-- | drivers/acpi/processor_throttling.c | 69 |
1 files changed, 32 insertions, 37 deletions
diff --git a/drivers/acpi/processor_throttling.c b/drivers/acpi/processor_throttling.c index 28baa05b8018..84243c32e29c 100644 --- a/drivers/acpi/processor_throttling.c +++ b/drivers/acpi/processor_throttling.c | |||
| @@ -56,6 +56,12 @@ struct throttling_tstate { | |||
| 56 | int target_state; /* target T-state */ | 56 | int target_state; /* target T-state */ |
| 57 | }; | 57 | }; |
| 58 | 58 | ||
| 59 | struct acpi_processor_throttling_arg { | ||
| 60 | struct acpi_processor *pr; | ||
| 61 | int target_state; | ||
| 62 | bool force; | ||
| 63 | }; | ||
| 64 | |||
| 59 | #define THROTTLING_PRECHANGE (1) | 65 | #define THROTTLING_PRECHANGE (1) |
| 60 | #define THROTTLING_POSTCHANGE (2) | 66 | #define THROTTLING_POSTCHANGE (2) |
| 61 | 67 | ||
| @@ -1060,16 +1066,24 @@ static int acpi_processor_set_throttling_ptc(struct acpi_processor *pr, | |||
| 1060 | return 0; | 1066 | return 0; |
| 1061 | } | 1067 | } |
| 1062 | 1068 | ||
| 1069 | static long acpi_processor_throttling_fn(void *data) | ||
| 1070 | { | ||
| 1071 | struct acpi_processor_throttling_arg *arg = data; | ||
| 1072 | struct acpi_processor *pr = arg->pr; | ||
| 1073 | |||
| 1074 | return pr->throttling.acpi_processor_set_throttling(pr, | ||
| 1075 | arg->target_state, arg->force); | ||
| 1076 | } | ||
| 1077 | |||
| 1063 | int acpi_processor_set_throttling(struct acpi_processor *pr, | 1078 | int acpi_processor_set_throttling(struct acpi_processor *pr, |
| 1064 | int state, bool force) | 1079 | int state, bool force) |
| 1065 | { | 1080 | { |
| 1066 | cpumask_var_t saved_mask; | ||
| 1067 | int ret = 0; | 1081 | int ret = 0; |
| 1068 | unsigned int i; | 1082 | unsigned int i; |
| 1069 | struct acpi_processor *match_pr; | 1083 | struct acpi_processor *match_pr; |
| 1070 | struct acpi_processor_throttling *p_throttling; | 1084 | struct acpi_processor_throttling *p_throttling; |
| 1085 | struct acpi_processor_throttling_arg arg; | ||
| 1071 | struct throttling_tstate t_state; | 1086 | struct throttling_tstate t_state; |
| 1072 | cpumask_var_t online_throttling_cpus; | ||
| 1073 | 1087 | ||
| 1074 | if (!pr) | 1088 | if (!pr) |
| 1075 | return -EINVAL; | 1089 | return -EINVAL; |
| @@ -1080,14 +1094,6 @@ int acpi_processor_set_throttling(struct acpi_processor *pr, | |||
| 1080 | if ((state < 0) || (state > (pr->throttling.state_count - 1))) | 1094 | if ((state < 0) || (state > (pr->throttling.state_count - 1))) |
| 1081 | return -EINVAL; | 1095 | return -EINVAL; |
| 1082 | 1096 | ||
| 1083 | if (!alloc_cpumask_var(&saved_mask, GFP_KERNEL)) | ||
| 1084 | return -ENOMEM; | ||
| 1085 | |||
| 1086 | if (!alloc_cpumask_var(&online_throttling_cpus, GFP_KERNEL)) { | ||
| 1087 | free_cpumask_var(saved_mask); | ||
| 1088 | return -ENOMEM; | ||
| 1089 | } | ||
| 1090 | |||
| 1091 | if (cpu_is_offline(pr->id)) { | 1097 | if (cpu_is_offline(pr->id)) { |
| 1092 | /* | 1098 | /* |
| 1093 | * the cpu pointed by pr->id is offline. Unnecessary to change | 1099 | * the cpu pointed by pr->id is offline. Unnecessary to change |
| @@ -1096,17 +1102,15 @@ int acpi_processor_set_throttling(struct acpi_processor *pr, | |||
| 1096 | return -ENODEV; | 1102 | return -ENODEV; |
| 1097 | } | 1103 | } |
| 1098 | 1104 | ||
| 1099 | cpumask_copy(saved_mask, ¤t->cpus_allowed); | ||
| 1100 | t_state.target_state = state; | 1105 | t_state.target_state = state; |
| 1101 | p_throttling = &(pr->throttling); | 1106 | p_throttling = &(pr->throttling); |
| 1102 | cpumask_and(online_throttling_cpus, cpu_online_mask, | 1107 | |
| 1103 | p_throttling->shared_cpu_map); | ||
| 1104 | /* | 1108 | /* |
| 1105 | * The throttling notifier will be called for every | 1109 | * The throttling notifier will be called for every |
| 1106 | * affected cpu in order to get one proper T-state. | 1110 | * affected cpu in order to get one proper T-state. |
| 1107 | * The notifier event is THROTTLING_PRECHANGE. | 1111 | * The notifier event is THROTTLING_PRECHANGE. |
| 1108 | */ | 1112 | */ |
| 1109 | for_each_cpu(i, online_throttling_cpus) { | 1113 | for_each_cpu_and(i, cpu_online_mask, p_throttling->shared_cpu_map) { |
| 1110 | t_state.cpu = i; | 1114 | t_state.cpu = i; |
| 1111 | acpi_processor_throttling_notifier(THROTTLING_PRECHANGE, | 1115 | acpi_processor_throttling_notifier(THROTTLING_PRECHANGE, |
| 1112 | &t_state); | 1116 | &t_state); |
| @@ -1118,21 +1122,18 @@ int acpi_processor_set_throttling(struct acpi_processor *pr, | |||
| 1118 | * it can be called only for the cpu pointed by pr. | 1122 | * it can be called only for the cpu pointed by pr. |
| 1119 | */ | 1123 | */ |
| 1120 | if (p_throttling->shared_type == DOMAIN_COORD_TYPE_SW_ANY) { | 1124 | if (p_throttling->shared_type == DOMAIN_COORD_TYPE_SW_ANY) { |
| 1121 | /* FIXME: use work_on_cpu() */ | 1125 | arg.pr = pr; |
| 1122 | if (set_cpus_allowed_ptr(current, cpumask_of(pr->id))) { | 1126 | arg.target_state = state; |
| 1123 | /* Can't migrate to the pr->id CPU. Exit */ | 1127 | arg.force = force; |
| 1124 | ret = -ENODEV; | 1128 | ret = work_on_cpu(pr->id, acpi_processor_throttling_fn, &arg); |
| 1125 | goto exit; | ||
| 1126 | } | ||
| 1127 | ret = p_throttling->acpi_processor_set_throttling(pr, | ||
| 1128 | t_state.target_state, force); | ||
| 1129 | } else { | 1129 | } else { |
| 1130 | /* | 1130 | /* |
| 1131 | * When the T-state coordination is SW_ALL or HW_ALL, | 1131 | * When the T-state coordination is SW_ALL or HW_ALL, |
| 1132 | * it is necessary to set T-state for every affected | 1132 | * it is necessary to set T-state for every affected |
| 1133 | * cpus. | 1133 | * cpus. |
| 1134 | */ | 1134 | */ |
| 1135 | for_each_cpu(i, online_throttling_cpus) { | 1135 | for_each_cpu_and(i, cpu_online_mask, |
| 1136 | p_throttling->shared_cpu_map) { | ||
| 1136 | match_pr = per_cpu(processors, i); | 1137 | match_pr = per_cpu(processors, i); |
| 1137 | /* | 1138 | /* |
| 1138 | * If the pointer is invalid, we will report the | 1139 | * If the pointer is invalid, we will report the |
| @@ -1153,13 +1154,12 @@ int acpi_processor_set_throttling(struct acpi_processor *pr, | |||
| 1153 | "on CPU %d\n", i)); | 1154 | "on CPU %d\n", i)); |
| 1154 | continue; | 1155 | continue; |
| 1155 | } | 1156 | } |
| 1156 | t_state.cpu = i; | 1157 | |
| 1157 | /* FIXME: use work_on_cpu() */ | 1158 | arg.pr = match_pr; |
| 1158 | if (set_cpus_allowed_ptr(current, cpumask_of(i))) | 1159 | arg.target_state = state; |
| 1159 | continue; | 1160 | arg.force = force; |
| 1160 | ret = match_pr->throttling. | 1161 | ret = work_on_cpu(pr->id, acpi_processor_throttling_fn, |
| 1161 | acpi_processor_set_throttling( | 1162 | &arg); |
| 1162 | match_pr, t_state.target_state, force); | ||
| 1163 | } | 1163 | } |
| 1164 | } | 1164 | } |
| 1165 | /* | 1165 | /* |
| @@ -1168,17 +1168,12 @@ int acpi_processor_set_throttling(struct acpi_processor *pr, | |||
| 1168 | * affected cpu to update the T-states. | 1168 | * affected cpu to update the T-states. |
| 1169 | * The notifier event is THROTTLING_POSTCHANGE | 1169 | * The notifier event is THROTTLING_POSTCHANGE |
| 1170 | */ | 1170 | */ |
| 1171 | for_each_cpu(i, online_throttling_cpus) { | 1171 | for_each_cpu_and(i, cpu_online_mask, p_throttling->shared_cpu_map) { |
| 1172 | t_state.cpu = i; | 1172 | t_state.cpu = i; |
| 1173 | acpi_processor_throttling_notifier(THROTTLING_POSTCHANGE, | 1173 | acpi_processor_throttling_notifier(THROTTLING_POSTCHANGE, |
| 1174 | &t_state); | 1174 | &t_state); |
| 1175 | } | 1175 | } |
| 1176 | /* restore the previous state */ | 1176 | |
| 1177 | /* FIXME: use work_on_cpu() */ | ||
| 1178 | set_cpus_allowed_ptr(current, saved_mask); | ||
| 1179 | exit: | ||
| 1180 | free_cpumask_var(online_throttling_cpus); | ||
| 1181 | free_cpumask_var(saved_mask); | ||
| 1182 | return ret; | 1177 | return ret; |
| 1183 | } | 1178 | } |
| 1184 | 1179 | ||
