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
This commit is contained in:
Ian Lance Taylor 2016-11-16 18:33:11 +00:00
parent 660e6c2c12
commit 350767bf22
11 changed files with 96 additions and 134 deletions

View file

@ -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.

View file

@ -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 $@

View file

@ -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 $@

View file

@ -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

View file

@ -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.

View file

@ -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
}

View file

@ -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
}

View file

@ -501,6 +501,7 @@ func needm()
func dropm()
func sigprof()
func mcount() int32
func gcount() int32
// Signal trampoline, written in C.
func sigtramp()

View file

@ -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);
}

View file

@ -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)

View file

@ -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--;
}