updated on Thu Jan 12 04:00:44 UTC 2012
[aur-mirror.git] / powertop-sysfs / powertop-1.13-with-3.0.6.patch
blobfc61913a8a2848c24cbf36db7e8327bff1219dd7
1 Common subdirectories: powertop-1.13/kernel-patches and powertop-patched/kernel-patches
2 Common subdirectories: powertop-1.13/po and powertop-patched/po
3 diff -u powertop-1.13/powertop.c powertop-patched/powertop.c
4 --- powertop-1.13/powertop.c 2010-07-20 01:08:21.000000000 +0200
5 +++ powertop-patched/powertop.c 2011-10-20 14:34:41.163951192 +0200
6 @@ -547,95 +547,6 @@
7 qsort (lines, linehead, sizeof (struct line), line_compare);
12 -int print_battery_proc_acpi(void)
14 - DIR *dir;
15 - struct dirent *dirent;
16 - FILE *file;
17 - double rate = 0;
18 - double cap = 0;
20 - char filename[256];
22 - dir = opendir("/proc/acpi/battery");
23 - if (!dir)
24 - return 0;
26 - while ((dirent = readdir(dir))) {
27 - int dontcount = 0;
28 - double voltage = 0.0;
29 - double amperes_drawn = 0.0;
30 - double watts_drawn = 0.0;
31 - double amperes_left = 0.0;
32 - double watts_left = 0.0;
33 - char line[1024];
35 - if (strlen(dirent->d_name) < 3)
36 - continue;
38 - sprintf(filename, "/proc/acpi/battery/%s/state", dirent->d_name);
39 - file = fopen(filename, "r");
40 - if (!file)
41 - continue;
42 - memset(line, 0, 1024);
43 - while (fgets(line, 1024, file) != NULL) {
44 - char *c;
45 - if (strstr(line, "present:") && strstr(line, "no"))
46 - break;
48 - if (strstr(line, "charging state:")
49 - && !strstr(line, "discharging"))
50 - dontcount = 1;
51 - c = strchr(line, ':');
52 - if (!c)
53 - continue;
54 - c++;
56 - if (strstr(line, "present voltage"))
57 - voltage = strtoull(c, NULL, 10) / 1000.0;
59 - if (strstr(line, "remaining capacity") && strstr(c, "mW"))
60 - watts_left = strtoull(c, NULL, 10) / 1000.0;
62 - if (strstr(line, "remaining capacity") && strstr(c, "mAh"))
63 - amperes_left = strtoull(c, NULL, 10) / 1000.0;
65 - if (strstr(line, "present rate") && strstr(c, "mW"))
66 - watts_drawn = strtoull(c, NULL, 10) / 1000.0 ;
68 - if (strstr(line, "present rate") && strstr(c, "mA"))
69 - amperes_drawn = strtoull(c, NULL, 10) / 1000.0;
71 - }
72 - fclose(file);
74 - if (!dontcount) {
75 - rate += watts_drawn + voltage * amperes_drawn;
76 - }
77 - cap += watts_left + voltage * amperes_left;
80 - }
81 - closedir(dir);
82 - if (prev_bat_cap - cap < 0.001 && rate < 0.001)
83 - last_bat_time = 0;
84 - if (!last_bat_time) {
85 - last_bat_time = prev_bat_time = time(NULL);
86 - last_bat_cap = prev_bat_cap = cap;
87 - }
88 - if (time(NULL) - last_bat_time >= 400) {
89 - prev_bat_cap = last_bat_cap;
90 - prev_bat_time = last_bat_time;
91 - last_bat_time = time(NULL);
92 - last_bat_cap = cap;
93 - }
95 - show_acpi_power_line(rate, cap, prev_bat_cap - cap, time(NULL) - prev_bat_time);
96 - return 1;
99 int print_battery_proc_pmu(void)
101 char line[80];
102 @@ -719,9 +630,6 @@
104 char filename[256];
106 - if (print_battery_proc_acpi())
107 - return;
109 if (print_battery_proc_pmu())
110 return;
112 @@ -733,7 +641,6 @@
113 while ((dirent = readdir(dir))) {
114 int dontcount = 0;
115 double voltage = 0.0;
116 - double amperes_drawn = 0.0;
117 double watts_drawn = 0.0;
118 double watts_left = 0.0;
119 char line[1024];
120 @@ -790,8 +697,12 @@
121 watts_left *= strtoull(line, NULL, 10) / 1000000.0;
122 fclose(file);
124 - sprintf(filename, "/sys/class/power_supply/%s/current_now", dirent->d_name);
125 + sprintf(filename, "/sys/class/power_supply/%s/power_now", dirent->d_name);
126 file = fopen(filename, "r");
127 + if (!file) {
128 + sprintf(filename, "/sys/class/power_supply/%s/current_now", dirent->d_name);
129 + file = fopen(filename, "r");
131 if (!file)
132 continue;
133 memset(line, 0, 1024);
134 @@ -801,7 +712,7 @@
135 fclose(file);
137 if (!dontcount) {
138 - rate += watts_drawn + voltage * amperes_drawn;
139 + rate += watts_drawn;
141 cap += watts_left;