From 32b1d51f16fe56b34e979fcfba4bc74dbd3592a9 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Wed, 28 Aug 2019 20:39:32 +0000 Subject: runtime: move osinit to Go This is a step toward updating libgo to 1.13. This adds the 1.13 version of the osinit function to Go code, and removes the corresponding code from the C runtime. This should simplify future updates. Some additional 1.13 code was brought in to simplify this change. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/191717 From-SVN: r275010 --- libgo/runtime/getncpu-aix.c | 15 --------------- libgo/runtime/getncpu-bsd.c | 24 ------------------------ libgo/runtime/getncpu-hurd.c | 16 ---------------- libgo/runtime/getncpu-irix.c | 16 ---------------- libgo/runtime/getncpu-linux.c | 36 ------------------------------------ libgo/runtime/getncpu-none.c | 12 ------------ libgo/runtime/getncpu-solaris.c | 16 ---------------- libgo/runtime/go-libmain.c | 3 +-- libgo/runtime/go-main.c | 3 +-- libgo/runtime/runtime.h | 8 ++------ 10 files changed, 4 insertions(+), 145 deletions(-) delete mode 100644 libgo/runtime/getncpu-aix.c delete mode 100644 libgo/runtime/getncpu-bsd.c delete mode 100644 libgo/runtime/getncpu-hurd.c delete mode 100644 libgo/runtime/getncpu-irix.c delete mode 100644 libgo/runtime/getncpu-linux.c delete mode 100644 libgo/runtime/getncpu-none.c delete mode 100644 libgo/runtime/getncpu-solaris.c (limited to 'libgo/runtime') diff --git a/libgo/runtime/getncpu-aix.c b/libgo/runtime/getncpu-aix.c deleted file mode 100644 index 064eed8..0000000 --- a/libgo/runtime/getncpu-aix.c +++ /dev/null @@ -1,15 +0,0 @@ -// 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 -#include - -#include "runtime.h" -#include "defs.h" - -int32_t -getproccount(void) -{ - return _system_configuration.ncpus; -} diff --git a/libgo/runtime/getncpu-bsd.c b/libgo/runtime/getncpu-bsd.c deleted file mode 100644 index 00a81d1..0000000 --- a/libgo/runtime/getncpu-bsd.c +++ /dev/null @@ -1,24 +0,0 @@ -// 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 -#include - -#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-hurd.c b/libgo/runtime/getncpu-hurd.c deleted file mode 100644 index 5d5d702..0000000 --- a/libgo/runtime/getncpu-hurd.c +++ /dev/null @@ -1,16 +0,0 @@ -// 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 - -#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/getncpu-irix.c b/libgo/runtime/getncpu-irix.c deleted file mode 100644 index a65ca63..0000000 --- a/libgo/runtime/getncpu-irix.c +++ /dev/null @@ -1,16 +0,0 @@ -// 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 - -#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 deleted file mode 100644 index de6606f..0000000 --- a/libgo/runtime/getncpu-linux.c +++ /dev/null @@ -1,36 +0,0 @@ -// 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 -#include - -// CPU_COUNT is only provided by glibc 2.6 or higher -#ifndef CPU_COUNT -#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 deleted file mode 100644 index ba6fd4e..0000000 --- a/libgo/runtime/getncpu-none.c +++ /dev/null @@ -1,12 +0,0 @@ -// 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 deleted file mode 100644 index 5d5d702..0000000 --- a/libgo/runtime/getncpu-solaris.c +++ /dev/null @@ -1,16 +0,0 @@ -// 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 - -#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-libmain.c b/libgo/runtime/go-libmain.c index f379569..10b202b 100644 --- a/libgo/runtime/go-libmain.c +++ b/libgo/runtime/go-libmain.c @@ -228,8 +228,7 @@ gostart (void *arg) runtime_ginit (); runtime_check (); runtime_args (a->argc, (byte **) a->argv); - setncpu (getproccount ()); - setpagesize (getpagesize ()); + runtime_osinit (); runtime_schedinit (); __go_go ((uintptr)(runtime_main), NULL); runtime_mstart (runtime_m ()); diff --git a/libgo/runtime/go-main.c b/libgo/runtime/go-main.c index 51ce15f..dcf763a 100644 --- a/libgo/runtime/go-main.c +++ b/libgo/runtime/go-main.c @@ -52,8 +52,7 @@ main (int argc, char **argv) runtime_cpuinit (); runtime_check (); runtime_args (argc, (byte **) argv); - setncpu (getproccount ()); - setpagesize (getpagesize ()); + runtime_osinit (); runtime_schedinit (); __go_go ((uintptr)(runtime_main), NULL); runtime_mstart (runtime_m ()); diff --git a/libgo/runtime/runtime.h b/libgo/runtime/runtime.h index 6da7bdf..4102f5d 100644 --- a/libgo/runtime/runtime.h +++ b/libgo/runtime/runtime.h @@ -211,6 +211,8 @@ void runtime_gogo(G*) struct __go_func_type; void runtime_args(int32, byte**) __asm__ (GOSYM_PREFIX "runtime.args"); +void runtime_osinit(void) + __asm__ (GOSYM_PREFIX "runtime.osinit"); void runtime_alginit(void) __asm__ (GOSYM_PREFIX "runtime.alginit"); void runtime_goargs(void) @@ -429,8 +431,6 @@ extern void __go_syminfo_fnname_callback(void*, uintptr_t, const char*, extern void runtime_main(void*) __asm__(GOSYM_PREFIX "runtime.main"); -int32 getproccount(void); - #define PREFETCH(p) __builtin_prefetch(p) void runtime_badsignal(int); @@ -456,12 +456,8 @@ extern void setSupportAES(bool) __asm__ (GOSYM_PREFIX "runtime.setSupportAES"); extern void typedmemmove(const Type *, void *, const void *) __asm__ (GOSYM_PREFIX "runtime.typedmemmove"); -extern void setncpu(int32) - __asm__(GOSYM_PREFIX "runtime.setncpu"); extern Sched* runtime_getsched(void) __asm__ (GOSYM_PREFIX "runtime.getsched"); -extern void setpagesize(uintptr_t) - __asm__(GOSYM_PREFIX "runtime.setpagesize"); struct funcfileline_return { -- cgit v1.1