All of lore.kernel.org
 help / color / mirror / Atom feed
From: Derek Basehore <dbasehore@chromium.org>
To: linux-kernel@vger.kernel.org
Cc: linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-rockchip@lists.infradead.org, linux-doc@vger.kernel.org,
	sboyd@kernel.org, mturquette@baylibre.com, heiko@sntech.de,
	aisheng.dong@nxp.com, mchehab+samsung@kernel.org, corbet@lwn.net,
	jbrunet@baylibre.com, Derek Basehore <dbasehore@chromium.org>
Subject: [PATCH v2 2/6] clk: fix clk_calc_subtree compute duplications
Date: Mon,  4 Mar 2019 20:49:32 -0800	[thread overview]
Message-ID: <20190305044936.22267-3-dbasehore@chromium.org> (raw)
In-Reply-To: <20190305044936.22267-1-dbasehore@chromium.org>

clk_calc_subtree was called at every step up the clk tree in
clk_calc_new_rates. Since it recursively calls itself for its
children, this means it would be called once on each clk for each
step above the top clk is.

This fixes this by breaking the subtree calculation into two parts.
The first part recalcs the rate for each child of the parent clk in
clk_calc_new_rates. This part is not recursive itself. The second part
recursively calls a new clk_calc_subtree on the clk_core that was
passed into clk_set_rate.

Signed-off-by: Derek Basehore <dbasehore@chromium.org>
---
 drivers/clk/clk.c | 49 ++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 38 insertions(+), 11 deletions(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 94b3ac783d90..e20364812b54 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -1732,11 +1732,19 @@ static int __clk_speculate_rates(struct clk_core *core,
 	return ret;
 }
 
-static void clk_calc_subtree(struct clk_core *core, unsigned long new_rate,
-			     struct clk_core *new_parent, u8 p_index)
+static void clk_calc_subtree(struct clk_core *core)
 {
 	struct clk_core *child;
 
+	hlist_for_each_entry(child, &core->children, child_node) {
+		child->new_rate = clk_recalc(child, core->new_rate);
+		clk_calc_subtree(child);
+	}
+}
+
+static void clk_set_change(struct clk_core *core, unsigned long new_rate,
+			   struct clk_core *new_parent, u8 p_index)
+{
 	core->new_rate = new_rate;
 	core->new_parent = new_parent;
 	core->new_parent_index = p_index;
@@ -1744,11 +1752,6 @@ static void clk_calc_subtree(struct clk_core *core, unsigned long new_rate,
 	core->new_child = NULL;
 	if (new_parent && new_parent != core->parent)
 		new_parent->new_child = core;
-
-	hlist_for_each_entry(child, &core->children, child_node) {
-		child->new_rate = clk_recalc(child, new_rate);
-		clk_calc_subtree(child, child->new_rate, NULL, 0);
-	}
 }
 
 /*
@@ -1759,7 +1762,7 @@ static struct clk_core *clk_calc_new_rates(struct clk_core *core,
 					   unsigned long rate)
 {
 	struct clk_core *top = core;
-	struct clk_core *old_parent, *parent;
+	struct clk_core *old_parent, *parent, *child;
 	unsigned long best_parent_rate = 0;
 	unsigned long new_rate;
 	unsigned long min_rate;
@@ -1806,6 +1809,13 @@ static struct clk_core *clk_calc_new_rates(struct clk_core *core,
 		/* pass-through clock with adjustable parent */
 		top = clk_calc_new_rates(parent, rate);
 		new_rate = parent->new_rate;
+		hlist_for_each_entry(child, &parent->children, child_node) {
+			if (child == core)
+				continue;
+
+			child->new_rate = clk_recalc(child, new_rate);
+			clk_calc_subtree(child);
+		}
 		goto out;
 	}
 
@@ -1828,11 +1838,19 @@ static struct clk_core *clk_calc_new_rates(struct clk_core *core,
 	}
 
 	if ((core->flags & CLK_SET_RATE_PARENT) && parent &&
-	    best_parent_rate != parent->rate)
+	    best_parent_rate != parent->rate) {
 		top = clk_calc_new_rates(parent, best_parent_rate);
+		hlist_for_each_entry(child, &parent->children, child_node) {
+			if (child == core)
+				continue;
+
+			child->new_rate = clk_recalc(child, parent->new_rate);
+			clk_calc_subtree(child);
+		}
+	}
 
 out:
