From 480824f8b3a7070bae48a911995f74ec4b90f41b Mon Sep 17 00:00:00 2001 From: CentOS Sources Date: Nov 19 2015 15:37:13 +0000 Subject: import powertop-2.3-9.el7 --- diff --git a/SOURCES/powertop-2.3-auto-tune.patch b/SOURCES/powertop-2.3-auto-tune.patch new file mode 100644 index 0000000..811f9f2 --- /dev/null +++ b/SOURCES/powertop-2.3-auto-tune.patch @@ -0,0 +1,121 @@ +diff --git a/doc/powertop.8 b/doc/powertop.8 +index 4a2f0b0..0f460ec 100644 +--- a/doc/powertop.8 ++++ b/doc/powertop.8 +@@ -14,7 +14,10 @@ experiment with various power management settings. When invoking powertop + without arguments powertop starts in interactive mode. + .SH OPTIONS + .TP +-\fB\-\-calibrate ++.B \-\-auto\-tune ++Set all tunable options to their good setting without interaction. ++.TP ++.BR \-c ", " \-\-calibrate + runs powertop in calibration mode. When running on battery, powertop + can track power consumption as well as system activity. When there + are enough measurements, powertop can start to report power estimates. One +diff --git a/src/main.cpp b/src/main.cpp +index 16b1613..9da3167 100644 +--- a/src/main.cpp ++++ b/src/main.cpp +@@ -75,6 +75,7 @@ static const struct option long_options[] = + {"version", no_argument, NULL, 'V'}, + {"help",no_argument, NULL, 'u'}, /* u for usage */ + {"calibrate",no_argument, NULL, 'c'}, ++ {"auto-tune",no_argument, NULL, 'a'}, + {"html", optional_argument, NULL, 'h'}, + {"csv", optional_argument, NULL, 'C'}, + {"extech", optional_argument, NULL, 'e'}, +@@ -110,6 +111,7 @@ static void print_usage() + printf("--debug \t\t %s\n",_("run in \"debug\" mode")); + printf("--version \t\t %s\n",_("print version information")); + printf("--calibrate \t\t %s\n",_("runs powertop in calibration mode")); ++ printf("--auto-tune \t\t %s\n",_("Sets all tunable options to their GOOD setting")); + printf("--extech%s \t %s\n",_("[=devnode]"),_("uses an Extech Power Analyzer for measurements")); + printf("--html%s \t %s\n",_("[=FILENAME]"),_("generate a html report")); + printf("--csv%s \t %s\n",_("[=FILENAME]"),_("generate a csv report")); +@@ -362,7 +364,7 @@ int main(int argc, char **argv) + int c; + char filename[4096]; + char workload[4096] = {0,}; +- int iterations = 1; ++ int iterations = 1, auto_tune = 0; + + set_new_handler(out_of_memory); + +@@ -390,7 +392,10 @@ int main(int argc, char **argv) + print_usage(); + exit(0); + break; +- ++ case 'a': ++ auto_tune = 1; ++ leave_powertop = 1; ++ break; + case 'c': + powertop_init(); + calibrate(); +@@ -446,20 +451,27 @@ int main(int argc, char **argv) + end_pci_access(); + exit(0); + } +- ++ if (!auto_tune) ++ init_display(); ++ initialize_tuning(); + /* first one is short to not let the user wait too long */ +- init_display(); + one_measurement(1, NULL); +- initialize_tuning(); +- tuning_update_display(); +- show_tab(0); ++ ++ if (!auto_tune) { ++ tuning_update_display(); ++ show_tab(0); ++ } else { ++ auto_toggle_tuning(); ++ } + + while (!leave_powertop) { +- show_cur_tab(); ++ if (!auto_tune) ++ show_cur_tab(); + one_measurement(time_out, NULL); + learn_parameters(15, 0); + } +- endwin(); ++ if (!auto_tune) ++ endwin(); + printf("%s\n", _("Leaving PowerTOP")); + + end_process_data(); +diff --git a/src/tuning/tuning.cpp b/src/tuning/tuning.cpp +index 08d8251..ff3d715 100644 +--- a/src/tuning/tuning.cpp ++++ b/src/tuning/tuning.cpp +@@ -273,3 +273,11 @@ void clear_tuning() + } + all_untunables.clear(); + } ++ ++void auto_toggle_tuning() ++{ ++ for (unsigned int i = 0; i < all_tunables.size(); i++) { ++ if (all_tunables[i]->good_bad() == TUNE_BAD) ++ all_tunables[i]->toggle(); ++ } ++} +diff --git a/src/tuning/tuning.h b/src/tuning/tuning.h +index 7c4921f..f70001b 100644 +--- a/src/tuning/tuning.h ++++ b/src/tuning/tuning.h +@@ -29,7 +29,5 @@ extern void initialize_tuning(void); + extern void tuning_update_display(void); + extern void report_show_tunables(void); + extern void clear_tuning(void); +- +- +- ++extern void auto_toggle_tuning(void); + #endif diff --git a/SOURCES/powertop-2.3-improve-reporting.patch b/SOURCES/powertop-2.3-improve-reporting.patch new file mode 100644 index 0000000..a6e48ef --- /dev/null +++ b/SOURCES/powertop-2.3-improve-reporting.patch @@ -0,0 +1,82 @@ +diff --git a/src/main.cpp b/src/main.cpp +index 9da3167..7ead705 100644 +--- a/src/main.cpp ++++ b/src/main.cpp +@@ -403,7 +403,12 @@ int main(int argc, char **argv) + + case 'h': /* html report */ + reporttype = REPORT_HTML; +- sprintf(filename, "%s", optarg ? optarg : "powertop.html" ); ++ snprintf(filename, 4096, "%s", optarg ? optarg : "powertop.html" ); ++ if (!strlen(filename)) ++ { ++ fprintf(stderr, _("Invalid HTML filename\n")); ++ exit(1); ++ } + break; + + case 't': +@@ -424,7 +429,12 @@ int main(int argc, char **argv) + + case 'C': /* csv report*/ + reporttype = REPORT_CSV; +- sprintf(filename, "%s", optarg ? optarg : "powertop.csv"); ++ snprintf(filename, 4096, "%s", optarg ? optarg : "powertop.csv"); ++ if (!strlen(filename)) ++ { ++ fprintf(stderr, _("Invalid CSV filename\n")); ++ exit(1); ++ } + break; + case '?': /* Unknown option */ + /* getopt_long already printed an error message. */ +diff --git a/src/report/report.cpp b/src/report/report.cpp +index c018bb1..b01b925 100644 +--- a/src/report/report.cpp ++++ b/src/report/report.cpp +@@ -149,28 +149,27 @@ static void system_info(void) + void init_report_output(char *filename_str, int iterations) + { + size_t period; +- char file_prefix[4096]; +- char file_postfix[8]; ++ string filename; + time_t stamp; + char datestr[200]; + +- string mystring = string(filename_str); +- sprintf(file_postfix, "%s", +- (reporttype == REPORT_HTML ? "html" : "csv")); +- period=mystring.find_last_of("."); +- sprintf(file_prefix, "%s",mystring.substr(0,period).c_str()); +- memset(&datestr, 0, 200); +- memset(&stamp, 0, sizeof(time_t)); +- stamp=time(NULL); +- strftime(datestr, sizeof(datestr), "%Y%m%d-%H%M%S", localtime(&stamp)); +- +- if (iterations != 1) +- sprintf(reportout.filename, "%s-%s.%s", +- file_prefix, datestr,file_postfix); ++ if (iterations == 1) ++ sprintf(reportout.filename, "%s", filename_str); + else +- sprintf(reportout.filename, "%s.%s", +- file_prefix, file_postfix); +- ++ { ++ filename = string(filename_str); ++ period = filename.find_last_of("."); ++ if (period > filename.length()) ++ period = filename.length(); ++ memset(&datestr, 0, 200); ++ memset(&stamp, 0, sizeof(time_t)); ++ stamp = time(NULL); ++ strftime(datestr, sizeof(datestr), "%Y%m%d-%H%M%S", localtime(&stamp)); ++ snprintf(reportout.filename, 4096, "%s-%s%s", ++ filename.substr(0, period).c_str(), datestr, ++ filename.substr(period).c_str()); ++ } ++ + reportout.report_file = fopen(reportout.filename, "wm"); + if (!reportout.report_file) { + fprintf(stderr, _("Cannot open output file %s (%s)\n"), diff --git a/SOURCES/powertop-2.3-msr-check.patch b/SOURCES/powertop-2.3-msr-check.patch new file mode 100644 index 0000000..70c1ca4 --- /dev/null +++ b/SOURCES/powertop-2.3-msr-check.patch @@ -0,0 +1,170 @@ +diff --git a/src/cpu/cpu.cpp b/src/cpu/cpu.cpp +index 1eb340c..b021955 100644 +--- a/src/cpu/cpu.cpp ++++ b/src/cpu/cpu.cpp +@@ -57,6 +57,7 @@ class perf_power_bundle: public perf_bundle + + static class abstract_cpu * new_package(int package, int cpu, char * vendor, int family, int model) + { ++ uint64_t msr; + class abstract_cpu *ret = NULL; + class cpudevice *cpudev; + char packagename[128]; +@@ -71,15 +72,19 @@ static class abstract_cpu * new_package(int package, int cpu, char * vendor, int + case 0x25: /* Westmere */ + case 0x27: /* Medfield Atom*/ + case 0x2C: /* Westmere */ +- ret = new class nhm_package; ++ if (read_msr(cpu, MSR_APERF, &msr) >= 0) ++ ret = new class nhm_package; + break; + case 0x2A: /* SNB */ + case 0x2D: /* SNB Xeon */ + case 0x3A: /* IVB */ + case 0x3C: + case 0x3D: /* IVB Xeon */ +- has_c2c7_res = 1; +- ret = new class nhm_package; ++ if (read_msr(cpu, MSR_PKG_C7_RESIDENCY, &msr) >= 0) ++ { ++ has_c2c7_res = 1; ++ ret = new class nhm_package; ++ } + break; + } + } +@@ -99,6 +104,7 @@ static class abstract_cpu * new_package(int package, int cpu, char * vendor, int + + static class abstract_cpu * new_core(int core, int cpu, char * vendor, int family, int model) + { ++ uint64_t msr; + class abstract_cpu *ret = NULL; + + if (strcmp(vendor, "GenuineIntel") == 0) { +@@ -116,7 +122,8 @@ static class abstract_cpu * new_core(int core, int cpu, char * vendor, int famil + case 0x3A: /* IVB */ + case 0x3C: + case 0x3D: /* IVB Xeon */ +- ret = new class nhm_core; ++ if (read_msr(cpu, MSR_APERF, &msr) >= 0) ++ ret = new class nhm_core; + } + } + +@@ -142,6 +149,7 @@ static class abstract_cpu * new_i965_gpu(void) + + static class abstract_cpu * new_cpu(int number, char * vendor, int family, int model) + { ++ uint64_t msr; + class abstract_cpu * ret = NULL; + + if (strcmp(vendor, "GenuineIntel") == 0) { +@@ -159,7 +167,8 @@ static class abstract_cpu * new_cpu(int number, char * vendor, int family, int m + case 0x3A: /* IVB */ + case 0x3C: + case 0x3D: /* IVB Xeon */ +- ret = new class nhm_cpu; ++ if (read_msr(number, MSR_APERF, &msr) >= 0) ++ ret = new class nhm_cpu; + } + } + +diff --git a/src/cpu/intel_cpus.cpp b/src/cpu/intel_cpus.cpp +index 2b78d31..8d5f51a 100644 +--- a/src/cpu/intel_cpus.cpp ++++ b/src/cpu/intel_cpus.cpp +@@ -49,30 +49,15 @@ static uint64_t get_msr(int cpu, uint64_t offset) + { + ssize_t retval; + uint64_t msr; +- int fd; +- char msr_path[256]; + +- fd = sprintf(msr_path, "/dev/cpu/%d/msr", cpu); +- +- if (access(msr_path, R_OK) != 0){ +- fd = sprintf(msr_path, "/dev/msr%d", cpu); +- +- if (access(msr_path, R_OK) != 0){ +- fprintf(stderr, _("msr reg not found")); +- exit(-2); +- } +- } +- +- fd = open(msr_path, O_RDONLY); +- +- retval = pread(fd, &msr, sizeof msr, offset); +- if (retval != sizeof msr) { ++ retval = read_msr(cpu, offset, &msr); ++ if (retval < 0) { + reset_display(); +- fprintf(stderr, _("pread cpu%d 0x%llx : "), cpu, (unsigned long long)offset); ++ fprintf(stderr, _("read_msr cpu%d 0x%llx : "), cpu, (unsigned long long)offset); + fprintf(stderr, "%s\n", strerror(errno)); + exit(-2); + } +- close(fd); ++ + return msr; + } + +diff --git a/src/lib.cpp b/src/lib.cpp +index 723517a..6993088 100644 +--- a/src/lib.cpp ++++ b/src/lib.cpp +@@ -56,6 +56,7 @@ extern "C" { + #include + #include + #include ++#include + + static int kallsyms_read = 0; + +@@ -450,3 +451,36 @@ int get_user_input(char *buf, unsigned sz) + /* to distinguish between getnstr error and empty line */ + return ret || strlen(buf); + } ++ ++int read_msr(int cpu, uint64_t offset, uint64_t *value) ++{ ++ ssize_t retval; ++ uint64_t msr; ++ int fd; ++ char msr_path[256]; ++ ++ sprintf(msr_path, "/dev/cpu/%d/msr", cpu); ++ ++ if (access(msr_path, R_OK) != 0){ ++ sprintf(msr_path, "/dev/msr%d", cpu); ++ ++ if (access(msr_path, R_OK) != 0){ ++ fprintf(stderr, ++ _("Model-specific registers (MSR)\ ++ not found (try enabling CONFIG_X86_MSR).\n")); ++ return -1; ++ } ++ } ++ ++ fd = open(msr_path, O_RDONLY); ++ if (fd < 0) ++ return -1; ++ retval = pread(fd, &msr, sizeof msr, offset); ++ close(fd); ++ if (retval != sizeof msr) { ++ return -1; ++ } ++ *value = msr; ++ ++ return retval; ++} +diff --git a/src/lib.h b/src/lib.h +index de2de5a..1c9ca42 100644 +--- a/src/lib.h ++++ b/src/lib.h +@@ -74,5 +74,6 @@ typedef void (*callback)(const char*); + extern void process_directory(const char *d_name, callback fn); + extern int utf_ok; + extern int get_user_input(char *buf, unsigned sz); ++extern int read_msr(int cpu, uint64_t offset, uint64_t *value); + + #endif diff --git a/SOURCES/powertop.service b/SOURCES/powertop.service new file mode 100644 index 0000000..96669ae --- /dev/null +++ b/SOURCES/powertop.service @@ -0,0 +1,9 @@ +[Unit] +Description=PowerTOP autotuner + +[Service] +Type=oneshot +ExecStart=/usr/sbin/powertop --auto-tune + +[Install] +WantedBy=multi-user.target diff --git a/SPECS/powertop.spec b/SPECS/powertop.spec index 0c664b6..0dce5d8 100644 --- a/SPECS/powertop.spec +++ b/SPECS/powertop.spec @@ -1,12 +1,13 @@ Name: powertop Version: 2.3 -Release: 8%{?dist} +Release: 9%{?dist} Summary: Power consumption monitor Group: Applications/System License: GPLv2 URL: http://01.org/powertop/ Source0: http://01.org/powertop/sites/default/files/downloads/%{name}-%{version}.tar.gz +Source1: powertop.service # Sent upstream Patch0: powertop-2.3-always-create-params.patch @@ -21,9 +22,18 @@ Patch4: powertop-2.3-fd-limit-err.patch # Sent upstream Patch5: powertop-2.3-reg-net-params.patch Patch6: powertop-2.3-tunable-overflow-fix.patch +# Reported upstream, but upstream powertop needs different patch +Patch7: powertop-2.3-msr-check.patch +# Backported from upstream +Patch8: powertop-2.3-auto-tune.patch +# Sent upstream +Patch9: powertop-2.3-improve-reporting.patch BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) BuildRequires: gettext, ncurses-devel, pciutils-devel, zlib-devel, libnl3-devel -Requires(post): coreutils +BuildRequires: systemd +Requires(post): systemd, coreutils +Requires(preun): systemd +Requires(postun): systemd %description PowerTOP is a tool that finds the software component(s) that make your @@ -38,6 +48,9 @@ computer use more power than necessary while it is idle. %patch4 -p1 -b .fd-limit-err %patch5 -p1 -b .reg-net-params %patch6 -p1 -b .tunable-overflow-fix.patch +%patch7 -p1 -b .msr-check +%patch8 -p1 -b .auto-tune +%patch9 -p1 -b .improve-reporting # remove left over object files find . -name "*.o" -exec rm {} \; @@ -53,7 +66,17 @@ install -Dd %{buildroot}%{_localstatedir}/cache/powertop touch %{buildroot}%{_localstatedir}/cache/powertop/{saved_parameters.powertop,saved_results.powertop} %find_lang %{name} +# Systemd +install -Dpm 644 %{SOURCE1} %{buildroot}%{_unitdir}/powertop.service + +%preun +%systemd_preun powertop.service + +%postun +%systemd_postun_with_restart powertop.service + %post +%systemd_post powertop.service # Hack for powertop not to show warnings on first start touch %{_localstatedir}/cache/powertop/{saved_parameters.powertop,saved_results.powertop} @@ -68,8 +91,18 @@ rm -rf %{buildroot} %ghost %{_localstatedir}/cache/powertop/saved_results.powertop %{_sbindir}/powertop %{_mandir}/man8/powertop.8* +%{_unitdir}/powertop.service %changelog +* Mon May 11 2015 Jaroslav Škarvada - 2.3-9 +- MSR read errors are no more fatal (by msr-check patch) + Resolves: rhbz#1102088 +- Backported --auto-tune feature and added one-shot systemd service + (by auto-tune patch) + Resolves: rhbz#1143014 +- Improved handling of reporting filenames (by improve-reporting patch) + Resolves: rhbz#1039822 + * Tue Mar 25 2014 Jaroslav Škarvada - 2.3-8 - Fixed buffer overflow in cpufreq tunables on systems with many CPUs (by tunable-overflow-fix patch)