diff options
author | Russ Cox <rsc@golang.org> | 2014-08-14 14:34:25 -0400 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2014-08-14 14:34:25 -0400 |
commit | f3632613eff2a93279fa9d357832e4d4c7d4b9bc (patch) | |
tree | be6bd35e9c8a0698393d50a3b402be87ebffa6ad /src/pkg | |
parent | 74cc0ef0595c8290c34ca664a896d0c3b8ebfeee (diff) | |
download | go-f3632613eff2a93279fa9d357832e4d4c7d4b9bc.tar.gz |
[dev.power64] runtime: replace getproccount with simpler code
This runs once. There is no need for inscrutable algorithms.
Also it doesn't compile correctly with 9c.
LGTM=minux
R=minux
CC=golang-codereviews
https://codereview.appspot.com/130000043
Diffstat (limited to 'src/pkg')
-rw-r--r-- | src/pkg/runtime/os_linux.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/pkg/runtime/os_linux.c b/src/pkg/runtime/os_linux.c index b9ac8c619..1751ea83b 100644 --- a/src/pkg/runtime/os_linux.c +++ b/src/pkg/runtime/os_linux.c @@ -78,19 +78,22 @@ static int32 getproccount(void) { uintptr buf[16], t; - int32 r, cnt, i; + int32 r, n, i; - cnt = 0; r = runtime·sched_getaffinity(0, sizeof(buf), buf); - if(r > 0) + if(r <= 0) + return 1; + n = 0; for(i = 0; i < r/sizeof(buf[0]); i++) { t = buf[i]; - t = t - ((t >> 1) & 0x5555555555555555ULL); - t = (t & 0x3333333333333333ULL) + ((t >> 2) & 0x3333333333333333ULL); - cnt += (int32)((((t + (t >> 4)) & 0xF0F0F0F0F0F0F0FULL) * 0x101010101010101ULL) >> 56); + while(t != 0) { + n += t&1; + t >>= 1; + } } - - return cnt ? cnt : 1; + if(n < 1) + n = 1; + return n; } // Clone, the Linux rfork. |