Commit bb3632c6 authored by Todd E Brandt's avatar Todd E Brandt Committed by Rafael J. Wysocki

PM / sleep: trace events for suspend/resume

Adds trace events that give finer resolution into suspend/resume. These
events are graphed in the timelines generated by the analyze_suspend.py
script. They represent large areas of time consumed that are typical to
suspend and resume.

The event is triggered by calling the function "trace_suspend_resume"
with three arguments: a string (the name of the event to be displayed
in the timeline), an integer (case specific number, such as the power
state or cpu number), and a boolean (where true is used to denote the start
of the timeline event, and false to denote the end).

The suspend_resume trace event reproduces the data that the machine_suspend
trace event did, so the latter has been removed.
Signed-off-by: default avatarTodd Brandt <todd.e.brandt@intel.com>
Acked-by: default avatarSteven Rostedt <rostedt@goodmis.org>
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent 3eba148d
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <linux/acpi.h> #include <linux/acpi.h>
#include <linux/module.h> #include <linux/module.h>
#include <asm/io.h> #include <asm/io.h>
#include <trace/events/power.h>
#include "internal.h" #include "internal.h"
#include "sleep.h" #include "sleep.h"
...@@ -501,6 +502,7 @@ static int acpi_suspend_enter(suspend_state_t pm_state) ...@@ -501,6 +502,7 @@ static int acpi_suspend_enter(suspend_state_t pm_state)
ACPI_FLUSH_CPU_CACHE(); ACPI_FLUSH_CPU_CACHE();
trace_suspend_resume(TPS("acpi_suspend"), acpi_state, true);
switch (acpi_state) { switch (acpi_state) {
case ACPI_STATE_S1: case ACPI_STATE_S1:
barrier(); barrier();
...@@ -516,6 +518,7 @@ static int acpi_suspend_enter(suspend_state_t pm_state) ...@@ -516,6 +518,7 @@ static int acpi_suspend_enter(suspend_state_t pm_state)
pr_info(PREFIX "Low-level resume complete\n"); pr_info(PREFIX "Low-level resume complete\n");
break; break;
} }
trace_suspend_resume(TPS("acpi_suspend"), acpi_state, false);
/* This violates the spec but is required for bug compatibility. */ /* This violates the spec but is required for bug compatibility. */
acpi_write_bit_register(ACPI_BITREG_SCI_ENABLE, 1); acpi_write_bit_register(ACPI_BITREG_SCI_ENABLE, 1);
......
...@@ -545,6 +545,7 @@ static void dpm_resume_noirq(pm_message_t state) ...@@ -545,6 +545,7 @@ static void dpm_resume_noirq(pm_message_t state)
struct device *dev; struct device *dev;
ktime_t starttime = ktime_get(); ktime_t starttime = ktime_get();
trace_suspend_resume(TPS("dpm_resume_noirq"), state.event, true);
mutex_lock(&dpm_list_mtx); mutex_lock(&dpm_list_mtx);
pm_transition = state; pm_transition = state;
...@@ -587,6 +588,7 @@ static void dpm_resume_noirq(pm_message_t state) ...@@ -587,6 +588,7 @@ static void dpm_resume_noirq(pm_message_t state)
dpm_show_time(starttime, state, "noirq"); dpm_show_time(starttime, state, "noirq");
resume_device_irqs(); resume_device_irqs();
cpuidle_resume(); cpuidle_resume();
trace_suspend_resume(TPS("dpm_resume_noirq"), state.event, false);
} }
/** /**
...@@ -664,6 +666,7 @@ static void dpm_resume_early(pm_message_t state) ...@@ -664,6 +666,7 @@ static void dpm_resume_early(pm_message_t state)
struct device *dev; struct device *dev;
ktime_t starttime = ktime_get(); ktime_t starttime = ktime_get();
trace_suspend_resume(TPS("dpm_resume_early"), state.event, true);
mutex_lock(&dpm_list_mtx); mutex_lock(&dpm_list_mtx);
pm_transition = state; pm_transition = state;
...@@ -703,6 +706,7 @@ static void dpm_resume_early(pm_message_t state) ...@@ -703,6 +706,7 @@ static void dpm_resume_early(pm_message_t state)
mutex_unlock(&dpm_list_mtx); mutex_unlock(&dpm_list_mtx);
async_synchronize_full(); async_synchronize_full();
dpm_show_time(starttime, state, "early"); dpm_show_time(starttime, state, "early");
trace_suspend_resume(TPS("dpm_resume_early"), state.event, false);
} }
/** /**
...@@ -834,6 +838,7 @@ void dpm_resume(pm_message_t state) ...@@ -834,6 +838,7 @@ void dpm_resume(pm_message_t state)
struct device *dev; struct device *dev;
ktime_t starttime = ktime_get(); ktime_t starttime = ktime_get();
trace_suspend_resume(TPS("dpm_resume"), state.event, true);
might_sleep(); might_sleep();
mutex_lock(&dpm_list_mtx); mutex_lock(&dpm_list_mtx);
...@@ -875,6 +880,7 @@ void dpm_resume(pm_message_t state) ...@@ -875,6 +880,7 @@ void dpm_resume(pm_message_t state)
dpm_show_time(starttime, state, NULL); dpm_show_time(starttime, state, NULL);
cpufreq_resume(); cpufreq_resume();
trace_suspend_resume(TPS("dpm_resume"), state.event, false);
} }
/** /**
...@@ -932,6 +938,7 @@ void dpm_complete(pm_message_t state) ...@@ -932,6 +938,7 @@ void dpm_complete(pm_message_t state)
{ {
struct list_head list; struct list_head list;
trace_suspend_resume(TPS("dpm_complete"), state.event, true);
might_sleep(); might_sleep();
INIT_LIST_HEAD(&list); INIT_LIST_HEAD(&list);
...@@ -951,6 +958,7 @@ void dpm_complete(pm_message_t state) ...@@ -951,6 +958,7 @@ void dpm_complete(pm_message_t state)
} }
list_splice(&list, &dpm_list); list_splice(&list, &dpm_list);
mutex_unlock(&dpm_list_mtx); mutex_unlock(&dpm_list_mtx);
trace_suspend_resume(TPS("dpm_complete"), state.event, false);
} }
/** /**
...@@ -1086,6 +1094,7 @@ static int dpm_suspend_noirq(pm_message_t state) ...@@ -1086,6 +1094,7 @@ static int dpm_suspend_noirq(pm_message_t state)
ktime_t starttime = ktime_get(); ktime_t starttime = ktime_get();
int error = 0; int error = 0;
trace_suspend_resume(TPS("dpm_suspend_noirq"), state.event, true);
cpuidle_pause(); cpuidle_pause();
suspend_device_irqs(); suspend_device_irqs();
mutex_lock(&dpm_list_mtx); mutex_lock(&dpm_list_mtx);
...@@ -1126,6 +1135,7 @@ static int dpm_suspend_noirq(pm_message_t state) ...@@ -1126,6 +1135,7 @@ static int dpm_suspend_noirq(pm_message_t state)
} else { } else {
dpm_show_time(starttime, state, "noirq"); dpm_show_time(starttime, state, "noirq");
} }
trace_suspend_resume(TPS("dpm_suspend_noirq"), state.event, false);
return error; return error;
} }
...@@ -1222,6 +1232,7 @@ static int dpm_suspend_late(pm_message_t state) ...@@ -1222,6 +1232,7 @@ static int dpm_suspend_late(pm_message_t state)
ktime_t starttime = ktime_get(); ktime_t starttime = ktime_get();
int error = 0; int error = 0;
trace_suspend_resume(TPS("dpm_suspend_late"), state.event, true);
mutex_lock(&dpm_list_mtx); mutex_lock(&dpm_list_mtx);
pm_transition = state; pm_transition = state;
async_error = 0; async_error = 0;
...@@ -1257,6 +1268,7 @@ static int dpm_suspend_late(pm_message_t state) ...@@ -1257,6 +1268,7 @@ static int dpm_suspend_late(pm_message_t state)
} else { } else {
dpm_show_time(starttime, state, "late"); dpm_show_time(starttime, state, "late");
} }
trace_suspend_resume(TPS("dpm_suspend_late"), state.event, false);
return error; return error;
} }
...@@ -1461,6 +1473,7 @@ int dpm_suspend(pm_message_t state) ...@@ -1461,6 +1473,7 @@ int dpm_suspend(pm_message_t state)
ktime_t starttime = ktime_get(); ktime_t starttime = ktime_get();
int error = 0; int error = 0;
trace_suspend_resume(TPS("dpm_suspend"), state.event, true);
might_sleep(); might_sleep();
cpufreq_suspend(); cpufreq_suspend();
...@@ -1498,6 +1511,7 @@ int dpm_suspend(pm_message_t state) ...@@ -1498,6 +1511,7 @@ int dpm_suspend(pm_message_t state)
dpm_save_failed_step(SUSPEND_SUSPEND); dpm_save_failed_step(SUSPEND_SUSPEND);
} else } else
dpm_show_time(starttime, state, NULL); dpm_show_time(starttime, state, NULL);
trace_suspend_resume(TPS("dpm_suspend"), state.event, false);
return error; return error;
} }
...@@ -1582,6 +1596,7 @@ int dpm_prepare(pm_message_t state) ...@@ -1582,6 +1596,7 @@ int dpm_prepare(pm_message_t state)
{ {
int error = 0; int error = 0;
trace_suspend_resume(TPS("dpm_prepare"), state.event, true);
might_sleep(); might_sleep();
mutex_lock(&dpm_list_mtx); mutex_lock(&dpm_list_mtx);
...@@ -1612,6 +1627,7 @@ int dpm_prepare(pm_message_t state) ...@@ -1612,6 +1627,7 @@ int dpm_prepare(pm_message_t state)
put_device(dev); put_device(dev);
} }
mutex_unlock(&dpm_list_mtx); mutex_unlock(&dpm_list_mtx);
trace_suspend_resume(TPS("dpm_prepare"), state.event, false);
return error; return error;
} }
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <trace/events/power.h>
static LIST_HEAD(syscore_ops_list); static LIST_HEAD(syscore_ops_list);
static DEFINE_MUTEX(syscore_ops_lock); static DEFINE_MUTEX(syscore_ops_lock);
...@@ -49,6 +50,7 @@ int syscore_suspend(void) ...@@ -49,6 +50,7 @@ int syscore_suspend(void)
struct syscore_ops *ops; struct syscore_ops *ops;
int ret = 0; int ret = 0;
trace_suspend_resume(TPS("syscore_suspend"), 0, true);
pr_debug("Checking wakeup interrupts\n"); pr_debug("Checking wakeup interrupts\n");
/* Return error code if there are any wakeup interrupts pending. */ /* Return error code if there are any wakeup interrupts pending. */
...@@ -70,6 +72,7 @@ int syscore_suspend(void) ...@@ -70,6 +72,7 @@ int syscore_suspend(void)
"Interrupts enabled after %pF\n", ops->suspend); "Interrupts enabled after %pF\n", ops->suspend);
} }
trace_suspend_resume(TPS("syscore_suspend"), 0, false);
return 0; return 0;
err_out: err_out:
...@@ -92,6 +95,7 @@ void syscore_resume(void) ...@@ -92,6 +95,7 @@ void syscore_resume(void)
{ {
struct syscore_ops *ops; struct syscore_ops *ops;
trace_suspend_resume(TPS("syscore_resume"), 0, true);
WARN_ONCE(!irqs_disabled(), WARN_ONCE(!irqs_disabled(),
"Interrupts enabled before system core resume.\n"); "Interrupts enabled before system core resume.\n");
...@@ -103,6 +107,7 @@ void syscore_resume(void) ...@@ -103,6 +107,7 @@ void syscore_resume(void)
WARN_ONCE(!irqs_disabled(), WARN_ONCE(!irqs_disabled(),
"Interrupts enabled after %pF\n", ops->resume); "Interrupts enabled after %pF\n", ops->resume);
} }
trace_suspend_resume(TPS("syscore_resume"), 0, false);
} }
EXPORT_SYMBOL_GPL(syscore_resume); EXPORT_SYMBOL_GPL(syscore_resume);
#endif /* CONFIG_PM_SLEEP */ #endif /* CONFIG_PM_SLEEP */
......
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
#include <linux/ktime.h> #include <linux/ktime.h>
#include <linux/pm_qos.h> #include <linux/pm_qos.h>
#include <linux/tracepoint.h> #include <linux/tracepoint.h>
#include <linux/ftrace_event.h>
#define TPS(x) tracepoint_string(x)
DECLARE_EVENT_CLASS(cpu, DECLARE_EVENT_CLASS(cpu,
...@@ -97,23 +100,6 @@ DEFINE_EVENT(cpu, cpu_frequency, ...@@ -97,23 +100,6 @@ DEFINE_EVENT(cpu, cpu_frequency,
TP_ARGS(frequency, cpu_id) TP_ARGS(frequency, cpu_id)
); );
TRACE_EVENT(machine_suspend,
TP_PROTO(unsigned int state),
TP_ARGS(state),
TP_STRUCT__entry(
__field( u32, state )
),
TP_fast_assign(
__entry->state = state;
),
TP_printk("state=%lu", (unsigned long)__entry->state)
);
TRACE_EVENT(device_pm_report_time, TRACE_EVENT(device_pm_report_time,
TP_PROTO(struct device *dev, const char *pm_ops, s64 ops_time, TP_PROTO(struct device *dev, const char *pm_ops, s64 ops_time,
...@@ -151,6 +137,28 @@ TRACE_EVENT(device_pm_report_time, ...@@ -151,6 +137,28 @@ TRACE_EVENT(device_pm_report_time,
__entry->ops_time, __entry->error) __entry->ops_time, __entry->error)
); );
TRACE_EVENT(suspend_resume,
TP_PROTO(const char *action, int val, bool start),
TP_ARGS(action, val, start),
TP_STRUCT__entry(
__field(const char *, action)
__field(int, val)
__field(bool, start)
),
TP_fast_assign(
__entry->action = action;
__entry->val = val;
__entry->start = start;
),
TP_printk("%s[%u] %s", __entry->action, (unsigned int)__entry->val,
(__entry->start)?"begin":"end")
);
DECLARE_EVENT_CLASS(wakeup_source, DECLARE_EVENT_CLASS(wakeup_source,
TP_PROTO(const char *name, unsigned int state), TP_PROTO(const char *name, unsigned int state),
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <linux/gfp.h> #include <linux/gfp.h>
#include <linux/suspend.h> #include <linux/suspend.h>
#include <linux/lockdep.h> #include <linux/lockdep.h>
#include <trace/events/power.h>
#include "smpboot.h" #include "smpboot.h"
...@@ -522,7 +523,9 @@ int disable_nonboot_cpus(void) ...@@ -522,7 +523,9 @@ int disable_nonboot_cpus(void)
for_each_online_cpu(cpu) { for_each_online_cpu(cpu) {
if (cpu == first_cpu) if (cpu == first_cpu)
continue; continue;
trace_suspend_resume(TPS("CPU_OFF"), cpu, true);
error = _cpu_down(cpu, 1); error = _cpu_down(cpu, 1);
trace_suspend_resume(TPS("CPU_OFF"), cpu, false);
if (!error) if (!error)
cpumask_set_cpu(cpu, frozen_cpus); cpumask_set_cpu(cpu, frozen_cpus);
else { else {
...@@ -566,7 +569,9 @@ void __ref enable_nonboot_cpus(void) ...@@ -566,7 +569,9 @@ void __ref enable_nonboot_cpus(void)
arch_enable_nonboot_cpus_begin(); arch_enable_nonboot_cpus_begin();
for_each_cpu(cpu, frozen_cpus) { for_each_cpu(cpu, frozen_cpus) {
trace_suspend_resume(TPS("CPU_ON"), cpu, true);
error = _cpu_up(cpu, 1); error = _cpu_up(cpu, 1);
trace_suspend_resume(TPS("CPU_ON"), cpu, false);
if (!error) { if (!error) {
printk(KERN_INFO "CPU%d is up\n", cpu); printk(KERN_INFO "CPU%d is up\n", cpu);
continue; continue;
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <linux/syscore_ops.h> #include <linux/syscore_ops.h>
#include <linux/ctype.h> #include <linux/ctype.h>
#include <linux/genhd.h> #include <linux/genhd.h>
#include <trace/events/power.h>
#include "power.h" #include "power.h"
...@@ -292,7 +293,9 @@ static int create_image(int platform_mode) ...@@ -292,7 +293,9 @@ static int create_image(int platform_mode)
in_suspend = 1; in_suspend = 1;
save_processor_state(); save_processor_state();
trace_suspend_resume(TPS("machine_suspend"), PM_EVENT_HIBERNATE, true);
error = swsusp_arch_suspend(); error = swsusp_arch_suspend();
trace_suspend_resume(TPS("machine_suspend"), PM_EVENT_HIBERNATE, false);
if (error) if (error)
printk(KERN_ERR "PM: Error %d creating hibernation image\n", printk(KERN_ERR "PM: Error %d creating hibernation image\n",
error); error);
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/workqueue.h> #include <linux/workqueue.h>
#include <linux/kmod.h> #include <linux/kmod.h>
#include <trace/events/power.h>
/* /*
* Timeout for stopping processes * Timeout for stopping processes
...@@ -175,6 +176,7 @@ void thaw_processes(void) ...@@ -175,6 +176,7 @@ void thaw_processes(void)
struct task_struct *g, *p; struct task_struct *g, *p;
struct task_struct *curr = current; struct task_struct *curr = current;
trace_suspend_resume(TPS("thaw_processes"), 0, true);
if (pm_freezing) if (pm_freezing)
atomic_dec(&system_freezing_cnt); atomic_dec(&system_freezing_cnt);
pm_freezing = false; pm_freezing = false;
...@@ -201,6 +203,7 @@ void thaw_processes(void) ...@@ -201,6 +203,7 @@ void thaw_processes(void)
schedule(); schedule();
printk("done.\n"); printk("done.\n");
trace_suspend_resume(TPS("thaw_processes"), 0, false);
} }
void thaw_kernel_threads(void) void thaw_kernel_threads(void)
......
...@@ -177,7 +177,9 @@ static int suspend_prepare(suspend_state_t state) ...@@ -177,7 +177,9 @@ static int suspend_prepare(suspend_state_t state)
if (error) if (error)
goto Finish; goto Finish;
trace_suspend_resume(TPS("freeze_processes"), 0, true);
error = suspend_freeze_processes(); error = suspend_freeze_processes();
trace_suspend_resume(TPS("freeze_processes"), 0, false);
if (!error) if (!error)
return 0; return 0;
...@@ -240,7 +242,9 @@ static int suspend_enter(suspend_state_t state, bool *wakeup) ...@@ -240,7 +242,9 @@ static int suspend_enter(suspend_state_t state, bool *wakeup)
* all the devices are suspended. * all the devices are suspended.
*/ */
if (state == PM_SUSPEND_FREEZE) { if (state == PM_SUSPEND_FREEZE) {
trace_suspend_resume(TPS("machine_suspend"), state, true);
freeze_enter(); freeze_enter();
trace_suspend_resume(TPS("machine_suspend"), state, false);
goto Platform_wake; goto Platform_wake;
} }
...@@ -256,7 +260,11 @@ static int suspend_enter(suspend_state_t state, bool *wakeup) ...@@ -256,7 +260,11 @@ static int suspend_enter(suspend_state_t state, bool *wakeup)
if (!error) { if (!error) {
*wakeup = pm_wakeup_pending(); *wakeup = pm_wakeup_pending();
if (!(suspend_test(TEST_CORE) || *wakeup)) { if (!(suspend_test(TEST_CORE) || *wakeup)) {
trace_suspend_resume(TPS("machine_suspend"),
state, true);
error = suspend_ops->enter(state); error = suspend_ops->enter(state);
trace_suspend_resume(TPS("machine_suspend"),
state, false);
events_check_enabled = false; events_check_enabled = false;
} }
syscore_resume(); syscore_resume();
...@@ -294,7 +302,6 @@ int suspend_devices_and_enter(suspend_state_t state) ...@@ -294,7 +302,6 @@ int suspend_devices_and_enter(suspend_state_t state)
if (need_suspend_ops(state) && !suspend_ops) if (need_suspend_ops(state) && !suspend_ops)
return -ENOSYS; return -ENOSYS;
trace_machine_suspend(state);
if (need_suspend_ops(state) && suspend_ops->begin) { if (need_suspend_ops(state) && suspend_ops->begin) {
error = suspend_ops->begin(state); error = suspend_ops->begin(state);
if (error) if (error)
...@@ -331,7 +338,6 @@ int suspend_devices_and_enter(suspend_state_t state) ...@@ -331,7 +338,6 @@ int suspend_devices_and_enter(suspend_state_t state)
else if (state == PM_SUSPEND_FREEZE && freeze_ops->end) else if (state == PM_SUSPEND_FREEZE && freeze_ops->end)
freeze_ops->end(); freeze_ops->end();
trace_machine_suspend(PWR_EVENT_EXIT);
return error; return error;
Recover_platform: Recover_platform:
...@@ -365,6 +371,7 @@ static int enter_state(suspend_state_t state) ...@@ -365,6 +371,7 @@ static int enter_state(suspend_state_t state)
{ {
int error; int error;
trace_suspend_resume(TPS("suspend_enter"), state, true);
if (state == PM_SUSPEND_FREEZE) { if (state == PM_SUSPEND_FREEZE) {
#ifdef CONFIG_PM_DEBUG #ifdef CONFIG_PM_DEBUG
if (pm_test_level != TEST_NONE && pm_test_level <= TEST_CPUS) { if (pm_test_level != TEST_NONE && pm_test_level <= TEST_CPUS) {
...@@ -382,9 +389,11 @@ static int enter_state(suspend_state_t state) ...@@ -382,9 +389,11 @@ static int enter_state(suspend_state_t state)
if (state == PM_SUSPEND_FREEZE) if (state == PM_SUSPEND_FREEZE)
freeze_begin(); freeze_begin();
trace_suspend_resume(TPS("sync_filesystems"), 0, true);
printk(KERN_INFO "PM: Syncing filesystems ... "); printk(KERN_INFO "PM: Syncing filesystems ... ");
sys_sync(); sys_sync();
printk("done.\n"); printk("done.\n");
trace_suspend_resume(TPS("sync_filesystems"), 0, false);
pr_debug("PM: Preparing system for %s sleep\n", pm_states[state].label); pr_debug("PM: Preparing system for %s sleep\n", pm_states[state].label);
error = suspend_prepare(state); error = suspend_prepare(state);
...@@ -394,6 +403,7 @@ static int enter_state(suspend_state_t state) ...@@ -394,6 +403,7 @@ static int enter_state(suspend_state_t state)
if (suspend_test(TEST_FREEZER)) if (suspend_test(TEST_FREEZER))
goto Finish; goto Finish;
trace_suspend_resume(TPS("suspend_enter"), state, false);
pr_debug("PM: Entering %s sleep\n", pm_states[state].label); pr_debug("PM: Entering %s sleep\n", pm_states[state].label);
pm_restrict_gfp_mask(); pm_restrict_gfp_mask();
error = suspend_devices_and_enter(state); error = suspend_devices_and_enter(state);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment