Skip to content

Commit 067b7ce

Browse files
Jisheng Zhangrafaeljw
authored andcommitted
PM / OPP: optimize dev_pm_opp_set_rate() performance a bit
In dev_pm_opp_set_rate(), _find_opp_table() is called 4 times: once by _get_opp_clk(), once by dev_pm_opp_set_rate() itself, and twice by dev_pm_opp_find_freq_ceil(). If there are several opp_tables in the system, three times of opp table finding is a big waste. This patch reduced the call of _find_opp_table() to twice. Signed-off-by: Jisheng Zhang <jszhang@marvell.com> Acked-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 523d939 commit 067b7ce

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

drivers/base/power/opp/core.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,22 @@ struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
402402
}
403403
EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_exact);
404404

405+
static noinline struct dev_pm_opp *_find_freq_ceil(struct opp_table *opp_table,
406+
unsigned long *freq)
407+
{
408+
struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ERANGE);
409+
410+
list_for_each_entry_rcu(temp_opp, &opp_table->opp_list, node) {
411+
if (temp_opp->available && temp_opp->rate >= *freq) {
412+
opp = temp_opp;
413+
*freq = opp->rate;
414+
break;
415+
}
416+
}
417+
418+
return opp;
419+
}
420+
405421
/**
406422
* dev_pm_opp_find_freq_ceil() - Search for an rounded ceil freq
407423
* @dev: device for which we do this operation
@@ -427,7 +443,6 @@ struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
427443
unsigned long *freq)
428444
{
429445
struct opp_table *opp_table;
430-
struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ERANGE);
431446

432447
opp_rcu_lockdep_assert();
433448

@@ -440,15 +455,7 @@ struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
440455
if (IS_ERR(opp_table))
441456
return ERR_CAST(opp_table);
442457

443-
list_for_each_entry_rcu(temp_opp, &opp_table->opp_list, node) {
444-
if (temp_opp->available && temp_opp->rate >= *freq) {
445-
opp = temp_opp;
446-
*freq = opp->rate;
447-
break;
448-
}
449-
}
450-
451-
return opp;
458+
return _find_freq_ceil(opp_table, freq);
452459
}
453460
EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_ceil);
454461

@@ -612,7 +619,7 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
612619
return PTR_ERR(opp_table);
613620
}
614621

615-
old_opp = dev_pm_opp_find_freq_ceil(dev, &old_freq);
622+
old_opp = _find_freq_ceil(opp_table, &old_freq);
616623
if (!IS_ERR(old_opp)) {
617624
ou_volt = old_opp->u_volt;
618625
ou_volt_min = old_opp->u_volt_min;
@@ -622,7 +629,7 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
622629
__func__, old_freq, PTR_ERR(old_opp));
623630
}
624631

625-
opp = dev_pm_opp_find_freq_ceil(dev, &freq);
632+
opp = _find_freq_ceil(opp_table, &freq);
626633
if (IS_ERR(opp)) {
627634
ret = PTR_ERR(opp);
628635
dev_err(dev, "%s: failed to find OPP for freq %lu (%d)\n",

0 commit comments

Comments
 (0)