cpufreq: governor: ondemand/conservative data structures rework
cover cpufreq: governor: ondemand/conservative data structures rework
Hi,
A few days ago I looked at the common code used by the ondemand and conservative governors because of the deadlock issue that Viresh has addressed recently
(http://marc.info/?l=linux-pm&m=145450832814058&w=4) and it occurred to me that the whole thing was really too tangled and might be made easier to follow at least. I started to work on this and ended up with the following series.
I'm not really going to stop here, but first, I'd like to let everybody know that this is happening and second, I'll need to rebase these patches on the ones from Viresh (in the series linked above), but that may take some time and I don't want to sit on them for all that long.
Overall, I'd like the governor code to be cleaner and easier to follow, so we can move at least some parts of governor work to utilization update callbacks (invoked by the scheduler) or to at least to irq_work so as to reduce the usage of process context in cpufreq to absolute minimum. That's the plan for the future, but for now this is just a major cleanup.
[1/11] Clean up the way in which the default and fallback governors are set up. [2/11] Use a common global mutex for dbs_data protection.
[3/11] Use common global pointer to dbs_data for system-wide governors. [4/11] Avoid passing dbs_data pointers to functions that can get them by themselves. [5/11] Make struct governor be a member of struct common_dbs_data.
[6/11] Rename struct common_dbs_data to struct dbs_governor.
[7/11] Rework cpufreq_governor_dbs() so it can be used as a governor callback directly. [8/11] Drop the dbs_governor (former cdata) pointer from struct dbs_data. [9/11] Rename struct cpu_common_dbs_info to struct policy_dbs_info.
[10/11] Rearrange data structures so policy->governor_data points to struct policy_dbs_info. [11/11] Drop the second argument of dbs_check_cpu().
The patches are on top of 4.5-rc2 with my earlier series replacing timers with utilization update callbacks (http://marc.info/?l=linux-kernel&m=145410842801883&w=4)
applied.
Thanks,
Rafael
PATCH 1/11 cpufreq: Clean up default and fallback governor setup
From: Rafael J. Wysocki <[email protected]>
The preprocessor magic used for setting the default cpufreq governor (and for using the performance governor as a fallback one for that matter) is really nasty, so replace it with __weak functions and overrides.
--- drivers/cpufreq/cpufreq.c | 37 ++++++++++++++++++--------------- drivers/cpufreq/cpufreq_conservative.c | 10 +++++--- drivers/cpufreq/cpufreq_ondemand.c | 34 ++++++++++++++++-------------- drivers/cpufreq/cpufreq_performance.c | 18 ++++++++++++---- drivers/cpufreq/cpufreq_powersave.c | 10 +++++--- drivers/cpufreq/cpufreq_userspace.c | 10 +++++--- include/linux/cpufreq.h | 25 +--------------------- 7 files changed, 73 insertions(+), 71 deletions(-)
drivers/cpufreq/cpufreq.c +21 -16
@@ -1003,6 +1003,11 @@ static int cpufreq_add_dev_interface(strreturn cpufreq_add_dev_symlink (policy); } +__weak struct cpufreq_governor *cpufreq_default_governor (void ) +{ +return NULL ; +} +static int cpufreq_init_policy (struct cpufreq_policy *policy) {struct cpufreq_governor *gov =NULL ;
@@ -1012,11 +1017,14 @@ static int cpufreq_init_policy(struct cp/* Update governor of new_policy to the governor used before hotplug */ gov =find_governor (policy->last_governor); -if (gov) +if (gov) {pr_debug ("Restoring governor %s for cpu %d\n" , policy->governor->name, policy->cpu); -else - gov =CPUFREQ_DEFAULT_GOVERNOR ; + }else { + gov =cpufreq_default_governor (); +if (!gov) +return -ENODATA ; + } new_policy.governor = gov;
@@ -1964,21 +1972,16 @@ int cpufreq_driver_target(struct cpufreq }EXPORT_SYMBOL_GPL (cpufreq_driver_target); +__weak struct cpufreq_governor *cpufreq_fallback_governor (void ) +{ +return NULL ; +} +static int __cpufreq_governor (struct cpufreq_policy *policy,unsigned int event) {int ret; -/* Only must be defined when default governor is known to have latency -restrictions, like e.g. conservative or ondemand. -That this is the case is already ensured in Kconfig -*/ -#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE -struct cpufreq_governor *gov = &cpufreq_gov_performance; -#else -struct cpufreq_governor *gov =NULL ; -#endif -/* Don't start any governor operations if we are entering suspend */ if (cpufreq_suspended)return 0 ;
@@ -1992,12 +1995,14 @@ static int __cpufreq_governor(struct cpuif (policy->governor->max_transition_latency && policy->cpuinfo.transition_latency > policy->governor->max_transition_latency) { -if (!gov) -return -EINVAL ; -else { +struct cpufreq_governor *gov =cpufreq_fallback_governor (); + +if (gov) {pr_warn ("%s governor failed, too long transition latency of HW, fallback to %s governor\n" , policy->governor->name, gov->name); policy->governor = gov; + }else { +return -EINVAL ; } }
drivers/cpufreq/cpufreq_conservative.c +6 -4
@@ -26,10 +26,7 @@ static DEFINE_PER_CPU(struct cs_cpu_dbs_static int cs_cpufreq_governor_dbs (struct cpufreq_policy *policy,unsigned int event); -#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE -static -#endif -struct cpufreq_governor cpufreq_gov_conservative = { +static struct cpufreq_governor cpufreq_gov_conservative = { .name ="conservative" , .governor = cs_cpufreq_governor_dbs, .max_transition_latency =TRANSITION_LATENCY_LIMIT ,
@@ -397,6 +394,11 @@ MODULE_DESCRIPTION("'cpufreq_conservativMODULE_LICENSE ("GPL" );#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE +struct cpufreq_governor *cpufreq_default_governor (void ) +{ +return &cpufreq_gov_conservative; +} +fs_initcall (cpufreq_gov_dbs_init);#else module_init (cpufreq_gov_dbs_init);
include/linux/cpufreq.h +2 -23
@@ -471,29 +471,8 @@ int __cpufreq_driver_target(struct cpufrint cpufreq_register_governor (struct cpufreq_governor *governor);void cpufreq_unregister_governor (struct cpufreq_governor *governor); -/* CPUFREQ DEFAULT GOVERNOR */ -/* -* Performance governor is fallback governor if any other gov failed to auto -* load due latency restrictions -*/ -#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE -extern struct cpufreq_governor cpufreq_gov_performance; -#endif -#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE -#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_performance) -#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE ) -extern struct cpufreq_governor cpufreq_gov_powersave; -#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_powersave) -#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE ) -extern struct cpufreq_governor cpufreq_gov_userspace; -#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_userspace) -#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND ) -extern struct cpufreq_governor cpufreq_gov_ondemand; -#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_ondemand) -#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE ) -extern struct cpufreq_governor cpufreq_gov_conservative; -#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_conservative) -#endif +struct cpufreq_governor *cpufreq_default_governor (void ); +struct cpufreq_governor *cpufreq_fallback_governor (void );/********************************************************************* * FREQUENCY TABLE HELPERS *
drivers/cpufreq/cpufreq_ondemand.c +18 -16
@@ -553,6 +553,19 @@ static struct common_dbs_data od_dbs_cda .mutex = __MUTEX_INITIALIZER(od_dbs_cdata.mutex), }; +static int od_cpufreq_governor_dbs (struct cpufreq_policy *policy, +unsigned int event) +{ +return cpufreq_governor_dbs (policy, &od_dbs_cdata, event); +} + +static struct cpufreq_governor cpufreq_gov_ondemand = { + .name ="ondemand" , + .governor = od_cpufreq_governor_dbs, + .max_transition_latency =TRANSITION_LATENCY_LIMIT , + .owner =THIS_MODULE , +}; +static void od_set_powersave_bias (unsigned int powersave_bias) {struct cpufreq_policy *policy;
@@ -604,22 +617,6 @@ void od_unregister_powersave_bias_handle }EXPORT_SYMBOL_GPL (od_unregister_powersave_bias_handler); -static int od_cpufreq_governor_dbs (struct cpufreq_policy *policy, -unsigned int event) -{ -return cpufreq_governor_dbs (policy, &od_dbs_cdata, event); -} - -#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND -static -#endif -struct cpufreq_governor cpufreq_gov_ondemand = { - .name ="ondemand" , - .governor = od_cpufreq_governor_dbs, - .max_transition_latency =TRANSITION_LATENCY_LIMIT , - .owner =THIS_MODULE , -}; -static int __init cpufreq_gov_dbs_init (void ) {return cpufreq_register_governor (&cpufreq_gov_ondemand);
@@ -637,6 +634,11 @@ MODULE_DESCRIPTION("'cpufreq_ondemand' -MODULE_LICENSE ("GPL" );#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND +struct cpufreq_governor *cpufreq_default_governor (void ) +{ +return &cpufreq_gov_ondemand; +} +fs_initcall (cpufreq_gov_dbs_init);#else module_init (cpufreq_gov_dbs_init);
drivers/cpufreq/cpufreq_performance.c +14 -4
@@ -33,10 +33,7 @@ static int cpufreq_governor_performance(return 0 ; } -#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE_MODULE -static -#endif -struct cpufreq_governor cpufreq_gov_performance = { +static struct cpufreq_governor cpufreq_gov_performance = { .name ="performance" , .governor = cpufreq_governor_performance, .owner =THIS_MODULE ,
@@ -52,6 +49,19 @@ static void __exit cpufreq_gov_performancpufreq_unregister_governor (&cpufreq_gov_performance); } +#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE +struct cpufreq_governor *cpufreq_default_governor (void ) +{ +return &cpufreq_gov_performance; +} +#endif +#ifndef CONFIG_CPU_FREQ_GOV_PERFORMANCE_MODULE +struct cpufreq_governor *cpufreq_fallback_governor (void ) +{ +return &cpufreq_gov_performance; +} +#endif +MODULE_AUTHOR ("Dominik Brodowski <[email protected]>" );MODULE_DESCRIPTION ("CPUfreq policy governor 'performance'" );MODULE_LICENSE ("GPL" );
drivers/cpufreq/cpufreq_powersave.c +6 -4
@@ -33,10 +33,7 @@ static int cpufreq_governor_powersave(streturn 0 ; } -#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE -static -#endif -struct cpufreq_governor cpufreq_gov_powersave = { +static struct cpufreq_governor cpufreq_gov_powersave = { .name ="powersave" , .governor = cpufreq_governor_powersave, .owner =THIS_MODULE ,
@@ -57,6 +54,11 @@ MODULE_DESCRIPTION("CPUfreq policy goverMODULE_LICENSE ("GPL" );#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE +struct cpufreq_governor *cpufreq_default_governor (void ) +{ +return &cpufreq_gov_powersave; +} +fs_initcall (cpufreq_gov_powersave_init);#else module_init (cpufreq_gov_powersave_init);
drivers/cpufreq/cpufreq_userspace.c +6 -4
@@ -89,10 +89,7 @@ static int cpufreq_governor_userspace(streturn rc; } -#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE -static -#endif -struct cpufreq_governor cpufreq_gov_userspace = { +static struct cpufreq_governor cpufreq_gov_userspace = { .name ="userspace" , .governor = cpufreq_governor_userspace, .store_setspeed = cpufreq_set,
@@ -116,6 +113,11 @@ MODULE_DESCRIPTION("CPUfreq policy goverMODULE_LICENSE ("GPL" );#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE +struct cpufreq_governor *cpufreq_default_governor (void ) +{ +return &cpufreq_gov_userspace; +} +fs_initcall (cpufreq_gov_userspace_init);#else module_init (cpufreq_gov_userspace_init);
Re: [PATCH 1/11] cpufreq: Clean up default and fallback governor setup
Quoted 314 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
The preprocessor magic used for setting the default cpufreq governor (and for using the performance governor as a fallback one for that matter) is really nasty, so replace it with
__weakfunctions and overrides.Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/cpufreq/cpufreq.c | 37 ++++++++++++++++++--------------- drivers/cpufreq/cpufreq_conservative.c | 10 +++++--- drivers/cpufreq/cpufreq_ondemand.c | 34 ++++++++++++++++-------------- drivers/cpufreq/cpufreq_performance.c | 18 ++++++++++++---- drivers/cpufreq/cpufreq_powersave.c | 10 +++++--- drivers/cpufreq/cpufreq_userspace.c | 10 +++++--- include/linux/cpufreq.h | 25 +--------------------- 7 files changed, 73 insertions(+), 71 deletions(-)Index:
linux-pm/drivers/cpufreq/cpufreq.c
===================================================================drivers/cpufreq/cpufreq.c +21
-16@@ -1003,6 +1003,11 @@ static int cpufreq_add_dev_interface(strreturn cpufreq_add_dev_symlink (policy); } +__weak struct cpufreq_governor *cpufreq_default_governor (void ) +{ +return NULL ; +} +static int cpufreq_init_policy (struct cpufreq_policy *policy) {struct cpufreq_governor *gov =NULL ;@@ -1012,11 +1017,14 @@ static int cpufreq_init_policy(struct cp/* Update governor of new_policy to the governor used before hotplug */ gov =find_governor (policy->last_governor); -if (gov) +if (gov) {pr_debug ("Restoring governor %s for cpu %d\n" , policy->governor->name, policy->cpu); -else - gov =CPUFREQ_DEFAULT_GOVERNOR ; + }else { + gov =cpufreq_default_governor (); +if (!gov) +return -ENODATA ; + } new_policy.governor = gov;@@ -1964,21 +1972,16 @@ int cpufreq_driver_target(struct cpufreq }EXPORT_SYMBOL_GPL (cpufreq_driver_target); +__weak struct cpufreq_governor *cpufreq_fallback_governor (void ) +{ +return NULL ; +} +static int __cpufreq_governor (struct cpufreq_policy *policy,unsigned int event) {int ret; -/* Only must be defined when default governor is known to have latency -restrictions, like e.g. conservative or ondemand. -That this is the case is already ensured in Kconfig -*/ -#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE -struct cpufreq_governor *gov = &cpufreq_gov_performance; -#else -struct cpufreq_governor *gov =NULL ; -#endif -/* Don't start any governor operations if we are entering suspend */ if (cpufreq_suspended)return 0 ;@@ -1992,12 +1995,14 @@ static int __cpufreq_governor(struct cpuif (policy->governor->max_transition_latency && policy->cpuinfo.transition_latency > policy->governor->max_transition_latency) { -if (!gov) -return -EINVAL ; -else { +struct cpufreq_governor *gov =cpufreq_fallback_governor (); + +if (gov) {pr_warn ("%s governor failed, too long transition latency of HW, fallback to %s governor\n" , policy->governor->name, gov->name); policy->governor = gov; + }else { +return -EINVAL ; } }Index:
linux-pm/drivers/cpufreq/cpufreq_conservative.c
===================================================================drivers/cpufreq/cpufreq_conservative.c +6
-4@@ -26,10 +26,7 @@ static DEFINE_PER_CPU(struct cs_cpu_dbs_static int cs_cpufreq_governor_dbs (struct cpufreq_policy *policy,unsigned int event); -#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE -static -#endif -struct cpufreq_governor cpufreq_gov_conservative = { +static struct cpufreq_governor cpufreq_gov_conservative = { .name ="conservative" , .governor = cs_cpufreq_governor_dbs, .max_transition_latency =TRANSITION_LATENCY_LIMIT ,@@ -397,6 +394,11 @@ MODULE_DESCRIPTION("'cpufreq_conservativMODULE_LICENSE ("GPL" );#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE +struct cpufreq_governor *cpufreq_default_governor (void ) +{ +return &cpufreq_gov_conservative; +} +fs_initcall (cpufreq_gov_dbs_init);#else module_init (cpufreq_gov_dbs_init);Index:
linux-pm/include/linux/cpufreq.h
===================================================================include/linux/cpufreq.h +2
-23@@ -471,29 +471,8 @@ int __cpufreq_driver_target(struct cpufrint cpufreq_register_governor (struct cpufreq_governor *governor);void cpufreq_unregister_governor (struct cpufreq_governor *governor); -/* CPUFREQ DEFAULT GOVERNOR */ -/* -* Performance governor is fallback governor if any other gov failed to auto -* load due latency restrictions -*/ -#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE -extern struct cpufreq_governor cpufreq_gov_performance; -#endif -#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE -#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_performance) -#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE ) -extern struct cpufreq_governor cpufreq_gov_powersave; -#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_powersave) -#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE ) -extern struct cpufreq_governor cpufreq_gov_userspace; -#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_userspace) -#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND ) -extern struct cpufreq_governor cpufreq_gov_ondemand; -#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_ondemand) -#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE ) -extern struct cpufreq_governor cpufreq_gov_conservative; -#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_conservative) -#endif +struct cpufreq_governor *cpufreq_default_governor (void ); +struct cpufreq_governor *cpufreq_fallback_governor (void );/********************************************************************* * FREQUENCY TABLE HELPERS * Index:
linux-pm/drivers/cpufreq/cpufreq_ondemand.c
===================================================================drivers/cpufreq/cpufreq_ondemand.c +18
-16@@ -553,6 +553,19 @@ static struct common_dbs_data od_dbs_cda .mutex = __MUTEX_INITIALIZER(od_dbs_cdata.mutex), }; +static int od_cpufreq_governor_dbs (struct cpufreq_policy *policy, +unsigned int event) +{ +return cpufreq_governor_dbs (policy, &od_dbs_cdata, event); +} + +static struct cpufreq_governor cpufreq_gov_ondemand = { + .name ="ondemand" , + .governor = od_cpufreq_governor_dbs, + .max_transition_latency =TRANSITION_LATENCY_LIMIT , + .owner =THIS_MODULE , +}; +static void od_set_powersave_bias (unsigned int powersave_bias) {struct cpufreq_policy *policy;@@ -604,22 +617,6 @@ void od_unregister_powersave_bias_handle }EXPORT_SYMBOL_GPL (od_unregister_powersave_bias_handler); -static int od_cpufreq_governor_dbs (struct cpufreq_policy *policy, -unsigned int event) -{ -return cpufreq_governor_dbs (policy, &od_dbs_cdata, event); -} - -#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND -static -#endif -struct cpufreq_governor cpufreq_gov_ondemand = { - .name ="ondemand" , - .governor = od_cpufreq_governor_dbs, - .max_transition_latency =TRANSITION_LATENCY_LIMIT , - .owner =THIS_MODULE , -}; -static int __init cpufreq_gov_dbs_init (void ) {return cpufreq_register_governor (&cpufreq_gov_ondemand);@@ -637,6 +634,11 @@ MODULE_DESCRIPTION("'cpufreq_ondemand' -MODULE_LICENSE ("GPL" );#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND +struct cpufreq_governor *cpufreq_default_governor (void ) +{ +return &cpufreq_gov_ondemand; +} +fs_initcall (cpufreq_gov_dbs_init);#else module_init (cpufreq_gov_dbs_init);Index:
linux-pm/drivers/cpufreq/cpufreq_performance.c
===================================================================drivers/cpufreq/cpufreq_performance.c +14
-4@@ -33,10 +33,7 @@ static int cpufreq_governor_performance(return 0 ; } -#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE_MODULE -static -#endif -struct cpufreq_governor cpufreq_gov_performance = { +static struct cpufreq_governor cpufreq_gov_performance = { .name ="performance" , .governor = cpufreq_governor_performance, .owner =THIS_MODULE ,@@ -52,6 +49,19 @@ static void __exit cpufreq_gov_performancpufreq_unregister_governor (&cpufreq_gov_performance); } +#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE +struct cpufreq_governor *cpufreq_default_governor (void ) +{ +return &cpufreq_gov_performance; +} +#endif +#ifndef CONFIG_CPU_FREQ_GOV_PERFORMANCE_MODULE +struct cpufreq_governor *cpufreq_fallback_governor (void ) +{ +return &cpufreq_gov_performance; +} +#endif +MODULE_AUTHOR ("Dominik Brodowski <[email protected]>" );MODULE_DESCRIPTION ("CPUfreq policy governor 'performance'" );MODULE_LICENSE ("GPL" );Index:
linux-pm/drivers/cpufreq/cpufreq_powersave.c
===================================================================drivers/cpufreq/cpufreq_powersave.c +6
-4@@ -33,10 +33,7 @@ static int cpufreq_governor_powersave(streturn 0 ; } -#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE -static -#endif -struct cpufreq_governor cpufreq_gov_powersave = { +static struct cpufreq_governor cpufreq_gov_powersave = { .name ="powersave" , .governor = cpufreq_governor_powersave, .owner =THIS_MODULE ,@@ -57,6 +54,11 @@ MODULE_DESCRIPTION("CPUfreq policy goverMODULE_LICENSE ("GPL" );#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE +struct cpufreq_governor *cpufreq_default_governor (void ) +{ +return &cpufreq_gov_powersave; +} +fs_initcall (cpufreq_gov_powersave_init);#else module_init (cpufreq_gov_powersave_init);Index:
linux-pm/drivers/cpufreq/cpufreq_userspace.c
===================================================================drivers/cpufreq/cpufreq_userspace.c +6
-5@@ -89,10 +89,7 @@ static int cpufreq_governor_userspace(streturn rc; } -#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE -static -#endif -struct cpufreq_governor cpufreq_gov_userspace = { +static struct cpufreq_governor cpufreq_gov_userspace = { .name ="userspace" , .governor = cpufreq_governor_userspace, .store_setspeed = cpufreq_set,@@ -116,6 +113,11 @@ MODULE_DESCRIPTION("CPUfreq policy goverMODULE_LICENSE ("GPL" );#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE +struct cpufreq_governor *cpufreq_default_governor (void ) +{ +return &cpufreq_gov_userspace; +} +fs_initcall (cpufreq_gov_userspace_init);#else module_init (cpufreq_gov_userspace_init); --
Quoted 4 lines
To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Ah, that's so much more cleaner!
Signature · 3 lines
Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [PATCH 1/11] cpufreq: Clean up default and fallback governor setup
In reply to Rafael J. WysockiQuoted 8 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
The preprocessor magic used for setting the default cpufreq governor (and for using the performance governor as a fallback one for that matter) is really nasty, so replace it with
__weakfunctions and overrides.Signed-off-by Rafael J. Wysocki <[email protected]>
Quoted 9 lines
--- drivers/cpufreq/cpufreq.c | 37 ++++++++++++++++++--------------- drivers/cpufreq/cpufreq_conservative.c | 10 +++++--- drivers/cpufreq/cpufreq_ondemand.c | 34 ++++++++++++++++-------------- drivers/cpufreq/cpufreq_performance.c | 18 ++++++++++++---- drivers/cpufreq/cpufreq_powersave.c | 10 +++++--- drivers/cpufreq/cpufreq_userspace.c | 10 +++++--- include/linux/cpufreq.h | 25 +--------------------- 7 files changed, 73 insertions(+), 71 deletions(-)
Signature · 1 line
viresh
PATCH 2/11 cpufreq: governor: Use common mutex for dbs_data protection
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Every governor relying on the common code in cpufreq_governor.c has to provide its own mutex in struct common_dbs_data. However, those mutexes are never used at the same time and doing it this way makes it rather difficult to follow the code. Moreover, if two governor modules are loaded we end up with two mutexes used for the same purpose one at a time.
Introduce a single common mutex for that instead and drop the mutex field from struct common_dbs_data. That at least will ensure that the mutex is always present and initialized regardless of what the particular governors do.
--- drivers/cpufreq/cpufreq_conservative.c | 1 - drivers/cpufreq/cpufreq_governor.c | 7 +++++-- drivers/cpufreq/cpufreq_governor.h | 6 +----- drivers/cpufreq/cpufreq_ondemand.c | 5 ++--- 4 files changed, 8 insertions(+), 11 deletions(-)
drivers/cpufreq/cpufreq_governor.c +5 -2
@@ -22,6 +22,9 @@#include "cpufreq_governor.h" +DEFINE_MUTEX (dbs_data_mutex); +EXPORT_SYMBOL_GPL (dbs_data_mutex); +static struct attribute_group *get_sysfs_attr (struct dbs_data *dbs_data) {if (have_governor_per_policy ())
@@ -542,7 +545,7 @@ int cpufreq_governor_dbs(struct cpufreq_int ret;/* Lock governor to block concurrent initialization of governor */ -mutex_lock (&cdata->mutex); +mutex_lock (&dbs_data_mutex);if (have_governor_per_policy ()) dbs_data = policy->governor_data;
@@ -575,7 +578,7 @@ int cpufreq_governor_dbs(struct cpufreq_ } unlock: -mutex_unlock (&cdata->mutex); +mutex_unlock (&dbs_data_mutex);return ret; }
drivers/cpufreq/cpufreq_governor.h +1 -5
@@ -223,11 +223,6 @@ struct common_dbs_data {/* Governor specific ops, see below */ void *gov_ops; - -/* -* Protects governor's data (struct dbs_data and struct common_dbs_data) -*/ -struct mutex mutex; };/* Governor Per policy data */
@@ -272,6 +267,7 @@ static ssize_t show_sampling_rate_min_goreturn sprintf (buf,"%u\n" , dbs_data->min_sampling_rate); \ } +extern struct mutex dbs_data_mutex;extern struct mutex cpufreq_governor_lock;void gov_set_update_util (struct cpu_common_dbs_info *shared,unsigned int delay_us);
drivers/cpufreq/cpufreq_ondemand.c +2 -3
@@ -251,7 +251,7 @@ static void update_sampling_rate(struct/* * Lock governor so that governor start/stop can't execute in parallel. */ -mutex_lock (&od_dbs_cdata.mutex); +mutex_lock (&dbs_data_mutex);cpumask_copy (&cpumask, cpu_online_mask);
@@ -304,7 +304,7 @@ static void update_sampling_rate(struct } } -mutex_unlock (&od_dbs_cdata.mutex); +mutex_unlock (&dbs_data_mutex); } static ssize_t store_sampling_rate(struct dbs_data *dbs_data, const char *buf,
@@ -550,7 +550,6 @@ static struct common_dbs_data od_dbs_cda .gov_ops = &od_ops, .init = od_init, .exit = od_exit, - .mutex = __MUTEX_INITIALIZER(od_dbs_cdata.mutex), }; static int od_cpufreq_governor_dbs(struct cpufreq_policy *policy,
drivers/cpufreq/cpufreq_conservative.c +0 -1
@@ -368,7 +368,6 @@ static struct common_dbs_data cs_dbs_cda .gov_check_cpu = cs_check_cpu, .init = cs_init, .exit = cs_exit, - .mutex = __MUTEX_INITIALIZER(cs_dbs_cdata.mutex), }; static int cs_cpufreq_governor_dbs(struct cpufreq_policy *policy,
Re: [PATCH 2/11] cpufreq: governor: Use common mutex for dbs_data protection
Quoted 122 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Every governor relying on the common code in
cpufreq_governor.chas to provide its own mutex in structcommon_dbs_data. However, those mutexes are never used at the same time and doing it this way makes it rather difficult to follow the code. Moreover, if two governor modules are loaded we end up with two mutexes used for the same purpose one at a time.Introduce a single common mutex for that instead and drop the mutex field from struct
common_dbs_data. That at least will ensure that the mutex is always present and initialized regardless of what the particular governors do.Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/cpufreq/cpufreq_conservative.c | 1 - drivers/cpufreq/cpufreq_governor.c | 7 +++++-- drivers/cpufreq/cpufreq_governor.h | 6 +----- drivers/cpufreq/cpufreq_ondemand.c | 5 ++--- 4 files changed, 8 insertions(+), 11 deletions(-)Index:
linux-pm/drivers/cpufreq/cpufreq_governor.c
===================================================================drivers/cpufreq/cpufreq_governor.c +5
-2@@ -22,6 +22,9 @@#include "cpufreq_governor.h" +DEFINE_MUTEX (dbs_data_mutex); +EXPORT_SYMBOL_GPL (dbs_data_mutex); +static struct attribute_group *get_sysfs_attr (struct dbs_data *dbs_data) {if (have_governor_per_policy ())@@ -542,7 +545,7 @@ int cpufreq_governor_dbs(struct cpufreq_int ret;/* Lock governor to block concurrent initialization of governor */ -mutex_lock (&cdata->mutex); +mutex_lock (&dbs_data_mutex);if (have_governor_per_policy ()) dbs_data = policy->governor_data;@@ -575,7 +578,7 @@ int cpufreq_governor_dbs(struct cpufreq_ } unlock: -mutex_unlock (&cdata->mutex); +mutex_unlock (&dbs_data_mutex);return ret; }Index:
linux-pm/drivers/cpufreq/cpufreq_governor.h
===================================================================drivers/cpufreq/cpufreq_governor.h +1
-5@@ -223,11 +223,6 @@ struct common_dbs_data {/* Governor specific ops, see below */ void *gov_ops; - -/* -* Protects governor's data (struct dbs_data and struct common_dbs_data) -*/ -struct mutex mutex; };/* Governor Per policy data */ @@ -272,6 +267,7 @@ static ssize_t show_sampling_rate_min_goreturn sprintf (buf,"%u\n" , dbs_data->min_sampling_rate); \ } +extern struct mutex dbs_data_mutex;extern struct mutex cpufreq_governor_lock;void gov_set_update_util (struct cpu_common_dbs_info *shared,unsigned int delay_us);Index:
linux-pm/drivers/cpufreq/cpufreq_ondemand.c
===================================================================drivers/cpufreq/cpufreq_ondemand.c +2
-3@@ -251,7 +251,7 @@ static void update_sampling_rate(struct/* * Lock governor so that governor start/stop can't execute in parallel. */ -mutex_lock (&od_dbs_cdata.mutex); +mutex_lock (&dbs_data_mutex);cpumask_copy (&cpumask, cpu_online_mask);@@ -304,7 +304,7 @@ static void update_sampling_rate(struct } } -mutex_unlock (&od_dbs_cdata.mutex); +mutex_unlock (&dbs_data_mutex); } static ssize_t store_sampling_rate(struct dbs_data *dbs_data, const char *buf,@@ -550,7 +550,6 @@ static struct common_dbs_data od_dbs_cda .gov_ops = &od_ops, .init = od_init, .exit = od_exit, - .mutex = __MUTEX_INITIALIZER(od_dbs_cdata.mutex), }; static int od_cpufreq_governor_dbs(struct cpufreq_policy *policy,Index:
linux-pm/drivers/cpufreq/cpufreq_conservative.c
===================================================================drivers/cpufreq/cpufreq_conservative.c +0
-2@@ -368,7 +368,6 @@ static struct common_dbs_data cs_dbs_cda .gov_check_cpu = cs_check_cpu, .init = cs_init, .exit = cs_exit, - .mutex = __MUTEX_INITIALIZER(cs_dbs_cdata.mutex), }; static int cs_cpufreq_governor_dbs(struct cpufreq_policy *policy, --
Quoted 4 lines
To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 3 lines
Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
Viresh Kumar
maintainerRe: [PATCH 2/11] cpufreq: governor: Use common mutex for dbs_data protection
In reply to Rafael J. WysockiQuoted 5 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Every governor relying on the common code in
cpufreq_governor.chas to provide its own mutex in structcommon_dbs_data. However, those mutexes are never used at the same time
Why do you think so? I thought they can always be used in parallel.
Consider 2 or more policies, one can have ondemand as the governor, whereas other one can have conservative.
If CPUs go online/offline or if governors are switching in parallel, then cpufreq_governor_dbs() can very much run in parallel for ondemand and conservative.
Or am I missing something here ?
Signature · 1 line
viresh
Rafael J. Wysocki
maintainerRe: [PATCH 2/11] cpufreq: governor: Use common mutex for dbs_data protection
Quoted 9 lines · Viresh Kumar
Quoted 5 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Every governor relying on the common code in
cpufreq_governor.chas to provide its own mutex in structcommon_dbs_data. However, those mutexes are never used at the same timeWhy do you think so? I thought they can always be used in parallel.
Quoted 8 lines
Consider 2 or more policies, one can have ondemand as the governor, whereas other one can have conservative.
If CPUs go online/offline or if governors are switching in parallel, then
cpufreq_governor_dbs()can very much run in parallel for ondemand and conservative.Or am I missing something here ?
Well, so perhaps the changelog is inaccurate.
However, what's wrong with using a single mutex then?
Thanks,
Rafael
Viresh Kumar
maintainerRe: [PATCH 2/11] cpufreq: governor: Use common mutex for dbs_data protection
Quoted 17 lines · Rafael J. Wysocki
Quoted 16 lines · Viresh Kumar
Quoted 5 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Every governor relying on the common code in
cpufreq_governor.chas to provide its own mutex in structcommon_dbs_data. However, those mutexes are never used at the same timeWhy do you think so? I thought they can always be used in parallel.
Consider 2 or more policies, one can have ondemand as the governor, whereas other one can have conservative.
If CPUs go online/offline or if governors are switching in parallel, then
cpufreq_governor_dbs()can very much run in parallel for ondemand and conservative.
Quoted 5 lines
Quoted 1 line
Or am I missing something here ?
Well, so perhaps the changelog is inaccurate.
However, what's wrong with using a single mutex then?
You are killing the possibility of running the code faster. Consider this:
- A 16 policy system with N CPUs in every policy (IBM has something similar only :) )..
- 4 policies using ondemand, 4 using conservative, 4 using powersave and 4 with performance.
- Now if we try to change governors for all of them in parallel, only one will be done at a time and others have to wait for this BIG-kernel lock.
- Ideally the lock shouldn't have been in cdata itself, but dbs_data only. But there was a specific race because of which we were required to move it to a higher level, i.e. cdata. And so we killed the possibility of parallelism of multiple governors of same type (ofcourse only of update-sampling-rate and cpufreq_governor_dbs()..
So, it makes thing much slower..
Signature · 1 line
viresh
Rafael J. Wysocki
maintainerRe: [PATCH 2/11] cpufreq: governor: Use common mutex for dbs_data protection
Quoted 24 lines · Viresh Kumar
Quoted 17 lines · Rafael J. Wysocki
Quoted 16 lines · Viresh Kumar
Quoted 5 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Every governor relying on the common code in
cpufreq_governor.chas to provide its own mutex in structcommon_dbs_data. However, those mutexes are never used at the same timeWhy do you think so? I thought they can always be used in parallel.
Consider 2 or more policies, one can have ondemand as the governor, whereas other one can have conservative.
If CPUs go online/offline or if governors are switching in parallel, then
cpufreq_governor_dbs()can very much run in parallel for ondemand and conservative.Quoted 5 lines
Quoted 1 line
Or am I missing something here ?
Well, so perhaps the changelog is inaccurate.
However, what's wrong with using a single mutex then?
Quoted 9 lines
You are killing the possibility of running the code faster. Consider this:
- A 16 policy system with N CPUs in every policy (IBM has something similar only :) )..
- 4 policies using ondemand, 4 using conservative, 4 using powersave and 4 with performance.
- Now if we try to change governors for all of them in parallel, only one will be done at a time and others have to wait for this BIG-kernel lock.
And why is this a big problem, actually? Why do we want the switching of governors to be that efficient?
Thanks,
Rafael
Rafael J. Wysocki
maintainerRe: [PATCH 2/11] cpufreq: governor: Use common mutex for dbs_data protection
Quoted 35 lines · Rafael J. Wysocki
Quoted 24 lines · Viresh Kumar
Quoted 17 lines · Rafael J. Wysocki
Quoted 16 lines · Viresh Kumar
Quoted 5 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Every governor relying on the common code in
cpufreq_governor.chas to provide its own mutex in structcommon_dbs_data. However, those mutexes are never used at the same timeWhy do you think so? I thought they can always be used in parallel.
Consider 2 or more policies, one can have ondemand as the governor, whereas other one can have conservative.
If CPUs go online/offline or if governors are switching in parallel, then
cpufreq_governor_dbs()can very much run in parallel for ondemand and conservative.Quoted 5 lines
Quoted 1 line
Or am I missing something here ?
Well, so perhaps the changelog is inaccurate.
However, what's wrong with using a single mutex then?
Quoted 9 lines
You are killing the possibility of running the code faster. Consider this:
- A 16 policy system with N CPUs in every policy (IBM has something similar only :) )..
- 4 policies using ondemand, 4 using conservative, 4 using powersave and 4 with performance.
- Now if we try to change governors for all of them in parallel, only one will be done at a time and others have to wait for this BIG-kernel lock.
Quoted 2 lines
And why is this a big problem, actually? Why do we want the switching of governors to be that efficient?
In any case, we're talking about having one lock instead of two, mind you (out of the tree things don't count), because performance and powersave don't even use the code in question.
I'm not really sure how much of a difference that would make on a really big system.
Thanks,
Rafael
Rafael J. Wysocki
maintainerRe: [PATCH 2/11] cpufreq: governor: Use common mutex for dbs_data protection
Quoted 39 lines · Rafael J. Wysocki
Quoted 35 lines · Rafael J. Wysocki
Quoted 24 lines · Viresh Kumar
Quoted 17 lines · Rafael J. Wysocki
Quoted 16 lines · Viresh Kumar
Quoted 5 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Every governor relying on the common code in
cpufreq_governor.chas to provide its own mutex in structcommon_dbs_data. However, those mutexes are never used at the same timeWhy do you think so? I thought they can always be used in parallel.
Consider 2 or more policies, one can have ondemand as the governor, whereas other one can have conservative.
If CPUs go online/offline or if governors are switching in parallel, then
cpufreq_governor_dbs()can very much run in parallel for ondemand and conservative.Quoted 5 lines
Quoted 1 line
Or am I missing something here ?
Well, so perhaps the changelog is inaccurate.
However, what's wrong with using a single mutex then?
Quoted 9 lines
You are killing the possibility of running the code faster. Consider this:
- A 16 policy system with N CPUs in every policy (IBM has something similar only :) )..
- 4 policies using ondemand, 4 using conservative, 4 using powersave and 4 with performance.
- Now if we try to change governors for all of them in parallel, only one will be done at a time and others have to wait for this BIG-kernel lock.Quoted 2 lines
And why is this a big problem, actually? Why do we want the switching of governors to be that efficient?
Quoted 6 lines
In any case, we're talking about having one lock instead of two, mind you (out of the tree things don't count), because performance and powersave don't even use the code in question.
I'm not really sure how much of a difference that would make on a really big system.
And don't we switch governors under policy->rwsem anyway?
Thanks,
Rafael
Viresh Kumar
maintainerRe: [PATCH 2/11] cpufreq: governor: Use common mutex for dbs_data protection
Quoted 1 line · Rafael J. Wysocki
And don't we switch governors under
policy->rwsemanyway?
So ? That is blocking only a single policy only, but with the new change, we will block all policies from doing that concurrently.
Signature · 1 line
viresh
Rafael J. Wysocki
maintainerRe: [PATCH 2/11] cpufreq: governor: Use common mutex for dbs_data protection
Quoted 5 lines · Viresh Kumar
Quoted 1 line · Rafael J. Wysocki
And don't we switch governors under
policy->rwsemanyway?So ? That is blocking only a single policy only, but with the new change, we will block all policies from doing that concurrently.
No, it won't. Again: one lock instead of two. How much of a difference this makes performance-wise?
And the price is the stupid dance we need to do to even get to those locks! Come on.
Thanks,
Rafael
Viresh Kumar
maintainerRe: [PATCH 2/11] cpufreq: governor: Use common mutex for dbs_data protection
In reply to Rafael J. WysockiQuoted 2 lines · Rafael J. Wysocki
And why is this a big problem, actually? Why do we want the switching of governors to be that efficient?
I am not saying its a big problem, just that its kind of a big lock, which could have been finer.
Signature · 1 line
viresh
PATCH 3/11 cpufreq: governor: Use common global_dbs_data pointer
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
If the ondemand and conservative governors cannot use per-policy tunables (CPUFREQ_HAVE_GOVERNOR_PER_POLICY is not set in the cpufreq driver), all policy objects point to the same single dbs_data object. Additionally, that object is pointed to by a global pointer hidden in the governor's data structures.
There is no reason for that pointer to be buried in those data structures, though, so make it explicitly global.
--- drivers/cpufreq/cpufreq_governor.c | 20 ++++++++++---------- drivers/cpufreq/cpufreq_governor.h | 20 ++++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-)
drivers/cpufreq/cpufreq_governor.h +10 -10
@@ -78,7 +78,7 @@ __ATTR(_name, 0644, show_##_name##_gov_p static ssize_t show_##file_name##_gov_sys \ (struct kobject *kobj, struct attribute *attr, char *buf) \ { \ - struct _gov##_dbs_tuners *tuners = _gov##_dbs_cdata.gdbs_data->tuners; \ + struct _gov##_dbs_tuners *tuners = global_dbs_data->tuners; \ return sprintf(buf, "%u\n", tuners->file_name); \ } \ \
@@ -94,7 +94,7 @@ static ssize_t show_##file_name##_gov_po static ssize_t store_##file_name##_gov_sys \ (struct kobject *kobj, struct attribute *attr, const char *buf, size_t count) \ { \ - struct dbs_data *dbs_data = _gov##_dbs_cdata.gdbs_data; \ + struct dbs_data *dbs_data = global_dbs_data; \ return store_##file_name(dbs_data, buf, count); \ } \ \
@@ -201,19 +201,14 @@ struct cs_dbs_tuners {/* Common Governor data across policies */ struct dbs_data ;struct common_dbs_data { -/* Common across governors */ +struct cpufreq_governor gov; +#define GOV_ONDEMAND 0#define GOV_CONSERVATIVE 1int governor;struct attribute_group *attr_group_gov_sys;/* one governor - system */ struct attribute_group *attr_group_gov_pol;/* one governor - policy */ -/* -* Common data for platforms that don't set -* CPUFREQ_HAVE_GOVERNOR_PER_POLICY -*/ -struct dbs_data *gdbs_data; -struct cpu_dbs_info *(*get_cpu_cdbs)(int cpu);void *(*get_cpu_dbs_info_s)(int cpu);unsigned int (*gov_dbs_timer)(struct cpufreq_policy *policy);
@@ -233,6 +228,11 @@ struct dbs_data {void *tuners; }; +/* +* Common governor data for platforms without CPUFREQ_HAVE_GOVERNOR_PER_POLICY. +*/ +extern struct dbs_data *global_dbs_data; +/* Governor specific ops, will be passed to dbs_data->gov_ops */ struct od_ops {void (*powersave_bias_init_cpu)(int cpu);
@@ -256,7 +256,7 @@ static inline int delay_for_sampling_ratstatic ssize_t show_sampling_rate_min_gov_sys \ (struct kobject *kobj,struct attribute *attr,char *buf) \ { \ - struct dbs_data *dbs_data = _gov##_dbs_cdata.gdbs_data; \ +struct dbs_data *dbs_data = global_dbs_data; \return sprintf (buf,"%u\n" , dbs_data->min_sampling_rate); \ } \ \
drivers/cpufreq/cpufreq_governor.c +10 -10
@@ -22,6 +22,9 @@#include "cpufreq_governor.h" +struct dbs_data *global_dbs_data; +EXPORT_SYMBOL_GPL (global_dbs_data); +DEFINE_MUTEX (dbs_data_mutex);EXPORT_SYMBOL_GPL (dbs_data_mutex);
@@ -377,22 +380,19 @@ static int cpufreq_governor_init(struct latency * LATENCY_MULTIPLIER));if (!have_governor_per_policy ()) - cdata->gdbs_data = dbs_data; + global_dbs_data = dbs_data; policy->governor_data = dbs_data; ret =sysfs_create_group (get_governor_parent_kobj (policy),get_sysfs_attr (dbs_data)); -if (ret) - goto reset_gdbs_data; - -return 0 ; +if (!ret) +return 0 ; -reset_gdbs_data: policy->governor_data =NULL ; -if (!have_governor_per_policy ()) - cdata->gdbs_data =NULL ; + global_dbs_data =NULL ; + cdata->exit (dbs_data, !policy->governor->initialized); free_common_dbs_info:free_common_dbs_info (policy, cdata);
@@ -418,7 +418,7 @@ static int cpufreq_governor_exit(struct policy->governor_data =NULL ;if (!have_governor_per_policy ()) - cdata->gdbs_data =NULL ; + global_dbs_data =NULL ; cdata->exit (dbs_data, policy->governor->initialized ==1 );kfree (dbs_data);
@@ -550,7 +550,7 @@ int cpufreq_governor_dbs(struct cpufreq_if (have_governor_per_policy ()) dbs_data = policy->governor_data;else - dbs_data = cdata->gdbs_data; + dbs_data = global_dbs_data;if (!dbs_data && (event !=CPUFREQ_GOV_POLICY_INIT )) { ret = -EINVAL ;
Re: [PATCH 3/11] cpufreq: governor: Use common global_dbs_data pointer
Quoted 103 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
If the ondemand and conservative governors cannot use per-policy tunables (
CPUFREQ_HAVE_GOVERNOR_PER_POLICYis not set in the cpufreq driver), all policy objects point to the same singledbs_dataobject. Additionally, that object is pointed to by a global pointer hidden in the governor's data structures.There is no reason for that pointer to be buried in those data structures, though, so make it explicitly global.
Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/cpufreq/cpufreq_governor.c | 20 ++++++++++---------- drivers/cpufreq/cpufreq_governor.h | 20 ++++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-)Index:
linux-pm/drivers/cpufreq/cpufreq_governor.h
===================================================================drivers/cpufreq/cpufreq_governor.h +10
-10@@ -78,7 +78,7 @@ __ATTR(_name, 0644, show_##_name##_gov_p static ssize_t show_##file_name##_gov_sys \ (struct kobject *kobj, struct attribute *attr, char *buf) \ { \ - struct _gov##_dbs_tuners *tuners = _gov##_dbs_cdata.gdbs_data->tuners; \ + struct _gov##_dbs_tuners *tuners = global_dbs_data->tuners; \ return sprintf(buf, "%u\n", tuners->file_name); \ } \ \@@ -94,7 +94,7 @@ static ssize_t show_##file_name##_gov_po static ssize_t store_##file_name##_gov_sys \ (struct kobject *kobj, struct attribute *attr, const char *buf, size_t count) \ { \ - struct dbs_data *dbs_data = _gov##_dbs_cdata.gdbs_data; \ + struct dbs_data *dbs_data = global_dbs_data; \ return store_##file_name(dbs_data, buf, count); \ } \ \@@ -201,19 +201,14 @@ struct cs_dbs_tuners {/* Common Governor data across policies */ struct dbs_data ;struct common_dbs_data { -/* Common across governors */ +struct cpufreq_governor gov; +#define GOV_ONDEMAND 0#define GOV_CONSERVATIVE 1int governor;struct attribute_group *attr_group_gov_sys;/* one governor - system */ struct attribute_group *attr_group_gov_pol;/* one governor - policy */ -/* -* Common data for platforms that don't set -* CPUFREQ_HAVE_GOVERNOR_PER_POLICY -*/ -struct dbs_data *gdbs_data; -struct cpu_dbs_info *(*get_cpu_cdbs)(int cpu);void *(*get_cpu_dbs_info_s)(int cpu);unsigned int (*gov_dbs_timer)(struct cpufreq_policy *policy);@@ -233,6 +228,11 @@ struct dbs_data {void *tuners; }; +/* +* Common governor data for platforms without CPUFREQ_HAVE_GOVERNOR_PER_POLICY. +*/ +extern struct dbs_data *global_dbs_data; +/* Governor specific ops, will be passed to dbs_data->gov_ops */ struct od_ops {void (*powersave_bias_init_cpu)(int cpu);@@ -256,7 +256,7 @@ static inline int delay_for_sampling_ratstatic ssize_t show_sampling_rate_min_gov_sys \ (struct kobject *kobj,struct attribute *attr,char *buf) \ { \ - struct dbs_data *dbs_data = _gov##_dbs_cdata.gdbs_data; \ +struct dbs_data *dbs_data = global_dbs_data; \return sprintf (buf,"%u\n" , dbs_data->min_sampling_rate); \ } \ \Index:
linux-pm/drivers/cpufreq/cpufreq_governor.c
===================================================================drivers/cpufreq/cpufreq_governor.c +4
-1@@ -22,6 +22,9 @@#include "cpufreq_governor.h" +struct dbs_data *global_dbs_data; +EXPORT_SYMBOL_GPL (global_dbs_data); +DEFINE_MUTEX (dbs_data_mutex);EXPORT_SYMBOL_GPL (dbs_data_mutex);@@ -377,22 +380,19 @@ static int cpufreq_governor_init(struct latency * LATENCY_MULTIPLIER));if (!have_governor_per_policy ()) - cdata->gdbs_data = dbs_data; + global_dbs_data = dbs_data;
drivers/cpufreq/cpufreq_governor.c static int cpufreq_governor_init(struct · line 390
Quoted 10 lines
drivers/cpufreq/cpufreq_governor.c +2
-4policy->governor_data = dbs_data; ret =sysfs_create_group (get_governor_parent_kobj (policy),get_sysfs_attr (dbs_data)); -if (ret) - goto reset_gdbs_data; - -return 0 ; +if (!ret) +return 0 ;
I think the previous method of a handling the error is easier to read and more in line with the typical kernel coding style. The successful path ends in an unconditional return statement and the error paths are handled with a goto.
This also doesn't seem relevant to what the patch is trying to do. So, I'd prefer that it be left as is.
Quoted 30 lines
drivers/cpufreq/cpufreq_governor.c +4
-6-reset_gdbs_data: policy->governor_data =NULL ; -if (!have_governor_per_policy ()) - cdata->gdbs_data =NULL ; + global_dbs_data =NULL ; + cdata->exit (dbs_data, !policy->governor->initialized); free_common_dbs_info:free_common_dbs_info (policy, cdata);@@ -418,7 +418,7 @@ static int cpufreq_governor_exit(struct policy->governor_data =NULL ;if (!have_governor_per_policy ()) - cdata->gdbs_data =NULL ; + global_dbs_data =NULL ; cdata->exit (dbs_data, policy->governor->initialized ==1 );kfree (dbs_data);@@ -550,7 +550,7 @@ int cpufreq_governor_dbs(struct cpufreq_if (have_governor_per_policy ()) dbs_data = policy->governor_data;else - dbs_data = cdata->gdbs_data; + dbs_data = global_dbs_data;if (!dbs_data && (event !=CPUFREQ_GOV_POLICY_INIT )) { ret = -EINVAL ; --
Quoted 4 lines
To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
If the minor comment is addressed, this looks okay to me.
Cautiously Acked-by: Saravana Kannan <[email protected]>
-Saravana
Signature · 3 lines
Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
Rafael J. Wysocki
maintainerRe: [PATCH 3/11] cpufreq: governor: Use common global_dbs_data pointer
Quoted 112 lines · Saravana Kannan
Quoted 111 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
If the ondemand and conservative governors cannot use per-policy tunables (
CPUFREQ_HAVE_GOVERNOR_PER_POLICYis not set in the cpufreq driver), all policy objects point to the same singledbs_dataobject. Additionally, that object is pointed to by a global pointer hidden in the governor's data structures.There is no reason for that pointer to be buried in those data structures, though, so make it explicitly global.
Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/cpufreq/cpufreq_governor.c | 20 ++++++++++---------- drivers/cpufreq/cpufreq_governor.h | 20 ++++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-)Index:
linux-pm/drivers/cpufreq/cpufreq_governor.h
===================================================================drivers/cpufreq/cpufreq_governor.h +1
-1@@ -78,7 +78,7 @@ __ATTR(_name, 0644, show_##_name##_gov_p static ssize_t show_##file_name##_gov_sys \ (struct kobject *kobj, struct attribute *attr, char *buf) \ { \ - struct _gov##_dbs_tuners *tuners = _gov##_dbs_cdata.gdbs_data->tuners; \ + struct _gov##_dbs_tuners *tuners = global_dbs_data->tuners; \ return sprintf(buf, "%u\n", tuners->file_name); \ } \\drivers/cpufreq/cpufreq_governor.h +1
-1@@ -94,7 +94,7 @@ static ssize_t show_##file_name##_gov_po static ssize_t store_##file_name##_gov_sys \ (struct kobject *kobj,struct attribute *attr,const char *buf,size_t count) \ { \ - struct dbs_data *dbs_data = _gov##_dbs_cdata.gdbs_data; \ +struct dbs_data *dbs_data = global_dbs_data; \ return store_##file_name(dbs_data, buf, count); \ } \\drivers/cpufreq/cpufreq_governor.h +2
-1@@ -201,19 +201,14 @@ struct cs_dbs_tuners {/* Common Governor data across policies */ struct dbs_data ;struct common_dbs_data { -/* Common across governors */ +struct cpufreq_governor gov; +#define GOV_ONDEMAND 0#define GOV_CONSERVATIVE 1int governor;struct attribute_group *attr_group_gov_sys;/* one governor - system */
structattribute_group*attr_group_gov_pol; /* one governor -
policy */drivers/cpufreq/cpufreq_governor.h +2
-6-/* -* Common data for platforms that don't set -* CPUFREQ_HAVE_GOVERNOR_PER_POLICY -*/ -struct dbs_data *gdbs_data; -struct cpu_dbs_info *(*get_cpu_cdbs)(int cpu);void *(*get_cpu_dbs_info_s)(int cpu);unsigned int (*gov_dbs_timer)(struct cpufreq_policy *policy);@@ -233,6 +228,11 @@ struct dbs_data {void *tuners; }; +/* +* Common governor data for platforms without
CPUFREQ_HAVE_GOVERNOR_PER_POLICY.
+ */drivers/cpufreq/cpufreq_governor.h +3
-1+extern struct dbs_data *global_dbs_data; +/* Governor specific ops, will be passed to dbs_data->gov_ops */ struct od_ops {void (*powersave_bias_init_cpu)(int cpu);@@ -256,7 +256,7 @@ static inline int delay_for_sampling_ratstatic ssize_t show_sampling_rate_min_gov_sys \ (struct kobject *kobj,struct attribute *attr,char *buf) \ { \ - struct dbs_data *dbs_data = _gov##_dbs_cdata.gdbs_data; \ +struct dbs_data *dbs_data = global_dbs_data; \return sprintf (buf,"%u\n" , dbs_data->min_sampling_rate); \ } \ \Index:
linux-pm/drivers/cpufreq/cpufreq_governor.c
===================================================================drivers/cpufreq/cpufreq_governor.c +4
-1@@ -22,6 +22,9 @@#include "cpufreq_governor.h" +struct dbs_data *global_dbs_data; +EXPORT_SYMBOL_GPL (global_dbs_data); +DEFINE_MUTEX (dbs_data_mutex);EXPORT_SYMBOL_GPL (dbs_data_mutex);@@ -377,22 +380,19 @@ static int cpufreq_governor_init(struct latency * LATENCY_MULTIPLIER));if (!have_governor_per_policy ()) - cdata->gdbs_data = dbs_data; + global_dbs_data = dbs_data; policy->governor_data = dbs_data;
Quoted 14 lines
drivers/cpufreq/cpufreq_governor.c static int cpufreq_governor_init(struct · line 390
Quoted 8 lines
drivers/cpufreq/cpufreq_governor.c +2
-4ret =sysfs_create_group (get_governor_parent_kobj (policy),get_sysfs_attr (dbs_data)); -if (ret) - goto reset_gdbs_data; - -return 0 ; +if (!ret) +return 0 ;I think the previous method of a handling the error is easier to read and more in line with the typical kernel coding style. The successful path ends in an unconditional return statement and the error paths are handled with a goto.
You are talking about something like this now:
if (condition)
goto label;
return 0;label:
do stuff
I'm sorry, but I fail to see how this is easier to read than
if (!condition)
return 0;
do stuffThe return statement is not unconditional in either case, but in the first one it is just obfuscated by using the label and goto which are completely unnecessary.
Quoted 4 lines
This also doesn't seem relevant to what the patch is trying to do. So, I'd prefer that it be left as is.
This is a fair point, though. I can make that change later. :-)
Thanks,
Rafael
Re: [PATCH 3/11] cpufreq: governor: Use common global_dbs_data pointer
Quoted 140 lines · Rafael J. Wysocki
Quoted 112 lines · Saravana Kannan
Quoted 111 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
If the ondemand and conservative governors cannot use per-policy tunables (
CPUFREQ_HAVE_GOVERNOR_PER_POLICYis not set in the cpufreq driver), all policy objects point to the same singledbs_dataobject. Additionally, that object is pointed to by a global pointer hidden in the governor's data structures.There is no reason for that pointer to be buried in those data structures, though, so make it explicitly global.
Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/cpufreq/cpufreq_governor.c | 20 ++++++++++---------- drivers/cpufreq/cpufreq_governor.h | 20 ++++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-)Index:
linux-pm/drivers/cpufreq/cpufreq_governor.h
===================================================================drivers/cpufreq/cpufreq_governor.h +1
-1@@ -78,7 +78,7 @@ __ATTR(_name, 0644, show_##_name##_gov_p static ssize_t show_##file_name##_gov_sys \ (struct kobject *kobj, struct attribute *attr, char *buf) \ { \ - struct _gov##_dbs_tuners *tuners = _gov##_dbs_cdata.gdbs_data->tuners; \ + struct _gov##_dbs_tuners *tuners = global_dbs_data->tuners; \ return sprintf(buf, "%u\n", tuners->file_name); \ } \\drivers/cpufreq/cpufreq_governor.h +1
-1@@ -94,7 +94,7 @@ static ssize_t show_##file_name##_gov_po static ssize_t store_##file_name##_gov_sys \ (struct kobject *kobj,struct attribute *attr,const char *buf,size_t count) \ { \ - struct dbs_data *dbs_data = _gov##_dbs_cdata.gdbs_data; \ +struct dbs_data *dbs_data = global_dbs_data; \ return store_##file_name(dbs_data, buf, count); \ } \\drivers/cpufreq/cpufreq_governor.h +2
-1@@ -201,19 +201,14 @@ struct cs_dbs_tuners {/* Common Governor data across policies */ struct dbs_data ;struct common_dbs_data { -/* Common across governors */ +struct cpufreq_governor gov; +#define GOV_ONDEMAND 0#define GOV_CONSERVATIVE 1int governor;struct attribute_group *attr_group_gov_sys;/* one governor - system */
structattribute_group*attr_group_gov_pol; /* one governor -
policy */drivers/cpufreq/cpufreq_governor.h +2
-6-/* -* Common data for platforms that don't set -* CPUFREQ_HAVE_GOVERNOR_PER_POLICY -*/ -struct dbs_data *gdbs_data; -struct cpu_dbs_info *(*get_cpu_cdbs)(int cpu);void *(*get_cpu_dbs_info_s)(int cpu);unsigned int (*gov_dbs_timer)(struct cpufreq_policy *policy);@@ -233,6 +228,11 @@ struct dbs_data {void *tuners; }; +/* +* Common governor data for platforms without
CPUFREQ_HAVE_GOVERNOR_PER_POLICY.
+ */drivers/cpufreq/cpufreq_governor.h +3
-1+extern struct dbs_data *global_dbs_data; +/* Governor specific ops, will be passed to dbs_data->gov_ops */ struct od_ops {void (*powersave_bias_init_cpu)(int cpu);@@ -256,7 +256,7 @@ static inline int delay_for_sampling_ratstatic ssize_t show_sampling_rate_min_gov_sys \ (struct kobject *kobj,struct attribute *attr,char *buf) \ { \ - struct dbs_data *dbs_data = _gov##_dbs_cdata.gdbs_data; \ +struct dbs_data *dbs_data = global_dbs_data; \return sprintf (buf,"%u\n" , dbs_data->min_sampling_rate); \ } \ \Index:
linux-pm/drivers/cpufreq/cpufreq_governor.c
===================================================================drivers/cpufreq/cpufreq_governor.c +4
-1@@ -22,6 +22,9 @@#include "cpufreq_governor.h" +struct dbs_data *global_dbs_data; +EXPORT_SYMBOL_GPL (global_dbs_data); +DEFINE_MUTEX (dbs_data_mutex);EXPORT_SYMBOL_GPL (dbs_data_mutex);@@ -377,22 +380,19 @@ static int cpufreq_governor_init(struct latency * LATENCY_MULTIPLIER));if (!have_governor_per_policy ()) - cdata->gdbs_data = dbs_data; + global_dbs_data = dbs_data; policy->governor_data = dbs_data;Quoted 14 lines
drivers/cpufreq/cpufreq_governor.c static int cpufreq_governor_init(struct · line 390
Quoted 8 lines
drivers/cpufreq/cpufreq_governor.c +2
-4ret =sysfs_create_group (get_governor_parent_kobj (policy),get_sysfs_attr (dbs_data)); -if (ret) - goto reset_gdbs_data; - -return 0 ; +if (!ret) +return 0 ;I think the previous method of a handling the error is easier to read and more in line with the typical kernel coding style. The successful path ends in an unconditional return statement and the error paths are handled with a goto.
You are talking about something like this now:
if (condition) goto label; return 0;label:
do stuffI'm sorry, but I fail to see how this is easier to read than
Quoted 9 lines
if (!condition) return 0; do stuffThe return statement is not unconditional in either case, but in the first one it is just obfuscated by using the label and goto which are completely unnecessary.
It's more readable because someone new is quickly scanning the code to understand what's going on, once you hit an unconditional return (as in, return without any ifs around it) you can just assume the rest of the code is error handling and skip reading/mentally processing them.
That, and it's more inline with how most of the kernel handles error conditions.
Anyway, you are removing it since it's not related to the patch. So, not planning to debate this fairly subjective opinion further.
-Saravana
Signature · 3 lines
Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
Viresh Kumar
maintainerRe: [PATCH 3/11] cpufreq: governor: Use common global_dbs_data pointer
In reply to Rafael J. WysockiQuoted 10 lines · Rafael J. Wysocki
You are talking about something like this now:
if (condition) goto label; return 0;label:
do stuff
Quoted 6 lines
I'm sorry, but I fail to see how this is easier to read than
if (!condition) return 0; do stuff
I have seen few people (Like Dan Carpenter), mostly coccinelle guys, saying that we should write code like this:
if (error)
...
return success;
Though I should accept that I would have written code the way Rafael has done this time, but those people get back everytime :)
Signature · 1 line
viresh
Re: [PATCH 3/11] cpufreq: governor: Use common global_dbs_data pointer
In reply to Saravana KannanQuoted 41 lines · Saravana Kannan
Quoted 40 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
If the ondemand and conservative governors cannot use per-policy tunables (
CPUFREQ_HAVE_GOVERNOR_PER_POLICYis not set in the cpufreq driver), all policy objects point to the same singledbs_dataobject. Additionally, that object is pointed to by a global pointer hidden in the governor's data structures.There is no reason for that pointer to be buried in those data structures, though, so make it explicitly global.
Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/cpufreq/cpufreq_governor.c | 20 ++++++++++---------- drivers/cpufreq/cpufreq_governor.h | 20 ++++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-)Index:
linux-pm/drivers/cpufreq/cpufreq_governor.h
===================================================================drivers/cpufreq/cpufreq_governor.h +1
-1@@ -78,7 +78,7 @@ __ATTR(_name, 0644, show_##_name##_gov_p static ssize_t show_##file_name##_gov_sys \ (struct kobject *kobj, struct attribute *attr, char *buf) \ { \ - struct _gov##_dbs_tuners *tuners = _gov##_dbs_cdata.gdbs_data->tuners; \ + struct _gov##_dbs_tuners *tuners = global_dbs_data->tuners; \ return sprintf(buf, "%u\n", tuners->file_name); \ } \\drivers/cpufreq/cpufreq_governor.h +1
-1@@ -94,7 +94,7 @@ static ssize_t show_##file_name##_gov_po static ssize_t store_##file_name##_gov_sys \ (struct kobject *kobj,struct attribute *attr,const char *buf,size_t count) \ { \ - struct dbs_data *dbs_data = _gov##_dbs_cdata.gdbs_data; \ +struct dbs_data *dbs_data = global_dbs_data; \ return store_##file_name(dbs_data, buf, count); \ } \
Quoted 8 lines
drivers/cpufreq/cpufreq_governor.h struct cs_dbs_tuners { · line 205
Quoted 8 lines
\drivers/cpufreq/cpufreq_governor.h +2
-1@@ -201,19 +201,14 @@ struct cs_dbs_tuners {/* Common Governor data across policies */ struct dbs_data ;struct common_dbs_data { -/* Common across governors */ +struct cpufreq_governor gov; +
Actually, this line is completely unrelated to this patch. Should go on Patch 5?
Quoted 2 lines
Cautiously Acked-by: Saravana Kannan <[email protected]>
Good call on the "cautiously" I guess!
-Saravana
Signature · 3 lines
Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
Viresh Kumar
maintainerRe: [PATCH 3/11] cpufreq: governor: Use common global_dbs_data pointer
In reply to Rafael J. WysockiQuoted 18 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
If the ondemand and conservative governors cannot use per-policy tunables (
CPUFREQ_HAVE_GOVERNOR_PER_POLICYis not set in the cpufreq driver), all policy objects point to the same singledbs_dataobject. Additionally, that object is pointed to by a global pointer hidden in the governor's data structures.There is no reason for that pointer to be buried in those data structures, though, so make it explicitly global.
Signed-off-by Rafael J. Wysocki <[email protected]>Index:
linux-pm/drivers/cpufreq/cpufreq_governor.c
===================================================================
drivers/cpufreq/cpufreq_governor.c line 26
Quoted 5 lines
drivers/cpufreq/cpufreq_governor.c +2
-0@@ -22,6 +22,9 @@#include "cpufreq_governor.h" +struct dbs_data *global_dbs_data; +EXPORT_SYMBOL_GPL (global_dbs_data);
Oh man, please save me from Rafael's Rant :)
I think, this is simply wrong.
Believe me its very difficult for me to say this to you :). You are way better than me, and I am sure that I haven't understood cupfreq after so many years :)
Consider a two policy system, who is stopping us from setting ondemand for one of them and conservative for the other one ? And so, we will have two gdbs_data ..
Sorry for the noise, if I am being utterly stupid :(
Signature · 1 line
viresh
A message that is not in the archive (sent off-list or not yet received): CAHZ_5WxJSDtFyFdCc-D2=HSaPON=3rzUxpxPYsCyZvrV1Nv3qw@mail.gmail.com
Viresh Kumar
maintainerRe: [PATCH 3/11] cpufreq: governor: Use common global_dbs_data pointer
Quoted 2 lines · Gautham R Shenoy
In a a two policy system, to run ondemand on one and conservative on the other, won't the driver have
CPUFREQ_HAVE_GOVERNOR_PER_POLICYset?
No.
CPUFREQ_HAVE_GOVERNOR_PER_POLICY is not about the facility of using separate governor-type for each policy, that is always available to the user.
CPUFREQ_HAVE_GOVERNOR_PER_POLICY was initially added for platforms with different type of CPUs on the same chip, though others can benefit from it as well.
For example, on a 4 core ARM big LITTLE platform, we will have:
- 2 A7 (low performance/low power)
- 2 A15 (high performance/high power)
The A7's share a policy and A15's share another one.
Without CPUFREQ_HAVE_GOVERNOR_PER_POLICY, if ondemand is selected for both the policies, the we used to get a single directory (and a set of tunables) at /sys/devices/system/cpu/cpufreq/ondemand/ .
That used to force us to use same tunables, like sampling rate, etc for both the policies.
But because the CPUs were so different, we really wanted independent control.
So, we designed CPUFREQ_HAVE_GOVERNOR_PER_POLICY, so that in such cases, each policy will have a set of tunables for the same governor type.
Hope that makes it clear.
If the below questionnaire is still valid, please let me know :)
Quoted 18 lines
If yes, then the changes in this patch won't come into play.
Also in
cpufreq_governor.c, we setcdata->gdbs_dataonly when !have_governor_per_policy().cdata->gdbs_datais NULL otherwise. A cursory inspection doesn't show any other place in the cpufreq codebase wherecdata->gdbs_datais set. Unless I have missed one such initialization, based on my reading of the patch, instead of doing an extra hop to get the governor data viacdata->gdbs_data, we can simply record it in a global variable.Also, if your concern is regarding the use of show_##file_name##_gov_sys in case
of governor per policy, then the existing code is also broken, since we would be
accessing _gov##_dbs_cdata.gdbs_data->tuners where _gov##_dbs_cdata.gdbs_data will be NULL!.What am I missing ?
Signature · 1 line
viresh
Re: [PATCH 3/11] cpufreq: governor: Use common global_dbs_data pointer
Hello Viresh,
Quoted 27 lines · Viresh Kumar
Quoted 2 lines · Gautham R Shenoy
In a a two policy system, to run ondemand on one and conservative on the other, won't the driver have
CPUFREQ_HAVE_GOVERNOR_PER_POLICYset?No.
CPUFREQ_HAVE_GOVERNOR_PER_POLICYis not about the facility of using separate governor-type for each policy, that is always available to the user.
CPUFREQ_HAVE_GOVERNOR_PER_POLICYwas initially added for platforms with different type of CPUs on the same chip, though others can benefit from it as well.For example, on a 4 core ARM big LITTLE platform, we will have:
- 2 A7 (low performance/low power)
- 2 A15 (high performance/high power)The A7's share a policy and A15's share another one.
Without
CPUFREQ_HAVE_GOVERNOR_PER_POLICY, if ondemand is selected for both the policies, the we used to get a single directory (and a set of tunables) at/sys/devices/system/cpu/cpufreq/ondemand/.That used to force us to use same tunables, like sampling rate, etc for both the policies.
Quoted 8 lines
But because the CPUs were so different, we really wanted independent control.
So, we designed
CPUFREQ_HAVE_GOVERNOR_PER_POLICY, so that in such cases, each policy will have a set of tunables for the same governor type.Hope that makes it clear.
Yes it does! Thank you for the explanation.
So, the CPUFREQ_HAVE_GOVERNOR_PER_POLICY is really CPUFREQ_HAVE_GOVERNOR_TUNERS_PER_POLICY. Can we change the name to reflect the intent?
Quoted 2 lines
If the below questionnaire is still valid, please let me know :)
No, it is no longer valid!
Quoted 2 lines
viresh
--
Thanks and Regards
gautham.
Viresh Kumar
maintainerRe: [PATCH 3/11] cpufreq: governor: Use common global_dbs_data pointer
Quoted 5 lines · Gautham R Shenoy
Yes it does! Thank you for the explanation.
So, the
CPUFREQ_HAVE_GOVERNOR_PER_POLICYis reallyCPUFREQ_HAVE_GOVERNOR_TUNERS_PER_POLICY. Can we change the name to reflect the intent?
Hmm, we might wanna do that. Though we are quite busy (screwed up) at the moment, will do that later on :)
Signature · 1 line
viresh
Rafael J. Wysocki
maintainerRe: [PATCH 3/11] cpufreq: governor: Use common global_dbs_data pointer
In reply to Viresh KumarQuoted 29 lines · Viresh Kumar
Quoted 18 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
If the ondemand and conservative governors cannot use per-policy tunables (
CPUFREQ_HAVE_GOVERNOR_PER_POLICYis not set in the cpufreq driver), all policy objects point to the same singledbs_dataobject. Additionally, that object is pointed to by a global pointer hidden in the governor's data structures.There is no reason for that pointer to be buried in those data structures, though, so make it explicitly global.
Signed-off-by Rafael J. Wysocki <[email protected]>Index:
linux-pm/drivers/cpufreq/cpufreq_governor.c
===================================================================drivers/cpufreq/cpufreq_governor.c line 26
Quoted 5 lines
drivers/cpufreq/cpufreq_governor.c +2
-0@@ -22,6 +22,9 @@#include "cpufreq_governor.h" +struct dbs_data *global_dbs_data; +EXPORT_SYMBOL_GPL (global_dbs_data);Oh man, please save me from Rafael's Rant :)
I think, this is simply wrong.
Quoted 7 lines
Believe me its very difficult for me to say this to you :). You are way better than me, and I am sure that I haven't understood cupfreq after so many years :)
Consider a two policy system, who is stopping us from setting ondemand for one of them and conservative for the other one ? And so, we will have two
gdbs_data..
I don't really regard that as an entirely sane thing to do, but you have a point here.
Quoted 1 line
Sorry for the noise, if I am being utterly stupid :(
No, that's something I have overlooked, sorry about that.
Well, I'll need to go back to this patch or maybe drop it even.
Thanks,
Rafael
Viresh Kumar
maintainerRe: [PATCH 3/11] cpufreq: governor: Use common global_dbs_data pointer
Quoted 8 lines · Rafael J. Wysocki
Quoted 3 lines · Viresh Kumar
Consider a two policy system, who is stopping us from setting ondemand for one of them and conservative for the other one ? And so, we will have two
gdbs_data..I don't really regard that as an entirely sane thing to do, but you have a point here.
Why? Its quite useful IMO. For example on TC2, we have two clusters of A7 and A15. And we actually can configure A7 for interactive and A15 for ondemand. And this is very useful for performance/power metrics.
Signature · 1 line
viresh
Rafael J. Wysocki
maintainerRe: [PATCH 3/11] cpufreq: governor: Use common global_dbs_data pointer
Quoted 7 lines · Viresh Kumar
Quoted 6 lines · Rafael J. Wysocki
Quoted 3 lines · Viresh Kumar
Consider a two policy system, who is stopping us from setting ondemand for one of them and conservative for the other one ? And so, we will have two
gdbs_data..
Quoted 6 lines
Quoted 2 lines
I don't really regard that as an entirely sane thing to do, but you have a point here.
Why? Its quite useful IMO. For example on TC2, we have two clusters of A7 and A15. And we actually can configure A7 for interactive and A15 for ondemand. And this is very useful for performance/power metrics.
Well, doing insane things may give you better results sometimes. Depending on what you want to achieve and other factors.
Thanks,
Rafael
PATCH 4/11 cpufreq: governor: Avoid passing dbs_data pointers around unnecessarily
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Do not pass struct dbs_data pointers to the family of functions implementing governor operations in cpufreq_governor.c as they can take that pointer from policy->governor by themselves.
The cpufreq_governor_init() case is slightly more complicated, since policy->governor may be NULL when it is invoked, but then it can use global_dbs_data directly just fine.
--- drivers/cpufreq/cpufreq_governor.c | 74 +++++++++++++++---------------------- 1 file changed, 30 insertions(+), 44 deletions(-)
drivers/cpufreq/cpufreq_governor.c +30 -44
@@ -330,9 +330,9 @@ static void free_common_dbs_info(struct }static int cpufreq_governor_init (struct cpufreq_policy *policy, -struct dbs_data *dbs_data,struct common_dbs_data *cdata) { +struct dbs_data *dbs_data;unsigned int latency;int ret;
@@ -340,7 +340,7 @@ static int cpufreq_governor_init(structif (policy->governor_data)return -EBUSY ; -if (dbs_data) { +if (global_dbs_data) {if (WARN_ON (have_governor_per_policy ()))return -EINVAL ;
@@ -348,8 +348,8 @@ static int cpufreq_governor_init(structif (ret)return ret; - dbs_data->usage_count++; - policy->governor_data = dbs_data; + global_dbs_data->usage_count++; + policy->governor_data = global_dbs_data;return 0 ; }
@@ -401,9 +401,9 @@ free_dbs_data:return ret; } -static int cpufreq_governor_exit (struct cpufreq_policy *policy, -struct dbs_data *dbs_data) +static int cpufreq_governor_exit (struct cpufreq_policy *policy) { +struct dbs_data *dbs_data = policy->governor_data;struct common_dbs_data *cdata = dbs_data->cdata;struct cpu_dbs_info *cdbs = cdata->get_cpu_cdbs (policy->cpu);
@@ -430,9 +430,9 @@ static int cpufreq_governor_exit(structreturn 0 ; } -static int cpufreq_governor_start (struct cpufreq_policy *policy, -struct dbs_data *dbs_data) +static int cpufreq_governor_start (struct cpufreq_policy *policy) { +struct dbs_data *dbs_data = policy->governor_data;struct common_dbs_data *cdata = dbs_data->cdata;unsigned int sampling_rate, ignore_nice, j, cpu = policy->cpu;struct cpu_dbs_info *cdbs = cdata->get_cpu_cdbs (cpu);
@@ -498,9 +498,9 @@ static int cpufreq_governor_start(structreturn 0 ; } -static int cpufreq_governor_stop (struct cpufreq_policy *policy, -struct dbs_data *dbs_data) +static int cpufreq_governor_stop (struct cpufreq_policy *policy) { +struct dbs_data *dbs_data = policy->governor_data;struct cpu_dbs_info *cdbs = dbs_data->cdata->get_cpu_cdbs (policy->cpu);struct cpu_common_dbs_info *shared = cdbs->shared;
@@ -514,9 +514,9 @@ static int cpufreq_governor_stop(structreturn 0 ; } -static int cpufreq_governor_limits (struct cpufreq_policy *policy, -struct dbs_data *dbs_data) +static int cpufreq_governor_limits (struct cpufreq_policy *policy) { +struct dbs_data *dbs_data = policy->governor_data;struct common_dbs_data *cdata = dbs_data->cdata;unsigned int cpu = policy->cpu;struct cpu_dbs_info *cdbs = cdata->get_cpu_cdbs (cpu);
@@ -541,45 +541,31 @@ static int cpufreq_governor_limits(strucint cpufreq_governor_dbs (struct cpufreq_policy *policy,struct common_dbs_data *cdata,unsigned int event) { -struct dbs_data *dbs_data; -int ret; +int ret = -EINVAL ;/* Lock governor to block concurrent initialization of governor */ mutex_lock (&dbs_data_mutex); -if (have_governor_per_policy ()) - dbs_data = policy->governor_data; -else - dbs_data = global_dbs_data; - -if (!dbs_data && (event !=CPUFREQ_GOV_POLICY_INIT )) { - ret = -EINVAL ; - goto unlock; +if (event ==CPUFREQ_GOV_POLICY_INIT ) { + ret =cpufreq_governor_init (policy, cdata); + }else if (policy->governor_data) { +switch (event) { +case CPUFREQ_GOV_POLICY_EXIT : + ret =cpufreq_governor_exit (policy); +break ; +case CPUFREQ_GOV_START : + ret =cpufreq_governor_start (policy); +break ; +case CPUFREQ_GOV_STOP : + ret =cpufreq_governor_stop (policy); +break ; +case CPUFREQ_GOV_LIMITS : + ret =cpufreq_governor_limits (policy); +break ; + } } -switch (event) { -case CPUFREQ_GOV_POLICY_INIT : - ret =cpufreq_governor_init (policy, dbs_data, cdata); -break ; -case CPUFREQ_GOV_POLICY_EXIT : - ret =cpufreq_governor_exit (policy, dbs_data); -break ; -case CPUFREQ_GOV_START : - ret =cpufreq_governor_start (policy, dbs_data); -break ; -case CPUFREQ_GOV_STOP : - ret =cpufreq_governor_stop (policy, dbs_data); -break ; -case CPUFREQ_GOV_LIMITS : - ret =cpufreq_governor_limits (policy, dbs_data); -break ; -default : - ret = -EINVAL ; - } - -unlock:mutex_unlock (&dbs_data_mutex); -return ret; }EXPORT_SYMBOL_GPL (cpufreq_governor_dbs);
Re: [PATCH 4/11] cpufreq: governor: Avoid passing dbs_data pointers around unnecessarily
Quoted 31 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Do not pass struct
dbs_datapointers to the family of functions implementing governor operations incpufreq_governor.cas they can take that pointer frompolicy->governorby themselves.The
cpufreq_governor_init()case is slightly more complicated, sincepolicy->governormay be NULL when it is invoked, but then it can useglobal_dbs_datadirectly just fine.Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/cpufreq/cpufreq_governor.c | 74 +++++++++++++++---------------------- 1 file changed, 30 insertions(+), 44 deletions(-)Index:
linux-pm/drivers/cpufreq/cpufreq_governor.c
===================================================================drivers/cpufreq/cpufreq_governor.c +1
-1@@ -330,9 +330,9 @@ static void free_common_dbs_info(struct }static int cpufreq_governor_init (struct cpufreq_policy *policy, -struct dbs_data *dbs_data,struct common_dbs_data *cdata) { +struct dbs_data *dbs_data;unsigned int latency;int ret;
drivers/cpufreq/cpufreq_governor.c static int cpufreq_governor_init(struct · line 345
Quoted 7 lines
drivers/cpufreq/cpufreq_governor.c +1
-1@@ -340,7 +340,7 @@ static int cpufreq_governor_init(structif (policy->governor_data)return -EBUSY ; -if (dbs_data) { +if (global_dbs_data) {if (WARN_ON (have_governor_per_policy ()))return -EINVAL ;
I'm not sure if this code is functionally equivalent to what was there before.
Old: If the dbs_data is not NULL (whether it's global or not), but we have gov per policy enabled, warn and bail out.
New: If the global_dbs_data is not NULL, but we have gov per policy enabled, warn and bail out.
Both of these are bad cases, but the meaning of the code here definitely changes. My guess is that the old code was put in here to catch the "Old" case since that's more likely to happen with the crappy locking we have/had. I don't think the "New" case is even possible given the code -- we can probably prove it will never happen if we trust the compiler.
I'm not necessarily asking you to go back to the old code (I don't have a strong preference either way), but just wanted to point out the difference and let the rest of you decide.
Quoted 111 lines
drivers/cpufreq/cpufreq_governor.c +28
-33@@ -348,8 +348,8 @@ static int cpufreq_governor_init(structif (ret)return ret; - dbs_data->usage_count++; - policy->governor_data = dbs_data; + global_dbs_data->usage_count++; + policy->governor_data = global_dbs_data;return 0 ; }@@ -401,9 +401,9 @@ free_dbs_data:return ret; } -static int cpufreq_governor_exit (struct cpufreq_policy *policy, -struct dbs_data *dbs_data) +static int cpufreq_governor_exit (struct cpufreq_policy *policy) { +struct dbs_data *dbs_data = policy->governor_data;struct common_dbs_data *cdata = dbs_data->cdata;struct cpu_dbs_info *cdbs = cdata->get_cpu_cdbs (policy->cpu);@@ -430,9 +430,9 @@ static int cpufreq_governor_exit(structreturn 0 ; } -static int cpufreq_governor_start (struct cpufreq_policy *policy, -struct dbs_data *dbs_data) +static int cpufreq_governor_start (struct cpufreq_policy *policy) { +struct dbs_data *dbs_data = policy->governor_data;struct common_dbs_data *cdata = dbs_data->cdata;unsigned int sampling_rate, ignore_nice, j, cpu = policy->cpu;struct cpu_dbs_info *cdbs = cdata->get_cpu_cdbs (cpu);@@ -498,9 +498,9 @@ static int cpufreq_governor_start(structreturn 0 ; } -static int cpufreq_governor_stop (struct cpufreq_policy *policy, -struct dbs_data *dbs_data) +static int cpufreq_governor_stop (struct cpufreq_policy *policy) { +struct dbs_data *dbs_data = policy->governor_data;struct cpu_dbs_info *cdbs = dbs_data->cdata->get_cpu_cdbs (policy->cpu);struct cpu_common_dbs_info *shared = cdbs->shared;@@ -514,9 +514,9 @@ static int cpufreq_governor_stop(structreturn 0 ; } -static int cpufreq_governor_limits (struct cpufreq_policy *policy, -struct dbs_data *dbs_data) +static int cpufreq_governor_limits (struct cpufreq_policy *policy) { +struct dbs_data *dbs_data = policy->governor_data;struct common_dbs_data *cdata = dbs_data->cdata;unsigned int cpu = policy->cpu;struct cpu_dbs_info *cdbs = cdata->get_cpu_cdbs (cpu);@@ -541,45 +541,31 @@ static int cpufreq_governor_limits(strucint cpufreq_governor_dbs (struct cpufreq_policy *policy,struct common_dbs_data *cdata,unsigned int event) { -struct dbs_data *dbs_data; -int ret; +int ret = -EINVAL ;/* Lock governor to block concurrent initialization of governor */ mutex_lock (&dbs_data_mutex); -if (have_governor_per_policy ()) - dbs_data = policy->governor_data; -else - dbs_data = global_dbs_data; - -if (!dbs_data && (event !=CPUFREQ_GOV_POLICY_INIT )) { - ret = -EINVAL ; - goto unlock; +if (event ==CPUFREQ_GOV_POLICY_INIT ) { + ret =cpufreq_governor_init (policy, cdata); + }else if (policy->governor_data) { +switch (event) { +case CPUFREQ_GOV_POLICY_EXIT : + ret =cpufreq_governor_exit (policy); +break ; +case CPUFREQ_GOV_START : + ret =cpufreq_governor_start (policy); +break ; +case CPUFREQ_GOV_STOP : + ret =cpufreq_governor_stop (policy); +break ; +case CPUFREQ_GOV_LIMITS : + ret =cpufreq_governor_limits (policy); +break ; + } } -switch (event) { -case CPUFREQ_GOV_POLICY_INIT : - ret =cpufreq_governor_init (policy, dbs_data, cdata); -break ; -case CPUFREQ_GOV_POLICY_EXIT : - ret =cpufreq_governor_exit (policy, dbs_data); -break ; -case CPUFREQ_GOV_START : - ret =cpufreq_governor_start (policy, dbs_data); -break ; -case CPUFREQ_GOV_STOP : - ret =cpufreq_governor_stop (policy, dbs_data); -break ;
drivers/cpufreq/cpufreq_governor.c static int cpufreq_governor_limits(struc · line 582
Quoted 10 lines
drivers/cpufreq/cpufreq_governor.c +0
-9-case CPUFREQ_GOV_LIMITS : - ret =cpufreq_governor_limits (policy, dbs_data); -break ; -default : - ret = -EINVAL ; - } - -unlock:mutex_unlock (&dbs_data_mutex); -
Po-tay-to, Po-tah-to.
drivers/cpufreq/cpufreq_governor.c static int cpufreq_governor_limits(struc · line 571
Quoted 4 lines
drivers/cpufreq/cpufreq_governor.c +0
-0return ret; }EXPORT_SYMBOL_GPL (cpufreq_governor_dbs);
Agree with the general idea of the patch though.
Conditional on the comment above being resolve amongst the others:
-Saravana
Signature · 3 lines
Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH 5/11 cpufreq: governor: Put governor structure into common_dbs_data
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
For the ondemand and conservative governors (generally, governors that use the common code in cpufreq_governor.c), there are two static data structures representing the governor, the struct governor structure (the interface to the cpufreq core) and the struct common_dbs_data one (the interface to the cpufreq_governor.c code).
There's no fundamental reason why those two structures have to be separate. Moreover, if the struct governor one is included into struct common_dbs_data, it will be possible to reach the latter from the policy via its policy->governor pointer, so it won't be necessary to pass a separate pointer to it around. For this reason, embed struct governor in struct common_dbs_data.
--- drivers/cpufreq/cpufreq_conservative.c | 78 +++++++++++++++++---------------- drivers/cpufreq/cpufreq_ondemand.c | 26 ++++++----- 2 files changed, 56 insertions(+), 48 deletions(-)
drivers/cpufreq/cpufreq_ondemand.c +15 -11
@@ -539,7 +539,16 @@ static struct od_ops od_ops = { .freq_increase = dbs_freq_increase, }; +static int od_cpufreq_governor_dbs (struct cpufreq_policy *policy, +unsigned int event); +static struct common_dbs_data od_dbs_cdata = { + .gov = { + .name ="ondemand" , + .governor = od_cpufreq_governor_dbs, + .max_transition_latency =TRANSITION_LATENCY_LIMIT , + .owner =THIS_MODULE , + }, .governor =GOV_ONDEMAND , .attr_group_gov_sys = &od_attr_group_gov_sys, .attr_group_gov_pol = &od_attr_group_gov_pol,
@@ -552,19 +561,14 @@ static struct common_dbs_data od_dbs_cda .exit = od_exit, }; +#define CPU_FREQ_GOV_ONDEMAND (&od_dbs_cdata.gov) +static int od_cpufreq_governor_dbs (struct cpufreq_policy *policy,unsigned int event) {return cpufreq_governor_dbs (policy, &od_dbs_cdata, event); } -static struct cpufreq_governor cpufreq_gov_ondemand = { - .name ="ondemand" , - .governor = od_cpufreq_governor_dbs, - .max_transition_latency =TRANSITION_LATENCY_LIMIT , - .owner =THIS_MODULE , -}; -static void od_set_powersave_bias (unsigned int powersave_bias) {struct cpufreq_policy *policy;
@@ -590,7 +594,7 @@ static void od_set_powersave_bias(unsign policy = shared->policy;cpumask_or (&done, &done, policy->cpus); -if (policy->governor != &cpufreq_gov_ondemand) +if (policy->governor !=CPU_FREQ_GOV_ONDEMAND )continue ; dbs_data = policy->governor_data;
@@ -618,12 +622,12 @@ EXPORT_SYMBOL_GPL(od_unregister_powersavstatic int __init cpufreq_gov_dbs_init (void ) { -return cpufreq_register_governor (&cpufreq_gov_ondemand); +return cpufreq_register_governor (CPU_FREQ_GOV_ONDEMAND ); } static void __exit cpufreq_gov_dbs_exit(void) { -cpufreq_unregister_governor (&cpufreq_gov_ondemand); +cpufreq_unregister_governor (CPU_FREQ_GOV_ONDEMAND ); }MODULE_AUTHOR ("Venkatesh Pallipadi <[email protected]>" );
@@ -635,7 +639,7 @@ MODULE_LICENSE("GPL");#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND struct cpufreq_governor *cpufreq_default_governor (void ) { -return &cpufreq_gov_ondemand; +return CPU_FREQ_GOV_ONDEMAND ; }fs_initcall (cpufreq_gov_dbs_init);
drivers/cpufreq/cpufreq_conservative.c +41 -37
121 lines not on this page · raw message
Re: [PATCH 5/11] cpufreq: governor: Put governor structure into common_dbs_data
Quoted 220 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
For the ondemand and conservative governors (generally, governors that use the common code in
cpufreq_governor.c), there are two static data structures representing the governor, the struct governor structure (the interface to the cpufreq core) and the structcommon_dbs_dataone (the interface to thecpufreq_governor.ccode).There's no fundamental reason why those two structures have to be separate. Moreover, if the struct governor one is included into struct
common_dbs_data, it will be possible to reach the latter from the policy via itspolicy->governorpointer, so it won't be necessary to pass a separate pointer to it around. For this reason, embed struct governor in structcommon_dbs_data.Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/cpufreq/cpufreq_conservative.c | 78 +++++++++++++++++---------------- drivers/cpufreq/cpufreq_ondemand.c | 26 ++++++----- 2 files changed, 56 insertions(+), 48 deletions(-)Index:
linux-pm/drivers/cpufreq/cpufreq_ondemand.c
===================================================================drivers/cpufreq/cpufreq_ondemand.c +15
-11@@ -539,7 +539,16 @@ static struct od_ops od_ops = { .freq_increase = dbs_freq_increase, }; +static int od_cpufreq_governor_dbs (struct cpufreq_policy *policy, +unsigned int event); +static struct common_dbs_data od_dbs_cdata = { + .gov = { + .name ="ondemand" , + .governor = od_cpufreq_governor_dbs, + .max_transition_latency =TRANSITION_LATENCY_LIMIT , + .owner =THIS_MODULE , + }, .governor =GOV_ONDEMAND , .attr_group_gov_sys = &od_attr_group_gov_sys, .attr_group_gov_pol = &od_attr_group_gov_pol,@@ -552,19 +561,14 @@ static struct common_dbs_data od_dbs_cda .exit = od_exit, }; +#define CPU_FREQ_GOV_ONDEMAND (&od_dbs_cdata.gov) +static int od_cpufreq_governor_dbs (struct cpufreq_policy *policy,unsigned int event) {return cpufreq_governor_dbs (policy, &od_dbs_cdata, event); } -static struct cpufreq_governor cpufreq_gov_ondemand = { - .name ="ondemand" , - .governor = od_cpufreq_governor_dbs, - .max_transition_latency =TRANSITION_LATENCY_LIMIT , - .owner =THIS_MODULE , -}; -static void od_set_powersave_bias (unsigned int powersave_bias) {struct cpufreq_policy *policy;@@ -590,7 +594,7 @@ static void od_set_powersave_bias(unsign policy = shared->policy;cpumask_or (&done, &done, policy->cpus); -if (policy->governor != &cpufreq_gov_ondemand) +if (policy->governor !=CPU_FREQ_GOV_ONDEMAND )continue ; dbs_data = policy->governor_data;@@ -618,12 +622,12 @@ EXPORT_SYMBOL_GPL(od_unregister_powersavstatic int __init cpufreq_gov_dbs_init (void ) { -return cpufreq_register_governor (&cpufreq_gov_ondemand); +return cpufreq_register_governor (CPU_FREQ_GOV_ONDEMAND ); } static void __exit cpufreq_gov_dbs_exit(void) { -cpufreq_unregister_governor (&cpufreq_gov_ondemand); +cpufreq_unregister_governor (CPU_FREQ_GOV_ONDEMAND ); }MODULE_AUTHOR ("Venkatesh Pallipadi <[email protected]>" );@@ -635,7 +639,7 @@ MODULE_LICENSE("GPL");#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND struct cpufreq_governor *cpufreq_default_governor (void ) { -return &cpufreq_gov_ondemand; +return CPU_FREQ_GOV_ONDEMAND ; }fs_initcall (cpufreq_gov_dbs_init);Index:
linux-pm/drivers/cpufreq/cpufreq_conservative.c
===================================================================drivers/cpufreq/cpufreq_conservative.c +40
-36@@ -23,16 +23,6 @@ static DEFINE_PER_CPU(struct cs_cpu_dbs_info_s, cs_cpu_dbs_info); -static int cs_cpufreq_governor_dbs (struct cpufreq_policy *policy, -unsigned int event); - -static struct cpufreq_governor cpufreq_gov_conservative = { - .name ="conservative" , - .governor = cs_cpufreq_governor_dbs, - .max_transition_latency =TRANSITION_LATENCY_LIMIT , - .owner =THIS_MODULE , -}; -static inline unsigned int get_freq_target (struct cs_dbs_tuners *cs_tuners,struct cpufreq_policy *policy) {@@ -122,30 +112,7 @@ static unsigned int cs_dbs_timer(struct }static int dbs_cpufreq_notifier (struct notifier_block *nb,unsigned long val, -void *data) -{ -struct cpufreq_freqs *freq = data; -struct cs_cpu_dbs_info_s *dbs_info = - &per_cpu (cs_cpu_dbs_info, freq->cpu); -struct cpufreq_policy *policy =cpufreq_cpu_get_raw (freq->cpu); - -if (!policy) -return 0 ; - -/* policy isn't governed by conservative governor */ -if (policy->governor != &cpufreq_gov_conservative) -return 0 ; - -/* -* we only care if our internally tracked freq moves outside the 'valid' -* ranges of frequency available to us otherwise we do not change it -*/ -if (dbs_info->requested_freq > policy->max - || dbs_info->requested_freq < policy->min) - dbs_info->requested_freq = freq->new; - -return 0 ; -} +void *data);static struct notifier_block cs_cpufreq_notifier_block = { .notifier_call = dbs_cpufreq_notifier,@@ -358,7 +325,16 @@ static void cs_exit(struct dbs_data *dbsdefine_get_cpu_dbs_routines (cs_cpu_dbs_info); +static int cs_cpufreq_governor_dbs (struct cpufreq_policy *policy, +unsigned int event); +static struct common_dbs_data cs_dbs_cdata = { + .gov = { + .name ="conservative" , + .governor = cs_cpufreq_governor_dbs, + .max_transition_latency =TRANSITION_LATENCY_LIMIT , + .owner =THIS_MODULE , + }, .governor =GOV_CONSERVATIVE , .attr_group_gov_sys = &cs_attr_group_gov_sys, .attr_group_gov_pol = &cs_attr_group_gov_pol,@@ -370,20 +346,48 @@ static struct common_dbs_data cs_dbs_cda .exit = cs_exit, }; +#define CPU_FREQ_GOV_CONSERVATIVE (&cs_dbs_cdata.gov) +static int cs_cpufreq_governor_dbs (struct cpufreq_policy *policy,unsigned int event) {return cpufreq_governor_dbs (policy, &cs_dbs_cdata, event); } +static int dbs_cpufreq_notifier (struct notifier_block *nb,unsigned long val, +void *data) +{ +struct cpufreq_freqs *freq = data; +struct cs_cpu_dbs_info_s *dbs_info = + &per_cpu (cs_cpu_dbs_info, freq->cpu); +struct cpufreq_policy *policy =cpufreq_cpu_get_raw (freq->cpu); + +if (!policy) +return 0 ; + +/* policy isn't governed by conservative governor */ +if (policy->governor !=CPU_FREQ_GOV_CONSERVATIVE ) +return 0 ; + +/* +* we only care if our internally tracked freq moves outside the 'valid' +* ranges of frequency available to us otherwise we do not change it +*/ +if (dbs_info->requested_freq > policy->max + || dbs_info->requested_freq < policy->min) + dbs_info->requested_freq = freq->new; + +return 0 ; +} +static int __init cpufreq_gov_dbs_init (void ) { -return cpufreq_register_governor (&cpufreq_gov_conservative); +return cpufreq_register_governor (CPU_FREQ_GOV_CONSERVATIVE ); } static void __exit cpufreq_gov_dbs_exit(void) { -cpufreq_unregister_governor (&cpufreq_gov_conservative); +cpufreq_unregister_governor (CPU_FREQ_GOV_CONSERVATIVE ); }MODULE_AUTHOR ("Alexander Clouter <[email protected]>" );
drivers/cpufreq/cpufreq_conservative.c MODULE_LICENSE("GPL"); · line 405
Quoted 8 lines
drivers/cpufreq/cpufreq_conservative.c +1
-1@@ -395,7 +399,7 @@ MODULE_LICENSE("GPL");#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE struct cpufreq_governor *cpufreq_default_governor (void ) { -return &cpufreq_gov_conservative; +return CPU_FREQ_GOV_CONSERVATIVE ; }fs_initcall (cpufreq_gov_dbs_init);
I'm not sold on the macros/#defines for the &blah.gov, but not a strong opinion.
-Saravana
Signature · 3 lines
Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH 6/11 cpufreq: governor: Rename some data types and variables
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
The ondemand and conservative governors are represented by struct common_dbs_data whose name doesn't reflect the purpose it is used for, so rename it to struct dbs_governor and rename variables of that type accordingly.
No functional changes.
--- drivers/cpufreq/amd_freq_sensitivity.c | 2 drivers/cpufreq/cpufreq_conservative.c | 8 +-- drivers/cpufreq/cpufreq_governor.c | 82 ++++++++++++++++----------------- drivers/cpufreq/cpufreq_governor.h | 6 +- drivers/cpufreq/cpufreq_ondemand.c | 8 +-- 5 files changed, 53 insertions(+), 53 deletions(-)
drivers/cpufreq/cpufreq_conservative.c +4 -4
@@ -119,7 +119,7 @@ static struct notifier_block cs_cpufreq_ };/************************** sysfs interface ************************/ -static struct common_dbs_data cs_dbs_cdata; +static struct dbs_governor cs_dbs_gov;static ssize_t store_sampling_down_factor (struct dbs_data *dbs_data,const char *buf,size_t count)
@@ -328,7 +328,7 @@ define_get_cpu_dbs_routines(cs_cpu_dbs_istatic int cs_cpufreq_governor_dbs (struct cpufreq_policy *policy,unsigned int event); -static struct common_dbs_data cs_dbs_cdata = { +static struct dbs_governor cs_dbs_gov = { .gov = { .name ="conservative" , .governor = cs_cpufreq_governor_dbs,
@@ -346,12 +346,12 @@ static struct common_dbs_data cs_dbs_cda .exit = cs_exit, }; -#define CPU_FREQ_GOV_CONSERVATIVE (&cs_dbs_cdata.gov) +#define CPU_FREQ_GOV_CONSERVATIVE (&cs_dbs_gov.gov)static int cs_cpufreq_governor_dbs (struct cpufreq_policy *policy,unsigned int event) { -return cpufreq_governor_dbs (policy, &cs_dbs_cdata, event); +return cpufreq_governor_dbs (policy, &cs_dbs_gov, event); } static int dbs_cpufreq_notifier(struct notifier_block *nb, unsigned long val,
drivers/cpufreq/cpufreq_governor.c +41 -41
268 lines not on this page · raw message
drivers/cpufreq/cpufreq_governor.h +3 -3
@@ -200,7 +200,7 @@ struct cs_dbs_tuners {/* Common Governor data across policies */ struct dbs_data ; -struct common_dbs_data { +struct dbs_governor {struct cpufreq_governor gov;#define GOV_ONDEMAND 0
@@ -222,7 +222,7 @@ struct common_dbs_data {/* Governor Per policy data */ struct dbs_data { -struct common_dbs_data *cdata; +struct dbs_governor *gov;unsigned int min_sampling_rate;int usage_count;void *tuners;
@@ -274,7 +274,7 @@ void gov_set_update_util(struct cpu_commvoid gov_cancel_work (struct cpu_common_dbs_info *shared);void dbs_check_cpu (struct dbs_data *dbs_data,int cpu);int cpufreq_governor_dbs (struct cpufreq_policy *policy, -struct common_dbs_data *cdata,unsigned int event); +struct dbs_governor *gov,unsigned int event);void od_register_powersave_bias_handler (unsigned int (*f) (struct cpufreq_policy *,unsigned int ,unsigned int ),unsigned int powersave_bias);
drivers/cpufreq/cpufreq_ondemand.c +4 -4
@@ -223,7 +223,7 @@ static unsigned int od_dbs_timer(struct }/************************** sysfs interface ************************/ -static struct common_dbs_data od_dbs_cdata; +static struct dbs_governor od_dbs_gov;/** * update_sampling_rate - update sampling rate effective immediately if needed.
@@ -542,7 +542,7 @@ static struct od_ops od_ops = {static int od_cpufreq_governor_dbs (struct cpufreq_policy *policy,unsigned int event); -static struct common_dbs_data od_dbs_cdata = { +static struct dbs_governor od_dbs_gov = { .gov = { .name ="ondemand" , .governor = od_cpufreq_governor_dbs,
@@ -561,12 +561,12 @@ static struct common_dbs_data od_dbs_cda .exit = od_exit, }; -#define CPU_FREQ_GOV_ONDEMAND (&od_dbs_cdata.gov) +#define CPU_FREQ_GOV_ONDEMAND (&od_dbs_gov.gov)static int od_cpufreq_governor_dbs (struct cpufreq_policy *policy,unsigned int event) { -return cpufreq_governor_dbs (policy, &od_dbs_cdata, event); +return cpufreq_governor_dbs (policy, &od_dbs_gov, event); }static void od_set_powersave_bias (unsigned int powersave_bias)
drivers/cpufreq/amd_freq_sensitivity.c +1 -1
@@ -48,7 +48,7 @@ static unsigned int amd_powersave_bias_tstruct dbs_data *od_data = policy->governor_data;struct od_dbs_tuners *od_tuners = od_data->tuners;struct od_cpu_dbs_info_s *od_info = - od_data->cdata->get_cpu_dbs_info_s (policy->cpu); + od_data->gov->get_cpu_dbs_info_s (policy->cpu);if (!od_info->freq_table)return freq_next;
PATCH 7/11 cpufreq: governor: Rework cpufreq_governor_dbs()
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Since it is possible to obtain a pointer to struct dbs_governor from a pointer to the struct governor embedded in it via container_of(), the second argument of cpufreq_governor_init() is not necessary. Accordingly, cpufreq_governor_dbs() doesn't need its second argument either and the ->governor callbacks for both the ondemand and conservative governors may be set to cpufreq_governor_dbs() directly. Make that happen.
--- drivers/cpufreq/cpufreq_conservative.c | 11 +---------- drivers/cpufreq/cpufreq_governor.c | 10 +++++----- drivers/cpufreq/cpufreq_governor.h | 3 +-- drivers/cpufreq/cpufreq_ondemand.c | 11 +---------- 4 files changed, 8 insertions(+), 27 deletions(-)
drivers/cpufreq/cpufreq_conservative.c +1 -10
@@ -325,13 +325,10 @@ static void cs_exit(struct dbs_data *dbsdefine_get_cpu_dbs_routines (cs_cpu_dbs_info); -static int cs_cpufreq_governor_dbs (struct cpufreq_policy *policy, -unsigned int event); -static struct dbs_governor cs_dbs_gov = { .gov = { .name ="conservative" , - .governor = cs_cpufreq_governor_dbs, + .governor = cpufreq_governor_dbs, .max_transition_latency =TRANSITION_LATENCY_LIMIT , .owner =THIS_MODULE , },
@@ -348,12 +345,6 @@ static struct dbs_governor cs_dbs_gov =#define CPU_FREQ_GOV_CONSERVATIVE (&cs_dbs_gov.gov) -static int cs_cpufreq_governor_dbs (struct cpufreq_policy *policy, -unsigned int event) -{ -return cpufreq_governor_dbs (policy, &cs_dbs_gov, event); -} -static int dbs_cpufreq_notifier (struct notifier_block *nb,unsigned long val,void *data) {
drivers/cpufreq/cpufreq_governor.c +5 -5
@@ -329,9 +329,9 @@ static void free_common_dbs_info(structkfree (shared); } -static int cpufreq_governor_init (struct cpufreq_policy *policy, -struct dbs_governor *gov) +static int cpufreq_governor_init (struct cpufreq_policy *policy) { +struct dbs_governor *gov;struct dbs_data *dbs_data;unsigned int latency;int ret;
@@ -340,6 +340,7 @@ static int cpufreq_governor_init(structif (policy->governor_data)return -EBUSY ; + gov = container_of(policy->governor, struct dbs_governor, gov);if (global_dbs_data) {if (WARN_ON (have_governor_per_policy ()))return -EINVAL ;
@@ -538,8 +539,7 @@ static int cpufreq_governor_limits(strucreturn 0 ; } -int cpufreq_governor_dbs (struct cpufreq_policy *policy, -struct dbs_governor *gov,unsigned int event) +int cpufreq_governor_dbs (struct cpufreq_policy *policy,unsigned int event) {int ret = -EINVAL ;
@@ -547,7 +547,7 @@ int cpufreq_governor_dbs(struct cpufreq_mutex_lock (&dbs_data_mutex);if (event ==CPUFREQ_GOV_POLICY_INIT ) { - ret =cpufreq_governor_init (policy, gov); + ret =cpufreq_governor_init (policy); }else if (policy->governor_data) {switch (event) {case CPUFREQ_GOV_POLICY_EXIT :
drivers/cpufreq/cpufreq_governor.h +1 -2
@@ -273,8 +273,7 @@ void gov_set_update_util(struct cpu_comm unsigned int delay_us);void gov_cancel_work (struct cpu_common_dbs_info *shared);void dbs_check_cpu (struct dbs_data *dbs_data,int cpu); -int cpufreq_governor_dbs (struct cpufreq_policy *policy, -struct dbs_governor *gov,unsigned int event); +int cpufreq_governor_dbs (struct cpufreq_policy *policy,unsigned int event);void od_register_powersave_bias_handler (unsigned int (*f) (struct cpufreq_policy *,unsigned int ,unsigned int ),unsigned int powersave_bias);
drivers/cpufreq/cpufreq_ondemand.c +1 -10
@@ -539,13 +539,10 @@ static struct od_ops od_ops = { .freq_increase = dbs_freq_increase, }; -static int od_cpufreq_governor_dbs (struct cpufreq_policy *policy, -unsigned int event); -static struct dbs_governor od_dbs_gov = { .gov = { .name ="ondemand" , - .governor = od_cpufreq_governor_dbs, + .governor = cpufreq_governor_dbs, .max_transition_latency =TRANSITION_LATENCY_LIMIT , .owner =THIS_MODULE , },
@@ -563,12 +560,6 @@ static struct dbs_governor od_dbs_gov =#define CPU_FREQ_GOV_ONDEMAND (&od_dbs_gov.gov) -static int od_cpufreq_governor_dbs (struct cpufreq_policy *policy, -unsigned int event) -{ -return cpufreq_governor_dbs (policy, &od_dbs_gov, event); -} -static void od_set_powersave_bias (unsigned int powersave_bias) {struct cpufreq_policy *policy;
Re: [PATCH 7/11] cpufreq: governor: Rework cpufreq_governor_dbs()
Quoted 141 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Since it is possible to obtain a pointer to struct
dbs_governorfrom a pointer to the struct governor embedded in it viacontainer_of(), the second argument ofcpufreq_governor_init()is not necessary. Accordingly,cpufreq_governor_dbs()doesn't need its second argument either and the ->governor callbacks for both the ondemand and conservative governors may be set tocpufreq_governor_dbs()directly. Make that happen.Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/cpufreq/cpufreq_conservative.c | 11 +---------- drivers/cpufreq/cpufreq_governor.c | 10 +++++----- drivers/cpufreq/cpufreq_governor.h | 3 +-- drivers/cpufreq/cpufreq_ondemand.c | 11 +---------- 4 files changed, 8 insertions(+), 27 deletions(-)Index:
linux-pm/drivers/cpufreq/cpufreq_conservative.c
===================================================================drivers/cpufreq/cpufreq_conservative.c +1
-10@@ -325,13 +325,10 @@ static void cs_exit(struct dbs_data *dbsdefine_get_cpu_dbs_routines (cs_cpu_dbs_info); -static int cs_cpufreq_governor_dbs (struct cpufreq_policy *policy, -unsigned int event); -static struct dbs_governor cs_dbs_gov = { .gov = { .name ="conservative" , - .governor = cs_cpufreq_governor_dbs, + .governor = cpufreq_governor_dbs, .max_transition_latency =TRANSITION_LATENCY_LIMIT , .owner =THIS_MODULE , },@@ -348,12 +345,6 @@ static struct dbs_governor cs_dbs_gov =#define CPU_FREQ_GOV_CONSERVATIVE (&cs_dbs_gov.gov) -static int cs_cpufreq_governor_dbs (struct cpufreq_policy *policy, -unsigned int event) -{ -return cpufreq_governor_dbs (policy, &cs_dbs_gov, event); -} -static int dbs_cpufreq_notifier (struct notifier_block *nb,unsigned long val,void *data) {Index:
linux-pm/drivers/cpufreq/cpufreq_governor.c
===================================================================drivers/cpufreq/cpufreq_governor.c +5
-5@@ -329,9 +329,9 @@ static void free_common_dbs_info(structkfree (shared); } -static int cpufreq_governor_init (struct cpufreq_policy *policy, -struct dbs_governor *gov) +static int cpufreq_governor_init (struct cpufreq_policy *policy) { +struct dbs_governor *gov;struct dbs_data *dbs_data;unsigned int latency;int ret;@@ -340,6 +340,7 @@ static int cpufreq_governor_init(structif (policy->governor_data)return -EBUSY ; + gov = container_of(policy->governor, struct dbs_governor, gov);if (global_dbs_data) {if (WARN_ON (have_governor_per_policy ()))return -EINVAL ;@@ -538,8 +539,7 @@ static int cpufreq_governor_limits(strucreturn 0 ; } -int cpufreq_governor_dbs (struct cpufreq_policy *policy, -struct dbs_governor *gov,unsigned int event) +int cpufreq_governor_dbs (struct cpufreq_policy *policy,unsigned int event) {int ret = -EINVAL ;@@ -547,7 +547,7 @@ int cpufreq_governor_dbs(struct cpufreq_mutex_lock (&dbs_data_mutex);if (event ==CPUFREQ_GOV_POLICY_INIT ) { - ret =cpufreq_governor_init (policy, gov); + ret =cpufreq_governor_init (policy); }else if (policy->governor_data) {switch (event) {case CPUFREQ_GOV_POLICY_EXIT :Index:
linux-pm/drivers/cpufreq/cpufreq_governor.h
===================================================================drivers/cpufreq/cpufreq_governor.h +1
-2@@ -273,8 +273,7 @@ void gov_set_update_util(struct cpu_comm unsigned int delay_us);void gov_cancel_work (struct cpu_common_dbs_info *shared);void dbs_check_cpu (struct dbs_data *dbs_data,int cpu); -int cpufreq_governor_dbs (struct cpufreq_policy *policy, -struct dbs_governor *gov,unsigned int event); +int cpufreq_governor_dbs (struct cpufreq_policy *policy,unsigned int event);void od_register_powersave_bias_handler (unsigned int (*f) (struct cpufreq_policy *,unsigned int ,unsigned int ),unsigned int powersave_bias);Index:
linux-pm/drivers/cpufreq/cpufreq_ondemand.c
===================================================================drivers/cpufreq/cpufreq_ondemand.c +1
-11@@ -539,13 +539,10 @@ static struct od_ops od_ops = { .freq_increase = dbs_freq_increase, }; -static int od_cpufreq_governor_dbs (struct cpufreq_policy *policy, -unsigned int event); -static struct dbs_governor od_dbs_gov = { .gov = { .name ="ondemand" , - .governor = od_cpufreq_governor_dbs, + .governor = cpufreq_governor_dbs, .max_transition_latency =TRANSITION_LATENCY_LIMIT , .owner =THIS_MODULE , },@@ -563,12 +560,6 @@ static struct dbs_governor od_dbs_gov =#define CPU_FREQ_GOV_ONDEMAND (&od_dbs_gov.gov) -static int od_cpufreq_governor_dbs (struct cpufreq_policy *policy, -unsigned int event) -{ -return cpufreq_governor_dbs (policy, &od_dbs_gov, event); -} -static void od_set_powersave_bias (unsigned int powersave_bias) {struct cpufreq_policy *policy; --
Quoted 4 lines
To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Nice!
-Saravana
Signature · 3 lines
Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH 8/11 cpufreq: governor: Drop the gov pointer from struct dbs_data
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Since it is possible to obtain a pointer to struct dbs_governor from a pointer to the struct governor embedded in it with the help of container_of(), the additional gov pointer in struct dbs_data isn't really necessary.
Drop that pointer and make the code using it reach the dbs_governor object via policy->governor.
--- drivers/cpufreq/cpufreq_conservative.c | 2 - drivers/cpufreq/cpufreq_governor.c | 62 ++++++++++++++++----------------- drivers/cpufreq/cpufreq_governor.h | 8 +++- drivers/cpufreq/cpufreq_ondemand.c | 2 - 4 files changed, 39 insertions(+), 35 deletions(-)
drivers/cpufreq/cpufreq_governor.h +6 -2
@@ -220,9 +220,13 @@ struct dbs_governor {void *gov_ops; }; +static inline struct dbs_governor *dbs_governor_of (struct cpufreq_policy *policy) +{ + return container_of(policy->governor, struct dbs_governor, gov); +} +/* Governor Per policy data */ struct dbs_data { -struct dbs_governor *gov;unsigned int min_sampling_rate;int usage_count;void *tuners;
@@ -272,7 +276,7 @@ extern struct mutex cpufreq_governor_locvoid gov_set_update_util (struct cpu_common_dbs_info *shared,unsigned int delay_us);void gov_cancel_work (struct cpu_common_dbs_info *shared); -void dbs_check_cpu (struct dbs_data *dbs_data,int cpu); +void dbs_check_cpu (struct cpufreq_policy *policy,int cpu);int cpufreq_governor_dbs (struct cpufreq_policy *policy,unsigned int event); void od_register_powersave_bias_handler(unsigned int (*f) (struct cpufreq_policy *, unsigned int, unsigned int),
drivers/cpufreq/cpufreq_conservative.c +1 -1
@@ -107,7 +107,7 @@ static unsigned int cs_dbs_timer(structstruct dbs_data *dbs_data = policy->governor_data;struct cs_dbs_tuners *cs_tuners = dbs_data->tuners; -dbs_check_cpu (dbs_data, policy->cpu); +dbs_check_cpu (policy, policy->cpu);return delay_for_sampling_rate (cs_tuners->sampling_rate); }
drivers/cpufreq/cpufreq_governor.c +31 -31
197 lines not on this page · raw message
drivers/cpufreq/cpufreq_ondemand.c +1 -1
@@ -207,7 +207,7 @@ static unsigned int od_dbs_timer(struct__cpufreq_driver_target (policy, dbs_info->freq_lo,CPUFREQ_RELATION_H ); }else { -dbs_check_cpu (dbs_data, cpu); +dbs_check_cpu (policy, cpu);if (dbs_info->freq_lo) {/* Setup timer for SUB_SAMPLE */ dbs_info->sample_type =OD_SUB_SAMPLE ;
PATCH 9/11 cpufreq: governor: Rename cpu_common_dbs_info to policy_dbs_info
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
The struct cpu_common_dbs_info structure represents the per-policy part of the governor data (for the ondemand and conservative governors), but its name doesn't reflect its purpose.
Rename it to struct policy_dbs_info and rename variables related to it accordingly.
No functional changes.
--- drivers/cpufreq/cpufreq_governor.c | 106 ++++++++++++++++++------------------- drivers/cpufreq/cpufreq_governor.h | 8 +- drivers/cpufreq/cpufreq_ondemand.c | 32 +++++------ 3 files changed, 73 insertions(+), 73 deletions(-)
drivers/cpufreq/cpufreq_governor.h +4 -4
@@ -131,7 +131,7 @@ static void *get_cpu_dbs_info_s(int cpu)*/ /* Common to all CPUs of a policy */ -struct cpu_common_dbs_info { +struct policy_dbs_info {struct cpufreq_policy *policy;/* * Per policy mutex that serializes load evaluation from limit-change
@@ -160,7 +160,7 @@ struct cpu_dbs_info {unsigned int prev_load;u64 last_sample_time;struct update_util_data update_util; -struct cpu_common_dbs_info *shared; +struct policy_dbs_info *shared; };struct od_cpu_dbs_info_s {
@@ -273,9 +273,9 @@ static ssize_t show_sampling_rate_min_goextern struct mutex dbs_data_mutex;extern struct mutex cpufreq_governor_lock; -void gov_set_update_util (struct cpu_common_dbs_info *shared, +void gov_set_update_util (struct policy_dbs_info *policy_dbs,unsigned int delay_us); -void gov_cancel_work (struct cpu_common_dbs_info *shared); +void gov_cancel_work (struct policy_dbs_info *policy_dbs);void dbs_check_cpu (struct cpufreq_policy *policy,int cpu);int cpufreq_governor_dbs (struct cpufreq_policy *policy,unsigned int event); void od_register_powersave_bias_handler(unsigned int (*f)
drivers/cpufreq/cpufreq_governor.c +53 -53
264 lines not on this page · raw message
drivers/cpufreq/cpufreq_ondemand.c +16 -16
@@ -259,21 +259,21 @@ static void update_sampling_rate(structstruct cpufreq_policy *policy;struct od_cpu_dbs_info_s *dbs_info;struct cpu_dbs_info *cdbs; -struct cpu_common_dbs_info *shared; +struct policy_dbs_info *policy_dbs;ktime_t next_sampling, appointed_at; dbs_info = &per_cpu (od_cpu_dbs_info, cpu); cdbs = &dbs_info->cdbs; - shared = cdbs->shared; + policy_dbs = cdbs->shared;/* -* A valid shared and shared->policy means governor hasn't -* stopped or exited yet. +* A valid policy_dbs and policy_dbs->policy means governor +* hasn't stopped or exited yet. */ -if (!shared || !shared->policy) +if (!policy_dbs || !policy_dbs->policy)continue ; - policy = shared->policy; + policy = policy_dbs->policy;/* clear all CPUs of this policy */ cpumask_andnot (&cpumask, &cpumask, policy->cpus);
@@ -293,14 +293,14 @@ static void update_sampling_rate(struct*/ next_sampling =ktime_add_us (ktime_get (), new_rate); -mutex_lock (&shared->timer_mutex); - appointed_at =ktime_add_ns (shared->time_stamp, - shared->sample_delay_ns); -mutex_unlock (&shared->timer_mutex); +mutex_lock (&policy_dbs->timer_mutex); + appointed_at =ktime_add_ns (policy_dbs->time_stamp, + policy_dbs->sample_delay_ns); +mutex_unlock (&policy_dbs->timer_mutex);if (ktime_before (next_sampling, appointed_at)) { -gov_cancel_work (shared); -gov_set_update_util (shared, new_rate); +gov_cancel_work (policy_dbs); +gov_set_update_util (policy_dbs, new_rate); } }
@@ -573,16 +573,16 @@ static void od_set_powersave_bias(unsignget_online_cpus ();for_each_online_cpu (cpu) { -struct cpu_common_dbs_info *shared; +struct policy_dbs_info *policy_dbs;if (cpumask_test_cpu (cpu, &done))continue ; - shared =per_cpu (od_cpu_dbs_info, cpu).cdbs.shared; -if (!shared) + policy_dbs =per_cpu (od_cpu_dbs_info, cpu).cdbs.shared; +if (!policy_dbs)continue ; - policy = shared->policy; + policy = policy_dbs->policy;cpumask_or (&done, &done, policy->cpus);if (policy->governor !=CPU_FREQ_GOV_ONDEMAND )
PATCH 10/11 cpufreq: governor: Rearrange governor data structures
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
The struct policy_dbs_info objects representing per-policy governor data are not accessible directly from the corresponding policy objects. To access them, one has to get a pointer to the struct cpu_dbs_info of policy->cpu and use the "shared" field of that which isn't really straightforward.
To address that rearrange the governor data structures so the governor_data pointer in struct cpufreq_policy will point to struct policy_dbs_info and that will contain a pointer to struct dbs_data.
--- drivers/cpufreq/amd_freq_sensitivity.c | 3 drivers/cpufreq/cpufreq_conservative.c | 6 + drivers/cpufreq/cpufreq_governor.c | 116 ++++++++++++++------------------- drivers/cpufreq/cpufreq_governor.h | 27 ++++--- drivers/cpufreq/cpufreq_ondemand.c | 18 +++-- 5 files changed, 83 insertions(+), 87 deletions(-)
drivers/cpufreq/cpufreq_governor.h +15 -12
@@ -85,7 +85,8 @@ static ssize_t show_##file_name##_gov_sy static ssize_t show_##file_name##_gov_pol \ (struct cpufreq_policy *policy, char *buf) \ { \ - struct dbs_data *dbs_data = policy->governor_data; \ + struct policy_dbs_info *policy_dbs = policy->governor_data; \ + struct dbs_data *dbs_data = policy_dbs->dbs_data; \ struct _gov##_dbs_tuners *tuners = dbs_data->tuners; \ return sprintf(buf, "%u\n", tuners->file_name); \ }
@@ -101,8 +102,8 @@ static ssize_t store_##file_name##_gov_s static ssize_t store_##file_name##_gov_pol \ (struct cpufreq_policy *policy, const char *buf, size_t count) \ { \ - struct dbs_data *dbs_data = policy->governor_data; \ - return store_##file_name(dbs_data, buf, count); \ + struct policy_dbs_info *policy_dbs = policy->governor_data; \ + return store_##file_name(policy_dbs->dbs_data, buf, count); \ }#define show_store_one (_gov, file_name) \
@@ -130,6 +131,13 @@ static void *get_cpu_dbs_info_s(int cpu)* cs_*: Conservative governor */ +/* Governor demand based switching data (per-policy or global). */ +struct dbs_data { +unsigned int min_sampling_rate; +int usage_count; +void *tuners; +}; +/* Common to all CPUs of a policy */ struct policy_dbs_info {struct cpufreq_policy *policy;
@@ -144,6 +152,8 @@ struct policy_dbs_info {atomic_t skip_work;struct irq_work irq_work;struct work_struct work; +/* dbs_data may be shared between multiple policy objects */ +struct dbs_data *dbs_data; };/* Per cpu structures */
@@ -199,7 +209,6 @@ struct cs_dbs_tuners { };/* Common Governor data across policies */ -struct dbs_data ;struct dbs_governor {struct cpufreq_governor gov;
@@ -225,13 +234,6 @@ static inline struct dbs_governor *dbs_g return container_of(policy->governor, struct dbs_governor, gov); } -/* Governor Per policy data */ -struct dbs_data { -unsigned int min_sampling_rate; -int usage_count; -void *tuners; -}; -/* * Common governor data for platforms without CPUFREQ_HAVE_GOVERNOR_PER_POLICY. */
@@ -267,7 +269,8 @@ static ssize_t show_sampling_rate_min_gostatic ssize_t show_sampling_rate_min_gov_pol \ (struct cpufreq_policy *policy,char *buf) \ { \ -struct dbs_data *dbs_data = policy->governor_data; \ +struct policy_dbs_info *policy_dbs = policy->governor_data; \ +struct dbs_data *dbs_data = policy_dbs->dbs_data; \return sprintf (buf,"%u\n" , dbs_data->min_sampling_rate); \ }
drivers/cpufreq/cpufreq_governor.c +51 -65
241 lines not on this page · raw message
drivers/cpufreq/cpufreq_ondemand.c +11 -7
@@ -82,7 +82,8 @@ static unsigned int generic_powersave_biunsigned int jiffies_total, jiffies_hi, jiffies_lo;struct od_cpu_dbs_info_s *dbs_info = &per_cpu (od_cpu_dbs_info, policy->cpu); -struct dbs_data *dbs_data = policy->governor_data; +struct policy_dbs_info *policy_dbs = policy->governor_data; +struct dbs_data *dbs_data = policy_dbs->dbs_data;struct od_dbs_tuners *od_tuners = dbs_data->tuners;if (!dbs_info->freq_table) {
@@ -134,7 +135,8 @@ static void ondemand_powersave_bias_initstatic void dbs_freq_increase (struct cpufreq_policy *policy,unsigned int freq) { -struct dbs_data *dbs_data = policy->governor_data; +struct policy_dbs_info *policy_dbs = policy->governor_data; +struct dbs_data *dbs_data = policy_dbs->dbs_data;struct od_dbs_tuners *od_tuners = dbs_data->tuners;if (od_tuners->powersave_bias)
@@ -155,8 +157,9 @@ static void dbs_freq_increase(struct cpustatic void od_check_cpu (int cpu,unsigned int load) {struct od_cpu_dbs_info_s *dbs_info = &per_cpu (od_cpu_dbs_info, cpu); -struct cpufreq_policy *policy = dbs_info->cdbs.shared->policy; -struct dbs_data *dbs_data = policy->governor_data; +struct policy_dbs_info *policy_dbs = dbs_info->cdbs.shared; +struct cpufreq_policy *policy = policy_dbs->policy; +struct dbs_data *dbs_data = policy_dbs->dbs_data;struct od_dbs_tuners *od_tuners = dbs_data->tuners; dbs_info->freq_lo =0 ;
@@ -193,7 +196,8 @@ static void od_check_cpu(int cpu, unsignstatic unsigned int od_dbs_timer (struct cpufreq_policy *policy) { -struct dbs_data *dbs_data = policy->governor_data; +struct policy_dbs_info *policy_dbs = policy->governor_data; +struct dbs_data *dbs_data = policy_dbs->dbs_data;unsigned int cpu = policy->cpu;struct od_cpu_dbs_info_s *dbs_info = &per_cpu (od_cpu_dbs_info, cpu);
@@ -284,7 +288,7 @@ static void update_sampling_rate(struct* policy will be governed by dbs_data, otherwise there can be * multiple policies that are governed by the same dbs_data. */ -if (dbs_data != policy->governor_data) +if (dbs_data != policy_dbs->dbs_data)continue ;/*
@@ -588,7 +592,7 @@ static void od_set_powersave_bias(unsignif (policy->governor !=CPU_FREQ_GOV_ONDEMAND )continue ; - dbs_data = policy->governor_data; + dbs_data = policy_dbs->dbs_data; od_tuners = dbs_data->tuners; od_tuners->powersave_bias = default_powersave_bias; }
drivers/cpufreq/amd_freq_sensitivity.c +2 -1
@@ -45,7 +45,8 @@ static unsigned int amd_powersave_bias_tlong d_actual, d_reference;struct msr actual, reference;struct cpu_data_t *data = &per_cpu (cpu_data, policy->cpu); -struct dbs_data *od_data = policy->governor_data; +struct policy_dbs_info *policy_dbs = policy->governor_data; +struct dbs_data *od_data = policy_dbs->dbs_data;struct od_dbs_tuners *od_tuners = od_data->tuners;struct od_cpu_dbs_info_s *od_info = od_data->gov->get_cpu_dbs_info_s (policy->cpu);
drivers/cpufreq/cpufreq_conservative.c +4 -2
@@ -48,7 +48,8 @@ static void cs_check_cpu(int cpu, unsign {struct cs_cpu_dbs_info_s *dbs_info = &per_cpu (cs_cpu_dbs_info, cpu);struct cpufreq_policy *policy = dbs_info->cdbs.shared->policy; -struct dbs_data *dbs_data = policy->governor_data; +struct policy_dbs_info *policy_dbs = policy->governor_data; +struct dbs_data *dbs_data = policy_dbs->dbs_data;struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;/*
@@ -104,7 +105,8 @@ static void cs_check_cpu(int cpu, unsignstatic unsigned int cs_dbs_timer (struct cpufreq_policy *policy) { -struct dbs_data *dbs_data = policy->governor_data; +struct policy_dbs_info *policy_dbs = policy->governor_data; +struct dbs_data *dbs_data = policy_dbs->dbs_data;struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;dbs_check_cpu (policy, policy->cpu);
PATCH 11/11 cpufreq: governor: Drop cpu argument from dbs_check_cpu()
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Since policy->cpu is always passed as the second argument to dbs_check_cpu(), it is not really necessary to pass it, because the function can obtain that value via its first argument just fine.
--- drivers/cpufreq/cpufreq_conservative.c | 2 +- drivers/cpufreq/cpufreq_governor.c | 5 +++-- drivers/cpufreq/cpufreq_governor.h | 2 +- drivers/cpufreq/cpufreq_ondemand.c | 6 ++---- 4 files changed, 7 insertions(+), 8 deletions(-)
drivers/cpufreq/cpufreq_governor.h +1 -1
@@ -279,7 +279,7 @@ extern struct mutex cpufreq_governor_locvoid gov_set_update_util (struct policy_dbs_info *policy_dbs,unsigned int delay_us);void gov_cancel_work (struct policy_dbs_info *policy_dbs); -void dbs_check_cpu (struct cpufreq_policy *policy,int cpu); +void dbs_check_cpu (struct cpufreq_policy *policy);int cpufreq_governor_dbs (struct cpufreq_policy *policy,unsigned int event); void od_register_powersave_bias_handler(unsigned int (*f) (struct cpufreq_policy *, unsigned int, unsigned int),
drivers/cpufreq/cpufreq_ondemand.c +2 -4
@@ -198,9 +198,7 @@ static unsigned int od_dbs_timer(struct {struct policy_dbs_info *policy_dbs = policy->governor_data;struct dbs_data *dbs_data = policy_dbs->dbs_data; -unsigned int cpu = policy->cpu; -struct od_cpu_dbs_info_s *dbs_info = &per_cpu (od_cpu_dbs_info, - cpu); +struct od_cpu_dbs_info_s *dbs_info = &per_cpu (od_cpu_dbs_info, policy->cpu);struct od_dbs_tuners *od_tuners = dbs_data->tuners;int delay =0 , sample_type = dbs_info->sample_type;
@@ -211,7 +209,7 @@ static unsigned int od_dbs_timer(struct__cpufreq_driver_target (policy, dbs_info->freq_lo,CPUFREQ_RELATION_H ); }else { -dbs_check_cpu (policy, cpu); +dbs_check_cpu (policy);if (dbs_info->freq_lo) {/* Setup timer for SUB_SAMPLE */ dbs_info->sample_type =OD_SUB_SAMPLE ;
drivers/cpufreq/cpufreq_conservative.c +1 -1
@@ -109,7 +109,7 @@ static unsigned int cs_dbs_timer(structstruct dbs_data *dbs_data = policy_dbs->dbs_data;struct cs_dbs_tuners *cs_tuners = dbs_data->tuners; -dbs_check_cpu (policy, policy->cpu); +dbs_check_cpu (policy);return delay_for_sampling_rate (cs_tuners->sampling_rate); }
drivers/cpufreq/cpufreq_governor.c +3 -2
@@ -34,13 +34,14 @@ static struct attribute_group *get_sysfs gov->attr_group_gov_pol : gov->attr_group_gov_sys; } -void dbs_check_cpu (struct cpufreq_policy *policy,int cpu) +void dbs_check_cpu (struct cpufreq_policy *policy) {struct dbs_governor *gov =dbs_governor_of (policy);struct policy_dbs_info *policy_dbs = policy->governor_data;struct dbs_data *dbs_data = policy_dbs->dbs_data;struct od_dbs_tuners *od_tuners = dbs_data->tuners;struct cs_dbs_tuners *cs_tuners = dbs_data->tuners; +int cpu = policy->cpu;unsigned int sampling_rate;unsigned int max_load =0 ;unsigned int ignore_nice;
@@ -519,7 +520,7 @@ static int cpufreq_governor_limits(struc__cpufreq_driver_target (policy, policy->max,CPUFREQ_RELATION_H ); else if (policy->min > policy->cur) __cpufreq_driver_target(policy, policy->min, CPUFREQ_RELATION_L); -dbs_check_cpu (policy, policy->cpu); +dbs_check_cpu (policy );mutex_unlock (&policy_dbs->timer_mutex);return 0 ;
Viresh Kumar
maintainerQuoted 19 lines · Rafael J. Wysocki
Hi,
A few days ago I looked at the common code used by the ondemand and conservative governors because of the deadlock issue that Viresh has addressed recently
(http://marc.info/?l=linux-pm&m=145450832814058&w=4) and it occurred to me that the whole thing was really too tangled and might be made easier to follow at least. I started to work on this and ended up with the following series.I'm not really going to stop here, but first, I'd like to let everybody know that this is happening and second, I'll need to rebase these patches on the ones from Viresh (in the series linked above), but that may take some time and I don't want to sit on them for all that long.
Overall, I'd like the governor code to be cleaner and easier to follow, so we can move at least some parts of governor work to utilization update callbacks (invoked by the scheduler) or to at least to
irq_workso as to reduce the usage of process context in cpufreq to absolute minimum. That's the plan for the future, but for now this is just a major cleanup.
Quoted 3 lines
[1/11] Clean up the way in which the default and fallback governors are set up. [2/11] Use a common global mutex for
dbs_dataprotection.
[3/11] Use common global pointer todbs_datafor system-wide governors.
Hi Rafael,
I have some very basic doubts on 2nd and 3rd patch, and so have stopped reviewing after that because there is too much dependency I believe on these two.
I will review the rest, if my concerns on the earlier ones are incorrect.
Signature · 1 line
viresh
Rafael J. Wysocki
maintainerQuoted 24 lines · Viresh Kumar
Quoted 19 lines · Rafael J. Wysocki
Hi,
A few days ago I looked at the common code used by the ondemand and conservative governors because of the deadlock issue that Viresh has addressed recently
(http://marc.info/?l=linux-pm&m=145450832814058&w=4) and it occurred to me that the whole thing was really too tangled and might be made easier to follow at least. I started to work on this and ended up with the following series.I'm not really going to stop here, but first, I'd like to let everybody know that this is happening and second, I'll need to rebase these patches on the ones from Viresh (in the series linked above), but that may take some time and I don't want to sit on them for all that long.
Overall, I'd like the governor code to be cleaner and easier to follow, so we can move at least some parts of governor work to utilization update callbacks (invoked by the scheduler) or to at least to
irq_workso as to reduce the usage of process context in cpufreq to absolute minimum. That's the plan for the future, but for now this is just a major cleanup.Quoted 3 lines
[1/11] Clean up the way in which the default and fallback governors are set up. [2/11] Use a common global mutex for
dbs_dataprotection.
[3/11] Use common global pointer todbs_datafor system-wide governors.
Quoted 8 lines
Hi Rafael,
I have some very basic doubts on 2nd and 3rd patch, and so have stopped reviewing after that because there is too much dependency I believe on these two.
I will review the rest, if my concerns on the earlier ones are incorrect.
Patch [3/11] is really incorrect (thanks for pointing the problem out to me), but it also isn't essential, so I can drop it just fine I think.
I don't see issues with the [2/11], though, apart from the changelog being inaccurate which should be easy to fix.
Thanks,
Rafael
v2 cover cpufreq: governor: ondemand/conservative data structures rework
In reply to Rafael J. WysockiQuoted 31 lines · Rafael J. Wysocki
Hi,
A few days ago I looked at the common code used by the ondemand and conservative governors because of the deadlock issue that Viresh has addressed recently
(http://marc.info/?l=linux-pm&m=145450832814058&w=4) and it occurred to me that the whole thing was really too tangled and might be made easier to follow at least. I started to work on this and ended up with the following series.I'm not really going to stop here, but first, I'd like to let everybody know that this is happening and second, I'll need to rebase these patches on the ones from Viresh (in the series linked above), but that may take some time and I don't want to sit on them for all that long.
Overall, I'd like the governor code to be cleaner and easier to follow, so we can move at least some parts of governor work to utilization update callbacks (invoked by the scheduler) or to at least to
irq_workso as to reduce the usage of process context in cpufreq to absolute minimum. That's the plan for the future, but for now this is just a major cleanup.[1/11] Clean up the way in which the default and fallback governors are set up. [2/11] Use a common global mutex for
dbs_dataprotection.
[3/11] Use common global pointer todbs_datafor system-wide governors. [4/11] Avoid passingdbs_datapointers to functions that can get them by themselves. [5/11] Make struct governor be a member of structcommon_dbs_data.
[6/11] Rename structcommon_dbs_datato structdbs_governor.
[7/11] Reworkcpufreq_governor_dbs()so it can be used as a governor callback directly. [8/11] Drop thedbs_governor(former cdata) pointer from structdbs_data. [9/11] Rename structcpu_common_dbs_infoto structpolicy_dbs_info.
[10/11] Rearrange data structures sopolicy->governor_datapoints to structpolicy_dbs_info. [11/11] Drop the second argument ofdbs_check_cpu().
Quoted 3 lines
The patches are on top of 4.5-rc2 with my earlier series replacing timers with utilization update callbacks (http://marc.info/?l=linux-kernel&m=145410842801883&w=4)
applied.
Some bugs fixed, some comments addressed. It's time for a v2. :-)
The most significant difference from the previous one is that I've dropped patch [3/11] (so there are 10 of them in the series now) due to a problem with it pointed out by Viresh. Fortunately, this particular one was completely not essential and the dependencies on it were rather cosmetic.
In addition to that I've rebased the series on top of
https://patchwork.kernel.org/patch/8229901/ as that differs from its previous version quite a bit.
I've already queued up [1/10] for 4.6 as it seems totally uncontroversial.
The whole series (along with some patches it depends on) is available from the git branch at
git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git pm-cpufreq-rjw
in case someone wants to try it. I've tested it (very lightly) on an x86 laptop with the ACPI cpufreq driver and the ondemand governor.
Thanks,
Rafael
PATCH v2 1/10 cpufreq: Clean up default and fallback governor setup
From: Rafael J. Wysocki <[email protected]>
The preprocessor magic used for setting the default cpufreq governor (and for using the performance governor as a fallback one for that matter) is really nasty, so replace it with __weak functions and overrides.
--- drivers/cpufreq/cpufreq.c | 37 ++++++++++++++++++--------------- drivers/cpufreq/cpufreq_conservative.c | 10 +++++--- drivers/cpufreq/cpufreq_ondemand.c | 36 ++++++++++++++++---------------- drivers/cpufreq/cpufreq_performance.c | 18 ++++++++++++---- drivers/cpufreq/cpufreq_powersave.c | 10 +++++--- drivers/cpufreq/cpufreq_userspace.c | 10 +++++--- include/linux/cpufreq.h | 25 +--------------------- 7 files changed, 73 insertions(+), 73 deletions(-)
drivers/cpufreq/cpufreq.c +21 -16
@@ -1003,6 +1003,11 @@ static int cpufreq_add_dev_interface(strreturn cpufreq_add_dev_symlink (policy); } +__weak struct cpufreq_governor *cpufreq_default_governor (void ) +{ +return NULL ; +} +static int cpufreq_init_policy (struct cpufreq_policy *policy) {struct cpufreq_governor *gov =NULL ;
@@ -1012,11 +1017,14 @@ static int cpufreq_init_policy(struct cp/* Update governor of new_policy to the governor used before hotplug */ gov =find_governor (policy->last_governor); -if (gov) +if (gov) {pr_debug ("Restoring governor %s for cpu %d\n" , policy->governor->name, policy->cpu); -else - gov =CPUFREQ_DEFAULT_GOVERNOR ; + }else { + gov =cpufreq_default_governor (); +if (!gov) +return -ENODATA ; + } new_policy.governor = gov;
@@ -1964,21 +1972,16 @@ int cpufreq_driver_target(struct cpufreq }EXPORT_SYMBOL_GPL (cpufreq_driver_target); +__weak struct cpufreq_governor *cpufreq_fallback_governor (void ) +{ +return NULL ; +} +static int __cpufreq_governor (struct cpufreq_policy *policy,unsigned int event) {int ret; -/* Only must be defined when default governor is known to have latency -restrictions, like e.g. conservative or ondemand. -That this is the case is already ensured in Kconfig -*/ -#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE -struct cpufreq_governor *gov = &cpufreq_gov_performance; -#else -struct cpufreq_governor *gov =NULL ; -#endif -/* Don't start any governor operations if we are entering suspend */ if (cpufreq_suspended)return 0 ;
@@ -1992,12 +1995,14 @@ static int __cpufreq_governor(struct cpuif (policy->governor->max_transition_latency && policy->cpuinfo.transition_latency > policy->governor->max_transition_latency) { -if (!gov) -return -EINVAL ; -else { +struct cpufreq_governor *gov =cpufreq_fallback_governor (); + +if (gov) {pr_warn ("%s governor failed, too long transition latency of HW, fallback to %s governor\n" , policy->governor->name, gov->name); policy->governor = gov; + }else { +return -EINVAL ; } }
drivers/cpufreq/cpufreq_conservative.c +6 -4
@@ -26,10 +26,7 @@ static DEFINE_PER_CPU(struct cs_cpu_dbs_static int cs_cpufreq_governor_dbs (struct cpufreq_policy *policy,unsigned int event); -#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE -static -#endif -struct cpufreq_governor cpufreq_gov_conservative = { +static struct cpufreq_governor cpufreq_gov_conservative = { .name ="conservative" , .governor = cs_cpufreq_governor_dbs, .max_transition_latency =TRANSITION_LATENCY_LIMIT ,
@@ -397,6 +394,11 @@ MODULE_DESCRIPTION("'cpufreq_conservativMODULE_LICENSE ("GPL" );#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE +struct cpufreq_governor *cpufreq_default_governor (void ) +{ +return &cpufreq_gov_conservative; +} +fs_initcall (cpufreq_gov_dbs_init);#else module_init (cpufreq_gov_dbs_init);
include/linux/cpufreq.h +2 -23
@@ -471,29 +471,8 @@ int __cpufreq_driver_target(struct cpufrint cpufreq_register_governor (struct cpufreq_governor *governor);void cpufreq_unregister_governor (struct cpufreq_governor *governor); -/* CPUFREQ DEFAULT GOVERNOR */ -/* -* Performance governor is fallback governor if any other gov failed to auto -* load due latency restrictions -*/ -#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE -extern struct cpufreq_governor cpufreq_gov_performance; -#endif -#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE -#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_performance) -#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE ) -extern struct cpufreq_governor cpufreq_gov_powersave; -#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_powersave) -#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE ) -extern struct cpufreq_governor cpufreq_gov_userspace; -#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_userspace) -#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND ) -extern struct cpufreq_governor cpufreq_gov_ondemand; -#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_ondemand) -#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE ) -extern struct cpufreq_governor cpufreq_gov_conservative; -#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_conservative) -#endif +struct cpufreq_governor *cpufreq_default_governor (void ); +struct cpufreq_governor *cpufreq_fallback_governor (void );/********************************************************************* * FREQUENCY TABLE HELPERS *
drivers/cpufreq/cpufreq_ondemand.c +18 -18
@@ -31,9 +31,7 @@ static DEFINE_PER_CPU(struct od_cpu_dbs_static struct od_ops od_ops; -#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND static struct cpufreq_governor cpufreq_gov_ondemand; -#endif static unsigned int default_powersave_bias;
@@ -553,6 +551,19 @@ static struct common_dbs_data od_dbs_cda .mutex = __MUTEX_INITIALIZER(od_dbs_cdata.mutex), }; +static int od_cpufreq_governor_dbs (struct cpufreq_policy *policy, +unsigned int event) +{ +return cpufreq_governor_dbs (policy, &od_dbs_cdata, event); +} + +static struct cpufreq_governor cpufreq_gov_ondemand = { + .name ="ondemand" , + .governor = od_cpufreq_governor_dbs, + .max_transition_latency =TRANSITION_LATENCY_LIMIT , + .owner =THIS_MODULE , +}; +static void od_set_powersave_bias (unsigned int powersave_bias) {struct cpufreq_policy *policy;
@@ -604,22 +615,6 @@ void od_unregister_powersave_bias_handle }EXPORT_SYMBOL_GPL (od_unregister_powersave_bias_handler); -static int od_cpufreq_governor_dbs (struct cpufreq_policy *policy, -unsigned int event) -{ -return cpufreq_governor_dbs (policy, &od_dbs_cdata, event); -} - -#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND -static -#endif -struct cpufreq_governor cpufreq_gov_ondemand = { - .name ="ondemand" , - .governor = od_cpufreq_governor_dbs, - .max_transition_latency =TRANSITION_LATENCY_LIMIT , - .owner =THIS_MODULE , -}; -static int __init cpufreq_gov_dbs_init (void ) {return cpufreq_register_governor (&cpufreq_gov_ondemand);
@@ -637,6 +632,11 @@ MODULE_DESCRIPTION("'cpufreq_ondemand' -MODULE_LICENSE ("GPL" );#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND +struct cpufreq_governor *cpufreq_default_governor (void ) +{ +return &cpufreq_gov_ondemand; +} +fs_initcall (cpufreq_gov_dbs_init);#else module_init (cpufreq_gov_dbs_init);
drivers/cpufreq/cpufreq_performance.c +14 -4
@@ -33,10 +33,7 @@ static int cpufreq_governor_performance(return 0 ; } -#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE_MODULE -static -#endif -struct cpufreq_governor cpufreq_gov_performance = { +static struct cpufreq_governor cpufreq_gov_performance = { .name ="performance" , .governor = cpufreq_governor_performance, .owner =THIS_MODULE ,
@@ -52,6 +49,19 @@ static void __exit cpufreq_gov_performancpufreq_unregister_governor (&cpufreq_gov_performance); } +#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE +struct cpufreq_governor *cpufreq_default_governor (void ) +{ +return &cpufreq_gov_performance; +} +#endif +#ifndef CONFIG_CPU_FREQ_GOV_PERFORMANCE_MODULE +struct cpufreq_governor *cpufreq_fallback_governor (void ) +{ +return &cpufreq_gov_performance; +} +#endif +MODULE_AUTHOR ("Dominik Brodowski <[email protected]>" );MODULE_DESCRIPTION ("CPUfreq policy governor 'performance'" );MODULE_LICENSE ("GPL" );
drivers/cpufreq/cpufreq_powersave.c +6 -4
@@ -33,10 +33,7 @@ static int cpufreq_governor_powersave(streturn 0 ; } -#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE -static -#endif -struct cpufreq_governor cpufreq_gov_powersave = { +static struct cpufreq_governor cpufreq_gov_powersave = { .name ="powersave" , .governor = cpufreq_governor_powersave, .owner =THIS_MODULE ,
@@ -57,6 +54,11 @@ MODULE_DESCRIPTION("CPUfreq policy goverMODULE_LICENSE ("GPL" );#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE +struct cpufreq_governor *cpufreq_default_governor (void ) +{ +return &cpufreq_gov_powersave; +} +fs_initcall (cpufreq_gov_powersave_init);#else module_init (cpufreq_gov_powersave_init);
drivers/cpufreq/cpufreq_userspace.c +6 -4
@@ -89,10 +89,7 @@ static int cpufreq_governor_userspace(streturn rc; } -#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE -static -#endif -struct cpufreq_governor cpufreq_gov_userspace = { +static struct cpufreq_governor cpufreq_gov_userspace = { .name ="userspace" , .governor = cpufreq_governor_userspace, .store_setspeed = cpufreq_set,
@@ -116,6 +113,11 @@ MODULE_DESCRIPTION("CPUfreq policy goverMODULE_LICENSE ("GPL" );#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE +struct cpufreq_governor *cpufreq_default_governor (void ) +{ +return &cpufreq_gov_userspace; +} +fs_initcall (cpufreq_gov_userspace_init);#else module_init (cpufreq_gov_userspace_init);
Re: [PATCH v2 1/10] cpufreq: Clean up default and fallback governor setup
Hello Rafael,
On Fri, Feb 05, 2016 at 03:11:54AM +0100, Rafael J. Wysocki wrote:
[..snip..]
Quoted 17 lines
Index:
linux-pm/drivers/cpufreq/cpufreq_performance.c
===================================================================drivers/cpufreq/cpufreq_performance.c +1
-4@@ -33,10 +33,7 @@ static int cpufreq_governor_performance(return 0 ; } -#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE_MODULE -static -#endif -struct cpufreq_governor cpufreq_gov_performance = { +static struct cpufreq_governor cpufreq_gov_performance = { .name ="performance" , .governor = cpufreq_governor_performance, .owner =THIS_MODULE ,
drivers/cpufreq/cpufreq_performance.c static void __exit cpufreq_gov_performan · line 58
Quoted 10 lines
drivers/cpufreq/cpufreq_performance.c +7
-0@@ -52,6 +49,19 @@ static void __exit cpufreq_gov_performancpufreq_unregister_governor (&cpufreq_gov_performance); } +#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE +struct cpufreq_governor *cpufreq_default_governor (void ) +{ +return &cpufreq_gov_performance; +} +#endif +#ifndef CONFIG_CPU_FREQ_GOV_PERFORMANCE_MODULE
Shouldn't this be #ifdef ?
drivers/cpufreq/cpufreq_performance.c static void __exit cpufreq_gov_performan · line 63
Quoted 5 lines
drivers/cpufreq/cpufreq_performance.c +5
-0+struct cpufreq_governor *cpufreq_fallback_governor (void ) +{ +return &cpufreq_gov_performance; +} +#endif
--
Thanks and Regards
gautham.
Re: [PATCH v2 1/10] cpufreq: Clean up default and fallback governor setup
Quoted 24 lines · Gautham R Shenoy
Hello Rafael,
On Fri, Feb 05, 2016 at 03:11:54AM +0100, Rafael J. Wysocki wrote:
[..snip..]Quoted 20 lines
Index:
linux-pm/drivers/cpufreq/cpufreq_performance.c
===================================================================drivers/cpufreq/cpufreq_performance.c +1
-4@@ -33,10 +33,7 @@ static int cpufreq_governor_performance(return 0 ; } -#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE_MODULE -static -#endif -struct cpufreq_governor cpufreq_gov_performance = { +static struct cpufreq_governor cpufreq_gov_performance = { .name ="performance" , .governor = cpufreq_governor_performance, .owner =THIS_MODULE ,@@ -52,6 +49,19 @@ static void __exit cpufreq_gov_performancpufreq_unregister_governor (&cpufreq_gov_performance); }
Quoted 9 lines
drivers/cpufreq/cpufreq_performance.c static void __exit cpufreq_gov_performan · line 58
Quoted 7 lines
drivers/cpufreq/cpufreq_performance.c +7
-0+#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE +struct cpufreq_governor *cpufreq_default_governor (void ) +{ +return &cpufreq_gov_performance; +} +#endif +#ifndef CONFIG_CPU_FREQ_GOV_PERFORMANCE_MODULE Shouldn't this be #ifdef ?
Never mind! Shouldn't be reviewing patches first thing in the morning!
PATCH v2 2/10 cpufreq: governor: Use common mutex for dbs_data protection
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Every governor relying on the common code in cpufreq_governor.c has to provide its own mutex in struct common_dbs_data. However, there actually is no need to have a separate mutex per governor for this purpose, they may be using the same global mutex just fine. Accordingly, introduce a single common mutex for that and drop the mutex field from struct common_dbs_data.
That at least will ensure that the mutex is always present and initialized regardless of what the particular governors do.
Another benefit is that the common code does not need a pointer to a governor-related structure to get to the mutex which sometimes helps.
Finally, it makes the code generally easier to follow.
--- drivers/cpufreq/cpufreq_conservative.c | 1 - drivers/cpufreq/cpufreq_governor.c | 7 +++++-- drivers/cpufreq/cpufreq_governor.h | 6 +----- drivers/cpufreq/cpufreq_ondemand.c | 5 ++--- 4 files changed, 8 insertions(+), 11 deletions(-)
drivers/cpufreq/cpufreq_governor.c +5 -2
@@ -22,6 +22,9 @@#include "cpufreq_governor.h" +DEFINE_MUTEX (dbs_data_mutex); +EXPORT_SYMBOL_GPL (dbs_data_mutex); +static struct attribute_group *get_sysfs_attr (struct dbs_data *dbs_data) {if (have_governor_per_policy ())
@@ -541,7 +544,7 @@ int cpufreq_governor_dbs(struct cpufreq_int ret;/* Lock governor to block concurrent initialization of governor */ -mutex_lock (&cdata->mutex); +mutex_lock (&dbs_data_mutex);if (have_governor_per_policy ()) dbs_data = policy->governor_data;
@@ -574,7 +577,7 @@ int cpufreq_governor_dbs(struct cpufreq_ } unlock: -mutex_unlock (&cdata->mutex); +mutex_unlock (&dbs_data_mutex);return ret; }
drivers/cpufreq/cpufreq_governor.h +1 -5
@@ -225,11 +225,6 @@ struct common_dbs_data {/* Governor specific ops, see below */ void *gov_ops; - -/* -* Protects governor's data (struct dbs_data and struct common_dbs_data) -*/ -struct mutex mutex; };/* Governor Per policy data */
@@ -274,6 +269,7 @@ static ssize_t show_sampling_rate_min_goreturn sprintf (buf,"%u\n" , dbs_data->min_sampling_rate); \ } +extern struct mutex dbs_data_mutex;extern struct mutex cpufreq_governor_lock;void gov_set_update_util (struct cpu_common_dbs_info *shared,unsigned int delay_us);
drivers/cpufreq/cpufreq_ondemand.c +2 -3
@@ -249,7 +249,7 @@ static void update_sampling_rate(struct/* * Lock governor so that governor start/stop can't execute in parallel. */ -mutex_lock (&od_dbs_cdata.mutex); +mutex_lock (&dbs_data_mutex);cpumask_copy (&cpumask, cpu_online_mask);
@@ -302,7 +302,7 @@ static void update_sampling_rate(struct } } -mutex_unlock (&od_dbs_cdata.mutex); +mutex_unlock (&dbs_data_mutex); } static ssize_t store_sampling_rate(struct dbs_data *dbs_data, const char *buf,
@@ -548,7 +548,6 @@ static struct common_dbs_data od_dbs_cda .gov_ops = &od_ops, .init = od_init, .exit = od_exit, - .mutex = __MUTEX_INITIALIZER(od_dbs_cdata.mutex), }; static int od_cpufreq_governor_dbs(struct cpufreq_policy *policy,
drivers/cpufreq/cpufreq_conservative.c +0 -1
@@ -368,7 +368,6 @@ static struct common_dbs_data cs_dbs_cda .gov_check_cpu = cs_check_cpu, .init = cs_init, .exit = cs_exit, - .mutex = __MUTEX_INITIALIZER(cs_dbs_cdata.mutex), }; static int cs_cpufreq_governor_dbs(struct cpufreq_policy *policy,
Re: [PATCH v2 2/10] cpufreq: governor: Use common mutex for dbs_data protection
Quoted 12 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Every governor relying on the common code in
cpufreq_governor.chas to provide its own mutex in structcommon_dbs_data. However, there actually is no need to have a separate mutex per governor for this purpose, they may be using the same global mutex just fine. Accordingly, introduce a single common mutex for that and drop the mutex field from structcommon_dbs_data.That at least will ensure that the mutex is always present and initialized regardless of what the particular governors do.
Quoted 8 lines
Another benefit is that the common code does not need a pointer to a governor-related structure to get to the mutex which sometimes helps.
Finally, it makes the code generally easier to follow.
Signed-off-by Rafael J. Wysocki <[email protected]>Acked-by Saravana Kannan <[email protected]>
Signature · 1 line
viresh
Re: [PATCH v2 2/10] cpufreq: governor: Use common mutex for dbs_data protection
Quoted 17 lines · Viresh Kumar
Quoted 16 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Every governor relying on the common code in
cpufreq_governor.chas to provide its own mutex in structcommon_dbs_data. However, there actually is no need to have a separate mutex per governor for this purpose, they may be using the same global mutex just fine. Accordingly, introduce a single common mutex for that and drop the mutex field from structcommon_dbs_data.That at least will ensure that the mutex is always present and initialized regardless of what the particular governors do.
Another benefit is that the common code does not need a pointer to a governor-related structure to get to the mutex which sometimes helps.
Quoted 6 lines
Quoted 4 lines
Finally, it makes the code generally easier to follow.
Signed-off-by Rafael J. Wysocki <[email protected]>Acked-by Saravana Kannan <[email protected]>Acked-by Viresh Kumar <[email protected]>
Thanks!
One more observation here.
If we are able to eliminate dbs_data_mutex from update_sampling_rate(), then cpufreq_governor_dbs() becomes the only user of that lock. Further, if we can guarantee that the governor's ->governor callback will always be invoked under policy->rwsem, dbs_data_mutex becomes unnecessary and may be dropped.
Thanks,
Rafael
Viresh Kumar
maintainerRe: [PATCH v2 2/10] cpufreq: governor: Use common mutex for dbs_data protection
Quoted 7 lines · Rafael J. Wysocki
One more observation here.
If we are able to eliminate
dbs_data_mutexfromupdate_sampling_rate(), thencpufreq_governor_dbs()becomes the only user of that lock. Further, if we can guarantee that the governor's ->governor callback will always be invoked underpolicy->rwsem,dbs_data_mutexbecomes unnecessary and may be dropped.
That will be guaranteed with my 7 patches, which I will rebase and send again.
But there are cases where a single dbs_data is going to be used for multiple policies and so relying on policy->rwsem isn't going to be sufficient.
But, yeah, we should be able to narrow down the locked area I believe.
Signature · 1 line
viresh
Re: [PATCH v2 2/10] cpufreq: governor: Use common mutex for dbs_data protection
Quoted 9 lines · Viresh Kumar
Quoted 7 lines · Rafael J. Wysocki
One more observation here.
If we are able to eliminate
dbs_data_mutexfromupdate_sampling_rate(), thencpufreq_governor_dbs()becomes the only user of that lock. Further, if we can guarantee that the governor's ->governor callback will always be invoked underpolicy->rwsem,dbs_data_mutexbecomes unnecessary and may be dropped.
Quoted 6 lines
That will be guaranteed with my 7 patches, which I will rebase and send again.
But there are cases where a single
dbs_datais going to be used for multiple policies and so relying onpolicy->rwsemisn't going to be sufficient.But, yeah, we should be able to narrow down the locked area I believe.
That should only be a matter of protecting the gov->gdbs_data object and its refcount then.
Thanks,
Rafael
PATCH v2 3/10 cpufreq: governor: Avoid passing dbs_data pointers around unnecessarily
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Do not pass struct dbs_data pointers to the family of functions implementing governor operations in cpufreq_governor.c as they can take that pointer from policy->governor by themselves.
The cpufreq_governor_init() case is slightly more complicated, since policy->governor may be NULL when it is invoked, but then it can reach the pointer in question via its cdata argument just fine.
While at it, rework cpufreq_governor_dbs() to avoid a pointless policy_governor check in the CPUFREQ_GOV_POLICY_INIT case.
--- drivers/cpufreq/cpufreq_governor.c | 68 ++++++++++++++----------------------- 1 file changed, 27 insertions(+), 41 deletions(-)
drivers/cpufreq/cpufreq_governor.c +27 -41
@@ -325,9 +325,9 @@ static void free_common_dbs_info(struct }static int cpufreq_governor_init (struct cpufreq_policy *policy, -struct dbs_data *dbs_data,struct common_dbs_data *cdata) { +struct dbs_data *dbs_data = cdata->gdbs_data;unsigned int latency;int ret;
@@ -399,9 +399,9 @@ free_dbs_data:return ret; } -static int cpufreq_governor_exit (struct cpufreq_policy *policy, -struct dbs_data *dbs_data) +static int cpufreq_governor_exit (struct cpufreq_policy *policy) { +struct dbs_data *dbs_data = policy->governor_data;struct common_dbs_data *cdata = dbs_data->cdata;struct cpu_dbs_info *cdbs = cdata->get_cpu_cdbs (policy->cpu);
@@ -428,9 +428,9 @@ static int cpufreq_governor_exit(structreturn 0 ; } -static int cpufreq_governor_start (struct cpufreq_policy *policy, -struct dbs_data *dbs_data) +static int cpufreq_governor_start (struct cpufreq_policy *policy) { +struct dbs_data *dbs_data = policy->governor_data;struct common_dbs_data *cdata = dbs_data->cdata;unsigned int sampling_rate, ignore_nice, j, cpu = policy->cpu;struct cpu_dbs_info *cdbs = cdata->get_cpu_cdbs (cpu);
@@ -497,9 +497,9 @@ static int cpufreq_governor_start(structreturn 0 ; } -static int cpufreq_governor_stop (struct cpufreq_policy *policy, -struct dbs_data *dbs_data) +static int cpufreq_governor_stop (struct cpufreq_policy *policy) { +struct dbs_data *dbs_data = policy->governor_data;struct cpu_dbs_info *cdbs = dbs_data->cdata->get_cpu_cdbs (policy->cpu);struct cpu_common_dbs_info *shared = cdbs->shared;
@@ -513,9 +513,9 @@ static int cpufreq_governor_stop(structreturn 0 ; } -static int cpufreq_governor_limits (struct cpufreq_policy *policy, -struct dbs_data *dbs_data) +static int cpufreq_governor_limits (struct cpufreq_policy *policy) { +struct dbs_data *dbs_data = policy->governor_data;struct common_dbs_data *cdata = dbs_data->cdata;unsigned int cpu = policy->cpu;struct cpu_dbs_info *cdbs = cdata->get_cpu_cdbs (cpu);
@@ -540,45 +540,31 @@ static int cpufreq_governor_limits(strucint cpufreq_governor_dbs (struct cpufreq_policy *policy,struct common_dbs_data *cdata,unsigned int event) { -struct dbs_data *dbs_data; -int ret; +int ret = -EINVAL ;/* Lock governor to block concurrent initialization of governor */ mutex_lock (&dbs_data_mutex); -if (have_governor_per_policy ()) - dbs_data = policy->governor_data; -else - dbs_data = cdata->gdbs_data; - -if (!dbs_data && (event !=CPUFREQ_GOV_POLICY_INIT )) { - ret = -EINVAL ; - goto unlock; - } - -switch (event) { -case CPUFREQ_GOV_POLICY_INIT : - ret =cpufreq_governor_init (policy, dbs_data, cdata); -break ; -case CPUFREQ_GOV_POLICY_EXIT : - ret =cpufreq_governor_exit (policy, dbs_data); -break ; -case CPUFREQ_GOV_START : - ret =cpufreq_governor_start (policy, dbs_data); -break ; -case CPUFREQ_GOV_STOP : - ret =cpufreq_governor_stop (policy, dbs_data); -break ; -case CPUFREQ_GOV_LIMITS : - ret =cpufreq_governor_limits (policy, dbs_data); -break ; -default : - ret = -EINVAL ; +if (event ==CPUFREQ_GOV_POLICY_INIT ) { + ret =cpufreq_governor_init (policy, cdata); + }else if (policy->governor_data) { +switch (event) { +case CPUFREQ_GOV_POLICY_EXIT : + ret =cpufreq_governor_exit (policy); +break ; +case CPUFREQ_GOV_START : + ret =cpufreq_governor_start (policy); +break ; +case CPUFREQ_GOV_STOP : + ret =cpufreq_governor_stop (policy); +break ; +case CPUFREQ_GOV_LIMITS : + ret =cpufreq_governor_limits (policy); +break ; + } } -unlock:mutex_unlock (&dbs_data_mutex); -return ret; }EXPORT_SYMBOL_GPL (cpufreq_governor_dbs);
Re: [PATCH v2 3/10] cpufreq: governor: Avoid passing dbs_data pointers around unnecessarily
Quoted 10 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Do not pass struct
dbs_datapointers to the family of functions implementing governor operations incpufreq_governor.cas they can take that pointer frompolicy->governorby themselves.The
cpufreq_governor_init()case is slightly more complicated, sincepolicy->governormay be NULL when it is invoked, but then it can reach the pointer in question via its cdata argument just fine.
Quoted 7 lines
While at it, rework
cpufreq_governor_dbs()to avoid a pointlesspolicy_governorcheck in theCPUFREQ_GOV_POLICY_INITcase.Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/cpufreq/cpufreq_governor.c | 68 ++++++++++++++----------------------- 1 file changed, 27 insertions(+), 41 deletions(-)
Took some time to review, but it looks nice cleanup :)
Signature · 1 line
viresh
PATCH v2 4/10 cpufreq: governor: Put governor structure into common_dbs_data
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
For the ondemand and conservative governors (generally, governors that use the common code in cpufreq_governor.c), there are two static data structures representing the governor, the struct governor structure (the interface to the cpufreq core) and the struct common_dbs_data one (the interface to the cpufreq_governor.c code).
There's no fundamental reason why those two structures have to be separate. Moreover, if the struct governor one is included into struct common_dbs_data, it will be possible to reach the latter from the policy via its policy->governor pointer, so it won't be necessary to pass a separate pointer to it around. For this reason, embed struct governor in struct common_dbs_data.
--- drivers/cpufreq/cpufreq_conservative.c | 78 +++++++++++++++++---------------- drivers/cpufreq/cpufreq_governor.h | 3 - drivers/cpufreq/cpufreq_ondemand.c | 28 ++++++----- 3 files changed, 58 insertions(+), 51 deletions(-)
drivers/cpufreq/cpufreq_ondemand.c +15 -13
@@ -31,8 +31,6 @@ static DEFINE_PER_CPU(struct od_cpu_dbs_static struct od_ops od_ops; -static struct cpufreq_governor cpufreq_gov_ondemand; -static unsigned int default_powersave_bias;static void ondemand_powersave_bias_init_cpu (int cpu)
@@ -537,7 +535,16 @@ static struct od_ops od_ops = { .freq_increase = dbs_freq_increase, }; +static int od_cpufreq_governor_dbs (struct cpufreq_policy *policy, +unsigned int event); +static struct common_dbs_data od_dbs_cdata = { + .gov = { + .name ="ondemand" , + .governor = od_cpufreq_governor_dbs, + .max_transition_latency =TRANSITION_LATENCY_LIMIT , + .owner =THIS_MODULE , + }, .governor =GOV_ONDEMAND , .attr_group_gov_sys = &od_attr_group_gov_sys, .attr_group_gov_pol = &od_attr_group_gov_pol,
@@ -550,19 +557,14 @@ static struct common_dbs_data od_dbs_cda .exit = od_exit, }; +#define CPU_FREQ_GOV_ONDEMAND (&od_dbs_cdata.gov) +static int od_cpufreq_governor_dbs (struct cpufreq_policy *policy,unsigned int event) {return cpufreq_governor_dbs (policy, &od_dbs_cdata, event); } -static struct cpufreq_governor cpufreq_gov_ondemand = { - .name ="ondemand" , - .governor = od_cpufreq_governor_dbs, - .max_transition_latency =TRANSITION_LATENCY_LIMIT , - .owner =THIS_MODULE , -}; -static void od_set_powersave_bias (unsigned int powersave_bias) {struct cpufreq_policy *policy;
@@ -588,7 +590,7 @@ static void od_set_powersave_bias(unsign policy = shared->policy;cpumask_or (&done, &done, policy->cpus); -if (policy->governor != &cpufreq_gov_ondemand) +if (policy->governor !=CPU_FREQ_GOV_ONDEMAND )continue ; dbs_data = policy->governor_data;
@@ -616,12 +618,12 @@ EXPORT_SYMBOL_GPL(od_unregister_powersavstatic int __init cpufreq_gov_dbs_init (void ) { -return cpufreq_register_governor (&cpufreq_gov_ondemand); +return cpufreq_register_governor (CPU_FREQ_GOV_ONDEMAND ); } static void __exit cpufreq_gov_dbs_exit(void) { -cpufreq_unregister_governor (&cpufreq_gov_ondemand); +cpufreq_unregister_governor (CPU_FREQ_GOV_ONDEMAND ); }MODULE_AUTHOR ("Venkatesh Pallipadi <[email protected]>" );
@@ -633,7 +635,7 @@ MODULE_LICENSE("GPL");#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND struct cpufreq_governor *cpufreq_default_governor (void ) { -return &cpufreq_gov_ondemand; +return CPU_FREQ_GOV_ONDEMAND ; }fs_initcall (cpufreq_gov_dbs_init);
drivers/cpufreq/cpufreq_conservative.c +41 -37
121 lines not on this page · raw message
drivers/cpufreq/cpufreq_governor.h +2 -1
@@ -203,7 +203,8 @@ struct cs_dbs_tuners {/* Common Governor data across policies */ struct dbs_data ;struct common_dbs_data { -/* Common across governors */ +struct cpufreq_governor gov; +#define GOV_ONDEMAND 0#define GOV_CONSERVATIVE 1int governor;
Re: [PATCH v2 4/10] cpufreq: governor: Put governor structure into common_dbs_data
Quoted 15 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
For the ondemand and conservative governors (generally, governors that use the common code in
cpufreq_governor.c), there are two static data structures representing the governor, the struct governor structure (the interface to the cpufreq core) and the structcommon_dbs_dataone (the interface to thecpufreq_governor.ccode).There's no fundamental reason why those two structures have to be separate. Moreover, if the struct governor one is included into struct
common_dbs_data, it will be possible to reach the latter from the policy via itspolicy->governorpointer, so it won't be necessary to pass a separate pointer to it around. For this reason, embed struct governor in structcommon_dbs_data.
Quoted 2 lines
Signed-off-by Rafael J. Wysocki <[email protected]>Acked-by Saravana Kannan <[email protected]>
Signature · 1 line
viresh
PATCH v2 5/10 cpufreq: governor: Rename some data types and variables
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
The ondemand and conservative governors are represented by struct common_dbs_data whose name doesn't reflect the purpose it is used for, so rename it to struct dbs_governor and rename variables of that type accordingly.
No functional changes.
--- drivers/cpufreq/amd_freq_sensitivity.c | 2 drivers/cpufreq/cpufreq_conservative.c | 8 +-- drivers/cpufreq/cpufreq_governor.c | 88 ++++++++++++++++----------------- drivers/cpufreq/cpufreq_governor.h | 12 ++-- drivers/cpufreq/cpufreq_ondemand.c | 8 +-- 5 files changed, 59 insertions(+), 59 deletions(-)
drivers/cpufreq/cpufreq_conservative.c +4 -4
@@ -119,7 +119,7 @@ static struct notifier_block cs_cpufreq_ };/************************** sysfs interface ************************/ -static struct common_dbs_data cs_dbs_cdata; +static struct dbs_governor cs_dbs_gov;static ssize_t store_sampling_down_factor (struct dbs_data *dbs_data,const char *buf,size_t count)
@@ -328,7 +328,7 @@ define_get_cpu_dbs_routines(cs_cpu_dbs_istatic int cs_cpufreq_governor_dbs (struct cpufreq_policy *policy,unsigned int event); -static struct common_dbs_data cs_dbs_cdata = { +static struct dbs_governor cs_dbs_gov = { .gov = { .name ="conservative" , .governor = cs_cpufreq_governor_dbs,
@@ -346,12 +346,12 @@ static struct common_dbs_data cs_dbs_cda .exit = cs_exit, }; -#define CPU_FREQ_GOV_CONSERVATIVE (&cs_dbs_cdata.gov) +#define CPU_FREQ_GOV_CONSERVATIVE (&cs_dbs_gov.gov)static int cs_cpufreq_governor_dbs (struct cpufreq_policy *policy,unsigned int event) { -return cpufreq_governor_dbs (policy, &cs_dbs_cdata, event); +return cpufreq_governor_dbs (policy, &cs_dbs_gov, event); } static int dbs_cpufreq_notifier(struct notifier_block *nb, unsigned long val,
drivers/cpufreq/cpufreq_governor.c +44 -44
276 lines not on this page · raw message
drivers/cpufreq/cpufreq_governor.h +6 -6
@@ -79,7 +79,7 @@ __ATTR(_name, 0644, show_##_name##_gov_p static ssize_t show_##file_name##_gov_sys \ (struct kobject *kobj, struct attribute *attr, char *buf) \ { \ - struct _gov##_dbs_tuners *tuners = _gov##_dbs_cdata.gdbs_data->tuners; \ + struct _gov##_dbs_tuners *tuners = _gov##_dbs_gov.gdbs_data->tuners; \ return sprintf(buf, "%u\n", tuners->file_name); \ } \ \
@@ -95,7 +95,7 @@ static ssize_t show_##file_name##_gov_po static ssize_t store_##file_name##_gov_sys \ (struct kobject *kobj, struct attribute *attr, const char *buf, size_t count) \ { \ - struct dbs_data *dbs_data = _gov##_dbs_cdata.gdbs_data; \ + struct dbs_data *dbs_data = _gov##_dbs_gov.gdbs_data; \ return store_##file_name(dbs_data, buf, count); \ } \ \
@@ -202,7 +202,7 @@ struct cs_dbs_tuners {/* Common Governor data across policies */ struct dbs_data ; -struct common_dbs_data { +struct dbs_governor {struct cpufreq_governor gov;#define GOV_ONDEMAND 0
@@ -230,7 +230,7 @@ struct common_dbs_data {/* Governor Per policy data */ struct dbs_data { -struct common_dbs_data *cdata; +struct dbs_governor *gov;unsigned int min_sampling_rate;int usage_count;void *tuners;
@@ -259,7 +259,7 @@ static inline int delay_for_sampling_ratstatic ssize_t show_sampling_rate_min_gov_sys \ (struct kobject *kobj,struct attribute *attr,char *buf) \ { \ - struct dbs_data *dbs_data = _gov##_dbs_cdata.gdbs_data; \ + struct dbs_data *dbs_data = _gov##_dbs_gov.gdbs_data; \return sprintf (buf,"%u\n" , dbs_data->min_sampling_rate); \ } \ \
@@ -277,7 +277,7 @@ void gov_set_update_util(struct cpu_commvoid gov_cancel_work (struct cpu_common_dbs_info *shared);void dbs_check_cpu (struct dbs_data *dbs_data,int cpu);int cpufreq_governor_dbs (struct cpufreq_policy *policy, -struct common_dbs_data *cdata,unsigned int event); +struct dbs_governor *gov,unsigned int event);void od_register_powersave_bias_handler (unsigned int (*f) (struct cpufreq_policy *,unsigned int ,unsigned int ),unsigned int powersave_bias);
drivers/cpufreq/cpufreq_ondemand.c +4 -4
@@ -219,7 +219,7 @@ static unsigned int od_dbs_timer(struct }/************************** sysfs interface ************************/ -static struct common_dbs_data od_dbs_cdata; +static struct dbs_governor od_dbs_gov;/** * update_sampling_rate - update sampling rate effective immediately if needed.
@@ -538,7 +538,7 @@ static struct od_ops od_ops = {static int od_cpufreq_governor_dbs (struct cpufreq_policy *policy,unsigned int event); -static struct common_dbs_data od_dbs_cdata = { +static struct dbs_governor od_dbs_gov = { .gov = { .name ="ondemand" , .governor = od_cpufreq_governor_dbs,
@@ -557,12 +557,12 @@ static struct common_dbs_data od_dbs_cda .exit = od_exit, }; -#define CPU_FREQ_GOV_ONDEMAND (&od_dbs_cdata.gov) +#define CPU_FREQ_GOV_ONDEMAND (&od_dbs_gov.gov)static int od_cpufreq_governor_dbs (struct cpufreq_policy *policy,unsigned int event) { -return cpufreq_governor_dbs (policy, &od_dbs_cdata, event); +return cpufreq_governor_dbs (policy, &od_dbs_gov, event); }static void od_set_powersave_bias (unsigned int powersave_bias)
drivers/cpufreq/amd_freq_sensitivity.c +1 -1
@@ -48,7 +48,7 @@ static unsigned int amd_powersave_bias_tstruct dbs_data *od_data = policy->governor_data;struct od_dbs_tuners *od_tuners = od_data->tuners;struct od_cpu_dbs_info_s *od_info = - od_data->cdata->get_cpu_dbs_info_s (policy->cpu); + od_data->gov->get_cpu_dbs_info_s (policy->cpu);if (!od_info->freq_table)return freq_next;
Re: [PATCH v2 5/10] cpufreq: governor: Rename some data types and variables
Quoted 10 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
The ondemand and conservative governors are represented by struct
common_dbs_datawhose name doesn't reflect the purpose it is used for, so rename it to structdbs_governorand rename variables of that type accordingly.No functional changes.
Signed-off-by Rafael J. Wysocki <[email protected]>
Signature · 1 line
viresh
PATCH v2 6/10 cpufreq: governor: Rework cpufreq_governor_dbs()
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Since it is possible to obtain a pointer to struct dbs_governor from a pointer to the struct governor embedded in it via container_of(), the second argument of cpufreq_governor_init() is not necessary. Accordingly, cpufreq_governor_dbs() doesn't need its second argument either and the ->governor callbacks for both the ondemand and conservative governors may be set to cpufreq_governor_dbs() directly. Make that happen.
--- drivers/cpufreq/cpufreq_conservative.c | 11 +---------- drivers/cpufreq/cpufreq_governor.c | 10 +++++----- drivers/cpufreq/cpufreq_governor.h | 3 +-- drivers/cpufreq/cpufreq_ondemand.c | 11 +---------- 4 files changed, 8 insertions(+), 27 deletions(-)
drivers/cpufreq/cpufreq_conservative.c +1 -10
@@ -325,13 +325,10 @@ static void cs_exit(struct dbs_data *dbsdefine_get_cpu_dbs_routines (cs_cpu_dbs_info); -static int cs_cpufreq_governor_dbs (struct cpufreq_policy *policy, -unsigned int event); -static struct dbs_governor cs_dbs_gov = { .gov = { .name ="conservative" , - .governor = cs_cpufreq_governor_dbs, + .governor = cpufreq_governor_dbs, .max_transition_latency =TRANSITION_LATENCY_LIMIT , .owner =THIS_MODULE , },
@@ -348,12 +345,6 @@ static struct dbs_governor cs_dbs_gov =#define CPU_FREQ_GOV_CONSERVATIVE (&cs_dbs_gov.gov) -static int cs_cpufreq_governor_dbs (struct cpufreq_policy *policy, -unsigned int event) -{ -return cpufreq_governor_dbs (policy, &cs_dbs_gov, event); -} -static int dbs_cpufreq_notifier (struct notifier_block *nb,unsigned long val,void *data) {
drivers/cpufreq/cpufreq_governor.c +5 -5
@@ -324,9 +324,10 @@ static void free_common_dbs_info(structkfree (shared); } -static int cpufreq_governor_init (struct cpufreq_policy *policy, -struct dbs_governor *gov) +static int cpufreq_governor_init (struct cpufreq_policy *policy) { +struct dbs_governor *gov =container_of (policy->governor, + struct dbs_governor, gov);struct dbs_data *dbs_data = gov->gdbs_data;unsigned int latency;int ret;
@@ -537,8 +538,7 @@ static int cpufreq_governor_limits(strucreturn 0 ; } -int cpufreq_governor_dbs (struct cpufreq_policy *policy, -struct dbs_governor *gov,unsigned int event) +int cpufreq_governor_dbs (struct cpufreq_policy *policy,unsigned int event) {int ret = -EINVAL ;
@@ -546,7 +546,7 @@ int cpufreq_governor_dbs(struct cpufreq_mutex_lock (&dbs_data_mutex);if (event ==CPUFREQ_GOV_POLICY_INIT ) { - ret =cpufreq_governor_init (policy, gov); + ret =cpufreq_governor_init (policy); }else if (policy->governor_data) {switch (event) {case CPUFREQ_GOV_POLICY_EXIT :
drivers/cpufreq/cpufreq_governor.h +1 -2
@@ -276,8 +276,7 @@ void gov_set_update_util(struct cpu_comm unsigned int delay_us);void gov_cancel_work (struct cpu_common_dbs_info *shared);void dbs_check_cpu (struct dbs_data *dbs_data,int cpu); -int cpufreq_governor_dbs (struct cpufreq_policy *policy, -struct dbs_governor *gov,unsigned int event); +int cpufreq_governor_dbs (struct cpufreq_policy *policy,unsigned int event);void od_register_powersave_bias_handler (unsigned int (*f) (struct cpufreq_policy *,unsigned int ,unsigned int ),unsigned int powersave_bias);
drivers/cpufreq/cpufreq_ondemand.c +1 -10
@@ -535,13 +535,10 @@ static struct od_ops od_ops = { .freq_increase = dbs_freq_increase, }; -static int od_cpufreq_governor_dbs (struct cpufreq_policy *policy, -unsigned int event); -static struct dbs_governor od_dbs_gov = { .gov = { .name ="ondemand" , - .governor = od_cpufreq_governor_dbs, + .governor = cpufreq_governor_dbs, .max_transition_latency =TRANSITION_LATENCY_LIMIT , .owner =THIS_MODULE , },
@@ -559,12 +556,6 @@ static struct dbs_governor od_dbs_gov =#define CPU_FREQ_GOV_ONDEMAND (&od_dbs_gov.gov) -static int od_cpufreq_governor_dbs (struct cpufreq_policy *policy, -unsigned int event) -{ -return cpufreq_governor_dbs (policy, &od_dbs_gov, event); -} -static void od_set_powersave_bias (unsigned int powersave_bias) {struct cpufreq_policy *policy;
Re: [PATCH v2 6/10] cpufreq: governor: Rework cpufreq_governor_dbs()
Quoted 10 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Since it is possible to obtain a pointer to struct
dbs_governorfrom a pointer to the struct governor embedded in it viacontainer_of(), the second argument ofcpufreq_governor_init()is not necessary. Accordingly,cpufreq_governor_dbs()doesn't need its second argument either and the ->governor callbacks for both the ondemand and conservative governors may be set tocpufreq_governor_dbs()directly. Make that happen.
Quoted 8 lines
Signed-off-by Rafael J. Wysocki <[email protected]>Acked-by Saravana Kannan <[email protected]>--- drivers/cpufreq/cpufreq_conservative.c | 11 +---------- drivers/cpufreq/cpufreq_governor.c | 10 +++++----- drivers/cpufreq/cpufreq_governor.h | 3 +-- drivers/cpufreq/cpufreq_ondemand.c | 11 +---------- 4 files changed, 8 insertions(+), 27 deletions(-)
Signature · 1 line
viresh
PATCH v2 7/10 cpufreq: governor: Drop the gov pointer from struct dbs_data
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Since it is possible to obtain a pointer to struct dbs_governor from a pointer to the struct governor embedded in it with the help of container_of(), the additional gov pointer in struct dbs_data isn't really necessary.
Drop that pointer and make the code using it reach the dbs_governor object via policy->governor.
--- drivers/cpufreq/amd_freq_sensitivity.c | 2 - drivers/cpufreq/cpufreq_conservative.c | 2 - drivers/cpufreq/cpufreq_governor.c | 63 +++++++++++++++------------------ drivers/cpufreq/cpufreq_governor.h | 8 +++- drivers/cpufreq/cpufreq_ondemand.c | 2 - 5 files changed, 39 insertions(+), 38 deletions(-)
drivers/cpufreq/cpufreq_governor.h +6 -2
@@ -228,9 +228,13 @@ struct dbs_governor {void *gov_ops; }; +static inline struct dbs_governor *dbs_governor_of (struct cpufreq_policy *policy) +{ + return container_of(policy->governor, struct dbs_governor, gov); +} +/* Governor Per policy data */ struct dbs_data { -struct dbs_governor *gov;unsigned int min_sampling_rate;int usage_count;void *tuners;
@@ -275,7 +279,7 @@ extern struct mutex cpufreq_governor_locvoid gov_set_update_util (struct cpu_common_dbs_info *shared,unsigned int delay_us);void gov_cancel_work (struct cpu_common_dbs_info *shared); -void dbs_check_cpu (struct dbs_data *dbs_data,int cpu); +void dbs_check_cpu (struct cpufreq_policy *policy,int cpu);int cpufreq_governor_dbs (struct cpufreq_policy *policy,unsigned int event); void od_register_powersave_bias_handler(unsigned int (*f) (struct cpufreq_policy *, unsigned int, unsigned int),
drivers/cpufreq/cpufreq_conservative.c +1 -1
@@ -107,7 +107,7 @@ static unsigned int cs_dbs_timer(structstruct dbs_data *dbs_data = policy->governor_data;struct cs_dbs_tuners *cs_tuners = dbs_data->tuners; -dbs_check_cpu (dbs_data, policy->cpu); +dbs_check_cpu (policy, policy->cpu);return delay_for_sampling_rate (cs_tuners->sampling_rate); }
drivers/cpufreq/cpufreq_governor.c +30 -33
195 lines not on this page · raw message
drivers/cpufreq/cpufreq_ondemand.c +1 -1
@@ -203,7 +203,7 @@ static unsigned int od_dbs_timer(struct__cpufreq_driver_target (policy, dbs_info->freq_lo,CPUFREQ_RELATION_H ); }else { -dbs_check_cpu (dbs_data, cpu); +dbs_check_cpu (policy, cpu);if (dbs_info->freq_lo) {/* Setup timer for SUB_SAMPLE */ dbs_info->sample_type =OD_SUB_SAMPLE ;
drivers/cpufreq/amd_freq_sensitivity.c +1 -1
@@ -48,7 +48,7 @@ static unsigned int amd_powersave_bias_tstruct dbs_data *od_data = policy->governor_data;struct od_dbs_tuners *od_tuners = od_data->tuners;struct od_cpu_dbs_info_s *od_info = - od_data->gov->get_cpu_dbs_info_s (policy->cpu); +dbs_governor_of (policy)->get_cpu_dbs_info_s (policy->cpu);if (!od_info->freq_table)return freq_next;
Re: [PATCH v2 7/10] cpufreq: governor: Drop the gov pointer from struct dbs_data
Quoted 10 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Since it is possible to obtain a pointer to struct
dbs_governorfrom a pointer to the struct governor embedded in it with the help ofcontainer_of(), the additional gov pointer in structdbs_dataisn't really necessary.Drop that pointer and make the code using it reach the
dbs_governorobject viapolicy->governor.
Quoted 8 lines
Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/cpufreq/amd_freq_sensitivity.c | 2 - drivers/cpufreq/cpufreq_conservative.c | 2 - drivers/cpufreq/cpufreq_governor.c | 63 +++++++++++++++------------------ drivers/cpufreq/cpufreq_governor.h | 8 +++- drivers/cpufreq/cpufreq_ondemand.c | 2 - 5 files changed, 39 insertions(+), 38 deletions(-)
Signature · 1 line
viresh
PATCH v2 8/10 cpufreq: governor: Rename cpu_common_dbs_info to policy_dbs_info
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
The struct cpu_common_dbs_info structure represents the per-policy part of the governor data (for the ondemand and conservative governors), but its name doesn't reflect its purpose.
Rename it to struct policy_dbs_info and rename variables related to it accordingly.
No functional changes.
--- drivers/cpufreq/cpufreq_governor.c | 120 ++++++++++++++++++------------------- drivers/cpufreq/cpufreq_governor.h | 8 +- drivers/cpufreq/cpufreq_ondemand.c | 32 ++++----- 3 files changed, 80 insertions(+), 80 deletions(-)
drivers/cpufreq/cpufreq_governor.h +4 -4
@@ -132,7 +132,7 @@ static void *get_cpu_dbs_info_s(int cpu)*/ /* Common to all CPUs of a policy */ -struct cpu_common_dbs_info { +struct policy_dbs_info {struct cpufreq_policy *policy;/* * Per policy mutex that serializes load evaluation from limit-change
@@ -162,7 +162,7 @@ struct cpu_dbs_info {*/ unsigned int prev_load;struct update_util_data update_util; -struct cpu_common_dbs_info *shared; +struct policy_dbs_info *shared; };struct od_cpu_dbs_info_s {
@@ -276,9 +276,9 @@ static ssize_t show_sampling_rate_min_goextern struct mutex dbs_data_mutex;extern struct mutex cpufreq_governor_lock; -void gov_set_update_util (struct cpu_common_dbs_info *shared, +void gov_set_update_util (struct policy_dbs_info *policy_dbs,unsigned int delay_us); -void gov_cancel_work (struct cpu_common_dbs_info *shared); +void gov_cancel_work (struct policy_dbs_info *policy_dbs);void dbs_check_cpu (struct cpufreq_policy *policy,int cpu);int cpufreq_governor_dbs (struct cpufreq_policy *policy,unsigned int event); void od_register_powersave_bias_handler(unsigned int (*f)
drivers/cpufreq/cpufreq_governor.c +60 -60
279 lines not on this page · raw message
drivers/cpufreq/cpufreq_ondemand.c +16 -16
@@ -255,21 +255,21 @@ static void update_sampling_rate(structstruct cpufreq_policy *policy;struct od_cpu_dbs_info_s *dbs_info;struct cpu_dbs_info *cdbs; -struct cpu_common_dbs_info *shared; +struct policy_dbs_info *policy_dbs;ktime_t next_sampling, appointed_at; dbs_info = &per_cpu (od_cpu_dbs_info, cpu); cdbs = &dbs_info->cdbs; - shared = cdbs->shared; + policy_dbs = cdbs->shared;/* -* A valid shared and shared->policy means governor hasn't -* stopped or exited yet. +* A valid policy_dbs and policy_dbs->policy means governor +* hasn't stopped or exited yet. */ -if (!shared || !shared->policy) +if (!policy_dbs || !policy_dbs->policy)continue ; - policy = shared->policy; + policy = policy_dbs->policy;/* clear all CPUs of this policy */ cpumask_andnot (&cpumask, &cpumask, policy->cpus);
@@ -289,14 +289,14 @@ static void update_sampling_rate(struct*/ next_sampling =ktime_add_us (ktime_get (), new_rate); -mutex_lock (&shared->timer_mutex); - appointed_at =ktime_add_ns (shared->time_stamp, - shared->sample_delay_ns); -mutex_unlock (&shared->timer_mutex); +mutex_lock (&policy_dbs->timer_mutex); + appointed_at =ktime_add_ns (policy_dbs->time_stamp, + policy_dbs->sample_delay_ns); +mutex_unlock (&policy_dbs->timer_mutex);if (ktime_before (next_sampling, appointed_at)) { -gov_cancel_work (shared); -gov_set_update_util (shared, new_rate); +gov_cancel_work (policy_dbs); +gov_set_update_util (policy_dbs, new_rate); } }
@@ -569,16 +569,16 @@ static void od_set_powersave_bias(unsignget_online_cpus ();for_each_online_cpu (cpu) { -struct cpu_common_dbs_info *shared; +struct policy_dbs_info *policy_dbs;if (cpumask_test_cpu (cpu, &done))continue ; - shared =per_cpu (od_cpu_dbs_info, cpu).cdbs.shared; -if (!shared) + policy_dbs =per_cpu (od_cpu_dbs_info, cpu).cdbs.shared; +if (!policy_dbs)continue ; - policy = shared->policy; + policy = policy_dbs->policy;cpumask_or (&done, &done, policy->cpus);if (policy->governor !=CPU_FREQ_GOV_ONDEMAND )
Re: [PATCH v2 8/10] cpufreq: governor: Rename cpu_common_dbs_info to policy_dbs_info
Quoted 32 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
The struct
cpu_common_dbs_infostructure represents the per-policy part of the governor data (for the ondemand and conservative governors), but its name doesn't reflect its purpose.Rename it to struct
policy_dbs_infoand rename variables related to it accordingly.No functional changes.
Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/cpufreq/cpufreq_governor.c | 120 ++++++++++++++++++------------------- drivers/cpufreq/cpufreq_governor.h | 8 +- drivers/cpufreq/cpufreq_ondemand.c | 32 ++++----- 3 files changed, 80 insertions(+), 80 deletions(-)Index:
linux-pm/drivers/cpufreq/cpufreq_governor.h
===================================================================drivers/cpufreq/cpufreq_governor.h +1
-1@@ -132,7 +132,7 @@ static void *get_cpu_dbs_info_s(int cpu)*/ /* Common to all CPUs of a policy */ -struct cpu_common_dbs_info { +struct policy_dbs_info {struct cpufreq_policy *policy;/* * Per policy mutex that serializes load evaluation from limit-change
drivers/cpufreq/cpufreq_governor.h struct cpu_dbs_info { · line 165
Quoted 5 lines
drivers/cpufreq/cpufreq_governor.h +1
-1@@ -162,7 +162,7 @@ struct cpu_dbs_info {*/ unsigned int prev_load;struct update_util_data update_util; -struct cpu_common_dbs_info *shared; +struct policy_dbs_info *shared;
You should replaced shared with policy_dbs here as well ? Apart from that:
Signature · 1 line
viresh
Re: [PATCH v2 8/10] cpufreq: governor: Rename cpu_common_dbs_info to policy_dbs_info
Quoted 26 lines · Viresh Kumar
Quoted 25 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
The struct
cpu_common_dbs_infostructure represents the per-policy part of the governor data (for the ondemand and conservative governors), but its name doesn't reflect its purpose.Rename it to struct
policy_dbs_infoand rename variables related to it accordingly.No functional changes.
Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/cpufreq/cpufreq_governor.c | 120 ++++++++++++++++++------------------- drivers/cpufreq/cpufreq_governor.h | 8 +- drivers/cpufreq/cpufreq_ondemand.c | 32 ++++----- 3 files changed, 80 insertions(+), 80 deletions(-)Index:
linux-pm/drivers/cpufreq/cpufreq_governor.h
===================================================================drivers/cpufreq/cpufreq_governor.h +0
-0@@ -132,7 +132,7 @@ static void *get_cpu_dbs_info_s(int cpu)*/
Quoted 15 lines
drivers/cpufreq/cpufreq_governor.h struct cpu_dbs_info { · line 165
Quoted 12 lines
drivers/cpufreq/cpufreq_governor.h +2
-2/* Common to all CPUs of a policy */ -struct cpu_common_dbs_info { +struct policy_dbs_info {struct cpufreq_policy *policy;/* * Per policy mutex that serializes load evaluation from limit-change @@ -162,7 +162,7 @@ struct cpu_dbs_info {*/ unsigned int prev_load;struct update_util_data update_util; -struct cpu_common_dbs_info *shared; +struct policy_dbs_info *shared;You should replaced shared with
policy_dbshere as well ? Apart from that:
I wanted to keep the name as the object pointed to by it is technically still "shared". I guess I can change it too, though.
Thanks,
Rafael
PATCH v3 8/10 cpufreq: governor: Rename cpu_common_dbs_info to policy_dbs_info
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Subject: [PATCH] cpufreq: governor: Rename cpu_common_dbs_info to policy_dbs_info
The struct cpu_common_dbs_info structure represents the per-policy part of the governor data (for the ondemand and conservative governors), but its name doesn't reflect its purpose.
Rename it to struct policy_dbs_info and rename variables related to it accordingly.
No functional changes.
---
Changes from v2:
- Rebase on top of https://patchwork.kernel.org/patch/8241231/
- Change all struct cpu_common_dbs_info pointers to be called policy_dbs.
--- drivers/cpufreq/cpufreq_conservative.c | 2 drivers/cpufreq/cpufreq_governor.c | 134 ++++++++++++++++----------------- drivers/cpufreq/cpufreq_governor.h | 8 - drivers/cpufreq/cpufreq_ondemand.c | 28 +++--- 4 files changed, 86 insertions(+), 86 deletions(-)
drivers/cpufreq/cpufreq_governor.h +4 -4
@@ -131,7 +131,7 @@ static void *get_cpu_dbs_info_s(int cpu)*/ /* Common to all CPUs of a policy */ -struct cpu_common_dbs_info { +struct policy_dbs_info {struct cpufreq_policy *policy;/* * Per policy mutex that serializes load evaluation from limit-change
@@ -146,10 +146,10 @@ struct cpu_common_dbs_info {struct work_struct work; }; -static inline void gov_update_sample_delay (struct cpu_common_dbs_info *shared, +static inline void gov_update_sample_delay (struct policy_dbs_info *policy_dbs,unsigned int delay_us) { - shared->sample_delay_ns = delay_us *NSEC_PER_USEC ; + policy_dbs->sample_delay_ns = delay_us *NSEC_PER_USEC ; }/* Per cpu structures */
@@ -165,7 +165,7 @@ struct cpu_dbs_info {*/ unsigned int prev_load;struct update_util_data update_util; -struct cpu_common_dbs_info *shared; +struct policy_dbs_info *policy_dbs; };struct od_cpu_dbs_info_s {
drivers/cpufreq/cpufreq_governor.c +67 -67
313 lines not on this page · raw message
drivers/cpufreq/cpufreq_ondemand.c +14 -14
@@ -151,7 +151,7 @@ static void dbs_freq_increase(struct cpustatic void od_check_cpu (int cpu,unsigned int load) {struct od_cpu_dbs_info_s *dbs_info = &per_cpu (od_cpu_dbs_info, cpu); -struct cpufreq_policy *policy = dbs_info->cdbs.shared->policy; +struct cpufreq_policy *policy = dbs_info->cdbs.policy_dbs->policy;struct dbs_data *dbs_data = policy->governor_data;struct od_dbs_tuners *od_tuners = dbs_data->tuners;
@@ -255,20 +255,20 @@ static void update_sampling_rate(structstruct cpufreq_policy *policy;struct od_cpu_dbs_info_s *dbs_info;struct cpu_dbs_info *cdbs; -struct cpu_common_dbs_info *shared; +struct policy_dbs_info *policy_dbs; dbs_info = &per_cpu (od_cpu_dbs_info, cpu); cdbs = &dbs_info->cdbs; - shared = cdbs->shared; + policy_dbs = cdbs->policy_dbs;/* -* A valid shared and shared->policy means governor hasn't -* stopped or exited yet. +* A valid policy_dbs and policy_dbs->policy means governor +* hasn't stopped or exited yet. */ -if (!shared || !shared->policy) +if (!policy_dbs || !policy_dbs->policy)continue ; - policy = shared->policy; + policy = policy_dbs->policy;/* clear all CPUs of this policy */ cpumask_andnot (&cpumask, &cpumask, policy->cpus);
@@ -280,7 +280,7 @@ static void update_sampling_rate(struct* multiple policies that are governed by the same dbs_data. */ if (dbs_data == policy->governor_data) { -mutex_lock (&shared->timer_mutex); +mutex_lock (&policy_dbs->timer_mutex);/* * On 32-bit architectures this may race with the * sample_delay_ns read in dbs_update_util_handler(),
@@ -299,8 +299,8 @@ static void update_sampling_rate(struct* too big and it will be corrected next time a sample * is taken, so it shouldn't be significant. */ -gov_update_sample_delay (shared, new_rate); -mutex_unlock (&shared->timer_mutex); +gov_update_sample_delay (policy_dbs, new_rate); +mutex_unlock (&policy_dbs->timer_mutex); } }
@@ -573,16 +573,16 @@ static void od_set_powersave_bias(unsignget_online_cpus ();for_each_online_cpu (cpu) { -struct cpu_common_dbs_info *shared; +struct policy_dbs_info *policy_dbs;if (cpumask_test_cpu (cpu, &done))continue ; - shared =per_cpu (od_cpu_dbs_info, cpu).cdbs.shared; -if (!shared) + policy_dbs =per_cpu (od_cpu_dbs_info, cpu).cdbs.policy_dbs; +if (!policy_dbs)continue ; - policy = shared->policy; + policy = policy_dbs->policy;cpumask_or (&done, &done, policy->cpus);if (policy->governor !=CPU_FREQ_GOV_ONDEMAND )
drivers/cpufreq/cpufreq_conservative.c +1 -1
@@ -47,7 +47,7 @@ static inline unsigned int get_freq_targstatic void cs_check_cpu (int cpu,unsigned int load) {struct cs_cpu_dbs_info_s *dbs_info = &per_cpu (cs_cpu_dbs_info, cpu); -struct cpufreq_policy *policy = dbs_info->cdbs.shared->policy; +struct cpufreq_policy *policy = dbs_info->cdbs.policy_dbs->policy;struct dbs_data *dbs_data = policy->governor_data;struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
Re: [PATCH v3 8/10] cpufreq: governor: Rename cpu_common_dbs_info to policy_dbs_info
Quoted 7 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Subject: [PATCH] cpufreq: governor: Renamecpu_common_dbs_infotopolicy_dbs_infoThe struct
cpu_common_dbs_infostructure represents the per-policy part of the governor data (for the ondemand and conservative governors), but its name doesn't reflect its purpose.
Quoted 6 lines
Rename it to struct
policy_dbs_infoand rename variables related to it accordingly.No functional changes.
Signed-off-by Rafael J. Wysocki <[email protected]>
Signature · 1 line
viresh
PATCH v2 9/10 cpufreq: governor: Rearrange governor data structures
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
The struct policy_dbs_info objects representing per-policy governor data are not accessible directly from the corresponding policy objects. To access them, one has to get a pointer to the struct cpu_dbs_info of policy->cpu and use the "shared" field of that which isn't really straightforward.
To address that rearrange the governor data structures so the governor_data pointer in struct cpufreq_policy will point to struct policy_dbs_info and that will contain a pointer to struct dbs_data.
--- drivers/cpufreq/amd_freq_sensitivity.c | 3 drivers/cpufreq/cpufreq_conservative.c | 6 + drivers/cpufreq/cpufreq_governor.c | 120 ++++++++++++++------------------- drivers/cpufreq/cpufreq_governor.h | 27 ++++--- drivers/cpufreq/cpufreq_ondemand.c | 18 +++- 5 files changed, 85 insertions(+), 89 deletions(-)
drivers/cpufreq/cpufreq_governor.h +15 -12
@@ -86,7 +86,8 @@ static ssize_t show_##file_name##_gov_sy static ssize_t show_##file_name##_gov_pol \ (struct cpufreq_policy *policy, char *buf) \ { \ - struct dbs_data *dbs_data = policy->governor_data; \ + struct policy_dbs_info *policy_dbs = policy->governor_data; \ + struct dbs_data *dbs_data = policy_dbs->dbs_data; \ struct _gov##_dbs_tuners *tuners = dbs_data->tuners; \ return sprintf(buf, "%u\n", tuners->file_name); \ }
@@ -102,8 +103,8 @@ static ssize_t store_##file_name##_gov_s static ssize_t store_##file_name##_gov_pol \ (struct cpufreq_policy *policy, const char *buf, size_t count) \ { \ - struct dbs_data *dbs_data = policy->governor_data; \ - return store_##file_name(dbs_data, buf, count); \ + struct policy_dbs_info *policy_dbs = policy->governor_data; \ + return store_##file_name(policy_dbs->dbs_data, buf, count); \ }#define show_store_one (_gov, file_name) \
@@ -131,6 +132,13 @@ static void *get_cpu_dbs_info_s(int cpu)* cs_*: Conservative governor */ +/* Governor demand based switching data (per-policy or global). */ +struct dbs_data { +unsigned int min_sampling_rate; +int usage_count; +void *tuners; +}; +/* Common to all CPUs of a policy */ struct policy_dbs_info {struct cpufreq_policy *policy;
@@ -147,6 +155,8 @@ struct policy_dbs_info {struct irq_work irq_work;struct completion irq_work_done;struct work_struct work; +/* dbs_data may be shared between multiple policy objects */ +struct dbs_data *dbs_data; };/* Per cpu structures */
@@ -201,7 +211,6 @@ struct cs_dbs_tuners { };/* Common Governor data across policies */ -struct dbs_data ;struct dbs_governor {struct cpufreq_governor gov;
@@ -233,13 +242,6 @@ static inline struct dbs_governor *dbs_g return container_of(policy->governor, struct dbs_governor, gov); } -/* Governor Per policy data */ -struct dbs_data { -unsigned int min_sampling_rate; -int usage_count; -void *tuners; -}; -/* Governor specific ops, will be passed to dbs_data->gov_ops */ struct od_ops {void (*powersave_bias_init_cpu)(int cpu);
@@ -270,7 +272,8 @@ static ssize_t show_sampling_rate_min_gostatic ssize_t show_sampling_rate_min_gov_pol \ (struct cpufreq_policy *policy,char *buf) \ { \ -struct dbs_data *dbs_data = policy->governor_data; \ +struct policy_dbs_info *policy_dbs = policy->governor_data; \ +struct dbs_data *dbs_data = policy_dbs->dbs_data; \return sprintf (buf,"%u\n" , dbs_data->min_sampling_rate); \ }
drivers/cpufreq/cpufreq_governor.c +53 -67
236 lines not on this page · raw message
drivers/cpufreq/cpufreq_ondemand.c +11 -7
@@ -78,7 +78,8 @@ static unsigned int generic_powersave_biunsigned int jiffies_total, jiffies_hi, jiffies_lo;struct od_cpu_dbs_info_s *dbs_info = &per_cpu (od_cpu_dbs_info, policy->cpu); -struct dbs_data *dbs_data = policy->governor_data; +struct policy_dbs_info *policy_dbs = policy->governor_data; +struct dbs_data *dbs_data = policy_dbs->dbs_data;struct od_dbs_tuners *od_tuners = dbs_data->tuners;if (!dbs_info->freq_table) {
@@ -130,7 +131,8 @@ static void ondemand_powersave_bias_initstatic void dbs_freq_increase (struct cpufreq_policy *policy,unsigned int freq) { -struct dbs_data *dbs_data = policy->governor_data; +struct policy_dbs_info *policy_dbs = policy->governor_data; +struct dbs_data *dbs_data = policy_dbs->dbs_data;struct od_dbs_tuners *od_tuners = dbs_data->tuners;if (od_tuners->powersave_bias)
@@ -151,8 +153,9 @@ static void dbs_freq_increase(struct cpustatic void od_check_cpu (int cpu,unsigned int load) {struct od_cpu_dbs_info_s *dbs_info = &per_cpu (od_cpu_dbs_info, cpu); -struct cpufreq_policy *policy = dbs_info->cdbs.shared->policy; -struct dbs_data *dbs_data = policy->governor_data; +struct policy_dbs_info *policy_dbs = dbs_info->cdbs.shared; +struct cpufreq_policy *policy = policy_dbs->policy; +struct dbs_data *dbs_data = policy_dbs->dbs_data;struct od_dbs_tuners *od_tuners = dbs_data->tuners; dbs_info->freq_lo =0 ;
@@ -189,7 +192,8 @@ static void od_check_cpu(int cpu, unsignstatic unsigned int od_dbs_timer (struct cpufreq_policy *policy) { -struct dbs_data *dbs_data = policy->governor_data; +struct policy_dbs_info *policy_dbs = policy->governor_data; +struct dbs_data *dbs_data = policy_dbs->dbs_data;unsigned int cpu = policy->cpu;struct od_cpu_dbs_info_s *dbs_info = &per_cpu (od_cpu_dbs_info, cpu);
@@ -280,7 +284,7 @@ static void update_sampling_rate(struct* policy will be governed by dbs_data, otherwise there can be * multiple policies that are governed by the same dbs_data. */ -if (dbs_data != policy->governor_data) +if (dbs_data != policy_dbs->dbs_data)continue ;/*
@@ -584,7 +588,7 @@ static void od_set_powersave_bias(unsignif (policy->governor !=CPU_FREQ_GOV_ONDEMAND )continue ; - dbs_data = policy->governor_data; + dbs_data = policy_dbs->dbs_data; od_tuners = dbs_data->tuners; od_tuners->powersave_bias = default_powersave_bias; }
drivers/cpufreq/amd_freq_sensitivity.c +2 -1
@@ -45,7 +45,8 @@ static unsigned int amd_powersave_bias_tlong d_actual, d_reference;struct msr actual, reference;struct cpu_data_t *data = &per_cpu (cpu_data, policy->cpu); -struct dbs_data *od_data = policy->governor_data; +struct policy_dbs_info *policy_dbs = policy->governor_data; +struct dbs_data *od_data = policy_dbs->dbs_data;struct od_dbs_tuners *od_tuners = od_data->tuners;struct od_cpu_dbs_info_s *od_info =dbs_governor_of (policy)->get_cpu_dbs_info_s (policy->cpu);
drivers/cpufreq/cpufreq_conservative.c +4 -2
@@ -48,7 +48,8 @@ static void cs_check_cpu(int cpu, unsign {struct cs_cpu_dbs_info_s *dbs_info = &per_cpu (cs_cpu_dbs_info, cpu);struct cpufreq_policy *policy = dbs_info->cdbs.shared->policy; -struct dbs_data *dbs_data = policy->governor_data; +struct policy_dbs_info *policy_dbs = policy->governor_data; +struct dbs_data *dbs_data = policy_dbs->dbs_data;struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;/*
@@ -104,7 +105,8 @@ static void cs_check_cpu(int cpu, unsignstatic unsigned int cs_dbs_timer (struct cpufreq_policy *policy) { -struct dbs_data *dbs_data = policy->governor_data; +struct policy_dbs_info *policy_dbs = policy->governor_data; +struct dbs_data *dbs_data = policy_dbs->dbs_data;struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;dbs_check_cpu (policy, policy->cpu);
Viresh Kumar
maintainerRe: [PATCH v2 9/10] cpufreq: governor: Rearrange governor data structures
Quoted 8 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
The struct
policy_dbs_infoobjects representing per-policy governor data are not accessible directly from the corresponding policy objects. To access them, one has to get a pointer to the structcpu_dbs_infoofpolicy->cpuand use the "shared" field of that which isn't really straightforward.
Quoted 4 lines
To address that rearrange the governor data structures so the
governor_datapointer in structcpufreq_policywill point to structpolicy_dbs_infoand that will contain a pointer to structdbs_data.
IMHO, this patch has done way too much over what's mentioned here.
drivers/cpufreq/cpufreq_governor.c static int alloc_policy_dbs_info(struct · line 303
Quoted 13 lines
Index:
linux-pm/drivers/cpufreq/cpufreq_governor.cdrivers/cpufreq/cpufreq_governor.c +2
-5@@ -297,16 +298,22 @@ static int alloc_policy_dbs_info(struct/* Allocate memory for the common information for policy->cpus */ policy_dbs =kzalloc (sizeof (*policy_dbs),GFP_KERNEL );if (!policy_dbs) -return -ENOMEM ; - -/* Set policy_dbs for all CPUs, online+offline */ -for_each_cpu (j, policy->related_cpus) - gov->get_cpu_cdbs (j)->shared = policy_dbs; +return NULL ; + policy_dbs->policy = policy;
Value of policy_dbs->policy was used to verify the state machine of the governor and so was updated only in start/stop.
You have moved it to INIT first (which shouldn't have been part of this patch at the least), and then there is no reasoning given on why that isn't required as part of the state machine now, which I believe is still required the way it was.
drivers/cpufreq/cpufreq_governor.c static int alloc_policy_dbs_info(struct · line 315
Quoted 13 lines
drivers/cpufreq/cpufreq_governor.c +9
-1mutex_init (&policy_dbs->timer_mutex);atomic_set (&policy_dbs->skip_work,0 ); +init_irq_work (&policy_dbs->irq_work, dbs_irq_work); +init_completion (&policy_dbs->irq_work_done);INIT_WORK (&policy_dbs->work, dbs_work_handler); -return 0 ; +/* Set policy_dbs for all CPUs, online+offline */ +for_each_cpu (j, policy->related_cpus) { +struct cpu_dbs_info *j_cdbs = gov->get_cpu_cdbs (j); + + j_cdbs->shared = policy_dbs; + j_cdbs->update_util.func = dbs_update_util_handler; + }
All other initializations are moved here for the good, but I think it could have been done in a separate patch as to make review of this trivial patch, which isn't so easy to review, easy :)
drivers/cpufreq/cpufreq_governor.c reset_gdbs_data: · line 408
Quoted 10 lines
drivers/cpufreq/cpufreq_governor.c +2
-3static int cpufreq_governor_exit (struct cpufreq_policy *policy) {struct dbs_governor *gov =dbs_governor_of (policy); -struct dbs_data *dbs_data = policy->governor_data; -struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs (policy->cpu); +struct policy_dbs_info *policy_dbs = policy->governor_data; +struct dbs_data *dbs_data = policy_dbs->dbs_data;/* State should be equivalent to INIT */ -if (!cdbs->shared || cdbs->shared->policy)
For example, to make sure the current state is equivalent to INIT, we had two checks earlier:
- First one made sure that cdbs->shared is allocated (which was done in INIT)
- And second one makes sure that shared->policy is NULL, as that is initialized in START.
Review
Quoted 2 lines
(quoted diff) +1
-0+ if (!dbs_data) return -EBUSY;
But now, the current state can be INIT or START, you can't differentiate.
Quoted 7 lines
static int
cpufreq_governor_start(struct cpufreq_policy *policy){drivers/cpufreq/cpufreq_governor.c +2
-1struct dbs_governor *gov =dbs_governor_of (policy); -struct dbs_data *dbs_data = policy->governor_data; +struct policy_dbs_info *policy_dbs = policy->governor_data; +struct dbs_data *dbs_data = policy_dbs->dbs_data;unsigned int sampling_rate, ignore_nice, j, cpu = policy->cpu;
drivers/cpufreq/cpufreq_governor.c static int cpufreq_governor_exit(struct · line 448
Quoted 10 lines
drivers/cpufreq/cpufreq_governor.c +1
-3-struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs (cpu); -struct policy_dbs_info *policy_dbs = cdbs->shared;int io_busy =0 ;if (!policy->cur)return -EINVAL ;/* State should be equivalent to INIT */ -if (!policy_dbs || policy_dbs->policy) +if (!dbs_data)
Same here..
drivers/cpufreq/cpufreq_governor.c static int cpufreq_governor_start(struct · line 506
Quoted 8 lines
static int
cpufreq_governor_stop(struct cpufreq_policy *policy){drivers/cpufreq/cpufreq_governor.c +0
-6-struct dbs_governor *gov =dbs_governor_of (policy); -struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs (policy->cpu); -struct policy_dbs_info *policy_dbs = cdbs->shared; - -/* State should be equivalent to START */ -if (!policy_dbs || !policy_dbs->policy)
And here ..
Quoted 9 lines
drivers/cpufreq/cpufreq_governor.c +1
-5-return -EBUSY ; - -gov_cancel_work (policy_dbs); - policy_dbs->policy =NULL ; - +gov_cancel_work (policy->governor_data);return 0 ; }
drivers/cpufreq/cpufreq_governor.c static int cpufreq_governor_start(struct · line 510
Quoted 10 lines
drivers/cpufreq/cpufreq_governor.c +2
-4static int cpufreq_governor_limits (struct cpufreq_policy *policy) { -struct dbs_governor *gov =dbs_governor_of (policy); -unsigned int cpu = policy->cpu; -struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs (cpu); +struct policy_dbs_info *policy_dbs = policy->governor_data;/* State should be equivalent to START */ -if (!cdbs->shared || !cdbs->shared->policy) +if (!policy_dbs->dbs_data)
And here...
Quoted 21 lines
drivers/cpufreq/cpufreq_governor.c +7
-9return -EBUSY ; -mutex_lock (&cdbs->shared->timer_mutex); -if (policy->max < cdbs->shared->policy->cur) -__cpufreq_driver_target (cdbs->shared->policy, policy->max, -CPUFREQ_RELATION_H ); -else if (policy->min > cdbs->shared->policy->cur) -__cpufreq_driver_target (cdbs->shared->policy, policy->min, -CPUFREQ_RELATION_L ); -dbs_check_cpu (policy, cpu); -mutex_unlock (&cdbs->shared->timer_mutex); +mutex_lock (&policy_dbs->timer_mutex); +if (policy->max < policy->cur) +__cpufreq_driver_target (policy, policy->max,CPUFREQ_RELATION_H ); +else if (policy->min > policy->cur) +__cpufreq_driver_target (policy, policy->min,CPUFREQ_RELATION_L ); +dbs_check_cpu (policy, policy->cpu); +mutex_unlock (&policy_dbs->timer_mutex);return 0 ; }
Signature · 1 line
viresh
Re: [PATCH v2 9/10] cpufreq: governor: Rearrange governor data structures
Quoted 28 lines · Viresh Kumar
Quoted 8 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
The struct
policy_dbs_infoobjects representing per-policy governor data are not accessible directly from the corresponding policy objects. To access them, one has to get a pointer to the structcpu_dbs_infoofpolicy->cpuand use the "shared" field of that which isn't really straightforward.Quoted 4 lines
To address that rearrange the governor data structures so the
governor_datapointer in structcpufreq_policywill point to structpolicy_dbs_infoand that will contain a pointer to structdbs_data.IMHO, this patch has done way too much over what's mentioned here.
Quoted 12 lines
Index:
linux-pm/drivers/cpufreq/cpufreq_governor.cdrivers/cpufreq/cpufreq_governor.c +1
-5@@ -297,16 +298,22 @@ static int alloc_policy_dbs_info(struct/* Allocate memory for the common information for policy->cpus */ policy_dbs =kzalloc (sizeof (*policy_dbs),GFP_KERNEL );if (!policy_dbs) -return -ENOMEM ; - -/* Set policy_dbs for all CPUs, online+offline */ -for_each_cpu (j, policy->related_cpus) - gov->get_cpu_cdbs (j)->shared = policy_dbs; +return NULL ;
Quoted 7 lines
drivers/cpufreq/cpufreq_governor.c static int alloc_policy_dbs_info(struct · line 303
Quoted 1 line
drivers/cpufreq/cpufreq_governor.c +1
-0+ policy_dbs->policy = policy;Value of
policy_dbs->policywas used to verify the state machine of the governor and so was updated only in start/stop.You have moved it to INIT first (which shouldn't have been part of this patch at the least),
Why?
Quoted 3 lines
and then there is no reasoning given on why
that isn't required as part of the state machine now, which I believe is still required the way it was.
No, it isn't required. The whole "state machine" isn't required IMO.
The only user of this is the cpufreq core, so why does the code here have to double check what the core is doing?
Thanks,
Rafael
Viresh Kumar
maintainerRe: [PATCH v2 9/10] cpufreq: governor: Rearrange governor data structures
Quoted 8 lines · Rafael J. Wysocki
Quoted 5 lines · Viresh Kumar
Value of
policy_dbs->policywas used to verify the state machine of the governor and so was updated only in start/stop.You have moved it to INIT first (which shouldn't have been part of this patch at the least),
Why?
Because it doesn't match $SUBJECT at all..
Quoted 5 lines
Quoted 3 lines
and then there is no reasoning given on why
that isn't required as part of the state machine now, which I believe is still required the way it was.No, it isn't required. The whole "state machine" isn't required IMO.
The state machine wasn't required if the core wasn't buggy. Its buggy because we drop policy->rwsem during set-policy, before calling EXIT. And other __cpufreq_governor() calls can shoot up at that point of time.
We have seen lots of crashes earlier and so the state machine was introduced to get them fixed.
It might not be required (after making sure things are working fine now), after applying my patch series of 7 patches. As that fixes the lock-drop issue ..
Quoted 2 lines
The only user of this is the cpufreq core, so why does the code here have to double check what the core is doing?
Because, core doesn't guarantee the order today.
Signature · 1 line
viresh
Re: [PATCH v2 9/10] cpufreq: governor: Rearrange governor data structures
Quoted 25 lines · Viresh Kumar
Quoted 8 lines · Rafael J. Wysocki
Quoted 5 lines · Viresh Kumar
Value of
policy_dbs->policywas used to verify the state machine of the governor and so was updated only in start/stop.You have moved it to INIT first (which shouldn't have been part of this patch at the least),
Why?
Because it doesn't match $SUBJECT at all..
Quoted 5 lines
Quoted 3 lines
and then there is no reasoning given on why
that isn't required as part of the state machine now, which I believe is still required the way it was.No, it isn't required. The whole "state machine" isn't required IMO.
The state machine wasn't required if the core wasn't buggy. Its buggy because we drop
policy->rwsemduring set-policy, before calling EXIT. And other__cpufreq_governor()calls can shoot up at that point of time.We have seen lots of crashes earlier and so the state machine was introduced to get them fixed.
Quoted 7 lines
It might not be required (after making sure things are working fine now), after applying my patch series of 7 patches. As that fixes the lock-drop issue ..
Quoted 2 lines
The only user of this is the cpufreq core, so why does the code here have to double check what the core is doing?
Because, core doesn't guarantee the order today.
OK, so I have reworked this. I have a series of 3 patches now instead of it that I'm going to post shortly.
Thanks,
Rafael
PATCH v2 10/10 cpufreq: governor: Drop cpu argument from dbs_check_cpu()
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Since policy->cpu is always passed as the second argument to dbs_check_cpu(), it is not really necessary to pass it, because the function can obtain that value via its first argument just fine.
--- drivers/cpufreq/cpufreq_conservative.c | 2 +- drivers/cpufreq/cpufreq_governor.c | 5 +++-- drivers/cpufreq/cpufreq_governor.h | 2 +- drivers/cpufreq/cpufreq_ondemand.c | 6 ++---- 4 files changed, 7 insertions(+), 8 deletions(-)
drivers/cpufreq/cpufreq_governor.h +1 -1
@@ -282,7 +282,7 @@ extern struct mutex cpufreq_governor_locvoid gov_set_update_util (struct policy_dbs_info *policy_dbs,unsigned int delay_us);void gov_cancel_work (struct policy_dbs_info *policy_dbs); -void dbs_check_cpu (struct cpufreq_policy *policy,int cpu); +void dbs_check_cpu (struct cpufreq_policy *policy);int cpufreq_governor_dbs (struct cpufreq_policy *policy,unsigned int event); void od_register_powersave_bias_handler(unsigned int (*f) (struct cpufreq_policy *, unsigned int, unsigned int),
drivers/cpufreq/cpufreq_ondemand.c +2 -4
@@ -194,9 +194,7 @@ static unsigned int od_dbs_timer(struct {struct policy_dbs_info *policy_dbs = policy->governor_data;struct dbs_data *dbs_data = policy_dbs->dbs_data; -unsigned int cpu = policy->cpu; -struct od_cpu_dbs_info_s *dbs_info = &per_cpu (od_cpu_dbs_info, - cpu); +struct od_cpu_dbs_info_s *dbs_info = &per_cpu (od_cpu_dbs_info, policy->cpu);struct od_dbs_tuners *od_tuners = dbs_data->tuners;int delay =0 , sample_type = dbs_info->sample_type;
@@ -207,7 +205,7 @@ static unsigned int od_dbs_timer(struct__cpufreq_driver_target (policy, dbs_info->freq_lo,CPUFREQ_RELATION_H ); }else { -dbs_check_cpu (policy, cpu); +dbs_check_cpu (policy);if (dbs_info->freq_lo) {/* Setup timer for SUB_SAMPLE */ dbs_info->sample_type =OD_SUB_SAMPLE ;
drivers/cpufreq/cpufreq_conservative.c +1 -1
@@ -109,7 +109,7 @@ static unsigned int cs_dbs_timer(structstruct dbs_data *dbs_data = policy_dbs->dbs_data;struct cs_dbs_tuners *cs_tuners = dbs_data->tuners; -dbs_check_cpu (policy, policy->cpu); +dbs_check_cpu (policy);return delay_for_sampling_rate (cs_tuners->sampling_rate); }
drivers/cpufreq/cpufreq_governor.c +3 -2
@@ -31,13 +31,14 @@ static struct attribute_group *get_sysfs gov->attr_group_gov_pol : gov->attr_group_gov_sys; } -void dbs_check_cpu (struct cpufreq_policy *policy,int cpu) +void dbs_check_cpu (struct cpufreq_policy *policy) {struct dbs_governor *gov =dbs_governor_of (policy);struct policy_dbs_info *policy_dbs = policy->governor_data;struct dbs_data *dbs_data = policy_dbs->dbs_data;struct od_dbs_tuners *od_tuners = dbs_data->tuners;struct cs_dbs_tuners *cs_tuners = dbs_data->tuners; +int cpu = policy->cpu;unsigned int sampling_rate;unsigned int max_load =0 ;unsigned int ignore_nice;
@@ -515,7 +516,7 @@ static int cpufreq_governor_limits(struc__cpufreq_driver_target (policy, policy->max,CPUFREQ_RELATION_H ); else if (policy->min > policy->cur) __cpufreq_driver_target(policy, policy->min, CPUFREQ_RELATION_L); -dbs_check_cpu (policy, policy->cpu); +dbs_check_cpu (policy );mutex_unlock (&policy_dbs->timer_mutex);return 0 ;
Re: [PATCH v2 10/10] cpufreq: governor: Drop cpu argument from dbs_check_cpu()
Quoted 6 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Since
policy->cpuis always passed as the second argument todbs_check_cpu(), it is not really necessary to pass it, because the function can obtain that value via its first argument just fine.
Quoted 7 lines
Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/cpufreq/cpufreq_conservative.c | 2 +- drivers/cpufreq/cpufreq_governor.c | 5 +++-- drivers/cpufreq/cpufreq_governor.h | 2 +- drivers/cpufreq/cpufreq_ondemand.c | 6 ++---- 4 files changed, 7 insertions(+), 8 deletions(-)
Signature · 1 line
viresh
PATCH v3 10/10 cpufreq: governor: Drop cpu argument from dbs_check_cpu()
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Since policy->cpu is always passed as the second argument to dbs_check_cpu(), it is not really necessary to pass it, because the function can obtain that value via its first argument just fine.
---
Changes from v2:
- Rebase on top of https://patchwork.kernel.org/patch/8241231/
and on the v3 of [8/10] without [9/10].
--- drivers/cpufreq/cpufreq_conservative.c | 2 +- drivers/cpufreq/cpufreq_governor.c | 8 ++++---- drivers/cpufreq/cpufreq_governor.h | 2 +- drivers/cpufreq/cpufreq_ondemand.c | 6 ++---- 4 files changed, 8 insertions(+), 10 deletions(-)
drivers/cpufreq/cpufreq_governor.h +1 -1
@@ -279,7 +279,7 @@ static ssize_t show_sampling_rate_min_goextern struct mutex dbs_data_mutex;extern struct mutex cpufreq_governor_lock; -void dbs_check_cpu (struct cpufreq_policy *policy,int cpu); +void dbs_check_cpu (struct cpufreq_policy *policy);int cpufreq_governor_dbs (struct cpufreq_policy *policy,unsigned int event); void od_register_powersave_bias_handler(unsigned int (*f) (struct cpufreq_policy *, unsigned int, unsigned int),
drivers/cpufreq/cpufreq_ondemand.c +2 -4
@@ -190,9 +190,7 @@ static void od_check_cpu(int cpu, unsignstatic unsigned int od_dbs_timer (struct cpufreq_policy *policy) {struct dbs_data *dbs_data = policy->governor_data; -unsigned int cpu = policy->cpu; -struct od_cpu_dbs_info_s *dbs_info = &per_cpu (od_cpu_dbs_info, - cpu); +struct od_cpu_dbs_info_s *dbs_info = &per_cpu (od_cpu_dbs_info, policy->cpu);struct od_dbs_tuners *od_tuners = dbs_data->tuners;int delay =0 , sample_type = dbs_info->sample_type;
@@ -203,7 +201,7 @@ static unsigned int od_dbs_timer(struct__cpufreq_driver_target (policy, dbs_info->freq_lo,CPUFREQ_RELATION_H ); }else { -dbs_check_cpu (policy, cpu); +dbs_check_cpu (policy);if (dbs_info->freq_lo) {/* Setup timer for SUB_SAMPLE */ dbs_info->sample_type =OD_SUB_SAMPLE ;
drivers/cpufreq/cpufreq_conservative.c +1 -1
@@ -107,7 +107,7 @@ static unsigned int cs_dbs_timer(structstruct dbs_data *dbs_data = policy->governor_data;struct cs_dbs_tuners *cs_tuners = dbs_data->tuners; -dbs_check_cpu (policy, policy->cpu); +dbs_check_cpu (policy);return delay_for_sampling_rate (cs_tuners->sampling_rate); }
drivers/cpufreq/cpufreq_governor.c +4 -4
@@ -31,8 +31,9 @@ static struct attribute_group *get_sysfs gov->attr_group_gov_pol : gov->attr_group_gov_sys; } -void dbs_check_cpu (struct cpufreq_policy *policy,int cpu) +void dbs_check_cpu (struct cpufreq_policy *policy) { +int cpu = policy->cpu;struct dbs_governor *gov =dbs_governor_of (policy);struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs (cpu);struct dbs_data *dbs_data = policy->governor_data;
@@ -516,8 +517,7 @@ static int cpufreq_governor_stop(structstatic int cpufreq_governor_limits (struct cpufreq_policy *policy) {struct dbs_governor *gov =dbs_governor_of (policy); -unsigned int cpu = policy->cpu; -struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs (cpu); +struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs (policy->cpu);/* State should be equivalent to START */ if (!cdbs->policy_dbs || !cdbs->policy_dbs->policy)
@@ -530,7 +530,7 @@ static int cpufreq_governor_limits(strucelse if (policy->min > cdbs->policy_dbs->policy->cur)__cpufreq_driver_target (cdbs->policy_dbs->policy, policy->min,CPUFREQ_RELATION_L ); -dbs_check_cpu (policy, cpu); +dbs_check_cpu (policy);mutex_unlock (&cdbs->policy_dbs->timer_mutex);return 0 ;
Re: [PATCH v3 10/10] cpufreq: governor: Drop cpu argument from dbs_check_cpu()
Quoted 6 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Since
policy->cpuis always passed as the second argument todbs_check_cpu(), it is not really necessary to pass it, because the function can obtain that value via its first argument just fine.
Quoted 6 lines
Signed-off-by Rafael J. Wysocki <[email protected]>---
Changes from v2:
- Rebase on top of https://patchwork.kernel.org/patch/8241231/
and on the v3 of [8/10] without [9/10].
Signature · 1 line
viresh
Quoted 49 lines · Rafael J. Wysocki
Quoted 31 lines · Rafael J. Wysocki
Hi,
A few days ago I looked at the common code used by the ondemand and conservative governors because of the deadlock issue that Viresh has addressed recently
(http://marc.info/?l=linux-pm&m=145450832814058&w=4) and it occurred to me that the whole thing was really too tangled and might be made easier to follow at least. I started to work on this and ended up with the following series.I'm not really going to stop here, but first, I'd like to let everybody know that this is happening and second, I'll need to rebase these patches on the ones from Viresh (in the series linked above), but that may take some time and I don't want to sit on them for all that long.
Overall, I'd like the governor code to be cleaner and easier to follow, so we can move at least some parts of governor work to utilization update callbacks (invoked by the scheduler) or to at least to
irq_workso as to reduce the usage of process context in cpufreq to absolute minimum. That's the plan for the future, but for now this is just a major cleanup.[1/11] Clean up the way in which the default and fallback governors are set up. [2/11] Use a common global mutex for
dbs_dataprotection.
[3/11] Use common global pointer todbs_datafor system-wide governors. [4/11] Avoid passingdbs_datapointers to functions that can get them by themselves. [5/11] Make struct governor be a member of structcommon_dbs_data.
[6/11] Rename structcommon_dbs_datato structdbs_governor.
[7/11] Reworkcpufreq_governor_dbs()so it can be used as a governor callback directly. [8/11] Drop thedbs_governor(former cdata) pointer from structdbs_data. [9/11] Rename structcpu_common_dbs_infoto structpolicy_dbs_info.
[10/11] Rearrange data structures sopolicy->governor_datapoints to structpolicy_dbs_info. [11/11] Drop the second argument ofdbs_check_cpu().Quoted 3 lines
The patches are on top of 4.5-rc2 with my earlier series replacing timers with utilization update callbacks (http://marc.info/?l=linux-kernel&m=145410842801883&w=4)
applied.Some bugs fixed, some comments addressed. It's time for a v2. :-)
The most significant difference from the previous one is that I've dropped patch [3/11] (so there are 10 of them in the series now) due to a problem with it pointed out by Viresh. Fortunately, this particular one was completely not essential and the dependencies on it were rather cosmetic.
In addition to that I've rebased the series on top of
https://patchwork.kernel.org/patch/8229901/ as that differs from its previous version quite a bit.I've already queued up [1/10] for 4.6 as it seems totally uncontroversial.
Quoted 7 lines
The whole series (along with some patches it depends on) is available from the git branch at
git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.gitpm-cpufreq-rjwin case someone wants to try it. I've tested it (very lightly) on an x86 laptop with the ACPI cpufreq driver and the ondemand governor.
I'm going to tentatively queue up patches [2-8,10/10] with Viresh's ACKs (thanks Viresh!) for 4.6 (tentatively, because they depend on the timers elimination series which is still under ongoing review, but that seems to be reaching conclusion).
Patches [8,10/10] needed a non-trivial rebase, so I'll post the new versions shortly for completeness.
I'm going to rework patch [9/10] on top of that into a few separate patches that will hopefully be easier to digest.
Thanks,
Rafael
cover cpufreq: governor: Data structure rearrangement
In reply to Rafael J. WysockiHi,
This was part of my recent cleanup series
(http://marc.info/?l=linux-pm&m=145463901630950&w=4), but Viresh had a good point about the patch doing too much and possibly going too far, so I've reworked it into a series of three smaller patches and dropped some more aggressive changes.
[1/3] simplifies cpufreq_governor_limits() to access the policy via its
argument directly.
[2/3] rearranges the data structures so policy->governor_data points to the
struct policy_dbs corresponding to that policy and the latter points to a struct dbs_data.
[3/3] makes the initialization and cleanup of struct cpu_dbs_info more
symmetrical.
Patches are on top of my bleeding-edge branch (and there is a separate pm-cpufreq-test branch with cpufreq patches only in case someone wants/needs to test those alone).
Thanks,
Rafael
PATCH 1/3 cpufreq: governor: Simplify cpufreq_governor_limits()
From: Rafael J. Wysocki <[email protected]>
Use the observation that cpufreq_governor_limits() doesn't have to get to the policy object it wants to manipulate by walking the reference chain cdbs->policy_dbs->policy, as the final pointer is actually equal to its argument, and make it access the policy object directy via its argument.
--- drivers/cpufreq/cpufreq_governor.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
drivers/cpufreq/cpufreq_governor.c +8 -9
@@ -518,20 +518,19 @@ static int cpufreq_governor_limits(struc {struct dbs_governor *gov =dbs_governor_of (policy);struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs (policy->cpu); +struct policy_dbs_info *policy_dbs = cdbs->policy_dbs;/* State should be equivalent to START */ -if (!cdbs->policy_dbs || !cdbs->policy_dbs->policy) +if (!policy_dbs || !policy_dbs->policy)return -EBUSY ; -mutex_lock (&cdbs->policy_dbs->timer_mutex); -if (policy->max < cdbs->policy_dbs->policy->cur) -__cpufreq_driver_target (cdbs->policy_dbs->policy, policy->max, -CPUFREQ_RELATION_H ); -else if (policy->min > cdbs->policy_dbs->policy->cur) -__cpufreq_driver_target (cdbs->policy_dbs->policy, policy->min, -CPUFREQ_RELATION_L ); +mutex_lock (&policy_dbs->timer_mutex); +if (policy->max < policy->cur) +__cpufreq_driver_target (policy, policy->max,CPUFREQ_RELATION_H ); +else if (policy->min > policy->cur) +__cpufreq_driver_target (policy, policy->min,CPUFREQ_RELATION_L );dbs_check_cpu (policy); -mutex_unlock (&cdbs->policy_dbs->timer_mutex); +mutex_unlock (&policy_dbs->timer_mutex);return 0 ; }
Re: [PATCH 1/3] cpufreq: governor: Simplify cpufreq_governor_limits()
Quoted 8 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Use the observation that
cpufreq_governor_limits()doesn't have to get to the policy object it wants to manipulate by walking the reference chaincdbs->policy_dbs->policy, as the final pointer is actually equal to its argument, and make it access the policy object directy via its argument.
Quoted 4 lines
Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/cpufreq/cpufreq_governor.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
Why the hell did we write it that way earlier ? :)
Signature · 1 line
viresh
Re: [PATCH 1/3] cpufreq: governor: Simplify cpufreq_governor_limits()
Quoted 9 lines · Viresh Kumar
Quoted 8 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Use the observation that
cpufreq_governor_limits()doesn't have to get to the policy object it wants to manipulate by walking the reference chaincdbs->policy_dbs->policy, as the final pointer is actually equal to its argument, and make it access the policy object directy via its argument.
Quoted 6 lines
Quoted 4 lines
Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/cpufreq/cpufreq_governor.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)Why the hell did we write it that way earlier ? :)
Honestly, I have no idea.
Quoted 1 line
Acked-by Viresh Kumar <[email protected]>
Thanks!
PATCH 2/3 cpufreq: governor: Rearrange governor data structures
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
The struct policy_dbs_info objects representing per-policy governor data are not accessible directly from the corresponding policy objects. To access them, one has to get a pointer to the struct cpu_dbs_info of policy->cpu and use the policy_dbs field of that which isn't really straightforward.
To address that rearrange the governor data structures so the governor_data pointer in struct cpufreq_policy will point to struct policy_dbs_info (instead of struct dbs_data) and that will contain a pointer to struct dbs_data.
--- drivers/cpufreq/amd_freq_sensitivity.c | 3 - drivers/cpufreq/cpufreq_conservative.c | 6 +- drivers/cpufreq/cpufreq_governor.c | 74 ++++++++++++++++----------------- drivers/cpufreq/cpufreq_governor.h | 27 ++++++------ drivers/cpufreq/cpufreq_ondemand.c | 18 ++++---- 5 files changed, 68 insertions(+), 60 deletions(-)
drivers/cpufreq/cpufreq_governor.h +15 -12
@@ -85,7 +85,8 @@ static ssize_t show_##file_name##_gov_sy static ssize_t show_##file_name##_gov_pol \ (struct cpufreq_policy *policy, char *buf) \ { \ - struct dbs_data *dbs_data = policy->governor_data; \ + struct policy_dbs_info *policy_dbs = policy->governor_data; \ + struct dbs_data *dbs_data = policy_dbs->dbs_data; \ struct _gov##_dbs_tuners *tuners = dbs_data->tuners; \ return sprintf(buf, "%u\n", tuners->file_name); \ }
@@ -101,8 +102,8 @@ static ssize_t store_##file_name##_gov_s static ssize_t store_##file_name##_gov_pol \ (struct cpufreq_policy *policy, const char *buf, size_t count) \ { \ - struct dbs_data *dbs_data = policy->governor_data; \ - return store_##file_name(dbs_data, buf, count); \ + struct policy_dbs_info *policy_dbs = policy->governor_data; \ + return store_##file_name(policy_dbs->dbs_data, buf, count); \ }#define show_store_one (_gov, file_name) \
@@ -130,6 +131,13 @@ static void *get_cpu_dbs_info_s(int cpu)* cs_*: Conservative governor */ +/* Governor demand based switching data (per-policy or global). */ +struct dbs_data { +unsigned int min_sampling_rate; +int usage_count; +void *tuners; +}; +/* Common to all CPUs of a policy */ struct policy_dbs_info {struct cpufreq_policy *policy;
@@ -144,6 +152,8 @@ struct policy_dbs_info {atomic_t skip_work;struct irq_work irq_work;struct work_struct work; +/* dbs_data may be shared between multiple policy objects */ +struct dbs_data *dbs_data; }; static inline void gov_update_sample_delay(struct policy_dbs_info *policy_dbs,
@@ -204,7 +214,6 @@ struct cs_dbs_tuners { };/* Common Governor data across policies */ -struct dbs_data ;struct dbs_governor {struct cpufreq_governor gov;
@@ -236,13 +245,6 @@ static inline struct dbs_governor *dbs_g return container_of(policy->governor, struct dbs_governor, gov); } -/* Governor Per policy data */ -struct dbs_data { -unsigned int min_sampling_rate; -int usage_count; -void *tuners; -}; -/* Governor specific ops, will be passed to dbs_data->gov_ops */ struct od_ops {void (*powersave_bias_init_cpu)(int cpu);
@@ -273,7 +275,8 @@ static ssize_t show_sampling_rate_min_gostatic ssize_t show_sampling_rate_min_gov_pol \ (struct cpufreq_policy *policy,char *buf) \ { \ -struct dbs_data *dbs_data = policy->governor_data; \ +struct policy_dbs_info *policy_dbs = policy->governor_data; \ +struct dbs_data *dbs_data = policy_dbs->dbs_data; \return sprintf (buf,"%u\n" , dbs_data->min_sampling_rate); \ }
drivers/cpufreq/cpufreq_governor.c +36 -38
173 lines not on this page · raw message
drivers/cpufreq/cpufreq_ondemand.c +11 -7
@@ -78,7 +78,8 @@ static unsigned int generic_powersave_biunsigned int jiffies_total, jiffies_hi, jiffies_lo;struct od_cpu_dbs_info_s *dbs_info = &per_cpu (od_cpu_dbs_info, policy->cpu); -struct dbs_data *dbs_data = policy->governor_data; +struct policy_dbs_info *policy_dbs = policy->governor_data; +struct dbs_data *dbs_data = policy_dbs->dbs_data;struct od_dbs_tuners *od_tuners = dbs_data->tuners;if (!dbs_info->freq_table) {
@@ -130,7 +131,8 @@ static void ondemand_powersave_bias_initstatic void dbs_freq_increase (struct cpufreq_policy *policy,unsigned int freq) { -struct dbs_data *dbs_data = policy->governor_data; +struct policy_dbs_info *policy_dbs = policy->governor_data; +struct dbs_data *dbs_data = policy_dbs->dbs_data;struct od_dbs_tuners *od_tuners = dbs_data->tuners;if (od_tuners->powersave_bias)
@@ -151,8 +153,9 @@ static void dbs_freq_increase(struct cpustatic void od_check_cpu (int cpu,unsigned int load) {struct od_cpu_dbs_info_s *dbs_info = &per_cpu (od_cpu_dbs_info, cpu); -struct cpufreq_policy *policy = dbs_info->cdbs.policy_dbs->policy; -struct dbs_data *dbs_data = policy->governor_data; +struct policy_dbs_info *policy_dbs = dbs_info->cdbs.policy_dbs; +struct cpufreq_policy *policy = policy_dbs->policy; +struct dbs_data *dbs_data = policy_dbs->dbs_data;struct od_dbs_tuners *od_tuners = dbs_data->tuners; dbs_info->freq_lo =0 ;
@@ -189,7 +192,8 @@ static void od_check_cpu(int cpu, unsignstatic unsigned int od_dbs_timer (struct cpufreq_policy *policy) { -struct dbs_data *dbs_data = policy->governor_data; +struct policy_dbs_info *policy_dbs = policy->governor_data; +struct dbs_data *dbs_data = policy_dbs->dbs_data;struct od_cpu_dbs_info_s *dbs_info = &per_cpu (od_cpu_dbs_info, policy->cpu);struct od_dbs_tuners *od_tuners = dbs_data->tuners;int delay =0 , sample_type = dbs_info->sample_type;
@@ -277,7 +281,7 @@ static void update_sampling_rate(struct* policy will be governed by dbs_data, otherwise there can be * multiple policies that are governed by the same dbs_data. */ -if (dbs_data == policy->governor_data) { +if (dbs_data == policy_dbs->dbs_data) {mutex_lock (&policy_dbs->timer_mutex);/* * On 32-bit architectures this may race with the
@@ -586,7 +590,7 @@ static void od_set_powersave_bias(unsignif (policy->governor !=CPU_FREQ_GOV_ONDEMAND )continue ; - dbs_data = policy->governor_data; + dbs_data = policy_dbs->dbs_data; od_tuners = dbs_data->tuners; od_tuners->powersave_bias = default_powersave_bias; }
drivers/cpufreq/amd_freq_sensitivity.c +2 -1
@@ -45,7 +45,8 @@ static unsigned int amd_powersave_bias_tlong d_actual, d_reference;struct msr actual, reference;struct cpu_data_t *data = &per_cpu (cpu_data, policy->cpu); -struct dbs_data *od_data = policy->governor_data; +struct policy_dbs_info *policy_dbs = policy->governor_data; +struct dbs_data *od_data = policy_dbs->dbs_data;struct od_dbs_tuners *od_tuners = od_data->tuners;struct od_cpu_dbs_info_s *od_info =dbs_governor_of (policy)->get_cpu_dbs_info_s (policy->cpu);
drivers/cpufreq/cpufreq_conservative.c +4 -2
@@ -48,7 +48,8 @@ static void cs_check_cpu(int cpu, unsign {struct cs_cpu_dbs_info_s *dbs_info = &per_cpu (cs_cpu_dbs_info, cpu);struct cpufreq_policy *policy = dbs_info->cdbs.policy_dbs->policy; -struct dbs_data *dbs_data = policy->governor_data; +struct policy_dbs_info *policy_dbs = policy->governor_data; +struct dbs_data *dbs_data = policy_dbs->dbs_data;struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;/*
@@ -104,7 +105,8 @@ static void cs_check_cpu(int cpu, unsignstatic unsigned int cs_dbs_timer (struct cpufreq_policy *policy) { -struct dbs_data *dbs_data = policy->governor_data; +struct policy_dbs_info *policy_dbs = policy->governor_data; +struct dbs_data *dbs_data = policy_dbs->dbs_data;struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;dbs_check_cpu (policy);
Viresh Kumar
maintainerRe: [PATCH 2/3] cpufreq: governor: Rearrange governor data structures
drivers/cpufreq/cpufreq_governor.c reset_gdbs_data: · line 416
Quoted 12 lines · Rafael J. Wysocki
static int
cpufreq_governor_exit(struct cpufreq_policy *policy){drivers/cpufreq/cpufreq_governor.c +3
-3struct dbs_governor *gov =dbs_governor_of (policy); -struct dbs_data *dbs_data = policy->governor_data; -struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs (policy->cpu); +struct policy_dbs_info *policy_dbs = policy->governor_data; +struct dbs_data *dbs_data = policy_dbs->dbs_data;/* State should be equivalent to INIT */ -if (!cdbs->policy_dbs || cdbs->policy_dbs->policy) +if (policy_dbs->policy)return -EBUSY ;
We can crash here if policy_dbs is NULL, which can happen if EXIT is called twice (due to the lock-dropping thing in cpufreq-core). So we really need to keep these checks for now atleast.
Signature · 1 line
viresh
Viresh Kumar
maintainerRe: [PATCH 2/3] cpufreq: governor: Rearrange governor data structures
Quoted 9 lines · Viresh Kumar
Quoted 8 lines · Rafael J. Wysocki
static int
cpufreq_governor_exit(struct cpufreq_policy *policy){drivers/cpufreq/cpufreq_governor.c +2
-2struct dbs_governor *gov =dbs_governor_of (policy); -struct dbs_data *dbs_data = policy->governor_data; -struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs (policy->cpu); +struct policy_dbs_info *policy_dbs = policy->governor_data; +struct dbs_data *dbs_data = policy_dbs->dbs_data;
Quoted 8 lines
drivers/cpufreq/cpufreq_governor.c reset_gdbs_data: · line 416
Quoted 4 lines
drivers/cpufreq/cpufreq_governor.c +1
-1/* State should be equivalent to INIT */ -if (!cdbs->policy_dbs || cdbs->policy_dbs->policy) +if (policy_dbs->policy)return -EBUSY ;We can crash here if
policy_dbsis NULL, which can happen if EXIT is called twice (due to the lock-dropping thing in cpufreq-core). So we really need to keep these checks for now atleast.
Well no, things have changed now a bit with your recent changes and so this wouldn't be an issue here. Sorry for the noise.
Signature · 1 line
viresh
Re: [PATCH 2/3] cpufreq: governor: Rearrange governor data structures
In reply to Rafael J. WysockiQuoted 13 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
The struct
policy_dbs_infoobjects representing per-policy governor data are not accessible directly from the corresponding policy objects. To access them, one has to get a pointer to the structcpu_dbs_infoofpolicy->cpuand use thepolicy_dbsfield of that which isn't really straightforward.To address that rearrange the governor data structures so the
governor_datapointer in structcpufreq_policywill point to structpolicy_dbs_info(instead of structdbs_data) and that will contain a pointer to structdbs_data.
Quoted 8 lines
Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/cpufreq/amd_freq_sensitivity.c | 3 - drivers/cpufreq/cpufreq_conservative.c | 6 +- drivers/cpufreq/cpufreq_governor.c | 74 ++++++++++++++++----------------- drivers/cpufreq/cpufreq_governor.h | 27 ++++++------ drivers/cpufreq/cpufreq_ondemand.c | 18 ++++---- 5 files changed, 68 insertions(+), 60 deletions(-)
Signature · 1 line
viresh
PATCH 3/3 cpufreq: governor: Symmetrize cpu_dbs_info initialization and cleanup
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Make the initialization of struct cpu_dbs_info objects in alloc_policy_dbs_info() and the code that cleans them up in free_policy_dbs_info() more symmetrical. In particular, set/clear the update_util.func field in those functions along with the policy_dbs field.
--- drivers/cpufreq/cpufreq_governor.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)
drivers/cpufreq/cpufreq_governor.c +13 -8
@@ -303,14 +303,18 @@ static struct policy_dbs_info *alloc_polif (!policy_dbs)return NULL ; -/* Set policy_dbs for all CPUs, online+offline */ -for_each_cpu (j, policy->related_cpus) - gov->get_cpu_cdbs (j)->policy_dbs = policy_dbs; -mutex_init (&policy_dbs->timer_mutex);atomic_set (&policy_dbs->skip_work,0 );init_irq_work (&policy_dbs->irq_work, dbs_irq_work);INIT_WORK (&policy_dbs->work, dbs_work_handler); + +/* Set policy_dbs for all CPUs, online+offline */ +for_each_cpu (j, policy->related_cpus) { +struct cpu_dbs_info *j_cdbs = gov->get_cpu_cdbs (j); + + j_cdbs->policy_dbs = policy_dbs; + j_cdbs->update_util.func = dbs_update_util_handler; + }return policy_dbs; }
@@ -323,9 +327,12 @@ static void free_policy_dbs_info(structmutex_destroy (&policy_dbs->timer_mutex); -for_each_cpu (j, policy->cpus) - gov->get_cpu_cdbs (j)->policy_dbs =NULL ; +for_each_cpu (j, policy->related_cpus) { +struct cpu_dbs_info *j_cdbs = gov->get_cpu_cdbs (j); + j_cdbs->policy_dbs =NULL ; + j_cdbs->update_util.func =NULL ; + }kfree (policy_dbs); }
@@ -476,8 +483,6 @@ static int cpufreq_governor_start(structif (ignore_nice) j_cdbs->prev_cpu_nice =kcpustat_cpu (j).cpustat[CPUTIME_NICE ]; - - j_cdbs->update_util.func = dbs_update_util_handler; } policy_dbs->policy = policy;
Re: [PATCH 3/3] cpufreq: governor: Symmetrize cpu_dbs_info initialization and cleanup
Quoted 8 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Make the initialization of struct
cpu_dbs_infoobjects inalloc_policy_dbs_info()and the code that cleans them up infree_policy_dbs_info()more symmetrical. In particular, set/clear the update_util.func field in those functions along with thepolicy_dbsfield.
Quoted 4 lines
Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/cpufreq/cpufreq_governor.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)
Signature · 1 line
viresh