Skip to contentSkip to conversation

drivers: sh: late disabling of clocks

RFC PATCH In review Magnus Damm 3 participants 11 messages Jun 9, 2011 – Jun 21, 2011 SuperH

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 drivers: sh: late disabling of clocks

From: Magnus Damm <[email protected]>

This RFC patch kills two birds with one stone:

1) Fix existing issue where in-use clocks without software reference are disabled during boot. One example of this is the handling of the Mackerel serial console output.

2) Make sure so far unused clocks actually get turned off

---

 drivers/sh/clk/core.c |   26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
drivers/sh/clk/core.c +25 -1
@@ -34,6 +34,9 @@ static LIST_HEAD(clock_list);
 static DEFINE_SPINLOCK(clock_lock);
 static DEFINE_MUTEX(clock_list_sem);
 
+/* clock disable operations are not passed on to hardware during boot */
+static int allow_disable;
+
 void clk_rate_table_build(struct clk *clk,
 			  struct cpufreq_frequency_table *freq_table,
 			  int nr_freqs,
@@ -228,7 +231,7 @@ static void __clk_disable(struct clk *cl
 		return;
 
 	if (!(--clk->usecount)) {
-		if (likely(clk->ops && clk->ops->disable))
+		if (likely(allow_disable && clk->ops && clk->ops->disable))
 			clk->ops->disable(clk);
 		if (likely(clk->parent))
 			__clk_disable(clk->parent);
@@ -747,3 +750,24 @@ err_out:
 	return err;
 }
 late_initcall(clk_debugfs_init);
+
+static int __init clk_late_init(void)
+{
+	unsigned long flags;
+	struct clk *clk;
+
+	/* from now on allow clock disable operations */
+	allow_disable = 1;
+
+	/* disable all clocks with zero use count */
+	mutex_lock(&clock_list_sem);
+	list_for_each_entry(clk, &clock_list, node) {
+		spin_lock_irqsave(&clock_lock, flags);
+		if (!clk->usecount && clk->ops && clk->ops->disable)
+			clk->ops->disable(clk);
+		spin_unlock_irqrestore(&clock_lock, flags);
+	}
+	mutex_unlock(&clock_list_sem);
+	return 0;
+}
+late_initcall(clk_late_init);
#1 lore raw
Quoted 9 lines · Magnus Damm

From: Magnus Damm <[email protected]>

This RFC patch kills two birds with one stone:

1) Fix existing issue where in-use clocks without software reference are disabled during boot. One example of this is the handling of the Mackerel serial console output.

2) Make sure so far unused clocks actually get turned off

Is access to allow_disable SMP-safe?
In particular, does the the access in clk_late_init() need to be guarded by clock_lock as calls to __clk_disable() are?

Quoted 58 lines

---

 drivers/sh/clk/core.c |   26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
drivers/sh/clk/core.c +25 -2
@@ -34,6 +34,9 @@ static LIST_HEAD(clock_list);
 static DEFINE_SPINLOCK(clock_lock);
 static DEFINE_MUTEX(clock_list_sem);
 
