pull request
Sergey Senozhatsky
cover pull request
Hello,
the following patch set contains a number of fixes and updates. added to -next tree.
I think this is the last pull request before 2.5 release.
David Rosca (1):
Fixed cpu_core::has_c1_res initialization
Jaroslav Skarvada (2):
tell user if the system is running out of FDs
set open files rlimit to /proc/sys/fs/nr_open
Sergey Senozhatsky (7):
lib: introduce ui_notify_user()
tuning: print executed toggle script
power_meter: introduce discharging member measurement: report
total global_time_left()
power_supply: delete unused power_supply class
parameters: report correct "base power" parameter
backlight: use process_directory() helper
backlight: decrease backlight() .ctor mem usage
Android.mk | 2 +- src/Makefile.am | 4 +- src/cpu/intel_cpus.cpp | 4 +- src/devices/backlight.cpp | 46 ++++------ src/devices/backlight.h | 4 +- src/lib.cpp | 20 +++++ src/lib.h | 2 + src/main.cpp | 20 ++++- src/measurement/measurement.cpp | 62 +++---------- src/measurement/measurement.h | 24 +++-- src/measurement/power_supply.cpp | 190 --------------------------------------- src/measurement/power_supply.h | 46 ---------- src/measurement/sysfs.cpp | 7 +- src/parameters/parameters.cpp | 10 +-- src/perf/perf.cpp | 13 ++- src/tuning/tuning.cpp | 6 +- 16 files changed, 117 insertions(+), 343 deletions(-) delete mode 100644 src/measurement/power_supply.cpp delete mode 100644 src/measurement/power_supply.h
Signature · 1 line
1.8.4.679.g0a1a803
Sergey Senozhatsky
PATCH 1/10 tell user if the system is running out of FDs
From: Jaroslav Skarvada <jskarvad(a)redhat.com>
From: Jaroslav Skarvada <jskarvad(a)redhat.com>
complex servers can run out of FDs easily (due to perf). In such case tell user that more FDs are needed instead of the generic message (that kernel doesn't support the perf).
--- src/perf/perf.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
src/perf/perf.cpp +10 -3
@@ -26,6 +26,7 @@ #include <iostream> #include <fstream> +#include <errno.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h>
@@ -72,6 +73,7 @@ void perf_event::create_perf_event(char *eventname, int _cpu) { struct perf_event_attr attr; int ret; + int err; struct { __u64 count;
@@ -107,10 +109,15 @@ void perf_event::create_perf_event(char *eventname, int _cpu) perf_fd = sys_perf_event_open(&attr, -1, _cpu, -1, 0); if (perf_fd < 0) { + err = errno; reset_display(); - fprintf(stderr, _("PowerTOP %s needs the kernel to support the 'perf' subsystem\n"), POWERTOP_VERSION); - fprintf(stderr, _("as well as support for trace points in the kernel:\n")); - fprintf(stderr, "CONFIG_PERF_EVENTS=y\nCONFIG_PERF_COUNTERS=y\nCONFIG_TRACEPOINTS=y\nCONFIG_TRACING=y\n"); + if (err == EMFILE) + fprintf(stderr, _("Too many open files, please increase the limit of open file descriptors.\n")); + else { + fprintf(stderr, _("PowerTOP %s needs the kernel to support the 'perf' subsystem\n"), POWERTOP_VERSION); + fprintf(stderr, _("as well as support for trace points in the kernel:\n")); + fprintf(stderr, "CONFIG_PERF_EVENTS=y\nCONFIG_PERF_COUNTERS=y\nCONFIG_TRACEPOINTS=y\nCONFIG_TRACING=y\n"); + } exit(EXIT_FAILURE); } if (read(perf_fd, &read_data, sizeof(read_data)) == -1) {
Signature · 1 line
1.8.4.679.g0a1a803
Sergey Senozhatsky
PATCH 2/10 set open files rlimit to /proc/sys/fs/nr_open
In reply to Sergey SenozhatskyFrom: Jaroslav Skarvada <jskarvad(a)redhat.com>
From: Jaroslav Skarvada <jskarvad(a)redhat.com>
we have noticed that it can only overcome soft limits, but not hard limits. E.g. on Fedora (and probably others) there is a soft limit of 1024 and a hard limit of 4096, so if powertop opens at least 15 file descriptors per CPU, then this will fail on a system with >273 CPUs.
On my system NR_OPEN is 1024, but /proc/sys/fs/nr_open gives me 1048576. It seems the linux kernel hardcodes 1024 * 1024 as the default kernel limit. This default limit can be raised to:
sysctl_nr_open_max = min((size_t)INT_MAX, ~(size_t)0/sizeof(void *)) &
-BITS_PER_LONG;
which is 2 Gi - 63 on my 64 bit system. I think we shouldn't touch/increase this. It seems there is no header definition for these limits.
I am proposing new patch, which reads the current kernel limit from the /proc. I am not sure about the portability, but at least it shouldn't break anything.
Finally I think, the first patch could be applied together with this patch (probably with the changed message) to notify user that he/she reached the FDs limit, because there is still some limit. This could also occur if some process would decrease the /proc/sys/fs/nr_open after it is read by powertop and before the ulimit is set
patch merge modifications by: Sergey Senozhatsky <sergey.senozhatsky(a)gmail.com>
--- src/main.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
src/main.cpp +18 -2
@@ -28,6 +28,7 @@ * Arjan van de Ven <arjan(a)linux.intel.com> */ #include <iostream> +#include <fstream> #include <stdlib.h> #include <stdio.h> #include <time.h>
@@ -61,6 +62,8 @@ #define DEBUGFS_MAGIC 0x64626720 +#define NR_OPEN_DEF 1024 * 1024 + int debug_learning = 0; unsigned time_out = 20; int leave_powertop = 0;
@@ -281,6 +284,20 @@ static void checkroot() { } +static int get_nr_open(void) { + int nr_open = NR_OPEN_DEF; + ifstream file; + + file.open("/proc/sys/fs/nr_open", ios::in); + if (file) { + file >> nr_open; + if (!file) + nr_open = NR_OPEN_DEF; + file.close(); + } + return nr_open; +} + static void powertop_init(void) { static char initialized = 0;
@@ -293,8 +310,7 @@ static void powertop_init(void) checkroot(); - getrlimit (RLIMIT_NOFILE, &rlmt); - rlmt.rlim_cur = rlmt.rlim_max; + rlmt.rlim_cur = rlmt.rlim_max = get_nr_open(); setrlimit (RLIMIT_NOFILE, &rlmt); ret = system("/sbin/modprobe cpufreq_stats > /dev/null 2>&1");
Signature · 1 line
1.8.4.679.g0a1a803
Sergey Senozhatsky
PATCH 3/10 lib: introduce ui_notify_user()
In reply to Sergey Senozhatskyui_notify_user(frmt, ...) prints formatted notification string at (x:1, y:0) WINDOW position.
use fixed UI_NOTIFY_BUFF_SZ size buffer, because there seems to be no ncurses() *print function which takes int x, int y WINDOW coordinates and va_list.
--- src/lib.cpp | 20 ++++++++++++++++++++ src/lib.h | 2 ++ 2 files changed, 22 insertions(+)
src/lib.cpp +20 -0
@@ -528,3 +528,23 @@ int write_msr(int cpu, uint64_t offset, uint64_t value) return retval; } + +#define UI_NOTIFY_BUFF_SZ 2048 + +void ui_notify_user(const char *frmt, ...) +{ + char notify[UI_NOTIFY_BUFF_SZ]; + va_list list; + + start_color(); + init_pair(1, COLOR_BLACK, COLOR_WHITE); + attron(COLOR_PAIR(1)); + va_start(list, frmt); + /* there is no ncurses *print() function which takes + * int x, int y and va_list, this is why we use temp + * buffer */ + vsnprintf(notify, UI_NOTIFY_BUFF_SZ - 1, frmt, list); + va_end(list); + mvprintw(1, 0, notify); + attroff(COLOR_PAIR(1)); +}
src/lib.h +2 -0
@@ -78,4 +78,6 @@ extern int read_msr(int cpu, uint64_t offset, uint64_t *value);extern int write_msr (int cpu,uint64_t offset,uint64_t value);extern void align_string (char *buffer,size_t min_sz,size_t max_sz); + +extern void ui_notify_user (const char *frmt, ...);#endif
Signature · 1 line
1.8.4.679.g0a1a803
Sergey Senozhatsky
PATCH 4/10 tuning: print executed toggle script
In reply to Sergey Senozhatskyreport executed toggle_script back to user via ui_notify_user().
Example:
Quoted 2 lines
Quoted 2 lines
'auto' > '/sys/bus/pci/devices/0000:00:1c.1/power/control'; echo 'on' > '/sys/bus/pci/devices/0000:00:1c.1/power/control';
--- src/tuning/tuning.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
src/tuning/tuning.cpp +5 -1
@@ -141,11 +141,15 @@ void tuning_window::repaint(void) void tuning_window::cursor_enter(void) { class tunable *tun; - + const char *toggle_script; tun = all_tunables[cursor_pos]; if (!tun) return; + /** device will change its state so need to store toggle script before + * we toggle()*/ + toggle_script = tun->toggle_script(); tun->toggle(); + ui_notify_user(">> %s\n", toggle_script); } static bool tunables_sort(class tunable * i, class tunable * j)
Signature · 1 line
1.8.4.679.g0a1a803
Sergey Senozhatsky
PATCH 5/10 power_meter: introduce discharging member measurement: report total global_time_left()
In reply to Sergey Senozhatskyreport total capacity and discahrge rate if at least one power_meter reports that is's discharging. previously we reported only discharging power_meters, thus user was not aware of total time left in case of N batteries. this is the reason why power_meter discharging member (with getter and setter one-liners were introduced) -- we need capacity and rate for every power_meter, regardless the fact whether its /sys/class/power_supply/*/status reports "Discharging" or not. report total "The battery discharge rate" and "The estimated remaining time" back to user when at least one power_meter is discharging.
Reported-and-tested-by: Maksim Melnikau <maxposedon(a)gmail.com>
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky(a)gmail.com>
--- src/measurement/measurement.cpp | 32 ++++++++++++++------------------ src/measurement/measurement.h | 24 +++++++++++++++++------- src/measurement/sysfs.cpp | 7 ++++--- 3 files changed, 35 insertions(+), 28 deletions(-)
src/measurement/measurement.cpp +14 -18
@@ -54,23 +54,6 @@ double power_meter::joules_consumed(void) return 0.0; } -double power_meter::time_left(void) -{ - double cap, rate; - - cap = dev_capacity(); - rate = joules_consumed(); - - if (cap < 0.001) - return 0.0; - - /* return 0.0 instead of INF+ */ - if (rate < 0.001) - return 0.0; - - return cap / rate; -} - vector<class power_meter *> power_meters; void start_power_measurement(void)
@@ -88,10 +71,17 @@ void end_power_measurement(void) double global_joules_consumed(void) { + bool global_discharging = false; double total = 0.0; unsigned int i; - for (i = 0; i < power_meters.size(); i++) + + for (i = 0; i < power_meters.size(); i++) { + global_discharging |= power_meters[i]->is_discharging(); total += power_meters[i]->joules_consumed(); + } + /* report global time left if at least one battery is discharging */ + if (!global_discharging) + return 0.0; all_results.power = total; if (total < min_power && total > 0.01)
@@ -101,13 +91,19 @@ double global_joules_consumed(void) double global_time_left(void) { + bool global_discharging = false; double total_capacity = 0.0; double total_rate = 0.0; unsigned int i; for (i = 0; i < power_meters.size(); i++) { + global_discharging |= power_meters[i]->is_discharging(); total_capacity += power_meters[i]->dev_capacity(); total_rate += power_meters[i]->joules_consumed(); } + /* report global time left if at least one battery is discharging */ + if (!global_discharging) + return 0.0; + /* return 0.0 instead of INF+ */ if (total_rate < 0.001) return 0.0;
src/measurement/measurement.h +17 -7
@@ -30,18 +30,29 @@ using namespace std;class power_meter { +bool discharging; public: + virtual ~power_meter() {}; + virtual void start_measurement(void); virtual void end_measurement(void); - virtual double joules_consumed(void); - virtual double dev_capacity(void) { return 0.0;}; /* in Joules */ - virtual double time_left(void); + virtual double dev_capacity(void) + { +return 0.0 ;/* in Joules */ + } - virtual ~power_meter() {}; -}; + virtual void set_discharging(bool d) + { + discharging = d; + } + virtual bool is_discharging() + { +return discharging; + } +}; extern vector<class power_meter *> power_meters;
@@ -53,7 +64,6 @@ extern double global_time_left(void);extern void detect_power_meters (void );extern void extech_power_meter (const char *devnode); -extern double min_power; -#endif +#endif
src/measurement/sysfs.cpp +4 -3
@@ -126,11 +126,13 @@ void sysfs_power_meter::measure() rate = 0.0; capacity = 0.0; + this->set_discharging(false); if (!is_present()) return; - if (read_sysfs_string("/sys/class/power_supply/%s/status", name) != "Discharging") - return; + /** do not jump over. we may have discharging battery */ + if (read_sysfs_string("/sys/class/power_supply/%s/status", name) == "Discharging") + this->set_discharging(true); got_rate = set_rate_from_power(); got_capacity = set_capacity_from_energy();
@@ -146,7 +148,6 @@ void sysfs_power_meter::measure() } } - void sysfs_power_meter::end_measurement(void) { measure();
Signature · 1 line
1.8.4.679.g0a1a803
Sergey Senozhatsky
PATCH 6/10 power_supply: delete unused power_supply class
In reply to Sergey Senozhatskywe use sysfs_power_meter or acpi_power_meter.
--- Android.mk | 2 +- src/Makefile.am | 4 +- src/measurement/measurement.cpp | 30 ------- src/measurement/power_supply.cpp | 190 --------------------------------------- src/measurement/power_supply.h | 46 ---------- 5 files changed, 3 insertions(+), 269 deletions(-) delete mode 100644 src/measurement/power_supply.cpp delete mode 100644 src/measurement/power_supply.h
Android.mk +1 -1
@@ -34,7 +34,7 @@ LOCAL_SRC_FILES += \ src/measurement/measurement.cpp \ src/measurement/acpi.cpp \ src/measurement/extech.cpp \ - src/measurement/power_supply.cpp \ + src/measurement/sysfs.cpp \ src/display.cpp \ src/report.cpp \ src/main.cpp \
src/Makefile.am +2 -2
@@ -24,9 +24,9 @@ powertop_SOURCES = parameters/persistent.cpp parameters/learn.cpp parameters/par tuning/tunable.cpp tuning/nl80211.h tuning/iw.c tuning/wifi.cpp tuning/tuningsysfs.h \ tuning/tuningsysfs.cpp tuning/wifi.h tuning/runtime.cpp tuning/tunable.h \ tuning/runtime.h tuning/tuningusb.h tuning/iw.h calibrate/calibrate.cpp \ - calibrate/calibrate.h measurement/measurement.cpp measurement/power_supply.cpp \ + calibrate/calibrate.h measurement/measurement.cpp \ measurement/measurement.h measurement/acpi.cpp measurement/sysfs.h measurement/sysfs.cpp \ - measurement/acpi.h measurement/extech.cpp measurement/power_supply.h measurement/extech.h \ + measurement/acpi.h measurement/extech.cpp measurement/extech.h \ report/report-maker.cpp report/report-maker.h report/report-formatter.h \ report/report-formatter-base.cpp report/report-formatter-base.h \ report/report-formatter-csv.cpp report/report-formatter-csv.h \
src/measurement/measurement.cpp +0 -30
@@ -25,7 +25,6 @@ #include "measurement.h" #include "acpi.h" #include "extech.h" -#include "power_supply.h" #include "sysfs.h" #include "../parameters/parameters.h" #include "../lib.h"
@@ -131,35 +130,6 @@ void acpi_power_meters_callback(const char *d_name) power_meters.push_back(meter); } -void power_supply_callback(const char *d_name) -{ - char filename[4096]; - char line[4096]; - ifstream file; - bool discharging = false; - - sprintf(filename, "/sys/class/power_supply/%s/uevent", d_name); - file.open(filename, ios::in); - if (!file) - return; - - while (file) { - file.getline(line, 4096); - - if (strstr(line, "POWER_SUPPLY_STATUS") && strstr(line, "Discharging")) - discharging = true; - } - file.close(); - - if (!discharging) - return; - - class power_supply *power; - power = new(std::nothrow) class power_supply(d_name); - if (power) - power_meters.push_back(power); -} - void detect_power_meters(void) { process_directory("/sys/class/power_supply", sysfs_power_meters_callback);
src/measurement/power_supply.cpp deleted +0 -190
190 lines not on this page · raw message
src/measurement/power_supply.h deleted +0 -46
46 lines not on this page · raw message
Signature · 1 line
1.8.4.679.g0a1a803
Sergey Senozhatsky
PATCH 7/10 parameters: report correct "base power" parameter
In reply to Sergey Senozhatsky--- src/parameters/parameters.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
src/parameters/parameters.cpp +3 -7
@@ -188,18 +188,14 @@ double compute_bundle(struct parameter_bundle *parameters, struct result_bundle if (!bpi) bpi = get_param_index("base power"); - power = parameters->parameters[bpi]; - - for (i = 0; i < all_devices.size(); i++) { - + for (i = 0; i < all_devices.size(); i++) power += all_devices[i]->power_usage(results, parameters); - } -// printf("result power is %6.2f guessed is %6.2f\n", results->power, power); + parameters->actual_power = results->power; parameters->guessed_power = power; /* scale the squared error by the actual power so that non-idle data points weigh heavier */ parameters->score += results->power * (power - results->power) * (power - results->power); - + parameters->parameters[bpi] = power; return power; }
Signature · 1 line
1.8.4.679.g0a1a803
Sergey Senozhatsky
PATCH 8/10 backlight: use process_directory() helper
In reply to Sergey Senozhatsky--- src/devices/backlight.cpp | 42 +++++++++++++++--------------------------- src/devices/backlight.h | 4 ++-- 2 files changed, 17 insertions(+), 29 deletions(-)
src/devices/backlight.cpp +15 -27
@@ -39,7 +39,7 @@ using namespace std; #include <string.h> -backlight::backlight(char *_name, char *path): device() +backlight::backlight(const char *_name, const char *path): device() { char devname[128]; min_level = 0;
@@ -156,36 +156,24 @@ const char * backlight::device_name(void) return name; } -void create_all_backlights(void) +static void create_all_backlights_callback(const char *d_name) { - struct dirent *entry; - DIR *dir; + class backlight *bl; char filename[4096]; - - dir = opendir("/sys/class/backlight/"); - if (!dir) - return; - while (1) { - class backlight *bl; - entry = readdir(dir); - if (!entry) - break; - if (entry->d_name[0] == '.') - continue; - sprintf(filename, "/sys/class/backlight/%s", entry->d_name); - bl = new class backlight(entry->d_name, filename); - all_devices.push_back(bl); - register_parameter("backlight"); - register_parameter("backlight-power"); - register_parameter("backlight-boost-40", 0, 0.5); - register_parameter("backlight-boost-80", 0, 0.5); - register_parameter("backlight-boost-100", 0, 0.5); - } - closedir(dir); - + sprintf(filename, "/sys/class/backlight/%s", d_name); + bl = new class backlight(d_name, filename); + all_devices.push_back(bl); } - +void create_all_backlights(void) +{ + process_directory("/sys/class/backlight/", create_all_backlights_callback); + register_parameter("backlight"); + register_parameter("backlight-power"); + register_parameter("backlight-boost-40", 0, 0.5); + register_parameter("backlight-boost-80", 0, 0.5); + register_parameter("backlight-boost-100", 0, 0.5); +} double backlight::power_usage(struct result_bundle *result, struct parameter_bundle *bundle) {
src/devices/backlight.h +2 -2
@@ -37,7 +37,7 @@ class backlight: public device {int r_index_power; public: -backlight (char *_name, char *path); + backlight(const char *_name, const char *path); virtual void start_measurement(void); virtual void end_measurement(void);
@@ -55,4 +55,4 @@ public:extern void create_all_backlights (void ); -#endif +#endif
Signature · 1 line
1.8.4.679.g0a1a803
Sergey Senozhatsky
PATCH 9/10 backlight: decrease backlight() .ctor mem usage
In reply to Sergey Senozhatsky--- src/devices/backlight.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
src/devices/backlight.cpp +1 -3
@@ -41,15 +41,13 @@ using namespace std; backlight::backlight(const char *_name, const char *path): device() { - char devname[128]; min_level = 0; max_level = 0; start_level = 0; end_level = 0; strncpy(sysfs_path, path, sizeof(sysfs_path)); register_sysfs_path(sysfs_path); - sprintf(devname, "backlight:%s", _name); - strncpy(name, devname, sizeof(name)); + snprintf(name, sizeof(name) - 1, "backlight:%s", _name); r_index = get_result_index(name); r_index_power = 0; }
Signature · 1 line
1.8.4.679.g0a1a803
Sergey Senozhatsky
PATCH 10/10 Fixed cpu_core::has_c1_res initialization
In reply to Sergey SenozhatskyFrom: David Rosca <nowrep(a)gmail.com>
cpu_core::has_c1_res is left uninitialized for anything other than BYT-M, resulting in error at startup:
read_msr cpu0 0x660 : Argument list too long.
--- src/cpu/intel_cpus.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
src/cpu/intel_cpus.cpp +3 -1
@@ -101,8 +101,10 @@ nhm_core::nhm_core(int model) if (model == 0x37) { has_c3_res = 0; has_c1_res = 1; - } else + } else { has_c3_res = 1; + has_c1_res = 0; + } } void nhm_core::measurement_start(void)
Signature · 1 line
1.8.4.679.g0a1a803
Kristen Carlson Accardi
AppliedQuoted 6 lines · On Mon, 14 Oct 2013 11:40:47 +0300 Sergey Senozhatsky…
Hello,
the following patch set contains a number of fixes and updates. added to -next tree.
I think this is the last pull request before 2.5 release.
Applied, thanks.
Kristen