Attached patch is updated vetsion of the previous one with the fixed
rate calculation (/sys/class/power_supply/*/current_* are in ľA
according to the linux-src/Documentation/power/power_supply_class.txt
and not in ľW as expected by the original code).

Please note that I don't have any notebook which provides energy_now so
I am not able to test if doesn't break powertop for this interface.

I am also rather surprised that original calculation of rate worked as
it obviously calculates bad value.
-- 
Michal Hocko
From: [EMAIL PROTECTED]
Subject: [PATCH] use charge_now when energy_now is not present

Some batteries (like one in the Futjitsu Siemens Lifebook S71110) don't
export energy_now attribute and exports only change_now in the power_supply
sys directory. 
However, we can use this value when it is multiplied by current voltage.

In addition, /sys/class/power_supply/*/current_* are in ľA according to the
linux-src/Documentation/power/power_supply_class.txt and not in ľW as
expected by the original code

Signed-off-by: Michal Hocko <[EMAIL PROTECTED]>

Index: powertop/powertop.c
===================================================================
--- powertop.orig/powertop.c	2008-09-01 14:19:21.000000000 -0600
+++ powertop/powertop.c	2008-09-01 14:27:07.000000000 -0600
@@ -630,12 +630,19 @@ void print_battery_sysfs(void)
 
 		sprintf(filename, "/sys/class/power_supply/%s/energy_now", dirent->d_name);
 		file = fopen(filename, "r");
-		if (!file)
-			continue;
-		memset(line, 0, 1024);
-		if (fgets(line, 1024, file) != NULL) {
-			watts_left = strtoull(line, NULL, 10) / 1000000.0;
+		watts_left = 1;
+		if (!file) {
+			sprintf(filename, "/sys/class/power_supply/%s/charge_now", dirent->d_name);
+			file = fopen(filename, "r");
+			if (!file) 
+				continue;
+
+			/* W = A * V */
+			watts_left = voltage;
 		}
+		memset(line, 0, 1024);
+		if (fgets(line, 1024, file) != NULL) 
+			watts_left *= strtoull(line, NULL, 10) / 1000000.0;
 		fclose(file);
 
 		sprintf(filename, "/sys/class/power_supply/%s/current_now", dirent->d_name);
@@ -644,7 +651,7 @@ void print_battery_sysfs(void)
 			continue;
 		memset(line, 0, 1024);
 		if (fgets(line, 1024, file) != NULL) {
-			watts_drawn = strtoull(line, NULL, 10) / 1000000.0;
+			amperes_drawn = strtoull(line, NULL, 10) / 1000000.0;
 		}
 		fclose(file);
 	

Reply via email to