Skip to content

Commit 0daa376

Browse files
committed
clk: Move rate and accuracy recalc to mostly consumer APIs
There's some confusion about when recalc is done for the rate and accuracy clk consumer APIs in relation to the prepare lock being taken. Oddly enough, we take the lock again in debugfs APIs so that we can call the internal "clk_core" APIs to get these fields with any necessary recalculations. Instead of having this confusion, let's introduce a recalc variant of these two consumer APIs as internal helpers and call them from the consumer APIs and the debugfs code so that we don't take the lock more than once. Cc: Douglas Anderson <[email protected]> Cc: Heiko Stuebner <[email protected]> Cc: Jerome Brunet <[email protected]> Signed-off-by: Stephen Boyd <[email protected]> Link: https://lkml.kernel.org/r/[email protected] Acked-by: Jerome Brunet <[email protected]>
1 parent 768a5d4 commit 0daa376

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

drivers/clk/clk.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ unsigned long clk_hw_get_rate(const struct clk_hw *hw)
488488
}
489489
EXPORT_SYMBOL_GPL(clk_hw_get_rate);
490490

491-
static unsigned long __clk_get_accuracy(struct clk_core *core)
491+
static unsigned long clk_core_get_accuracy_no_lock(struct clk_core *core)
492492
{
493493
if (!core)
494494
return 0;
@@ -1517,18 +1517,12 @@ static void __clk_recalc_accuracies(struct clk_core *core)
15171517
__clk_recalc_accuracies(child);
15181518
}
15191519

1520-
static long clk_core_get_accuracy(struct clk_core *core)
1520+
static long clk_core_get_accuracy_recalc(struct clk_core *core)
15211521
{
1522-
unsigned long accuracy;
1523-
1524-
clk_prepare_lock();
15251522
if (core && (core->flags & CLK_GET_ACCURACY_NOCACHE))
15261523
__clk_recalc_accuracies(core);
15271524

1528-
accuracy = __clk_get_accuracy(core);
1529-
clk_prepare_unlock();
1530-
1531-
return accuracy;
1525+
return clk_core_get_accuracy_no_lock(core);
15321526
}
15331527

15341528
/**
@@ -1542,10 +1536,16 @@ static long clk_core_get_accuracy(struct clk_core *core)
15421536
*/
15431537
long clk_get_accuracy(struct clk *clk)
15441538
{
1539+
long accuracy;
1540+
15451541
if (!clk)
15461542
return 0;
15471543

1548-
return clk_core_get_accuracy(clk->core);
1544+
clk_prepare_lock();
1545+
accuracy = clk_core_get_accuracy_recalc(clk->core);
1546+
clk_prepare_unlock();
1547+
1548+
return accuracy;
15491549
}
15501550
EXPORT_SYMBOL_GPL(clk_get_accuracy);
15511551

@@ -1599,19 +1599,12 @@ static void __clk_recalc_rates(struct clk_core *core, unsigned long msg)
15991599
__clk_recalc_rates(child, msg);
16001600
}
16011601

1602-
static unsigned long clk_core_get_rate(struct clk_core *core)
1602+
static unsigned long clk_core_get_rate_recalc(struct clk_core *core)
16031603
{
1604-
unsigned long rate;
1605-
1606-
clk_prepare_lock();
1607-
16081604
if (core && (core->flags & CLK_GET_RATE_NOCACHE))
16091605
__clk_recalc_rates(core, 0);
16101606

1611-
rate = clk_core_get_rate_nolock(core);
1612-
clk_prepare_unlock();
1613-
1614-
return rate;
1607+
return clk_core_get_rate_nolock(core);
16151608
}
16161609

16171610
/**
@@ -1624,10 +1617,16 @@ static unsigned long clk_core_get_rate(struct clk_core *core)
16241617
*/
16251618
unsigned long clk_get_rate(struct clk *clk)
16261619
{
1620+
unsigned long rate;
1621+
16271622
if (!clk)
16281623
return 0;
16291624

1630-
return clk_core_get_rate(clk->core);
1625+
clk_prepare_lock();
1626+
rate = clk_core_get_rate_recalc(clk->core);
1627+
clk_prepare_unlock();
1628+
1629+
return rate;
16311630
}
16321631
EXPORT_SYMBOL_GPL(clk_get_rate);
16331632

@@ -2910,7 +2909,8 @@ static void clk_summary_show_one(struct seq_file *s, struct clk_core *c,
29102909
level * 3 + 1, "",
29112910
30 - level * 3, c->name,
29122911
c->enable_count, c->prepare_count, c->protect_count,
2913-
clk_core_get_rate(c), clk_core_get_accuracy(c));
2912+
clk_core_get_rate_recalc(c),
2913+
clk_core_get_accuracy_recalc(c));
29142914

29152915
phase = clk_core_get_phase(c);
29162916
if (phase >= 0)
@@ -2965,10 +2965,10 @@ static void clk_dump_one(struct seq_file *s, struct clk_core *c, int level)
29652965
seq_printf(s, "\"enable_count\": %d,", c->enable_count);
29662966
seq_printf(s, "\"prepare_count\": %d,", c->prepare_count);
29672967
seq_printf(s, "\"protect_count\": %d,", c->protect_count);
2968-
seq_printf(s, "\"rate\": %lu,", clk_core_get_rate(c));
2968+
seq_printf(s, "\"rate\": %lu,", clk_core_get_rate_recalc(c));
29692969
seq_printf(s, "\"min_rate\": %lu,", min_rate);
29702970
seq_printf(s, "\"max_rate\": %lu,", max_rate);
2971-
seq_printf(s, "\"accuracy\": %lu,", clk_core_get_accuracy(c));
2971+
seq_printf(s, "\"accuracy\": %lu,", clk_core_get_accuracy_recalc(c));
29722972
phase = clk_core_get_phase(c);
29732973
if (phase >= 0)
29742974
seq_printf(s, "\"phase\": %d,", phase);
@@ -3446,7 +3446,7 @@ static int __clk_core_init(struct clk_core *core)
34463446
*/
34473447
if (core->ops->recalc_accuracy)
34483448
core->accuracy = core->ops->recalc_accuracy(core->hw,
3449-
__clk_get_accuracy(parent));
3449+
clk_core_get_accuracy_no_lock(parent));
34503450
else if (parent)
34513451
core->accuracy = parent->accuracy;
34523452
else

0 commit comments

Comments
 (0)