@@ -84,7 +84,6 @@ static inline struct acpi_processor_performance *to_perf_data(struct acpi_cpufre
8484static struct cpufreq_driver acpi_cpufreq_driver ;
8585
8686static unsigned int acpi_pstate_strict ;
87- static struct msr __percpu * msrs ;
8887
8988static bool boost_state (unsigned int cpu )
9089{
@@ -104,11 +103,10 @@ static bool boost_state(unsigned int cpu)
104103 return false;
105104}
106105
107- static void boost_set_msrs (bool enable , const struct cpumask * cpumask )
106+ static int boost_set_msr (bool enable )
108107{
109- u32 cpu ;
110108 u32 msr_addr ;
111- u64 msr_mask ;
109+ u64 msr_mask , val ;
112110
113111 switch (boot_cpu_data .x86_vendor ) {
114112 case X86_VENDOR_INTEL :
@@ -120,26 +118,31 @@ static void boost_set_msrs(bool enable, const struct cpumask *cpumask)
120118 msr_mask = MSR_K7_HWCR_CPB_DIS ;
121119 break ;
122120 default :
123- return ;
121+ return - EINVAL ;
124122 }
125123
126- rdmsr_on_cpus ( cpumask , msr_addr , msrs );
124+ rdmsrl ( msr_addr , val );
127125
128- for_each_cpu (cpu , cpumask ) {
129- struct msr * reg = per_cpu_ptr (msrs , cpu );
130- if (enable )
131- reg -> q &= ~msr_mask ;
132- else
133- reg -> q |= msr_mask ;
134- }
126+ if (enable )
127+ val &= ~msr_mask ;
128+ else
129+ val |= msr_mask ;
130+
131+ wrmsrl (msr_addr , val );
132+ return 0 ;
133+ }
134+
135+ static void boost_set_msr_each (void * p_en )
136+ {
137+ bool enable = (bool ) p_en ;
135138
136- wrmsr_on_cpus ( cpumask , msr_addr , msrs );
139+ boost_set_msr ( enable );
137140}
138141
139142static int set_boost (int val )
140143{
141144 get_online_cpus ();
142- boost_set_msrs ( val , cpu_online_mask );
145+ on_each_cpu ( boost_set_msr_each , ( void * )( long ) val , 1 );
143146 put_online_cpus ();
144147 pr_debug ("Core Boosting %sabled.\n" , val ? "en" : "dis" );
145148
@@ -536,46 +539,24 @@ static void free_acpi_perf_data(void)
536539 free_percpu (acpi_perf_data );
537540}
538541
539- static int boost_notify (struct notifier_block * nb , unsigned long action ,
540- void * hcpu )
542+ static int cpufreq_boost_online (unsigned int cpu )
541543{
542- unsigned cpu = (long )hcpu ;
543- const struct cpumask * cpumask ;
544-
545- cpumask = get_cpu_mask (cpu );
544+ /*
545+ * On the CPU_UP path we simply keep the boost-disable flag
546+ * in sync with the current global state.
547+ */
548+ return boost_set_msr (acpi_cpufreq_driver .boost_enabled );
549+ }
546550
551+ static int cpufreq_boost_down_prep (unsigned int cpu )
552+ {
547553 /*
548554 * Clear the boost-disable bit on the CPU_DOWN path so that
549- * this cpu cannot block the remaining ones from boosting. On
550- * the CPU_UP path we simply keep the boost-disable flag in
551- * sync with the current global state.
555+ * this cpu cannot block the remaining ones from boosting.
552556 */
553-
554- switch (action ) {
555- case CPU_DOWN_FAILED :
556- case CPU_DOWN_FAILED_FROZEN :
557- case CPU_ONLINE :
558- case CPU_ONLINE_FROZEN :
559- boost_set_msrs (acpi_cpufreq_driver .boost_enabled , cpumask );
560- break ;
561-
562- case CPU_DOWN_PREPARE :
563- case CPU_DOWN_PREPARE_FROZEN :
564- boost_set_msrs (1 , cpumask );
565- break ;
566-
567- default :
568- break ;
569- }
570-
571- return NOTIFY_OK ;
557+ return boost_set_msr (1 );
572558}
573559
574-
575- static struct notifier_block boost_nb = {
576- .notifier_call = boost_notify ,
577- };
578-
579560/*
580561 * acpi_cpufreq_early_init - initialize ACPI P-States library
581562 *
@@ -922,37 +903,35 @@ static struct cpufreq_driver acpi_cpufreq_driver = {
922903 .attr = acpi_cpufreq_attr ,
923904};
924905
906+ static enum cpuhp_state acpi_cpufreq_online ;
907+
925908static void __init acpi_cpufreq_boost_init (void )
926909{
927- if (boot_cpu_has (X86_FEATURE_CPB ) || boot_cpu_has (X86_FEATURE_IDA )) {
928- msrs = msrs_alloc ();
929-
930- if (!msrs )
931- return ;
932-
933- acpi_cpufreq_driver .set_boost = set_boost ;
934- acpi_cpufreq_driver .boost_enabled = boost_state (0 );
935-
936- cpu_notifier_register_begin ();
910+ int ret ;
937911
938- /* Force all MSRs to the same value */
939- boost_set_msrs (acpi_cpufreq_driver .boost_enabled ,
940- cpu_online_mask );
912+ if (!(boot_cpu_has (X86_FEATURE_CPB ) || boot_cpu_has (X86_FEATURE_IDA )))
913+ return ;
941914
942- __register_cpu_notifier (& boost_nb );
915+ acpi_cpufreq_driver .set_boost = set_boost ;
916+ acpi_cpufreq_driver .boost_enabled = boost_state (0 );
943917
944- cpu_notifier_register_done ();
918+ /*
919+ * This calls the online callback on all online cpu and forces all
920+ * MSRs to the same value.
921+ */
922+ ret = cpuhp_setup_state (CPUHP_AP_ONLINE_DYN , "cpufreq/acpi:online" ,
923+ cpufreq_boost_online , cpufreq_boost_down_prep );
924+ if (ret < 0 ) {
925+ pr_err ("acpi_cpufreq: failed to register hotplug callbacks\n" );
926+ return ;
945927 }
928+ acpi_cpufreq_online = ret ;
946929}
947930
948931static void acpi_cpufreq_boost_exit (void )
949932{
950- if (msrs ) {
951- unregister_cpu_notifier (& boost_nb );
952-
953- msrs_free (msrs );
954- msrs = NULL ;
955- }
933+ if (acpi_cpufreq_online >= 0 )
934+ cpuhp_remove_state_nocalls (acpi_cpufreq_online );
956935}
957936
958937static int __init acpi_cpufreq_init (void )
0 commit comments