+/* clock disable operations are not passed on to hardware during boot */
+static int allow_disable;
+
 void clk_rate_table_build(struct clk *clk,
 			  struct cpufreq_frequency_table *freq_table,
 			  int nr_freqs,
@@ -228,7 +231,7 @@ static void __clk_disable(struct clk *cl
 		return;
 
 	if (!(--clk->usecount)) {
-		if (likely(clk->ops && clk->ops->disable))
+		if (likely(allow_disable && clk->ops && clk->ops->disable))
 			clk->ops->disable(clk);
 		if (likely(clk->parent))
 			__clk_disable(clk->parent);
@@ -747,3 +750,24 @@ err_out:
 	return err;
 }
 late_initcall(clk_debugfs_init);
+
+static int __init clk_late_init(void)
+{
+	unsigned long flags;
+	struct clk *clk;
+
+	/* from now on allow clock disable operations */
+	allow_disable = 1;
+
+	/* disable all clocks with zero use count */
+	mutex_lock(&clock_list_sem);
+	list_for_each_entry(clk, &clock_list, node) {
+		spin_lock_irqsave(&clock_lock, flags);
+		if (!clk->usecount && clk->ops && clk->ops->disable)
+			clk->ops->disable(clk);
+		spin_unlock_irqrestore(&clock_lock, flags);
+	}
+	mutex_unlock(&clock_list_sem);
+	return 0;
+}
+late_initcall(clk_late_init);
--

To unsubscribe from this list: send the line "unsubscribe linux-sh" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
In reply to Magnus Damm
Quoted 9 lines · Simon Horman
Quoted 8 lines · Magnus Damm

From: Magnus Damm <[email protected]>

This RFC patch kills two birds with one stone:

1) Fix existing issue where in-use clocks without software reference are disabled during boot. One example of this is the handling of the Mackerel serial console output.

Quoted 5 lines
Quoted 1 line

2) Make sure so far unused clocks actually get turned off

Is access to allow_disable SMP-safe?
In particular, does the the access in clk_late_init() need to be guarded by clock_lock as calls to __clk_disable() are?

On reflection I think that the problem is a bit deeper.

I think allow_disable is set to 1 prematurely, as it indicates to __clk_disable() that calling clk->ops->disable(clk) is allowed, even if the iteration of the loop in clk_late_init() is not complete.

My proposed re-working of clk_late_init() is below. Completely untested.

Quoted 44 lines
Quoted 44 lines

---

 drivers/sh/clk/core.c |   26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
drivers/sh/clk/core.c +16 -1
@@ -34,6 +34,9 @@ static LIST_HEAD(clock_list);
 static DEFINE_SPINLOCK(clock_lock);
 static DEFINE_MUTEX(clock_list_sem);
 
+/* clock disable operations are not passed on to hardware during boot */
+static int allow_disable;
+
 void clk_rate_table_build(struct clk *clk,
 			  struct cpufreq_frequency_table *freq_table,
 			  int nr_freqs,
@@ -228,7 +231,7 @@ static void __clk_disable(struct clk *cl
 		return;
 
 	if (!(--clk->usecount)) {
-		if (likely(clk->ops && clk->ops->disable))
+		if (likely(allow_disable && clk->ops && clk->ops->disable))
 			clk->ops->disable(clk);
 		if (likely(clk->parent))
 			__clk_disable(clk->parent);
@@ -747,3 +750,24 @@ err_out:
 	return err;
 }
 late_initcall(clk_debugfs_init);
+
+static int __init clk_late_init(void)
+{
+	unsigned long flags;
+	struct clk *clk;
+
+	/* from now on allow clock disable operations */
+	allow_disable = 1;
+
+	/* disable all clocks with zero use count */
+	mutex_lock(&clock_list_sem);
+	list_for_each_entry(clk, &clock_list, node) {
Quoted 8 lines

drivers/sh/clk/core.c err_out: · line 772

Quoted 8 lines
drivers/sh/clk/core.c +8 -0
+		spin_lock_irqsave(&clock_lock, flags);
+		if (!clk->usecount && clk->ops && clk->ops->disable)
+			clk->ops->disable(clk);
+		spin_unlock_irqrestore(&clock_lock, flags);
+	}
+	mutex_unlock(&clock_list_sem);
+	return 0;
+}

static int __init clk_late_init(void)

{
	unsigned long flags;
	struct clk *clk;

	mutex_lock(&clock_list_sem);
	spin_lock_irqsave(&clock_lock, flags);

	/* disable all clocks with zero use count */
	list_for_each_entry(clk, &clock_list, node)
		if (!clk->usecount && clk->ops && clk->ops->disable)
			clk->ops->disable(clk);

	/* from now on allow clock disable operations */
	allow_disable = 1;

	spin_unlock_irqrestore(&clock_lock, flags);
	mutex_unlock(&clock_list_sem);

	return 0;
}
Quoted 1 line
Quoted 1 line
drivers/sh/clk/core.c +1 -0
+late_initcall(clk_late_init);
#3 lore raw
In reply to Magnus Damm
Quoted 16 lines · Simon Horman
Quoted 9 lines · Simon Horman
Quoted 8 lines · Magnus Damm

From: Magnus Damm <[email protected]>

This RFC patch kills two birds with one stone:

1) Fix existing issue where in-use clocks without software reference are disabled during boot. One example of this is the handling of the Mackerel serial console output.

Quoted 5 lines
Quoted 1 line

2) Make sure so far unused clocks actually get turned off

