目录
目录
源代码目录
├── calibrate (测试之前的校准)
│ ├── calibrate.cpp
│ └── calibrate.h
├── cpu (CPU 、内存接口)
│ ├── abstract_cpu.cpp
│ ├── cpu_core.cpp
│ ├── cpu.cpp
│ ├── cpudevice.cpp
│ ├── cpudevice.h
│ ├── cpu.h
│ ├── cpu_linux.cpp
│ ├── cpu_package.cpp
│ ├── cpu_rapl_device.cpp
│ ├── cpu_rapl_device.h
│ ├── dram_rapl_device.cpp
│ ├── dram_rapl_device.h
│ ├── intel_cpus.cpp
│ ├── intel_cpus.h
│ ├── intel_gpu.cpp
│ └── rapl
│ ├── rapl_interface.cpp
│ └── rapl_interface.h
├── csstoh.sh
├── devices (SCSI、音频、背光、设备频率控制、intel GPU、网卡、wifi蓝牙、usb、
| | thinkpad风扇、设备runtime控制)
│ ├── ahci.cpp
│ ├── ahci.h
│ ├── alsa.cpp
│ ├── alsa.h
│ ├── backlight.cpp
│ ├── backlight.h
│ ├── devfreq.cpp
│ ├── devfreq.h
│ ├── device.cpp
│ ├── device.h
│ ├── gpu_rapl_device.cpp
│ ├── gpu_rapl_device.h
│ ├── i915-gpu.cpp
│ ├── i915-gpu.h
│ ├── network.cpp
│ ├── network.h
│ ├── rfkill.cpp
│ ├── rfkill.h
│ ├── runtime_pm.cpp
│ ├── runtime_pm.h
│ ├── thinkpad-fan.cpp
│ ├── thinkpad-fan.h
│ ├── thinkpad-light.cpp
│ ├── thinkpad-light.h
│ ├── usb.cpp
│ └── usb.h
├── devlist.cpp
├── devlist.h
├── display.cpp
├── display.h
├── lib.cpp
├── lib.h
├── main.cpp
├── Makefile
├── Makefile.am
├── Makefile.in
├── measurement
│ ├── acpi.cpp
│ ├── acpi.h
│ ├── extech.cpp
│ ├── extech.h
│ ├── measurement.cpp
│ ├── measurement.h
│ ├── opal-sensors.cpp
│ ├── opal-sensors.h
│ ├── sysfs.cpp
│ └── sysfs.h
├── parameters (这里还具有学习优化的机制?)
│ ├── learn.cpp
│ ├── parameters.cpp
│ ├── parameters.h
│ └── persistent.cpp
├── perf (采用linux内核event跟踪机制监控,主要关注哪些事件用来衡量哪些事情)
│ ├── perf_bundle.cpp
│ ├── perf_bundle.h
│ ├── perf.cpp
│ ├── perf_event.h
│ └── perf.h
├── powertop.css
├── process (进程、中断的占用CPU时间)
│ ├── do_process.cpp
│ ├── interrupt.cpp
│ ├── interrupt.h
│ ├── powerconsumer.cpp
│ ├── powerconsumer.h
│ ├── process.cpp
│ ├── processdevice.cpp
│ ├── processdevice.h
│ ├── process.h
│ ├── timer.cpp
│ ├── timer.h
│ ├── work.cpp
│ └── work.h
├── report
│ ├── report.cpp
│ ├── report-data-html.cpp
│ ├── report-data-html.h
│ ├── report-formatter-base.cpp
│ ├── report-formatter-base.h
│ ├── report-formatter-csv.cpp
│ ├── report-formatter-csv.h
│ ├── report-formatter.h
│ ├── report-formatter-html.cpp
│ ├── report-formatter-html.h
│ ├── report.h
│ ├── report-maker.cpp
│ └── report-maker.h
├── tuning (调整电源管理的接口汇总)
│ ├── bluetooth.cpp
│ ├── bluetooth.h
│ ├── ethernet.cpp
│ ├── ethernet.h
│ ├── iw.c
│ ├── iw.h
│ ├── nl80211.h
│ ├── runtime.cpp
│ ├── runtime.h
│ ├── tunable.cpp
│ ├── tunable.h
│ ├── tuning.cpp
│ ├── tuning.h
│ ├── tuningi2c.cpp
│ ├── tuningi2c.h
│ ├── tuningsysfs.cpp
│ ├── tuningsysfs.h
│ ├── tuningusb.cpp
│ ├── tuningusb.h
│ ├── wifi.cpp
│ └── wifi.h
└── wakeup
├── waketab.cpp
├── wakeup.cpp
├── wakeup_ethernet.cpp
├── wakeup_ethernet.h
├── wakeup.h
├── wakeup_usb.cpp
└── wakeup_usb.h
名字解释
Since Intel Sandy Bridge CPUs, the Intel Running Average Power Limit (RAPL) interface allows monitoring and controlling the power consumption of the CPU and DRAM in software. Hence, the CPU basically comes with its own power meter. With the current implementation of the Linux driver, every unprivileged user has access to its measurements.
main.cpp
main->powertop_init
1) mount -t debugfs debugfs /sys/kernel/debug 挂载debugfs
2) 在 /data/local/powertop 或者 /var/cache/powertop 创建调配参数保存
CPU 电源管理
3) enumerate_cpus 函数解析 "/proc/cpuinfo" 中cpu信息,包括 厂家、型号、model等
同时针对/sys/class/drm/card0/power/rc6_residency_ms 的存在情况,进行handle_i965_gpu GPU 的处理。
perf_events 对象,主要作用是什么?
RAPL接口
msr接口获取及设置CPU 内存的功耗配置
/dev/cpu/0/msr
/sys/class/powercap/intel-rapl/
虽然 接口 set_dram_power_limit 实现了,但实际没有使用。
这一块儿还要记录研究!!!
CPU Freq
为了节省CPU的功耗和减少发热,根据当前CPU的负载状态,动态地提供刚好足够的主频给CPU,即在系统正常运行时的节能策略。;有一点需要关注的,这个根据负载调频,并不是tlp或者powertop这种工具做的,而是在内核实现的。内核仅仅通过governor对外面暴露策略。
sys系统接口
/sys/devices/system/cpu/cpu6/cpufreq
字段 | 取值 | 含义 |
affected_cpus | ||
cpuinfo_min_freq | ||
energy_performance_available_preferences | ||
related_cpus | ||
scaling_cur_freq | ||
scaling_governor | powersave | |
scaling_min_freq | ||
cpuinfo_max_freq | ||
cpuinfo_transition_latency | ||
energy_performance_preference | ||
scaling_available_governors s | performance powersave |
scaling_driver | intel_pstate |
trace事件
power:power_frequency 事件涉及到的内核代码为:
/x86-kernel/drivers/cpufreq/cpufreq.c :cpufreq_notify_transition - Notify frequency transition and adjust_jiffies
/x86-kernel/drivers/cpufreq/intel_pstate.c
x86-kernel/kernel/sched/cpufreq_schedutil.c :CPUFreq governor based on scheduler-provided CPU utilization data
if (!perf_events->add_event("power:cpu_frequency"))
perf_events->add_event("power:power_frequency")
governor
调度
CPU idle
为在空闲时,CPU依次关闭某些逻辑期间的程序。
sys文件系统接口
/sys/devices/system/cpu/cpu0/cpuidle/state0
字段 | 取值 | 含义 |
---|---|---|
desc | ||
disable | 0 | 启用此状态 |
latency | ||
name | POLL | intel cpu状态的名字 |
power | ||
residency | ||
time | ||
usage |
对这些字段的使用是在 /powertop-2.14/src/cpu/cpu_linux.cpp 中,主要使用 time usage 和name 字段,即统计各个cpu 状态的百分比。
trace 事件
power:cpu_idle
!perf_events->add_event("power:cpu_idle")){
perf_events->add_event("power:power_start");
perf_events->add_event("power:power_end");
}
这个事件在内核里面没有搜到???
外设电源管理
4) create_all_devices 依次调用如下接口,对各种外设的电源管理进行检测:
create_all_backlights(); :对此目录下的文件进行处理 "/sys/class/backlight/
create_all_usb_devices(); :对此目录下的文件进行处理 "("/sys/bus/usb/devices/"
create_all_ahcis(); : /sys/class/scsi_host/"
create_all_alsa(); : "/sys/class/sound/"
create_all_rfkills(); /sys/class/rfkill/" "/sys/class/rfkill/%s/name
create_i915_gpu(); /sys/kernel/debug/tracing/events/i915/i915_gem_ring_dispatch/format (跟踪GPU的事务,已衡量GPU的功耗??)
create_thinkpad_fan(); :/sys/devices/platform/thinkpad_hwmon/fan1_input 特定品牌风扇信息的处理?
create_thinkpad_light(); :/sys/devices/platform/thinkpad_acpi/leds/tpacpi::thinklight/brightness
create_all_nics(); :"/sys/class/net/
create_all_runtime_pm_devices(); 又包含支持 runtime的各种总线设备:
do_bus("pci"); /sys/bus/pci/devices/0000\:00\:1f.0/power/runtime_suspended_time 某个设备
do_bus("spi");
do_bus("platform");
do_bus("i2c");
}