├── autogen.sh ├── po ├── .tx │ └── config ├── LINGUAS ├── ChangeLog ├── POTFILES.in └── Makevars ├── doc ├── Makefile.am └── powertop.8 ├── PowerTop.png ├── scripts ├── bash-completion │ ├── Makefile.am │ └── powertop └── regenerate-potfiles-in ├── powertop.service ├── Makefile.am ├── m4 └── ChangeLog ├── src ├── devlist.h ├── calibrate │ └── calibrate.h ├── tuning │ ├── tuning.h │ ├── tuningi2c.h │ ├── bluetooth.h │ ├── wifi.h │ ├── ethernet.h │ ├── tuningusb.h │ ├── runtime.h │ ├── tunable.cpp │ ├── tuningsysfs.h │ ├── iw.h │ ├── tunable.h │ ├── wifi.cpp │ ├── tuningsysfs.cpp │ ├── tuningi2c.cpp │ └── ethernet.cpp ├── measurement │ ├── opal-sensors.h │ ├── opal-sensors.cpp │ ├── acpi.h │ ├── extech.h │ ├── sysfs.h │ ├── measurement.h │ └── sysfs.cpp ├── csstoh.sh ├── report │ ├── report.h │ ├── report-formatter-base.h │ ├── report-data-html.h │ ├── report-formatter.h │ ├── report-formatter-html.h │ ├── report-formatter-csv.h │ ├── report-formatter-base.cpp │ ├── report-data-html.cpp │ ├── report-maker.h │ └── report-formatter-csv.cpp ├── wakeup │ ├── wakeup_usb.h │ ├── wakeup_ethernet.h │ ├── wakeup.cpp │ ├── wakeup.h │ ├── wakeup_usb.cpp │ └── wakeup_ethernet.cpp ├── perf │ ├── perf_bundle.h │ └── perf.h ├── process │ ├── work.h │ ├── processdevice.h │ ├── timer.h │ ├── interrupt.h │ ├── powerconsumer.h │ ├── process.h │ ├── powerconsumer.cpp │ ├── processdevice.cpp │ ├── work.cpp │ ├── interrupt.cpp │ └── timer.cpp ├── devices │ ├── i915-gpu.h │ ├── gpu_rapl_device.h │ ├── backlight.h │ ├── thinkpad-light.h │ ├── thinkpad-fan.h │ ├── rfkill.h │ ├── gpu_rapl_device.cpp │ ├── alsa.h │ ├── runtime_pm.h │ ├── usb.h │ ├── ahci.h │ ├── device.h │ ├── devfreq.h │ ├── network.h │ ├── thinkpad-light.cpp │ ├── i915-gpu.cpp │ └── thinkpad-fan.cpp ├── cpu │ ├── dram_rapl_device.h │ ├── cpu_rapl_device.h │ ├── cpudevice.h │ ├── cpu_rapl_device.cpp │ ├── dram_rapl_device.cpp │ ├── cpudevice.cpp │ ├── cpu_core.cpp │ ├── rapl │ │ └── rapl_interface.h │ ├── cpu_package.cpp │ └── intel_gpu.cpp ├── display.h └── lib.h ├── TODO ├── .gitignore └── patches ├── linux-3.3.0-vfs-dirty-inode.patch └── linux-2.6.37-vfs-dirty-inode.patch /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | autoreconf --install --verbose 4 | -------------------------------------------------------------------------------- /po/.tx/config: -------------------------------------------------------------------------------- 1 | [main] 2 | host = https://www.transifex.com 3 | 4 | -------------------------------------------------------------------------------- /doc/Makefile.am: -------------------------------------------------------------------------------- 1 | man_MANS = powertop.8 2 | EXTRA_DIST = powertop.8 3 | -------------------------------------------------------------------------------- /PowerTop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fenrus75/powertop/HEAD/PowerTop.png -------------------------------------------------------------------------------- /scripts/bash-completion/Makefile.am: -------------------------------------------------------------------------------- 1 | bashcompletiondir = @bashcompletiondir@ 2 | dist_bashcompletion_DATA = powertop 3 | -------------------------------------------------------------------------------- /po/LINGUAS: -------------------------------------------------------------------------------- 1 | # set of available languages 2 | ca 3 | cs_CZ 4 | de_DE 5 | en_GB 6 | en_US 7 | es_ES 8 | hu_HU 9 | id_ID 10 | nl_NL 11 | zh_TW 12 | -------------------------------------------------------------------------------- /powertop.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Extend the battery life of laptop 3 | 4 | [Service] 5 | Type=oneshot 6 | ExecStart=/usr/sbin/powertop --auto-tune 7 | 8 | [Install] 9 | WantedBy=multi-user.target sleep.target 10 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | AUTOMAKE_OPTIONS = subdir-objects 2 | ACLOCAL_AMFLAGS = --install -I m4 3 | 4 | SUBDIRS = \ 5 | src \ 6 | po \ 7 | doc \ 8 | scripts/bash-completion 9 | 10 | EXTRA_DIST = \ 11 | config.rpath \ 12 | m4/ChangeLog \ 13 | README \ 14 | TODO \ 15 | COPYING \ 16 | autogen.sh 17 | -------------------------------------------------------------------------------- /m4/ChangeLog: -------------------------------------------------------------------------------- 1 | 2016-08-03 gettextize 2 | 3 | * gettext.m4: New file, from gettext-0.18.2. 4 | * iconv.m4: New file, from gettext-0.18.2. 5 | * lib-ld.m4: New file, from gettext-0.18.2. 6 | * lib-link.m4: New file, from gettext-0.18.2. 7 | * lib-prefix.m4: New file, from gettext-0.18.2. 8 | * nls.m4: New file, from gettext-0.18.2. 9 | * po.m4: New file, from gettext-0.18.2. 10 | * progtest.m4: New file, from gettext-0.18.2. 11 | 12 | -------------------------------------------------------------------------------- /po/ChangeLog: -------------------------------------------------------------------------------- 1 | 2016-08-03 gettextize 2 | 3 | * Makefile.in.in: Upgrade to gettext-0.18.2. 4 | * boldquot.sed: New file, from gettext-0.18.2. 5 | * en@boldquot.header: New file, from gettext-0.18.2. 6 | * en@quot.header: New file, from gettext-0.18.2. 7 | * insert-header.sin: New file, from gettext-0.18.2. 8 | * quot.sed: New file, from gettext-0.18.2. 9 | * remove-potcdate.sin: New file, from gettext-0.18.2. 10 | * Rules-quot: New file, from gettext-0.18.2. 11 | 12 | -------------------------------------------------------------------------------- /scripts/regenerate-potfiles-in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo "INFO: checking for git ..." 4 | git --version > /dev/null 2>&1 || exit 1 5 | 6 | echo "INFO: priming ./POTFILES.in.new ..." 7 | touch POTFILES.in.new || exit 2 8 | echo "# List of source files which contain translatable strings." > POTFILES.in.new || exit 3 9 | echo "" >> POTFILES.in.new || exit 4 10 | 11 | echo "INFO: populating ./POTFILES.in.new ..." 12 | git grep -l -e "__(" -e "_(" | sort >> POTFILES.in.new || exit 5 13 | 14 | echo "INFO: contents of ./POTFILES.in.new ..." 15 | cat POTFILES.in.new 16 | -------------------------------------------------------------------------------- /src/devlist.h: -------------------------------------------------------------------------------- 1 | #ifndef __INCLUDE_GUARD_DEVLIST_H__ 2 | #define __INCLUDE_GUARD_DEVLIST_H__ 3 | 4 | struct devuser { 5 | unsigned int pid; 6 | char comm[32]; 7 | char device[252]; 8 | }; 9 | 10 | class device; 11 | 12 | struct devpower { 13 | char device[252]; 14 | double power; 15 | class device *dev; 16 | }; 17 | 18 | extern void clean_open_devices(); 19 | extern void collect_open_devices(void); 20 | 21 | extern void clear_devpower(void); 22 | extern void register_devpower(const char *devstring, double power, class device *dev); 23 | extern void run_devpower_list(void); 24 | 25 | extern void report_show_open_devices(void); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | Needed for 2.2 2 | ---------------------------------- 3 | 4 | * more translations / strings 5 | * more end user documentation 6 | * audio calibration? Need appropriate sample 7 | * reporting for workload mode 8 | * Add GPU stats to reports [csv,html] 9 | 10 | 11 | Nice to Have 12 | ---------------------------------- 13 | NCURSES STUB (anyone who may care to do this) 14 | PowerTOP is intended to be run with ncurses. As such if there is any 15 | distribution that can't or won't support ncurses, they need to supply 16 | a separate stub to handle there issues. 17 | 18 | DONE for 2.2 19 | ---------------------------------- 20 | * interactive mode scrolling 21 | * In tunables suggest writing min_power to all SATA ports 22 | -------------------------------------------------------------------------------- /src/calibrate/calibrate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #ifndef __INCLUDE_GUARD_CALIBRATE_H 26 | #define __INCLUDE_GUARD_CALIBRATE_H 27 | 28 | extern void one_measurement(int seconds, int sample_interval, char *workload); 29 | extern void calibrate(void); 30 | 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /po/POTFILES.in: -------------------------------------------------------------------------------- 1 | # List of source files which contain translatable strings. 2 | 3 | src/calibrate/calibrate.cpp 4 | src/cpu/abstract_cpu.cpp 5 | src/cpu/cpu_core.cpp 6 | src/cpu/cpu.cpp 7 | src/cpu/cpu_linux.cpp 8 | src/cpu/cpu_package.cpp 9 | src/cpu/intel_cpus.cpp 10 | src/cpu/intel_gpu.cpp 11 | src/devices/ahci.cpp 12 | src/devices/alsa.cpp 13 | src/devices/devfreq.cpp 14 | src/devices/device.cpp 15 | src/devices/network.cpp 16 | src/devices/rfkill.cpp 17 | src/devices/runtime_pm.cpp 18 | src/devices/usb.cpp 19 | src/devlist.cpp 20 | src/display.cpp 21 | src/lib.cpp 22 | src/lib.h 23 | src/main.cpp 24 | src/parameters/persistent.cpp 25 | src/perf/perf_bundle.cpp 26 | src/perf/perf.cpp 27 | src/process/do_process.cpp 28 | src/report/report.cpp 29 | src/report/report-maker.h 30 | src/tuning/bluetooth.cpp 31 | src/tuning/ethernet.cpp 32 | src/tuning/nl80211.h 33 | src/tuning/runtime.cpp 34 | src/tuning/tunable.cpp 35 | src/tuning/tuning.cpp 36 | src/tuning/tuningi2c.cpp 37 | src/tuning/tuningsysfs.cpp 38 | src/tuning/tuningusb.cpp 39 | src/tuning/wifi.cpp 40 | src/wakeup/waketab.cpp 41 | src/wakeup/wakeup.cpp 42 | src/wakeup/wakeup_ethernet.cpp 43 | src/wakeup/wakeup_usb.cpp 44 | traceevent/event-parse.h 45 | traceevent/parse-utils.c 46 | -------------------------------------------------------------------------------- /src/tuning/tuning.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #ifndef _INCLUDE_GUARD_TUNING_H 26 | #define _INCLUDE_GUARD_TUNING_H 27 | 28 | extern void initialize_tuning(void); 29 | extern void tuning_update_display(void); 30 | extern void report_show_tunables(void); 31 | extern void clear_tuning(void); 32 | extern void auto_toggle_tuning(bool dump_only); 33 | #endif 34 | -------------------------------------------------------------------------------- /src/tuning/tuningi2c.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * Authors: 16 | * Arjan van de Ven 17 | * Daniel Leung 18 | */ 19 | 20 | #ifndef _INCLUDE_GUARD_I2C_TUNE_H 21 | #define _INCLUDE_GUARD_I2C_TUNE_H 22 | 23 | #include 24 | #include 25 | 26 | #include "tunable.h" 27 | 28 | using namespace std; 29 | 30 | class i2c_tunable : public tunable { 31 | char i2c_path[PATH_MAX]; 32 | public: 33 | i2c_tunable(const char *path, const char *name, bool is_adapter); 34 | 35 | virtual int good_bad(void); 36 | 37 | virtual void toggle(void); 38 | 39 | virtual const char *toggle_script(void); 40 | 41 | }; 42 | 43 | extern void add_i2c_tunables(void); 44 | 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /scripts/bash-completion/powertop: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Powertop tab completion for bash. 4 | # 5 | # This is part of PowerTOP 6 | # 7 | # This program file is free software; you can redistribute it and/or modify it 8 | # under the terms of the GNU General Public License as published by the 9 | # Free Software Foundation; version 2 of the License. 10 | # 11 | # This program is distributed in the hope that it will be useful, but WITHOUT 12 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | # for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program in a file named COPYING; if not, write to the 18 | # Free Software Foundation, Inc, 19 | # 51 Franklin Street, Fifth Floor, 20 | # Boston, MA 02110-1301 USA 21 | # or just google for it. 22 | 23 | _powertop() 24 | { 25 | local cur prev words cword split 26 | _init_completion -s || return 27 | 28 | case $prev in 29 | '-C'|'--csv'|'--extech'|'-r'|'--html'|'-w'|'--workload') 30 | _filedir 31 | return 0 32 | ;; 33 | esac 34 | 35 | local all_long_options=$( _parse_help "$1" ) 36 | 37 | COMPREPLY=( $( compgen -W "${all_long_options}" -- "$cur" ) ) 38 | 39 | return 0 40 | } 41 | 42 | # load the completion 43 | complete -F _powertop powertop 44 | -------------------------------------------------------------------------------- /src/tuning/bluetooth.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #ifndef _INCLUDE_GUARD_BLUETOOTH_TUNE_H 26 | #define _INCLUDE_GUARD_BLUETOOTH_TUNE_H 27 | 28 | #include 29 | 30 | #include "tunable.h" 31 | 32 | using namespace std; 33 | 34 | class bt_tunable : public tunable { 35 | public: 36 | bt_tunable(void); 37 | 38 | virtual int good_bad(void); 39 | 40 | virtual void toggle(void); 41 | 42 | virtual const char *toggle_script(void); 43 | 44 | }; 45 | 46 | extern void add_bt_tunable(void); 47 | 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /src/tuning/wifi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #ifndef _INCLUDE_GUARD_WIFI_TUNE_H 26 | #define _INCLUDE_GUARD_WIFI_TUNE_H 27 | 28 | #include 29 | 30 | #include "tunable.h" 31 | 32 | using namespace std; 33 | 34 | class wifi_tunable : public tunable { 35 | char iface[4096]; 36 | public: 37 | wifi_tunable(const char *_iface); 38 | 39 | virtual int good_bad(void); 40 | 41 | virtual void toggle(void); 42 | 43 | virtual const char *toggle_script(void); 44 | 45 | }; 46 | 47 | extern void add_wifi_tunables(void); 48 | 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/measurement/opal-sensors.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 IBM Corp. 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Stewart Smith 24 | */ 25 | #ifndef INCLUDE_GUARD_OPAL_SENSORS_H 26 | #define INCLUDE_GUARD_OPAL_SENSORS_H 27 | 28 | #include "measurement.h" 29 | #include 30 | 31 | class opal_sensors_power_meter: public power_meter { 32 | char name[PATH_MAX]; 33 | public: 34 | opal_sensors_power_meter(const char *power_supply_name); 35 | virtual void start_measurement(void) {}; 36 | virtual void end_measurement(void) {}; 37 | 38 | virtual double power(void); 39 | virtual double dev_capacity(void) { return 0.0; } 40 | }; 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /src/tuning/ethernet.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #ifndef _INCLUDE_GUARD_ETHERNET_TUNE_H 26 | #define _INCLUDE_GUARD_ETHERNET_TUNE_H 27 | 28 | #include 29 | 30 | #include "tunable.h" 31 | 32 | using namespace std; 33 | 34 | class ethernet_tunable : public tunable { 35 | public: 36 | char interf[4096]; 37 | ethernet_tunable(const char *iface); 38 | 39 | virtual int good_bad(void); 40 | 41 | virtual void toggle(void); 42 | 43 | virtual const char *toggle_script(void); 44 | 45 | }; 46 | 47 | extern void add_ethernet_tunable(void); 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /src/csstoh.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This program file is free software; you can redistribute it and/or modify it 4 | # under the terms of the GNU General Public License as published by the 5 | # Free Software Foundation; version 2 of the License. 6 | # 7 | # This program is distributed in the hope that it will be useful, but WITHOUT 8 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 9 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 10 | # for more details. 11 | # 12 | # You should have received a copy of the GNU General Public License 13 | # along with this program in a file named COPYING; if not, write to the 14 | # Free Software Foundation, Inc, 15 | # 51 Franklin Street, Fifth Floor, 16 | # Boston, MA 02110-1301 USA 17 | # or just google for it. 18 | # 19 | # Written by Igor Zhbanov 20 | 21 | if [ $# -ne 2 ]; then 22 | echo "Usage: csstoh.sh cssfile header.h" >&2 23 | exit 1 24 | fi 25 | if [ ! -f "$1" ]; then 26 | echo "$1: no such file or directory" >&2 27 | exit 1 28 | fi 29 | # redirect stdout to a file 30 | exec 1> "$2" || exit $? 31 | 32 | # header 33 | cat <&- 49 | # return status of output file write 50 | exit $? 51 | -------------------------------------------------------------------------------- /src/measurement/opal-sensors.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 IBM Corp. 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Stewart Smith 24 | */ 25 | #include "measurement.h" 26 | #include "opal-sensors.h" 27 | #include "../lib.h" 28 | #include 29 | #include 30 | #include 31 | 32 | opal_sensors_power_meter::opal_sensors_power_meter(const char *power_supply_name) 33 | { 34 | strncpy(name, power_supply_name, sizeof(name)); 35 | } 36 | 37 | double opal_sensors_power_meter::power(void) 38 | { 39 | bool ok; 40 | int value; 41 | double r = 0; 42 | 43 | value = read_sysfs(name, &ok); 44 | 45 | if(ok) 46 | r = value / 1000000.0; 47 | return r; 48 | } 49 | -------------------------------------------------------------------------------- /src/tuning/tuningusb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #ifndef _INCLUDE_GUARD_USB_TUNE_H 26 | #define _INCLUDE_GUARD_USB_TUNE_H 27 | 28 | #include 29 | #include 30 | 31 | #include "tunable.h" 32 | 33 | using namespace std; 34 | 35 | class usb_tunable : public tunable { 36 | char usb_path[PATH_MAX]; 37 | public: 38 | usb_tunable(const char *usb_path, const char *path); 39 | 40 | virtual int good_bad(void); 41 | 42 | virtual void toggle(void); 43 | 44 | virtual const char *toggle_script(void); 45 | 46 | }; 47 | 48 | extern void add_usb_tunables(void); 49 | 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /src/measurement/acpi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #ifndef __INCLUDE_GUARD_ACPI_H 26 | #define __INCLUDE_GUARD_ACPI_H 27 | 28 | #include "measurement.h" 29 | 30 | class acpi_power_meter: public power_meter { 31 | char battery_name[256]; 32 | 33 | double capacity; 34 | double rate; 35 | double voltage; 36 | void measure(void); 37 | public: 38 | acpi_power_meter(const char *_battery_name); 39 | virtual void start_measurement(void); 40 | virtual void end_measurement(void); 41 | 42 | virtual double power(void); 43 | virtual double dev_capacity(void) { return capacity; }; 44 | }; 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /src/report/report.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #ifndef __INCLUDE_GUARD_REPORT_H_ 26 | #define __INCLUDE_GUARD_REPORT_H_ 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #include "report-maker.h" 33 | 34 | using namespace std; 35 | 36 | struct reportstream { 37 | FILE *report_file; 38 | char filename[PATH_MAX]; 39 | }; 40 | 41 | extern report_type reporttype; 42 | extern report_maker report; 43 | extern struct reportstream reportout; 44 | extern void init_report_output(char *filename_str, int iterations); 45 | extern void finish_report_output(void); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /src/wakeup/wakeup_usb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Gayatri Kammela 24 | */ 25 | #ifndef _INCLUDE_GUARD_USB_WAKEUP_H 26 | #define _INCLUDE_GUARD_USB_WAKEUP_H 27 | 28 | #include 29 | 30 | #include "wakeup.h" 31 | 32 | using namespace std; 33 | 34 | class usb_wakeup : public wakeup { 35 | char usb_path[PATH_MAX]; 36 | public: 37 | char interf[4096]; 38 | usb_wakeup(const char *usb_path, const char *iface); 39 | 40 | virtual int wakeup_value(void); 41 | 42 | virtual void wakeup_toggle(void); 43 | 44 | virtual const char *wakeup_toggle_script(void); 45 | 46 | }; 47 | 48 | extern void add_usb_wakeup(void); 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/wakeup/wakeup_ethernet.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Gayatri Kammela 24 | */ 25 | #ifndef _INCLUDE_GUARD_ETHERNET_WAKEUP_H 26 | #define _INCLUDE_GUARD_ETHERNET_WAKEUP_H 27 | 28 | #include 29 | 30 | #include "wakeup.h" 31 | 32 | using namespace std; 33 | 34 | class ethernet_wakeup : public wakeup { 35 | char eth_path[PATH_MAX]; 36 | public: 37 | char interf[4096]; 38 | ethernet_wakeup(const char *eth_path, const char *iface); 39 | 40 | virtual int wakeup_value(void); 41 | 42 | virtual void wakeup_toggle(void); 43 | 44 | virtual const char *wakeup_toggle_script(void); 45 | 46 | }; 47 | 48 | extern void add_ethernet_wakeup(void); 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/tuning/runtime.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #ifndef _INCLUDE_GUARD_RUNTIME_TUNE_H 26 | #define _INCLUDE_GUARD_RUNTIME_TUNE_H 27 | 28 | #include 29 | #include 30 | 31 | #include "tunable.h" 32 | using namespace std; 33 | 34 | class runtime_tunable : public tunable { 35 | char runtime_path[PATH_MAX]; 36 | public: 37 | runtime_tunable(const char *runtime_path, const char *bus, const char *dev, const char *port); 38 | 39 | virtual int good_bad(void); 40 | 41 | virtual void toggle(void); 42 | 43 | virtual const char *toggle_script(void); 44 | 45 | }; 46 | 47 | extern void add_runtime_tunables(const char *bus); 48 | 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/measurement/extech.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #ifndef __INCLUDE_GUARD_EXTECH_H 26 | #define __INCLUDE_GUARD_EXTECH_H 27 | 28 | #include 29 | #include "measurement.h" 30 | 31 | class extech_power_meter: public power_meter { 32 | char dev_name[256]; 33 | int fd; 34 | 35 | double rate; 36 | void measure(void); 37 | double sum; 38 | int samples; 39 | int end_thread; 40 | pthread_t thread; 41 | public: 42 | extech_power_meter(const char *_dev_name); 43 | virtual void start_measurement(void); 44 | virtual void end_measurement(void); 45 | virtual void sample(void); 46 | 47 | virtual double power(void); 48 | virtual double dev_capacity(void) { return 0.0; }; 49 | }; 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /src/tuning/tunable.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | 26 | #include "tuning.h" 27 | #include "tunable.h" 28 | #include 29 | #include "../lib.h" 30 | 31 | vector all_tunables; 32 | vector all_untunables; 33 | 34 | 35 | tunable::tunable(const char *str, double _score, const char *good, const char *bad, const char *neutral) 36 | { 37 | score = _score; 38 | pt_strcpy(desc, str); 39 | pt_strcpy(good_string, good); 40 | pt_strcpy(bad_string, bad); 41 | pt_strcpy(neutral_string, neutral); 42 | } 43 | 44 | 45 | tunable::tunable(void) 46 | { 47 | score = 0; 48 | desc[0] = 0; 49 | pt_strcpy(good_string, _("Good")); 50 | pt_strcpy(bad_string, _("Bad")); 51 | pt_strcpy(neutral_string, _("Unknown")); 52 | } 53 | -------------------------------------------------------------------------------- /src/wakeup/wakeup.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Gayatri Kammela 24 | */ 25 | 26 | #include 27 | #include 28 | #include "wakeup.h" 29 | #include 30 | #include "../lib.h" 31 | 32 | using namespace std; 33 | 34 | vector wakeup_all; 35 | 36 | wakeup::wakeup(const char *str, double _score, const char *enable, const char *disable) 37 | { 38 | score = _score; 39 | pt_strcpy(desc, str); 40 | pt_strcpy(wakeup_enable, enable); 41 | pt_strcpy(wakeup_disable, disable); 42 | } 43 | 44 | wakeup::wakeup(void) 45 | { 46 | score = 0; 47 | desc[0] = 0; 48 | pt_strcpy(wakeup_enable, _("Enabled")); 49 | pt_strcpy(wakeup_disable, _("Disabled")); 50 | pt_strcpy(wakeup_idle, _("Unknown")); 51 | } 52 | 53 | -------------------------------------------------------------------------------- /src/perf/perf_bundle.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #ifndef _INCLUDE_GUARD_PERF_BUNDLE_H_ 26 | #define _INCLUDE_GUARD_PERF_BUNDLE_H_ 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | using namespace std; 33 | 34 | #include "perf.h" 35 | class perf_event; 36 | 37 | 38 | class perf_bundle { 39 | protected: 40 | vector events; 41 | public: 42 | vector records; 43 | virtual ~perf_bundle() {}; 44 | 45 | virtual void release(void); 46 | bool add_event(const char *system_name, const char *event_name); 47 | 48 | void start(void); 49 | void stop(void); 50 | void clear(void); 51 | 52 | void process(void); 53 | 54 | virtual void handle_trace_point(void *trace, int cpu = 0, uint64_t time = 0); 55 | }; 56 | 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /src/tuning/tuningsysfs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #ifndef _INCLUDE_GUARD_SYSFS_TUNE_H 26 | #define _INCLUDE_GUARD_SYSFS_TUNE_H 27 | 28 | #include 29 | #include 30 | 31 | #include "tunable.h" 32 | 33 | using namespace std; 34 | 35 | class sysfs_tunable : public tunable { 36 | char sysfs_path[PATH_MAX]; 37 | char target_value[4096]; 38 | char bad_value[4096]; 39 | public: 40 | sysfs_tunable(const char *str, const char *sysfs_path, const char *target_content); 41 | 42 | virtual int good_bad(void); 43 | 44 | virtual void toggle(void); 45 | 46 | virtual const char *toggle_script(void); 47 | 48 | }; 49 | 50 | extern void add_sysfs_tunable(const char *str, const char *_sysfs_path, const char *_target_content); 51 | extern void add_sata_tunables(void); 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # automake 2 | Makefile 3 | Makefile.in 4 | /ar-lib 5 | /mdate-sh 6 | /py-compile 7 | /test-driver 8 | /ylwrap 9 | .deps/ 10 | .dirstamp 11 | 12 | # autoconf 13 | autom4te.cache 14 | /config.h 15 | /config.rpath 16 | /autoscan.log 17 | /autoscan-*.log 18 | /aclocal.m4 19 | /compile 20 | /config.guess 21 | /config.h.in 22 | /config.log 23 | /config.status 24 | /config.sub 25 | /configure 26 | /configure.scan 27 | /depcomp 28 | /install-sh 29 | /missing 30 | /stamp-h1 31 | 32 | # libtool 33 | /libtool 34 | /ltmain.sh 35 | m4/libtool.m4 36 | m4/ltoptions.m4 37 | m4/ltsugar.m4 38 | m4/ltversion.m4 39 | m4/lt~obsolete.m4 40 | .libs 41 | *.lo 42 | *.la 43 | 44 | # texinfo 45 | /texinfo.tex 46 | 47 | # autoreconf and gettext 48 | /ABOUT-NLS 49 | m4/ax_add_fortify_source.m4 50 | m4/ax_cxx_compile_stdcxx.m4 51 | m4/ax_pthread.m4 52 | m4/gettext.m4 53 | m4/host-cpu-c-abi.m4 54 | m4/iconv.m4 55 | m4/intlmacosx.m4 56 | m4/lib-ld.m4 57 | m4/lib-link.m4 58 | m4/lib-prefix.m4 59 | m4/nls.m4 60 | m4/pkg.m4 61 | m4/po.m4 62 | m4/progtest.m4 63 | po/POTFILES 64 | po/Makevars.template 65 | po/Rules-quot 66 | po/boldquot.sed 67 | po/en@boldquot.header 68 | po/en@quot.header 69 | po/insert-header.sin 70 | po/quot.sed 71 | po/remove-potcdate.sin 72 | po/remove-potcdate.sed 73 | 74 | # gettext build artifacts 75 | po/ca.gmo 76 | po/cs_CZ.gmo 77 | po/de_DE.gmo 78 | po/en_GB.gmo 79 | po/en_US.gmo 80 | po/es_ES.gmo 81 | po/hu_HU.gmo 82 | po/id_ID.gmo 83 | po/nl_NL.gmo 84 | po/stamp-po 85 | po/zh_TW.gmo 86 | 87 | # other generated files 88 | /Doxyfile 89 | src/css.h 90 | 91 | # object files 92 | *.o 93 | src/powertop 94 | 95 | # development tools 96 | cscope.out 97 | tags 98 | 99 | # doxygen 100 | doc/html 101 | Doxyfile.in.bak 102 | -------------------------------------------------------------------------------- /src/measurement/sysfs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Anssi Hannula 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Anssi Hannula 24 | */ 25 | #ifndef INCLUDE_GUARD_SYSFS_H 26 | #define INCLUDE_GUARD_SYSFS_H 27 | 28 | #include "measurement.h" 29 | 30 | class sysfs_power_meter: public power_meter { 31 | char name[256]; 32 | 33 | double capacity; 34 | double rate; 35 | 36 | bool get_sysfs_attr(const char *attribute, int *value); 37 | bool is_present(); 38 | double get_voltage(); 39 | 40 | bool set_rate_from_power(); 41 | bool set_rate_from_current(double voltage); 42 | bool set_capacity_from_energy(); 43 | bool set_capacity_from_charge(double voltage); 44 | 45 | void measure(); 46 | public: 47 | sysfs_power_meter(const char *power_supply_name); 48 | virtual void start_measurement(void); 49 | virtual void end_measurement(void); 50 | 51 | virtual double power(void) { return rate; } 52 | virtual double dev_capacity(void) { return capacity; } 53 | }; 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /src/process/work.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #ifndef _INCLUDE_GUARD_WORK_H 26 | #define _INCLUDE_GUARD_WORK_H 27 | 28 | #include 29 | 30 | #include "powerconsumer.h" 31 | 32 | class work : public power_consumer { 33 | char desc[256]; 34 | public: 35 | char handler[32]; 36 | int raw_count; 37 | 38 | work(unsigned long work_func); 39 | 40 | void fire(uint64_t time, uint64_t work_struct); 41 | uint64_t done(uint64_t time, uint64_t work_struct); 42 | 43 | virtual const char * description(void); 44 | virtual const char * name(void) { return "work"; }; 45 | virtual const char * type(void) { return "kWork"; }; 46 | virtual double usage_summary(void); 47 | virtual const char * usage_units_summary(void); 48 | 49 | }; 50 | 51 | 52 | extern void all_work_to_all_power(void); 53 | extern class work * find_create_work(uint64_t func); 54 | 55 | extern void clear_work(void); 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /src/report/report-formatter-base.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012 Samsung Electronics Co., Ltd. 2 | * http://www.samsung.com/ 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Common part of report_formatter_csv and report_formatter_html. 23 | * Written by Igor Zhbanov 24 | * 2012.10 */ 25 | 26 | #ifndef _REPORT_FORMATTER_BASE_H_ 27 | #define _REPORT_FORMATTER_BASE_H_ 28 | 29 | #include "report-formatter.h" 30 | 31 | class report_formatter_string_base: public report_formatter 32 | { 33 | public: 34 | virtual const char *get_result(); 35 | virtual void clear_result(); 36 | 37 | virtual void add(const char *str); 38 | virtual void addv(const char *fmt, va_list ap); 39 | 40 | protected: 41 | void add_exact(const char *str); 42 | void addf(const char *fmt, ...) 43 | __attribute__ ((format (printf, 2, 3))); 44 | void addf_exact(const char *fmt, ...) 45 | __attribute__ ((format (printf, 2, 3))); 46 | 47 | virtual std::string escape_string(const char *str) = 0; 48 | 49 | std::string result; 50 | }; 51 | 52 | #endif /* _REPORT_FORMATTER_BASE_H_ */ 53 | -------------------------------------------------------------------------------- /src/devices/i915-gpu.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #ifndef _INCLUDE_GUARD_i915_GPU_H 26 | #define _INCLUDE_GUARD_i915_GPU_H 27 | 28 | 29 | #include "device.h" 30 | 31 | class i915gpu: public device { 32 | int index; 33 | int rindex; 34 | vectorchild_devices; 35 | 36 | public: 37 | 38 | i915gpu(); 39 | 40 | virtual void start_measurement(void); 41 | virtual void end_measurement(void); 42 | 43 | virtual double utilization(void); /* percentage */ 44 | 45 | virtual const char * class_name(void) { return "GPU";}; 46 | 47 | virtual const char * device_name(void); 48 | virtual double power_usage(struct result_bundle *result, struct parameter_bundle *bundle); 49 | virtual bool show_in_list(void) {return false;}; 50 | virtual const char * util_units(void) { return " ops/s"; }; 51 | 52 | virtual void add_child(device *dev_ptr) { child_devices.push_back(dev_ptr);} 53 | }; 54 | 55 | extern void create_i915_gpu(void); 56 | 57 | 58 | #endif -------------------------------------------------------------------------------- /src/tuning/iw.h: -------------------------------------------------------------------------------- 1 | #ifndef __IW_H 2 | #define __IW_H 3 | 4 | /* 5 | * This code has been blatently stolen from 6 | * 7 | * nl80211 userspace tool 8 | * 9 | * Copyright 2007, 2008 Johannes Berg 10 | * 11 | * and has been stripped down to just the pieces needed. 12 | */ 13 | 14 | /* 15 | 16 | Copyright (c) 2007, 2008 Johannes Berg 17 | Copyright (c) 2007 Andy Lutomirski 18 | Copyright (c) 2007 Mike Kershaw 19 | Copyright (c) 2008-2009 Luis R. Rodriguez 20 | 21 | Permission to use, copy, modify, and/or distribute this software for any 22 | purpose with or without fee is hereby granted, provided that the above 23 | copyright notice and this permission notice appear in all copies. 24 | 25 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 26 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 27 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 28 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 29 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 30 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 31 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 32 | 33 | */ 34 | 35 | #include 36 | 37 | #define ETH_ALEN 6 38 | 39 | #if HAVE_CONFIG_H 40 | #include "config.h" 41 | #endif 42 | 43 | #ifndef HAVE_LIBNL20 44 | #define nl_sock nl_handle 45 | #endif 46 | 47 | struct nl80211_state { 48 | struct nl_sock *nl_sock; 49 | struct nl_cache *nl_cache; 50 | struct genl_family *nl80211; 51 | }; 52 | 53 | enum command_identify_by { 54 | CIB_NONE, 55 | CIB_PHY, 56 | CIB_NETDEV, 57 | }; 58 | 59 | enum id_input { 60 | II_NONE, 61 | II_NETDEV, 62 | II_PHY_NAME, 63 | II_PHY_IDX, 64 | }; 65 | 66 | int get_wifi_power_saving(const char *iface); 67 | int set_wifi_power_saving(const char *iface, int state); 68 | 69 | #endif /* __IW_H */ 70 | -------------------------------------------------------------------------------- /src/devices/gpu_rapl_device.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Srinivas Pandruvada 24 | */ 25 | #ifndef _INCLUDE_GUARD_GPU_RAPL_DEVICE_H 26 | #define _INCLUDE_GUARD_GPU_RAPL_DEVICE_H 27 | 28 | #include 29 | #include 30 | 31 | using namespace std; 32 | 33 | #include 34 | #include "i915-gpu.h" 35 | #include "cpu/rapl/rapl_interface.h" 36 | 37 | class gpu_rapl_device: public i915gpu { 38 | 39 | c_rapl_interface rapl; 40 | time_t last_time; 41 | double last_energy; 42 | double consumed_power; 43 | bool device_valid; 44 | 45 | public: 46 | gpu_rapl_device(i915gpu *parent); 47 | virtual const char * class_name(void) { return "GPU core";}; 48 | virtual const char * device_name(void) { return "GPU core";}; 49 | bool device_present() { return device_valid;} 50 | virtual double power_usage(struct result_bundle *result, struct parameter_bundle *bundle); 51 | virtual void start_measurement(void); 52 | virtual void end_measurement(void); 53 | 54 | }; 55 | 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /src/process/processdevice.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #ifndef _INCLUDE_GUARD_DEVICE2_H 26 | #define _INCLUDE_GUARD_DEVICE2_H 27 | 28 | #include 29 | 30 | #include "powerconsumer.h" 31 | #include "../devices/device.h" 32 | 33 | class device_consumer : public power_consumer { 34 | char str[4096]; 35 | public: 36 | int prio; 37 | double power; 38 | class device *device; 39 | device_consumer(class device *dev); 40 | 41 | virtual const char * description(void); 42 | virtual const char * name(void) { return "device"; }; 43 | virtual const char * type(void) { return "Device"; }; 44 | virtual double Witts(void); 45 | virtual double usage(void) { return device->utilization();}; 46 | virtual const char * usage_units(void) {return device->util_units();}; 47 | virtual int show_events(void) { return 0; }; 48 | }; 49 | 50 | extern void all_devices_to_all_power(void); 51 | extern vector all_proc_devices; 52 | 53 | extern void clear_proc_devices(void); 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /src/devices/backlight.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #ifndef _INCLUDE_GUARD_BACKLIGHT_H 26 | #define _INCLUDE_GUARD_BACKLIGHT_H 27 | 28 | #include 29 | 30 | #include "device.h" 31 | 32 | class backlight: public device { 33 | int min_level, max_level; 34 | int start_level, end_level; 35 | char sysfs_path[PATH_MAX]; 36 | char name[4096]; 37 | int r_index; 38 | int r_index_power; 39 | public: 40 | 41 | backlight(const char *_name, const char *path); 42 | 43 | virtual void start_measurement(void); 44 | virtual void end_measurement(void); 45 | 46 | virtual double utilization(void); /* percentage */ 47 | 48 | virtual const char * class_name(void) { return "backlight";}; 49 | 50 | virtual const char * device_name(void); 51 | virtual const char * human_name(void) { return "Display backlight";}; 52 | virtual double power_usage(struct result_bundle *result, struct parameter_bundle *bundle); 53 | virtual int grouping_prio(void) { return 10; }; 54 | }; 55 | 56 | extern void create_all_backlights(void); 57 | 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /src/cpu/dram_rapl_device.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Srinivas Pandruvada 24 | */ 25 | #ifndef _INCLUDE_GUARD_DRAM_RAPL_DEVICE_H 26 | #define _INCLUDE_GUARD_DRAM_RAPL_DEVICE_H 27 | 28 | #include 29 | #include 30 | 31 | using namespace std; 32 | 33 | #include 34 | #include "cpudevice.h" 35 | #include "rapl/rapl_interface.h" 36 | 37 | class dram_rapl_device: public cpudevice { 38 | 39 | c_rapl_interface *rapl; 40 | time_t last_time; 41 | double last_energy; 42 | double consumed_power; 43 | bool device_valid; 44 | 45 | public: 46 | dram_rapl_device(cpudevice *parent, const char *classname = "dram_core", const char *device_name = "dram_core", class abstract_cpu *_cpu = NULL); 47 | ~dram_rapl_device() { delete rapl; } 48 | virtual const char * device_name(void) {return "DRAM";}; 49 | bool device_present() { return device_valid;} 50 | virtual double power_usage(struct result_bundle *result, struct parameter_bundle *bundle); 51 | void start_measurement(void); 52 | void end_measurement(void); 53 | 54 | }; 55 | 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /src/cpu/cpu_rapl_device.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Srinivas Pandruvada 24 | */ 25 | #ifndef _INCLUDE_GUARD_CPU_RAPL_DEVICE_H 26 | #define _INCLUDE_GUARD_CPU_RAPL_DEVICE_H 27 | 28 | #include 29 | #include 30 | 31 | using namespace std; 32 | 33 | #include 34 | #include "cpudevice.h" 35 | #include "rapl/rapl_interface.h" 36 | 37 | class cpu_rapl_device: public cpudevice { 38 | 39 | c_rapl_interface *rapl; 40 | time_t last_time; 41 | double last_energy; 42 | double consumed_power; 43 | bool device_valid; 44 | 45 | public: 46 | cpu_rapl_device(cpudevice *parent, const char *classname = "cpu_core", const char *device_name = "cpu_core", class abstract_cpu *_cpu = NULL); 47 | ~cpu_rapl_device() { delete rapl; } 48 | virtual const char * device_name(void) {return "CPU core";}; 49 | bool device_present() { return device_valid;} 50 | virtual double power_usage(struct result_bundle *result, struct parameter_bundle *bundle); 51 | virtual void start_measurement(void); 52 | virtual void end_measurement(void); 53 | 54 | }; 55 | 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /src/process/timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #ifndef _INCLUDE_GUARD_TIMER_H 26 | #define _INCLUDE_GUARD_TIMER_H 27 | 28 | #include 29 | 30 | #include "powerconsumer.h" 31 | 32 | class timer : public power_consumer { 33 | char desc[256]; 34 | public: 35 | char handler[32]; 36 | int raw_count; 37 | bool deferred; 38 | 39 | timer(unsigned long timer_func); 40 | 41 | void fire(uint64_t time, uint64_t timer_struct); 42 | uint64_t done(uint64_t time, uint64_t timer_struct); 43 | bool is_deferred(void); 44 | 45 | virtual const char * description(void); 46 | virtual const char * name(void) { return "timer"; }; 47 | virtual const char * type(void) { return "Timer"; }; 48 | virtual double usage_summary(void); 49 | virtual const char * usage_units_summary(void); 50 | 51 | }; 52 | 53 | class timer_list { 54 | public: 55 | uint64_t timer_address; 56 | uint64_t timer_func; 57 | }; 58 | 59 | 60 | extern void all_timers_to_all_power(void); 61 | extern class timer * find_create_timer(uint64_t func); 62 | extern void clear_timers(void); 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /src/devices/thinkpad-light.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #ifndef _INCLUDE_GUARD_THINKPAD_LIGHT_H 26 | #define _INCLUDE_GUARD_THINKPAD_LIGHT_H 27 | 28 | 29 | #include "device.h" 30 | #include "../parameters/parameters.h" 31 | 32 | class thinkpad_light: public device { 33 | double start_rate, end_rate; 34 | int light_index; 35 | int r_index; 36 | public: 37 | 38 | thinkpad_light(); 39 | 40 | virtual void start_measurement(void); 41 | virtual void end_measurement(void); 42 | 43 | virtual double utilization(void); /* percentage */ 44 | 45 | virtual const char * class_name(void) { return "light";}; 46 | 47 | virtual const char * device_name(void) { return "Light-1";}; 48 | virtual const char * human_name(void) { return "Thinkpad light";}; 49 | virtual double power_usage(struct result_bundle *result, struct parameter_bundle *bundle); 50 | virtual const char * util_units(void) { return "%"; }; 51 | virtual int power_valid(void) { return utilization_power_valid(r_index);}; 52 | virtual int grouping_prio(void) { return 1; }; 53 | }; 54 | 55 | extern void create_thinkpad_light(void); 56 | 57 | 58 | #endif -------------------------------------------------------------------------------- /src/devices/thinkpad-fan.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #ifndef _INCLUDE_GUARD_THINKPAD_FAN_H 26 | #define _INCLUDE_GUARD_THINKPAD_FAN_H 27 | 28 | 29 | #include "device.h" 30 | #include "../parameters/parameters.h" 31 | 32 | class thinkpad_fan: public device { 33 | double start_rate, end_rate; 34 | int fan_index, fansqr_index, fancub_index; 35 | int r_index; 36 | public: 37 | 38 | thinkpad_fan(); 39 | 40 | virtual void start_measurement(void); 41 | virtual void end_measurement(void); 42 | 43 | virtual double utilization(void); /* percentage */ 44 | 45 | virtual const char * class_name(void) { return "fan";}; 46 | 47 | virtual const char * device_name(void) { return "Fan-1";}; 48 | virtual const char * human_name(void) { return "Laptop fan";}; 49 | virtual double power_usage(struct result_bundle *result, struct parameter_bundle *bundle); 50 | virtual const char * util_units(void) { return " rpm"; }; 51 | virtual int power_valid(void) { return utilization_power_valid(r_index);}; 52 | virtual int grouping_prio(void) { return 1; }; 53 | }; 54 | 55 | extern void create_thinkpad_fan(void); 56 | 57 | 58 | #endif -------------------------------------------------------------------------------- /src/report/report-data-html.h: -------------------------------------------------------------------------------- 1 | #ifndef PowerTop_REPORT_DATA_HTML_H_C58C116411234A34AC2EFB8D23A69713 2 | #define PowerTop_REPORT_DATA_HTML_H_C58C116411234A34AC2EFB8D23A69713 3 | 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | struct tag_attr { 10 | const char *css_class; 11 | const char *css_id; 12 | }; 13 | /* T:Top, L:Left, TL:Top-Left, TLC: Top-Left-Center */ 14 | enum position { T, L, TL, TC, TLC }; 15 | 16 | struct table_attributes { 17 | const char *table_class; 18 | const char *td_class; 19 | const char *tr_class; 20 | const char *th_class; 21 | position pos_table_title; 22 | int title_mod; 23 | int rows; 24 | int cols; 25 | }; 26 | 27 | struct table_size { 28 | int rows; 29 | int cols; 30 | }; 31 | 32 | 33 | /* Definition of css attributes for the cases that apply to powertop 34 | * html report 35 | * */ 36 | 37 | void 38 | init_div(struct tag_attr *div_attr, const char *css_class, const char *css_id); 39 | 40 | void 41 | init_top_table_attr(struct table_attributes *table_css, int rows, int cols); 42 | 43 | void 44 | init_title_attr(struct tag_attr *title_attr); 45 | 46 | void 47 | init_std_table_attr(struct table_attributes *table_css, int rows, int cols); 48 | 49 | void 50 | init_std_side_table_attr(struct table_attributes *table_css, int rows, 51 | int cols); 52 | 53 | void 54 | init_pkg_table_attr(struct table_attributes *table_css, int rows, int cols); 55 | 56 | void 57 | init_core_table_attr(struct table_attributes *table_css, int title_mod, 58 | int rows, int cols); 59 | 60 | void 61 | init_cpu_table_attr(struct table_attributes *table_css, int title_mod, 62 | int rows, int cols); 63 | void 64 | init_nowarp_table_attr(struct table_attributes *table_css, int rows, int cols); 65 | 66 | void 67 | init_tune_table_attr(struct table_attributes *table_css, int rows, int cols); 68 | 69 | void 70 | init_wakeup_table_attr(struct table_attributes *table_css, int rows, int cols); 71 | 72 | /* Other helper functions */ 73 | string 74 | double_to_string(double dval); 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /src/perf/perf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #ifndef _INCLUDE_GUARD_PERF_H_ 26 | #define _INCLUDE_GUARD_PERF_H_ 27 | 28 | #include 29 | 30 | 31 | extern "C" { 32 | #include 33 | } 34 | 35 | 36 | using namespace std; 37 | 38 | class perf_event { 39 | protected: 40 | int perf_fd; 41 | void * perf_mmap; 42 | void * data_mmap; 43 | struct perf_event_mmap_page *pc; 44 | 45 | 46 | 47 | int bufsize; 48 | char *name; 49 | int cpu; 50 | void create_perf_event(char *eventname, int cpu); 51 | 52 | public: 53 | unsigned int trace_type; 54 | 55 | perf_event(void); 56 | perf_event(const char *system_name, const char *event_name, int cpu = 0, int buffer_size = 128); 57 | 58 | virtual ~perf_event(void); 59 | 60 | 61 | void set_event_name(const char *system_name, const char *event_name); 62 | void set_cpu(int cpu); 63 | 64 | void start(void); 65 | void stop(void); 66 | void clear(void); 67 | 68 | void process(void *cookie); 69 | 70 | virtual void handle_event(struct perf_event_header *header, void *cookie) { }; 71 | 72 | static struct tep_handle *tep; 73 | 74 | }; 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /src/devices/rfkill.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #ifndef _INCLUDE_GUARD_RFKILL_H 26 | #define _INCLUDE_GUARD_RFKILL_H 27 | 28 | #include 29 | 30 | #include "device.h" 31 | #include "../parameters/parameters.h" 32 | 33 | class rfkill: public device { 34 | int start_soft, end_soft; 35 | int start_hard, end_hard; 36 | char sysfs_path[PATH_MAX]; 37 | char name[4096]; 38 | char humanname[4096]; 39 | int index; 40 | int rindex; 41 | public: 42 | 43 | rfkill(char *_name, char *path); 44 | 45 | virtual void start_measurement(void); 46 | virtual void end_measurement(void); 47 | 48 | virtual double utilization(void); /* percentage */ 49 | 50 | virtual const char * class_name(void) { return "radio";}; 51 | 52 | virtual const char * device_name(void); 53 | virtual const char * human_name(void) { return humanname; }; 54 | virtual double power_usage(struct result_bundle *result, struct parameter_bundle *bundle); 55 | virtual int power_valid(void) { return utilization_power_valid(rindex);}; 56 | virtual int grouping_prio(void) { return 5; }; 57 | }; 58 | 59 | extern void create_all_rfkills(void); 60 | 61 | 62 | #endif -------------------------------------------------------------------------------- /src/process/interrupt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #ifndef _INCLUDE_GUARD_INTERRUPT_H 26 | #define _INCLUDE_GUARD_INTERRUPT_H 27 | 28 | #include 29 | 30 | #include "powerconsumer.h" 31 | 32 | class interrupt : public power_consumer { 33 | uint64_t running_since; 34 | char desc[256]; 35 | public: 36 | char handler[32]; 37 | int number; 38 | 39 | int raw_count; 40 | 41 | interrupt(const char *_handler, int _number); 42 | 43 | virtual void start_interrupt(uint64_t time); 44 | virtual uint64_t end_interrupt(uint64_t time); 45 | 46 | virtual const char * description(void); 47 | 48 | virtual const char * name(void) { return "interrupt"; }; 49 | virtual const char * type(void) { return "Interrupt"; }; 50 | virtual double usage_summary(void); 51 | virtual const char * usage_units_summary(void); 52 | }; 53 | 54 | extern vector all_interrupts; 55 | extern const char* softirqs[]; 56 | 57 | 58 | extern class interrupt * find_create_interrupt(const char *_handler, int nr, int cpu); 59 | extern void all_interrupts_to_all_power(void); 60 | extern void clear_interrupts(void); 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /src/cpu/cpudevice.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #ifndef _INCLUDE_GUARD_CPUDEVICE_H 26 | #define _INCLUDE_GUARD_CPUDEVICE_H 27 | 28 | #include 29 | #include 30 | 31 | using namespace std; 32 | 33 | #include "../devices/device.h" 34 | #include "cpu.h" 35 | 36 | class cpudevice: public device { 37 | protected: 38 | char _class[128]; 39 | char _cpuname[128]; 40 | 41 | vector params; 42 | class abstract_cpu *cpu; 43 | int wake_index; 44 | int consumption_index; 45 | int r_wake_index; 46 | int r_consumption_index; 47 | 48 | vectorchild_devices; 49 | 50 | public: 51 | cpudevice(const char *classname = "cpu", const char *device_name = "cpu0", class abstract_cpu *_cpu = NULL); 52 | virtual const char * class_name(void) { return _class;}; 53 | 54 | virtual const char * device_name(void); 55 | 56 | virtual double power_usage(struct result_bundle *result, struct parameter_bundle *bundle); 57 | virtual bool show_in_list(void) {return false;}; 58 | virtual double utilization(void); /* percentage */ 59 | void add_child(device *dev_ptr) { child_devices.push_back(dev_ptr);} 60 | }; 61 | 62 | 63 | #endif -------------------------------------------------------------------------------- /src/measurement/measurement.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #ifndef __INCLUDE_GUARD_MEASUREMENT_H 26 | #define __INCLUDE_GUARD_MEASUREMENT_H 27 | 28 | #include 29 | 30 | using namespace std; 31 | 32 | class power_meter { 33 | bool discharging = false; 34 | public: 35 | virtual ~power_meter() {}; 36 | 37 | virtual void start_measurement(void); 38 | virtual void end_measurement(void); 39 | virtual double power(void); 40 | 41 | virtual double dev_capacity(void) 42 | { 43 | return 0.0; /* in Joules */ 44 | } 45 | 46 | virtual void set_discharging(bool d) 47 | { 48 | discharging = d; 49 | } 50 | 51 | virtual bool is_discharging() 52 | { 53 | return discharging; 54 | } 55 | }; 56 | 57 | extern vector power_meters; 58 | 59 | extern void start_power_measurement(void); 60 | extern void end_power_measurement(void); 61 | extern double global_power(void); 62 | extern void global_sample_power(void); 63 | extern double global_joules(void); 64 | extern double global_time_left(void); 65 | 66 | extern void detect_power_meters(void); 67 | extern void extech_power_meter(const char *devnode); 68 | 69 | extern double min_power; 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /src/report/report-formatter.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012 Samsung Electronics Co., Ltd. 2 | * http://www.samsung.com/ 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * report_formatter interface. 23 | * Written by Igor Zhbanov 24 | * 2012.10 */ 25 | 26 | #ifndef _REPORT_FORMATTER_H_ 27 | #define _REPORT_FORMATTER_H_ 28 | 29 | #include "report-maker.h" 30 | using namespace std; 31 | 32 | class report_formatter 33 | { 34 | public: 35 | virtual ~report_formatter() {} 36 | 37 | virtual void finish_report() {} 38 | virtual const char *get_result() {return "Basic report_formatter::get_result() call\n";} 39 | virtual void clear_result() {} 40 | 41 | virtual void add(const char *str) {} 42 | virtual void addv(const char *fmt, va_list ap) {} 43 | 44 | /* *** Report Style *** */ 45 | virtual void add_logo() {} 46 | virtual void add_header() {} 47 | virtual void end_header() {} 48 | virtual void add_div(struct tag_attr *div_attr) {} 49 | virtual void end_div() {} 50 | virtual void add_title(struct tag_attr *att_title, const char *title) {} 51 | virtual void add_navigation() {} 52 | virtual void add_summary_list(string *list, int size) {} 53 | virtual void add_table(string *system_data, 54 | struct table_attributes *tb_attr) {} 55 | }; 56 | 57 | #endif /* _REPORT_FORMATTER_H_ */ 58 | -------------------------------------------------------------------------------- /src/devices/gpu_rapl_device.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Srinivas Pandruvada 24 | */ 25 | #include 26 | #include 27 | #include 28 | #include "../parameters/parameters.h" 29 | #include "gpu_rapl_device.h" 30 | 31 | gpu_rapl_device::gpu_rapl_device(i915gpu *parent) 32 | : i915gpu(), 33 | device_valid(false) 34 | { 35 | last_time = time(NULL); 36 | if (rapl.pp1_domain_present()) { 37 | device_valid = true; 38 | parent->add_child(this); 39 | rapl.get_pp1_energy_status(&last_energy); 40 | } 41 | } 42 | 43 | void gpu_rapl_device::start_measurement(void) 44 | { 45 | last_time = time(NULL); 46 | 47 | rapl.get_pp1_energy_status(&last_energy); 48 | } 49 | 50 | void gpu_rapl_device::end_measurement(void) 51 | { 52 | time_t curr_time = time(NULL); 53 | double energy; 54 | 55 | consumed_power = 0.0; 56 | if ((curr_time - last_time) > 0) { 57 | rapl.get_pp1_energy_status(&energy); 58 | consumed_power = (energy-last_energy)/(curr_time-last_time); 59 | last_energy = energy; 60 | last_time = curr_time; 61 | } 62 | } 63 | 64 | double gpu_rapl_device::power_usage(struct result_bundle *result, struct parameter_bundle *bundle) 65 | { 66 | if (rapl.pp1_domain_present()) 67 | return consumed_power; 68 | else 69 | return 0.0; 70 | } 71 | -------------------------------------------------------------------------------- /src/devices/alsa.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #ifndef _INCLUDE_GUARD_ALSA_H 26 | #define _INCLUDE_GUARD_ALSA_H 27 | 28 | 29 | #include "device.h" 30 | #include "../parameters/parameters.h" 31 | 32 | #include 33 | #include 34 | 35 | class alsa: public device { 36 | uint64_t start_active, end_active; 37 | uint64_t start_inactive, end_inactive; 38 | char sysfs_path[PATH_MAX]; 39 | char name[4096]; 40 | char humanname[4096]; 41 | char temp_buf[4096]; 42 | int rindex; 43 | public: 44 | 45 | alsa(const char *_name, const char *path); 46 | 47 | virtual void start_measurement(void); 48 | virtual void end_measurement(void); 49 | 50 | virtual double utilization(void); /* percentage */ 51 | 52 | virtual const char * class_name(void) { return "alsa";}; 53 | 54 | virtual const char * device_name(void); 55 | virtual const char * human_name(void); 56 | virtual double power_usage(struct result_bundle *result, struct parameter_bundle *bundle); 57 | virtual int power_valid(void) { return utilization_power_valid(rindex);}; 58 | 59 | virtual void register_power_with_devlist(struct result_bundle *results, struct parameter_bundle *bundle); 60 | virtual int grouping_prio(void) { return 0; }; 61 | 62 | }; 63 | 64 | extern void create_all_alsa(void); 65 | 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /src/devices/runtime_pm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #ifndef _INCLUDE_GUARD_RUNTIMEPM_H 26 | #define _INCLUDE_GUARD_RUNTIMEPM_H 27 | 28 | #include 29 | 30 | #include "device.h" 31 | #include "../parameters/parameters.h" 32 | 33 | class runtime_pmdevice: public device { 34 | uint64_t before_suspended_time, before_active_time; 35 | uint64_t after_suspended_time, after_active_time; 36 | char sysfs_path[PATH_MAX]; 37 | char name[4096]; 38 | char humanname[4096]; 39 | int index; 40 | int r_index; 41 | public: 42 | 43 | runtime_pmdevice(const char *_name, const char *path); 44 | 45 | virtual void start_measurement(void); 46 | virtual void end_measurement(void); 47 | 48 | virtual double utilization(void); /* percentage */ 49 | 50 | virtual const char * class_name(void) { return "runtime_pm";}; 51 | 52 | virtual const char * device_name(void); 53 | virtual const char * human_name(void); 54 | virtual double power_usage(struct result_bundle *result, struct parameter_bundle *bundle); 55 | virtual int power_valid(void) { return utilization_power_valid(r_index);}; 56 | 57 | void set_human_name(char *name); 58 | virtual int grouping_prio(void) { return 1; }; 59 | }; 60 | 61 | extern void create_all_runtime_pm_devices(void); 62 | 63 | extern int device_has_runtime_pm(const char *sysfs_path); 64 | 65 | 66 | #endif -------------------------------------------------------------------------------- /src/devices/usb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #ifndef _INCLUDE_GUARD_USB_H 26 | #define _INCLUDE_GUARD_USB_H 27 | 28 | #include 29 | 30 | #include "device.h" 31 | #include "../parameters/parameters.h" 32 | 33 | class usbdevice: public device { 34 | int active_before, active_after; 35 | int connected_before, connected_after; 36 | char sysfs_path[PATH_MAX]; 37 | char name[4096]; 38 | char devname[4096]; 39 | char humanname[4096]; 40 | int index; 41 | int r_index; 42 | int rootport; 43 | int busnum; 44 | int devnum; 45 | public: 46 | 47 | usbdevice(const char *_name, const char *path, const char *devid); 48 | 49 | virtual void start_measurement(void); 50 | virtual void end_measurement(void); 51 | 52 | virtual double utilization(void); /* percentage */ 53 | 54 | virtual const char * class_name(void) { return "usb";}; 55 | 56 | virtual const char * device_name(void); 57 | virtual const char * human_name(void); 58 | virtual void register_power_with_devlist(struct result_bundle *results, struct parameter_bundle *bundle); 59 | virtual double power_usage(struct result_bundle *result, struct parameter_bundle *bundle); 60 | virtual int power_valid(void) { return utilization_power_valid(r_index);}; 61 | virtual int grouping_prio(void) { return 4; }; 62 | }; 63 | 64 | extern void create_all_usb_devices(void); 65 | 66 | 67 | #endif -------------------------------------------------------------------------------- /src/wakeup/wakeup.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Gayatri Kammela 24 | */ 25 | #ifndef _INCLUDE_GUARD_WAKEUP_H 26 | #define _INCLUDE_GUARD_WAKEUP_H 27 | 28 | #include 29 | #include 30 | 31 | using namespace std; 32 | 33 | #define WAKEUP_ENABLE 1 34 | #define WAKEUP_DISABLE 0 35 | 36 | class wakeup { 37 | char wakeup_enable[128]; 38 | char wakeup_disable[128]; 39 | char wakeup_idle[128]; 40 | protected: 41 | char toggle_enable[4096]; 42 | char toggle_disable[4096]; 43 | public: 44 | char desc[4096]; 45 | double score; 46 | 47 | wakeup(const char *str, double _score, const char *enable = "", const char *disable = ""); 48 | wakeup(void); 49 | 50 | virtual ~wakeup () {}; 51 | 52 | virtual int wakeup_value(void) { return WAKEUP_DISABLE; } 53 | 54 | virtual char *wakeup_string(void) 55 | { 56 | switch (wakeup_value()) { 57 | case WAKEUP_ENABLE: 58 | return wakeup_enable; 59 | case WAKEUP_DISABLE: 60 | return wakeup_disable; 61 | } 62 | return wakeup_idle; 63 | } 64 | 65 | 66 | virtual const char *description(void) { return desc; }; 67 | 68 | virtual void wakeup_toggle(void) { }; 69 | 70 | virtual const char *wakeup_toggle_script(void) { return toggle_enable; } 71 | 72 | }; 73 | 74 | extern vector wakeup_all; 75 | 76 | extern void initialize_wakeup(void); 77 | extern void wakeup_update_display(void); 78 | extern void report_show_wakeup(void); 79 | extern void clear_wakeup(void); 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /src/cpu/cpu_rapl_device.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Srinivas Pandruvada 24 | */ 25 | #include 26 | #include 27 | #include 28 | #include "../parameters/parameters.h" 29 | #include "cpu_rapl_device.h" 30 | 31 | cpu_rapl_device::cpu_rapl_device(cpudevice *parent, const char *classname, const char *dev_name, class abstract_cpu *_cpu) 32 | : cpudevice(classname, dev_name, _cpu), 33 | device_valid(false) 34 | { 35 | if (_cpu) 36 | rapl = new c_rapl_interface(dev_name, cpu->get_first_cpu()); 37 | else 38 | rapl = new c_rapl_interface(); 39 | last_time = time(NULL); 40 | if (rapl->pp0_domain_present()) { 41 | device_valid = true; 42 | parent->add_child(this); 43 | rapl->get_pp0_energy_status(&last_energy); 44 | } 45 | } 46 | 47 | void cpu_rapl_device::start_measurement(void) 48 | { 49 | last_time = time(NULL); 50 | 51 | rapl->get_pp0_energy_status(&last_energy); 52 | } 53 | 54 | void cpu_rapl_device::end_measurement(void) 55 | { 56 | time_t curr_time = time(NULL); 57 | double energy; 58 | 59 | consumed_power = 0.0; 60 | if ((curr_time - last_time) > 0) { 61 | rapl->get_pp0_energy_status(&energy); 62 | consumed_power = (energy-last_energy)/(curr_time-last_time); 63 | last_energy = energy; 64 | last_time = curr_time; 65 | } 66 | } 67 | 68 | double cpu_rapl_device::power_usage(struct result_bundle *result, struct parameter_bundle *bundle) 69 | { 70 | if (rapl->pp0_domain_present()) 71 | return consumed_power; 72 | else 73 | return 0.0; 74 | } 75 | -------------------------------------------------------------------------------- /src/cpu/dram_rapl_device.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Srinivas Pandruvada 24 | */ 25 | #include 26 | #include 27 | #include 28 | #include "../parameters/parameters.h" 29 | #include "dram_rapl_device.h" 30 | 31 | 32 | dram_rapl_device::dram_rapl_device(cpudevice *parent, const char *classname, const char *dev_name, class abstract_cpu *_cpu) 33 | : cpudevice(classname, dev_name, _cpu), 34 | device_valid(false) 35 | { 36 | if (_cpu) 37 | rapl = new c_rapl_interface(dev_name, cpu->get_first_cpu()); 38 | else 39 | rapl = new c_rapl_interface(); 40 | last_time = time(NULL); 41 | if (rapl->dram_domain_present()) { 42 | device_valid = true; 43 | parent->add_child(this); 44 | rapl->get_dram_energy_status(&last_energy); 45 | } 46 | } 47 | 48 | void dram_rapl_device::start_measurement(void) 49 | { 50 | last_time = time(NULL); 51 | 52 | rapl->get_dram_energy_status(&last_energy); 53 | } 54 | 55 | void dram_rapl_device::end_measurement(void) 56 | { 57 | time_t curr_time = time(NULL); 58 | double energy; 59 | 60 | consumed_power = 0.0; 61 | if ((curr_time - last_time) > 0) { 62 | rapl->get_dram_energy_status(&energy); 63 | consumed_power = (energy-last_energy)/(curr_time-last_time); 64 | last_energy = energy; 65 | last_time = curr_time; 66 | } 67 | } 68 | 69 | double dram_rapl_device::power_usage(struct result_bundle *result, struct parameter_bundle *bundle) 70 | { 71 | if (rapl->dram_domain_present()) 72 | return consumed_power; 73 | else 74 | return 0.0; 75 | } 76 | -------------------------------------------------------------------------------- /src/report/report-formatter-html.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012 Samsung Electronics Co., Ltd. 2 | * http://www.samsung.com/ 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * HTML report generator. 23 | * Written by Igor Zhbanov 24 | * 2012.10 */ 25 | 26 | #ifndef _REPORT_FORMATTER_HTML_H_ 27 | #define _REPORT_FORMATTER_HTML_H_ 28 | 29 | #include 30 | 31 | #include "report-formatter-base.h" 32 | #include "report-data-html.h" 33 | 34 | using namespace std; 35 | 36 | /* Whether to replace " and ' in HTML by " and ' respectively */ 37 | /*#define REPORT_HTML_ESCAPE_QUOTES*/ 38 | 39 | /* ************************************************************************ */ 40 | 41 | struct html_section { 42 | const char *id; 43 | }; 44 | 45 | /* ************************************************************************ */ 46 | 47 | class report_formatter_html: public report_formatter_string_base 48 | { 49 | public: 50 | report_formatter_html(); 51 | void finish_report(); 52 | 53 | /* Report Style */ 54 | void add_logo(); 55 | void add_header(); 56 | void end_header(); 57 | void add_div(struct tag_attr *div_attr); 58 | void end_div(); 59 | void add_title(struct tag_attr *title_att, const char *title); 60 | void add_navigation(); 61 | void add_summary_list(string *list, int size); 62 | void add_table(string *system_data, struct table_attributes *tb_attr); 63 | 64 | private: 65 | /* Document structure related functions */ 66 | void init_markup(); 67 | void add_doc_header(); 68 | void add_doc_footer(); 69 | string escape_string(const char *str); 70 | 71 | }; 72 | 73 | #endif /* _REPORT_FORMATTER_HTML_H_ */ 74 | -------------------------------------------------------------------------------- /src/tuning/tunable.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #ifndef _INCLUDE_GUARD_TUNABLE_H 26 | #define _INCLUDE_GUARD_TUNABLE_H 27 | 28 | #include 29 | 30 | #include "../lib.h" 31 | 32 | using namespace std; 33 | 34 | #define TUNE_GOOD 1 35 | #define TUNE_BAD -1 36 | #define TUNE_UNFIXABLE -2 37 | #define TUNE_UNKNOWN 0 38 | #define TUNE_NEUTRAL 0 39 | 40 | class tunable { 41 | 42 | char good_string[128]; 43 | char bad_string[128]; 44 | char neutral_string[128]; 45 | protected: 46 | char toggle_good[4096]; 47 | char toggle_bad[4096]; 48 | public: 49 | char desc[4096]; 50 | double score; 51 | 52 | tunable(void); 53 | tunable(const char *str, double _score, const char *good = "", const char *bad = "", const char *neutral =""); 54 | 55 | void dump_cmd_good(FILE *fp) { 56 | (void) fprintf(fp, "\n### %s\n# %s\n", desc, toggle_good); 57 | } 58 | 59 | virtual ~tunable() {}; 60 | 61 | virtual int good_bad(void) { return TUNE_NEUTRAL; } 62 | 63 | virtual char *result_string(void) 64 | { 65 | switch (good_bad()) { 66 | case TUNE_GOOD: 67 | return good_string; 68 | case TUNE_BAD: 69 | case TUNE_UNFIXABLE: 70 | return bad_string; 71 | } 72 | return neutral_string; 73 | } 74 | 75 | 76 | virtual const char *description(void) { return desc; }; 77 | 78 | virtual void toggle(void) { }; 79 | 80 | virtual const char *toggle_script(void) { return NULL; } 81 | }; 82 | 83 | extern vector all_tunables; 84 | extern vector all_untunables; 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /src/report/report-formatter-csv.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012 Samsung Electronics Co., Ltd. 2 | * http://www.samsung.com/ 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * CSV report generator. 23 | * Written by Igor Zhbanov 24 | * 2012.10 */ 25 | 26 | #ifndef _REPORT_FORMATTER_CSV_H_ 27 | #define _REPORT_FORMATTER_CSV_H_ 28 | 29 | #include 30 | 31 | #include "report-formatter-base.h" 32 | 33 | /* Offices like semicolon separated values instead of comma */ 34 | #define REPORT_CSV_DELIMITER ',' 35 | 36 | /* "a,b,c" vs "a, b, c" */ 37 | /*#define REPORT_CSV_ADD_SPACE*/ 38 | 39 | /* Whether to escape with quotes empty cell values */ 40 | /*#define REPORT_CSV_ESCAPE_EMPTY*/ 41 | 42 | /* Whether to escape with quotes empty cell values with spaces */ 43 | /*#define REPORT_CSV_SPACE_NEED_QUOTES*/ 44 | 45 | using namespace std; 46 | 47 | /* ************************************************************************ */ 48 | 49 | class report_formatter_csv: public report_formatter_string_base 50 | { 51 | public: 52 | report_formatter_csv(); 53 | void finish_report(); 54 | 55 | /* Report Style */ 56 | void add_logo(); 57 | void add_header(); 58 | void end_header(); 59 | void add_div(struct tag_attr *div_attr); 60 | void end_div(); 61 | void add_title(struct tag_attr *title_att, const char *title); 62 | void add_navigation(); 63 | void add_summary_list(string *list, int size); 64 | void add_table(string *system_data, struct table_attributes *tb_attr); 65 | 66 | private: 67 | void add_quotes(); 68 | string escape_string(const char *str); 69 | bool csv_need_quotes; 70 | size_t text_start; 71 | }; 72 | 73 | #endif /* _REPORT_FORMATTER_CSV_H_ */ 74 | -------------------------------------------------------------------------------- /src/devices/ahci.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #ifndef _INCLUDE_GUARD_AHCI_H 26 | #define _INCLUDE_GUARD_AHCI_H 27 | 28 | 29 | #include 30 | #include 31 | #include "device.h" 32 | #include "../parameters/parameters.h" 33 | #include 34 | 35 | class ahci: public device { 36 | uint64_t start_active, end_active; 37 | uint64_t start_partial, end_partial; 38 | uint64_t start_slumber, end_slumber; 39 | uint64_t start_devslp, end_devslp; 40 | char sysfs_path[PATH_MAX]; 41 | char name[4096]; 42 | int partial_rindex; 43 | int active_rindex; 44 | int slumber_rindex; 45 | int devslp_rindex; 46 | int partial_index; 47 | int active_index; 48 | char humanname[4096]; 49 | public: 50 | 51 | ahci(char *_name, char *path); 52 | 53 | virtual void start_measurement(void); 54 | virtual void end_measurement(void); 55 | 56 | virtual double utilization(void); /* percentage */ 57 | 58 | virtual const char * class_name(void) { return "ahci";}; 59 | 60 | virtual const char * device_name(void); 61 | virtual const char * human_name(void) { return humanname;}; 62 | virtual double power_usage(struct result_bundle *result, struct parameter_bundle *bundle); 63 | virtual int power_valid(void) { return utilization_power_valid(partial_rindex) + utilization_power_valid(active_rindex);}; 64 | virtual int grouping_prio(void) { return 1; }; 65 | virtual void report_device_stats(string *ahci_data, int idx); 66 | }; 67 | 68 | extern void create_all_ahcis(void); 69 | extern void ahci_create_device_stats_table(void); 70 | 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /po/Makevars: -------------------------------------------------------------------------------- 1 | # Makefile variables for PO directory in any package using GNU gettext. 2 | 3 | # Usually the message domain is the same as the package name. 4 | DOMAIN = $(PACKAGE) 5 | 6 | # These two variables depend on the location of this directory. 7 | subdir = po 8 | top_builddir = .. 9 | 10 | # These options get passed to xgettext. 11 | XGETTEXT_OPTIONS = --keyword=_ --keyword=N_ --keyword=__ 12 | 13 | # This is the copyright holder that gets inserted into the header of the 14 | # $(DOMAIN).pot file. Set this to the copyright holder of the surrounding 15 | # package. (Note that the msgstr strings, extracted from the package's 16 | # sources, belong to the copyright holder of the package.) Translators are 17 | # expected to transfer the copyright for their translations to this person 18 | # or entity, or to disclaim their copyright. The empty string stands for 19 | # the public domain; in this case the translators are expected to disclaim 20 | # their copyright. 21 | COPYRIGHT_HOLDER = Intel Corporation 22 | 23 | # This is the email address or URL to which the translators shall report 24 | # bugs in the untranslated strings: 25 | # - Strings which are not entire sentences, see the maintainer guidelines 26 | # in the GNU gettext documentation, section 'Preparing Strings'. 27 | # - Strings which use unclear terms or require additional context to be 28 | # understood. 29 | # - Strings which make invalid assumptions about notation of date, time or 30 | # money. 31 | # - Pluralisation problems. 32 | # - Incorrect English spelling. 33 | # - Incorrect formatting. 34 | # It can be your email address, or a mailing list address where translators 35 | # can write to without being subscribed, or the URL of a web page through 36 | # which the translators can contact you. 37 | MSGID_BUGS_ADDRESS = "powertop@lists.01.org" 38 | 39 | # This is the list of locale categories, beyond LC_MESSAGES, for which the 40 | # message catalogs shall be used. It is usually empty. 41 | EXTRA_LOCALE_CATEGORIES = 42 | 43 | # This tells whether the $(DOMAIN).pot file contains messages with an 'msgctxt' 44 | # context. Possible values are "yes" and "no". Set this to yes if the 45 | # package uses functions taking also a message context, like pgettext(), or 46 | # if in $(XGETTEXT_OPTIONS) you define keywords with a context argument. 47 | USE_MSGCTXT = no 48 | 49 | # These options get passed to msgmerge. 50 | # Useful options are in particular: 51 | # --previous to keep previous msgids of translated messages, 52 | # --quiet to reduce the verbosity. 53 | MSGMERGE_OPTIONS = 54 | -------------------------------------------------------------------------------- /src/process/powerconsumer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #ifndef __INCLUDE_GUARD_POWER_CONSUMER_ 26 | #define __INCLUDE_GUARD_POWER_CONSUMER_ 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | using namespace std; 33 | 34 | extern double measurement_time; 35 | 36 | class power_consumer; 37 | 38 | class power_consumer { 39 | 40 | public: 41 | uint64_t accumulated_runtime; 42 | uint64_t child_runtime; 43 | int disk_hits; 44 | int wake_ups; 45 | int gpu_ops; 46 | int hard_disk_hits; /* those which are likely a wakeup of the disk */ 47 | int xwakes; 48 | 49 | double power_charge; /* power consumed by devices opened by this process */ 50 | class power_consumer *waker; 51 | class power_consumer *last_waker; 52 | 53 | power_consumer(void); 54 | virtual ~power_consumer() {}; 55 | 56 | virtual double Witts(void); 57 | virtual const char * description(void) { return ""; }; 58 | 59 | virtual const char * name(void) { return "abstract"; }; 60 | virtual const char * type(void) { return "abstract"; }; 61 | 62 | virtual double usage(void); 63 | virtual const char * usage_units(void); 64 | 65 | virtual double usage_summary(void) { return usage();}; 66 | virtual const char * usage_units_summary(void) { return usage_units(); }; 67 | virtual double events(void) { return (wake_ups + gpu_ops + hard_disk_hits) / measurement_time;}; 68 | virtual int show_events(void) { return 1; }; 69 | }; 70 | 71 | extern vector all_power; 72 | 73 | extern double total_wakeups(void); 74 | extern double total_cpu_time(void); 75 | extern double total_gpu_ops(void); 76 | 77 | 78 | 79 | #endif -------------------------------------------------------------------------------- /src/cpu/cpudevice.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #include "cpudevice.h" 26 | #include 27 | #include 28 | #include 29 | #include "../lib.h" 30 | #include "../parameters/parameters.h" 31 | 32 | 33 | cpudevice::cpudevice(const char *classname, const char *dev_name, class abstract_cpu *_cpu) 34 | { 35 | pt_strcpy(_class, classname); 36 | pt_strcpy(_cpuname, dev_name); 37 | cpu = _cpu; 38 | wake_index = get_param_index("cpu-wakeups");; 39 | consumption_index = get_param_index("cpu-consumption");; 40 | r_wake_index = get_result_index("cpu-wakeups");; 41 | r_consumption_index = get_result_index("cpu-consumption");; 42 | } 43 | 44 | const char * cpudevice::device_name(void) 45 | { 46 | if (child_devices.size()) 47 | return "CPU misc"; 48 | else 49 | return "CPU use"; 50 | } 51 | 52 | double cpudevice::power_usage(struct result_bundle *result, struct parameter_bundle *bundle) 53 | { 54 | double power; 55 | double factor; 56 | double _utilization; 57 | double child_power; 58 | 59 | power = 0; 60 | factor = get_parameter_value(wake_index, bundle); 61 | _utilization = get_result_value(r_wake_index, result); 62 | 63 | power += _utilization * factor / 10000.0; 64 | 65 | factor = get_parameter_value(consumption_index, bundle); 66 | _utilization = get_result_value(r_consumption_index, result); 67 | 68 | power += _utilization * factor; 69 | 70 | for (unsigned int i = 0; i < child_devices.size(); ++i) { 71 | child_power = child_devices[i]->power_usage(result, bundle); 72 | if ((power - child_power) > 0.0) 73 | power -= child_power; 74 | } 75 | 76 | return power; 77 | } 78 | 79 | double cpudevice::utilization(void) 80 | { 81 | double _utilization; 82 | _utilization = get_result_value(r_consumption_index); 83 | 84 | return _utilization * 100; 85 | 86 | } 87 | -------------------------------------------------------------------------------- /src/devices/device.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #ifndef _INCLUDE_GUARD_DEVICE_H 26 | #define _INCLUDE_GUARD_DEVICE_H 27 | 28 | 29 | #include 30 | #include 31 | 32 | struct parameter_bundle; 33 | struct result_bundle; 34 | 35 | class device { 36 | public: 37 | int cached_valid; 38 | bool hide; 39 | 40 | char guilty[4096]; 41 | char real_path[PATH_MAX+1]; 42 | 43 | virtual void start_measurement(void); 44 | virtual void end_measurement(void); 45 | 46 | device(void); 47 | 48 | virtual ~device() {}; 49 | 50 | void register_sysfs_path(const char *path); 51 | 52 | virtual double utilization(void); /* percentage */ 53 | 54 | virtual const char * util_units(void) { return "%"; }; 55 | 56 | virtual const char * class_name(void) { return "abstract device";}; 57 | virtual const char * device_name(void) { return "abstract device";}; 58 | 59 | virtual const char * human_name(void) { return device_name(); }; 60 | 61 | virtual double power_usage(struct result_bundle *results, struct parameter_bundle *bundle) { return 0.0; }; 62 | 63 | virtual bool show_in_list(void) {return !hide;}; 64 | 65 | virtual int power_valid(void) { return 1;}; 66 | 67 | virtual void register_power_with_devlist(struct result_bundle *results, struct parameter_bundle *bundle) { ; }; 68 | 69 | virtual int grouping_prio(void) { return 0; }; /* priority of this device class if multiple classes match to the same underlying device. 0 is lowest */ 70 | }; 71 | 72 | using namespace std; 73 | 74 | extern vector all_devices; 75 | 76 | extern void devices_start_measurement(void); 77 | extern void devices_end_measurement(void); 78 | extern void show_report_devices(void); 79 | extern void report_devices(void); 80 | 81 | 82 | extern void create_all_devices(void); 83 | extern void clear_all_devices(void); 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /src/devices/devfreq.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012, Linaro 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Rajagopal Venkat 24 | */ 25 | #ifndef _INCLUDE_GUARD_DEVFREQ_H 26 | #define _INCLUDE_GUARD_DEVFREQ_H 27 | 28 | #include "device.h" 29 | #include "../parameters/parameters.h" 30 | #include 31 | 32 | struct frequency; 33 | 34 | class devfreq: public device { 35 | char dir_name[128]; 36 | struct timeval stamp_before, stamp_after; 37 | double sample_time; 38 | 39 | uint64_t parse_freq_time(char *ptr); 40 | void add_devfreq_freq_state(uint64_t freq, uint64_t time); 41 | void update_devfreq_freq_state(uint64_t freq, uint64_t time); 42 | void parse_devfreq_trans_stat(char *dname); 43 | void process_time_stamps(); 44 | 45 | public: 46 | 47 | vector dstates; 48 | 49 | devfreq(const char *c); 50 | void fill_freq_utilization(unsigned int idx, char *buf); 51 | void fill_freq_name(unsigned int idx, char *buf); 52 | 53 | virtual void start_measurement(void); 54 | virtual void end_measurement(void); 55 | 56 | virtual double utilization(void); /* percentage */ 57 | 58 | virtual const char * class_name(void) { return "devfreq";}; 59 | 60 | virtual const char * device_name(void) { return dir_name;}; 61 | virtual const char * human_name(void) { return "devfreq";}; 62 | virtual double power_usage(struct result_bundle *result, struct parameter_bundle *bundle); 63 | virtual const char * util_units(void) { return " rpm"; }; 64 | virtual int power_valid(void) { return 0; /*utilization_power_valid(r_index);*/}; 65 | virtual int grouping_prio(void) { return 1; }; 66 | }; 67 | 68 | extern void create_all_devfreq_devices(void); 69 | extern void clear_all_devfreq(void); 70 | extern void display_devfreq_devices(void); 71 | extern void report_devfreq_devices(void); 72 | extern void initialize_devfreq(void); 73 | extern void start_devfreq_measurement(void); 74 | extern void end_devfreq_measurement(void); 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /src/devices/network.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #ifndef _INCLUDE_GUARD_NETWORK_H 26 | #define _INCLUDE_GUARD_NETWORK_H 27 | 28 | #include 29 | #include 30 | 31 | #include "device.h" 32 | #include "../parameters/parameters.h" 33 | 34 | class network: public device { 35 | int start_up, end_up; 36 | uint64_t start_pkts, end_pkts; 37 | struct timeval before, after; 38 | 39 | int start_speed; /* 0 is "no link" */ 40 | int end_speed; /* 0 is "no link" */ 41 | 42 | char sysfs_path[PATH_MAX]; 43 | char name[4096]; 44 | char humanname[4096]; 45 | int index_up; 46 | int rindex_up; 47 | int index_link_100; 48 | int rindex_link_100; 49 | int index_link_1000; 50 | int rindex_link_1000; 51 | int index_link_high; 52 | int rindex_link_high; 53 | int index_pkts; 54 | int rindex_pkts; 55 | int index_powerunsave; 56 | int rindex_powerunsave; 57 | 58 | int valid_100; 59 | int valid_1000; 60 | int valid_high; 61 | int valid_powerunsave; 62 | public: 63 | uint64_t pkts; 64 | double duration; 65 | 66 | network(const char *_name, const char *path); 67 | 68 | virtual void start_measurement(void); 69 | virtual void end_measurement(void); 70 | 71 | virtual double utilization(void); 72 | virtual const char * util_units(void) { return " pkts/s"; }; 73 | 74 | virtual const char * class_name(void) { return "ethernet";}; 75 | 76 | virtual const char * device_name(void); 77 | virtual const char * human_name(void) { return humanname; }; 78 | virtual double power_usage(struct result_bundle *result, struct parameter_bundle *bundle); 79 | virtual int power_valid(void) { return utilization_power_valid(rindex_up) + utilization_power_valid(rindex_link_100) + utilization_power_valid(rindex_link_1000) + utilization_power_valid(rindex_link_high);}; 80 | virtual int grouping_prio(void) { return 10; }; 81 | }; 82 | 83 | extern void create_all_nics(callback fn = NULL); 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /src/cpu/cpu_core.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #include 26 | #include "cpu.h" 27 | #include "../lib.h" 28 | 29 | #include "../parameters/parameters.h" 30 | 31 | char * cpu_core::fill_cstate_line(int line_nr, char *buffer, const char *separator) 32 | { 33 | unsigned int i; 34 | buffer[0] = 0; 35 | 36 | if (line_nr == LEVEL_HEADER) 37 | sprintf(buffer, this->has_intel_MSR ? _(" Core(HW)"): _(" Core(OS)")); 38 | 39 | for (i = 0; i < cstates.size(); i++) { 40 | if (cstates[i]->line_level != line_nr) 41 | continue; 42 | sprintf(buffer,"%5.1f%%", percentage(cstates[i]->duration_delta / time_factor)); 43 | } 44 | 45 | return buffer; 46 | } 47 | 48 | 49 | char * cpu_core::fill_cstate_name(int line_nr, char *buffer) 50 | { 51 | unsigned int i; 52 | buffer[0] = 0; 53 | 54 | for (i = 0; i < cstates.size(); i++) { 55 | if (cstates[i]->line_level != line_nr) 56 | continue; 57 | 58 | sprintf(buffer,"%s", cstates[i]->human_name); 59 | } 60 | 61 | return buffer; 62 | } 63 | 64 | 65 | 66 | char * cpu_core::fill_pstate_name(int line_nr, char *buffer) 67 | { 68 | buffer[0] = 0; 69 | 70 | if (line_nr >= (int)pstates.size() || line_nr < 0) 71 | return buffer; 72 | 73 | sprintf(buffer,"%s", pstates[line_nr]->human_name); 74 | 75 | return buffer; 76 | } 77 | 78 | char * cpu_core::fill_pstate_line(int line_nr, char *buffer) 79 | { 80 | buffer[0] = 0; 81 | unsigned int i; 82 | 83 | if (total_stamp ==0) { 84 | for (i = 0; i < pstates.size(); i++) 85 | total_stamp += pstates[i]->time_after; 86 | if (total_stamp == 0) 87 | total_stamp = 1; 88 | } 89 | 90 | if (line_nr == LEVEL_HEADER) { 91 | sprintf(buffer,_(" Core")); 92 | return buffer; 93 | } 94 | 95 | if (line_nr >= (int)pstates.size() || line_nr < 0) 96 | return buffer; 97 | 98 | sprintf(buffer," %5.1f%% ", percentage(1.0* (pstates[line_nr]->time_after) / total_stamp)); 99 | return buffer; 100 | } 101 | -------------------------------------------------------------------------------- /src/tuning/wifi.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | 26 | #include "tuning.h" 27 | #include "tunable.h" 28 | #include "unistd.h" 29 | #include "wifi.h" 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #include "../lib.h" 39 | 40 | extern "C" { 41 | #include "iw.h" 42 | } 43 | 44 | 45 | wifi_tunable::wifi_tunable(const char *_iface) : tunable("", 1.5, _("Good"), _("Bad"), _("Unknown")) 46 | { 47 | pt_strcpy(iface, _iface); 48 | sprintf(desc, _("Wireless Power Saving for interface %s"), iface); 49 | 50 | snprintf(toggle_good, sizeof(toggle_good), "iw dev %s set power_save on", iface); 51 | snprintf(toggle_bad, sizeof(toggle_bad), "iw dev %s set power_save off", iface); 52 | } 53 | 54 | int wifi_tunable::good_bad(void) 55 | { 56 | if (get_wifi_power_saving(iface)) 57 | return TUNE_GOOD; 58 | 59 | return TUNE_BAD; 60 | } 61 | 62 | void wifi_tunable::toggle(void) 63 | { 64 | int good; 65 | good = good_bad(); 66 | 67 | if (good == TUNE_GOOD) { 68 | set_wifi_power_saving(iface, 0); 69 | return; 70 | } 71 | 72 | set_wifi_power_saving(iface, 1); 73 | } 74 | 75 | const char *wifi_tunable::toggle_script(void) 76 | { 77 | int good; 78 | good = good_bad(); 79 | 80 | if (good == TUNE_GOOD) { 81 | return toggle_bad; 82 | } 83 | 84 | return toggle_good; 85 | } 86 | 87 | void add_wifi_tunables(void) 88 | { 89 | struct dirent *entry; 90 | DIR *dir; 91 | char* wlan_name; 92 | class wifi_tunable *wifi; 93 | 94 | 95 | dir = opendir("/sys/class/net/"); 96 | if (!dir) 97 | return; 98 | while (1) { 99 | entry = readdir(dir); 100 | if (!entry) 101 | break; 102 | wlan_name = strstr(entry->d_name, "wlan"); 103 | if (wlan_name) { 104 | wifi = new class wifi_tunable(wlan_name); 105 | all_tunables.push_back(wifi); 106 | } 107 | 108 | } 109 | 110 | closedir(dir); 111 | 112 | } 113 | -------------------------------------------------------------------------------- /src/display.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #ifndef __INCLUDE_GUARD_DISPLAY_H_ 26 | #define __INCLUDE_GUARD_DISPLAY_H_ 27 | 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | using namespace std; 34 | 35 | extern void init_display(void); 36 | extern void reset_display(void); 37 | extern int ncurses_initialized(void); 38 | extern void show_tab(unsigned int tab); 39 | extern void show_next_tab(void); 40 | extern void show_prev_tab(void); 41 | extern void show_cur_tab(void); 42 | extern void cursor_up(void); 43 | extern void cursor_down(void); 44 | extern void cursor_right(void); 45 | extern void cursor_left(void); 46 | extern void cursor_enter(void); 47 | extern void window_refresh(void); 48 | 49 | class tab_window { 50 | public: 51 | int cursor_pos; 52 | int cursor_max; 53 | short int xpad_pos, ypad_pos; 54 | WINDOW *win; 55 | 56 | tab_window() { 57 | cursor_pos = 0; 58 | cursor_max = 0; 59 | xpad_pos =0; 60 | ypad_pos = 0; 61 | win = NULL; 62 | } 63 | 64 | virtual void cursor_down(void) { 65 | if (cursor_pos < cursor_max) 66 | cursor_pos++; 67 | repaint(); 68 | } ; 69 | virtual void cursor_up(void) { 70 | if (cursor_pos > 0) 71 | cursor_pos--; 72 | repaint(); 73 | }; 74 | virtual void cursor_left(void) { }; 75 | virtual void cursor_right(void) { }; 76 | 77 | virtual void cursor_enter(void) { }; 78 | virtual void window_refresh() { }; 79 | 80 | virtual void repaint(void) { }; 81 | virtual void expose(void) { cursor_pos = 0; repaint();}; 82 | virtual void hide(void) { }; 83 | 84 | virtual ~tab_window() 85 | { 86 | delwin(win); 87 | win = NULL; 88 | } 89 | }; 90 | 91 | extern map tab_windows; 92 | 93 | WINDOW *get_ncurses_win(const char *name); 94 | WINDOW *get_ncurses_win(const string &name); 95 | WINDOW *get_ncurses_win(int nr); 96 | 97 | void create_tab(const string &name, const string &translation, class tab_window *w = NULL, string bottom_line = ""); 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /src/process/process.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #ifndef _INCLUDE_GUARD_PROCESS_H 26 | #define _INCLUDE_GUARD_PROCESS_H 27 | 28 | #include 29 | 30 | #include "powerconsumer.h" 31 | 32 | #ifdef __x86_64__ 33 | #define BIT64 1 34 | #endif 35 | 36 | /* 37 | Need to collect 38 | * CPU time consumed by each application 39 | * Number of wakeups out of idle -- received and wakeups sent 40 | * Number of disk dirties (inode for now) 41 | */ 42 | class process : public power_consumer { 43 | uint64_t running_since; 44 | public: 45 | char desc[256]; 46 | int tgid; 47 | char comm[16]; 48 | int pid; 49 | 50 | 51 | int is_idle; /* count this as if the cpu was idle */ 52 | int running; 53 | int is_kernel; /* kernel thread */ 54 | 55 | process(const char *_comm, int _pid, int _tid = 0); 56 | 57 | virtual void schedule_thread(uint64_t time, int thread_id); 58 | virtual uint64_t deschedule_thread(uint64_t time, int thread_id = 0); 59 | 60 | virtual void account_disk_dirty(void); 61 | 62 | virtual const char * description(void); 63 | virtual const char * name(void) { return "process"; }; 64 | virtual const char * type(void) { return "Process"; }; 65 | 66 | virtual double usage_summary(void); 67 | virtual const char * usage_units_summary(void); 68 | 69 | }; 70 | 71 | extern vector all_processes; 72 | 73 | extern double measurement_time; 74 | 75 | 76 | extern void start_process_measurement(void); 77 | extern void end_process_measurement(void); 78 | extern void process_process_data(void); 79 | extern void end_process_data(void); 80 | extern void clear_process_data(void); 81 | extern void merge_processes(void); 82 | 83 | extern class process * find_create_process(const char *comm, int pid); 84 | extern class process * find_create_process(char *comm, int pid); 85 | extern void all_processes_to_all_power(void); 86 | 87 | extern void clear_processes(void); 88 | extern void process_update_display(void); 89 | extern void report_process_update_display(void); 90 | extern void report_summary(void); 91 | 92 | 93 | 94 | extern void clear_timers(void); 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /src/process/powerconsumer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | 26 | #include "powerconsumer.h" 27 | #include "process.h" 28 | #include "../parameters/parameters.h" 29 | 30 | double power_consumer::Witts(void) 31 | { 32 | double cost; 33 | double timecost; 34 | double wakeupcost; 35 | double gpucost; 36 | double disk_cost; 37 | double hard_disk_cost; 38 | double xwake_cost; 39 | 40 | if (child_runtime > accumulated_runtime) 41 | child_runtime = 0; 42 | 43 | timecost = get_parameter_value("cpu-consumption"); 44 | wakeupcost = get_parameter_value("cpu-wakeups"); 45 | gpucost = get_parameter_value("gpu-operations"); 46 | disk_cost = get_parameter_value("disk-operations"); 47 | hard_disk_cost = get_parameter_value("disk-operations-hard"); 48 | xwake_cost = get_parameter_value("xwakes"); 49 | 50 | cost = 0; 51 | 52 | cost += wakeupcost * wake_ups / 10000.0; 53 | cost += ( (accumulated_runtime - child_runtime) / 1000000000.0) * timecost; 54 | cost += gpucost * gpu_ops / 100.0; 55 | cost += hard_disk_cost * hard_disk_hits / 100.0; 56 | cost += disk_cost * disk_hits / 100.0; 57 | cost += xwake_cost * xwakes / 100.0; 58 | 59 | cost = cost / measurement_time; 60 | 61 | cost += power_charge; 62 | 63 | return cost; 64 | } 65 | 66 | power_consumer::power_consumer(void) 67 | { 68 | accumulated_runtime = 0; 69 | child_runtime = 0; 70 | disk_hits = 0; 71 | wake_ups = 0; 72 | gpu_ops = 0; 73 | hard_disk_hits = 0; 74 | xwakes = 0; 75 | waker = NULL; 76 | last_waker = NULL; 77 | power_charge = 0.0; 78 | } 79 | 80 | double power_consumer::usage(void) 81 | { 82 | double t; 83 | t = (accumulated_runtime - child_runtime) / 1000000.0 / measurement_time; 84 | if (t < 0.7) 85 | t = t * 1000; 86 | return t; 87 | } 88 | 89 | const char * power_consumer::usage_units(void) 90 | { 91 | double t; 92 | t = (accumulated_runtime - child_runtime) / 1000000.0 / measurement_time; 93 | if (t < 0.7) { 94 | if (utf_ok) 95 | return " µs/s"; 96 | else 97 | return " us/s"; 98 | } 99 | return " ms/s"; 100 | } 101 | -------------------------------------------------------------------------------- /src/process/processdevice.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #include "processdevice.h" 26 | #include "../parameters/parameters.h" 27 | #include 28 | 29 | vector all_proc_devices; 30 | 31 | 32 | device_consumer::device_consumer(class device *dev) : power_consumer() 33 | { 34 | device = dev; 35 | power = device->power_usage(&all_results, &all_parameters); 36 | prio = dev->grouping_prio(); 37 | } 38 | 39 | 40 | const char * device_consumer::description(void) 41 | { 42 | snprintf(str, sizeof(str), "%s", device->human_name()); 43 | return str; 44 | } 45 | 46 | double device_consumer::Witts(void) 47 | { 48 | return power; 49 | } 50 | 51 | static void add_device(class device *device) 52 | { 53 | class device_consumer *dev; 54 | unsigned int i; 55 | 56 | /* first check if we want to be shown at all */ 57 | 58 | if (device->show_in_list() == 0) 59 | return; 60 | 61 | /* then check if a device with the same underlying object is already registered */ 62 | for (i = 0; i < all_proc_devices.size(); i++) { 63 | class device_consumer *cdev; 64 | cdev = all_proc_devices[i]; 65 | if (device->real_path[0] != 0 && strcmp(cdev->device->real_path, device->real_path) == 0) { 66 | /* we have a device with the same underlying object */ 67 | 68 | /* aggregate the power */ 69 | cdev->power += device->power_usage(&all_results, &all_parameters); 70 | 71 | if (cdev->prio < device->grouping_prio()) { 72 | cdev->device = device; 73 | cdev->prio = device->grouping_prio(); 74 | } 75 | 76 | return; 77 | } 78 | } 79 | 80 | dev = new class device_consumer(device); 81 | all_power.push_back(dev); 82 | all_proc_devices.push_back(dev); 83 | } 84 | 85 | void all_devices_to_all_power(void) 86 | { 87 | unsigned int i; 88 | for (i = 0; i < all_devices.size(); i++) 89 | add_device(all_devices[i]); 90 | } 91 | 92 | void clear_proc_devices(void) 93 | { 94 | std::vector::iterator it = all_proc_devices.begin(); 95 | while (it != all_proc_devices.end()) { 96 | delete *it; 97 | it = all_proc_devices.erase(it); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/cpu/rapl/rapl_interface.h: -------------------------------------------------------------------------------- 1 | /* rapl_interface.h: rapl interface for power top 2 | * 3 | * Copyright (C) 2012 Intel Corporation. All rights reserved. 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License version 7 | * 2 as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 | * 02110-1301, USA. 18 | * 19 | * 20 | * Author Name 21 | * 22 | */ 23 | 24 | #ifndef RAPL_INTERFACE_H 25 | #define RAPL_INTERFACE_H 26 | 27 | class c_rapl_interface 28 | { 29 | private: 30 | static const int def_sampling_interval = 1; //In seconds 31 | bool powercap_sysfs_present; 32 | string powercap_core_path; 33 | string powercap_uncore_path; 34 | string powercap_dram_path; 35 | 36 | unsigned char rapl_domains; 37 | int first_cpu; 38 | 39 | double power_units; 40 | double energy_status_units; 41 | double time_units; 42 | 43 | int read_msr(int cpu, unsigned int idx, uint64_t *val); 44 | int write_msr(int cpu, unsigned int idx, uint64_t val); 45 | 46 | protected: 47 | int measurment_interval; 48 | double last_pkg_energy_status; 49 | double last_dram_energy_status; 50 | double last_pp0_energy_status; 51 | double last_pp1_energy_status; 52 | 53 | public: 54 | c_rapl_interface(const char *dev_name = "package-0", int cpu = 0); 55 | 56 | int get_rapl_power_unit(uint64_t *value); 57 | double get_power_unit(); 58 | double get_energy_status_unit(); 59 | double get_time_unit(); 60 | 61 | int get_pkg_energy_status(double *status); 62 | int get_pkg_power_info(double *thermal_spec_power, 63 | double *max_power, double *min_power, double *max_time_window); 64 | int get_pkg_power_limit(uint64_t *value); 65 | int set_pkg_power_limit(uint64_t value); 66 | 67 | int get_dram_energy_status(double *status); 68 | int get_dram_power_info(double *thermal_spec_power, 69 | double *max_power, double *min_power, double *max_time_window); 70 | int get_dram_power_limit(uint64_t *value); 71 | int set_dram_power_limit(uint64_t value); 72 | 73 | int get_pp0_energy_status(double *status); 74 | int get_pp0_power_limit(uint64_t *value); 75 | int set_pp0_power_limit(uint64_t value); 76 | int get_pp0_power_policy(unsigned int *pp0_power_policy); 77 | 78 | int get_pp1_energy_status(double *status); 79 | int get_pp1_power_limit(uint64_t *value); 80 | int set_pp1_power_limit(uint64_t value); 81 | int get_pp1_power_policy(unsigned int *pp1_power_policy); 82 | 83 | bool pkg_domain_present(); 84 | bool dram_domain_present(); 85 | bool pp0_domain_present(); 86 | bool pp1_domain_present(); 87 | 88 | void rapl_measure_energy(); 89 | }; 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /src/report/report-formatter-base.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012 Samsung Electronics Co., Ltd. 2 | * http://www.samsung.com/ 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Common part of report_formatter_csv and report_formatter_html. 23 | * Written by Igor Zhbanov 24 | * 2012.10 */ 25 | 26 | /* Uncomment to disable asserts */ 27 | /*#define NDEBUG*/ 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #include "report-formatter-base.h" 34 | 35 | /* ************************************************************************ */ 36 | 37 | const char * 38 | report_formatter_string_base::get_result() 39 | { 40 | return result.c_str(); 41 | } 42 | 43 | /* ************************************************************************ */ 44 | 45 | void 46 | report_formatter_string_base::clear_result() 47 | { 48 | result.clear(); 49 | } 50 | 51 | /* ************************************************************************ */ 52 | 53 | void 54 | report_formatter_string_base::add(const char *str) 55 | { 56 | assert(str); 57 | 58 | result += escape_string(str); 59 | } 60 | 61 | /* ************************************************************************ */ 62 | 63 | void 64 | report_formatter_string_base::add_exact(const char *str) 65 | { 66 | assert(str); 67 | 68 | result += std::string(str); 69 | } 70 | 71 | /* ************************************************************************ */ 72 | 73 | #define LINE_SIZE 8192 74 | 75 | void 76 | report_formatter_string_base::addv(const char *fmt, va_list ap) 77 | { 78 | char str[LINE_SIZE]; 79 | 80 | assert(fmt); 81 | 82 | vsnprintf(str, sizeof(str), fmt, ap); 83 | add(str); 84 | } 85 | 86 | /* ************************************************************************ */ 87 | 88 | void 89 | report_formatter_string_base::addf(const char *fmt, ...) 90 | { 91 | va_list ap; 92 | 93 | assert(fmt); 94 | 95 | va_start(ap, fmt); 96 | addv(fmt, ap); 97 | va_end(ap); 98 | } 99 | 100 | /* ************************************************************************ */ 101 | 102 | void 103 | report_formatter_string_base::addf_exact(const char *fmt, ...) 104 | { 105 | char str[LINE_SIZE]; 106 | va_list ap; 107 | 108 | assert(fmt); 109 | 110 | va_start(ap, fmt); 111 | vsnprintf(str, sizeof(str), fmt, ap); 112 | add_exact(str); 113 | va_end(ap); 114 | } 115 | -------------------------------------------------------------------------------- /src/lib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #ifndef INCLUDE_GUARD_LIB_H 26 | #define INCLUDE_GUARD_LIB_H 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | /* Include only for Automake builds */ 34 | #ifdef HAVE_CONFIG_H 35 | #include "config.h" 36 | #endif 37 | 38 | #ifdef ENABLE_NLS 39 | #define _(STRING) gettext(STRING) 40 | #else 41 | #define _(STRING) (STRING) 42 | #endif 43 | 44 | extern int is_turbo(uint64_t freq, uint64_t max, uint64_t maxmo); 45 | 46 | extern int get_max_cpu(void); 47 | extern void set_max_cpu(int cpu); 48 | 49 | extern double percentage(double F); 50 | extern char *hz_to_human(unsigned long hz, char *buffer, int digits = 2); 51 | 52 | 53 | extern const char *kernel_function(uint64_t address); 54 | 55 | 56 | 57 | #include 58 | #include 59 | using namespace std; 60 | 61 | extern void write_sysfs(const string &filename, const string &value); 62 | extern int read_sysfs(const string &filename, bool *ok = NULL); 63 | extern string read_sysfs_string(const string &filename); 64 | extern string read_sysfs_string(const char *format, const char *param); 65 | 66 | extern void format_watts(double W, char *buffer, unsigned int len); 67 | 68 | extern char *pci_id_to_name(uint16_t vendor, uint16_t device, char *buffer, int len); 69 | extern void end_pci_access(void); 70 | 71 | 72 | extern char *fmt_prefix(double n, char *buf); 73 | extern char *pretty_print(const char *str, char *buf, int len); 74 | extern int equals(double a, double b); 75 | 76 | template void pt_strcpy(char (&d)[N], const char *s) 77 | { 78 | strncpy(d, s, N); 79 | d[N-1] = '\0'; 80 | } 81 | 82 | typedef void (*callback)(const char*); 83 | extern void process_directory(const char *d_name, callback fn); 84 | extern void process_glob(const char *glob, callback fn); 85 | extern int utf_ok; 86 | extern int get_user_input(char *buf, unsigned sz); 87 | extern int read_msr(int cpu, uint64_t offset, uint64_t *value); 88 | extern int write_msr(int cpu, uint64_t offset, uint64_t value); 89 | 90 | extern void align_string(char *buffer, size_t min_sz, size_t max_sz); 91 | 92 | extern void ui_notify_user_ncurses(const char *frmt, ...); 93 | extern void ui_notify_user_console(const char *frmt, ...); 94 | extern void (*ui_notify_user) (const char *frmt, ...); 95 | #endif 96 | -------------------------------------------------------------------------------- /src/cpu/cpu_package.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #include 26 | #include "cpu.h" 27 | #include "../lib.h" 28 | #include "../parameters/parameters.h" 29 | 30 | void cpu_package::freq_updated(uint64_t time) 31 | { 32 | if (parent) 33 | parent->calculate_freq(time); 34 | /* 35 | * Make the frequency changes to propagate to all cores in a package. 36 | */ 37 | change_effective_frequency(time, current_frequency); 38 | old_idle = idle; 39 | } 40 | 41 | char * cpu_package::fill_cstate_line(int line_nr, char *buffer, const char *separator) 42 | { 43 | unsigned int i; 44 | buffer[0] = 0; 45 | 46 | if (line_nr == LEVEL_HEADER) { 47 | sprintf(buffer, this->has_intel_MSR ? _(" Pkg(HW)"): _(" Pkg(OS)")); 48 | } 49 | 50 | for (i = 0; i < cstates.size(); i++) { 51 | if (cstates[i]->line_level != line_nr) 52 | continue; 53 | 54 | sprintf(buffer,"%5.1f%%", percentage(cstates[i]->duration_delta / time_factor)); 55 | } 56 | 57 | return buffer; 58 | } 59 | 60 | 61 | char * cpu_package::fill_cstate_name(int line_nr, char *buffer) 62 | { 63 | unsigned int i; 64 | buffer[0] = 0; 65 | 66 | for (i = 0; i < cstates.size(); i++) { 67 | if (cstates[i]->line_level != line_nr) 68 | continue; 69 | 70 | sprintf(buffer,"%s", cstates[i]->human_name); 71 | } 72 | 73 | return buffer; 74 | } 75 | 76 | 77 | 78 | char * cpu_package::fill_pstate_name(int line_nr, char *buffer) 79 | { 80 | buffer[0] = 0; 81 | 82 | if (line_nr >= (int)pstates.size() || line_nr < 0) 83 | return buffer; 84 | 85 | sprintf(buffer,"%s", pstates[line_nr]->human_name); 86 | 87 | return buffer; 88 | } 89 | 90 | char * cpu_package::fill_pstate_line(int line_nr, char *buffer) 91 | { 92 | buffer[0] = 0; 93 | unsigned int i; 94 | 95 | if (total_stamp ==0) { 96 | for (i = 0; i < pstates.size(); i++) 97 | total_stamp += pstates[i]->time_after; 98 | if (total_stamp == 0) 99 | total_stamp = 1; 100 | } 101 | 102 | 103 | if (line_nr == LEVEL_HEADER) { 104 | sprintf(buffer,_(" Package")); 105 | return buffer; 106 | } 107 | 108 | if (line_nr >= (int)pstates.size() || line_nr < 0) 109 | return buffer; 110 | 111 | sprintf(buffer," %5.1f%% ", percentage(1.0* (pstates[line_nr]->time_after) / total_stamp)); 112 | return buffer; 113 | } 114 | -------------------------------------------------------------------------------- /src/devices/thinkpad-light.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #include "../lib.h" 36 | 37 | 38 | #include "device.h" 39 | #include "thinkpad-light.h" 40 | #include "../parameters/parameters.h" 41 | #include "../process/powerconsumer.h" 42 | 43 | #include 44 | #include 45 | 46 | thinkpad_light::thinkpad_light(): device() 47 | { 48 | start_rate = 0; 49 | end_rate = 0; 50 | light_index = get_param_index("thinkpad-light"); 51 | r_index = get_result_index("thinkpad-light"); 52 | register_sysfs_path("/sys/devices/platform/thinkpad_acpi/leds/tpacpi::thinklight"); 53 | } 54 | 55 | void thinkpad_light::start_measurement(void) 56 | { 57 | /* read the rpms of the light */ 58 | start_rate = read_sysfs("/sys/devices/platform/thinkpad_acpi/leds/tpacpi::thinklight/brightness"); 59 | } 60 | 61 | void thinkpad_light::end_measurement(void) 62 | { 63 | end_rate = read_sysfs("/sys/devices/platform/thinkpad_acpi/leds/tpacpi::thinklight/brightness"); 64 | 65 | report_utilization("thinkpad-light", utilization()); 66 | } 67 | 68 | 69 | double thinkpad_light::utilization(void) 70 | { 71 | return (start_rate+end_rate) / 2.55 / 2.0; 72 | } 73 | 74 | void create_thinkpad_light(void) 75 | { 76 | char filename[PATH_MAX]; 77 | class thinkpad_light *light; 78 | 79 | pt_strcpy(filename, "/sys/devices/platform/thinkpad_acpi/leds/tpacpi::thinklight/brightness"); 80 | 81 | if (access(filename, R_OK) !=0) 82 | return; 83 | 84 | register_parameter("thinkpad-light", 10); 85 | 86 | light = new class thinkpad_light(); 87 | all_devices.push_back(light); 88 | } 89 | 90 | 91 | 92 | double thinkpad_light::power_usage(struct result_bundle *result, struct parameter_bundle *bundle) 93 | { 94 | double power; 95 | double factor; 96 | double util; 97 | 98 | 99 | power = 0; 100 | util = get_result_value(r_index, result); 101 | 102 | if (util < 0) 103 | util = 0; 104 | 105 | 106 | factor = get_parameter_value(light_index, bundle) - 10.0; 107 | power += util / 100.0 * factor; 108 | 109 | if (power <= 0.0) 110 | power = 0.0; 111 | 112 | return power; 113 | } 114 | -------------------------------------------------------------------------------- /src/devices/i915-gpu.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include "../lib.h" 34 | 35 | using namespace std; 36 | 37 | #include "device.h" 38 | #include "i915-gpu.h" 39 | #include "../parameters/parameters.h" 40 | #include "../process/powerconsumer.h" 41 | #include "gpu_rapl_device.h" 42 | 43 | extern "C" { 44 | #include 45 | #include 46 | #include 47 | } 48 | 49 | i915gpu::i915gpu(): device() 50 | { 51 | index = get_param_index("gpu-operations"); 52 | rindex = get_result_index("gpu-operations"); 53 | } 54 | 55 | const char * i915gpu::device_name(void) 56 | { 57 | if (child_devices.size()) 58 | return "GPU misc"; 59 | else 60 | return "GPU"; 61 | } 62 | 63 | void i915gpu::start_measurement(void) 64 | { 65 | } 66 | 67 | void i915gpu::end_measurement(void) 68 | { 69 | } 70 | 71 | 72 | double i915gpu::utilization(void) 73 | { 74 | return get_result_value(rindex); 75 | 76 | } 77 | 78 | void create_i915_gpu(void) 79 | { 80 | class i915gpu *gpu; 81 | gpu_rapl_device *rapl_dev; 82 | 83 | if (!tracefs_event_file_exists(NULL, "i915", "i915_gem_ring_dispatch", "format")) { 84 | /* try an older tracepoint */ 85 | if (!tracefs_event_file_exists(NULL, "i915", "i915_gem_request_submit", "format")) 86 | return; 87 | } 88 | 89 | register_parameter("gpu-operations"); 90 | 91 | gpu = new class i915gpu(); 92 | all_devices.push_back(gpu); 93 | 94 | rapl_dev = new class gpu_rapl_device(gpu); 95 | if (rapl_dev->device_present()) 96 | all_devices.push_back(rapl_dev); 97 | } 98 | 99 | 100 | 101 | double i915gpu::power_usage(struct result_bundle *result, struct parameter_bundle *bundle) 102 | { 103 | double power; 104 | double factor; 105 | double util; 106 | double child_power; 107 | 108 | power = 0; 109 | factor = get_parameter_value(index, bundle); 110 | util = get_result_value(rindex, result); 111 | 112 | power += util * factor / 100.0; 113 | for (unsigned int i = 0; i < child_devices.size(); ++i) { 114 | child_power = child_devices[i]->power_usage(result, bundle); 115 | if ((power - child_power) > 0.0) 116 | power -= child_power; 117 | } 118 | 119 | return power; 120 | } 121 | -------------------------------------------------------------------------------- /src/process/work.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #include "work.h" 33 | #include "../lib.h" 34 | #include "process.h" 35 | 36 | using namespace std; 37 | 38 | 39 | work::work(unsigned long address) : power_consumer() 40 | { 41 | pt_strcpy(handler, kernel_function(address)); 42 | raw_count = 0; 43 | snprintf(desc, sizeof(desc), "%s", handler); 44 | } 45 | 46 | 47 | static map all_work; 48 | static map running_since; 49 | 50 | void work::fire(uint64_t time, uint64_t work_struct) 51 | { 52 | running_since[work_struct] = time; 53 | } 54 | 55 | uint64_t work::done(uint64_t time, uint64_t work_struct) 56 | { 57 | int64_t delta; 58 | 59 | if (running_since.find(work_struct) == running_since.end()) 60 | return ~0ULL; 61 | 62 | if (running_since[work_struct] > time) 63 | return 0; 64 | 65 | delta = time - running_since[work_struct]; 66 | 67 | accumulated_runtime += delta; 68 | 69 | raw_count++; 70 | 71 | return delta; 72 | } 73 | 74 | double work::usage_summary(void) 75 | { 76 | double t; 77 | t = (accumulated_runtime - child_runtime) / 1000000.0 / measurement_time / 10; 78 | return t; 79 | } 80 | 81 | const char * work::usage_units_summary(void) 82 | { 83 | return "%"; 84 | } 85 | 86 | 87 | 88 | 89 | static void add_work(const pair& elem) 90 | { 91 | all_power.push_back(elem.second); 92 | } 93 | 94 | void all_work_to_all_power(void) 95 | { 96 | for_each(all_work.begin(), all_work.end(), add_work); 97 | 98 | } 99 | 100 | void clear_work(void) 101 | { 102 | std::map::iterator it = all_work.begin(); 103 | while (it != all_work.end()) { 104 | delete it->second; 105 | all_work.erase(it); 106 | it = all_work.begin(); 107 | } 108 | running_since.clear(); 109 | } 110 | 111 | 112 | const char * work::description(void) 113 | { 114 | if (child_runtime > accumulated_runtime) 115 | child_runtime = 0; 116 | 117 | return desc; 118 | } 119 | 120 | 121 | class work * find_create_work(uint64_t func) 122 | { 123 | class work * work; 124 | if (all_work.find(func) != all_work.end()) 125 | return all_work[func]; 126 | 127 | work = new class work(func); 128 | all_work[func] = work; 129 | return work; 130 | } 131 | -------------------------------------------------------------------------------- /src/wakeup/wakeup_usb.cpp: -------------------------------------------------------------------------------- 1 | ;/* 2 | * Copyright 2018, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Gayatri Kammela 24 | */ 25 | 26 | #include "wakeup.h" 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | #include 43 | 44 | #include "../lib.h" 45 | #include "wakeup_usb.h" 46 | 47 | usb_wakeup::usb_wakeup(const char *path, const char *iface) : wakeup("", 0.5, _("Enabled"), _("Disabled")) 48 | { 49 | memset(interf, 0, sizeof(interf)); 50 | pt_strcpy(interf, iface); 51 | sprintf(desc, _("Wake status for USB device %s"), iface); 52 | snprintf(usb_path, sizeof(usb_path), "/sys/bus/usb/devices/%s/power/wakeup", iface); 53 | snprintf(toggle_enable, sizeof(toggle_enable), "echo 'enabled' > '%s';", usb_path); 54 | snprintf(toggle_disable, sizeof(toggle_disable), "echo 'disabled' > '%s';", usb_path); 55 | } 56 | 57 | int usb_wakeup::wakeup_value(void) 58 | { 59 | string content; 60 | 61 | content = read_sysfs_string(usb_path); 62 | 63 | if (strcmp(content.c_str(), "enabled") == 0) 64 | return WAKEUP_ENABLE; 65 | 66 | return WAKEUP_DISABLE; 67 | } 68 | 69 | void usb_wakeup::wakeup_toggle(void) 70 | { 71 | int enable; 72 | enable = wakeup_value(); 73 | 74 | if (enable == WAKEUP_ENABLE) { 75 | write_sysfs(usb_path, "disabled"); 76 | return; 77 | } 78 | 79 | write_sysfs(usb_path, "enabled"); 80 | } 81 | 82 | const char *usb_wakeup::wakeup_toggle_script(void) 83 | { 84 | int enable; 85 | enable = wakeup_value(); 86 | 87 | if (enable == WAKEUP_ENABLE) { 88 | return toggle_disable; 89 | } 90 | 91 | return toggle_enable; 92 | } 93 | 94 | void wakeup_usb_callback(const char *d_name) 95 | { 96 | class usb_wakeup *usb; 97 | char filename[PATH_MAX]; 98 | 99 | snprintf(filename, sizeof(filename), "/sys/bus/usb/devices/%s/power/wakeup", d_name); 100 | if (access(filename, R_OK) != 0) 101 | return; 102 | 103 | snprintf(filename, sizeof(filename), "/sys/bus/usb/devices/%s/power/wakeup", d_name); 104 | usb = new class usb_wakeup(filename, d_name); 105 | wakeup_all.push_back(usb); 106 | } 107 | 108 | void add_usb_wakeup(void) 109 | { 110 | process_directory("/sys/bus/usb/devices/", wakeup_usb_callback); 111 | } 112 | -------------------------------------------------------------------------------- /src/wakeup/wakeup_ethernet.cpp: -------------------------------------------------------------------------------- 1 | ;/* 2 | * Copyright 2018, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Gayatri Kammela 24 | */ 25 | 26 | #include "wakeup.h" 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | #include 43 | 44 | #include "../lib.h" 45 | #include "wakeup_ethernet.h" 46 | 47 | ethernet_wakeup::ethernet_wakeup(const char *path, const char *iface) : wakeup("", 0.5, _("Enabled"), _("Disabled")) 48 | { 49 | memset(interf, 0, sizeof(interf)); 50 | pt_strcpy(interf, iface); 51 | sprintf(desc, _("Wake-on-lan status for device %s"), iface); 52 | snprintf(eth_path, sizeof(eth_path), "/sys/class/net/%s/device/power/wakeup", iface); 53 | snprintf(toggle_enable, sizeof(toggle_enable), "echo 'enabled' > '%s';", eth_path); 54 | snprintf(toggle_disable, sizeof(toggle_disable), "echo 'disabled' > '%s';", eth_path); 55 | } 56 | 57 | int ethernet_wakeup::wakeup_value(void) 58 | { 59 | string content; 60 | 61 | content = read_sysfs_string(eth_path); 62 | 63 | if (strcmp(content.c_str(), "enabled") == 0) 64 | return WAKEUP_ENABLE; 65 | 66 | return WAKEUP_DISABLE; 67 | } 68 | 69 | void ethernet_wakeup::wakeup_toggle(void) 70 | { 71 | int enable; 72 | enable = wakeup_value(); 73 | 74 | if (enable == WAKEUP_ENABLE) { 75 | write_sysfs(eth_path, "disabled"); 76 | return; 77 | } 78 | 79 | write_sysfs(eth_path, "enabled"); 80 | } 81 | 82 | const char *ethernet_wakeup::wakeup_toggle_script(void) 83 | { 84 | int enable; 85 | enable = wakeup_value(); 86 | 87 | if (enable == WAKEUP_ENABLE) { 88 | return toggle_disable; 89 | } 90 | 91 | return toggle_enable; 92 | } 93 | 94 | void wakeup_eth_callback(const char *d_name) 95 | { 96 | class ethernet_wakeup *eth; 97 | char filename[PATH_MAX]; 98 | 99 | snprintf(filename, sizeof(filename), "/sys/class/net/%s/device/power/wakeup", d_name); 100 | if (access(filename, R_OK) != 0) 101 | return; 102 | 103 | snprintf(filename, sizeof(filename), "/sys/class/net/%s/device/power/wakeup", d_name); 104 | eth = new class ethernet_wakeup(filename, d_name); 105 | wakeup_all.push_back(eth); 106 | } 107 | 108 | void add_ethernet_wakeup(void) 109 | { 110 | process_directory("/sys/class/net/", wakeup_eth_callback); 111 | } 112 | -------------------------------------------------------------------------------- /doc/powertop.8: -------------------------------------------------------------------------------- 1 | .TH POWERTOP "8" "2014-08-02" "powertop manual" "System Administration" 2 | .SH NAME 3 | powertop \- a power consumption and power management diagnosis tool. 4 | .SH SYNOPSIS 5 | .B powertop 6 | .RI [ options ] 7 | .SH DESCRIPTION 8 | .B powertop 9 | is a program that helps to diagnose various issues with power consumption 10 | and power management. It also has an interactive mode allowing one to 11 | experiment with various power management settings. When invoking 12 | powertop without arguments powertop starts in interactive mode. 13 | .SH OPTIONS 14 | .TP 15 | .B \-\-auto\-tune 16 | Set all tunable options to their good setting without interaction. 17 | .TP 18 | .BR \-c ", " \-\-calibrate 19 | Runs powertop in calibration mode. When running on battery, powertop can 20 | track power consumption as well as system activity. When there are 21 | enough measurements, powertop can start to report power estimates. One 22 | can get more accurate estimates by using this option to enable a 23 | calibration cycle. This will cycle through various display levels and 24 | USB device activities and workloads. 25 | .TP 26 | \fB\-C\fR, \fB\-\-csv\fR[=\fIfilename\fR] 27 | Generate a CSV report. If a 28 | .I filename 29 | is not specified then the default name 30 | .B powertop.csv 31 | is used. The CSV report can be used for reporting and data analysis. 32 | .TP 33 | .B \-\-debug 34 | Run in debug mode. 35 | .TP 36 | \fB\-\-extech\fR=\fIdevnode\fR 37 | Use the Extech Power Analyzer for measurements. This allows one to 38 | specify the serial device node of the serial to USB adaptor connecting to 39 | the Extech Power Analyzer, for example 40 | .IR /dev/ttyUSB0 . 41 | .TP 42 | \fB\-r\fR, \fB\-\-html\fR[=\fIfilename\fR] 43 | Generate an HTML report. If a 44 | .I filename 45 | is not specified then the default name 46 | .B powertop.html 47 | is used. The HTML report can be sent to others to help diagnose power 48 | issues. 49 | .TP 50 | \fB\-i\fR, \fB\-\-iteration\fR[=\fIiterations\fR] 51 | Number of times to run each test. 52 | .TP 53 | .BR \-q ", " \-\-quiet 54 | Suppress stderr output. 55 | .TP 56 | \fB\-t\fR, \fB\-\-time\fR[=\fIseconds\fR] 57 | Generate a report for a specified number of 58 | .IR seconds . 59 | .TP 60 | \fB\-w\fR, \fB\-\-workload\fR[=\fIworkload\fR] 61 | Execute 62 | .I workload 63 | file as a part of calibration before making a report. 64 | .TP 65 | .BR \-V ", " \-\-version 66 | Print version information and exit. 67 | .TP 68 | .BR \-h ", " \-\-help 69 | Show the help message and exit. 70 | .SH COMMANDS 71 | In interactive mode, the following key bindings are available: 72 | .IP 73 | .TS 74 | tab(@); 75 | l l. 76 | \fBTab\fR@Show next tab 77 | \fBBackTab\fR@Show previous tab 78 | \fBRight Arrow\fR@Scroll to the right 79 | \fBLeft Arrow\fR@Scroll to the left 80 | \fBUp Arrow\fR, \fBPageUp\fR@Scroll up or select previous item 81 | \fBDown Arrow\fR, \fBPageDown\fR@Scroll down or select next item 82 | \fBSpace\fR, \fBReturn\fR@Activate current item 83 | \fBs\fR@Set refresh timeout 84 | \fBr\fR@Refresh window 85 | \fBq\fR, \fBCtrl-C\fR, \fBEscape\fR@Exit powertop 86 | .TE 87 | .SH BUGS 88 | Send bug reports to 89 | .MT powertop@lists.01.org 90 | .ME 91 | .SH SEE ALSO 92 | The program is more fully described at 93 | .UR https://01.org/powertop 94 | .UE 95 | .SH AUTHOR 96 | powertop was written by 97 | .MT arjan@\:linux.\:intel.\:com 98 | Arjan van de Ven 99 | .ME , 100 | and is currently maintained by 101 | .MT chris.\:e.\:ferron@\:linux.\:intel.\:com 102 | Chris E Ferron 103 | .ME . 104 | -------------------------------------------------------------------------------- /src/devices/thinkpad-fan.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #include "../lib.h" 36 | 37 | 38 | #include "device.h" 39 | #include "thinkpad-fan.h" 40 | #include "../parameters/parameters.h" 41 | #include "../process/powerconsumer.h" 42 | 43 | #include 44 | #include 45 | 46 | thinkpad_fan::thinkpad_fan(): device() 47 | { 48 | start_rate = 0; 49 | end_rate = 0; 50 | fan_index = get_param_index("thinkpad-fan"); 51 | fansqr_index = get_param_index("thinkpad-fan-sqr"); 52 | fancub_index = get_param_index("thinkpad-fan-cub"); 53 | r_index = get_result_index("thinkpad-fan"); 54 | register_sysfs_path("/sys/devices/platform/thinkpad_hwmon"); 55 | } 56 | 57 | void thinkpad_fan::start_measurement(void) 58 | { 59 | /* read the rpms of the fan */ 60 | start_rate = read_sysfs("/sys/devices/platform/thinkpad_hwmon/fan1_input"); 61 | } 62 | 63 | void thinkpad_fan::end_measurement(void) 64 | { 65 | end_rate = read_sysfs("/sys/devices/platform/thinkpad_hwmon/fan1_input"); 66 | 67 | report_utilization("thinkpad-fan", utilization()); 68 | } 69 | 70 | 71 | double thinkpad_fan::utilization(void) 72 | { 73 | return (start_rate+end_rate) / 2; 74 | } 75 | 76 | void create_thinkpad_fan(void) 77 | { 78 | char filename[PATH_MAX]; 79 | class thinkpad_fan *fan; 80 | 81 | pt_strcpy(filename, "/sys/devices/platform/thinkpad_hwmon/fan1_input"); 82 | 83 | if (access(filename, R_OK) !=0) 84 | return; 85 | 86 | register_parameter("thinkpad-fan", 10); 87 | register_parameter("thinkpad-fan-sqr", 5); 88 | register_parameter("thinkpad-fan-cub", 10); 89 | 90 | fan = new class thinkpad_fan(); 91 | all_devices.push_back(fan); 92 | } 93 | 94 | 95 | 96 | double thinkpad_fan::power_usage(struct result_bundle *result, struct parameter_bundle *bundle) 97 | { 98 | double power; 99 | double factor; 100 | double util; 101 | 102 | 103 | power = 0; 104 | util = get_result_value(r_index, result); 105 | 106 | if (util < 0) 107 | util = 0; 108 | 109 | 110 | /* physics dictact that fan power goes cubic with the rpms, but there's also a linear component for friction*/ 111 | factor = get_parameter_value(fancub_index, bundle); 112 | power += factor * pow(util / 3600.0, 3); 113 | 114 | factor = get_parameter_value(fansqr_index, bundle) - 5.0; 115 | power += factor * pow(util / 3600.0, 2); 116 | 117 | factor = get_parameter_value(fan_index, bundle) - 10.0; 118 | power += util / 5000.0 * factor; 119 | 120 | if (power <= 0.0) 121 | power = 0.0; 122 | 123 | return power; 124 | } 125 | -------------------------------------------------------------------------------- /src/process/interrupt.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #include 26 | #include 27 | #include 28 | #include "process.h" 29 | #include "interrupt.h" 30 | #include "../lib.h" 31 | 32 | const char* softirqs[] = { 33 | "HI_SOFTIRQ", 34 | "timer(softirq)", 35 | "net tx(softirq)", 36 | "net_rx(softirq)", 37 | "block(softirq)", 38 | "block_iopoll(softirq)", 39 | "tasklet(softirq)", 40 | "sched(softirq)", 41 | "hrtimer(softirq)", 42 | "RCU(softirq)", 43 | NULL 44 | }; 45 | 46 | 47 | interrupt::interrupt(const char *_handler, int _number) : power_consumer() 48 | { 49 | char buf[128]; 50 | running_since = 0; 51 | number = _number; 52 | pt_strcpy(handler, _handler); 53 | raw_count = 0; 54 | snprintf(desc, sizeof(desc), "[%i] %s", number, pretty_print(handler, buf, 128)); 55 | } 56 | 57 | 58 | vector all_interrupts; 59 | 60 | void interrupt::start_interrupt(uint64_t time) 61 | { 62 | running_since = time; 63 | raw_count ++; 64 | } 65 | 66 | uint64_t interrupt::end_interrupt(uint64_t time) 67 | { 68 | uint64_t delta; 69 | 70 | delta = time - running_since; 71 | accumulated_runtime += delta; 72 | return delta; 73 | } 74 | 75 | const char * interrupt::description(void) 76 | { 77 | if (child_runtime > accumulated_runtime) 78 | child_runtime = 0; 79 | return desc; 80 | } 81 | 82 | double interrupt::usage_summary(void) 83 | { 84 | double t; 85 | t = (accumulated_runtime - child_runtime) / 1000000.0 / measurement_time / 10; 86 | return t; 87 | } 88 | 89 | const char * interrupt::usage_units_summary(void) 90 | { 91 | return "%"; 92 | } 93 | 94 | 95 | class interrupt * find_create_interrupt(const char *_handler, int nr, int cpu) 96 | { 97 | char handler[64]; 98 | unsigned int i; 99 | class interrupt *new_irq; 100 | 101 | pt_strcpy(handler, _handler); 102 | if (strcmp(handler, "timer")==0) 103 | sprintf(handler, "timer/%i", cpu); 104 | 105 | 106 | for (i = 0; i < all_interrupts.size(); i++) { 107 | if (all_interrupts[i] && all_interrupts[i]->number == nr && strcmp(handler, all_interrupts[i]->handler) == 0) 108 | return all_interrupts[i]; 109 | } 110 | 111 | new_irq = new class interrupt(handler, nr); 112 | all_interrupts.push_back(new_irq); 113 | return new_irq; 114 | } 115 | 116 | void all_interrupts_to_all_power(void) 117 | { 118 | unsigned int i; 119 | for (i = 0; i < all_interrupts.size() ; i++) 120 | if (all_interrupts[i]->accumulated_runtime) 121 | all_power.push_back(all_interrupts[i]); 122 | } 123 | 124 | void clear_interrupts(void) 125 | { 126 | std::vector::iterator it = all_interrupts.begin(); 127 | while (it != all_interrupts.end()) { 128 | delete *it; 129 | it = all_interrupts.erase(it); 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /src/cpu/intel_gpu.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #include "intel_cpus.h" 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #include "../lib.h" 40 | #include "../parameters/parameters.h" 41 | #include "../display.h" 42 | 43 | void i965_core::measurement_start(void) 44 | { 45 | ifstream file; 46 | 47 | gettimeofday(&before, NULL); 48 | rc6_before = read_sysfs("/sys/class/drm/card0/power/rc6_residency_ms", NULL); 49 | rc6p_before = read_sysfs("/sys/class/drm/card0/power/rc6p_residency_ms", NULL); 50 | rc6pp_before = read_sysfs("/sys/class/drm/card0/power/rc6pp_residency_ms", NULL); 51 | 52 | update_cstate("gpu c0", "Powered On", 0, 0, 1, 0); 53 | update_cstate("gpu rc6", "RC6", 0, rc6_before, 1, 1); 54 | update_cstate("gpu rc6p", "RC6p", 0, rc6p_before, 1, 2); 55 | update_cstate("gpu rc6pp", "RC6pp", 0, rc6pp_before, 1, 3); 56 | } 57 | 58 | char * i965_core::fill_cstate_line(int line_nr, char *buffer, const char *separator) 59 | { 60 | buffer[0] = 0; 61 | double ratio, d = -1.0, time_delta; 62 | 63 | if (line_nr == LEVEL_HEADER) { 64 | sprintf(buffer,_(" GPU ")); 65 | return buffer; 66 | } 67 | 68 | buffer[0] = 0; 69 | 70 | time_delta = 1000000 * (after.tv_sec - before.tv_sec) + after.tv_usec - before.tv_usec; 71 | ratio = 100000.0/time_delta; 72 | 73 | switch (line_nr) { 74 | case 0: 75 | d = 100.0 - ratio * (rc6_after + rc6p_after + rc6pp_after - rc6_before - rc6p_before - rc6pp_before); 76 | break; 77 | case 1: 78 | d = ratio * (rc6_after - rc6_before); 79 | break; 80 | case 2: 81 | d = ratio * (rc6p_after - rc6p_before); 82 | break; 83 | case 3: 84 | d = ratio * (rc6pp_after - rc6pp_before); 85 | break; 86 | default: 87 | return buffer; 88 | } 89 | 90 | /* cope with rounding errors due to the measurement interval */ 91 | if (d < 0.0) 92 | d = 0.0; 93 | if (d > 100.0) 94 | d = 100.0; 95 | 96 | sprintf(buffer,"%5.1f%%", d); 97 | 98 | return buffer; 99 | } 100 | 101 | 102 | void i965_core::measurement_end(void) 103 | { 104 | gettimeofday(&after, NULL); 105 | 106 | rc6_after = read_sysfs("/sys/class/drm/card0/power/rc6_residency_ms", NULL); 107 | rc6p_after = read_sysfs("/sys/class/drm/card0/power/rc6p_residency_ms", NULL); 108 | rc6pp_after = read_sysfs("/sys/class/drm/card0/power/rc6pp_residency_ms", NULL); 109 | } 110 | 111 | char * i965_core::fill_pstate_line(int line_nr, char *buffer) 112 | { 113 | buffer[0] = 0; 114 | return buffer; 115 | } 116 | 117 | char * i965_core::fill_pstate_name(int line_nr, char *buffer) 118 | { 119 | buffer[0] = 0; 120 | return buffer; 121 | } 122 | 123 | -------------------------------------------------------------------------------- /src/tuning/tuningsysfs.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | 26 | #include "tuning.h" 27 | #include "tunable.h" 28 | #include "unistd.h" 29 | #include "tuningsysfs.h" 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | 43 | #include "../lib.h" 44 | 45 | sysfs_tunable::sysfs_tunable(const char *str, const char *_sysfs_path, const char *_target_content) : tunable(str, 1.0, _("Good"), _("Bad"), _("Unknown")) 46 | { 47 | pt_strcpy(sysfs_path, _sysfs_path); 48 | pt_strcpy(target_value, _target_content); 49 | bad_value[0] = 0; 50 | snprintf(toggle_good, sizeof(toggle_good), "echo '%s' > '%s';", target_value, sysfs_path); 51 | snprintf(toggle_bad, sizeof(toggle_bad), "echo '%s' > '%s';", bad_value, sysfs_path); 52 | } 53 | 54 | int sysfs_tunable::good_bad(void) 55 | { 56 | char current_value[4096], *c; 57 | ifstream file; 58 | 59 | file.open(sysfs_path, ios::in); 60 | if (!file) 61 | return TUNE_NEUTRAL; 62 | file.getline(current_value, 4096); 63 | file.close(); 64 | 65 | c = strchr(current_value, '\n'); 66 | if (c) 67 | *c = 0; 68 | 69 | if (strcmp(current_value, target_value) == 0) 70 | return TUNE_GOOD; 71 | 72 | pt_strcpy(bad_value, current_value); 73 | return TUNE_BAD; 74 | } 75 | 76 | void sysfs_tunable::toggle(void) 77 | { 78 | int good; 79 | good = good_bad(); 80 | 81 | if (good == TUNE_GOOD) { 82 | if (strlen(bad_value) > 0) 83 | write_sysfs(sysfs_path, bad_value); 84 | return; 85 | } 86 | 87 | write_sysfs(sysfs_path, target_value); 88 | } 89 | 90 | const char *sysfs_tunable::toggle_script(void) { 91 | int good; 92 | good = good_bad(); 93 | 94 | if (good == TUNE_GOOD) { 95 | if (strlen(bad_value) > 0) 96 | return toggle_bad; 97 | return NULL; 98 | } 99 | 100 | return toggle_good; 101 | } 102 | 103 | 104 | void add_sysfs_tunable(const char *str, const char *_sysfs_path, const char *_target_content) 105 | { 106 | class sysfs_tunable *tunable; 107 | 108 | if (access(_sysfs_path, R_OK) != 0) 109 | return; 110 | 111 | tunable = new class sysfs_tunable(str, _sysfs_path, _target_content); 112 | 113 | 114 | all_tunables.push_back(tunable); 115 | } 116 | 117 | static void add_sata_tunables_callback(const char *d_name) 118 | { 119 | char filename[PATH_MAX]; 120 | char msg[4096]; 121 | 122 | snprintf(filename, sizeof(filename), "/sys/class/scsi_host/%s/link_power_management_policy", d_name); 123 | snprintf(msg, sizeof(msg), _("Enable SATA link power management for %s"), d_name); 124 | add_sysfs_tunable(msg, filename, "med_power_with_dipm"); 125 | } 126 | 127 | void add_sata_tunables(void) 128 | { 129 | process_directory("/sys/class/scsi_host", add_sata_tunables_callback); 130 | } 131 | -------------------------------------------------------------------------------- /patches/linux-3.3.0-vfs-dirty-inode.patch: -------------------------------------------------------------------------------- 1 | From 9f7c5d04fdee46dbe715f2758152bb1664d4259c Mon Sep 17 00:00:00 2001 2 | From: Arjan van de Ven 3 | Date: Fri, 26 Nov 2010 12:18:03 -0800 4 | Subject: [PATCH 1/2] vfs: Add a trace point in the mark_inode_dirty function 5 | 6 | PowerTOP would like to be able to show who is keeping the disk 7 | busy by dirtying data. The most logical spot for this is in the vfs 8 | in the mark_inode_dirty() function, doing this on the block level 9 | is not possible because by the time the IO hits the block layer the 10 | guilty party can no longer be found ("kjournald" and "pdflush" are not 11 | useful answers to "who caused this file to be dirty). 12 | 13 | The trace point follows the same logic/style as the block_dump code 14 | and pretty much dumps the same data, just not to dmesg (and thus to 15 | /var/log/messages) but via the trace events streams. 16 | 17 | Eventually we should be able to phase out the block dump code, but that's 18 | for later on after a transition time. 19 | --- 20 | fs/fs-writeback.c | 3 +++ 21 | include/linux/fs.h | 11 +++++++++++ 22 | include/trace/events/writeback.h | 28 ++++++++++++++++++++++++++++ 23 | 3 files changed, 42 insertions(+), 0 deletions(-) 24 | 25 | diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c 26 | index 5b4a936..5ef5bb0 100644 27 | --- a/fs/fs-writeback.c 28 | +++ b/fs/fs-writeback.c 29 | @@ -1081,6 +1081,9 @@ void __mark_inode_dirty(struct inode *inode, int flags) 30 | if ((inode->i_state & flags) == flags) 31 | return; 32 | 33 | + if (flags & (I_DIRTY_SYNC | I_DIRTY_DATASYNC | I_DIRTY_PAGES)) 34 | + trace_writeback_inode_dirty(inode, flags); 35 | + 36 | if (unlikely(block_dump)) 37 | block_dump___mark_inode_dirty(inode); 38 | 39 | diff --git a/include/linux/fs.h b/include/linux/fs.h 40 | index 69cd5bb..e0ac37c 100644 41 | --- a/include/linux/fs.h 42 | +++ b/include/linux/fs.h 43 | @@ -1768,6 +1768,18 @@ struct super_operations { 44 | 45 | #define I_DIRTY (I_DIRTY_SYNC | I_DIRTY_DATASYNC | I_DIRTY_PAGES) 46 | 47 | +#define INODE_DIRTY_FLAGS \ 48 | + { I_DIRTY_SYNC, "DIRTY-SYNC" }, \ 49 | + { I_DIRTY_DATASYNC, "DIRTY-DATASYNC" }, \ 50 | + { I_DIRTY_PAGES, "DIRTY-PAGES" }, \ 51 | + { I_NEW, "NEW" }, \ 52 | + { I_WILL_FREE, "WILL-FREE" }, \ 53 | + { I_FREEING, "FREEING" }, \ 54 | + { I_CLEAR, "CLEAR" }, \ 55 | + { I_SYNC, "SYNC" }, \ 56 | + { I_REFERENCED, "REFERENCED" } 57 | + 58 | + 59 | extern void __mark_inode_dirty(struct inode *, int); 60 | static inline void mark_inode_dirty(struct inode *inode) 61 | { 62 | diff --git a/include/trace/events/writeback.h b/include/trace/events/writeback.h 63 | index 5973410..5f1e2a3 100644 64 | --- a/include/trace/events/writeback.h 65 | +++ b/include/trace/events/writeback.h 66 | @@ -408,6 +408,34 @@ DEFINE_EVENT(writeback_congest_waited_template, writeback_wait_iff_congested, 67 | TP_ARGS(usec_timeout, usec_delayed) 68 | ); 69 | 70 | +/* 71 | + * Tracepoint for dirtying an inode; used by PowerTOP 72 | + */ 73 | +TRACE_EVENT(writeback_inode_dirty, 74 | + 75 | + TP_PROTO(struct inode *inode, int flags), 76 | + 77 | + TP_ARGS(inode, flags), 78 | + 79 | + TP_STRUCT__entry( 80 | + __field( __kernel_dev_t, dev ) 81 | + __field( ino_t, ino ) 82 | + __field( u32, flags ) 83 | + ), 84 | + 85 | + TP_fast_assign( 86 | + __entry->dev = inode->i_sb->s_dev; 87 | + __entry->ino = inode->i_ino; 88 | + __entry->flags = flags; 89 | + ), 90 | + 91 | + TP_printk("dev %d:%d ino %lu flags %d %s", MAJOR(__entry->dev), MINOR(__entry->dev), 92 | + (unsigned long) __entry->ino, 93 | + __entry->flags, 94 | + __print_flags(__entry->flags, "|", INODE_DIRTY_FLAGS) 95 | + ) 96 | +); 97 | + 98 | DECLARE_EVENT_CLASS(writeback_single_inode_template, 99 | 100 | TP_PROTO(struct inode *inode, 101 | -- 102 | 1.7.8.5 103 | 104 | -------------------------------------------------------------------------------- /patches/linux-2.6.37-vfs-dirty-inode.patch: -------------------------------------------------------------------------------- 1 | From 3950d3c04a6bf8ccf9ff912a49bdd242a2fe9e47 Mon Sep 17 00:00:00 2001 2 | From: Arjan van de Ven 3 | Date: Fri, 26 Nov 2010 12:18:03 -0800 4 | Subject: [PATCH] vfs: Add a trace point in the mark_inode_dirty function 5 | 6 | PowerTOP would like to be able to show who is keeping the disk 7 | busy by dirtying data. The most logical spot for this is in the vfs 8 | in the mark_inode_dirty() function, doing this on the block level 9 | is not possible because by the time the IO hits the block layer the 10 | guilty party can no longer be found ("kjournald" and "pdflush" are not 11 | useful answers to "who caused this file to be dirty). 12 | 13 | The trace point follows the same logic/style as the block_dump code 14 | and pretty much dumps the same data, just not to dmesg (and thus to 15 | /var/log/messages) but via the trace events streams. 16 | 17 | Eventually we should be able to phase out the block dump code, but that's 18 | for later on after a transition time. 19 | 20 | Signed-of-by: Arjan van de Ven 21 | --- 22 | fs/fs-writeback.c | 3 +++ 23 | include/linux/fs.h | 12 ++++++++++++ 24 | include/trace/events/writeback.h | 28 ++++++++++++++++++++++++++++ 25 | 3 files changed, 43 insertions(+) 26 | 27 | Index: linux-2.6.37/fs/fs-writeback.c 28 | =================================================================== 29 | --- linux-2.6.37.orig/fs/fs-writeback.c 30 | +++ linux-2.6.37/fs/fs-writeback.c 31 | @@ -952,6 +952,9 @@ void __mark_inode_dirty(struct inode *in 32 | if ((inode->i_state & flags) == flags) 33 | return; 34 | 35 | + if (flags & (I_DIRTY_SYNC | I_DIRTY_DATASYNC | I_DIRTY_PAGES)) 36 | + trace_writeback_inode_dirty(inode, flags); 37 | + 38 | if (unlikely(block_dump)) 39 | block_dump___mark_inode_dirty(inode); 40 | 41 | Index: linux-2.6.37/include/linux/fs.h 42 | =================================================================== 43 | --- linux-2.6.37.orig/include/linux/fs.h 44 | +++ linux-2.6.37/include/linux/fs.h 45 | @@ -1677,6 +1677,18 @@ struct super_operations { 46 | 47 | #define I_DIRTY (I_DIRTY_SYNC | I_DIRTY_DATASYNC | I_DIRTY_PAGES) 48 | 49 | +#define INODE_DIRTY_FLAGS \ 50 | + { I_DIRTY_SYNC, "DIRTY-SYNC" }, \ 51 | + { I_DIRTY_DATASYNC, "DIRTY-DATASYNC" }, \ 52 | + { I_DIRTY_PAGES, "DIRTY-PAGES" }, \ 53 | + { I_NEW, "NEW" }, \ 54 | + { I_WILL_FREE, "WILL-FREE" }, \ 55 | + { I_FREEING, "FREEING" }, \ 56 | + { I_CLEAR, "CLEAR" }, \ 57 | + { I_SYNC, "SYNC" }, \ 58 | + { I_REFERENCED, "REFERENCED" } 59 | + 60 | + 61 | extern void __mark_inode_dirty(struct inode *, int); 62 | static inline void mark_inode_dirty(struct inode *inode) 63 | { 64 | Index: linux-2.6.37/include/trace/events/writeback.h 65 | =================================================================== 66 | --- linux-2.6.37.orig/include/trace/events/writeback.h 67 | +++ linux-2.6.37/include/trace/events/writeback.h 68 | @@ -186,6 +186,34 @@ DEFINE_EVENT(writeback_congest_waited_te 69 | TP_ARGS(usec_timeout, usec_delayed) 70 | ); 71 | 72 | +/* 73 | + * Tracepoint for dirtying an inode; used by PowerTOP 74 | + */ 75 | +TRACE_EVENT(writeback_inode_dirty, 76 | + 77 | + TP_PROTO(struct inode *inode, int flags), 78 | + 79 | + TP_ARGS(inode, flags), 80 | + 81 | + TP_STRUCT__entry( 82 | + __field( __kernel_dev_t, dev ) 83 | + __field( ino_t, ino ) 84 | + __field( u32, flags ) 85 | + ), 86 | + 87 | + TP_fast_assign( 88 | + __entry->dev = inode->i_sb->s_dev; 89 | + __entry->ino = inode->i_ino; 90 | + __entry->flags = flags; 91 | + ), 92 | + 93 | + TP_printk("dev %d:%d ino %lu flags %d %s", MAJOR(__entry->dev), MINOR(__entry->dev), 94 | + (unsigned long) __entry->ino, 95 | + __entry->flags, 96 | + __print_flags(__entry->flags, "|", INODE_DIRTY_FLAGS) 97 | + ) 98 | +); 99 | + 100 | #endif /* _TRACE_WRITEBACK_H */ 101 | 102 | /* This part must be outside protection */ 103 | -------------------------------------------------------------------------------- /src/tuning/tuningi2c.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * Authors: 16 | * Arjan van de Ven 17 | * Daniel Leung 18 | */ 19 | 20 | #include "tuning.h" 21 | #include "tunable.h" 22 | #include "unistd.h" 23 | #include "tuningi2c.h" 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "../lib.h" 33 | #include "../devices/runtime_pm.h" 34 | 35 | i2c_tunable::i2c_tunable(const char *path, const char *name, bool is_adapter) : tunable("", 0.9, _("Good"), _("Bad"), _("Unknown")) 36 | { 37 | ifstream file; 38 | char filename[PATH_MAX]; 39 | string devname; 40 | 41 | snprintf(filename, sizeof(filename), "%s/name", path); 42 | file.open(filename, ios::in); 43 | if (file) { 44 | getline(file, devname); 45 | file.close(); 46 | } 47 | 48 | if (is_adapter) { 49 | snprintf(i2c_path, sizeof(i2c_path), "%s/device/power/control", path); 50 | snprintf(filename, sizeof(filename), "%s/device", path); 51 | } else { 52 | snprintf(i2c_path, sizeof(i2c_path), "%s/power/control", path); 53 | snprintf(filename, sizeof(filename), "%s/device", path); 54 | } 55 | 56 | if (device_has_runtime_pm(filename)) 57 | snprintf(desc, sizeof(desc), _("Runtime PM for I2C %s %s (%s)"), (is_adapter ? _("Adapter") : _("Device")), name, (devname.empty() ? "" : devname.c_str())); 58 | else 59 | snprintf(desc, sizeof(desc), _("I2C %s %s has no runtime power management"), (is_adapter ? _("Adapter") : _("Device")), name); 60 | 61 | snprintf(toggle_good, sizeof(toggle_good), "echo 'auto' > '%s';", i2c_path); 62 | snprintf(toggle_bad, sizeof(toggle_bad), "echo 'on' > '%s';", i2c_path); 63 | } 64 | 65 | int i2c_tunable::good_bad(void) 66 | { 67 | string content; 68 | 69 | content = read_sysfs_string(i2c_path); 70 | 71 | if (strcmp(content.c_str(), "auto") == 0) 72 | return TUNE_GOOD; 73 | 74 | return TUNE_BAD; 75 | } 76 | 77 | void i2c_tunable::toggle(void) 78 | { 79 | int good; 80 | good = good_bad(); 81 | 82 | if (good == TUNE_GOOD) { 83 | write_sysfs(i2c_path, "on"); 84 | return; 85 | } 86 | 87 | write_sysfs(i2c_path, "auto"); 88 | } 89 | 90 | const char *i2c_tunable::toggle_script(void) 91 | { 92 | int good; 93 | good = good_bad(); 94 | 95 | if (good == TUNE_GOOD) { 96 | return toggle_bad; 97 | } 98 | 99 | return toggle_good; 100 | } 101 | 102 | static void add_i2c_callback(const char *d_name) 103 | { 104 | class i2c_tunable *i2c; 105 | char filename[PATH_MAX]; 106 | bool is_adapter = false; 107 | 108 | snprintf(filename, PATH_MAX, "/sys/bus/i2c/devices/%s/new_device", d_name); 109 | if (access(filename, W_OK) == 0) 110 | is_adapter = true; 111 | 112 | snprintf(filename, PATH_MAX, "/sys/bus/i2c/devices/%s", d_name); 113 | i2c = new class i2c_tunable(filename, d_name, is_adapter); 114 | 115 | if (is_adapter) 116 | snprintf(filename, PATH_MAX, "/sys/bus/i2c/devices/%s/device", d_name); 117 | else 118 | snprintf(filename, PATH_MAX, "/sys/bus/i2c/devices/%s", d_name); 119 | 120 | if (device_has_runtime_pm(filename)) 121 | all_tunables.push_back(i2c); 122 | else 123 | all_untunables.push_back(i2c); 124 | } 125 | 126 | void add_i2c_tunables(void) 127 | { 128 | process_directory("/sys/bus/i2c/devices/", add_i2c_callback); 129 | } 130 | -------------------------------------------------------------------------------- /src/report/report-data-html.cpp: -------------------------------------------------------------------------------- 1 | #include "report-data-html.h" 2 | 3 | void init_div(struct tag_attr *div_attr, const char *css_class, const char *css_id) 4 | { 5 | div_attr->css_class=css_class; 6 | div_attr->css_id=css_id; 7 | } 8 | 9 | void 10 | init_top_table_attr(struct table_attributes *table_css, int rows, int cols){ 11 | table_css->pos_table_title=L; 12 | table_css->table_class="emphasis1"; 13 | table_css->th_class="table_sysinfo"; 14 | table_css->td_class=""; 15 | table_css->tr_class=""; 16 | table_css->title_mod=0; 17 | table_css->rows=rows; 18 | table_css->cols=cols; 19 | } 20 | 21 | void init_title_attr(struct tag_attr *title_attr) 22 | { 23 | title_attr->css_class="content_title"; 24 | title_attr->css_id=""; 25 | } 26 | 27 | void init_std_table_attr(struct table_attributes *table_css, int rows, int cols){ 28 | table_css->table_class="emphasis2"; 29 | table_css->tr_class="emph1"; 30 | table_css->th_class="emph_title"; 31 | table_css->td_class=""; 32 | table_css->pos_table_title=T; 33 | table_css->title_mod=0; 34 | table_css->rows=rows; 35 | table_css->cols=cols; 36 | } 37 | void init_std_side_table_attr(struct table_attributes *table_css, int rows, int cols){ 38 | table_css->table_class="emphasis2 side_by_side_left"; 39 | table_css->tr_class="emph1"; 40 | table_css->th_class="emph_title"; 41 | table_css->td_class=""; 42 | table_css->pos_table_title=T; 43 | table_css->title_mod=0; 44 | table_css->rows=rows; 45 | table_css->cols=cols; 46 | } 47 | 48 | 49 | void init_pkg_table_attr(struct table_attributes *table_css, int rows, int cols){ 50 | table_css->table_class="emphasis2 side_by_side_left"; 51 | table_css->tr_class=""; 52 | table_css->th_class="title"; 53 | table_css->td_class="package"; 54 | table_css->pos_table_title=T; 55 | table_css->title_mod=0; 56 | table_css->rows=rows; 57 | table_css->cols=cols; 58 | } 59 | 60 | void init_core_table_attr(struct table_attributes *table_css, int title_mod, 61 | int rows, int cols){ 62 | table_css->table_class="emphasis2 side_by_side_left"; 63 | table_css->tr_class=""; 64 | table_css->th_class="title"; 65 | table_css->td_class="core"; 66 | table_css->pos_table_title=TC; 67 | table_css->title_mod=title_mod; 68 | table_css->rows=rows; 69 | table_css->cols=cols; 70 | } 71 | 72 | void init_cpu_table_attr(struct table_attributes *table_css, int title_mod, 73 | int rows, int cols){ 74 | table_css->table_class="emphasis2 side_by_side_left"; 75 | table_css->tr_class=""; 76 | table_css->th_class="title"; 77 | table_css->td_class="cpu"; 78 | table_css->pos_table_title=TLC; 79 | table_css->title_mod=title_mod; 80 | table_css->rows=rows; 81 | table_css->cols=cols; 82 | } 83 | 84 | 85 | void init_nowarp_table_attr(struct table_attributes *table_css, int rows, int cols){ 86 | table_css->table_class="emphasis2"; 87 | table_css->tr_class="emph1"; 88 | table_css->th_class="emph_title"; 89 | table_css->td_class="no_wrap"; 90 | table_css->pos_table_title=T; 91 | table_css->title_mod=0; 92 | table_css->rows=rows; 93 | table_css->cols=cols; 94 | } 95 | 96 | void init_tune_table_attr(struct table_attributes *table_css, int rows, int cols){ 97 | table_css->table_class="emphasis2"; 98 | table_css->tr_class="tune"; 99 | table_css->th_class="emph_title"; 100 | table_css->td_class=""; 101 | table_css->pos_table_title=T; 102 | table_css->rows=rows; 103 | table_css->cols=cols; 104 | } 105 | 106 | void init_wakeup_table_attr(struct table_attributes *table_css, int rows, int cols){ 107 | table_css->table_class="emphasis2"; 108 | table_css->tr_class="tune"; 109 | table_css->th_class="emph_title"; 110 | table_css->td_class=""; 111 | table_css->pos_table_title=T; 112 | table_css->rows=rows; 113 | table_css->cols=cols; 114 | } 115 | 116 | /* Other Helper Functions */ 117 | string 118 | double_to_string(double dval) 119 | { 120 | ostringstream dtmp; 121 | string str; 122 | dtmp << dval; 123 | str= dtmp.str(); 124 | str = str.substr(0, str.find(".")+2); 125 | return str; 126 | } 127 | 128 | 129 | -------------------------------------------------------------------------------- /src/process/timer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #include "timer.h" 33 | #include "../lib.h" 34 | #include "process.h" 35 | 36 | using namespace std; 37 | 38 | static bool timer_is_deferred(const char *handler) 39 | { 40 | FILE *file; 41 | bool ret = false; 42 | char line[4096]; 43 | 44 | file = fopen("/proc/timer_stats", "r"); 45 | if (!file) { 46 | return ret; 47 | } 48 | 49 | while (!feof(file)) { 50 | if (fgets(line, 4096, file) == NULL) 51 | break; 52 | if (strstr(line, handler)) { 53 | ret = (strstr(line, "D,") != NULL); 54 | if (ret == true) 55 | break; 56 | } 57 | } 58 | fclose(file); 59 | return ret; 60 | } 61 | 62 | timer::timer(unsigned long address) : power_consumer() 63 | { 64 | pt_strcpy(handler, kernel_function(address)); 65 | raw_count = 0; 66 | deferred = timer_is_deferred(handler); 67 | } 68 | 69 | 70 | static map all_timers; 71 | static map running_since; 72 | 73 | void timer::fire(uint64_t time, uint64_t timer_struct) 74 | { 75 | running_since[timer_struct] = time; 76 | } 77 | 78 | uint64_t timer::done(uint64_t time, uint64_t timer_struct) 79 | { 80 | int64_t delta; 81 | 82 | if (running_since.find(timer_struct) == running_since.end()) 83 | return ~0ULL; 84 | 85 | if (running_since[timer_struct] > time) 86 | return 0; 87 | 88 | delta = time - running_since[timer_struct]; 89 | 90 | accumulated_runtime += delta; 91 | 92 | raw_count++; 93 | 94 | return delta; 95 | } 96 | 97 | double timer::usage_summary(void) 98 | { 99 | double t; 100 | t = (accumulated_runtime - child_runtime) / 1000000.0 / measurement_time / 10; 101 | return t; 102 | } 103 | 104 | const char * timer::usage_units_summary(void) 105 | { 106 | return "%"; 107 | } 108 | 109 | 110 | 111 | static void add_timer(const pair& elem) 112 | { 113 | all_power.push_back(elem.second); 114 | } 115 | 116 | void all_timers_to_all_power(void) 117 | { 118 | for_each(all_timers.begin(), all_timers.end(), add_timer); 119 | 120 | } 121 | 122 | 123 | const char * timer::description(void) 124 | { 125 | if (child_runtime > accumulated_runtime) 126 | child_runtime = 0; 127 | 128 | snprintf(desc, sizeof(desc), "%s", handler); 129 | return desc; 130 | } 131 | 132 | 133 | class timer * find_create_timer(uint64_t func) 134 | { 135 | class timer * timer; 136 | if (all_timers.find(func) != all_timers.end()) 137 | return all_timers[func]; 138 | 139 | timer = new class timer(func); 140 | all_timers[func] = timer; 141 | return timer; 142 | 143 | } 144 | 145 | void clear_timers(void) 146 | { 147 | std::map::iterator it = all_timers.begin(); 148 | while (it != all_timers.end()) { 149 | delete it->second; 150 | all_timers.erase(it); 151 | it = all_timers.begin(); 152 | } 153 | running_since.clear(); 154 | } 155 | 156 | bool timer::is_deferred(void) 157 | { 158 | return deferred; 159 | } 160 | -------------------------------------------------------------------------------- /src/tuning/ethernet.cpp: -------------------------------------------------------------------------------- 1 | ;/* 2 | * Copyright 2010, Intel Corporation 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Arjan van de Ven 24 | */ 25 | 26 | #include "tuning.h" 27 | #include "tunable.h" 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | #include 44 | 45 | #include "../lib.h" 46 | #include "ethernet.h" 47 | 48 | extern void create_all_nics(callback fn); 49 | 50 | ethernet_tunable::ethernet_tunable(const char *iface) : tunable("", 0.3, _("Good"), _("Bad"), _("Unknown")) 51 | { 52 | memset(interf, 0, sizeof(interf)); 53 | pt_strcpy(interf, iface); 54 | sprintf(desc, _("Wake-on-lan status for device %s"), iface); 55 | snprintf(toggle_good, sizeof(toggle_good), "ethtool -s %s wol d;", iface); 56 | 57 | } 58 | 59 | 60 | int ethernet_tunable::good_bad(void) 61 | { 62 | int sock; 63 | struct ifreq ifr; 64 | struct ethtool_wolinfo wol; 65 | int ret; 66 | int result = TUNE_GOOD; 67 | 68 | memset(&ifr, 0, sizeof(struct ifreq)); 69 | 70 | sock = socket(AF_INET, SOCK_DGRAM, 0); 71 | if (sock<0) 72 | return result; 73 | 74 | pt_strcpy(ifr.ifr_name, interf); 75 | 76 | /* Check if the interf is up */ 77 | ret = ioctl(sock, SIOCGIFFLAGS, &ifr); 78 | if (ret<0) { 79 | close(sock); 80 | return result; 81 | } 82 | 83 | memset(&wol, 0, sizeof(wol)); 84 | 85 | wol.cmd = ETHTOOL_GWOL; 86 | ifr.ifr_data = (caddr_t)&wol; 87 | ioctl(sock, SIOCETHTOOL, &ifr); 88 | 89 | if (wol.wolopts) 90 | result = TUNE_BAD; 91 | 92 | close(sock); 93 | 94 | return result; 95 | } 96 | 97 | void ethernet_tunable::toggle(void) 98 | { 99 | int sock; 100 | struct ifreq ifr; 101 | struct ethtool_wolinfo wol; 102 | int ret; 103 | 104 | memset(&ifr, 0, sizeof(struct ifreq)); 105 | 106 | sock = socket(AF_INET, SOCK_DGRAM, 0); 107 | if (sock<0) 108 | return; 109 | 110 | pt_strcpy(ifr.ifr_name, interf); 111 | 112 | /* Check if the interface is up */ 113 | ret = ioctl(sock, SIOCGIFFLAGS, &ifr); 114 | if (ret<0) { 115 | close(sock); 116 | return; 117 | } 118 | 119 | memset(&wol, 0, sizeof(wol)); 120 | 121 | wol.cmd = ETHTOOL_GWOL; 122 | ifr.ifr_data = (caddr_t)&wol; 123 | ioctl(sock, SIOCETHTOOL, &ifr); 124 | wol.cmd = ETHTOOL_SWOL; 125 | wol.wolopts = 0; 126 | ioctl(sock, SIOCETHTOOL, &ifr); 127 | 128 | close(sock); 129 | } 130 | 131 | const char *ethernet_tunable::toggle_script(void) 132 | { 133 | int good; 134 | good = good_bad(); 135 | 136 | if (good != TUNE_GOOD) { 137 | return toggle_good; 138 | } 139 | 140 | return NULL; 141 | } 142 | 143 | 144 | void ethtunable_callback(const char *d_name) 145 | { 146 | class ethernet_tunable *eth; 147 | if (strcmp(d_name, "lo") == 0) 148 | return; 149 | eth = new(std::nothrow) class ethernet_tunable(d_name); 150 | if (eth) 151 | all_tunables.push_back(eth); 152 | } 153 | 154 | void add_ethernet_tunable(void) 155 | { 156 | create_all_nics(ðtunable_callback); 157 | } 158 | -------------------------------------------------------------------------------- /src/report/report-maker.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012 Samsung Electronics Co., Ltd. 2 | * http://www.samsung.com/ 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Generic report generator. 23 | * Written by Igor Zhbanov 24 | * 2012.10 */ 25 | 26 | #ifndef _REPORT_MAKER_H_ 27 | #define _REPORT_MAKER_H_ 28 | 29 | /* This report generator implements the following document structure: 30 | * body 31 | * \---> section 32 | * |---> Title 33 | * |---> paragraph 34 | * |---> table 35 | * |---> list 36 | * 37 | * The report body consists of a number of sections (a.k.a.
s, 38 | * a.k.a. tabs). 39 | * Each section can contain titles (

), paragraphs (

) 40 | * and tables (). 41 | * 42 | * A header is a single line of text. 43 | * 44 | * Paragraphs can contain only text. 45 | * 46 | * 47 | * Each section, table, row or cell could have its own formatting. 48 | * 49 | * Example of usage: 50 | * report_maker report(REPORT_OFF); 51 | * 52 | * report.set_type(REPORT_HTML); 53 | * report.add_div 54 | * report.add_title 55 | * report.add_list 56 | * report.add_table 57 | * report.finish_report(); 58 | * const char *result = report.get_result(); 59 | */ 60 | 61 | #include 62 | 63 | #include 64 | using namespace std; 65 | /* Conditional gettext. We need original strings for CSV. */ 66 | #ifdef ENABLE_NLS 67 | #define __(STRING) \ 68 | ((report.get_type() == REPORT_CSV) ? (STRING) : gettext(STRING)) 69 | #else 70 | #define __(STRING) (STRING) 71 | #endif 72 | 73 | #ifndef UNUSED 74 | #define UNUSED __attribute__((unused)) 75 | #endif /* UNUSED */ 76 | 77 | /* ************************************************************************ */ 78 | 79 | enum report_type { 80 | REPORT_OFF, 81 | REPORT_HTML, 82 | REPORT_CSV 83 | }; 84 | 85 | /* ************************************************************************ */ 86 | 87 | enum section_type { 88 | SECTION_DEFAULT, 89 | SECTION_SYSINFO, 90 | SECTION_CPUIDLE, 91 | SECTION_CPUFREQ, 92 | SECTION_DEVFREQ, 93 | SECTION_DEVPOWER, 94 | SECTION_SOFTWARE, 95 | SECTION_SUMMARY, 96 | SECTION_TUNING, 97 | SECTION_MAX /* Must be last in this enum */ 98 | }; 99 | 100 | 101 | /* ************************************************************************ */ 102 | 103 | class report_formatter; 104 | 105 | class report_maker 106 | { 107 | public: 108 | report_maker(report_type t); 109 | ~report_maker(); 110 | 111 | report_type get_type(); 112 | void set_type(report_type t); 113 | 114 | void addf(const char *fmt, ...) 115 | __attribute__ ((format (printf, 2, 3))); 116 | 117 | void finish_report(); 118 | const char *get_result(); 119 | void clear_result(); 120 | 121 | void add(const char *str); 122 | 123 | /* *** Report Style *** */ 124 | void add_header(); 125 | void end_header(); 126 | void add_logo(); 127 | void add_div(struct tag_attr *div_attr); 128 | void end_div(); 129 | void add_title(struct tag_attr *att_title, const char *title); 130 | void add_navigation(); 131 | void add_summary_list(string *list, int size); 132 | void add_table(string *system_data, struct table_attributes *tb_attr); 133 | 134 | private: 135 | void setup_report_formatter(); 136 | report_type type; 137 | report_formatter *formatter; 138 | }; 139 | #endif /* _REPORT_MAKER_H_ */ 140 | -------------------------------------------------------------------------------- /src/report/report-formatter-csv.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012 Samsung Electronics Co., Ltd. 2 | * http://www.samsung.com/ 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * CSV report generator. 23 | * Written by Igor Zhbanov 24 | * 2012.10 */ 25 | 26 | /* Uncomment to disable asserts */ 27 | /*#define NDEBUG*/ 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #include "report-formatter-csv.h" 34 | #include "report-data-html.h" 35 | 36 | 37 | /* ************************************************************************ */ 38 | report_formatter_csv::report_formatter_csv() 39 | { 40 | /* Do nothing special */ 41 | } 42 | 43 | /* ************************************************************************ */ 44 | void 45 | report_formatter_csv::finish_report() 46 | { 47 | /* Do nothing special */ 48 | } 49 | 50 | 51 | string 52 | report_formatter_csv::escape_string(const char *str) 53 | { 54 | string res; 55 | 56 | assert(str); 57 | 58 | for (const char *i = str; *i; i++) { 59 | switch (*i) { 60 | case '"': 61 | res += '"'; 62 | #ifdef REPORT_CSV_SPACE_NEED_QUOTES 63 | case ' ': 64 | #endif /* REPORT_CSV_SPACE_NEED_QUOTES */ 65 | case '\n': 66 | case REPORT_CSV_DELIMITER: 67 | csv_need_quotes = true; 68 | break; 69 | } 70 | 71 | res += *i; 72 | } 73 | 74 | return res; 75 | } 76 | 77 | 78 | 79 | 80 | /* Report Style */ 81 | void 82 | report_formatter_csv::add_header() 83 | { 84 | add_exact("____________________________________________________________________\n"); 85 | } 86 | 87 | void 88 | report_formatter_csv::end_header() 89 | { 90 | /* Do nothing */ 91 | } 92 | 93 | void 94 | report_formatter_csv::add_logo() 95 | { 96 | add_exact("\t\t\tP o w e r T O P\n"); 97 | } 98 | 99 | 100 | void 101 | report_formatter_csv::add_div(struct tag_attr * div_attr) 102 | { 103 | add_exact("\n"); 104 | } 105 | 106 | void 107 | report_formatter_csv::end_div() 108 | { 109 | /*Do nothing*/ 110 | } 111 | 112 | void 113 | report_formatter_csv::add_title(struct tag_attr *title_att, const char *title) 114 | { 115 | add_exact("____________________________________________________________________\n"); 116 | addf_exact(" * * * %s * * *\n", title); 117 | } 118 | 119 | void 120 | report_formatter_csv::add_navigation() 121 | { 122 | /* No nav in csv - thinking on table of contents */ 123 | } 124 | 125 | void 126 | report_formatter_csv::add_summary_list(string *list, int size) 127 | { 128 | int i; 129 | add_exact("\n"); 130 | for (i=0; i < size; i+=2){ 131 | addf_exact("%s %s", list[i].c_str(), list[i+1].c_str()); 132 | if(i < (size - 1)) 133 | add_exact(";"); 134 | } 135 | add_exact("\n"); 136 | } 137 | 138 | void 139 | report_formatter_csv::add_table(string *system_data, struct table_attributes* tb_attr) 140 | { 141 | int i, j; 142 | int offset=0; 143 | string tmp_str=""; 144 | int empty_row=0; 145 | add_exact("\n"); 146 | for (i=0; i < tb_attr->rows; i++){ 147 | for (j=0; j < tb_attr->cols; j++){ 148 | offset = i * (tb_attr->cols) + j; 149 | tmp_str=system_data[offset]; 150 | 151 | if(tmp_str == " ") 152 | empty_row+=1; 153 | else{ 154 | addf_exact("%s", system_data[offset].c_str()); 155 | if(j < (tb_attr->cols - 1)) 156 | add_exact(";"); 157 | } 158 | } 159 | if(empty_row < tb_attr->cols) 160 | add_exact("\n"); 161 | empty_row=0; 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /src/measurement/sysfs.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Anssi Hannula 3 | * 4 | * This file is part of PowerTOP 5 | * 6 | * This program file is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; version 2 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program in a file named COPYING; if not, write to the 17 | * Free Software Foundation, Inc, 18 | * 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * or just google for it. 21 | * 22 | * Authors: 23 | * Anssi Hannula 24 | */ 25 | #include "measurement.h" 26 | #include "sysfs.h" 27 | #include "../lib.h" 28 | #include 29 | #include 30 | #include 31 | 32 | sysfs_power_meter::sysfs_power_meter(const char *power_supply_name) 33 | { 34 | rate = 0.0; 35 | capacity = 0.0; 36 | pt_strcpy(name, power_supply_name); 37 | } 38 | 39 | bool sysfs_power_meter::get_sysfs_attr(const char *attribute, int *value) 40 | { 41 | char filename[PATH_MAX]; 42 | bool ok; 43 | 44 | snprintf(filename, sizeof(filename), "/sys/class/power_supply/%s/%s", name, attribute); 45 | *value = read_sysfs(filename, &ok); 46 | 47 | return ok; 48 | } 49 | 50 | bool sysfs_power_meter::is_present() 51 | { 52 | int present = 0; 53 | 54 | if (!get_sysfs_attr("present", &present)) 55 | return true; /* assume always present */ 56 | 57 | return present; 58 | } 59 | 60 | double sysfs_power_meter::get_voltage() 61 | { 62 | int voltage; 63 | 64 | if (!get_sysfs_attr("voltage_now", &voltage)) 65 | return -1.0; 66 | 67 | /* µV to V */ 68 | return voltage / 1000000.0; 69 | } 70 | 71 | bool sysfs_power_meter::set_rate_from_power() 72 | { 73 | int power; 74 | 75 | if (!get_sysfs_attr("power_now", &power)) 76 | return false; 77 | 78 | /* µW to W 79 | * Some drivers (example: Qualcomm) exposes use a negative value when 80 | * discharging, positive value when charging, so use the absolute value. */ 81 | rate = std::abs(power) / 1000000.0; 82 | return true; 83 | } 84 | 85 | bool sysfs_power_meter::set_rate_from_current(double voltage) 86 | { 87 | int current; 88 | 89 | if (!get_sysfs_attr("current_now", ¤t)) 90 | return false; 91 | 92 | /* current: µA 93 | * voltage: V 94 | * rate: W 95 | * Documentation ABI allows a negative value when discharging, positive 96 | * value when charging, so use the absolute value. */ 97 | rate = (std::abs(current) / 1000000.0) * voltage; 98 | return true; 99 | } 100 | 101 | bool sysfs_power_meter::set_capacity_from_energy() 102 | { 103 | int energy; 104 | 105 | if (!get_sysfs_attr("energy_now", &energy)) 106 | return false; 107 | 108 | /* µWh to J */ 109 | capacity = energy / 1000000.0 * 3600.0; 110 | return true; 111 | } 112 | 113 | bool sysfs_power_meter::set_capacity_from_charge(double voltage) 114 | { 115 | int charge; 116 | 117 | if (!get_sysfs_attr("charge_now", &charge)) 118 | return false; 119 | 120 | /* charge: µAh 121 | * voltage: V 122 | * capacity: J */ 123 | capacity = (charge / 1000000.0) * voltage * 3600.0; 124 | return true; 125 | } 126 | 127 | void sysfs_power_meter::measure() 128 | { 129 | bool got_rate = false; 130 | bool got_capacity = false; 131 | 132 | rate = 0.0; 133 | capacity = 0.0; 134 | this->set_discharging(false); 135 | 136 | if (!is_present()) 137 | return; 138 | /** do not jump over. we may have discharging battery */ 139 | if (read_sysfs_string("/sys/class/power_supply/%s/status", name) == "Discharging") 140 | this->set_discharging(true); 141 | 142 | got_rate = set_rate_from_power(); 143 | got_capacity = set_capacity_from_energy(); 144 | 145 | if (!got_rate || !got_capacity) { 146 | double voltage = get_voltage(); 147 | if (voltage < 0.0) 148 | return; 149 | if (!got_rate) 150 | set_rate_from_current(voltage); 151 | if (!got_capacity) 152 | set_capacity_from_charge(voltage); 153 | } 154 | } 155 | 156 | void sysfs_power_meter::end_measurement(void) 157 | { 158 | measure(); 159 | } 160 | 161 | void sysfs_power_meter::start_measurement(void) 162 | { 163 | /* Battery state is generally a lagging indication, lets only measure at the end */ 164 | } 165 | --------------------------------------------------------------------------------