diff options
author | bstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-08-29 12:37:05 +0000 |
---|---|---|
committer | bstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-08-29 12:37:05 +0000 |
commit | 12cb78d1cca1387a092ec0bd49c250340bff4afc (patch) | |
tree | 1eab97da96906e0a2786d51d9f25f20de02befcf /libgo/runtime | |
parent | 31879e18aea3222fe3e56f2c0319c9f230645ff3 (diff) | |
download | gcc-12cb78d1cca1387a092ec0bd49c250340bff4afc.tar.gz |
2012-08-29 Basile Starynkevitch <basile@starynkevitch.net>
MELT branch merged with trunk rev 190745 using svnmerge, notably
C++ conversion.
[gcc/]
2012-08-29 Basile Starynkevitch <basile@starynkevitch.net>
{{merging with trunk, converted to C++}}
* melt-runtime.h (MELT_FLEXIBLE_DIM): Set when C++.
* melt-runtime.c (melt_tempdir_path): Don't use choose_tmpdir from
libiberty.
(meltgc_start_module_by_index): Use address-of & on VEC_index.
(melt_really_initialize): When printing builtin settings, handle
GCC 4.8 as with implicit ENABLE_BUILD_WITH_CXX.
(meltgc_out_edge): Provide additional flag TDF_DETAILS for dump_edge_info.
(melt_val2passflag): Handle PROP_referenced_vars only when defined.
* melt-module.mk: Use GCCMELT_COMPILER instead of GCCMELT_CC.
* melt-build-script.tpl: Transmit GCCMELT_COMPILER on every make
using melt-module.mk and improve the error message.
* melt-build-script.sh: Regenerate.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/melt-branch@190778 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/runtime')
-rw-r--r-- | libgo/runtime/getncpu-bsd.c | 24 | ||||
-rw-r--r-- | libgo/runtime/getncpu-irix.c | 16 | ||||
-rw-r--r-- | libgo/runtime/getncpu-linux.c | 36 | ||||
-rw-r--r-- | libgo/runtime/getncpu-none.c | 12 | ||||
-rw-r--r-- | libgo/runtime/getncpu-solaris.c | 16 | ||||
-rw-r--r-- | libgo/runtime/go-new-map.c | 4 | ||||
-rw-r--r-- | libgo/runtime/go-signal.c | 3 | ||||
-rw-r--r-- | libgo/runtime/proc.c | 5 | ||||
-rw-r--r-- | libgo/runtime/runtime.h | 4 | ||||
-rw-r--r-- | libgo/runtime/thread-linux.c | 36 | ||||
-rw-r--r-- | libgo/runtime/thread-sema.c | 1 |
11 files changed, 112 insertions, 45 deletions
diff --git a/libgo/runtime/getncpu-bsd.c b/libgo/runtime/getncpu-bsd.c new file mode 100644 index 00000000000..00a81d1ddae --- /dev/null +++ b/libgo/runtime/getncpu-bsd.c @@ -0,0 +1,24 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include <sys/types.h> +#include <sys/sysctl.h> + +#include "runtime.h" +#include "defs.h" + +int32 +getproccount(void) +{ + int mib[2], out; + size_t len; + + mib[0] = CTL_HW; + mib[1] = HW_NCPU; + len = sizeof(out); + if(sysctl(mib, 2, &out, &len, NULL, 0) >= 0) + return (int32)out; + else + return 0; +} diff --git a/libgo/runtime/getncpu-irix.c b/libgo/runtime/getncpu-irix.c new file mode 100644 index 00000000000..a65ca63d2ae --- /dev/null +++ b/libgo/runtime/getncpu-irix.c @@ -0,0 +1,16 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include <unistd.h> + +#include "runtime.h" +#include "defs.h" + +int32 +getproccount(void) +{ + int32 n; + n = (int32)sysconf(_SC_NPROC_ONLN); + return n > 1 ? n : 1; +} diff --git a/libgo/runtime/getncpu-linux.c b/libgo/runtime/getncpu-linux.c new file mode 100644 index 00000000000..0122b77c9ff --- /dev/null +++ b/libgo/runtime/getncpu-linux.c @@ -0,0 +1,36 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include <features.h> +#include <sched.h> + +// CPU_COUNT is only provided by glibc 2.6 or higher +#if !defined(__GLIBC_PREREQ) || !__GLIBC_PREREQ(2, 6) +#define CPU_COUNT(set) _CPU_COUNT((unsigned int *)(set), sizeof(*(set))/sizeof(unsigned int)) +static int _CPU_COUNT(unsigned int *set, size_t len) { + int cnt; + + cnt = 0; + while (len--) + cnt += __builtin_popcount(*set++); + return cnt; +} +#endif + +#include "runtime.h" +#include "defs.h" + +int32 +getproccount(void) +{ + cpu_set_t set; + int32 r, cnt; + + cnt = 0; + r = sched_getaffinity(0, sizeof(set), &set); + if(r == 0) + cnt += CPU_COUNT(&set); + + return cnt ? cnt : 1; +} diff --git a/libgo/runtime/getncpu-none.c b/libgo/runtime/getncpu-none.c new file mode 100644 index 00000000000..ba6fd4e689d --- /dev/null +++ b/libgo/runtime/getncpu-none.c @@ -0,0 +1,12 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "runtime.h" +#include "defs.h" + +int32 +getproccount(void) +{ + return 0; +} diff --git a/libgo/runtime/getncpu-solaris.c b/libgo/runtime/getncpu-solaris.c new file mode 100644 index 00000000000..5d5d7025dfe --- /dev/null +++ b/libgo/runtime/getncpu-solaris.c @@ -0,0 +1,16 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include <unistd.h> + +#include "runtime.h" +#include "defs.h" + +int32 +getproccount(void) +{ + int32 n; + n = (int32)sysconf(_SC_NPROCESSORS_ONLN); + return n > 1 ? n : 1; +} diff --git a/libgo/runtime/go-new-map.c b/libgo/runtime/go-new-map.c index eef71ddf47c..64466183924 100644 --- a/libgo/runtime/go-new-map.c +++ b/libgo/runtime/go-new-map.c @@ -90,9 +90,9 @@ __go_map_next_prime (uintptr_t n) /* Here LOW <= MID < HIGH. */ if (prime_list[mid] < n) - high = mid; - else if (prime_list[mid] > n) low = mid + 1; + else if (prime_list[mid] > n) + high = mid; else return n; } diff --git a/libgo/runtime/go-signal.c b/libgo/runtime/go-signal.c index 5d398b04a02..9fbe86e0c51 100644 --- a/libgo/runtime/go-signal.c +++ b/libgo/runtime/go-signal.c @@ -149,8 +149,7 @@ sig_handler (int sig) #ifdef SIGPROF if (sig == SIGPROF) { - /* FIXME. */ - runtime_sigprof (0, 0, nil, nil); + runtime_sigprof (); return; } #endif diff --git a/libgo/runtime/proc.c b/libgo/runtime/proc.c index e3befbec996..224dce95ba0 100644 --- a/libgo/runtime/proc.c +++ b/libgo/runtime/proc.c @@ -1681,10 +1681,7 @@ static struct { // Called if we receive a SIGPROF signal. void -runtime_sigprof(uint8 *pc __attribute__ ((unused)), - uint8 *sp __attribute__ ((unused)), - uint8 *lr __attribute__ ((unused)), - G *gp __attribute__ ((unused))) +runtime_sigprof() { int32 n; diff --git a/libgo/runtime/runtime.h b/libgo/runtime/runtime.h index 76a9eef4fd6..cebc1fd9801 100644 --- a/libgo/runtime/runtime.h +++ b/libgo/runtime/runtime.h @@ -451,7 +451,7 @@ const byte* runtime_getenv(const char*); int32 runtime_atoi(const byte*); uint32 runtime_fastrand1(void); -void runtime_sigprof(uint8 *pc, uint8 *sp, uint8 *lr, G *gp); +void runtime_sigprof(); void runtime_resetcpuprofiler(int32); void runtime_setcpuprofilerate(void(*)(uintptr*, int32), int32); void runtime_usleep(uint32); @@ -518,3 +518,5 @@ void __go_register_gc_roots(struct root_list*); extern uintptr runtime_stacks_sys; extern _Bool __go_file_line (uintptr, String*, String*, int *); + +int32 getproccount(void); diff --git a/libgo/runtime/thread-linux.c b/libgo/runtime/thread-linux.c index 0014068b2cd..13d23c47b07 100644 --- a/libgo/runtime/thread-linux.c +++ b/libgo/runtime/thread-linux.c @@ -72,42 +72,6 @@ runtime_futexwakeup(uint32 *addr, uint32 cnt) *(int32*)0x1006 = 0x1006; } -#ifndef O_CLOEXEC -#define O_CLOEXEC 0 -#endif - -static int32 -getproccount(void) -{ - int32 fd, rd, cnt, cpustrlen; - const char *cpustr; - const byte *pos; - byte *bufpos; - byte buf[256]; - - fd = open("/proc/stat", O_RDONLY|O_CLOEXEC, 0); - if(fd == -1) - return 1; - cnt = 0; - bufpos = buf; - cpustr = "\ncpu"; - cpustrlen = strlen(cpustr); - for(;;) { - rd = read(fd, bufpos, sizeof(buf)-cpustrlen); - if(rd == -1) - break; - bufpos[rd] = 0; - for(pos=buf; (pos=(const byte*)strstr((const char*)pos, cpustr)) != nil; cnt++, pos++) { - } - if(rd < cpustrlen) - break; - memmove(buf, bufpos+rd-cpustrlen+1, cpustrlen-1); - bufpos = buf+cpustrlen-1; - } - close(fd); - return cnt ? cnt : 1; -} - void runtime_osinit(void) { diff --git a/libgo/runtime/thread-sema.c b/libgo/runtime/thread-sema.c index 7d0acfb1ce1..18827b025d7 100644 --- a/libgo/runtime/thread-sema.c +++ b/libgo/runtime/thread-sema.c @@ -138,6 +138,7 @@ runtime_semawakeup (M *mp) void runtime_osinit (void) { + runtime_ncpu = getproccount(); } void |