-	clk_calc_subtree(core, new_rate, parent, p_index);
+	clk_set_change(core, new_rate, parent, p_index);
 
 	return top;
 }
@@ -2007,7 +2025,7 @@ static unsigned long clk_core_req_round_rate_nolock(struct clk_core *core,
 static int clk_core_set_rate_nolock(struct clk_core *core,
 				    unsigned long req_rate)
 {
-	struct clk_core *top, *fail_clk;
+	struct clk_core *top, *fail_clk, *child;
 	unsigned long rate;
 	int ret = 0;
 
@@ -2033,6 +2051,15 @@ static int clk_core_set_rate_nolock(struct clk_core *core,
 	if (ret)
 		return ret;
 
+	if (top != core) {
+		/* new_parent cannot be NULL in this case */
+		hlist_for_each_entry(child, &core->new_parent->children,
+				child_node)
+			clk_calc_subtree(child);
+	} else {
+		clk_calc_subtree(core);
+	}
+
 	/* notify that we are about to change rates */
 	fail_clk = clk_propagate_rate_change(top, PRE_RATE_CHANGE);
 	if (fail_clk) {
-- 
2.21.0.352.gf09ad66450-goog


WARNING: multiple messages have this Message-ID (diff)
From: Derek Basehore <dbasehore@chromium.org>
To: linux-kernel@vger.kernel.org
Cc: aisheng.dong@nxp.com, Derek Basehore <dbasehore@chromium.org>,
	heiko@sntech.de, linux-doc@vger.kernel.org, sboyd@kernel.org,
	mturquette@baylibre.com, corbet@lwn.net,
	linux-rockchip@lists.infradead.org, mchehab+samsung@kernel.org,
	linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	jbrunet@baylibre.com
Subject: [PATCH v2 2/6] clk: fix clk_calc_subtree compute duplications
Date: Mon,  4 Mar 2019 20:49:32 -0800	[thread overview]
Message-ID: <20190305044936.22267-3-dbasehore@chromium.org> (raw)
In-Reply-To: <20190305044936.22267-1-dbasehore@chromium.org>

clk_calc_subtree was called at every step up the clk tree in
clk_calc_new_rates. Since it recursively calls itself for its
children, this means it would be called once on each clk for each
step above the top clk is.

This fixes this by breaking the subtree calculation into two parts.
The first part recalcs the rate for each child of the parent clk in
clk_calc_new_rates. This part is not recursive itself. The second part
recursively calls a new clk_calc_subtree on the clk_core that was
passed into clk_set_rate.

Signed-off-by: Derek Basehore <dbasehore@chromium.org>
---
 drivers/clk/clk.c | 49 ++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 38 insertions(+), 11 deletions(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 94b3ac783d90..e20364812b54 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -1732,11 +1732,19 @@ static int __clk_speculate_rates(struct clk_core *core,
 	return ret;
 }
 
-static void clk_calc_subtree(struct clk_core *core, unsigned long new_rate,
-			     struct clk_core *new_parent, u8 p_index)
+static void clk_calc_subtree(struct clk_core *core)
 {
 	struct clk_core *child;
 
+	hlist_for_each_entry(child, &core->children, child_node) {
+		child->new_rate = clk_recalc(child, core->new_rate);
+		clk_calc_subtree(child);
+	}
+}
+
+static void clk_set_change(struct clk_core *core, unsigned long new_rate,
+			   struct clk_core *new_parent, u8 p_index)
+{
 	core->new_rate = new_rate;
 	core->new_parent = new_parent;
 	core->new_parent_index = p_index;
@@ -1744,11 +1752,6 @@ static void clk_calc_subtree(struct clk_core *core, unsigned long new_rate,
 	core->new_child = NULL;
 	if (new_parent && new_parent != core->parent)
 		new_parent->new_child = core;
-
-	hlist_for_each_entry(child, &core->children, child_node) {
-		child->new_rate = clk_recalc(child, new_rate);
-		clk_calc_subtree(child, child->new_rate, NULL, 0);
-	}
 }
 
 /*
@@ -1759,7 +1762,7 @@ static struct clk_core *clk_calc_new_rates(struct clk_core *core,
 					   unsigned long rate)
 {
 	struct clk_core *top = core;
-	struct clk_core *old_parent, *parent;
+	struct clk_core *old_parent, *parent, *child;
 	unsigned long best_parent_rate = 0;
 	unsigned long new_rate;
 	unsigned long min_rate;
@@ -1806,6 +1809,13 @@ static struct clk_core *clk_calc_new_rates(struct clk_core *core,
 		/* pass-through clock with adjustable parent */
 		top = clk_calc_new_rates(parent, rate);
 		new_rate = parent->new_rate;
+		hlist_for_each_entry(child, &parent->children, child_node) {
+			if (child == core)
+				continue;
+
+			child->new_rate = clk_recalc(child, new_rate);
+			clk_calc_subtree(child);
+		}
 		goto out;
 	}
 
@@ -1828,11 +1838,19 @@ static struct clk_core *clk_calc_new_rates(struct clk_core *core,
 	}
 
 	if ((core->flags & CLK_SET_RATE_PARENT) && parent &&
-	    best_parent_rate != parent->rate)
+	    best_parent_rate != parent->rate) {
 		top = clk_calc_new_rates(parent, best_parent_rate);
+		hlist_for_each_entry(child, &parent->children, child_node) {
+			if (child == core)
+				continue;
+
+			child->new_rate = clk_recalc(child, parent->new_rate);
+			clk_calc_subtree(child);
+		}
+	}
 
 out:
-	clk_calc_subtree(core, new_rate, parent, p_index);
+	clk_set_change(core, new_rate, parent, p_index);
 
 	return top;
 }
@@ -2007,7 +2025,7 @@ static unsigned long clk_core_req_round_rate_nolock(struct clk_core *core,
 static int clk_core_set_rate_nolock(struct clk_core *core,
 				    unsigned long req_rate)
 {
-	struct clk_core *top, *fail_clk;
+	struct clk_core *top, *fail_clk, *child;
 	unsigned long rate;
 	int ret = 0;
 
@@ -2033,6 +2051,15 @@ static int clk_core_set_rate_nolock(struct clk_core *core,
 	if (ret)
 		return ret;
 
+	if (top != core) {
+		/* new_parent cannot be NULL in this case */
+		hlist_for_each_entry(child, &core->new_parent->children,
+				child_node)
+			clk_calc_subtree(child);
+	} else {
+		clk_calc_subtree(core);
+	}
+
 	/* notify that we are about to change rates */
 	fail_clk = clk_propagate_rate_change(top, PRE_RATE_CHANGE);
 	if (fail_clk) {
-- 
2.21.0.352.gf09ad66450-goog

WARNING: multiple messages have this Message-ID (diff)
From: Derek Basehore <dbasehore@chromium.org>
To: linux-kernel@vger.kernel.org
Cc: aisheng.dong@nxp.com, Derek Basehore <dbasehore@chromium.org>,
	heiko@sntech.de, linux-doc@vger.kernel.org, sboyd@kernel.org,
	mturquette@baylibre.com, corbet@lwn.net,
	linux-rockchip@lists.infradead.org, mchehab+samsung@kernel.org,
	linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	jbrunet@baylibre.com
Subject: [PATCH v2 2/6] clk: fix clk_calc_subtree compute duplications
Date: Mon,  4 Mar 2019 20:49:32 -0800	[thread overview]
Message-ID: <20190305044936.22267-3-dbasehore@chromium.org> (raw)
In-Reply-To: <20190305044936.22267-1-dbasehore@chromium.org>

clk_calc_subtree was called at every step up the clk tree in
clk_calc_new_rates. Since it recursively calls itself for its
children, this means it would be called once on each clk for each
step above the top clk is.

This fixes this by breaking the subtree calculation into two parts.
The first part recalcs the rate for each child of the parent clk in
clk_calc_new_rates. This part is not recursive itself. The second part
recursively calls a new clk_calc_subtree on the clk_core that was
passed into clk_set_rate.

Signed-off-by: Derek Basehore <dbasehore@chromium.org>
---
 drivers/clk/clk.c | 49 ++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 38 insertions(+), 11 deletions(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 94b3ac783d90..e20364812b54 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -1732,11 +1732,19 @@ static int __clk_speculate_rates(struct clk_core *core,
 	return ret;
 }
 
-static void clk_calc_subtree(struct clk_core *core, unsigned long new_rate,
-			     struct clk_core *new_parent, u8 p_index)
+static void clk_calc_subtree(struct clk_core *core)
 {
 	struct clk_core *child;
 
+	hlist_for_each_entry(child, &core->children, child_node) {
+		child->new_rate = clk_recalc(child, core->new_rate);
+		clk_calc_subtree(child);
+	}
+}
+
+static void clk_set_change(struct clk_core *core, unsigned long new_rate,
+			   struct clk_core *new_parent, u8 p_index)
+{
 	core->new_rate = new_rate;
 	core->new_parent = new_parent;
 	core->new_parent_index = p_index;
@@ -1744,11 +1752,6 @@ static void clk_calc_subtree(struct clk_core *core, unsigned long new_rate,
 	core->new_child = NULL;
 	if (new_parent && new_parent != core->parent)
 		new_parent->new_child = core;
-
-	hlist_for_each_entry(child, &core->children, child_node) {
-		child->new_rate = clk_recalc(child, new_rate);
-		clk_calc_subtree(child, child->new_rate, NULL, 0);
-	}
 }
 
 /*
@@ -1759,7 +1762,7 @@ static struct clk_core *clk_calc_new_rates(struct clk_core *core,
 					   unsigned long rate)
 {
 	struct clk_core *top = core;
-	struct clk_core *old_parent, *parent;
+	struct clk_core *old_parent, *parent, *child;
 	unsigned long best_parent_rate = 0;
 	unsigned long new_rate;
 	unsigned long min_rate;
@@ -1806,6 +1809,13 @@ static struct clk_core *clk_calc_new_rates(struct clk_core *core,
 		/* pass-through clock with adjustable parent */
 		top = clk_calc_new_rates(parent, rate);
 		new_rate = parent->new_rate;
+		hlist_for_each_entry(child, &parent->children, child_node) {
+			if (child == core)
+				continue;
+
+			child->new_rate = clk_recalc(child, new_rate);
+			clk_calc_subtree(child);
+		}
 		goto out;
 	}
 
@@ -1828,11 +1838,19 @@ static struct clk_core *clk_calc_new_rates(struct clk_core *core,
 	}
 
 	if ((core->flags & CLK_SET_RATE_PARENT) && parent &&
-	    best_parent_rate != parent->rate)
+	    best_parent_rate != parent->rate) {
 		top = clk_calc_new_rates(parent, best_parent_rate);
+		hlist_for_each_entry(child, &parent->children, child_node) {
+			if (child == core)
+				continue;
+
+			child->new_rate = clk_recalc(child, parent->new_rate);
+			clk_calc_subtree(child);
+		}
+	}
 
 out:
-	clk_calc_subtree(core, new_rate, parent, p_index);
+	clk_set_change(core, new_rate, parent, p_index);
 
 	return top;
 }
@@ -2007,7 +2025,7 @@ static unsigned long clk_core_req_round_rate_nolock(struct clk_core *core,
 static int clk_core_set_rate_nolock(struct clk_core *core,
 				    unsigned long req_rate)
 {
-	struct clk_core *top, *fail_clk;
+	struct clk_core *top, *fail_clk, *child;
 	unsigned long rate;
 	int ret = 0;
 
@@ -2033,6 +2051,15 @@ static int clk_core_set_rate_nolock(struct clk_core *core,
 	if (ret)
 		return ret;
 
+	if (top != core) {
+		/* new_parent cannot be NULL in this case */
+		hlist_for_each_entry(child, &core->new_parent->children,
+				child_node)
+			clk_calc_subtree(child);
+	} else {
+		clk_calc_subtree(core);
+	}
+
 	/* notify that we are about to change rates */
 	fail_clk = clk_propagate_rate_change(top, PRE_RATE_CHANGE);
 	if (fail_clk) {
-- 
2.21.0.352.gf09ad66450-goog


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2019-03-05  4:50 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-05  4:49 [PATCH v2 0/6] Coordinated Clks Derek Basehore
2019-03-05  4:49 ` Derek Basehore
2019-03-05  4:49 ` [PATCH v2 1/6] clk: Remove recursion in clk_core_{prepare,enable}() Derek Basehore
2019-03-05  4:49   ` Derek Basehore
2019-03-05 18:49   ` Stephen Boyd
2019-03-05 18:49     ` [PATCH v2 1/6] clk: Remove recursion in clk_core_{prepare, enable}() Stephen Boyd
2019-03-05 18:49     ` Stephen Boyd
2019-03-06  1:35     ` [PATCH v2 1/6] clk: Remove recursion in clk_core_{prepare,enable}() dbasehore .
2019-03-06  1:35       ` [PATCH v2 1/6] clk: Remove recursion in clk_core_{prepare, enable}() dbasehore .
2019-03-06  4:11       ` [PATCH v2 1/6] clk: Remove recursion in clk_core_{prepare,enable}() dbasehore .
2019-03-06  4:11         ` [PATCH v2 1/6] clk: Remove recursion in clk_core_{prepare, enable}() dbasehore .
2019-03-06  4:11         ` dbasehore .
     [not found]         ` <CAGAzgsp0fWbH1f7gRKvhTotvdHMAL8gWw1bTKpVHfW9hJddXAw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2019-03-06 21:16           ` Stephen Boyd
2019-03-06 21:16         ` Stephen Boyd
2019-03-05  4:49 ` Derek Basehore [this message]
2019-03-05  4:49   ` [PATCH v2 2/6] clk: fix clk_calc_subtree compute duplications Derek Basehore
2019-03-05  4:49   ` Derek Basehore
2019-03-05  4:49 ` [PATCH v3 3/6] clk: change rates via list iteration Derek Basehore
2019-03-05  4:49   ` Derek Basehore
2019-03-09  0:07   ` dbasehore .
2019-03-09  0:07     ` dbasehore .
2019-03-05  4:49 ` [PATCH v2 4/6] clk: add coordinated clk changes support Derek Basehore
2019-03-05  4:49   ` Derek Basehore
2019-03-05  4:49 ` [PATCH v2 5/6] docs: driver-api: add pre_rate_req to clk documentation Derek Basehore
2019-03-05  4:49   ` Derek Basehore
2019-03-05  4:49 ` [PATCH v2 6/6] clk: rockchip: use pre_rate_req for cpuclk Derek Basehore
2019-03-05  4:49   ` Derek Basehore

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190305044936.22267-3-dbasehore@chromium.org \
    --to=dbasehore@chromium.org \
    --cc=aisheng.dong@nxp.com \
    --cc=corbet@lwn.net \
    --cc=heiko@sntech.de \
    --cc=jbrunet@baylibre.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=mchehab+samsung@kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=sboyd@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.