Is access to allow_disable SMP-safe?
In particular, does the the access in clk_late_init() need to be guarded by clock_lock as calls to __clk_disable() are?

Quoted 8 lines

On reflection I think that the problem is a bit deeper.

I think allow_disable is set to 1 prematurely, as it indicates to __clk_disable() that calling clk->ops->disable(clk) is allowed, even if the iteration of the loop in clk_late_init() is not complete.

My proposed re-working of clk_late_init() is below. Completely untested.

Right, I was thinking something along those lines too. The spinlock should make sure we're serialized.

Thanks,

/ magnus

#4 lore raw
In reply to Magnus Damm
Quoted 23 lines · Magnus Damm
Quoted 22 lines · Simon Horman
Quoted 9 lines · Simon Horman
Quoted 8 lines · Magnus Damm

From: Magnus Damm <[email protected]>

This RFC patch kills two birds with one stone:

1) Fix existing issue where in-use clocks without software reference are disabled during boot. One example of this is the handling of the Mackerel serial console output.

Quoted 5 lines
Quoted 1 line

2) Make sure so far unused clocks actually get turned off

Is access to allow_disable SMP-safe?
In particular, does the the access in clk_late_init() need to be guarded by clock_lock as calls to __clk_disable() are?

On reflection I think that the problem is a bit deeper.

I think allow_disable is set to 1 prematurely, as it indicates to __clk_disable() that calling clk->ops->disable(clk) is allowed, even if the iteration of the loop in clk_late_init() is not complete.

Quoted 5 lines
Quoted 2 lines

My proposed re-working of clk_late_init() is below. Completely untested.

Right, I was thinking something along those lines too. The spinlock should make sure we're serialized.

Great. Feel free to take my ideas verbatim if it helps.

#5 lore raw
In reply to Magnus Damm
Quoted 24 lines · Simon Horman
Quoted 23 lines · Magnus Damm
Quoted 22 lines · Simon Horman
Quoted 9 lines · Simon Horman
Quoted 8 lines · Magnus Damm

From: Magnus Damm <[email protected]>

This RFC patch kills two birds with one stone:

1) Fix existing issue where in-use clocks without software reference are disabled during boot. One example of this is the handling of the Mackerel serial console output.

Quoted 5 lines
Quoted 1 line

2) Make sure so far unused clocks actually get turned off

Is access to allow_disable SMP-safe?
In particular, does the the access in clk_late_init() need to be guarded by clock_lock as calls to __clk_disable() are?

On reflection I think that the problem is a bit deeper.

I think allow_disable is set to 1 prematurely, as it indicates to __clk_disable() that calling clk->ops->disable(clk) is allowed, even if the iteration of the loop in clk_late_init() is not complete.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

My proposed re-working of clk_late_init() is below. Completely untested.

Right, I was thinking something along those lines too. The spinlock should make sure we're serialized.

Great. Feel free to take my ideas verbatim if it helps.

Hi Magnus,

have you had time to look into this?

#6 lore raw
In reply to Magnus Damm
Quoted 28 lines · Simon Horman
Quoted 27 lines · Simon Horman
Quoted 26 lines · Magnus Damm
Quoted 24 lines · Simon Horman
Quoted 9 lines · Simon Horman
Quoted 8 lines · Magnus Damm

