Package: powertop
Version: 2.8-1
Severity: important
Tags: patch

Powertop still lacks POWER enablement, mainly for PowerNV (bare-metal) mode.

This patch are a backport from a recenlty accepted commits:
180ac4fd196d169cd788ab13ccadf365d75d986b
9ac909bba40cda08ce2c68fed76d206d9a2d6387

I would appreciate if these patches get accepted before the next powertop
release.

Thanks,
Breno


-- System Information:
Debian Release: stretch/sid
  APT prefers testing
  APT policy: (500, 'testing')
Architecture: ppc64el (ppc64le)

Kernel: Linux 4.2.0-1-powerpc64le (SMP w/4 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages powertop depends on:
ii  libc6             2.19-22
ii  libgcc1           1:5.2.1-23
ii  libncurses5       6.0+20151024-2
ii  libncursesw5      6.0+20151024-2
ii  libnl-3-200       3.2.26-1
ii  libnl-genl-3-200  3.2.26-1
ii  libpci3           1:3.3.1-1
ii  libstdc++6        5.2.1-23
ii  libtinfo5         6.0+20151024-2

powertop recommends no packages.

Versions of packages powertop suggests:
pn  cpufrequtils       <none>
pn  laptop-mode-tools  <none>

-- no debconf information
>From 9ac909bba40cda08ce2c68fed76d206d9a2d6387 Mon Sep 17 00:00:00 2001
From: Stewart Smith <stew...@linux.vnet.ibm.com>
Date: Fri, 27 Nov 2015 11:07:28 +1100
Subject: [PATCH 1/2] cpu: support powerpc /proc/cpuinfo

Clean up duplicate code added for ARM and add support for what
seems to be a good deliminator on ppc64.

This patch makes powertop pick up CPUs on powernv platform.

Signed-off-by: Stewart Smith <stew...@linux.vnet.ibm.com>
---
 src/cpu/cpu.cpp | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/src/cpu/cpu.cpp b/src/cpu/cpu.cpp
index 9ca320f..64e1d3d 100644
--- a/src/cpu/cpu.cpp
+++ b/src/cpu/cpu.cpp
@@ -285,19 +285,13 @@ void enumerate_cpus(void)
 				model = strtoull(c, NULL, 10);
 			}
 		}
