Package: powertop
Version: 1.97-2
Powertop doesn't seem well maintained and many of its source locations (or
git tree) have disappeared, but 1.98 seems to be the latest:
http://ftp.osuosl.org/pub/linux/status/powertop/powertop-1.98.tar.bz2
Watts used while on battery does not work anymore with unpatched powertop
since the deprecated /proc/acpi/battery is now gone. See:
https://bugs.archlinux.org/task/26416
I found this:
https://aur.archlinux.org/packages.php?ID=48935
and this patch fixed it for me:
http://www.tinloaf.de/~tinloaf/software/powertop-1.98-sysfs.patch
I'm attaching the patch to this Email just in case it disappears from the
net at some point (too many bad links for powertop already).
Could you upgrade debian powertop so that it provides a usable binary for
laptop battery tuning again?
Thanks,
Marc
--
"A mouse is a device used to point at the xterm you want to type in" - A.S.R.
Microsoft is to operating systems ....
.... what McDonalds is to gourmet cooking
Home page: http://marc.merlins.org/
diff -N -r -u powertop-1.98/Makefile powertop-patched/Makefile
--- powertop-1.98/Makefile 2011-05-11 06:48:37.000000000 +0200
+++ powertop-patched/Makefile 2011-10-20 16:06:37.753900039 +0200
@@ -13,7 +13,7 @@
OBJS += process/process.o process/do_process.o process/interrupt.o
process/timer.o process/work.o process/powerconsumer.o process/device.o
DEVS += devices/device.o devices/backlight.o devices/usb.o devices/ahci.o
devices/alsa.o devices/rfkill.o devices/i915-gpu.o devices/thinkpad-fan.o
devices/network.o devices/thinkpad-light.o
DEVS += devices/runtime_pm.o
-DEVS += measurement/measurement.o measurement/acpi.o measurement/extech.o
+DEVS += measurement/measurement.o measurement/acpi.o measurement/sysfs.o
measurement/extech.o
OBJS += $(DEVS)
OBJS += parameters/parameters.o parameters/learn.o parameters/persistent.o
OBJS += calibrate/calibrate.o
diff -N -r -u powertop-1.98/measurement/measurement.cpp
powertop-patched/measurement/measurement.cpp
--- powertop-1.98/measurement/measurement.cpp 2011-05-11 06:48:37.000000000
+0200
+++ powertop-patched/measurement/measurement.cpp 2011-10-20
16:00:50.305782326 +0200
@@ -24,6 +24,7 @@
*/
#include "measurement.h"
#include "acpi.h"
+#include "sysfs.h"
#include "extech.h"
#include "../parameters/parameters.h"
#include "../lib.h"
@@ -103,7 +104,7 @@
return total;
}
-void power_meters_callback(const char *d_name)
+void power_meters_callback_acpi(const char *d_name)
{
class acpi_power_meter *meter;
meter = new(std::nothrow) class acpi_power_meter(d_name);
@@ -111,9 +112,23 @@
power_meters.push_back(meter);
}
+void power_meters_callback_sysfs(const char *d_name)
+{
+ if (strstr(d_name, "AC") ||
+ strstr(d_name, ".")) {
+ return;
+ }
+
+ class sysfs_power_meter *meter;
+ meter = new(std::nothrow) class sysfs_power_meter(d_name);
+ if (meter)
+ power_meters.push_back(meter);
+}
+
void detect_power_meters(void)
{
- process_directory("/proc/acpi/battery", power_meters_callback);
+ process_directory("/proc/acpi/battery", power_meters_callback_acpi);
+ process_directory("/sys/class/power_supply",
power_meters_callback_sysfs);
}
void extech_power_meter(const char *devnode)
diff -N -r -u powertop-1.98/measurement/sysfs.cpp
powertop-patched/measurement/sysfs.cpp
--- powertop-1.98/measurement/sysfs.cpp 1970-01-01 01:00:00.000000000 +0100
+++ powertop-patched/measurement/sysfs.cpp 2011-10-20 16:19:29.289720272
+0200
@@ -0,0 +1,134 @@
+/*
+ * Copyright 2010, Intel Corporation
+ *
+ * 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:
+ * Lukas Barth <m...@tinloaf.de>
+ */
+#include "measurement.h"
+#include "sysfs.h"
+#include <iostream>
+#include <fstream>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+using namespace std;
+
+sysfs_power_meter::sysfs_power_meter(const char *sysfs_name)
+{
+ rate = 0.0;
+ capacity = 0.0;
+ voltage = 0.0;
+ strncpy(battery_name, sysfs_name, sizeof(battery_name));
+}
+
+void sysfs_power_meter::measure(void)
+{
+ char filename[4096];
+ char line[4096];
+ ifstream file;
+
+ rate = 0;
+ voltage = 0;
+ capacity = 0;
+
+ sprintf(filename, "/sys/class/power_supply/%s/status", battery_name);
+
+ file.open(filename, ios::in);
+ if (!file)
+ return;
+ memset(line, 0, 4096);
+ file.getline(line, 4096);
+ if (strstr(line, "Discharging") == NULL) {
+ return; /* not discharging */
+ }
+ file.close();
+
+ sprintf(filename, "/sys/class/power_supply/%s/present", battery_name);
+ file.open(filename, ios::in);
+ if (!file)
+ return;
+ char s;
+ if (!file.eof()) {
+ file >> s;
+ if (s == '0') {
+ return;
+ }
+ }
+ file.close();
+
+ sprintf(filename, "/sys/class/power_supply/%s/voltage_now",
battery_name);
+ file.open(filename, ios::in);
+ if (!file)
+ return;
+ memset(line, 0, 4096);
+ file.getline(line, 4096);
+ voltage = strtoull(line, NULL, 10) / 1000000.0;
+ file.close();
+
+ sprintf(filename, "/sys/class/power_supply/%s/power_now", battery_name);
+ file.open(filename, ios::in);
+ if (!file) {
+ sprintf(filename, "/sys/class/power_supply/%s/current_now",
battery_name);
+ file.open(filename, ios::in);
+ }
+ if (!file)
+ return;
+ memset(line, 0, 4096);
+ file.getline(line, 4096);
+ rate = strtoull(line, NULL, 10) / 1000000.0;
+ file.close();
+
+ sprintf(filename, "/sys/class/power_supply/%s/energy_now",
battery_name);
+ file.open(filename, ios::in);
+ capacity = 1;
+ if (!file) {
+ file.close();
+ sprintf(filename, "/sys/class/power_supply/%s/charge_now",
battery_name);
+ file.open(filename, ios::in);
+ if (!file)
+ return;
+
+ /* W = A * V */
+ capacity = voltage;
+ }
+ memset(line, 0, 4096);
+ file.getline(line, 4096);
+ capacity *= strtoull(line, NULL, 10) / 1000000.0;
+ file.close();
+}
+
+
+void sysfs_power_meter::end_measurement(void)
+{
+ measure();
+}
+
+void sysfs_power_meter::start_measurement(void)
+{
+ /* Sysfs battery state is a lagging indication, lets only measure at
the end */
+}
+
+
+double sysfs_power_meter::joules_consumed(void)
+{
+ return rate;
+}
diff -N -r -u powertop-1.98/measurement/sysfs.h
powertop-patched/measurement/sysfs.h
--- powertop-1.98/measurement/sysfs.h 1970-01-01 01:00:00.000000000 +0100
+++ powertop-patched/measurement/sysfs.h 2011-10-20 16:18:33.016691795
+0200
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2010, Intel Corporation
+ *
+ * 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:
+ * Lukas Barth <m...@tinloaf.de>
+ */
+#ifndef __INCLUDE_GUARD_SYSFS_H
+#define __INCLUDE_GUARD_SYSFS_H
+
+#include "measurement.h"
+
+class sysfs_power_meter: public power_meter {
+ char battery_name[256];
+
+ double capacity;
+ double rate;
+ double voltage;
+ void measure(void);
+public:
+ sysfs_power_meter(const char *_battery_name);
+ virtual void start_measurement(void);
+ virtual void end_measurement(void);
+
+ virtual double joules_consumed(void);
+ virtual double dev_capacity(void) { return capacity; };
+};
+
+#endif