From: Magnus Damm <[email protected]>

This RFC patch kills two birds with one stone:

1) Fix existing issue where in-use clocks without software reference are disabled during boot. One example of this is the handling of the Mackerel serial console output.

Quoted 5 lines
Quoted 1 line

2) Make sure so far unused clocks actually get turned off

Is access to allow_disable SMP-safe?
In particular, does the the access in clk_late_init() need to be guarded by clock_lock as calls to __clk_disable() are?

On reflection I think that the problem is a bit deeper.

I think allow_disable is set to 1 prematurely, as it indicates to __clk_disable() that calling clk->ops->disable(clk) is allowed, even if the iteration of the loop in clk_late_init() is not complete.

My proposed re-working of clk_late_init() is below. Completely untested.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Right, I was thinking something along those lines too. The spinlock should make sure we're serialized.

Great. Feel free to take my ideas verbatim if it helps.

Hi Magnus,

have you had time to look into this?

I have not updated this patch yet, mainly due to lack of feedback. Not so much due to lack of feedback from you - I appreciate your ideas and I agree that your rework of the ordering is correct. I'm however still not sure if other people agree with my approach of delaying the disable operations until a certain point in time.

Thanks,

/ magnus

#7 lore raw
In reply to Magnus Damm
Quoted 36 lines · Magnus Damm
Quoted 35 lines · Simon Horman
Quoted 24 lines · Simon Horman
Quoted 23 lines · Magnus Damm
Quoted 22 lines · Simon Horman
Quoted 9 lines · Simon Horman
Quoted 8 lines · Magnus Damm

From: Magnus Damm <[email protected]>

This RFC patch kills two birds with one stone:

1) Fix existing issue where in-use clocks without software reference are disabled during boot. One example of this is the handling of the Mackerel serial console output.

Quoted 5 lines
Quoted 1 line

2) Make sure so far unused clocks actually get turned off

Is access to allow_disable SMP-safe?
In particular, does the the access in clk_late_init() need to be guarded by clock_lock as calls to __clk_disable() are?

On reflection I think that the problem is a bit deeper.

I think allow_disable is set to 1 prematurely, as it indicates to __clk_disable() that calling clk->ops->disable(clk) is allowed, even if the iteration of the loop in clk_late_init() is not complete.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

My proposed re-working of clk_late_init() is below. Completely untested.

Right, I was thinking something along those lines too. The spinlock should make sure we're serialized.

Great. Feel free to take my ideas verbatim if it helps.

Hi Magnus,

Quoted 7 lines
Quoted 1 line

have you had time to look into this?

I have not updated this patch yet, mainly due to lack of feedback. Not so much due to lack of feedback from you - I appreciate your ideas and I agree that your rework of the ordering is correct. I'm however still not sure if other people agree with my approach of delaying the disable operations until a certain point in time.

Understood.

#8 lore raw
In reply to Magnus Damm
Quoted 9 lines · Magnus Damm
Quoted 8 lines · Simon Horman
Quoted 4 lines · Simon Horman
Quoted 2 lines

Right, I was thinking something along those lines too. The spinlock should make sure we're serialized.

Great. Feel free to take my ideas verbatim if it helps.

Hi Magnus,

Quoted 8 lines
Quoted 1 line

have you had time to look into this?

I have not updated this patch yet, mainly due to lack of feedback. Not so much due to lack of feedback from you - I appreciate your ideas and I agree that your rework of the ordering is correct. I'm however still not sure if other people agree with my approach of delaying the disable operations until a certain point in time.

Except that's not really how it works. I don't have the time or inclination to go through and provide feedback for every single patch that crosses my inbox. If something has been posted for awhile and has feedback, then it's expected that the feedback is addressed and an updated version is posted. If no other action happens within an arbitrary but not too long period of time, I'll then roll it in to one of my trees for testing (assuming there are no glaring issues with the concept or implementation prior to integration/testing). You've posted multiple versions of the same patches in the past upon receiving feedback, so it's a bit perplexing as to why this time you've simply opted to throw the patch over the fence and do nothing.

