Commit 350767bf by Ian Lance Taylor

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
parent 660e6c2c
31ff8c31d33c3e77cae4fd55445f12825eb92af5 d9189ebc139ff739af956094626ccc5eb92c3091
The first line of this file holds the git revision number of the last The first line of this file holds the git revision number of the last
merge done from the gofrontend repository. merge done from the gofrontend repository.
...@@ -485,7 +485,6 @@ runtime_files = \ ...@@ -485,7 +485,6 @@ runtime_files = \
runtime/yield.c \ runtime/yield.c \
$(rtems_task_variable_add_file) \ $(rtems_task_variable_add_file) \
malloc.c \ malloc.c \
runtime1.c \
$(runtime_getncpu_file) $(runtime_getncpu_file)
goc2c.$(OBJEXT): runtime/goc2c.c goc2c.$(OBJEXT): runtime/goc2c.c
...@@ -498,10 +497,6 @@ malloc.c: $(srcdir)/runtime/malloc.goc goc2c ...@@ -498,10 +497,6 @@ malloc.c: $(srcdir)/runtime/malloc.goc goc2c
./goc2c $< > $@.tmp ./goc2c $< > $@.tmp
mv -f $@.tmp $@ mv -f $@.tmp $@
runtime1.c: $(srcdir)/runtime/runtime1.goc goc2c
./goc2c $< > $@.tmp
mv -f $@.tmp $@
%.c: $(srcdir)/runtime/%.goc goc2c %.c: $(srcdir)/runtime/%.goc goc2c
./goc2c $< > $@.tmp ./goc2c $< > $@.tmp
mv -f $@.tmp $@ mv -f $@.tmp $@
......
...@@ -204,7 +204,7 @@ am__objects_5 = go-assert.lo go-breakpoint.lo go-caller.lo \ ...@@ -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 \ mcentral.lo $(am__objects_1) mfixalloc.lo mgc0.lo mheap.lo \
msize.lo panic.lo parfor.lo print.lo proc.lo runtime_c.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 \ 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) am_libgo_llgo_la_OBJECTS = $(am__objects_5)
libgo_llgo_la_OBJECTS = $(am_libgo_llgo_la_OBJECTS) libgo_llgo_la_OBJECTS = $(am_libgo_llgo_la_OBJECTS)
libgo_llgo_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ libgo_llgo_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
...@@ -832,7 +832,6 @@ runtime_files = \ ...@@ -832,7 +832,6 @@ runtime_files = \
runtime/yield.c \ runtime/yield.c \
$(rtems_task_variable_add_file) \ $(rtems_task_variable_add_file) \
malloc.c \ malloc.c \
runtime1.c \
$(runtime_getncpu_file) $(runtime_getncpu_file)
noinst_DATA = zstdpkglist.go noinst_DATA = zstdpkglist.go
...@@ -1520,7 +1519,6 @@ distclean-compile: ...@@ -1520,7 +1519,6 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/print.Plo@am__quote@ @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)/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)/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)/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-linux.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/thread-sema.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 ...@@ -3161,10 +3159,6 @@ malloc.c: $(srcdir)/runtime/malloc.goc goc2c
./goc2c $< > $@.tmp ./goc2c $< > $@.tmp
mv -f $@.tmp $@ mv -f $@.tmp $@
runtime1.c: $(srcdir)/runtime/runtime1.goc goc2c
./goc2c $< > $@.tmp
mv -f $@.tmp $@
%.c: $(srcdir)/runtime/%.goc goc2c %.c: $(srcdir)/runtime/%.goc goc2c
./goc2c $< > $@.tmp ./goc2c $< > $@.tmp
mv -f $@.tmp $@ mv -f $@.tmp $@
......
...@@ -4,6 +4,11 @@ ...@@ -4,6 +4,11 @@
package runtime package runtime
import (
"runtime/internal/atomic"
"unsafe"
)
// GOMAXPROCS sets the maximum number of CPUs that can be executing // GOMAXPROCS sets the maximum number of CPUs that can be executing
// simultaneously and returns the previous setting. If n < 1, it does not // simultaneously and returns the previous setting. If n < 1, it does not
// change the current setting. // change the current setting.
...@@ -19,10 +24,18 @@ func GOMAXPROCS(n int) int ...@@ -19,10 +24,18 @@ func GOMAXPROCS(n int) int
func NumCPU() int func NumCPU() int
// NumCgoCall returns the number of cgo calls made by the current process. // 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. // 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" // Get field tracking information. Only fields with a tag go:"track"
// are tracked. This function will add every such field that is // are tracked. This function will add every such field that is
......
...@@ -133,7 +133,10 @@ type stringer interface { ...@@ -133,7 +133,10 @@ type stringer interface {
String() string String() string
} }
func typestring(interface{}) string func typestring(x interface{}) string {
e := efaceOf(&x)
return *e._type.string
}
// For calling from C. // For calling from C.
// Prints an argument passed to panic. // Prints an argument passed to panic.
......
...@@ -21,11 +21,10 @@ import ( ...@@ -21,11 +21,10 @@ import (
//var F64toint = f64toint //var F64toint = f64toint
//var Sqrt = sqrt //var Sqrt = sqrt
func golockedOSThread() bool
var Entersyscall = entersyscall var Entersyscall = entersyscall
var Exitsyscall = exitsyscall var Exitsyscall = exitsyscall
var LockedOSThread = golockedOSThread
// var LockedOSThread = lockedOSThread
// var Xadduintptr = xadduintptr // var Xadduintptr = xadduintptr
...@@ -44,29 +43,6 @@ func LFStackPop(head *uint64) *LFNode { ...@@ -44,29 +43,6 @@ func LFStackPop(head *uint64) *LFNode {
return (*LFNode)(unsafe.Pointer(lfstackpop(head))) 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) { func GCMask(x interface{}) (ret []byte) {
return nil return nil
} }
......
...@@ -274,13 +274,11 @@ func SetFinalizer(obj interface{}, finalizer interface{}) ...@@ -274,13 +274,11 @@ func SetFinalizer(obj interface{}, finalizer interface{})
// the actual system call. // the actual system call.
func KeepAlive(interface{}) func KeepAlive(interface{})
func getgoroot() string
// GOROOT returns the root of the Go tree. // GOROOT returns the root of the Go tree.
// It uses the GOROOT environment variable, if set, // It uses the GOROOT environment variable, if set,
// or else the root used during the Go build. // or else the root used during the Go build.
func GOROOT() string { func GOROOT() string {
s := getgoroot() s := gogetenv("GOROOT")
if s != "" { if s != "" {
return s return s
} }
......
...@@ -501,6 +501,7 @@ func needm() ...@@ -501,6 +501,7 @@ func needm()
func dropm() func dropm()
func sigprof() func sigprof()
func mcount() int32 func mcount() int32
func gcount() int32
// Signal trampoline, written in C. // Signal trampoline, written in C.
func sigtramp() func sigtramp()
......
...@@ -2535,15 +2535,19 @@ runtime_Gosched(void) ...@@ -2535,15 +2535,19 @@ runtime_Gosched(void)
// Implementation of runtime.GOMAXPROCS. // Implementation of runtime.GOMAXPROCS.
// delete when scheduler is even stronger // 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) if(n > _MaxGomaxprocs)
n = _MaxGomaxprocs; n = _MaxGomaxprocs;
runtime_lock(&runtime_sched); runtime_lock(&runtime_sched);
ret = runtime_gomaxprocs; ret = (intgo)runtime_gomaxprocs;
if(n <= 0 || n == ret) { if(n <= 0 || n == ret) {
runtime_unlock(&runtime_sched); runtime_unlock(&runtime_sched);
return ret; return ret;
...@@ -2553,7 +2557,7 @@ runtime_gomaxprocsfunc(int32 n) ...@@ -2553,7 +2557,7 @@ runtime_gomaxprocsfunc(int32 n)
runtime_acquireWorldsema(); runtime_acquireWorldsema();
g->m->gcing = 1; g->m->gcing = 1;
runtime_stopTheWorldWithSema(); runtime_stopTheWorldWithSema();
newprocs = n; newprocs = (int32)n;
g->m->gcing = 0; g->m->gcing = 0;
runtime_releaseWorldsema(); runtime_releaseWorldsema();
runtime_startTheWorldWithSema(); runtime_startTheWorldWithSema();
...@@ -3499,6 +3503,58 @@ runtime_setmaxthreads(intgo in) ...@@ -3499,6 +3503,58 @@ runtime_setmaxthreads(intgo in)
return out; 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 void
runtime_proc_scan(struct Workbuf** wbufp, void (*enqueue1)(struct Workbuf**, Obj)) runtime_proc_scan(struct Workbuf** wbufp, void (*enqueue1)(struct Workbuf**, Obj))
{ {
...@@ -3589,3 +3645,11 @@ runtime_go_allgs() ...@@ -3589,3 +3645,11 @@ runtime_go_allgs()
s.__capacity = allgcap; s.__capacity = allgcap;
return s; return s;
} }
intgo NumCPU(void) __asm__ (GOSYM_PREFIX "runtime.NumCPU");
intgo
NumCPU()
{
return (intgo)(runtime_ncpu);
}
...@@ -315,7 +315,8 @@ void runtime_mprofinit(void); ...@@ -315,7 +315,8 @@ void runtime_mprofinit(void);
#define runtime_getcallersp(p) __builtin_frame_address(0) #define runtime_getcallersp(p) __builtin_frame_address(0)
int32 runtime_mcount(void) int32 runtime_mcount(void)
__asm__ (GOSYM_PREFIX "runtime.mcount"); __asm__ (GOSYM_PREFIX "runtime.mcount");
int32 runtime_gcount(void); int32 runtime_gcount(void)
__asm__ (GOSYM_PREFIX "runtime.gcount");
void runtime_mcall(void(*)(G*)); void runtime_mcall(void(*)(G*));
uint32 runtime_fastrand1(void) __asm__ (GOSYM_PREFIX "runtime.fastrand1"); uint32 runtime_fastrand1(void) __asm__ (GOSYM_PREFIX "runtime.fastrand1");
int32 runtime_timediv(int64, int32, int32*) int32 runtime_timediv(int64, int32, int32*)
...@@ -512,7 +513,6 @@ void runtime_semacquire(uint32 volatile *, bool) ...@@ -512,7 +513,6 @@ void runtime_semacquire(uint32 volatile *, bool)
__asm__ (GOSYM_PREFIX "runtime.semacquire"); __asm__ (GOSYM_PREFIX "runtime.semacquire");
void runtime_semrelease(uint32 volatile *) void runtime_semrelease(uint32 volatile *)
__asm__ (GOSYM_PREFIX "runtime.semrelease"); __asm__ (GOSYM_PREFIX "runtime.semrelease");
int32 runtime_gomaxprocsfunc(int32 n);
void runtime_procyield(uint32) void runtime_procyield(uint32)
__asm__(GOSYM_PREFIX "runtime.procyield"); __asm__(GOSYM_PREFIX "runtime.procyield");
void runtime_osyield(void) void runtime_osyield(void)
......
// 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--;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment