diff options
author | Geunsik Lim <geunsik.lim@samsung.com> | 2013-03-05 21:01:07 +0900 |
---|---|---|
committer | Geunsik Lim <geunsik.lim@samsung.com> | 2013-03-06 10:18:50 +0900 |
commit | b3cd55a4e23e443cc4561424e22c27fe7f05b5c1 (patch) | |
tree | 985420293e0e9f151c8267e153008e14897d5075 /gcc-4.4.3/contrib | |
parent | 125708b8e3afa6007ce3aa7132165d27b719ccc3 (diff) | |
download | toolchain_gcc-b3cd55a4e23e443cc4561424e22c27fe7f05b5c1.tar.gz toolchain_gcc-b3cd55a4e23e443cc4561424e22c27fe7f05b5c1.tar.bz2 toolchain_gcc-b3cd55a4e23e443cc4561424e22c27fe7f05b5c1.zip |
OpenMP: Better CPU count detection for Linux
.PURPOSE
This patch is to improve the detection of total CPU count for OpenMP/Linux.
This patch helps that OpenMP recognizes the actual CPUs correctly for
the task parallelism.
Recent mobile devices dynamically disable or enable CPU cores on demand to
optimize battery life. This impacts the output of '/proc/cpuinfo' (which only
reports active ones). This patch provides a way to compute the total
number of cores by parsing the content of '/sys/devices/system/cpu/' instead.
Actual CPUs: total installed CPUs
Online's CPUs: CPUs of the turn-on status
Offline's CPUs: CPUs of the turn-off status
Therefore, We need to enhance the existing approach using procfs like
'/proc/cpuinfo/' or '/proc/stat'. This patch is suitable for Linux kernel.
This patch is based on GCC 4.7.2.
.RELATED LINKS:
https://android-review.googlesource.com/#/c/52821/
https://android-review.googlesource.com/#/c/51950/
https://android-review.googlesource.com/#/c/51370/
https://android.googlesource.com/toolchain/gcc/
.UNIT TEST
int main (int argc, char *argv[])
{ int nthreads, tid;
printf("SC_NPROCESSORS_ONLN: %d\n", sysconf (_SC_NPROCESSORS_ONLN));
/* Fork a team of threads giving them their own copies of variables */
{
/* Obtain thread number */
tid = omp_get_thread_num();
printf("Hello World from thread = %d\n", tid);
/* Only master thread does this */
if (tid == 0)
{
nthreads = omp_get_num_threads();
printf("Number of threads = %d\n", nthreads);
}
} /* All threads join master thread and disband */
}
.LIMITATION OF SCOPE
These functions have to be included in Bionic C library
as the resource of sysconf().
Examples:
_SC_NPROCESSORS_ONLN /proc/stat (= /sys/devices/system/cpu/online)
_SC_NPROCESSORS_CONF /proc/cpuinfo (= /sys/devices/system/cpu/online)
_SC_NPROCESSORS_ACTU /sys/devices/system/cpu/present (* Future work)
.COST EVALUATION OF SYSCALLS (On 32bit Quad core)
------------------------------------------
time seconds usecs/call calls syscall
------------------------------------------
-nan 0.000000 0 3 read
-nan 0.000000 0 9 write
-nan 0.000000 0 4 open
-nan 0.000000 0 4 close
-nan 0.000000 0 1 execve
-nan 0.000000 0 1 access
-nan 0.000000 0 1 brk
-nan 0.000000 0 1 munmap
-nan 0.000000 0 2 mprotect
-nan 0.000000 0 7 mmap2
-nan 0.000000 0 3 fstat64
-nan 0.000000 0 1 set_thread_area
------------------------------------------
100 0.000000 0 37 total
Change-Id: I2c6e41616f309eee89ee1145e92201ffe73463f4
Signed-off-by: Geunsik Lim <leemgs@gmail.com>
Signed-off-by: Geunsik Lim <geunsik.lim@samsung.com>
Acked-by: Changwoo Min <multics69@gmail.com>
CC: David Turner <digit@android.com>
CC: Keith Obenschain <obenschaink@gmail.com>
CC: Pavel Chupin <pavel.v.chupin@intel.com>
CC: Andrew Hsieh <andrewhsieh@google.com>
Diffstat (limited to 'gcc-4.4.3/contrib')
0 files changed, 0 insertions, 0 deletions