@@ -74,6 +74,9 @@ static void cpufreq_exit_governor(struct cpufreq_policy *policy);
74
74
static int cpufreq_start_governor (struct cpufreq_policy * policy );
75
75
static void cpufreq_stop_governor (struct cpufreq_policy * policy );
76
76
static void cpufreq_governor_limits (struct cpufreq_policy * policy );
77
+ static int cpufreq_set_policy (struct cpufreq_policy * policy ,
78
+ struct cpufreq_governor * new_gov ,
79
+ unsigned int new_pol );
77
80
78
81
/**
79
82
* Two notifier lists: the "policy" list is involved in the
@@ -616,25 +619,22 @@ static struct cpufreq_governor *find_governor(const char *str_governor)
616
619
return NULL ;
617
620
}
618
621
619
- static int cpufreq_parse_policy (char * str_governor ,
620
- struct cpufreq_policy * policy )
622
+ static unsigned int cpufreq_parse_policy (char * str_governor )
621
623
{
622
- if (!strncasecmp (str_governor , "performance" , CPUFREQ_NAME_LEN )) {
623
- policy -> policy = CPUFREQ_POLICY_PERFORMANCE ;
624
- return 0 ;
625
- }
626
- if (!strncasecmp (str_governor , "powersave" , CPUFREQ_NAME_LEN )) {
627
- policy -> policy = CPUFREQ_POLICY_POWERSAVE ;
628
- return 0 ;
629
- }
630
- return - EINVAL ;
624
+ if (!strncasecmp (str_governor , "performance" , CPUFREQ_NAME_LEN ))
625
+ return CPUFREQ_POLICY_PERFORMANCE ;
626
+
627
+ if (!strncasecmp (str_governor , "powersave" , CPUFREQ_NAME_LEN ))
628
+ return CPUFREQ_POLICY_POWERSAVE ;
629
+
630
+ return CPUFREQ_POLICY_UNKNOWN ;
631
631
}
632
632
633
633
/**
634
634
* cpufreq_parse_governor - parse a governor string only for has_target()
635
+ * @str_governor: Governor name.
635
636
*/
636
- static int cpufreq_parse_governor (char * str_governor ,
637
- struct cpufreq_policy * policy )
637
+ static struct cpufreq_governor * cpufreq_parse_governor (char * str_governor )
638
638
{
639
639
struct cpufreq_governor * t ;
640
640
@@ -648,7 +648,7 @@ static int cpufreq_parse_governor(char *str_governor,
648
648
649
649
ret = request_module ("cpufreq_%s" , str_governor );
650
650
if (ret )
651
- return - EINVAL ;
651
+ return NULL ;
652
652
653
653
mutex_lock (& cpufreq_governor_mutex );
654
654
@@ -659,12 +659,7 @@ static int cpufreq_parse_governor(char *str_governor,
659
659
660
660
mutex_unlock (& cpufreq_governor_mutex );
661
661
662
- if (t ) {
663
- policy -> governor = t ;
664
- return 0 ;
665
- }
666
-
667
- return - EINVAL ;
662
+ return t ;
668
663
}
669
664
670
665
/**
@@ -765,28 +760,33 @@ static ssize_t show_scaling_governor(struct cpufreq_policy *policy, char *buf)
765
760
static ssize_t store_scaling_governor (struct cpufreq_policy * policy ,
766
761
const char * buf , size_t count )
767
762
{
763
+ char str_governor [16 ];
768
764
int ret ;
769
- char str_governor [16 ];
770
- struct cpufreq_policy new_policy ;
771
-
772
- memcpy (& new_policy , policy , sizeof (* policy ));
773
765
774
766
ret = sscanf (buf , "%15s" , str_governor );
775
767
if (ret != 1 )
776
768
return - EINVAL ;
777
769
778
770
if (cpufreq_driver -> setpolicy ) {
779
- if (cpufreq_parse_policy (str_governor , & new_policy ))
771
+ unsigned int new_pol ;
772
+
773
+ new_pol = cpufreq_parse_policy (str_governor );
774
+ if (!new_pol )
780
775
return - EINVAL ;
776
+
777
+ ret = cpufreq_set_policy (policy , NULL , new_pol );
781
778
} else {
782
- if (cpufreq_parse_governor (str_governor , & new_policy ))
779
+ struct cpufreq_governor * new_gov ;
780
+
781
+ new_gov = cpufreq_parse_governor (str_governor );
782
+ if (!new_gov )
783
783
return - EINVAL ;
784
- }
785
784
786
- ret = cpufreq_set_policy (policy , & new_policy );
785
+ ret = cpufreq_set_policy (policy , new_gov ,
786
+ CPUFREQ_POLICY_UNKNOWN );
787
787
788
- if ( new_policy . governor )
789
- module_put ( new_policy . governor -> owner );
788
+ module_put ( new_gov -> owner );
789
+ }
790
790
791
791
return ret ? ret : count ;
792
792
}
@@ -1053,40 +1053,33 @@ __weak struct cpufreq_governor *cpufreq_default_governor(void)
1053
1053
1054
1054
static int cpufreq_init_policy (struct cpufreq_policy * policy )
1055
1055
{
1056
- struct cpufreq_governor * gov = NULL , * def_gov = NULL ;
1057
- struct cpufreq_policy new_policy ;
1058
-
1059
- memcpy (& new_policy , policy , sizeof (* policy ));
1060
-
1061
- def_gov = cpufreq_default_governor ();
1056
+ struct cpufreq_governor * def_gov = cpufreq_default_governor ();
1057
+ struct cpufreq_governor * gov = NULL ;
1058
+ unsigned int pol = CPUFREQ_POLICY_UNKNOWN ;
1062
1059
1063
1060
if (has_target ()) {
1064
- /*
1065
- * Update governor of new_policy to the governor used before
1066
- * hotplug
1067
- */
1061
+ /* Update policy governor to the one used before hotplug. */
1068
1062
gov = find_governor (policy -> last_governor );
1069
1063
if (gov ) {
1070
1064
pr_debug ("Restoring governor %s for cpu %d\n" ,
1071
- policy -> governor -> name , policy -> cpu );
1072
- } else {
1073
- if (!def_gov )
1074
- return - ENODATA ;
1065
+ policy -> governor -> name , policy -> cpu );
1066
+ } else if (def_gov ) {
1075
1067
gov = def_gov ;
1068
+ } else {
1069
+ return - ENODATA ;
1076
1070
}
1077
- new_policy .governor = gov ;
1078
1071
} else {
1079
1072
/* Use the default policy if there is no last_policy. */
1080
1073
if (policy -> last_policy ) {
1081
- new_policy .policy = policy -> last_policy ;
1074
+ pol = policy -> last_policy ;
1075
+ } else if (def_gov ) {
1076
+ pol = cpufreq_parse_policy (def_gov -> name );
1082
1077
} else {
1083
- if (!def_gov )
1084
- return - ENODATA ;
1085
- cpufreq_parse_policy (def_gov -> name , & new_policy );
1078
+ return - ENODATA ;
1086
1079
}
1087
1080
}
1088
1081
1089
- return cpufreq_set_policy (policy , & new_policy );
1082
+ return cpufreq_set_policy (policy , gov , pol );
1090
1083
}
1091
1084
1092
1085
static int cpufreq_add_policy_cpu (struct cpufreq_policy * policy , unsigned int cpu )
@@ -1114,13 +1107,10 @@ static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy, unsigned int cp
1114
1107
1115
1108
void refresh_frequency_limits (struct cpufreq_policy * policy )
1116
1109
{
1117
- struct cpufreq_policy new_policy ;
1118
-
1119
1110
if (!policy_is_inactive (policy )) {
1120
- new_policy = * policy ;
1121
1111
pr_debug ("updating policy for CPU %u\n" , policy -> cpu );
1122
1112
1123
- cpufreq_set_policy (policy , & new_policy );
1113
+ cpufreq_set_policy (policy , policy -> governor , policy -> policy );
1124
1114
}
1125
1115
}
1126
1116
EXPORT_SYMBOL (refresh_frequency_limits );
@@ -2364,46 +2354,49 @@ EXPORT_SYMBOL(cpufreq_get_policy);
2364
2354
/**
2365
2355
* cpufreq_set_policy - Modify cpufreq policy parameters.
2366
2356
* @policy: Policy object to modify.
2367
- * @new_policy: New policy data.
2357
+ * @new_gov: Policy governor pointer.
2358
+ * @new_pol: Policy value (for drivers with built-in governors).
2368
2359
*
2369
- * Pass @new_policy to the cpufreq driver's ->verify() callback. Next, copy the
2370
- * min and max parameters of @new_policy to @policy and either invoke the
2371
- * driver's ->setpolicy() callback (if present) or carry out a governor update
2372
- * for @policy. That is, run the current governor's ->limits() callback (if the
2373
- * governor field in @new_policy points to the same object as the one in
2374
- * @policy) or replace the governor for @policy with the new one stored in
2375
- * @new_policy.
2360
+ * Invoke the cpufreq driver's ->verify() callback to sanity-check the frequency
2361
+ * limits to be set for the policy, update @policy with the verified limits
2362
+ * values and either invoke the driver's ->setpolicy() callback (if present) or
2363
+ * carry out a governor update for @policy. That is, run the current governor's
2364
+ * ->limits() callback (if @new_gov points to the same object as the one in
2365
+ * @policy) or replace the governor for @policy with @new_gov.
2376
2366
*
2377
2367
* The cpuinfo part of @policy is not updated by this function.
2378
2368
*/
2379
- int cpufreq_set_policy (struct cpufreq_policy * policy ,
2380
- struct cpufreq_policy * new_policy )
2369
+ static int cpufreq_set_policy (struct cpufreq_policy * policy ,
2370
+ struct cpufreq_governor * new_gov ,
2371
+ unsigned int new_pol )
2381
2372
{
2373
+ struct cpufreq_policy_data new_data ;
2382
2374
struct cpufreq_governor * old_gov ;
2383
2375
int ret ;
2384
2376
2385
- pr_debug ("setting new policy for CPU %u: %u - %u kHz\n" ,
2386
- new_policy -> cpu , new_policy -> min , new_policy -> max );
2387
-
2388
- memcpy (& new_policy -> cpuinfo , & policy -> cpuinfo , sizeof (policy -> cpuinfo ));
2389
-
2377
+ memcpy (& new_data .cpuinfo , & policy -> cpuinfo , sizeof (policy -> cpuinfo ));
2378
+ new_data .freq_table = policy -> freq_table ;
2379
+ new_data .cpu = policy -> cpu ;
2390
2380
/*
2391
2381
* PM QoS framework collects all the requests from users and provide us
2392
2382
* the final aggregated value here.
2393
2383
*/
2394
- new_policy -> min = freq_qos_read_value (& policy -> constraints , FREQ_QOS_MIN );
2395
- new_policy -> max = freq_qos_read_value (& policy -> constraints , FREQ_QOS_MAX );
2384
+ new_data .min = freq_qos_read_value (& policy -> constraints , FREQ_QOS_MIN );
2385
+ new_data .max = freq_qos_read_value (& policy -> constraints , FREQ_QOS_MAX );
2386
+
2387
+ pr_debug ("setting new policy for CPU %u: %u - %u kHz\n" ,
2388
+ new_data .cpu , new_data .min , new_data .max );
2396
2389
2397
2390
/*
2398
2391
* Verify that the CPU speed can be set within these limits and make sure
2399
2392
* that min <= max.
2400
2393
*/
2401
- ret = cpufreq_driver -> verify (new_policy );
2394
+ ret = cpufreq_driver -> verify (& new_data );
2402
2395
if (ret )
2403
2396
return ret ;
2404
2397
2405
- policy -> min = new_policy -> min ;
2406
- policy -> max = new_policy -> max ;
2398
+ policy -> min = new_data . min ;
2399
+ policy -> max = new_data . max ;
2407
2400
trace_cpu_frequency_limits (policy );
2408
2401
2409
2402
policy -> cached_target_freq = UINT_MAX ;
@@ -2412,12 +2405,12 @@ int cpufreq_set_policy(struct cpufreq_policy *policy,
2412
2405
policy -> min , policy -> max );
2413
2406
2414
2407
if (cpufreq_driver -> setpolicy ) {
2415
- policy -> policy = new_policy -> policy ;
2408
+ policy -> policy = new_pol ;
2416
2409
pr_debug ("setting range\n" );
2417
2410
return cpufreq_driver -> setpolicy (policy );
2418
2411
}
2419
2412
2420
- if (new_policy -> governor == policy -> governor ) {
2413
+ if (new_gov == policy -> governor ) {
2421
2414
pr_debug ("governor limits update\n" );
2422
2415
cpufreq_governor_limits (policy );
2423
2416
return 0 ;
@@ -2434,7 +2427,7 @@ int cpufreq_set_policy(struct cpufreq_policy *policy,
2434
2427
}
2435
2428
2436
2429
/* start new governor */
2437
- policy -> governor = new_policy -> governor ;
2430
+ policy -> governor = new_gov ;
2438
2431
ret = cpufreq_init_governor (policy );
2439
2432
if (!ret ) {
2440
2433
ret = cpufreq_start_governor (policy );
0 commit comments