[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH RFC 37/59] libxl.go: Provide a single global context by default



From: George Dunlap <george.dunlap@xxxxxxxxxx>

Provide a single global context by default, Ctx.  Allow this to be
called with Ctx.Open() multiple times (but Close() only once).

Move xenworker.go to use this global context instead; and open it when
starting the benchmark (rather than opening and closing it for every
run, which is effectively what happens now).

Signed-off-by: George Dunlap <george.dunlap@xxxxxxxxxx>
---
 libxl.go     | 12 +++++-------
 run.go       |  7 +++++++
 xenworker.go | 25 +++++--------------------
 3 files changed, 17 insertions(+), 27 deletions(-)

diff --git a/libxl.go b/libxl.go
index 5bdabb1..9477bca 100644
--- a/libxl.go
+++ b/libxl.go
@@ -16,19 +16,17 @@ type Context struct {
        ctx *C.libxl_ctx
 }
 
-func NewContext() (Ctx *Context, err error) {
-       Ctx = &Context{}
-       
-       err = Ctx.Open()
-
-       return
-}
+var Ctx Context
 
 func (Ctx *Context) IsOpen() bool {
        return Ctx.ctx != nil
 }
 
 func (Ctx *Context) Open() (err error) {
+       if Ctx.ctx != nil {
+               return
+       }
+       
        ret := C.libxl_ctx_alloc(unsafe.Pointer(&Ctx.ctx), C.LIBXL_VERSION, 0, 
nil)
 
        if ret != 0 {
diff --git a/run.go b/run.go
index 1b39730..08a43ff 100644
--- a/run.go
+++ b/run.go
@@ -228,6 +228,13 @@ func (plan *BenchmarkPlan) Run() (err error) {
        if err != nil {
                return
        }
+
+       if plan.WorkerType == WorkerXen {
+               err = Ctx.Open()
+               if err != nil {
+                       return
+               }
+       }
        
        for i := range plan.Runs {
                r := &plan.Runs[i];
diff --git a/xenworker.go b/xenworker.go
index 45e0876..2649392 100644
--- a/xenworker.go
+++ b/xenworker.go
@@ -27,13 +27,6 @@ import (
        "io"
 )
 
-type xenGlobal struct {
-       Ctx Context
-       count int
-}
-
-var xg xenGlobal
-
 type XenWorker struct {
        id WorkerId
        Ctx Context
@@ -68,13 +61,9 @@ func (w *XenWorker) SetId(i WorkerId) {
 }
 
 func (w *XenWorker) Init(p WorkerParams, g WorkerConfig) (err error) {
-       if xg.count == 0 {
-               err = xg.Ctx.Open()
-               if err != nil {
-                       return
-               }
+       if err != nil {
+               return
        }
-       xg.count++
        
        mock := false
        
@@ -220,11 +209,6 @@ func (w *XenWorker) Shutdown() {
        e.Stdout = os.Stdout
        e.Stderr = os.Stderr
 
-       xg.count--
-       if xg.count == 0 {
-               defer xg.Ctx.Close()
-       }
-
        err := e.Run()
        if err != nil {
                fmt.Printf("Error destroying domain: %v\n", err)
@@ -249,7 +233,8 @@ func (w *XenWorker) DumpLog(f io.Writer) (err error) {
 // FIXME: Return an error
 func (w *XenWorker) Process(report chan WorkerReport, done chan WorkerId) {
        // // xl unpause [vmname]
-       err := xg.Ctx.DomainUnpause(Domid(w.domid))
+       //err := xg.Ctx.DomainUnpause(Domid(w.domid))
+       err := Ctx.DomainUnpause(Domid(w.domid))
        if err != nil {
                fmt.Printf("Error unpausing domain: %v\n", err)
                return
@@ -268,7 +253,7 @@ func (w *XenWorker) Process(report chan WorkerReport, done 
chan WorkerId) {
                        var r WorkerReport
                        json.Unmarshal([]byte(s), &r)
                        r.Id = w.id
-                       di, err := xg.Ctx.DomainInfo(Domid(w.domid))
+                       di, err := Ctx.DomainInfo(Domid(w.domid))
                        // Ignore errors for now
                        if err == nil {
                                r.Cputime = di.Cpu_time
-- 
2.7.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.