cpufreq: Introduce macros for cpufreq_frequency_table iteration
Subsystems (2)
PATCH v2 1/8 cpufreq: Introduce macros for cpufreq_frequency_table iteration
Many cpufreq drivers need to iterate over the cpufreq_frequency_table for various tasks.
This patch introduces two macros which can be used for iteration over cpufreq_frequency_table keeping a common coding style across drivers:
- cpufreq_for_each_entry: iterate over each entry of the table
- cpufreq_for_each_valid_entry: iterate over each entry that contains a valid frequency.
It should have no functional changes.
--- Documentation/cpu-freq/cpu-drivers.txt | 16 ++++++++++++++++ drivers/cpufreq/cpufreq.c | 11 +++++++++++ include/linux/cpufreq.h | 21 +++++++++++++++++++++ 3 files changed, 48 insertions(+)
Documentation/cpu-freq/cpu-drivers.txt +16 -0
@@ -228,3 +228,19 @@ is the corresponding frequency table helper for the ->target stage. Just pass the values to this function, and the unsigned int index returns the number of the frequency table entry which contains the frequency the CPU shall be set to. + +The following macros can be used as iterators over cpufreq_frequency_table: +cpufreq_for_each_entry(pos, table) - iterates over all entries of frequency +table. +cpufreq-for_each_valid_entry(pos, table) - iterates over all entries, +excluding CPUFREQ_ENTRY_INVALID frequencies. +Use arguments "pos" - a cpufreq_frequency_table * as a loop cursor and +"table" - the cpufreq_frequency_table * you want to iterate over. +For example: + + struct cpufreq_frequency_table *pos, *driver_freq_table; + + cpufreq_for_each_entry(pos, driver_freq_table) { + /* Do something with pos */ + pos->frequency = ... + }
drivers/cpufreq/cpufreq.c +11 -0
@@ -237,6 +237,17 @@ void cpufreq_cpu_put(struct cpufreq_policy *policy) }EXPORT_SYMBOL_GPL (cpufreq_cpu_put); +bool cpufreq_next_valid (struct cpufreq_frequency_table **pos) +{ +while ((*pos)->frequency !=CPUFREQ_TABLE_END ) +if ((*pos)->frequency !=CPUFREQ_ENTRY_INVALID ) +return true; +else + (*pos)++; +return false; +} +EXPORT_SYMBOL_GPL (cpufreq_next_valid); +/********************************************************************* * EXTERNALLY AFFECTING FREQUENCY CHANGES * *********************************************************************/
include/linux/cpufreq.h +21 -0
@@ -468,6 +468,27 @@ struct cpufreq_frequency_table {* order */ }; +bool cpufreq_next_valid (struct cpufreq_frequency_table **pos); + +/* +* cpufreq_for_each_entry - iterate over a cpufreq_frequency_table +* @pos: the cpufreq_frequency_table * to use as a loop cursor. +* @table: the cpufreq_frequency_table * to iterate over. +*/ + +#define cpufreq_for_each_entry (pos, table) \ + for (pos = table; pos->frequency != CPUFREQ_TABLE_END; pos++) + +/* +* cpufreq_for_each_valid_entry - iterate over a cpufreq_frequency_table +* exluding CPUFREQ_ENTRY_INVALID frequencies. +* @pos: the cpufreq_frequency_table * to use as a loop cursor. +* @table: the cpufreq_frequency_table * to iterate over. +*/ + +#define cpufreq_for_each_valid_entry (pos, table) \ + for (pos = table; cpufreq_next_valid(&pos); pos++) +int cpufreq_frequency_table_cpuinfo (struct cpufreq_policy *policy,struct cpufreq_frequency_table *table);
Signature · 1 line
1.9.0
Randy Dunlap
reviewerQuoted 24 lines · Stratos Karafotis
Many cpufreq drivers need to iterate over the
cpufreq_frequency_tablefor various tasks.This patch introduces two macros which can be used for iteration over
cpufreq_frequency_tablekeeping a common coding style across drivers:-
cpufreq_for_each_entry: iterate over each entry of the table
-cpufreq_for_each_valid_entry: iterate over each entry that contains a valid frequency.It should have no functional changes.
Signed-off-by Stratos Karafotis <[email protected]>--- Documentation/cpu-freq/cpu-drivers.txt | 16 ++++++++++++++++ drivers/cpufreq/cpufreq.c | 11 +++++++++++ include/linux/cpufreq.h | 21 +++++++++++++++++++++ 3 files changed, 48 insertions(+)Documentation/cpu-freq/cpu-drivers.txt +0
-0
Documentation/cpu-freq/cpu-drivers.txt is the corresponding frequency table helper for the ->target · line 232
Quoted 5 lines
Documentation/cpu-freq/cpu-drivers.txt +2
-0@@ -228,3 +228,19 @@ is the corresponding frequency table helper for the ->target stage. Just pass the values to this function, and the unsigned int index returns the number of the frequency table entry which contains the frequency the CPU shall be set to. + +The following macros can be used as iterators over cpufreq_frequency_table:
<insert blank line>
Documentation/cpu-freq/cpu-drivers.txt is the corresponding frequency table helper for the ->target · line 234
Quoted 2 lines
Documentation/cpu-freq/cpu-drivers.txt +2
-0+cpufreq_for_each_entry(pos, table) - iterates over all entries of frequency +table.
<insert blank line>
Documentation/cpu-freq/cpu-drivers.txt is the corresponding frequency table helper for the ->target · line 238
Quoted 4 lines
Documentation/cpu-freq/cpu-drivers.txt +4
-0+cpufreq-for_each_valid_entry(pos, table) - iterates over all entries, +excluding CPUFREQ_ENTRY_INVALID frequencies. +Use arguments "pos" - a cpufreq_frequency_table * as a loop cursor and +"table" - the cpufreq_frequency_table * you want to iterate over.
<insert blank line>
Quoted 21 lines
Documentation/cpu-freq/cpu-drivers.txt +8
-0+For example: + + struct cpufreq_frequency_table *pos, *driver_freq_table; + + cpufreq_for_each_entry(pos, driver_freq_table) { + /* Do something with pos */ + pos->frequency = ... + }include/linux/cpufreq.h +4
-0@@ -468,6 +468,27 @@ struct cpufreq_frequency_table {* order */ }; +bool cpufreq_next_valid (struct cpufreq_frequency_table **pos); + +/* +* cpufreq_for_each_entry - iterate over a cpufreq_frequency_table
include/linux/cpufreq.h struct cpufreq_frequency_table { · line 484
Quoted 10 lines
include/linux/cpufreq.h +10
-0+* @pos: the cpufreq_frequency_table * to use as a loop cursor. +* @table: the cpufreq_frequency_table * to iterate over. +*/ + +#define cpufreq_for_each_entry (pos, table) \ + for (pos = table; pos->frequency != CPUFREQ_TABLE_END; pos++) + +/* +* cpufreq_for_each_valid_entry - iterate over a cpufreq_frequency_table +* exluding CPUFREQ_ENTRY_INVALID frequencies.
excluding
Quoted 11 lines
include/linux/cpufreq.h +7
-0+* @pos: the cpufreq_frequency_table * to use as a loop cursor. +* @table: the cpufreq_frequency_table * to iterate over. +*/ + +#define cpufreq_for_each_valid_entry (pos, table) \ + for (pos = table; cpufreq_next_valid(&pos); pos++) +int cpufreq_frequency_table_cpuinfo (struct cpufreq_policy *policy,struct cpufreq_frequency_table *table);
Signature · 1 line
~Randy