Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ffd81dcf authored by Dominik Brodowski's avatar Dominik Brodowski Committed by Rafael J. Wysocki
Browse files

cpufreq: Add and use cpufreq_for_each_{valid_,}entry_idx()



Pointer subtraction is slow and tedious. Therefore, replace all instances
where cpufreq_for_each_{valid_,}entry loops contained such substractions
with an iteration macro providing an index to the frequency_table entry.

Suggested-by: default avatarAl Viro <viro@ZenIV.linux.org.uk>
Link: http://lkml.kernel.org/r/20180120020237.GM13338@ZenIV.linux.org.uk


Acked-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: default avatarDominik Brodowski <linux@dominikbrodowski.net>
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent 70f6bf2a
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -291,3 +291,7 @@ For example:
		/* Do something with pos */
		pos->frequency = ...
	}

If you need to work with the position of pos within driver_freq_table,
do not subtract the pointers, as it is quite costly. Instead, use the
macros cpufreq_for_each_entry_idx() and cpufreq_for_each_valid_entry_idx().
+3 −4
Original line number Diff line number Diff line
@@ -115,10 +115,10 @@ static struct cpufreq_freqs freqs;
static int init_div_table(void)
{
	struct cpufreq_frequency_table *pos, *freq_tbl = dvfs_info->freq_table;
	unsigned int tmp, clk_div, ema_div, freq, volt_id;
	unsigned int tmp, clk_div, ema_div, freq, volt_id, idx;
	struct dev_pm_opp *opp;

	cpufreq_for_each_entry(pos, freq_tbl) {
	cpufreq_for_each_entry_idx(pos, freq_tbl, idx) {
		opp = dev_pm_opp_find_freq_exact(dvfs_info->dev,
					pos->frequency * 1000, true);
		if (IS_ERR(opp)) {
@@ -154,8 +154,7 @@ static int init_div_table(void)
		tmp = (clk_div | ema_div | (volt_id << P0_7_VDD_SHIFT)
			| ((freq / FREQ_UNIT) << P0_7_FREQ_SHIFT));

		__raw_writel(tmp, dvfs_info->base + XMU_PMU_P0_7 + 4 *
						(pos - freq_tbl));
		__raw_writel(tmp, dvfs_info->base + XMU_PMU_P0_7 + 4 * idx);
		dev_pm_opp_put(opp);
	}

+4 −4
Original line number Diff line number Diff line
@@ -143,10 +143,9 @@ int cpufreq_table_index_unsorted(struct cpufreq_policy *policy,
		break;
	}

	cpufreq_for_each_valid_entry(pos, table) {
	cpufreq_for_each_valid_entry_idx(pos, table, i) {
		freq = pos->frequency;

		i = pos - table;
		if ((freq < policy->min) || (freq > policy->max))
			continue;
		if (freq == target_freq) {
@@ -211,15 +210,16 @@ int cpufreq_frequency_table_get_index(struct cpufreq_policy *policy,
		unsigned int freq)
{
	struct cpufreq_frequency_table *pos, *table = policy->freq_table;
	int idx;

	if (unlikely(!table)) {
		pr_debug("%s: Unable to find frequency table\n", __func__);
		return -ENOENT;
	}

	cpufreq_for_each_valid_entry(pos, table)
	cpufreq_for_each_valid_entry_idx(pos, table, idx)
		if (pos->frequency == freq)
			return pos - table;
			return idx;

	return -EINVAL;
}
+2 −2
Original line number Diff line number Diff line
@@ -600,7 +600,7 @@ static void longhaul_setup_voltagescaling(void)
	/* Calculate kHz for one voltage step */
	kHz_step = (highest_speed - min_vid_speed) / numvscales;

	cpufreq_for_each_entry(freq_pos, longhaul_table) {
	cpufreq_for_each_entry_idx(freq_pos, longhaul_table, j) {
		speed = freq_pos->frequency;
		if (speed > min_vid_speed)
			pos = (speed - min_vid_speed) / kHz_step + minvid.pos;
@@ -609,7 +609,7 @@ static void longhaul_setup_voltagescaling(void)
		freq_pos->driver_data |= mV_vrm_table[pos] << 8;
		vid = vrm_mV_table[mV_vrm_table[pos]];
		pr_info("f: %d kHz, index: %d, vid: %d mV\n",
			speed, (int)(freq_pos - longhaul_table), vid.mV);
			speed, j, vid.mV);
	}

	can_scale_voltage = 1;
+3 −3
Original line number Diff line number Diff line
@@ -139,7 +139,7 @@ static int pas_cpufreq_cpu_init(struct cpufreq_policy *policy)
	struct cpufreq_frequency_table *pos;
	const u32 *max_freqp;
	u32 max_freq;
	int cur_astate;
	int cur_astate, idx;
	struct resource res;
	struct device_node *cpu, *dn;
	int err = -ENODEV;
@@ -198,9 +198,9 @@ static int pas_cpufreq_cpu_init(struct cpufreq_policy *policy)
	pr_debug("initializing frequency table\n");

	/* initialize frequency table */
	cpufreq_for_each_entry(pos, pas_freqs) {
	cpufreq_for_each_entry_idx(pos, pas_freqs, idx) {
		pos->frequency = get_astate_freq(pos->driver_data) * 100000;
		pr_debug("%d: %d\n", (int)(pos - pas_freqs), pos->frequency);
		pr_debug("%d: %d\n", idx, pos->frequency);
	}

	cur_astate = get_cur_astate(policy->cpu);
Loading