зеркало из https://github.com/github/ruby.git
* ext/etc/etc.c (etc_nprocessors_affin): optimize memory usege a
bit. Typical rubyist never use 8k cpus machine. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48080 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
a4f0db49ab
Коммит
0fa75e813e
|
@ -1,3 +1,8 @@
|
|||
Wed Oct 22 03:33:58 2014 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
||||
|
||||
* ext/etc/etc.c (etc_nprocessors_affin): optimize memory usege a
|
||||
bit. Typical rubyist never use 8k cpus machine.
|
||||
|
||||
Wed Oct 22 00:01:09 2014 Yuki Yugui Sonoda <yugui@yugui.jp>
|
||||
|
||||
* configure.in (XCFLAGS): Add include path for NaCl libraries.
|
||||
|
|
|
@ -916,7 +916,7 @@ etc_nprocessors_affin(void)
|
|||
cpu_set_t *cpuset;
|
||||
size_t size;
|
||||
int ret;
|
||||
int ncpus;
|
||||
int n;
|
||||
|
||||
/*
|
||||
* XXX:
|
||||
|
@ -934,23 +934,30 @@ etc_nprocessors_affin(void)
|
|||
* So, we use hardcode number for workaround. Current linux kernel
|
||||
* (Linux 3.17) support 8192 cpus at maximum. Then 16384 is enough large.
|
||||
*/
|
||||
ncpus = 16384;
|
||||
|
||||
cpuset = CPU_ALLOC(ncpus);
|
||||
if (!cpuset) {
|
||||
for (n=64; n < 16384; n *= 2) {
|
||||
size = CPU_ALLOC_SIZE(n);
|
||||
if (size >= 1024) {
|
||||
cpuset = xcalloc(1, size);
|
||||
if (!cpuset)
|
||||
return -1;
|
||||
}
|
||||
size = CPU_ALLOC_SIZE(ncpus);
|
||||
} else {
|
||||
cpuset = alloca(size);
|
||||
CPU_ZERO_S(size, cpuset);
|
||||
}
|
||||
|
||||
ret = sched_getaffinity(0, size, cpuset);
|
||||
if (ret==-1) {
|
||||
goto free;
|
||||
if (ret == 0) {
|
||||
/* On success, count number of cpus. */
|
||||
ret = CPU_COUNT_S(size, cpuset);
|
||||
}
|
||||
|
||||
ret = CPU_COUNT_S(size, cpuset);
|
||||
free:
|
||||
CPU_FREE(cpuset);
|
||||
if (size >= 1024) {
|
||||
xfree(cpuset);
|
||||
}
|
||||
if (ret > 0) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче