From 3f36168651a281fadb5d28a4eb55505ddee89d95 Mon Sep 17 00:00:00 2001 From: Lucian Cristian Date: Fri, 15 Feb 2019 21:24:44 +0200 Subject: [PATCH] powertop: add package package for monitoring power consumption 001 and 002 patches are taken from Alpine Linux Signed-off-by: Lucian Cristian --- utils/powertop/Makefile | 46 +++++++++++++++++++ .../patches/001-musl-fix-headers.patch | 22 +++++++++ utils/powertop/patches/002-strerror_r.patch | 20 ++++++++ ...-src-main-Add-missing-pthread-header.patch | 38 +++++++++++++++ ...-Change-open-parameter-to-const-char.patch | 30 ++++++++++++ 5 files changed, 156 insertions(+) create mode 100644 utils/powertop/Makefile create mode 100644 utils/powertop/patches/001-musl-fix-headers.patch create mode 100644 utils/powertop/patches/002-strerror_r.patch create mode 100644 utils/powertop/patches/010-src-main-Add-missing-pthread-header.patch create mode 100644 utils/powertop/patches/020-intel_cpus.cpp-Change-open-parameter-to-const-char.patch diff --git a/utils/powertop/Makefile b/utils/powertop/Makefile new file mode 100644 index 000000000..430ce693b --- /dev/null +++ b/utils/powertop/Makefile @@ -0,0 +1,46 @@ +# +# Copyright (C) 2019 Lucian Cristain +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +include $(TOPDIR)/rules.mk + +PKG_NAME:=powertop +PKG_VERSION:=2.10 +PKG_RELEASE:=1 + +PKG_SOURCE:=$(PKG_NAME)-v$(PKG_VERSION).tar.gz +PKG_SOURCE_URL:=https://01.org/sites/default/files/downloads/ +PKG_HASH:=d3b7459eaba7d01c8841dd33a3b4d369416c01e9bd8951b0d88234cf18fe4a75 + +PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-v$(PKG_VERSION) +PKG_MAINTAINER:=Lucian Cristain +PKG_LICENSE:=GPL-2.0 + +PKG_BUILD_PARALLEL:=1 +PKG_INSTALL:=1 + +include $(INCLUDE_DIR)/package.mk + +define Package/powertop + SECTION:=utils + CATEGORY:=Utilities + DEPENDS:=+libpci +libncursesw +libnl-genl +libstdcpp + TITLE:=Power consumption monitor + URL:=https://01.org/powertop +endef + +define Package/powertop/description + PowerTOP is a Linux tool to diagnose issues with power consumption + and power management. +endef + +define Package/powertop/install + $(INSTALL_DIR) $(1)/usr/sbin + $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/powertop \ + $(1)/usr/sbin/ +endef + +$(eval $(call BuildPackage,powertop)) diff --git a/utils/powertop/patches/001-musl-fix-headers.patch b/utils/powertop/patches/001-musl-fix-headers.patch new file mode 100644 index 000000000..9839d15bf --- /dev/null +++ b/utils/powertop/patches/001-musl-fix-headers.patch @@ -0,0 +1,22 @@ +--- ./src/devices/devfreq.h.orig ++++ ./src/devices/devfreq.h +@@ -25,6 +25,7 @@ + #ifndef _INCLUDE_GUARD_DEVFREQ_H + #define _INCLUDE_GUARD_DEVFREQ_H + ++#include + #include "device.h" + #include "../parameters/parameters.h" + +diff --git a/src/perf/perf.h b/src/perf/perf.h +index ee072ae06d24..932588a684f9 100644 +--- a/src/perf/perf.h ++++ b/src/perf/perf.h +@@ -26,6 +26,7 @@ + #define _INCLUDE_GUARD_PERF_H_ + + #include ++#include + + + extern "C" { diff --git a/utils/powertop/patches/002-strerror_r.patch b/utils/powertop/patches/002-strerror_r.patch new file mode 100644 index 000000000..cf8659e1e --- /dev/null +++ b/utils/powertop/patches/002-strerror_r.patch @@ -0,0 +1,20 @@ +--- traceevent/event-parse.c.orig ++++ ./traceevent/event-parse.c +@@ -5121,12 +5121,17 @@ + const char *msg; + + if (errnum >= 0) { ++#if defined(__GLIBC__) + msg = strerror_r(errnum, buf, buflen); + if (msg != buf) { + size_t len = strlen(msg); + memcpy(buf, msg, min(buflen - 1, len)); + *(buf + min(buflen - 1, len)) = '\0'; + } ++#else ++ if (strerror_r(errnum, buf, buflen)) ++ snprintf(buf, buflen, "errnum %i", errnum); ++#endif + return 0; + } + diff --git a/utils/powertop/patches/010-src-main-Add-missing-pthread-header.patch b/utils/powertop/patches/010-src-main-Add-missing-pthread-header.patch new file mode 100644 index 000000000..e01f0d540 --- /dev/null +++ b/utils/powertop/patches/010-src-main-Add-missing-pthread-header.patch @@ -0,0 +1,38 @@ +From 7235a786ea30ae5ca7c1b3458ef5b2388c08dfd9 Mon Sep 17 00:00:00 2001 +From: Rosen Penev +Date: Thu, 28 Mar 2019 18:44:27 -0700 +Subject: [PATCH] src/main: Add missing pthread header + +Otherwise compilation can fail with: + +main.cpp: In function 'void one_measurement(int, int, char*)': +main.cpp:226:3: error: 'pthread_t' was not declared in this scope + pthread_t thread = 0UL; + ^~~~~~~~~ +main.cpp:226:3: note: suggested alternative: 'pread' + pthread_t thread = 0UL; + ^~~~~~~~~ + pread + +et al. + +Signed-off-by: Rosen Penev +--- + src/main.cpp | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/src/main.cpp b/src/main.cpp +index cbb7a4e..75d4202 100644 +--- a/src/main.cpp ++++ b/src/main.cpp +@@ -39,6 +39,7 @@ + #include + #include + #include ++#include + + #include "cpu/cpu.h" + #include "process/process.h" +-- +2.17.1 + diff --git a/utils/powertop/patches/020-intel_cpus.cpp-Change-open-parameter-to-const-char.patch b/utils/powertop/patches/020-intel_cpus.cpp-Change-open-parameter-to-const-char.patch new file mode 100644 index 000000000..46d01703f --- /dev/null +++ b/utils/powertop/patches/020-intel_cpus.cpp-Change-open-parameter-to-const-char.patch @@ -0,0 +1,30 @@ +From 8cdf846922ffb3e0d2a828be473fdf9c45a56e7c Mon Sep 17 00:00:00 2001 +From: Rosen Penev +Date: Sat, 30 Mar 2019 20:19:17 -0700 +Subject: [PATCH] intel_cpus.cpp: Change open parameter to const char * + +ifstream::open takes std::string starting with C++11, not before. + +This fixes compilation with uClibc++ and potentially other older libraries + +Signed-off-by: Rosen Penev +--- + src/cpu/intel_cpus.cpp | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/cpu/intel_cpus.cpp b/src/cpu/intel_cpus.cpp +index 0030dba..4dffadc 100644 +--- a/src/cpu/intel_cpus.cpp ++++ b/src/cpu/intel_cpus.cpp +@@ -92,7 +92,7 @@ int is_supported_intel_cpu(int model, int cpu) + + int is_intel_pstate_driver_loaded() + { +- const string filename("/sys/devices/system/cpu/cpu0/cpufreq/scaling_driver"); ++ const char *filename = "/sys/devices/system/cpu/cpu0/cpufreq/scaling_driver"; + const string intel_pstate("intel_pstate"); + char line[32] = { '\0' }; + ifstream file; +-- +2.17.1 +