From ccba8877ce9c3a85a7948f0c707b4f5f3a6c8c5a Mon Sep 17 00:00:00 2001 From: Achilleas Anagnostopoulos Date: Fri, 14 Jul 2017 07:49:20 +0100 Subject: [PATCH] Enable support for deferred calls --- src/gopheros/kernel/goruntime/bootstrap.go | 13 +++++++++++++ src/gopheros/kernel/goruntime/bootstrap_test.go | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/gopheros/kernel/goruntime/bootstrap.go b/src/gopheros/kernel/goruntime/bootstrap.go index 1010a18..e51fedc 100644 --- a/src/gopheros/kernel/goruntime/bootstrap.go +++ b/src/gopheros/kernel/goruntime/bootstrap.go @@ -21,6 +21,7 @@ var ( typeLinksInitFn = typeLinksInit itabsInitFn = itabsInit initGoPackagesFn = initGoPackages + procResizeFn = procResize // A seed for the pseudo-random number generator used by getRandomData prngSeed = 0xdeadc0de @@ -44,6 +45,9 @@ func mallocInit() //go:linkname mSysStatInc runtime.mSysStatInc func mSysStatInc(*uint64, uintptr) +//go:linkname procResize runtime.procresize +func procResize(int32) uintptr + // initGoPackages is an alias to main.init which recursively calls the init() // methods in all imported packages. Unless this function is called, things like // package errors will not be properly initialized causing various problems when @@ -184,11 +188,20 @@ func Init() *kernel.Error { typeLinksInitFn() // uses maps, activeModules itabsInitFn() // uses activeModules + // Set processor count to 1. This initializes the p pointer in the + // currently active m allowing the kernel to register defer functions + SetCPUCount(1) + initGoPackagesFn() return nil } +// SetCPUCount registers the number of available CPUs with the Go runtime. +func SetCPUCount(numCPUs int32) { + procResizeFn(numCPUs) +} + func init() { // Dummy calls so the compiler does not optimize away the functions in // this file. diff --git a/src/gopheros/kernel/goruntime/bootstrap_test.go b/src/gopheros/kernel/goruntime/bootstrap_test.go index 37d1287..bf2aca6 100644 --- a/src/gopheros/kernel/goruntime/bootstrap_test.go +++ b/src/gopheros/kernel/goruntime/bootstrap_test.go @@ -267,6 +267,7 @@ func TestInit(t *testing.T) { typeLinksInitFn = typeLinksInit itabsInitFn = itabsInit initGoPackagesFn = initGoPackages + procResizeFn = procResize }() mallocInitFn = func() {} @@ -275,7 +276,7 @@ func TestInit(t *testing.T) { typeLinksInitFn = func() {} itabsInitFn = func() {} initGoPackagesFn = func() {} - + procResizeFn = func(_ int32) uintptr { return 0 } if err := Init(); err != nil { t.Fatal(t) }