* [PATCH 1/2] clk: tegra: register clocks from root to leaf
@ 2022-04-06 15:17 Jon Hunter
2022-04-06 15:17 ` [PATCH 2/2] clk: tegra: replace round_rate with determine_rate Jon Hunter
2022-05-04 9:32 ` [PATCH 1/2] clk: tegra: register clocks from root to leaf Thierry Reding
0 siblings, 2 replies; 3+ messages in thread
From: Jon Hunter @ 2022-04-06 15:17 UTC (permalink / raw)
To: Peter De Schrijver, Michael Turquette, Stephen Boyd,
Thierry Reding
Cc: linux-clk, linux-tegra, Timo Alho, Jon Hunter
From: Timo Alho <talho@nvidia.com>
Current clock initialization causes intermediate registering of orphan
clocks (i.e. a clock without a parent registered). CCF keeps track of
orphan clocks and any time a new clock is registered, it will loop
through the list of orphan and queries if the parent is now
available. This operation triggers a clk operation(s), which is an IPC
with BPMP-FW. Hence, due to the order of which the clock appear
currently, this causes >5000 IPC messages to be sent to BPMP-FW during
clock initialization.
Optimize the clock probing by registering clocks hierarchically from
root clock towards leafs.
Signed-off-by: Timo Alho <talho@nvidia.com>
[ Checkpatch warnings fixed by Jon Hunter <jonathanh@nvidia.com> ]
Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
---
drivers/clk/tegra/clk-bpmp.c | 72 ++++++++++++++++++++++++++++--------
1 file changed, 56 insertions(+), 16 deletions(-)
diff --git a/drivers/clk/tegra/clk-bpmp.c b/drivers/clk/tegra/clk-bpmp.c
index 6ecf18f71c32..bacaa468e114 100644
--- a/drivers/clk/tegra/clk-bpmp.c
+++ b/drivers/clk/tegra/clk-bpmp.c
@@ -448,15 +448,29 @@ static int tegra_bpmp_probe_clocks(struct tegra_bpmp *bpmp,
return count;
}
+static unsigned int
+tegra_bpmp_clk_id_to_index(const struct tegra_bpmp_clk_info *clocks,
+ unsigned int num_clocks, unsigned int id)
+{
+ unsigned int i;
+
+ for (i = 0; i < num_clocks; i++)
+ if (clocks[i].id == id)
+ return i;
+
+ return UINT_MAX;
+}
+
static const struct tegra_bpmp_clk_info *
tegra_bpmp_clk_find(const struct tegra_bpmp_clk_info *clocks,
unsigned int num_clocks, unsigned int id)
{
unsigned int i;
- for (i = 0; i < num_clocks; i++)
- if (clocks[i].id == id)
- return &clocks[i];
+ i = tegra_bpmp_clk_id_to_index(clocks, num_clocks, id);
+
+ if (i < num_clocks)
+ return &clocks[i];
return NULL;
}
@@ -539,31 +553,57 @@ tegra_bpmp_clk_register(struct tegra_bpmp *bpmp,
return clk;
}
+static void tegra_bpmp_register_clocks_one(struct tegra_bpmp *bpmp,
+ struct tegra_bpmp_clk_info *infos,
+ unsigned int i,
+ unsigned int count)
+{
+ unsigned int j;
+ struct tegra_bpmp_clk_info *info;
+ struct tegra_bpmp_clk *clk;
+
+ if (bpmp->clocks[i]) {
+ /* already registered */
+ return;
+ }
+
+ info = &infos[i];
+ for (j = 0; j < info->num_parents; ++j) {
+ unsigned int p_id = info->parents[j];
+ unsigned int p_i = tegra_bpmp_clk_id_to_index(infos, count,
+ p_id);
+ if (p_i < count)
+ tegra_bpmp_register_clocks_one(bpmp, infos, p_i, count);
+ }
+
+ clk = tegra_bpmp_clk_register(bpmp, info, infos, count);
+ if (IS_ERR(clk)) {
+ dev_err(bpmp->dev,
+ "failed to register clock %u (%s): %ld\n",
+ info->id, info->name, PTR_ERR(clk));
+ /* intentionally store the error pointer to
+ * bpmp->clocks[i] to avoid re-attempting the
+ * registration later
+ */
+ }
+
+ bpmp->clocks[i] = clk;
+}
+
static int tegra_bpmp_register_clocks(struct tegra_bpmp *bpmp,
struct tegra_bpmp_clk_info *infos,
unsigned int count)
{
- struct tegra_bpmp_clk *clk;
unsigned int i;
bpmp->num_clocks = count;
- bpmp->clocks = devm_kcalloc(bpmp->dev, count, sizeof(clk), GFP_KERNEL);
+ bpmp->clocks = devm_kcalloc(bpmp->dev, count, sizeof(struct tegra_bpmp_clk), GFP_KERNEL);
if (!bpmp->clocks)
return -ENOMEM;
for (i = 0; i < count; i++) {
- struct tegra_bpmp_clk_info *info = &infos[i];
-
- clk = tegra_bpmp_clk_register(bpmp, info, infos, count);
- if (IS_ERR(clk)) {
- dev_err(bpmp->dev,
- "failed to register clock %u (%s): %ld\n",
- info->id, info->name, PTR_ERR(clk));
- continue;
- }
-
- bpmp->clocks[i] = clk;
+ tegra_bpmp_register_clocks_one(bpmp, infos, i, count);
}
return 0;
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH 2/2] clk: tegra: replace round_rate with determine_rate
2022-04-06 15:17 [PATCH 1/2] clk: tegra: register clocks from root to leaf Jon Hunter
@ 2022-04-06 15:17 ` Jon Hunter
2022-05-04 9:32 ` [PATCH 1/2] clk: tegra: register clocks from root to leaf Thierry Reding
1 sibling, 0 replies; 3+ messages in thread
From: Jon Hunter @ 2022-04-06 15:17 UTC (permalink / raw)
To: Peter De Schrijver, Michael Turquette, Stephen Boyd,
Thierry Reding
Cc: linux-clk, linux-tegra, Rajkumar Kasirajan, Jon Hunter
From: Rajkumar Kasirajan <rkasirajan@nvidia.com>
Replace round_rate callback with determine_rate which can consider
max_rate imposed by clk_set_max_rate while rounding clock rate.
Note that if the determine_rate callback is defined it will be called
instead of the round_rate callback when calling clk_round_rate(). By
using determine_rate, the max rate returned when calling
clk_round_rate() is now limited by the current max_rate.
Signed-off-by: Rajkumar Kasirajan <rkasirajan@nvidia.com>
[ Checkpatch warning fixed and commit message updated by
Jon Hunter <jonathanh@nvidia.com> ]
Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
---
drivers/clk/tegra/clk-bpmp.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/drivers/clk/tegra/clk-bpmp.c b/drivers/clk/tegra/clk-bpmp.c
index bacaa468e114..3748a39dae7c 100644
--- a/drivers/clk/tegra/clk-bpmp.c
+++ b/drivers/clk/tegra/clk-bpmp.c
@@ -164,15 +164,18 @@ static unsigned long tegra_bpmp_clk_recalc_rate(struct clk_hw *hw,
return response.rate;
}
-static long tegra_bpmp_clk_round_rate(struct clk_hw *hw, unsigned long rate,
- unsigned long *parent_rate)
+static int tegra_bpmp_clk_determine_rate(struct clk_hw *hw,
+ struct clk_rate_request *rate_req)
{
struct tegra_bpmp_clk *clk = to_tegra_bpmp_clk(hw);
struct cmd_clk_round_rate_response response;
struct cmd_clk_round_rate_request request;
struct tegra_bpmp_clk_message msg;
+ unsigned long rate;
int err;
+ rate = min(max(rate_req->rate, rate_req->min_rate), rate_req->max_rate);
+
memset(&request, 0, sizeof(request));
request.rate = min_t(u64, rate, S64_MAX);
@@ -188,7 +191,9 @@ static long tegra_bpmp_clk_round_rate(struct clk_hw *hw, unsigned long rate,
if (err < 0)
return err;
- return response.rate;
+ rate_req->rate = (unsigned long)response.rate;
+
+ return 0;
}
static int tegra_bpmp_clk_set_parent(struct clk_hw *hw, u8 index)
@@ -290,7 +295,7 @@ static const struct clk_ops tegra_bpmp_clk_rate_ops = {
.unprepare = tegra_bpmp_clk_unprepare,
.is_prepared = tegra_bpmp_clk_is_prepared,
.recalc_rate = tegra_bpmp_clk_recalc_rate,
- .round_rate = tegra_bpmp_clk_round_rate,
+ .determine_rate = tegra_bpmp_clk_determine_rate,
.set_rate = tegra_bpmp_clk_set_rate,
};
@@ -299,7 +304,7 @@ static const struct clk_ops tegra_bpmp_clk_mux_rate_ops = {
.unprepare = tegra_bpmp_clk_unprepare,
.is_prepared = tegra_bpmp_clk_is_prepared,
.recalc_rate = tegra_bpmp_clk_recalc_rate,
- .round_rate = tegra_bpmp_clk_round_rate,
+ .determine_rate = tegra_bpmp_clk_determine_rate,
.set_parent = tegra_bpmp_clk_set_parent,
.get_parent = tegra_bpmp_clk_get_parent,
.set_rate = tegra_bpmp_clk_set_rate,
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH 1/2] clk: tegra: register clocks from root to leaf
2022-04-06 15:17 [PATCH 1/2] clk: tegra: register clocks from root to leaf Jon Hunter
2022-04-06 15:17 ` [PATCH 2/2] clk: tegra: replace round_rate with determine_rate Jon Hunter
@ 2022-05-04 9:32 ` Thierry Reding
1 sibling, 0 replies; 3+ messages in thread
From: Thierry Reding @ 2022-05-04 9:32 UTC (permalink / raw)
To: Jon Hunter
Cc: Peter De Schrijver, Michael Turquette, Stephen Boyd, linux-clk,
linux-tegra, Timo Alho
[-- Attachment #1: Type: text/plain, Size: 1124 bytes --]
On Wed, Apr 06, 2022 at 04:17:00PM +0100, Jon Hunter wrote:
> From: Timo Alho <talho@nvidia.com>
>
> Current clock initialization causes intermediate registering of orphan
> clocks (i.e. a clock without a parent registered). CCF keeps track of
> orphan clocks and any time a new clock is registered, it will loop
> through the list of orphan and queries if the parent is now
> available. This operation triggers a clk operation(s), which is an IPC
> with BPMP-FW. Hence, due to the order of which the clock appear
> currently, this causes >5000 IPC messages to be sent to BPMP-FW during
> clock initialization.
>
> Optimize the clock probing by registering clocks hierarchically from
> root clock towards leafs.
>
> Signed-off-by: Timo Alho <talho@nvidia.com>
> [ Checkpatch warnings fixed by Jon Hunter <jonathanh@nvidia.com> ]
> Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
> ---
> drivers/clk/tegra/clk-bpmp.c | 72 ++++++++++++++++++++++++++++--------
> 1 file changed, 56 insertions(+), 16 deletions(-)
Both patches applied, with slight tweaks to the commit message.
Thanks,
Thierry
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-05-04 9:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-06 15:17 [PATCH 1/2] clk: tegra: register clocks from root to leaf Jon Hunter
2022-04-06 15:17 ` [PATCH 2/2] clk: tegra: replace round_rate with determine_rate Jon Hunter
2022-05-04 9:32 ` [PATCH 1/2] clk: tegra: register clocks from root to leaf Thierry Reding
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox