Skip to contentSkip to conversation

PM / tracing: Add pm_qos_update_target/flags tracepoints

PATCH Superseded [email protected] 3 participants 7 messages Jun 20, 2013 – Jun 21, 2013

Subsystems (6)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 PM / tracing: Add pm_qos_update_target/flags tracepoints

From: Sahara <[email protected]>

This patch adds tracepoints to pm_qos_update_target and pm_qos_update_flags. It's useful for checking pm qos action, previous value and current value.

---
 include/trace/events/power.h |   49 ++++++++++++++++++++++++++++++++++++++++++
 kernel/power/qos.c           |    3 ++
 2 files changed, 52 insertions(+), 0 deletions(-)
include/trace/events/power.h +49 -0
index 427acab..27a714c 100644
@@ -5,6 +5,7 @@
 #define _TRACE_POWER_H
 
 #include <linux/ktime.h>
+#include <linux/pm_qos.h>
 #include <linux/tracepoint.h>
 
 DECLARE_EVENT_CLASS(cpu,
@@ -177,6 +178,54 @@ DEFINE_EVENT(power_domain, power_domain_target,
 
 	TP_ARGS(name, state, cpu_id)
 );
+
+/*
+ * The pm qos events are used for pm qos update
+ */
+DECLARE_EVENT_CLASS(pm_qos_update,
+
+	TP_PROTO(enum pm_qos_req_action action, int prev_value, int curr_value),
+
+	TP_ARGS(action, prev_value, curr_value),
+
+	TP_STRUCT__entry(
+		__field( enum pm_qos_req_action, action         )
+		__field( int,                    prev_value     )
+		__field( int,                    curr_value     )
+	),
+
+	TP_fast_assign(
+		__entry->action = action;
+		__entry->prev_value = prev_value;
+		__entry->curr_value = curr_value;
+	),
+
+	TP_printk("action=%s prev_value=%d curr_value=%d",
+		  (__entry->action == PM_QOS_ADD_REQ) ? "ADD_REQ" :
+		  (__entry->action == PM_QOS_UPDATE_REQ) ? "UPDATE_REQ" :
+		  (__entry->action == PM_QOS_REMOVE_REQ) ? "REMOVE_REQ" : "??",
+		  __entry->prev_value, __entry->curr_value)
+);
+
+DEFINE_EVENT(pm_qos_update, pm_qos_update_target,
+
+	TP_PROTO(enum pm_qos_req_action action, int prev_value, int curr_value),
+
+	TP_ARGS(action, prev_value, curr_value)
+);
+
+DEFINE_EVENT_PRINT(pm_qos_update, pm_qos_update_flags,
+
+	TP_PROTO(enum pm_qos_req_action action, int prev_value, int curr_value),
+
+	TP_ARGS(action, prev_value, curr_value),
+
+	TP_printk("action=%s prev_value=0x%x curr_value=0x%x",
+		  (__entry->action == PM_QOS_ADD_REQ) ? "ADD_REQ" :
+		  (__entry->action == PM_QOS_UPDATE_REQ) ? "UPDATE_REQ" :
+		  (__entry->action == PM_QOS_REMOVE_REQ) ? "REMOVE_REQ" : "??",
+		  __entry->prev_value, __entry->curr_value)
+);
 #endif /* _TRACE_POWER_H */
 
 /* This part must be outside protection */
kernel/power/qos.c +3 -0
index f2f5f6e..4fb8d14 100644
@@ -44,6 +44,7 @@
 
 #include <linux/uaccess.h>
 #include <linux/export.h>
+#include <trace/events/power.h>
 
 /*
  * locking rule: all changes to constraints or notifiers lists
@@ -202,6 +203,7 @@ int pm_qos_update_target(struct pm_qos_constraints *c, struct plist_node *node,
 
 	spin_unlock_irqrestore(&pm_qos_lock, flags);
 
+	trace_pm_qos_update_target(action, prev_value, curr_value);
 	if (prev_value != curr_value) {
 		blocking_notifier_call_chain(c->notifiers,
 					     (unsigned long)curr_value,
@@ -272,6 +274,7 @@ bool pm_qos_update_flags(struct pm_qos_flags *pqf,
 
 	spin_unlock_irqrestore(&pm_qos_lock, irqflags);
 
+	trace_pm_qos_update_flags(action, prev_value, curr_value);
 	return prev_value != curr_value;
 }
 
Signature · 1 line
1.7.1
#1 lore raw

PATCH 2/4 PM / tracing: Add pm_qos_request tracepoints

From: Sahara <[email protected]>

Adds tracepoints to pm_qos_add_request, pm_qos_update_request, pm_qos_remove_request, and pm_qos_update_request_timeout. It's useful for checking pm_qos_class, value, and timeout_us.

---
 include/trace/events/power.h |   75 ++++++++++++++++++++++++++++++++++++++++++
 kernel/power/qos.c           |    5 +++
 2 files changed, 80 insertions(+), 0 deletions(-)
include/trace/events/power.h +75 -0
index 27a714c..28b6645 100644
@@ -182,6 +182,81 @@ DEFINE_EVENT(power_domain, power_domain_target,
 /*
  * The pm qos events are used for pm qos update
  */
+DECLARE_EVENT_CLASS(pm_qos_request,
+
+	TP_PROTO(int pm_qos_class, s32 value),
+
+	TP_ARGS(pm_qos_class, value),
+
+	TP_STRUCT__entry(
+		__field( int,                    pm_qos_class   )
+		__field( s32,                    value          )
+	),
+
+	TP_fast_assign(
+		__entry->pm_qos_class = pm_qos_class;
+		__entry->value = value;
+	),
+
+	TP_printk("pm_qos_class=%s value=%d",
+		  (__entry->pm_qos_class == PM_QOS_CPU_DMA_LATENCY) ?
+			"CPU_DMA_LATENCY" :
+		  (__entry->pm_qos_class == PM_QOS_NETWORK_LATENCY) ?
+			"NETWORK_LATENCY" :
+		  (__entry->pm_qos_class == PM_QOS_NETWORK_THROUGHPUT) ?
+			"NETWORK_THROUGHPUT" : "??",
+		  __entry->value)
+);
+
+DEFINE_EVENT(pm_qos_request, pm_qos_add_request,
+
+	TP_PROTO(int pm_qos_class, s32 value),
+
+	TP_ARGS(pm_qos_class, value)
+);
+
+DEFINE_EVENT(pm_qos_request, pm_qos_update_request,
+
+	TP_PROTO(int pm_qos_class, s32 value),
+
+	TP_ARGS(pm_qos_class, value)
+);
+
+DEFINE_EVENT(pm_qos_request, pm_qos_remove_request,
+
+	TP_PROTO(int pm_qos_class, s32 value),
+
+	TP_ARGS(pm_qos_class, value)
+);
+
+TRACE_EVENT(pm_qos_update_request_timeout,
+
+	TP_PROTO(int pm_qos_class, s32 value, unsigned long timeout_us),
+
+	TP_ARGS(pm_qos_class, value, timeout_us),
+
+	TP_STRUCT__entry(
+		__field( int,                    pm_qos_class   )
+		__field( s32,                    value          )
+		__field( unsigned long,          timeout_us     )
+	),
+
+	TP_fast_assign(
+		__entry->pm_qos_class = pm_qos_class;
+		__entry->value = value;
+		__entry->timeout_us = timeout_us;
+	),
+
+	TP_printk("pm_qos_class=%s value=%d, timeout_us=%ld",
+		  (__entry->pm_qos_class == PM_QOS_CPU_DMA_LATENCY) ?
+			"CPU_DMA_LATENCY" :
+		  (__entry->pm_qos_class == PM_QOS_NETWORK_LATENCY) ?
+			"NETWORK_LATENCY" :
+		  (__entry->pm_qos_class == PM_QOS_NETWORK_THROUGHPUT) ?
+			"NETWORK_THROUGHPUT" : "??",
+		  __entry->value, __entry->timeout_us)
+);
+
 DECLARE_EVENT_CLASS(pm_qos_update,
 
 	TP_PROTO(enum pm_qos_req_action action, int prev_value, int curr_value),
kernel/power/qos.c +5 -0
index 4fb8d14..06fe285 100644
@@ -336,6 +336,7 @@ void pm_qos_add_request(struct pm_qos_request *req,
 	}
 	req->pm_qos_class = pm_qos_class;
 	INIT_DELAYED_WORK(&req->work, pm_qos_work_fn);
+	trace_pm_qos_add_request(pm_qos_class, value);
 	pm_qos_update_target(pm_qos_array[pm_qos_class]->constraints,
 			     &req->node, PM_QOS_ADD_REQ, value);
 }
@@ -364,6 +365,7 @@ void pm_qos_update_request(struct pm_qos_request *req,
 
 	cancel_delayed_work_sync(&req->work);
 
+	trace_pm_qos_update_request(req->pm_qos_class, new_value);
 	if (new_value != req->node.prio)
 		pm_qos_update_target(
 			pm_qos_array[req->pm_qos_class]->constraints,
@@ -390,6 +392,8 @@ void pm_qos_update_request_timeout(struct pm_qos_request *req, s32 new_value,
 
 	cancel_delayed_work_sync(&req->work);
 
+	trace_pm_qos_update_request_timeout(req->pm_qos_class,
+					    new_value, timeout_us);
 	if (new_value != req->node.prio)
 		pm_qos_update_target(
 			pm_qos_array[req->pm_qos_class]->constraints,
@@ -419,6 +423,7 @@ void pm_qos_remove_request(struct pm_qos_request *req)
 
 	cancel_delayed_work_sync(&req->work);
 
+	trace_pm_qos_remove_request(req->pm_qos_class, PM_QOS_DEFAULT_VALUE);
 	pm_qos_update_target(pm_qos_array[req->pm_qos_class]->constraints,
 			     &req->node, PM_QOS_REMOVE_REQ,
 			     PM_QOS_DEFAULT_VALUE);
Signature · 1 line
1.7.1
#2 lore raw

PATCH 3/4 PM / tracing: Add dev_pm_qos_request tracepoints

From: Sahara <[email protected]>

Adds tracepoints to dev_pm_qos_add_request, dev_pm_qos_update_request, and dev_pm_qos_remove_request. It's useful for checking device name, dev_pm_qos_request_type, and value.

---
 drivers/base/power/qos.c     |    6 +++++
 include/trace/events/power.h |   52 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+), 0 deletions(-)
drivers/base/power/qos.c +6 -0
index 71671c4..5c1361a 100644
@@ -42,6 +42,7 @@
 #include <linux/export.h>
 #include <linux/pm_runtime.h>
 #include <linux/err.h>
+#include <trace/events/power.h>
 
 #include "power.h"
 
@@ -305,6 +306,7 @@ int dev_pm_qos_add_request(struct device *dev, struct dev_pm_qos_request *req,
 	else if (!dev->power.qos)
 		ret = dev_pm_qos_constraints_allocate(dev);
 
+	trace_dev_pm_qos_add_request(dev_name(dev), type, value);
 	if (!ret) {
 		req->dev = dev;
 		req->type = type;
@@ -349,6 +351,8 @@ static int __dev_pm_qos_update_request(struct dev_pm_qos_request *req,
 		return -EINVAL;
 	}
 
+	trace_dev_pm_qos_update_request(dev_name(req->dev), req->type,
+					new_value);
 	if (curr_value != new_value)
 		ret = apply_constraint(req, PM_QOS_UPDATE_REQ, new_value);
 
@@ -398,6 +402,8 @@ static int __dev_pm_qos_remove_request(struct dev_pm_qos_request *req)
 	if (IS_ERR_OR_NULL(req->dev->power.qos))
 		return -ENODEV;
 
+	trace_dev_pm_qos_remove_request(dev_name(req->dev), req->type,
+					PM_QOS_DEFAULT_VALUE);
 	ret = apply_constraint(req, PM_QOS_REMOVE_REQ, PM_QOS_DEFAULT_VALUE);
 	memset(req, 0, sizeof(*req));
 	return ret;
include/trace/events/power.h +52 -0

58 lines not on this page · raw message

Signature · 1 line
1.7.1
#3 lore raw

PATCH 4/4 Documentation: Add pm_qos and dev_pm_qos to events-power.txt

From: Sahara <[email protected]>

Add PM QOS events section and description to events-power.txt.

---
 Documentation/trace/events-power.txt |   31 +++++++++++++++++++++++++++++++
 1 files changed, 31 insertions(+), 0 deletions(-)
Documentation/trace/events-power.txt +31 -0
index e1498ff..90ebab6 100644
@@ -63,3 +63,34 @@ power_domain_target	"%s state=%lu cpu_id=%lu"
 The first parameter gives the power domain name (e.g. "mpu_pwrdm").
 The second parameter is the power domain target state.
 
+4. PM QOS events
+================
+The pm qos events are used for qos add/update/remove request and for
+target/flags update.
+
+pm_qos_add_request                 "pm_qos_class=%s value=%d"
+pm_qos_update_request              "pm_qos_class=%s value=%d"
+pm_qos_remove_request              "pm_qos_class=%s value=%d"
+pm_qos_update_request_timeout      "pm_qos_class=%s value=%d, timeout_us=%ld"
+
+The first parameter gives the qos class name (e.g. "CPU_DMA_LATENCY").
+The second parameter is value to be added/updated/removed.
+The third parameter is timeout value in usec.
+
+pm_qos_update_target               "action=%s prev_value=%d curr_value=%d"
+pm_qos_update_flags                "action=%s prev_value=0x%x curr_value=0x%x"
+
+The first parameter gives the qos action name (e.g. "ADD_REQ").
+The second parameter is the previous qos value.
+The third parameter is the current qos value to update.
+
+And, there are also events used for device pm qos add/update/remove request.
+
+dev_pm_qos_add_request             "device=%s type=%s new_value=%d"
+dev_pm_qos_update_request          "device=%s type=%s new_value=%d"
+dev_pm_qos_remove_request          "device=%s type=%s new_value=%d"
+
+The first parameter gives the device name which tries to add/update/remove
+qos requests.
+The second parameter gives the request type (e.g. "DEV_PM_QOS_LATENCY").
+The third parameter is value to be added/updated/removed.
Signature · 1 line
1.7.1
maintainer
#4 lore raw
In reply to [email protected]

include/trace/events/power.h DEFINE_EVENT(power_domain, power_domain_target, · line 229

Quoted 13 lines · On Thu, 2013-06-20 at 13:56 +0900, [email protected] wrote:
include/trace/events/power.h +12 -0
+DEFINE_EVENT_PRINT(pm_qos_update, pm_qos_update_flags,
+
+	TP_PROTO(enum pm_qos_req_action action, int prev_value, int curr_value),
+
+	TP_ARGS(action, prev_value, curr_value),
+
+	TP_printk("action=%s prev_value=0x%x curr_value=0x%x",
+		  (__entry->action == PM_QOS_ADD_REQ) ? "ADD_REQ" :
+		  (__entry->action == PM_QOS_UPDATE_REQ) ? "UPDATE_REQ" :
+		  (__entry->action == PM_QOS_REMOVE_REQ) ? "REMOVE_REQ" : "??",
+		  __entry->prev_value, __entry->curr_value)
+);
 #endif /* _TRACE_POWER_H */

Nice! I believe you are the first one to add a new event using a DEFINE_EVENT_PRINT(). And you did it properly (almost, see below) :-)

The only other use of that was by Li Zefan who converted an existing event to DEFINE_EVENT_PRINT().

There's a helper function to convert numbers into strings:

	TP_printk("action=%s prev_value=0x%x curr_value=0x%x",
		__print_symbolic(__entry->action,
			{ PM_QOS_ADD_REQ,	"ADD_REQ" },
			{ PM_QOS_UPDATE_REQ,	"UPDATE_REQ" },
			{ PM_QOS_REMOVE_REQ,	"REMOVE_REQ" }),
		__entry->prev_value, __entry->curr_value)

The advantage of using __print_symbolic() is that it allows both perf and trace-cmd to read this event properly. Their parsers are not full C parsers, and when you open code the the processing, they both will fail to parse how to read the output, and will just default to printing the fields via their raw numbers.

Another advantage is if the __entry->action is not one of the defined fields, instead of outputting "??" it will output the number in hex. Say if __entry->action is 0x123, the __print_symbolic will return "0x123" as a string and that will be shown to the user, letting you know the actual value of the field that was unknown.

-- Steve

maintainer
#6 lore raw
In reply to [email protected]
Quoted 18 lines · On Thu, 2013-06-20 at 13:56 +0900, [email protected] wrote:

/*
+ * The pm qos events are used for pm qos update
+ */

include/trace/events/power.h +15 -0
+DECLARE_EVENT_CLASS(pm_qos_update,
+
+	TP_PROTO(enum pm_qos_req_action action, int prev_value, int curr_value),
+
+	TP_ARGS(action, prev_value, curr_value),
+
+	TP_STRUCT__entry(
+		__field( enum pm_qos_req_action, action         )
+		__field( int,                    prev_value     )
+		__field( int,                    curr_value     )
+	),
+
+	TP_fast_assign(
+		__entry->action = action;
+		__entry->prev_value = prev_value;

include/trace/events/power.h DEFINE_EVENT(power_domain, power_domain_target, · line 209

Quoted 10 lines
include/trace/events/power.h +10 -0
+		__entry->curr_value = curr_value;
+	),
+
+	TP_printk("action=%s prev_value=%d curr_value=%d",
+		  (__entry->action == PM_QOS_ADD_REQ) ? "ADD_REQ" :
+		  (__entry->action == PM_QOS_UPDATE_REQ) ? "UPDATE_REQ" :
+		  (__entry->action == PM_QOS_REMOVE_REQ) ? "REMOVE_REQ" : "??",
+		  __entry->prev_value, __entry->curr_value)
+);
+

This should be converted to use __print_symbolic() as well.

-- Steve

#5 lore raw
In reply to Steven Rostedt

2013년 06월 20일 21:35, Steven Rostedt 쓴 글:

Quoted 36 lines · On Thu, 2013-06-20 at 13:56 +0900, [email protected] wrote:
Quoted 4 lines
include/trace/events/power.h +3 -0
+DEFINE_EVENT_PRINT(pm_qos_update, pm_qos_update_flags,
+
+	TP_PROTO(enum pm_qos_req_action action, int prev_value, int curr_value),

include/trace/events/power.h DEFINE_EVENT(power_domain, power_domain_target, · line 229

Quoted 10 lines
include/trace/events/power.h +9 -0
+
+	TP_ARGS(action, prev_value, curr_value),
+
+	TP_printk("action=%s prev_value=0x%x curr_value=0x%x",
+		  (__entry->action == PM_QOS_ADD_REQ) ? "ADD_REQ" :
+		  (__entry->action == PM_QOS_UPDATE_REQ) ? "UPDATE_REQ" :
+		  (__entry->action == PM_QOS_REMOVE_REQ) ? "REMOVE_REQ" : "??",
+		  __entry->prev_value, __entry->curr_value)
+);
  #endif /* _TRACE_POWER_H */

Nice! I believe you are the first one to add a new event using a DEFINE_EVENT_PRINT(). And you did it properly (almost, see below) :-)

The only other use of that was by Li Zefan who converted an existing event to DEFINE_EVENT_PRINT().

There's a helper function to convert numbers into strings:

	TP_printk("action=%s prev_value=0x%x curr_value=0x%x",
		__print_symbolic(__entry->action,
			{ PM_QOS_ADD_REQ,	"ADD_REQ" },
			{ PM_QOS_UPDATE_REQ,	"UPDATE_REQ" },
			{ PM_QOS_REMOVE_REQ,	"REMOVE_REQ" }),
		__entry->prev_value, __entry->curr_value)

The advantage of using __print_symbolic() is that it allows both perf and trace-cmd to read this event properly. Their parsers are not full C parsers, and when you open code the the processing, they both will fail to parse how to read the output, and will just default to printing the fields via their raw numbers.

Quoted 10 lines

Another advantage is if the __entry->action is not one of the defined fields, instead of outputting "??" it will output the number in hex. Say if __entry->action is 0x123, the __print_symbolic will return "0x123" as a string and that will be shown to the user, letting you know the actual value of the field that was unknown.

-- Steve

Thanks Steve. I modified codes to use __print_symbolic following your recommendation.

-- Sahara