From 350767bf22688f7645fe959370240825a3cf0421 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Wed, 16 Nov 2016 18:33:11 +0000 Subject: [PATCH] runtime: replace runtime1.goc with Go and C code A step toward eliminating goc2c. Drop the exported parfor code; it was needed for tests in the past, but no longer is. The Go 1.7 runtime no longer uses parfor. Reviewed-on: https://go-review.googlesource.com/33324 From-SVN: r242509 --- gcc/go/gofrontend/MERGE | 2 +- libgo/Makefile.am | 5 -- libgo/Makefile.in | 8 +--- libgo/go/runtime/debug.go | 17 ++++++- libgo/go/runtime/error.go | 5 +- libgo/go/runtime/export_test.go | 28 +---------- libgo/go/runtime/extern.go | 4 +- libgo/go/runtime/stubs.go | 1 + libgo/runtime/proc.c | 74 +++++++++++++++++++++++++++-- libgo/runtime/runtime.h | 4 +- libgo/runtime/runtime1.goc | 82 --------------------------------- 11 files changed, 96 insertions(+), 134 deletions(-) delete mode 100644 libgo/runtime/runtime1.goc diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index 56ba8a56a0f..20e085974c8 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -31ff8c31d33c3e77cae4fd55445f12825eb92af5 +d9189ebc139ff739af956094626ccc5eb92c3091 The first line of this file holds the git revision number of the last merge done from the gofrontend repository. diff --git a/libgo/Makefile.am b/libgo/Makefile.am index b29f6c4ff57..534a7b225c4 100644 --- a/libgo/Makefile.am +++ b/libgo/Makefile.am @@ -485,7 +485,6 @@ runtime_files = \ runtime/yield.c \ $(rtems_task_variable_add_file) \ malloc.c \ - runtime1.c \ $(runtime_getncpu_file) goc2c.$(OBJEXT): runtime/goc2c.c @@ -498,10 +497,6 @@ malloc.c: $(srcdir)/runtime/malloc.goc goc2c ./goc2c $< > $@.tmp mv -f $@.tmp $@ -runtime1.c: $(srcdir)/runtime/runtime1.goc goc2c - ./goc2c $< > $@.tmp - mv -f $@.tmp $@ - %.c: $(srcdir)/runtime/%.goc goc2c ./goc2c $< > $@.tmp mv -f $@.tmp $@ diff --git a/libgo/Makefile.in b/libgo/Makefile.in index 44a6999c206..9edcf37011b 100644 --- a/libgo/Makefile.in +++ b/libgo/Makefile.in @@ -204,7 +204,7 @@ am__objects_5 = go-assert.lo go-breakpoint.lo go-caller.lo \ mcentral.lo $(am__objects_1) mfixalloc.lo mgc0.lo mheap.lo \ msize.lo panic.lo parfor.lo print.lo proc.lo runtime_c.lo \ thread.lo $(am__objects_2) yield.lo $(am__objects_3) malloc.lo \ - runtime1.lo $(am__objects_4) + $(am__objects_4) am_libgo_llgo_la_OBJECTS = $(am__objects_5) libgo_llgo_la_OBJECTS = $(am_libgo_llgo_la_OBJECTS) libgo_llgo_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ @@ -832,7 +832,6 @@ runtime_files = \ runtime/yield.c \ $(rtems_task_variable_add_file) \ malloc.c \ - runtime1.c \ $(runtime_getncpu_file) noinst_DATA = zstdpkglist.go @@ -1520,7 +1519,6 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/print.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/proc.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rtems-task-variable-add.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/runtime1.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/runtime_c.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/thread-linux.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/thread-sema.Plo@am__quote@ @@ -3161,10 +3159,6 @@ malloc.c: $(srcdir)/runtime/malloc.goc goc2c ./goc2c $< > $@.tmp mv -f $@.tmp $@ -runtime1.c: $(srcdir)/runtime/runtime1.goc goc2c - ./goc2c $< > $@.tmp - mv -f $@.tmp $@ - %.c: $(srcdir)/runtime/%.goc goc2c ./goc2c $< > $@.tmp mv -f $@.tmp $@ diff --git a/libgo/go/runtime/debug.go b/libgo/go/runtime/debug.go index 56e307fb3f5..43f6e1e00f6 100644 --- a/libgo/go/runtime/debug.go +++ b/libgo/go/runtime/debug.go @@ -4,6 +4,11 @@ package runtime +import ( + "runtime/internal/atomic" + "unsafe" +) + // GOMAXPROCS sets the maximum number of CPUs that can be executing // simultaneously and returns the previous setting. If n < 1, it does not // change the current setting. @@ -19,10 +24,18 @@ func GOMAXPROCS(n int) int func NumCPU() int // NumCgoCall returns the number of cgo calls made by the current process. -func NumCgoCall() int64 +func NumCgoCall() int64 { + var n int64 + for mp := (*m)(atomic.Loadp(unsafe.Pointer(allm()))); mp != nil; mp = mp.alllink { + n += int64(mp.ncgocall) + } + return n +} // NumGoroutine returns the number of goroutines that currently exist. -func NumGoroutine() int +func NumGoroutine() int { + return int(gcount()) +} // Get field tracking information. Only fields with a tag go:"track" // are tracked. This function will add every such field that is diff --git a/libgo/go/runtime/error.go b/libgo/go/runtime/error.go index 36830016a5b..d5d502c396d 100644 --- a/libgo/go/runtime/error.go +++ b/libgo/go/runtime/error.go @@ -133,7 +133,10 @@ type stringer interface { String() string } -func typestring(interface{}) string +func typestring(x interface{}) string { + e := efaceOf(&x) + return *e._type.string +} // For calling from C. // Prints an argument passed to panic. diff --git a/libgo/go/runtime/export_test.go b/libgo/go/runtime/export_test.go index d3443566d92..b8b129d815d 100644 --- a/libgo/go/runtime/export_test.go +++ b/libgo/go/runtime/export_test.go @@ -21,11 +21,10 @@ import ( //var F64toint = f64toint //var Sqrt = sqrt -func golockedOSThread() bool - var Entersyscall = entersyscall var Exitsyscall = exitsyscall -var LockedOSThread = golockedOSThread + +// var LockedOSThread = lockedOSThread // var Xadduintptr = xadduintptr @@ -44,29 +43,6 @@ func LFStackPop(head *uint64) *LFNode { return (*LFNode)(unsafe.Pointer(lfstackpop(head))) } -type ParFor struct { - body func(*ParFor, uint32) - done uint32 - Nthr uint32 - thrseq uint32 - Cnt uint32 - wait bool -} - -func newParFor(nthrmax uint32) *ParFor -func parForSetup(desc *ParFor, nthr, n uint32, wait bool, body func(*ParFor, uint32)) -func parForDo(desc *ParFor) -func parForIters(desc *ParFor, tid uintptr) (uintptr, uintptr) - -var NewParFor = newParFor -var ParForSetup = parForSetup -var ParForDo = parForDo - -func ParForIters(desc *ParFor, tid uint32) (uint32, uint32) { - begin, end := parForIters(desc, uintptr(tid)) - return uint32(begin), uint32(end) -} - func GCMask(x interface{}) (ret []byte) { return nil } diff --git a/libgo/go/runtime/extern.go b/libgo/go/runtime/extern.go index e0c5aacc55a..c0746878c4f 100644 --- a/libgo/go/runtime/extern.go +++ b/libgo/go/runtime/extern.go @@ -274,13 +274,11 @@ func SetFinalizer(obj interface{}, finalizer interface{}) // the actual system call. func KeepAlive(interface{}) -func getgoroot() string - // GOROOT returns the root of the Go tree. // It uses the GOROOT environment variable, if set, // or else the root used during the Go build. func GOROOT() string { - s := getgoroot() + s := gogetenv("GOROOT") if s != "" { return s } diff --git a/libgo/go/runtime/stubs.go b/libgo/go/runtime/stubs.go index d0641ed7150..8d90cd6061f 100644 --- a/libgo/go/runtime/stubs.go +++ b/libgo/go/runtime/stubs.go @@ -501,6 +501,7 @@ func needm() func dropm() func sigprof() func mcount() int32 +func gcount() int32 // Signal trampoline, written in C. func sigtramp() diff --git a/libgo/runtime/proc.c b/libgo/runtime/proc.c index 62abc9d238b..43ced39c0f7 100644 --- a/libgo/runtime/proc.c +++ b/libgo/runtime/proc.c @@ -2535,15 +2535,19 @@ runtime_Gosched(void) // Implementation of runtime.GOMAXPROCS. // delete when scheduler is even stronger -int32 -runtime_gomaxprocsfunc(int32 n) + +intgo runtime_GOMAXPROCS(intgo) + __asm__(GOSYM_PREFIX "runtime.GOMAXPROCS"); + +intgo +runtime_GOMAXPROCS(intgo n) { - int32 ret; + intgo ret; if(n > _MaxGomaxprocs) n = _MaxGomaxprocs; runtime_lock(&runtime_sched); - ret = runtime_gomaxprocs; + ret = (intgo)runtime_gomaxprocs; if(n <= 0 || n == ret) { runtime_unlock(&runtime_sched); return ret; @@ -2553,7 +2557,7 @@ runtime_gomaxprocsfunc(int32 n) runtime_acquireWorldsema(); g->m->gcing = 1; runtime_stopTheWorldWithSema(); - newprocs = n; + newprocs = (int32)n; g->m->gcing = 0; runtime_releaseWorldsema(); runtime_startTheWorldWithSema(); @@ -3499,6 +3503,58 @@ runtime_setmaxthreads(intgo in) return out; } +static intgo +procPin() +{ + M *mp; + + mp = runtime_m(); + mp->locks++; + return (intgo)(((P*)mp->p)->id); +} + +static void +procUnpin() +{ + runtime_m()->locks--; +} + +intgo sync_runtime_procPin(void) + __asm__ (GOSYM_PREFIX "sync.runtime_procPin"); + +intgo +sync_runtime_procPin() +{ + return procPin(); +} + +void sync_runtime_procUnpin(void) + __asm__ (GOSYM_PREFIX "sync.runtime_procUnpin"); + +void +sync_runtime_procUnpin() +{ + procUnpin(); +} + +intgo sync_atomic_runtime_procPin(void) + __asm__ (GOSYM_PREFIX "sync_atomic.runtime_procPin"); + +intgo +sync_atomic_runtime_procPin() +{ + return procPin(); +} + +void sync_atomic_runtime_procUnpin(void) + __asm__ (GOSYM_PREFIX "sync_atomic.runtime_procUnpin"); + +void +sync_atomic_runtime_procUnpin() +{ + procUnpin(); +} + void runtime_proc_scan(struct Workbuf** wbufp, void (*enqueue1)(struct Workbuf**, Obj)) { @@ -3589,3 +3645,11 @@ runtime_go_allgs() s.__capacity = allgcap; return s; } + +intgo NumCPU(void) __asm__ (GOSYM_PREFIX "runtime.NumCPU"); + +intgo +NumCPU() +{ + return (intgo)(runtime_ncpu); +} diff --git a/libgo/runtime/runtime.h b/libgo/runtime/runtime.h index 7d22631bddc..50143fe0aaf 100644 --- a/libgo/runtime/runtime.h +++ b/libgo/runtime/runtime.h @@ -315,7 +315,8 @@ void runtime_mprofinit(void); #define runtime_getcallersp(p) __builtin_frame_address(0) int32 runtime_mcount(void) __asm__ (GOSYM_PREFIX "runtime.mcount"); -int32 runtime_gcount(void); +int32 runtime_gcount(void) + __asm__ (GOSYM_PREFIX "runtime.gcount"); void runtime_mcall(void(*)(G*)); uint32 runtime_fastrand1(void) __asm__ (GOSYM_PREFIX "runtime.fastrand1"); int32 runtime_timediv(int64, int32, int32*) @@ -512,7 +513,6 @@ void runtime_semacquire(uint32 volatile *, bool) __asm__ (GOSYM_PREFIX "runtime.semacquire"); void runtime_semrelease(uint32 volatile *) __asm__ (GOSYM_PREFIX "runtime.semrelease"); -int32 runtime_gomaxprocsfunc(int32 n); void runtime_procyield(uint32) __asm__(GOSYM_PREFIX "runtime.procyield"); void runtime_osyield(void) diff --git a/libgo/runtime/runtime1.goc b/libgo/runtime/runtime1.goc deleted file mode 100644 index a83b93ebdb8..00000000000 --- a/libgo/runtime/runtime1.goc +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright 2010 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. - -package runtime -#include "runtime.h" -#include "arch.h" -#include "go-type.h" - -func GOMAXPROCS(n int) (ret int) { - ret = runtime_gomaxprocsfunc(n); -} - -func NumCPU() (ret int) { - ret = runtime_ncpu; -} - -func NumCgoCall() (ret int64) { - M *mp; - - ret = 0; - for(mp=runtime_atomicloadp(&runtime_allm); mp; mp=mp->alllink) - ret += mp->ncgocall; -} - -func newParFor(nthrmax uint32) (desc *ParFor) { - desc = runtime_parforalloc(nthrmax); -} - -func parForSetup(desc *ParFor, nthr uint32, n uint32, wait bool, body *byte) { - runtime_parforsetup(desc, nthr, n, wait, (const FuncVal*) body); -} - -func parForDo(desc *ParFor) { - runtime_parfordo(desc); -} - -func parForIters(desc *ParFor, tid uintptr) (start uintptr, end uintptr) { - runtime_parforiters(desc, tid, &start, &end); -} - -func typestring(e Eface) (s String) { - s = *((Type*)e._type)->__reflection; -} - -func golockedOSThread() (ret bool) { - ret = runtime_lockedOSThread(); -} - -func NumGoroutine() (ret int) { - ret = runtime_gcount(); -} - -func getgoroot() (out String) { - out = runtime_getenv("GOROOT"); -} - -func sync.runtime_procPin() (p int) { - M *mp; - - mp = runtime_m(); - // Disable preemption. - mp->locks++; - p = ((P*)mp->p)->id; -} - -func sync.runtime_procUnpin() { - runtime_m()->locks--; -} - -func sync_atomic.runtime_procPin() (p int) { - M *mp; - - mp = runtime_m(); - // Disable preemption. - mp->locks++; - p = ((P*)mp->p)->id; -} - -func sync_atomic.runtime_procUnpin() { - runtime_m()->locks--; -} -- 2.30.2