162306a36Sopenharmony_ci                                                _
262306a36Sopenharmony_ci    _ __  _ __ ___         __ _ _ __ __ _ _ __ | |__
362306a36Sopenharmony_ci   | '_ \| '_ ` _ \ _____ / _` | '__/ _` | '_ \| '_ \
462306a36Sopenharmony_ci   | |_) | | | | | |_____| (_| | | | (_| | |_) | | | |
562306a36Sopenharmony_ci   | .__/|_| |_| |_|      \__, |_|  \__,_| .__/|_| |_|
662306a36Sopenharmony_ci   |_|                    |___/          |_|
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci   pm-graph: suspend/resume/boot timing analysis tools
962306a36Sopenharmony_ci    Version: 5.11
1062306a36Sopenharmony_ci     Author: Todd Brandt <todd.e.brandt@intel.com>
1162306a36Sopenharmony_ci  Home Page: https://www.intel.com/content/www/us/en/developer/topic-technology/open/pm-graph/overview.html
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci Report bugs/issues at bugzilla.kernel.org Tools/pm-graph
1462306a36Sopenharmony_ci	- https://bugzilla.kernel.org/buglist.cgi?component=pm-graph&product=Tools
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci Full documentation available online & in man pages
1762306a36Sopenharmony_ci	- Getting Started:
1862306a36Sopenharmony_ci	  https://www.intel.com/content/www/us/en/developer/articles/technical/usage.html
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci	- Feature Summary:
2162306a36Sopenharmony_ci	  https://www.intel.com/content/www/us/en/developer/topic-technology/open/pm-graph/features.html
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ci	- upstream version in git:
2462306a36Sopenharmony_ci	  git clone https://github.com/intel/pm-graph/
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci Table of Contents
2762306a36Sopenharmony_ci	- Overview
2862306a36Sopenharmony_ci	- Setup
2962306a36Sopenharmony_ci	- Usage
3062306a36Sopenharmony_ci		- Basic Usage
3162306a36Sopenharmony_ci		- Dev Mode Usage
3262306a36Sopenharmony_ci		- Proc Mode Usage
3362306a36Sopenharmony_ci	- Endurance Testing
3462306a36Sopenharmony_ci		- Usage Examples
3562306a36Sopenharmony_ci	- Configuration Files
3662306a36Sopenharmony_ci		- Usage Examples
3762306a36Sopenharmony_ci		- Config File Options
3862306a36Sopenharmony_ci	- Custom Timeline Entries
3962306a36Sopenharmony_ci		- Adding/Editing Timeline Functions
4062306a36Sopenharmony_ci		- Adding/Editing Dev Timeline Source Functions
4162306a36Sopenharmony_ci		- Verifying your Custom Functions
4262306a36Sopenharmony_ci	- Testing on consumer linux Operating Systems
4362306a36Sopenharmony_ci		- Android
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ci------------------------------------------------------------------
4662306a36Sopenharmony_ci|                          OVERVIEW                              |
4762306a36Sopenharmony_ci------------------------------------------------------------------
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci This tool suite is designed to assist kernel and OS developers in optimizing
5062306a36Sopenharmony_ci their linux stack's suspend/resume & boot time. Using a kernel image built
5162306a36Sopenharmony_ci with a few extra options enabled, the tools will execute a suspend or boot,
5262306a36Sopenharmony_ci and will capture dmesg and ftrace data. This data is transformed into a set of
5362306a36Sopenharmony_ci timelines and a callgraph to give a quick and detailed view of which devices
5462306a36Sopenharmony_ci and kernel processes are taking the most time in suspend/resume & boot.
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ci------------------------------------------------------------------
5762306a36Sopenharmony_ci|                            SETUP                               |
5862306a36Sopenharmony_ci------------------------------------------------------------------
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci    Package Requirements
6162306a36Sopenharmony_ci       - runs with python2 or python3, choice is made by /usr/bin/python link
6262306a36Sopenharmony_ci       - python
6362306a36Sopenharmony_ci       - python-configparser (for python2 sleepgraph)
6462306a36Sopenharmony_ci       - python-requests (for stresstester.py)
6562306a36Sopenharmony_ci       - linux-tools-common (for turbostat usage in sleepgraph)
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ci       Ubuntu:
6862306a36Sopenharmony_ci          sudo apt-get install python python-configparser python-requests linux-tools-common
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_ci       Fedora:
7162306a36Sopenharmony_ci          sudo dnf install python python-configparser python-requests linux-tools-common
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci    The tools can most easily be installed via git clone and make install
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_ci    $> git clone http://github.com/intel/pm-graph.git
7662306a36Sopenharmony_ci    $> cd pm-graph
7762306a36Sopenharmony_ci    $> sudo make install
7862306a36Sopenharmony_ci    $> man sleepgraph ; man bootgraph
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ci    Setup involves some minor kernel configuration
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ci    The following kernel build options are required for all kernels:
8362306a36Sopenharmony_ci        CONFIG_DEVMEM=y
8462306a36Sopenharmony_ci        CONFIG_PM_DEBUG=y
8562306a36Sopenharmony_ci        CONFIG_PM_SLEEP_DEBUG=y
8662306a36Sopenharmony_ci        CONFIG_FTRACE=y
8762306a36Sopenharmony_ci        CONFIG_FUNCTION_TRACER=y
8862306a36Sopenharmony_ci        CONFIG_FUNCTION_GRAPH_TRACER=y
8962306a36Sopenharmony_ci        CONFIG_KPROBES=y
9062306a36Sopenharmony_ci        CONFIG_KPROBES_ON_FTRACE=y
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ci	In kernel 3.15.0, two patches were upstreamed which enable the
9362306a36Sopenharmony_ci        v3.0 behavior. These patches allow the tool to read all the
9462306a36Sopenharmony_ci        data from trace events instead of from dmesg. You can enable
9562306a36Sopenharmony_ci        this behavior on earlier kernels with these patches:
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_ci        (kernel/pre-3.15/enable_trace_events_suspend_resume.patch)
9862306a36Sopenharmony_ci        (kernel/pre-3.15/enable_trace_events_device_pm_callback.patch)
9962306a36Sopenharmony_ci
10062306a36Sopenharmony_ci	If you're using bootgraph, or sleepgraph with a kernel older than 3.15.0,
10162306a36Sopenharmony_ci		the following additional kernel parameters are required:
10262306a36Sopenharmony_ci        (e.g. in file /etc/default/grub)
10362306a36Sopenharmony_ci        GRUB_CMDLINE_LINUX_DEFAULT="... initcall_debug log_buf_len=32M ..."
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_ci	If you're using a kernel older than 3.11-rc2, the following simple
10662306a36Sopenharmony_ci		patch must be applied to enable ftrace data:
10762306a36Sopenharmony_ci        in file: kernel/power/suspend.c
10862306a36Sopenharmony_ci        in function: int suspend_devices_and_enter(suspend_state_t state)
10962306a36Sopenharmony_ci        remove call to "ftrace_stop();"
11062306a36Sopenharmony_ci        remove call to "ftrace_start();"
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ci        There is a patch which does this for kernel v3.8.0:
11362306a36Sopenharmony_ci        (kernel/pre-3.11-rc2/enable_ftrace_in_suspendresume.patch)
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_ci
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_ci------------------------------------------------------------------
11862306a36Sopenharmony_ci|                            USAGE                               |
11962306a36Sopenharmony_ci------------------------------------------------------------------
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_ciBasic Usage
12262306a36Sopenharmony_ci___________
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_ci 1) First configure a kernel using the instructions from the previous sections.
12562306a36Sopenharmony_ci    Then build, install, and boot with it.
12662306a36Sopenharmony_ci 2) Open up a terminal window and execute the mode list command:
12762306a36Sopenharmony_ci
12862306a36Sopenharmony_ci	%> sudo ./sleepgraph.py -modes
12962306a36Sopenharmony_ci		['freeze', 'mem', 'disk']
13062306a36Sopenharmony_ci
13162306a36Sopenharmony_ci Execute a test using one of the available power modes, e.g. mem (S3):
13262306a36Sopenharmony_ci
13362306a36Sopenharmony_ci	%> sudo ./sleepgraph.py -m mem -rtcwake 15
13462306a36Sopenharmony_ci
13562306a36Sopenharmony_ci		or with a config file
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_ci	%> sudo ./sleepgraph.py -config config/suspend.cfg
13862306a36Sopenharmony_ci
13962306a36Sopenharmony_ci When the system comes back you'll see the script finishing up and
14062306a36Sopenharmony_ci creating the output files in the test subdir. It generates output
14162306a36Sopenharmony_ci files in subdirectory: suspend-mmddyy-HHMMSS. The ftrace file can
14262306a36Sopenharmony_ci be used to regenerate the html timeline with different options
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_ci     HTML output:                    <hostname>_<mode>.html
14562306a36Sopenharmony_ci     raw dmesg output:               <hostname>_<mode>_dmesg.txt
14662306a36Sopenharmony_ci     raw ftrace output:              <hostname>_<mode>_ftrace.txt
14762306a36Sopenharmony_ci
14862306a36Sopenharmony_ci View the html in firefox or chrome.
14962306a36Sopenharmony_ci
15062306a36Sopenharmony_ci
15162306a36Sopenharmony_ciDev Mode Usage
15262306a36Sopenharmony_ci______________
15362306a36Sopenharmony_ci
15462306a36Sopenharmony_ci Developer mode adds information on low level source calls to the timeline.
15562306a36Sopenharmony_ci The tool sets kprobes on all delay and mutex calls to see which devices
15662306a36Sopenharmony_ci are waiting for something and when. It also sets a suite of kprobes on
15762306a36Sopenharmony_ci subsystem dependent calls to better fill out the timeline.
15862306a36Sopenharmony_ci
15962306a36Sopenharmony_ci The tool will also expose kernel threads that don't normally show up in the
16062306a36Sopenharmony_ci timeline. This is useful in discovering dependent threads to get a better
16162306a36Sopenharmony_ci idea of what each device is waiting for. For instance, the scsi_eh thread,
16262306a36Sopenharmony_ci a.k.a. scsi resume error handler, is what each SATA disk device waits for
16362306a36Sopenharmony_ci before it can continue resume.
16462306a36Sopenharmony_ci
16562306a36Sopenharmony_ci The timeline will be much larger if run with dev mode, so it can be useful
16662306a36Sopenharmony_ci to set the -mindev option to clip out any device blocks that are too small
16762306a36Sopenharmony_ci to see easily. The following command will give a nice dev mode run:
16862306a36Sopenharmony_ci
16962306a36Sopenharmony_ci %> sudo ./sleepgraph.py -m mem -rtcwake 15 -mindev 1 -dev
17062306a36Sopenharmony_ci
17162306a36Sopenharmony_ci	or with a config file
17262306a36Sopenharmony_ci
17362306a36Sopenharmony_ci %> sudo ./sleepgraph.py -config config/suspend-dev.cfg
17462306a36Sopenharmony_ci
17562306a36Sopenharmony_ci
17662306a36Sopenharmony_ciProc Mode Usage
17762306a36Sopenharmony_ci_______________
17862306a36Sopenharmony_ci
17962306a36Sopenharmony_ci Proc mode adds user process info to the timeline. This is done in a manner
18062306a36Sopenharmony_ci similar to the bootchart utility, which graphs init processes and their
18162306a36Sopenharmony_ci execution as the system boots. This tool option does the same thing but for
18262306a36Sopenharmony_ci the period before and after suspend/resume.
18362306a36Sopenharmony_ci
18462306a36Sopenharmony_ci In order to see any process info, there needs to be some delay before or
18562306a36Sopenharmony_ci after resume since processes are frozen in suspend_prepare and thawed in
18662306a36Sopenharmony_ci resume_complete. The predelay and postdelay args allow you to do this. It
18762306a36Sopenharmony_ci can also be useful to run in x2 mode with an x2 delay, this way you can
18862306a36Sopenharmony_ci see process activity before and after resume, and in between two
18962306a36Sopenharmony_ci successive suspend/resumes.
19062306a36Sopenharmony_ci
19162306a36Sopenharmony_ci The command can be run like this:
19262306a36Sopenharmony_ci
19362306a36Sopenharmony_ci %> sudo ./sleepgraph.py -m mem -rtcwake 15 -x2 -x2delay 1000 -predelay 1000 -postdelay 1000 -proc
19462306a36Sopenharmony_ci
19562306a36Sopenharmony_ci	or with a config file
19662306a36Sopenharmony_ci
19762306a36Sopenharmony_ci %> sudo ./sleepgraph.py -config config/suspend-proc.cfg
19862306a36Sopenharmony_ci
19962306a36Sopenharmony_ci------------------------------------------------------------------
20062306a36Sopenharmony_ci|                     ENDURANCE TESTING                          |
20162306a36Sopenharmony_ci------------------------------------------------------------------
20262306a36Sopenharmony_ci
20362306a36Sopenharmony_ci The best way to gauge the health of a system is to run a series of
20462306a36Sopenharmony_ci suspend/resumes over an extended period and analyze the behavior. This can be
20562306a36Sopenharmony_ci accomplished with sleepgraph's -multi argument. You specify two numbers: the
20662306a36Sopenharmony_ci number of tests to run OR the duration in days, hours, or minutes, and the
20762306a36Sopenharmony_ci delay in seconds between them. For instance, -multi 20 5: execute 20 tests with
20862306a36Sopenharmony_ci a 5 second delay between each, or -multi 24h 0: execute tests over a 24 hour
20962306a36Sopenharmony_ci period with no delay between tests. You can include any other options you like
21062306a36Sopenharmony_ci to generate the data you want. It's most useful to collect dev mode timelines
21162306a36Sopenharmony_ci as the kprobes don't alter the performance much and you get more insight.
21262306a36Sopenharmony_ci
21362306a36Sopenharmony_ci On completion, the output folder contains a series of folders for the
21462306a36Sopenharmony_ci individual test data and a set of summary pages in the root. The summary.html
21562306a36Sopenharmony_ci file is a tabular list of the tests with relevant info and links. The
21662306a36Sopenharmony_ci summary-issue.html and summary-devices.html files include data taken from
21762306a36Sopenharmony_ci all tests on kernel issues and device performance. The folder looks like this:
21862306a36Sopenharmony_ci
21962306a36Sopenharmony_ci  suspend-xN-{date}-{time}:
22062306a36Sopenharmony_ci	summary.html
22162306a36Sopenharmony_ci	summary-issues.html
22262306a36Sopenharmony_ci	summary-devices.html
22362306a36Sopenharmony_ci	suspend-{date}-{time} (1)
22462306a36Sopenharmony_ci	suspend-{date}-{time} (2)
22562306a36Sopenharmony_ci	...
22662306a36Sopenharmony_ci
22762306a36Sopenharmony_ci These are the relevant arguments to use for testing:
22862306a36Sopenharmony_ci
22962306a36Sopenharmony_ci  -m mode
23062306a36Sopenharmony_ci	Mode to initiate for suspend e.g. mem, freeze, standby (default: mem).
23162306a36Sopenharmony_ci
23262306a36Sopenharmony_ci  -rtcwake t
23362306a36Sopenharmony_ci	Use rtcwake to autoresume after t seconds (default: 15).
23462306a36Sopenharmony_ci
23562306a36Sopenharmony_ci  -gzip (optional)
23662306a36Sopenharmony_ci	Gzip the trace and dmesg logs to save space. The tool can also read in
23762306a36Sopenharmony_ci	gzipped logs for processing. This reduces the multitest folder size.
23862306a36Sopenharmony_ci
23962306a36Sopenharmony_ci  -dev (optional)
24062306a36Sopenharmony_ci	Add kernel source calls and threads to the timeline (default: disabled).
24162306a36Sopenharmony_ci
24262306a36Sopenharmony_ci  -multi n d
24362306a36Sopenharmony_ci	Execute n consecutive tests at d seconds intervals. The outputs will be
24462306a36Sopenharmony_ci	created in a new subdirectory: suspend-xN-{date}-{time}. When the multitest
24562306a36Sopenharmony_ci	run is done, the -summary command is called automatically to create summary
24662306a36Sopenharmony_ci	html files for all the data (unless you use -skiphtml). -skiphtml will
24762306a36Sopenharmony_ci	speed up the testing by not creating timelines or summary html files. You
24862306a36Sopenharmony_ci	can then run the tool again at a later time with -summary and -genhtml to
24962306a36Sopenharmony_ci	create the timelines.
25062306a36Sopenharmony_ci
25162306a36Sopenharmony_ci  -skiphtml (optional)
25262306a36Sopenharmony_ci	Run the test and capture the trace logs, but skip the timeline and summary
25362306a36Sopenharmony_ci	html generation. This can greatly speed up overall testing. You can then
25462306a36Sopenharmony_ci	copy the data to a faster host machine and run -summary -genhtml to
25562306a36Sopenharmony_ci	generate the timelines and summary.
25662306a36Sopenharmony_ci
25762306a36Sopenharmony_ci These are the relevant commands to use after testing is complete:
25862306a36Sopenharmony_ci
25962306a36Sopenharmony_ci  -summary indir
26062306a36Sopenharmony_ci	Generate or regenerate the summary for a -multi test run. Creates three
26162306a36Sopenharmony_ci	files: summary.html, summary-issues.html, and summary-devices.html in the
26262306a36Sopenharmony_ci	current folder. summary.html is a table of tests with relevant info sorted
26362306a36Sopenharmony_ci	by kernel/host/mode, and links to the test html files. summary-issues.html
26462306a36Sopenharmony_ci	is a list of kernel issues found in dmesg from all the tests.
26562306a36Sopenharmony_ci	summary-devices.html is a list of devices and times from all the tests.
26662306a36Sopenharmony_ci
26762306a36Sopenharmony_ci  -genhtml
26862306a36Sopenharmony_ci	Used  with -summary to regenerate any missing html timelines from their
26962306a36Sopenharmony_ci	dmesg and ftrace logs. This will require a significant amount of time if
27062306a36Sopenharmony_ci	there are thousands of tests.
27162306a36Sopenharmony_ci
27262306a36Sopenharmony_ciUsage Examples
27362306a36Sopenharmony_ci_______________
27462306a36Sopenharmony_ci
27562306a36Sopenharmony_ci A multitest is initiated like this:
27662306a36Sopenharmony_ci
27762306a36Sopenharmony_ci  %> sudo ./sleepgraph.py -m mem -rtcwake 10 -dev -gzip -multi 2000 0
27862306a36Sopenharmony_ci
27962306a36Sopenharmony_ci	or you can skip timeline generation in order to speed things up
28062306a36Sopenharmony_ci
28162306a36Sopenharmony_ci  %> sudo ./sleepgraph.py -m mem -rtcwake 10 -dev -gzip -multi 2000 0 -skiphtml
28262306a36Sopenharmony_ci
28362306a36Sopenharmony_ci The tool will produce an output folder with all the test subfolders inside.
28462306a36Sopenharmony_ci Each test subfolder contains the dmesg/ftrace logs and/or the html timeline
28562306a36Sopenharmony_ci depending on whether you used the -skiphtml option. The root folder contains
28662306a36Sopenharmony_ci the summary.html files.
28762306a36Sopenharmony_ci
28862306a36Sopenharmony_ci The summary for an existing multitest is generated like this:
28962306a36Sopenharmony_ci
29062306a36Sopenharmony_ci  %> cd suspend-x2000-{date}-{time}
29162306a36Sopenharmony_ci  %> sleepgraph.py -summary .
29262306a36Sopenharmony_ci
29362306a36Sopenharmony_ci	or if you need to generate the html timelines you can use -genhtml
29462306a36Sopenharmony_ci
29562306a36Sopenharmony_ci  %> cd suspend-xN-{date}-{time}
29662306a36Sopenharmony_ci  %> sleepgraph.py -summary . -genhtml
29762306a36Sopenharmony_ci
29862306a36Sopenharmony_ci------------------------------------------------------------------
29962306a36Sopenharmony_ci|                    CONFIGURATION FILES                         |
30062306a36Sopenharmony_ci------------------------------------------------------------------
30162306a36Sopenharmony_ci
30262306a36Sopenharmony_ci Since 4.0 we've moved to using config files in lieu of command line options.
30362306a36Sopenharmony_ci The config folder contains a collection of typical use cases.
30462306a36Sopenharmony_ci There are corresponding configs for other power modes:
30562306a36Sopenharmony_ci
30662306a36Sopenharmony_ci	Simple suspend/resume with basic timeline (mem/freeze/standby)
30762306a36Sopenharmony_ci		config/suspend.cfg
30862306a36Sopenharmony_ci		config/freeze.cfg
30962306a36Sopenharmony_ci		config/standby.cfg
31062306a36Sopenharmony_ci
31162306a36Sopenharmony_ci	Dev mode suspend/resume with dev timeline (mem/freeze/standby)
31262306a36Sopenharmony_ci		config/suspend-dev.cfg
31362306a36Sopenharmony_ci		config/freeze-dev.cfg
31462306a36Sopenharmony_ci		config/standby-dev.cfg
31562306a36Sopenharmony_ci
31662306a36Sopenharmony_ci	Simple suspend/resume with timeline and callgraph (mem/freeze/standby)
31762306a36Sopenharmony_ci		config/suspend-callgraph.cfg
31862306a36Sopenharmony_ci		config/freeze-callgraph.cfg
31962306a36Sopenharmony_ci		config/standby-callgraph.cfg
32062306a36Sopenharmony_ci
32162306a36Sopenharmony_ci	Sample proc mode x2 run using mem suspend
32262306a36Sopenharmony_ci		config/suspend-x2-proc.cfg
32362306a36Sopenharmony_ci
32462306a36Sopenharmony_ci	Sample for editing timeline funcs (moves internal functions into config)
32562306a36Sopenharmony_ci		config/custom-timeline-functions.cfg
32662306a36Sopenharmony_ci
32762306a36Sopenharmony_ci	Sample debug config for serio subsystem
32862306a36Sopenharmony_ci		config/debug-serio-suspend.cfg
32962306a36Sopenharmony_ci
33062306a36Sopenharmony_ci
33162306a36Sopenharmony_ciUsage Examples
33262306a36Sopenharmony_ci______________
33362306a36Sopenharmony_ci
33462306a36Sopenharmony_ci Run a simple mem suspend:
33562306a36Sopenharmony_ci %> sudo ./sleepgraph.py -config config/suspend.cfg
33662306a36Sopenharmony_ci
33762306a36Sopenharmony_ci Run a mem suspend with callgraph data:
33862306a36Sopenharmony_ci %> sudo ./sleepgraph.py -config config/suspend-callgraph.cfg
33962306a36Sopenharmony_ci
34062306a36Sopenharmony_ci Run a mem suspend with dev mode detail:
34162306a36Sopenharmony_ci %> sudo ./sleepgraph.py -config config/suspend-dev.cfg
34262306a36Sopenharmony_ci
34362306a36Sopenharmony_ci
34462306a36Sopenharmony_ciConfig File Options
34562306a36Sopenharmony_ci___________________
34662306a36Sopenharmony_ci
34762306a36Sopenharmony_ci [Settings]
34862306a36Sopenharmony_ci
34962306a36Sopenharmony_ci # Verbosity: print verbose messages (def: false)
35062306a36Sopenharmony_ci verbose: false
35162306a36Sopenharmony_ci
35262306a36Sopenharmony_ci # Suspend Mode: e.g. standby, mem, freeze, disk (def: mem)
35362306a36Sopenharmony_ci mode: mem
35462306a36Sopenharmony_ci
35562306a36Sopenharmony_ci # Output Directory Format: {hostname}, {date}, {time} give current values
35662306a36Sopenharmony_ci output-dir: suspend-{hostname}-{date}-{time}
35762306a36Sopenharmony_ci
35862306a36Sopenharmony_ci # Automatic Wakeup: use rtcwake to wakeup after X seconds (def: infinity)
35962306a36Sopenharmony_ci rtcwake: 15
36062306a36Sopenharmony_ci
36162306a36Sopenharmony_ci # Add Logs: add the dmesg and ftrace log to the html output (def: false)
36262306a36Sopenharmony_ci addlogs: false
36362306a36Sopenharmony_ci
36462306a36Sopenharmony_ci # Sus/Res Gap: insert a gap between sus & res in the timeline (def: false)
36562306a36Sopenharmony_ci srgap: false
36662306a36Sopenharmony_ci
36762306a36Sopenharmony_ci # Custom Command: Command to execute in lieu of suspend (def: "")
36862306a36Sopenharmony_ci command: echo mem > /sys/power/state
36962306a36Sopenharmony_ci
37062306a36Sopenharmony_ci # Proc mode: graph user processes and cpu usage in the timeline (def: false)
37162306a36Sopenharmony_ci proc: false
37262306a36Sopenharmony_ci
37362306a36Sopenharmony_ci # Dev mode: graph source functions in the timeline (def: false)
37462306a36Sopenharmony_ci dev: false
37562306a36Sopenharmony_ci
37662306a36Sopenharmony_ci # Suspend/Resume x2: run 2 suspend/resumes back to back (def: false)
37762306a36Sopenharmony_ci x2: false
37862306a36Sopenharmony_ci
37962306a36Sopenharmony_ci # x2 Suspend Delay: time delay between the two test runs in ms (def: 0 ms)
38062306a36Sopenharmony_ci x2delay: 0
38162306a36Sopenharmony_ci
38262306a36Sopenharmony_ci # Pre Suspend Delay: nclude an N ms delay before (1st) suspend (def: 0 ms)
38362306a36Sopenharmony_ci predelay: 0
38462306a36Sopenharmony_ci
38562306a36Sopenharmony_ci # Post Resume Delay: include an N ms delay after (last) resume (def: 0 ms)
38662306a36Sopenharmony_ci postdelay: 0
38762306a36Sopenharmony_ci
38862306a36Sopenharmony_ci # Min Device Length: graph only dev callbacks longer than min (def: 0.001 ms)
38962306a36Sopenharmony_ci mindev: 0.001
39062306a36Sopenharmony_ci
39162306a36Sopenharmony_ci # Callgraph: gather ftrace callgraph data on all timeline events (def: false)
39262306a36Sopenharmony_ci callgraph: false
39362306a36Sopenharmony_ci
39462306a36Sopenharmony_ci # Expand Callgraph: pre-expand the callgraph treeviews in html (def: false)
39562306a36Sopenharmony_ci expandcg: false
39662306a36Sopenharmony_ci
39762306a36Sopenharmony_ci # Min Callgraph Length: show callgraphs only if longer than min (def: 1 ms)
39862306a36Sopenharmony_ci mincg: 1
39962306a36Sopenharmony_ci
40062306a36Sopenharmony_ci # Timestamp Precision: number of sig digits in timestamps (0:S, [3:ms], 6:us)
40162306a36Sopenharmony_ci timeprec: 3
40262306a36Sopenharmony_ci
40362306a36Sopenharmony_ci # Device Filter: show only devs whose name/driver includes one of these strings
40462306a36Sopenharmony_ci devicefilter: _cpu_up,_cpu_down,i915,usb
40562306a36Sopenharmony_ci
40662306a36Sopenharmony_ci # Override default timeline entries:
40762306a36Sopenharmony_ci # Do not use the internal default functions for timeline entries (def: false)
40862306a36Sopenharmony_ci # Set this to true if you intend to only use the ones defined in the config
40962306a36Sopenharmony_ci override-timeline-functions: true
41062306a36Sopenharmony_ci
41162306a36Sopenharmony_ci # Override default dev timeline entries:
41262306a36Sopenharmony_ci # Do not use the internal default functions for dev timeline entries (def: false)
41362306a36Sopenharmony_ci # Set this to true if you intend to only use the ones defined in the config
41462306a36Sopenharmony_ci override-dev-timeline-functions: true
41562306a36Sopenharmony_ci
41662306a36Sopenharmony_ci # Call Loop Max Gap (dev mode only)
41762306a36Sopenharmony_ci # merge loops of the same call if each is less than maxgap apart (def: 100us)
41862306a36Sopenharmony_ci callloop-maxgap: 0.0001
41962306a36Sopenharmony_ci
42062306a36Sopenharmony_ci # Call Loop Max Length (dev mode only)
42162306a36Sopenharmony_ci # merge loops of the same call if each is less than maxlen in length (def: 5ms)
42262306a36Sopenharmony_ci callloop-maxlen: 0.005
42362306a36Sopenharmony_ci
42462306a36Sopenharmony_ci------------------------------------------------------------------
42562306a36Sopenharmony_ci|                   CUSTOM TIMELINE ENTRIES                      |
42662306a36Sopenharmony_ci------------------------------------------------------------------
42762306a36Sopenharmony_ci
42862306a36Sopenharmony_ciAdding or Editing Timeline Functions
42962306a36Sopenharmony_ci____________________________________
43062306a36Sopenharmony_ci
43162306a36Sopenharmony_ci The tool uses an array of function names to fill out empty spaces in the
43262306a36Sopenharmony_ci timeline where device callbacks don't appear. For instance, in suspend_prepare
43362306a36Sopenharmony_ci the tool adds the sys_sync and freeze_processes calls as virtual device blocks
43462306a36Sopenharmony_ci in the timeline to show you where the time is going. These calls should fill
43562306a36Sopenharmony_ci the timeline with contiguous data so that most kernel execution is covered.
43662306a36Sopenharmony_ci
43762306a36Sopenharmony_ci It is possible to add new function calls to the timeline by adding them to
43862306a36Sopenharmony_ci the config. It's also possible to copy the internal timeline functions into
43962306a36Sopenharmony_ci the config so that you can override and edit them. Place them in the
44062306a36Sopenharmony_ci timeline_functions_ARCH section with the name of your architecture appended.
44162306a36Sopenharmony_ci i.e. for x86_64: [timeline_functions_x86_64]
44262306a36Sopenharmony_ci
44362306a36Sopenharmony_ci Use the override-timeline-functions option if you only want to use your
44462306a36Sopenharmony_ci custom calls, or leave it false to append them to the internal ones.
44562306a36Sopenharmony_ci
44662306a36Sopenharmony_ci This section includes a list of functions (set using kprobes) which use both
44762306a36Sopenharmony_ci symbol data and function arg data. The args are pulled directly from the
44862306a36Sopenharmony_ci stack using this architecture's registers and stack formatting. Each entry
44962306a36Sopenharmony_ci can include up to four pieces of info: The function name, a format string,
45062306a36Sopenharmony_ci an argument list, and a color. But only a function name is required.
45162306a36Sopenharmony_ci
45262306a36Sopenharmony_ci For a full example config, see config/custom-timeline-functions.cfg. It pulls
45362306a36Sopenharmony_ci all the internal timeline functions into the config and allows you to edit
45462306a36Sopenharmony_ci them.
45562306a36Sopenharmony_ci
45662306a36Sopenharmony_ci  Entry format:
45762306a36Sopenharmony_ci
45862306a36Sopenharmony_ci    function: format{fn_arg1}_{fn_arg2} fn_arg1 fn_arg2 ... [color=purple]
45962306a36Sopenharmony_ci
46062306a36Sopenharmony_ci  Required Arguments:
46162306a36Sopenharmony_ci
46262306a36Sopenharmony_ci    function: The symbol name for the function you want probed, this is the
46362306a36Sopenharmony_ci              minimum required for an entry, it will show up as the function
46462306a36Sopenharmony_ci              name with no arguments.
46562306a36Sopenharmony_ci
46662306a36Sopenharmony_ci        example: _cpu_up:
46762306a36Sopenharmony_ci
46862306a36Sopenharmony_ci  Optional Arguments:
46962306a36Sopenharmony_ci
47062306a36Sopenharmony_ci    format: The format to display the data on the timeline in. Use braces to
47162306a36Sopenharmony_ci            enclose the arg names.
47262306a36Sopenharmony_ci
47362306a36Sopenharmony_ci        example: CPU_ON[{cpu}]
47462306a36Sopenharmony_ci
47562306a36Sopenharmony_ci    color: The color of the entry block in the timeline. The default color is
47662306a36Sopenharmony_ci           transparent, so the entry shares the phase color. The color is an
47762306a36Sopenharmony_ci           html color string, either a word, or an RGB.
47862306a36Sopenharmony_ci
47962306a36Sopenharmony_ci        example: [color=#CC00CC]
48062306a36Sopenharmony_ci
48162306a36Sopenharmony_ci    arglist: A list of arguments from registers/stack addresses. See URL:
48262306a36Sopenharmony_ci             https://www.kernel.org/doc/Documentation/trace/kprobetrace.txt
48362306a36Sopenharmony_ci
48462306a36Sopenharmony_ci        example: cpu=%di:s32
48562306a36Sopenharmony_ci
48662306a36Sopenharmony_ci Here is a full example entry. It displays cpu resume calls in the timeline
48762306a36Sopenharmony_ci in orange. They will appear as CPU_ON[0], CPU_ON[1], etc.
48862306a36Sopenharmony_ci
48962306a36Sopenharmony_ci  [timeline_functions_x86_64]
49062306a36Sopenharmony_ci  _cpu_up: CPU_ON[{cpu}] cpu=%di:s32 [color=orange]
49162306a36Sopenharmony_ci
49262306a36Sopenharmony_ci
49362306a36Sopenharmony_ciAdding or Editing Dev Mode Timeline Source Functions
49462306a36Sopenharmony_ci____________________________________________________
49562306a36Sopenharmony_ci
49662306a36Sopenharmony_ci In dev mode, the tool uses an array of function names to monitor source
49762306a36Sopenharmony_ci execution within the timeline entries.
49862306a36Sopenharmony_ci
49962306a36Sopenharmony_ci The function calls are displayed inside the main device/call blocks in the
50062306a36Sopenharmony_ci timeline. However, if a function call is not within a main timeline event,
50162306a36Sopenharmony_ci it will spawn an entirely new event named after the caller's kernel thread.
50262306a36Sopenharmony_ci These asynchronous kernel threads will populate in a separate section
50362306a36Sopenharmony_ci beneath the main device/call section.
50462306a36Sopenharmony_ci
50562306a36Sopenharmony_ci The tool has a set of hard coded calls which focus on the most common use
50662306a36Sopenharmony_ci cases: msleep, udelay, schedule_timeout, mutex_lock_slowpath, etc. These are
50762306a36Sopenharmony_ci the functions that add a hardcoded time delay to the suspend/resume path.
50862306a36Sopenharmony_ci The tool also includes some common functions native to important
50962306a36Sopenharmony_ci subsystems: ata, i915, and ACPI, etc.
51062306a36Sopenharmony_ci
51162306a36Sopenharmony_ci It is possible to add new function calls to the dev timeline by adding them
51262306a36Sopenharmony_ci to the config. It's also possible to copy the internal dev timeline
51362306a36Sopenharmony_ci functions into the config so that you can override and edit them. Place them
51462306a36Sopenharmony_ci in the dev_timeline_functions_ARCH section with the name of your architecture
51562306a36Sopenharmony_ci appended. i.e. for x86_64: [dev_timeline_functions_x86_64]
51662306a36Sopenharmony_ci
51762306a36Sopenharmony_ci Use the override-dev-timeline-functions option if you only want to use your
51862306a36Sopenharmony_ci custom calls, or leave it false to append them to the internal ones.
51962306a36Sopenharmony_ci
52062306a36Sopenharmony_ci The format is the same as the timeline_functions_x86_64 section. It's a
52162306a36Sopenharmony_ci list of functions (set using kprobes) which use both symbol data and function
52262306a36Sopenharmony_ci arg data. The args are pulled directly from the stack using this
52362306a36Sopenharmony_ci architecture's registers and stack formatting. Each entry can include up
52462306a36Sopenharmony_ci to four pieces of info: The function name, a format string, an argument list,
52562306a36Sopenharmony_ci and a color. But only the function name is required.
52662306a36Sopenharmony_ci
52762306a36Sopenharmony_ci For a full example config, see config/custom-timeline-functions.cfg. It pulls
52862306a36Sopenharmony_ci all the internal dev timeline functions into the config and allows you to edit
52962306a36Sopenharmony_ci them.
53062306a36Sopenharmony_ci
53162306a36Sopenharmony_ci Here is a full example entry. It displays the ATA port reset calls as
53262306a36Sopenharmony_ci ataN_port_reset in the timeline. This is where most of the SATA disk resume
53362306a36Sopenharmony_ci time goes, so it can be helpful to see the low level call.
53462306a36Sopenharmony_ci
53562306a36Sopenharmony_ci  [dev_timeline_functions_x86_64]
53662306a36Sopenharmony_ci  ata_eh_recover: ata{port}_port_reset port=+36(%di):s32 [color=#CC00CC]
53762306a36Sopenharmony_ci
53862306a36Sopenharmony_ci
53962306a36Sopenharmony_ciVerifying your custom functions
54062306a36Sopenharmony_ci_______________________________
54162306a36Sopenharmony_ci
54262306a36Sopenharmony_ci Once you have a set of functions (kprobes) defined, it can be useful to
54362306a36Sopenharmony_ci perform a quick check to see if you formatted them correctly and if the system
54462306a36Sopenharmony_ci actually supports them. To do this, run the tool with your config file
54562306a36Sopenharmony_ci and the -status option. The tool will go through all the kprobes (both
54662306a36Sopenharmony_ci custom and internal if you haven't overridden them) and actually attempts
54762306a36Sopenharmony_ci to set them in ftrace. It will then print out success or fail for you.
54862306a36Sopenharmony_ci
54962306a36Sopenharmony_ci Note that kprobes which don't actually exist in the kernel won't stop the
55062306a36Sopenharmony_ci tool, they just wont show up.
55162306a36Sopenharmony_ci
55262306a36Sopenharmony_ci For example:
55362306a36Sopenharmony_ci
55462306a36Sopenharmony_ci sudo ./sleepgraph.py -config config/custom-timeline-functions.cfg -status
55562306a36Sopenharmony_ci Checking this system (myhostname)...
55662306a36Sopenharmony_ci    have root access: YES
55762306a36Sopenharmony_ci    is sysfs mounted: YES
55862306a36Sopenharmony_ci    is "mem" a valid power mode: YES
55962306a36Sopenharmony_ci    is ftrace supported: YES
56062306a36Sopenharmony_ci    are kprobes supported: YES
56162306a36Sopenharmony_ci    timeline data source: FTRACE (all trace events found)
56262306a36Sopenharmony_ci    is rtcwake supported: YES
56362306a36Sopenharmony_ci    verifying timeline kprobes work:
56462306a36Sopenharmony_ci         _cpu_down: YES
56562306a36Sopenharmony_ci         _cpu_up: YES
56662306a36Sopenharmony_ci         acpi_pm_finish: YES
56762306a36Sopenharmony_ci         acpi_pm_prepare: YES
56862306a36Sopenharmony_ci         freeze_kernel_threads: YES
56962306a36Sopenharmony_ci         freeze_processes: YES
57062306a36Sopenharmony_ci         sys_sync: YES
57162306a36Sopenharmony_ci         thaw_processes: YES
57262306a36Sopenharmony_ci    verifying dev kprobes work:
57362306a36Sopenharmony_ci         __const_udelay: YES
57462306a36Sopenharmony_ci         __mutex_lock_slowpath: YES
57562306a36Sopenharmony_ci         acpi_os_stall: YES
57662306a36Sopenharmony_ci         acpi_ps_parse_aml: YES
57762306a36Sopenharmony_ci         intel_opregion_init: NO
57862306a36Sopenharmony_ci         intel_opregion_register: NO
57962306a36Sopenharmony_ci         intel_opregion_setup: NO
58062306a36Sopenharmony_ci         msleep: YES
58162306a36Sopenharmony_ci         schedule_timeout: YES
58262306a36Sopenharmony_ci         schedule_timeout_uninterruptible: YES
58362306a36Sopenharmony_ci         usleep_range: YES
58462306a36Sopenharmony_ci
58562306a36Sopenharmony_ci
58662306a36Sopenharmony_ci------------------------------------------------------------------
58762306a36Sopenharmony_ci|           TESTING ON CONSUMER LINUX OPERATING SYSTEMS          |
58862306a36Sopenharmony_ci------------------------------------------------------------------
58962306a36Sopenharmony_ci
59062306a36Sopenharmony_ciAndroid
59162306a36Sopenharmony_ci_______
59262306a36Sopenharmony_ci
59362306a36Sopenharmony_ci The easiest way to execute on an android device is to run the android.sh
59462306a36Sopenharmony_ci script on the device, then pull the ftrace log back to the host and run
59562306a36Sopenharmony_ci sleepgraph.py on it.
59662306a36Sopenharmony_ci
59762306a36Sopenharmony_ci Here are the steps:
59862306a36Sopenharmony_ci
59962306a36Sopenharmony_ci [download and install the tool on the device]
60062306a36Sopenharmony_ci
60162306a36Sopenharmony_ci	host%> wget https://raw.githubusercontent.com/intel/pm-graph/master/tools/android.sh
60262306a36Sopenharmony_ci	host%> adb connect 192.168.1.6
60362306a36Sopenharmony_ci	host%> adb root
60462306a36Sopenharmony_ci	# push the script to a writeable location
60562306a36Sopenharmony_ci	host%> adb push android.sh /sdcard/
60662306a36Sopenharmony_ci
60762306a36Sopenharmony_ci [check whether the tool will run on your device]
60862306a36Sopenharmony_ci
60962306a36Sopenharmony_ci	host%> adb shell
61062306a36Sopenharmony_ci	dev%> cd /sdcard
61162306a36Sopenharmony_ci	dev%> sh android.sh status
61262306a36Sopenharmony_ci		host    : asus_t100
61362306a36Sopenharmony_ci		kernel  : 3.14.0-i386-dirty
61462306a36Sopenharmony_ci		modes   : freeze mem
61562306a36Sopenharmony_ci		rtcwake : supported
61662306a36Sopenharmony_ci		ftrace  : supported
61762306a36Sopenharmony_ci		trace events {
61862306a36Sopenharmony_ci		    suspend_resume: found
61962306a36Sopenharmony_ci		    device_pm_callback_end: found
62062306a36Sopenharmony_ci		    device_pm_callback_start: found
62162306a36Sopenharmony_ci		}
62262306a36Sopenharmony_ci	# the above is what you see on a system that's properly patched
62362306a36Sopenharmony_ci
62462306a36Sopenharmony_ci [execute the suspend]
62562306a36Sopenharmony_ci
62662306a36Sopenharmony_ci	# NOTE: The suspend will only work if the screen isn't timed out,
62762306a36Sopenharmony_ci	# so you have to press some keys first to wake it up b4 suspend)
62862306a36Sopenharmony_ci	dev%> sh android.sh suspend mem
62962306a36Sopenharmony_ci	------------------------------------
63062306a36Sopenharmony_ci	Suspend/Resume timing test initiated
63162306a36Sopenharmony_ci	------------------------------------
63262306a36Sopenharmony_ci	hostname   : asus_t100
63362306a36Sopenharmony_ci	kernel     : 3.14.0-i386-dirty
63462306a36Sopenharmony_ci	mode       : mem
63562306a36Sopenharmony_ci	ftrace out : /mnt/shell/emulated/0/ftrace.txt
63662306a36Sopenharmony_ci	dmesg out  : /mnt/shell/emulated/0/dmesg.txt
63762306a36Sopenharmony_ci	log file   : /mnt/shell/emulated/0/log.txt
63862306a36Sopenharmony_ci	------------------------------------
63962306a36Sopenharmony_ci	INITIALIZING FTRACE........DONE
64062306a36Sopenharmony_ci	STARTING FTRACE
64162306a36Sopenharmony_ci	SUSPEND START @ 21:24:02 (rtcwake in 10 seconds)
64262306a36Sopenharmony_ci	<adb connection will now terminate>
64362306a36Sopenharmony_ci
64462306a36Sopenharmony_ci [retrieve the data from the device]
64562306a36Sopenharmony_ci
64662306a36Sopenharmony_ci	# I find that you have to actually kill the adb process and
64762306a36Sopenharmony_ci	# reconnect sometimes in order for the connection to work post-suspend
64862306a36Sopenharmony_ci	host%> adb connect 192.168.1.6
64962306a36Sopenharmony_ci	# (required) get the ftrace data, this is the most important piece
65062306a36Sopenharmony_ci	host%> adb pull /sdcard/ftrace.txt
65162306a36Sopenharmony_ci	# (optional) get the dmesg data, this is for debugging
65262306a36Sopenharmony_ci	host%> adb pull /sdcard/dmesg.txt
65362306a36Sopenharmony_ci	# (optional) get the log, which just lists some test times for comparison
65462306a36Sopenharmony_ci	host%> adb pull /sdcard/log.txt
65562306a36Sopenharmony_ci
65662306a36Sopenharmony_ci [create an output html file using sleepgraph.py]
65762306a36Sopenharmony_ci
65862306a36Sopenharmony_ci	host%> sleepgraph.py -ftrace ftrace.txt
65962306a36Sopenharmony_ci
66062306a36Sopenharmony_ci You should now have an output.html with the android data, enjoy!
661