-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding instruction on how to build for Android on README. Included Android patches to build PowerTOP. Signed-off-by: Alexandra Yates <alexandra.yates@linux.intel.com>
- Loading branch information
Alexandra Yates
committed
Mar 19, 2015
1 parent
7a355ca
commit 3f5bccb
Showing
4 changed files
with
666 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
For some reason, ofstream fails to write to sysfs nodes | ||
on Android. So use old-fashion open()/write()/close(). | ||
|
||
Signed-off-by: Daniel Leung <daniel.leung@linux.intel.com> | ||
--- | ||
.../0001-Android-disable-C-exceptions.patch | 34 +++++----------------- | ||
src/lib.cpp | 14 +++++++++ | ||
2 files changed, 22 insertions(+), 26 deletions(-) | ||
|
||
diff --git a/patches/Android/0001-Android-disable-C-exceptions.patch b/patches/Android/0001-Android-disable-C-exceptions.patch | ||
index 435cd95..b11bdc7 100644 | ||
--- a/patches/Android/0001-Android-disable-C-exceptions.patch | ||
+++ b/patches/Android/0001-Android-disable-C-exceptions.patch | ||
@@ -1,4 +1,4 @@ | ||
-From 604d8f6da54524f0f7bfdd7aea91d353b4f1b612 Mon Sep 17 00:00:00 2001 | ||
+From 4570b7d6559047b384c50b4766e168fd5e11db8e Mon Sep 17 00:00:00 2001 | ||
From: Daniel Leung <daniel.leung@intel.com> | ||
Date: Wed, 25 Feb 2015 13:24:14 -0800 | ||
Subject: [PATCH 1/1] Android: disable C++ exceptions | ||
@@ -11,11 +11,11 @@ Signed-off-by: Daniel Leung <daniel.leung@intel.com> | ||
Android.mk | 2 +- | ||
src/devices/ahci.cpp | 8 ++++++++ | ||
src/devices/alsa.cpp | 8 ++++++++ | ||
- src/lib.cpp | 19 +++++++++++++++++++ | ||
- 4 files changed, 36 insertions(+), 1 deletion(-) | ||
+ src/lib.cpp | 15 +++++++++++++++ | ||
+ 4 files changed, 32 insertions(+), 1 deletion(-) | ||
|
||
diff --git a/Android.mk b/Android.mk | ||
-index dd98d0f..f6b8689 100644 | ||
+index 0c95e3a..ff1040a 100644 | ||
--- a/Android.mk | ||
+++ b/Android.mk | ||
@@ -14,7 +14,7 @@ LOCAL_MODULE := powertop | ||
@@ -128,28 +128,10 @@ index a1fca71..ba3c0b6 100644 | ||
p = (end_active - start_active) / (0.001 + end_active + end_inactive - start_active - start_inactive) * 100.0; | ||
report_utilization(name, p); | ||
diff --git a/src/lib.cpp b/src/lib.cpp | ||
-index 0dec0b7..91dac7a 100644 | ||
+index 24d6d07..4812ff1 100644 | ||
--- a/src/lib.cpp | ||
+++ b/src/lib.cpp | ||
-@@ -176,13 +176,17 @@ void write_sysfs(const string &filename, const string &value) | ||
- file.open(filename.c_str(), ios::out); | ||
- if (!file) | ||
- return; | ||
-+#ifndef DISABLE_TRYCATCH | ||
- try | ||
- { | ||
-+#endif | ||
- file << value; | ||
- file.close(); | ||
-+#ifndef DISABLE_TRYCATCH | ||
- } catch (std::exception &exc) { | ||
- return; | ||
- } | ||
-+#endif | ||
- } | ||
- | ||
- int read_sysfs(const string &filename, bool *ok) | ||
-@@ -196,16 +200,23 @@ int read_sysfs(const string &filename, bool *ok) | ||
+@@ -210,16 +210,23 @@ int read_sysfs(const string &filename, bool *ok) | ||
*ok = false; | ||
return 0; | ||
} | ||
@@ -173,7 +155,7 @@ index 0dec0b7..91dac7a 100644 | ||
file.close(); | ||
return i; | ||
} | ||
-@@ -219,17 +230,21 @@ string read_sysfs_string(const string &filename) | ||
+@@ -233,17 +240,21 @@ string read_sysfs_string(const string &filename) | ||
file.open(filename.c_str(), ios::in); | ||
if (!file) | ||
return ""; | ||
@@ -195,7 +177,7 @@ index 0dec0b7..91dac7a 100644 | ||
return content; | ||
} | ||
|
||
-@@ -246,17 +261,21 @@ string read_sysfs_string(const char *format, const char *param) | ||
+@@ -260,17 +271,21 @@ string read_sysfs_string(const char *format, const char *param) | ||
file.open(filename, ios::in); | ||
if (!file) | ||
return ""; | ||
diff --git a/src/lib.cpp b/src/lib.cpp | ||
index 6b1bc0a..24d6d07 100644 | ||
--- a/src/lib.cpp | ||
+++ b/src/lib.cpp | ||
@@ -171,6 +171,7 @@ void set_max_cpu(int cpu) | ||
|
||
void write_sysfs(const string &filename, const string &value) | ||
{ | ||
+#ifndef ANDROID | ||
ofstream file; | ||
|
||
file.open(filename.c_str(), ios::out); | ||
@@ -183,6 +184,19 @@ void write_sysfs(const string &filename, const string &value) | ||
} catch (std::exception &exc) { | ||
return; | ||
} | ||
+#else | ||
+ int fd; | ||
+ | ||
+ fd = ::open(filename.c_str(), O_WRONLY); | ||
+ if (fd < 0) | ||
+ return; | ||
+ | ||
+ ::write(fd, value.c_str(), value.length()); | ||
+ | ||
+ close(fd); | ||
+ | ||
+ return; | ||
+#endif | ||
} | ||
|
||
int read_sysfs(const string &filename, bool *ok) | ||
-- | ||
1.8.3.2 | ||
|
||
_______________________________________________ | ||
PowerTop mailing list | ||
PowerTop@lists.01.org | ||
https://lists.01.org/mailman/listinfo/powertop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
The mbsrtowcs() in Android seems to change the content of | ||
source pointer to 0x00. So save a copy of the source | ||
string so we can manipulate it later, preventing segfaults. | ||
|
||
Signed-off-by: Daniel Leung <daniel.leung@linux.intel.com> | ||
--- | ||
src/lib.cpp | 4 +++- | ||
1 file changed, 3 insertions(+), 1 deletion(-) | ||
|
||
diff --git a/src/lib.cpp b/src/lib.cpp | ||
index 0dec0b7..6b1bc0a 100644 | ||
--- a/src/lib.cpp | ||
+++ b/src/lib.cpp | ||
@@ -263,6 +263,7 @@ string read_sysfs_string(const char *format, const char *param) | ||
void align_string(char *buffer, size_t min_sz, size_t max_sz) | ||
{ | ||
size_t sz; | ||
+ char *buf = buffer; | ||
|
||
/** mbsrtowcs() allows NULL dst and zero sz, | ||
* comparing to mbstowcs(), which causes undefined | ||
@@ -275,8 +276,9 @@ void align_string(char *buffer, size_t min_sz, size_t max_sz) | ||
buffer[min_sz] = 0x00; | ||
return; | ||
} | ||
+ | ||
while (sz < min_sz) { | ||
- strcat(buffer, " "); | ||
+ strcat(buf, " "); | ||
sz++; | ||
} | ||
} | ||
-- | ||
1.8.3.2 | ||
|
||
_______________________________________________ | ||
PowerTop mailing list | ||
PowerTop@lists.01.org | ||
https://lists.01.org/mailman/listinfo/powertop |
Oops, something went wrong.