Skip to contentSkip to conversation

clk: Add tracepoints for hardware operations

PATCH Superseded Stephen Boyd 3 participants 5 messages Jan 31, 2015 – Feb 2, 2015

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clk: Add tracepoints for hardware operations

It's useful to have tracepoints around operations that change the hardware state so that we can debug clock hardware performance and operations. Four basic types of events are supported: on/off events for enable, disable, prepare, unprepare that only record an event and a clock name, rate changing events for clk_set_{min_,max_}rate{_range}(), phase changing events for clk_set_phase() and parent changing events for clk_set_parent().

Cc Steven Rostedt <[email protected]>
---
 drivers/clk/clk.c          |  32 ++++++++
 include/trace/events/clk.h | 198 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 230 insertions(+)
 create mode 100644 include/trace/events/clk.h
drivers/clk/clk.c +32 -0
index a29daf9edea4..271c3fe71277 100644
@@ -22,6 +22,9 @@
 #include <linux/init.h>
 #include <linux/sched.h>
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/clk.h>
+
 #include "clk.h"
 
 static DEFINE_SPINLOCK(enable_lock);
@@ -448,10 +451,12 @@ static void clk_unprepare_unused_subtree(struct clk_core *clk)
 		return;
 
 	if (clk_core_is_prepared(clk)) {
+		trace_clk_unprepare(clk);
 		if (clk->ops->unprepare_unused)
 			clk->ops->unprepare_unused(clk->hw);
 		else if (clk->ops->unprepare)
 			clk->ops->unprepare(clk->hw);
+		trace_clk_unprepare_complete(clk);
 	}
 }
 
@@ -478,10 +483,12 @@ static void clk_disable_unused_subtree(struct clk_core *clk)
 	 * back to .disable
 	 */
 	if (clk_core_is_enabled(clk)) {
+		trace_clk_disable(clk);
 		if (clk->ops->disable_unused)
 			clk->ops->disable_unused(clk->hw);
 		else if (clk->ops->disable)
 			clk->ops->disable(clk->hw);
+		trace_clk_disable_complete(clk);
 	}
 
 unlock_out:
@@ -861,9 +868,12 @@ static void clk_core_unprepare(struct clk_core *clk)
 
 	WARN_ON(clk->enable_count > 0);
 
+	trace_clk_unprepare(clk);
+
 	if (clk->ops->unprepare)
 		clk->ops->unprepare(clk->hw);
 
+	trace_clk_unprepare_complete(clk);
 	clk_core_unprepare(clk->parent);
 }
 
@@ -901,6 +911,8 @@ static int clk_core_prepare(struct clk_core *clk)
 		if (ret)
 			return ret;
 
+		trace_clk_prepare(clk);
+
 		if (clk->ops->prepare) {
 			ret = clk->ops->prepare(clk->hw);
 			if (ret) {
@@ -908,6 +920,8 @@ static int clk_core_prepare(struct clk_core *clk)
 				return ret;
 			}
 		}
+
+		trace_clk_prepare_complete(clk);
 	}
 
 	clk->prepare_count++;
@@ -953,9 +967,13 @@ static void clk_core_disable(struct clk_core *clk)
 	if (--clk->enable_count > 0)
 		return;
 
+	trace_clk_disable(clk);
+
 	if (clk->ops->disable)
 		clk->ops->disable(clk->hw);
 
+	trace_clk_disable_complete(clk);
+
 	clk_core_disable(clk->parent);
 }
 
@@ -1008,6 +1026,7 @@ static int clk_core_enable(struct clk_core *clk)
 		if (ret)
 			return ret;
 
+		trace_clk_enable(clk);
 		if (clk->ops->enable) {
 			ret = clk->ops->enable(clk->hw);
 			if (ret) {
@@ -1015,6 +1034,7 @@ static int clk_core_enable(struct clk_core *clk)
 				return ret;
 			}
 		}
+		trace_clk_enable_complete(clk);
 	}
 
 	clk->enable_count++;