#9 lore raw
In reply to Magnus Damm
Quoted 18 lines · Paul Mundt
Quoted 9 lines · Magnus Damm
Quoted 8 lines · Simon Horman
Quoted 4 lines · Simon Horman
Quoted 2 lines

Right, I was thinking something along those lines too. The spinlock should make sure we're serialized.

Great. Feel free to take my ideas verbatim if it helps.

Hi Magnus,

Quoted 8 lines
Quoted 1 line

have you had time to look into this?

I have not updated this patch yet, mainly due to lack of feedback. Not so much due to lack of feedback from you - I appreciate your ideas and I agree that your rework of the ordering is correct. I'm however still not sure if other people agree with my approach of delaying the disable operations until a certain point in time.

Quoted 11 lines

Except that's not really how it works. I don't have the time or inclination to go through and provide feedback for every single patch that crosses my inbox. If something has been posted for awhile and has feedback, then it's expected that the feedback is addressed and an updated version is posted. If no other action happens within an arbitrary but not too long period of time, I'll then roll it in to one of my trees for testing (assuming there are no glaring issues with the concept or implementation prior to integration/testing). You've posted multiple versions of the same patches in the past upon receiving feedback, so it's a bit perplexing as to why this time you've simply opted to throw the patch over the fence and do nothing.

I believe I received some feedback through face-to-face conversations earlier, and that feedback was not all that positive. I decided to post the code anyway, and Simon kindly provided detailed feedback via email about internal ordering. The main idea behind the patch is not really changed, so in that area there still is silence.

I'll resend a new version in a little while. Thanks.

/ magnus

#10 lore raw
In reply to Magnus Damm
Quoted 31 lines · Magnus Damm
Quoted 18 lines · Paul Mundt
Quoted 9 lines · Magnus Damm
Quoted 8 lines · Simon Horman
Quoted 4 lines · Simon Horman
Quoted 2 lines

Right, I was thinking something along those lines too. The spinlock should make sure we're serialized.

Great. Feel free to take my ideas verbatim if it helps.

Hi Magnus,

Quoted 8 lines
Quoted 1 line

have you had time to look into this?

I have not updated this patch yet, mainly due to lack of feedback. Not so much due to lack of feedback from you - I appreciate your ideas and I agree that your rework of the ordering is correct. I'm however still not sure if other people agree with my approach of delaying the disable operations until a certain point in time.

Quoted 11 lines

Except that's not really how it works. I don't have the time or inclination to go through and provide feedback for every single patch that crosses my inbox. If something has been posted for awhile and has feedback, then it's expected that the feedback is addressed and an updated version is posted. If no other action happens within an arbitrary but not too long period of time, I'll then roll it in to one of my trees for testing (assuming there are no glaring issues with the concept or implementation prior to integration/testing). You've posted multiple versions of the same patches in the past upon receiving feedback, so it's a bit perplexing as to why this time you've simply opted to throw the patch over the fence and do nothing.

Quoted 8 lines

I believe I received some feedback through face-to-face conversations earlier, and that feedback was not all that positive. I decided to post the code anyway, and Simon kindly provided detailed feedback via email about internal ordering. The main idea behind the patch is not really changed, so in that area there still is silence.

I'll resend a new version in a little while. Thanks.

I don't have any particular problems with the approach at least, and at this point it's really just the locking stuff pointed out by Simon that is keeping it from being applied. It's obviously somewhat of a hack and I'm certainly not thrilled by it, but the fact we're forced in to this position and are entering with undefined state is certainly not your fault, nor something we can really do much about. We also have half a dozen syscall ABIs for no good reason because of hardware designer muppetry, such is life.

Having said that, it might need a bit of fiddling in terms of deciding on how to enable it or present it to the user, but those are fairly superficial details that can be worked out once an updated version is posted.