bionic: Update mechanism to detect number of CPU's for msm targets
msm targets use CPU hotplug for power management, which results in
/proc/cpuinfo and /proc/stat to return back incorrect number of
available CPUs for msm configuration.
Use /sys/devices/system/cpu/present instead when indicating total
number of CPUs to userspace processes and let system power
management take care of when to swich CPUs between online/offline
states.
Only 0-N format is supported for detecting number of CPUs.
0-N,M format for detecting number of CPUs is not supported, and is
currently not a valid configuration on msm targets.
ifdef for QCOM_HARDWARE
Change-Id: I40ab2f79ca67cdbf7f1bf87d52007f822ee76269
diff --git a/libc/Android.mk b/libc/Android.mk
index 82ef6ec..59d0065 100644
--- a/libc/Android.mk
+++ b/libc/Android.mk
@@ -487,6 +487,10 @@
-DPOSIX_MISTAKE \
-DLOG_ON_HEAP_ERROR \
+ifeq ($(BOARD_USES_QCOM_HARDWARE),true)
+libc_common_cflags += -DQCOM_HARDWARE
+endif
+
# these macro definitions are required to implement the
# 'timezone' and 'daylight' global variables, as well as
# properly update the 'tm_gmtoff' field in 'struct tm'.
diff --git a/libc/unistd/sysconf.c b/libc/unistd/sysconf.c
index 9377802..c6bf000 100644
--- a/libc/unistd/sysconf.c
+++ b/libc/unistd/sysconf.c
@@ -367,11 +367,19 @@
const char* p;
int count = 0;
+#ifdef QCOM_HARDWARE
+ if (line_parser_init(parser, "/sys/devices/system/cpu/present") < 0)
+#else
if (line_parser_init(parser, "/proc/cpuinfo") < 0)
+#endif
return 1;
while ((p = line_parser_gets(parser))) {
+#ifdef QCOM_HARDWARE
+ if ( sscanf(p, "0-%d", &count) == 1 )
+#else
if ( !memcmp(p, "processor", 9) )
+#endif
count += 1;
}
return (count < 1) ? 1 : count;
@@ -385,11 +393,19 @@
const char* p;
int count = 0;
+#ifdef QCOM_HARDWARE
+ if (line_parser_init(parser, "/sys/devices/system/cpu/present") < 0)
+#else
if (line_parser_init(parser, "/proc/stat") < 0)
+#endif
return 1;
while ((p = line_parser_gets(parser))) {
+#ifdef QCOM_HARDWARE
+ if ( sscanf(p, "0-%d", &count) == 1 )
+#else
if ( !memcmp(p, "cpu", 3) && isdigit(p[3]) )
+#endif
count += 1;
}
return (count < 1) ? 1 : count;