@@ -1383,6 +1403,8 @@ static struct clk_core *__clk_set_parent_before(struct clk_core *clk,
 	unsigned long flags;
 	struct clk_core *old_parent = clk->parent;
 
+	trace_clk_set_parent(clk, parent);
+
 	/*
 	 * Migrate prepare state between parents and prevent race with
 	 * clk_enable().
@@ -1427,6 +1449,8 @@ static void __clk_set_parent_after(struct clk_core *core,
 		clk_core_disable(old_parent);
 		clk_core_unprepare(old_parent);
 	}
+
+	trace_clk_set_parent_complete(core, parent);
 }
 
 static int __clk_set_parent(struct clk_core *clk, struct clk_core *parent,
@@ -1663,6 +1687,8 @@ static void clk_change_rate(struct clk_core *clk)
 	else if (clk->parent)
 		best_parent_rate = clk->parent->rate;
 
+	trace_clk_set_rate(clk, clk->new_rate);
+
 	if (clk->new_parent && clk->new_parent != clk->parent) {
 		old_parent = __clk_set_parent_before(clk, clk->new_parent);
 
@@ -1681,6 +1707,8 @@ static void clk_change_rate(struct clk_core *clk)
 	if (!skip_set_rate && clk->ops->set_rate)
 		clk->ops->set_rate(clk->hw, clk->new_rate, best_parent_rate);
 
+	trace_clk_set_rate_complete(clk, clk->new_rate);
+
 	clk->rate = clk_recalc(clk, best_parent_rate);
 
 	if (clk->notifier_count && old_rate != clk->rate)
@@ -2081,6 +2109,8 @@ int clk_set_phase(struct clk *clk, int degrees)
 
 	clk_prepare_lock();
 
+	trace_clk_set_phase(clk->core, degrees);
+
 	if (!clk->core->ops->set_phase)
 		goto out_unlock;
 
@@ -2090,6 +2120,8 @@ int clk_set_phase(struct clk *clk, int degrees)
 		clk->core->phase = degrees;
 
 out_unlock:
+	trace_clk_set_phase_complete(clk->core, degrees);
+
 	clk_prepare_unlock();
 
 out:
include/trace/events/clk.h new file +198 -0

198 lines not on this page · raw message

Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
maintainer
#1 lore raw
Quoted 9 lines · On Fri, 30 Jan 2015 16:16:11 -0800 Stephen Boyd <[email protected]> wrote:

It's useful to have tracepoints around operations that change the hardware state so that we can debug clock hardware performance and operations. Four basic types of events are supported: on/off events for enable, disable, prepare, unprepare that only record an event and a clock name, rate changing events for clk_set_{min_,max_}rate{_range}(), phase changing events for clk_set_phase() and parent changing events for clk_set_parent().

Cc Steven Rostedt <[email protected]>

I don't see anything wrong with the implementation of the tracepoints. Now whether or not they are useful is up to the clk maintainer to decide.

Quoted 12 lines
---
 drivers/clk/clk.c          |  32 ++++++++
 include/trace/events/clk.h | 198 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 230 insertions(+)
 create mode 100644 include/trace/events/clk.h

unlock_out:

drivers/clk/clk.c static void clk_core_unprepare(struct clk_core *clk) · line 877

Quoted 10 lines
drivers/clk/clk.c +3 -0
@@ -861,9 +868,12 @@ static void clk_core_unprepare(struct clk_core *clk)
 
 	WARN_ON(clk->enable_count > 0);
 
+	trace_clk_unprepare(clk);
+
 	if (clk->ops->unprepare)
 		clk->ops->unprepare(clk->hw);
 
+	trace_clk_unprepare_complete(clk);
 	clk_core_unprepare(clk->parent);

I guess you do not care about the clk_core_unprepare time.

Quoted 12 lines
drivers/clk/clk.c +2 -0
 }
 
@@ -901,6 +911,8 @@ static int clk_core_prepare(struct clk_core *clk)
 		if (ret)
 			return ret;
 
+		trace_clk_prepare(clk);
+
 		if (clk->ops->prepare) {
 			ret = clk->ops->prepare(clk->hw);
 			if (ret) {

drivers/clk/clk.c static int clk_core_prepare(struct clk_core *clk) · line 924

Quoted 5 lines
drivers/clk/clk.c +2 -0
@@ -908,6 +920,8 @@ static int clk_core_prepare(struct clk_core *clk)
 				return ret;
 			}
 		}
+
+		trace_clk_prepare_complete(clk);

I'm curious to why you do not put the tracepoint within the if statement, and only show the tracepoints if the clock prepare is actually called. Also, if you exit out with that return, will you tools be OK with seeing the clk_prepare but not the clk_prepare_complete?

Quoted 26 lines
drivers/clk/clk.c +5 -0
 	}
 
 	clk->prepare_count++;
@@ -953,9 +967,13 @@ static void clk_core_disable(struct clk_core *clk)
 	if (--clk->enable_count > 0)
 		return;
 
+	trace_clk_disable(clk);
+
 	if (clk->ops->disable)
 		clk->ops->disable(clk->hw);
 
+	trace_clk_disable_complete(clk);
+
 	clk_core_disable(clk->parent);
 }
 
@@ -1008,6 +1026,7 @@ static int clk_core_enable(struct clk_core *clk)
 		if (ret)
 			return ret;
 
+		trace_clk_enable(clk);
 		if (clk->ops->enable) {
 			ret = clk->ops->enable(clk->hw);
 			if (ret) {

drivers/clk/clk.c static int clk_core_enable(struct clk_core *clk) · line 1037

Quoted 4 lines
drivers/clk/clk.c +1 -0
@@ -1015,6 +1034,7 @@ static int clk_core_enable(struct clk_core *clk)
 				return ret;
 			}
 		}
+		trace_clk_enable_complete(clk);

Same here.

-- Steve

Quoted 57 lines
drivers/clk/clk.c +12 -0
 	}
 
 	clk->enable_count++;
@@ -1383,6 +1403,8 @@ static struct clk_core *__clk_set_parent_before(struct clk_core *clk,
 	unsigned long flags;
 	struct clk_core *old_parent = clk->parent;
 
+	trace_clk_set_parent(clk, parent);
+
 	/*
 	 * Migrate prepare state between parents and prevent race with
 	 * clk_enable().
@@ -1427,6 +1449,8 @@ static void __clk_set_parent_after(struct clk_core *core,
 		clk_core_disable(old_parent);
 		clk_core_unprepare(old_parent);
 	}
+
+	trace_clk_set_parent_complete(core, parent);
 }
 
 static int __clk_set_parent(struct clk_core *clk, struct clk_core *parent,
@@ -1663,6 +1687,8 @@ static void clk_change_rate(struct clk_core *clk)
 	else if (clk->parent)
 		best_parent_rate = clk->parent->rate;
 
+	trace_clk_set_rate(clk, clk->new_rate);
+
 	if (clk->new_parent && clk->new_parent != clk->parent) {
 		old_parent = __clk_set_parent_before(clk, clk->new_parent);
 
@@ -1681,6 +1707,8 @@ static void clk_change_rate(struct clk_core *clk)
 	if (!skip_set_rate && clk->ops->set_rate)
 		clk->ops->set_rate(clk->hw, clk->new_rate, best_parent_rate);
 
+	trace_clk_set_rate_complete(clk, clk->new_rate);
+
 	clk->rate = clk_recalc(clk, best_parent_rate);
 
 	if (clk->notifier_count && old_rate != clk->rate)
@@ -2081,6 +2109,8 @@ int clk_set_phase(struct clk *clk, int degrees)
 
 	clk_prepare_lock();
 
+	trace_clk_set_phase(clk->core, degrees);
+
 	if (!clk->core->ops->set_phase)
 		goto out_unlock;
 
@@ -2090,6 +2120,8 @@ int clk_set_phase(struct clk *clk, int degrees)
 		clk->core->phase = degrees;
 
 out_unlock:
+	trace_clk_set_phase_complete(clk->core, degrees);
+
 	clk_prepare_unlock();
 
 out:
#2 lore raw

Quoting Steven Rostedt (2015-02-02 08:00:33)

Quoted 11 lines
Quoted 8 lines · On Fri, 30 Jan 2015 16:16:11 -0800 Stephen Boyd <[email protected]> wrote:

It's useful to have tracepoints around operations that change the hardware state so that we can debug clock hardware performance and operations. Four basic types of events are supported: on/off events for enable, disable, prepare, unprepare that only record an event and a clock name, rate changing events for clk_set_{min_,max_}rate{_range}(), phase changing events for clk_set_phase() and parent changing events for clk_set_parent().

Quoted 5 lines
Quoted 1 line
Cc Steven Rostedt <[email protected]>

I don't see anything wrong with the implementation of the tracepoints. Now whether or not they are useful is up to the clk maintainer to decide.

Steven,

Thanks for the review. Stephen Boyd is now co-maintaining the framework by the way.

Regards,
Mike

Quoted 143 lines
Quoted 13 lines
---
 drivers/clk/clk.c          |  32 ++++++++
 include/trace/events/clk.h | 198 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 230 insertions(+)
 create mode 100644 include/trace/events/clk.h

unlock_out:

drivers/clk/clk.c static void clk_core_unprepare(struct clk_core *clk) · line 877

Quoted 10 lines
drivers/clk/clk.c +3 -0
@@ -861,9 +868,12 @@ static void clk_core_unprepare(struct clk_core *clk)
 
      WARN_ON(clk->enable_count > 0);
 
+     trace_clk_unprepare(clk);
+
      if (clk->ops->unprepare)
              clk->ops->unprepare(clk->hw);
 
+     trace_clk_unprepare_complete(clk);
      clk_core_unprepare(clk->parent);

I guess you do not care about the clk_core_unprepare time.

Quoted 12 lines
drivers/clk/clk.c +2 -0
 }
 
@@ -901,6 +911,8 @@ static int clk_core_prepare(struct clk_core *clk)
              if (ret)
                      return ret;
 
+             trace_clk_prepare(clk);
+
              if (clk->ops->prepare) {
                      ret = clk->ops->prepare(clk->hw);
                      if (ret) {

drivers/clk/clk.c static int clk_core_prepare(struct clk_core *clk) · line 924

Quoted 5 lines
drivers/clk/clk.c +2 -0
@@ -908,6 +920,8 @@ static int clk_core_prepare(struct clk_core *clk)
                              return ret;
                      }
              }
+
+             trace_clk_prepare_complete(clk);

I'm curious to why you do not put the tracepoint within the if statement, and only show the tracepoints if the clock prepare is actually called. Also, if you exit out with that return, will you tools be OK with seeing the clk_prepare but not the clk_prepare_complete?

Quoted 26 lines
drivers/clk/clk.c +5 -0
      }
 
      clk->prepare_count++;
@@ -953,9 +967,13 @@ static void clk_core_disable(struct clk_core *clk)
      if (--clk->enable_count > 0)
              return;
 
+     trace_clk_disable(clk);
+
      if (clk->ops->disable)
              clk->ops->disable(clk->hw);
 
+     trace_clk_disable_complete(clk);
+
      clk_core_disable(clk->parent);
 }
 
@@ -1008,6 +1026,7 @@ static int clk_core_enable(struct clk_core *clk)
              if (ret)
                      return ret;
 
+             trace_clk_enable(clk);
              if (clk->ops->enable) {
                      ret = clk->ops->enable(clk->hw);
                      if (ret) {

drivers/clk/clk.c static int clk_core_enable(struct clk_core *clk) · line 1037

Quoted 4 lines
drivers/clk/clk.c +1 -0
@@ -1015,6 +1034,7 @@ static int clk_core_enable(struct clk_core *clk)
                              return ret;
                      }
              }
+             trace_clk_enable_complete(clk);

Same here.

-- Steve

Quoted 57 lines
drivers/clk/clk.c +12 -0
      }
 
      clk->enable_count++;
@@ -1383,6 +1403,8 @@ static struct clk_core *__clk_set_parent_before(struct clk_core *clk,
      unsigned long flags;
      struct clk_core *old_parent = clk->parent;
 
+     trace_clk_set_parent(clk, parent);
+
      /*
       * Migrate prepare state between parents and prevent race with
       * clk_enable().
@@ -1427,6 +1449,8 @@ static void __clk_set_parent_after(struct clk_core *core,
              clk_core_disable(old_parent);
              clk_core_unprepare(old_parent);
      }
+
+     trace_clk_set_parent_complete(core, parent);
 }
 
 static int __clk_set_parent(struct clk_core *clk, struct clk_core *parent,
@@ -1663,6 +1687,8 @@ static void clk_change_rate(struct clk_core *clk)
      else if (clk->parent)
              best_parent_rate = clk->parent->rate;
 
+     trace_clk_set_rate(clk, clk->new_rate);
+
      if (clk->new_parent && clk->new_parent != clk->parent) {
              old_parent = __clk_set_parent_before(clk, clk->new_parent);
 
@@ -1681,6 +1707,8 @@ static void clk_change_rate(struct clk_core *clk)
      if (!skip_set_rate && clk->ops->set_rate)
              clk->ops->set_rate(clk->hw, clk->new_rate, best_parent_rate);
 
+     trace_clk_set_rate_complete(clk, clk->new_rate);
+
      clk->rate = clk_recalc(clk, best_parent_rate);
 
      if (clk->notifier_count && old_rate != clk->rate)
@@ -2081,6 +2109,8 @@ int clk_set_phase(struct clk *clk, int degrees)
 
      clk_prepare_lock();
 
+     trace_clk_set_phase(clk->core, degrees);
+
      if (!clk->core->ops->set_phase)
              goto out_unlock;
 
@@ -2090,6 +2120,8 @@ int clk_set_phase(struct clk *clk, int degrees)
              clk->core->phase = degrees;
 
 out_unlock:
+     trace_clk_set_phase_complete(clk->core, degrees);
+
      clk_prepare_unlock();
 
 out:
#3 lore raw
In reply to Steven Rostedt
Quoted 30 lines · Steven Rostedt
Quoted 9 lines · On Fri, 30 Jan 2015 16:16:11 -0800 Stephen Boyd <[email protected]> wrote:

It's useful to have tracepoints around operations that change the hardware state so that we can debug clock hardware performance and operations. Four basic types of events are supported: on/off events for enable, disable, prepare, unprepare that only record an event and a clock name, rate changing events for clk_set_{min_,max_}rate{_range}(), phase changing events for clk_set_phase() and parent changing events for clk_set_parent().

Cc Steven Rostedt <[email protected]>

I don't see anything wrong with the implementation of the tracepoints. Now whether or not they are useful is up to the clk maintainer to decide.

Quoted 14 lines
---
 drivers/clk/clk.c          |  32 ++++++++
 include/trace/events/clk.h | 198 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 230 insertions(+)
 create mode 100644 include/trace/events/clk.h

unlock_out:

drivers/clk/clk.c +0 -0
@@ -861,9 +868,12 @@ static void clk_core_unprepare(struct clk_core *clk)
 
 	WARN_ON(clk->enable_count > 0);
 
Quoted 8 lines

drivers/clk/clk.c static void clk_core_unprepare(struct clk_core *clk) · line 877

Quoted 7 lines
drivers/clk/clk.c +3 -0
+	trace_clk_unprepare(clk);
+
 	if (clk->ops->unprepare)
 		clk->ops->unprepare(clk->hw);
 
+	trace_clk_unprepare_complete(clk);
 	clk_core_unprepare(clk->parent);

I guess you do not care about the clk_core_unprepare time.

Function trace will handle that?

Quoted 7 lines
Quoted 7 lines
drivers/clk/clk.c +0 -0
 }
 
@@ -901,6 +911,8 @@ static int clk_core_prepare(struct clk_core *clk)
 		if (ret)
 			return ret;
 
Quoted 16 lines

drivers/clk/clk.c static int clk_core_prepare(struct clk_core *clk) · line 924

Quoted 11 lines
drivers/clk/clk.c +4 -0
+		trace_clk_prepare(clk);
+
 		if (clk->ops->prepare) {
 			ret = clk->ops->prepare(clk->hw);
 			if (ret) {
@@ -908,6 +920,8 @@ static int clk_core_prepare(struct clk_core *clk)
 				return ret;
 			}
 		}
+
+		trace_clk_prepare_complete(clk);

I'm curious to why you do not put the tracepoint within the if statement, and only show the tracepoints if the clock prepare is actually called. Also, if you exit out with that return, will you tools be OK with seeing the clk_prepare but not the clk_prepare_complete?

Ah good point. I'll rework it so we always get the tracepoint around the clk op.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
maintainer
#4 lore raw

On Mon, 02 Feb 2015 11:41:40 -0800
Stephen Boyd <[email protected]> wrote:

+ trace_clk_unprepare_complete(clk);

Quoted 5 lines
Quoted 2 lines
Quoted 1 line

clk_core_unprepare(clk->parent);

I guess you do not care about the clk_core_unprepare time.

Function trace will handle that?

If gcc doesn't inline it.

-- Steve