-		if (strncasecmp(line, "bogomips\t", 9) == 0) {
-			if (number == -1) {
-				/* Not all /proc/cpuinfo include "processor\t". */
-				number = 0;
-			}
-			if (number >= 0) {
-				handle_one_cpu(number, vendor, family, model);
-				set_max_cpu(number);
-				number = -2;
-			}
-		}
-		/* bogomips is removed in ARM, using CPU revision to enumerate */
-		if (strncasecmp(line, "CPU revision\t", 13) == 0) {
+		/* on x86 and others 'bogomips' is last
+		 * on ARM it *can* be bogomips, or 'CPU revision'
+		 * on POWER, it's revision
+		 */
+		if (strncasecmp(line, "bogomips\t", 9) == 0
+		    || strncasecmp(line, "CPU revision\t", 13) == 0
+		    || strncmp(line, "revision", 7) == 0) {
 			if (number == -1) {
 				/* Not all /proc/cpuinfo include "processor\t". */
 				number = 0;
-- 
2.1.0

>From 180ac4fd196d169cd788ab13ccadf365d75d986b Mon Sep 17 00:00:00 2001
From: Stewart Smith <stew...@linux.vnet.ibm.com>
Date: Fri, 27 Nov 2015 11:07:29 +1100
Subject: [PATCH 2/2] Add support for power consumption sensors through
 opal-sensors sysfs

The OPAL firmware on PowerNV (non-virtualized POWER) may export
certain sensors in the system through sysfs entries.

While arguably we *should* go and support the more standard locations
in sysfs to put power information (which existing powertop code would
pick up without modification), existing systems do have this interface
and the extra code needed to get information from it is minimal.

With this patch, on a powernv system that has a power consumption
sensor (e.g. an IBM S822L), powertop will display current power
usage.

Signed-off-by: Stewart Smith <stew...@linux.vnet.ibm.com>
---
 src/Makefile.am                  |  2 ++
 src/measurement/measurement.cpp  | 14 +++++++++++
 src/measurement/opal-sensors.cpp | 50 ++++++++++++++++++++++++++++++++++++++++
 src/measurement/opal-sensors.h   | 41 ++++++++++++++++++++++++++++++++
 4 files changed, 107 insertions(+)
 create mode 100644 src/measurement/opal-sensors.cpp
 create mode 100644 src/measurement/opal-sensors.h

diff --git a/src/Makefile.am b/src/Makefile.am
index 87d8469..8357bae 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -67,6 +67,8 @@ powertop_SOURCES = \
 	measurement/measurement.h \
 	measurement/sysfs.cpp \
 	measurement/sysfs.h \
+	measurement/opal-sensors.cpp \
+	measurement/opal-sensors.h \
 	parameters/learn.cpp \
 	parameters/parameters.cpp \
 	parameters/parameters.h \
diff --git a/src/measurement/measurement.cpp b/src/measurement/measurement.cpp
index efbdc1e..68c41fe 100644
--- a/src/measurement/measurement.cpp
+++ b/src/measurement/measurement.cpp
@@ -26,6 +26,7 @@
 #include "acpi.h"
 #include "extech.h"
 #include "sysfs.h"
+#include "opal-sensors.h"
 #include "../parameters/parameters.h"
 #include "../lib.h"
 
@@ -130,9 +131,22 @@ void acpi_power_meters_callback(const char *d_name)
 		power_meters.push_back(meter);
 }
 
+void sysfs_opal_sensors_callback(const char *d_name)
+{
+	class opal_sensors_power_meter *meter;
+
+	if (strncmp(d_name, "power", 5) != 0)
+		return;
+
+	meter = new(std::nothrow) class opal_sensors_power_meter(d_name);
+	if (meter)
+		power_meters.push_back(meter);
+}
+
 void detect_power_meters(void)
 {
 	process_directory("/sys/class/power_supply", sysfs_power_meters_callback);
+	process_directory("/sys/devices/platform/opal-sensor/hwmon/hwmon0", sysfs_opal_sensors_callback);
 	if (power_meters.size() == 0) {
 		process_directory("/proc/acpi/battery", acpi_power_meters_callback);
 	}
diff --git a/src/measurement/opal-sensors.cpp b/src/measurement/opal-sensors.cpp
new file mode 100644
index 0000000..4198b63
--- /dev/null
+++ b/src/measurement/opal-sensors.cpp
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2015 IBM Corp.
+ *
+ * This file is part of PowerTOP
+ *
+ * This program file is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program in a file named COPYING; if not, write to the
+ * Free Software Foundation, Inc,
+ * 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ * or just google for it.
+ *
+ * Authors:
+ *	Stewart Smith <stew...@linux.vnet.ibm.com>
+ */
+#include "measurement.h"
+#include "opal-sensors.h"
+#include "../lib.h"
+#include <string.h>
+#include <stdio.h>
+#include <limits.h>
+
+opal_sensors_power_meter::opal_sensors_power_meter(const char *power_supply_name)
+{
+	strncpy(name, power_supply_name, sizeof(name));
+}
+
+double opal_sensors_power_meter::joules_consumed(void)
+{
+	char filename[PATH_MAX];
+	bool ok;
+	int value;
+	double r = 0;
+
+	snprintf(filename, sizeof(filename), "/sys/devices/platform/opal-sensor/hwmon/hwmon0/%s", name);
+	value = read_sysfs(filename, &ok);
+
+	if(ok)
+		r = value / 1000000.0;
+	return r;
+}
diff --git a/src/measurement/opal-sensors.h b/src/measurement/opal-sensors.h
new file mode 100644
index 0000000..d8aa5e2
--- /dev/null
+++ b/src/measurement/opal-sensors.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2015 IBM Corp.
+ *
+ * This file is part of PowerTOP
+ *
+ * This program file is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program in a file named COPYING; if not, write to the
+ * Free Software Foundation, Inc,
+ * 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ * or just google for it.
+ *
+ * Authors:
+ *	Stewart Smith <stew...@linux.vnet.ibm.com>
+ */
+#ifndef INCLUDE_GUARD_OPAL_SENSORS_H
+#define INCLUDE_GUARD_OPAL_SENSORS_H
+
+#include "measurement.h"
+
+class opal_sensors_power_meter: public power_meter {
+	char name[256];
+public:
+	opal_sensors_power_meter(const char *power_supply_name);
+	virtual void start_measurement(void) {};
+	virtual void end_measurement(void) {};
+
+	virtual double joules_consumed(void);
+	virtual double dev_capacity(void) { return 0.0; }
+};
+
+#endif
-- 
2.1.0

Reply via email to