pm-graph使用记录

本文介绍了如何使用pm-graph工具在内核中抓取休眠唤醒时的函数调用过程,包括安装步骤、内核配置需求以及压力测试的应用。通过示例展示了如何分析和理解设备在不同阶段的电源管理行为。

工具在内核源代码的tools/power/pm-graph目录下,在github上有pm-graph 的项目。

 

目录

1.安装

2. 应用

抓取休眠唤醒时的函数调用过程

压力测试


 


1.安装

其实不用安装也可以直接用

$> git clone http://github.com/intel/pm-graph.git
    $> cd pm-graph
    $> sudo make install
    

2. 应用

自带了config配置文件,设定各种参数。此处不采用配置文件,直接用参数。

需要内核配置项目

 CONFIG_DEVMEM=y
        CONFIG_PM_DEBUG=y
        CONFIG_PM_SLEEP_DEBUG=y
        CONFIG_FTRACE=y
        CONFIG_FUNCTION_TRACER=y
        CONFIG_FUNCTION_GRAPH_TRACER=y
        CONFIG_KPROBES=y
        CONFIG_KPROBES_ON_FTRACE=y

抓取休眠唤醒时的函数调用过程

 

运行 sleepgraph -m mem(或者disk ,mem表示测试suspend to mem过程;disk表示suspend to disk 过程)  -f (表示抓取函数调用过程)

抓取的效果为:

可以很清楚的看出休眠唤醒的几个阶段,对于sleep to disk阶段,由于在suspend前,进程已经被freeze,因而实际不能抓取thaw阶段的内容。如果真的在suspend前被freeze,那么这个软件抓取的事件的进程是如何保证运行的呢

提出上面这个问题本身,说明你对内核的ftrace不清楚,在配置了trace后,内核会将需要trace的信息写入到某个buf中,不是说启用哪个用户进程、线程进行处理。

以intel i915为例子,在各个阶段的功能

pre阶段更多是驱动软件层面清理。官方文档描述如下:

The ``prepare`` phase is meant to prevent races by preventing new
    devices from being registered; the PM core would never know that all the
    children of a device had been suspended if new children could be
    registered at will.  [By contrast, from the PM core's perspective,
    devices may be unregistered at any time.]  Unlike the other
    suspend-related phases, during the ``prepare`` phase the device
    hierarchy is traversed top-down. 主要阻止新的设备被添加到系统中,以免后续suspend开始时,还有设备添加,导致新添加的设备不能被处理。

在suspend阶段,可以看到保存设备的pci的状态及设备本身的状态,display的关闭等。

The ``->suspend`` methods should quiesce the device to stop it from
    performing I/O.  They also may save the device registers and put it into
    the appropriate low-power state
,
depending on the bus type the device is
    on, and they may enable wakeup events. 在此处i915阶段仅仅是保持了寄存器的信息,并没有操作设备电源状态。

在suspend late阶段 就将设备电源状态设置为低功耗,不能直接关闭设备吧

 

 3.    For a number of devices it is convenient to split suspend into the
    "quiesce device" and "save device state" phases, in which cases
    ``suspend_late`` is meant to do the latter.  It is always executed after
    runtime power management has been disabled for the device in question.

    4.    The ``suspend_noirq`` phase occurs after IRQ handlers have been disabled,
    which means that the driver's interrupt handler will not be called while
    the callback method is running.  The ``->suspend_noirq`` methods should
    save the values of the device's registers that weren't saved previously
    and finally put the device into the appropriate low-power state.

从描述和实际trace看,各个驱动 在实现上存在差异。

压力测试

https://01.org/pm-graph/endurance-testing

multi参数 50次,每次间隔多少秒

 sudo ./sleepgraph.py -m mem -rtcwake 10 -dev -gzip -multi 50 0 -skiphtml

suspend-210620-111433-x10$ ../sleepgraph.py -summary . -genhtml -dev
进入生成的目录suspend-210620-111433-x10,运行命令,生成summary报告

pm-graph这个项目的主要意义在于,启发了针对内核某个特定模块进行全过程跟踪的应用程序开发

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

proware

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值