Initial controller framework
RFC PATCH 1/59 Initial controller framework
From: George Dunlap <[email protected]>
Go code to execute a worker and parse its output.
The go json marshaller needs capitalized structure elements; make the output match.
Also add fflush()-es to make sure that output actually gets to the controller in a timely manner.
--- Makefile | 12 ++++++++++ main.go | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 Makefile create mode 100644 main.go
Makefile new file +12 -0
@@ -0,0 +1,12 @@ +BIN = controller +BINALL = $(BIN) + +.PHONY: all +all: $(BIN) + +controller: main.go + go build -o $@ $< + +.PHONY: clean +clean: + rm -f $(BINALL)
main.go new file +78 -0
78 lines not on this page · raw message
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 2/59 controller: Revamp communication structure
From: George Dunlap <[email protected]>
Two general-purporse channels rather than one per worker.
Set up two workers, gather and collate the information at the central station.
Have the worker print out a report at start-of-day, so we get timing information for the first actual report.
Catch SIGINT as a shorthand testing way of managing tear-down gracefully.
--- main.go | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 78 insertions(+), 18 deletions(-)
main.go +78 -18
@@ -2,13 +2,18 @@ package main import ( "fmt" + "os" "os/exec" + "os/signal" "encoding/json" "bufio" "io" + ) type Worker struct { + Id int + c *exec.Cmd stdout io.ReadCloser
@@ -17,14 +22,14 @@ type Worker struct { } type WorkerReport struct { + Id int Now int Mops int MaxDelta int } -func (w *Worker) Start() (err error) { +func (w *Worker) Init() (err error) { w.c = exec.Command("../worker/worker-proc", "burnwait", "20", "20000000") - w.stdout, err = w.c.StdoutPipe() if err != nil {
@@ -32,47 +37,102 @@ func (w *Worker) Start() (err error) { return } - w.c.Start() - - b, err := json.Marshal(WorkerReport{5,6,7}) - fmt.Print("Example json: ", string(b)) - return } -func (w *Worker) Wait() { - w.c.Wait() +func (w *Worker) Shutdown() { + w.c.Process.Kill() } -func (w *Worker) Process() { +func (w *Worker) Process(report chan WorkerReport, done chan bool) { + w.c.Start() + scanner := bufio.NewScanner(w.stdout) for scanner.Scan() { s := scanner.Text() - fmt.Println("Got these bytes: ", s); + //fmt.Println("Got these bytes: ", s); if w.jsonStarted { var r WorkerReport - json.Unmarshal([]byte(s), &r) - fmt.Println(r) + r.Id = w.Id + report <- r } else { if s == "START JSON" { - fmt.Println("Got token to start parsing json") + //fmt.Println("Got token to start parsing json") w.jsonStarted = true } } } + + done <- true + + w.c.Wait() +} + +const ( + USEC = 1000 + MSEC = USEC * 1000 + SEC = MSEC * 1000 +) + +type WorkerState struct { + Worker + LastReport WorkerReport +} + +func Report(ws *WorkerState, r WorkerReport) { + //fmt.Println(r) + + lr := ws.LastReport + + if (lr.Now > 0) { + time := float64(r.Now - lr.Now) / SEC + mops := r.Mops - lr.Mops + + tput := float64(mops) / time + + fmt.Printf("%d Time: %2.3f Mops: %d Tput: %4.2f\n", r.Id, time, mops, tput); + } + + ws.LastReport = r } func main() { + count := 2 + + report := make(chan WorkerReport) + done := make(chan bool) + signals := make(chan os.Signal, 1) - w:=Worker{} + signal.Notify(signals, os.Interrupt) - w.Start() + i := 0 - w.Process() + Workers := make([]WorkerState, count) + + for i = 0; i< count; i++ { + Workers[i].Id = i + + Workers[i].Init() + + go Workers[i].Process(report, done) + } - w.Wait() + for i > 0 { + select { + case r := <-report: + Report(&Workers[r.Id], r) + case <-done: + i--; + fmt.Println(i, "workers left"); + case <-signals: + fmt.Println("SIGINT receieved, shutting down workers") + for j := range Workers { + Workers[j].Shutdown() + } + } + } }
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 3/59 controller: Initial attempt to generalize process / vm creation
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
Create a "Worker" interface, and have ProcessWorker implement that interface.
Rename "Worker" to "WorkerReport" to make room for the interface.
--- main.go | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-)
main.go +27 -18
@@ -11,24 +11,32 @@ import ( ) -type Worker struct { +type WorkerReport struct { Id int - - c *exec.Cmd + Now int + Mops int + MaxDelta int +} + +type Worker interface { + SetId(int) + Init() error + Shutdown() + Process(chan WorkerReport, chan bool) +} +type ProcessWorker struct { + id int + c *exec.Cmd stdout io.ReadCloser - jsonStarted bool } -type WorkerReport struct { - Id int - Now int - Mops int - MaxDelta int +func (w *ProcessWorker) SetId(i int) { + w.id = i } -func (w *Worker) Init() (err error) { +func (w *ProcessWorker) Init() (err error) { w.c = exec.Command("../worker/worker-proc", "burnwait", "20", "20000000") w.stdout, err = w.c.StdoutPipe()
@@ -40,11 +48,11 @@ func (w *Worker) Init() (err error) { return } -func (w *Worker) Shutdown() { +func (w *ProcessWorker) Shutdown() { w.c.Process.Kill() } -func (w *Worker) Process(report chan WorkerReport, done chan bool) { +func (w *ProcessWorker) Process(report chan WorkerReport, done chan bool) { w.c.Start() scanner := bufio.NewScanner(w.stdout)
@@ -57,7 +65,7 @@ func (w *Worker) Process(report chan WorkerReport, done chan bool) { if w.jsonStarted { var r WorkerReport json.Unmarshal([]byte(s), &r) - r.Id = w.Id + r.Id = w.id report <- r } else { if s == "START JSON" {
@@ -79,7 +87,7 @@ const ( ) type WorkerState struct { - Worker + w Worker LastReport WorkerReport }
@@ -114,11 +122,12 @@ func main() { Workers := make([]WorkerState, count) for i = 0; i< count; i++ { - Workers[i].Id = i + Workers[i].w = &ProcessWorker{} + Workers[i].w.SetId(i) - Workers[i].Init() + Workers[i].w.Init() - go Workers[i].Process(report, done) + go Workers[i].w.Process(report, done) } for i > 0 {
@@ -131,7 +140,7 @@ func main() { case <-signals: fmt.Println("SIGINT receieved, shutting down workers") for j := range Workers { - Workers[j].Shutdown() + Workers[j].w.Shutdown() } } }
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 4/59 Controller: Move process worker into its own file
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
Also fix Makefile rule to use correct automatic variable.
--- Makefile | 4 ++-- main.go | 59 -------------------------------------------------- processworker.go | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 61 deletions(-) create mode 100644 processworker.go
Makefile +2 -2
@@ -4,8 +4,8 @@ BINALL = $(BIN) .PHONY: all all: $(BIN) -controller: main.go - go build -o $@ $< +controller: main.go processworker.go + go build -o $@ $^ .PHONY: clean clean:
main.go +0 -59
72 lines not on this page · raw message
processworker.go new file +66 -0
66 lines not on this page · raw message
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 5/59 controller: Add WorkerParams argument to Init in Worker interface
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
For now just make it a plain []string; later make it more abstrcted.
--- main.go | 22 +++++++++++++++++----- processworker.go | 4 ++-- 2 files changed, 19 insertions(+), 7 deletions(-)
main.go +17 -5
@@ -14,9 +14,13 @@ type WorkerReport struct { MaxDelta int } +type WorkerParams struct { + Args []string +} + type Worker interface { SetId(int) - Init() error + Init(WorkerParams) error Shutdown() Process(chan WorkerReport, chan bool) }
@@ -49,6 +53,14 @@ func Report(ws *WorkerState, r WorkerReport) { ws.LastReport = r } +type WorkerList []WorkerState + +func (ws *WorkerList) Start(report chan WorkerReport, done chan bool) { + for i := range *ws { + go (*ws)[i].w.Process(report, done) + } +} + func main() { count := 2
@@ -60,17 +72,17 @@ func main() { i := 0 - Workers := make([]WorkerState, count) + Workers := WorkerList(make([]WorkerState, count)) for i = 0; i< count; i++ { Workers[i].w = &ProcessWorker{} Workers[i].w.SetId(i) - Workers[i].w.Init() - - go Workers[i].w.Process(report, done) + Workers[i].w.Init(WorkerParams{[]string{"burnwait", "20", "20000000"}}) } + Workers.Start(report, done) + for i > 0 { select { case r := <-report:
processworker.go +2 -2
@@ -20,8 +20,8 @@ func (w *ProcessWorker) SetId(i int) { w.id = i } -func (w *ProcessWorker) Init() (err error) { - w.c = exec.Command("../worker/worker-proc", "burnwait", "20", "20000000") +func (w *ProcessWorker) Init(p WorkerParams) (err error) { + w.c = exec.Command("../worker/worker-proc", p.Args...) w.stdout, err = w.c.StdoutPipe() if err != nil {
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 6/59 Reorganize to enable "Dist" directory
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
Make a toplevel Makefile which defaults to 'make dist'. Add "make dist" targets in all subdirs, which copy the distribution files into $PWD/dist.
Modify processworker.go such that it looks for worker-proc in the same directory.
--- Makefile | 4 ++++ processworker.go | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-)
Makefile +4 -0
@@ -10,3 +10,7 @@ controller: main.go processworker.go .PHONY: clean clean: rm -f $(BINALL) + +.PHONY: dist +dist: + cp $(BIN) $(DISTDIR)
processworker.go +1 -1
@@ -21,7 +21,7 @@ func (w *ProcessWorker) SetId(i int) { } func (w *ProcessWorker) Init(p WorkerParams) (err error) { - w.c = exec.Command("../worker/worker-proc", p.Args...) + w.c = exec.Command("./worker-proc", p.Args...) w.stdout, err = w.c.StdoutPipe() if err != nil {
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 7/59 controller: Introduce basic Xen functionality
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
Rough-and-ready execution of xl commands, but they work, amazingly.
--- Makefile | 2 +- main.go | 3 +- xenworker.go | 231 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 234 insertions(+), 2 deletions(-) create mode 100644 xenworker.go
Makefile +1 -1
@@ -4,7 +4,7 @@ BINALL = $(BIN) .PHONY: all all: $(BIN) -controller: main.go processworker.go +controller: main.go processworker.go xenworker.go go build -o $@ $^ .PHONY: clean
main.go +2 -1
@@ -75,7 +75,8 @@ func main() { Workers := WorkerList(make([]WorkerState, count)) for i = 0; i< count; i++ { - Workers[i].w = &ProcessWorker{} + //Workers[i].w = &ProcessWorker{} + Workers[i].w = &XenWorker{} Workers[i].w.SetId(i) Workers[i].w.Init(WorkerParams{[]string{"burnwait", "20", "20000000"}})
xenworker.go new file +231 -0
231 lines not on this page · raw message
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 8/59 controller: Exit after second SIGINT
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
Otherwise you have to kill -9 the process.
--- main.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
main.go +11 -3
@@ -62,6 +62,8 @@ func (ws *WorkerList) Start(report chan WorkerReport, done chan bool) { } func main() { + killed := false + count := 2 report := make(chan WorkerReport)
@@ -92,9 +94,15 @@ func main() { i--; fmt.Println(i, "workers left"); case <-signals: - fmt.Println("SIGINT receieved, shutting down workers") - for j := range Workers { - Workers[j].w.Shutdown() + if ! killed { + fmt.Println("SIGINT receieved, shutting down workers") + for j := range Workers { + Workers[j].w.Shutdown() + } + killed = true + } else { + fmt.Println("Second SIGINT received, exiting without cleaning up") + os.Exit(1) } } }
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 9/59 controller: Refactor creation and stopping of workers into WorkerList methods
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
--- main.go | 59 ++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 17 deletions(-)
main.go +42 -17
@@ -55,10 +55,43 @@ func Report(ws *WorkerState, r WorkerReport) { type WorkerList []WorkerState -func (ws *WorkerList) Start(report chan WorkerReport, done chan bool) { +func (ws *WorkerList) Start(report chan WorkerReport, done chan bool) (i int) { + i = 0 + for j := range *ws { + go (*ws)[j].w.Process(report, done) + i++ + } + return +} + +func (ws *WorkerList) Stop() { for i := range *ws { - go (*ws)[i].w.Process(report, done) + (*ws)[i].w.Shutdown() + } +} + +const ( + WorkerProcess = iota + WorkerXen = iota +) + +func NewWorkerList(count int, workerType int) (ws WorkerList, err error) { + ws = WorkerList(make([]WorkerState, count)) + + for i := 0; i< count; i++ { + switch workerType { + case WorkerProcess: + ws[i].w = &ProcessWorker{} + case WorkerXen: + ws[i].w = &XenWorker{} + default: + err = fmt.Errorf("Unknown type: %d", workerType) + } + ws[i].w.SetId(i) + + ws[i].w.Init(WorkerParams{[]string{"burnwait", "20", "20000000"}}) } + return } func main() {
@@ -72,19 +105,13 @@ func main() { signal.Notify(signals, os.Interrupt) - i := 0 - - Workers := WorkerList(make([]WorkerState, count)) - - for i = 0; i< count; i++ { - //Workers[i].w = &ProcessWorker{} - Workers[i].w = &XenWorker{} - Workers[i].w.SetId(i) - - Workers[i].w.Init(WorkerParams{[]string{"burnwait", "20", "20000000"}}) + Workers, err := NewWorkerList(count, WorkerProcess) + if err != nil { + fmt.Println("Error creating workers: %v", err) + return } - - Workers.Start(report, done) + + i := Workers.Start(report, done) for i > 0 { select {
@@ -96,9 +123,7 @@ func main() { case <-signals: if ! killed { fmt.Println("SIGINT receieved, shutting down workers") - for j := range Workers { - Workers[j].w.Shutdown() - } + Workers.Stop() killed = true } else { fmt.Println("Second SIGINT received, exiting without cleaning up")
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 10/59 controller: First cut at BenchmarkParams
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
Struct for configurable worker sets, as well as a set runtime.
--- main.go | 75 ++++++++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 53 insertions(+), 22 deletions(-)
main.go +53 -22
@@ -4,7 +4,7 @@ import ( "fmt" "os" "os/signal" - + "time" ) type WorkerReport struct {
@@ -18,6 +18,16 @@ type WorkerParams struct { Args []string } +type WorkerSet struct { + Params WorkerParams + Count int +} + +type BenchmarkParams struct { + Workers []WorkerSet + RuntimeSeconds int +} + type Worker interface { SetId(int) Init(WorkerParams) error
@@ -75,29 +85,53 @@ const ( WorkerXen = iota ) -func NewWorkerList(count int, workerType int) (ws WorkerList, err error) { +func NewWorkerList(workers []WorkerSet, workerType int) (ws WorkerList, err error) { + count := 0 + + // wsi: WorkerSet index + for wsi := range workers { + count += workers[wsi].Count + } + + fmt.Println("Making ", count, " total workers") ws = WorkerList(make([]WorkerState, count)) - for i := 0; i< count; i++ { - switch workerType { - case WorkerProcess: - ws[i].w = &ProcessWorker{} - case WorkerXen: - ws[i].w = &XenWorker{} - default: - err = fmt.Errorf("Unknown type: %d", workerType) - } - ws[i].w.SetId(i) + // wli: WorkerList index + wli := 0 + for wsi := range workers { + for i := 0; i < workers[wsi].Count; i, wli = i+1, wli+1 { + switch workerType { + case WorkerProcess: + ws[wli].w = &ProcessWorker{} + case WorkerXen: + ws[wli].w = &XenWorker{} + default: + err = fmt.Errorf("Unknown type: %d", workerType) + } + ws[wli].w.SetId(wli) - ws[i].w.Init(WorkerParams{[]string{"burnwait", "20", "20000000"}}) + ws[wli].w.Init(workers[wsi].Params) + } } return } func main() { - killed := false - - count := 2 + bp := BenchmarkParams{ + Workers:[]WorkerSet{ + {Params:WorkerParams{[]string{"burnwait", "20", "20000000"}}, + Count:2}, + {Params:WorkerParams{[]string{"burnwait", "10", "30000000"}}, + Count:3}, + }, + RuntimeSeconds:5, + } + + Workers, err := NewWorkerList(bp.Workers, WorkerProcess) + if err != nil { + fmt.Println("Error creating workers: %v", err) + return + } report := make(chan WorkerReport) done := make(chan bool)
@@ -105,14 +139,10 @@ func main() { signal.Notify(signals, os.Interrupt) - Workers, err := NewWorkerList(count, WorkerProcess) - if err != nil { - fmt.Println("Error creating workers: %v", err) - return - } - i := Workers.Start(report, done) + timeout := time.After(time.Duration(bp.RuntimeSeconds) * time.Second); + killed := false for i > 0 { select { case r := <-report:
@@ -121,6 +151,7 @@ func main() { i--; fmt.Println(i, "workers left"); case <-signals: + case <-timeout: if ! killed { fmt.Println("SIGINT receieved, shutting down workers") Workers.Stop()
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 11/59 Refactor to move towards benchmark "plans" and data analysis
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
A bit of a roll-up of lots of bits.
--- Makefile | 4 +- benchmark.go | 256 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ main.go | 197 ++++++++++----------------------------------- 3 files changed, 302 insertions(+), 155 deletions(-) create mode 100644 benchmark.go
Makefile +2 -2
@@ -1,10 +1,10 @@ -BIN = controller +BIN = schedbench BINALL = $(BIN) .PHONY: all all: $(BIN) -controller: main.go processworker.go xenworker.go +schedbench: main.go processworker.go xenworker.go benchmark.go go build -o $@ $^ .PHONY: clean
benchmark.go new file +256 -0
256 lines not on this page · raw message
main.go +44 -153
207 lines not on this page · raw message
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 12/59 Basic 'report' functionality
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
Go through the raw data and re-calculate throughput for each timeframe. Record for each worker the min and max of these; then take an average over the whole run.
Have the report go through each and show the worker setup, as well as the avg, min, and max for each worker.
Also default to running Xen again (rather than processes), and clean up some chattiness wrt starting Xen processes.
Finally, make the "plan" slightly more programmatic, and test a more "pipelined" testcase.
--- benchmark.go | 163 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- main.go | 56 ++++++++++++++++---- xenworker.go | 4 +- 3 files changed, 205 insertions(+), 18 deletions(-)
benchmark.go +158 -5
@@ -9,6 +9,12 @@ import ( "encoding/json" ) +type WorkerSummary struct { + MaxTput float64 + AvgTput float64 + MinTput float64 +} + type WorkerReport struct { Id int Now int
@@ -43,6 +49,14 @@ type WorkerState struct { LastReport WorkerReport } +func Throughput(lt int, lm int, t int, m int) (tput float64) { + time := float64(t - lt) / SEC + mops := m - lm + + tput = float64(mops) / time + return +} + func Report(ws *WorkerState, r WorkerReport) { //fmt.Println(r)
@@ -52,8 +66,8 @@ func Report(ws *WorkerState, r WorkerReport) { time := float64(r.Now - lr.Now) / SEC mops := r.Mops - lr.Mops - tput := float64(mops) / time - + tput := Throughput(lr.Now, lr.Mops, r.Now, r.Mops) + fmt.Printf("%d Time: %2.3f Mops: %d Tput: %4.2f\n", r.Id, time, mops, tput); }
@@ -114,19 +128,21 @@ func NewWorkerList(workers []WorkerSet, workerType int) (ws WorkerList, err erro } type BenchmarkRunData struct { - Raw []WorkerReport + WorkerCount int + Raw []WorkerReport `json:",omitempty"` + Summary []WorkerSummary `json:",omitempty"` } type BenchmarkRun struct { - Completed bool Label string Workers []WorkerSet RuntimeSeconds int + Completed bool Results BenchmarkRunData } func (run *BenchmarkRun) Run() (err error) { - Workers, err := NewWorkerList(run.Workers, WorkerProcess) + Workers, err := NewWorkerList(run.Workers, WorkerXen) if err != nil { fmt.Println("Error creating workers: %v", err) return
@@ -140,6 +156,8 @@ func (run *BenchmarkRun) Run() (err error) { i := Workers.Start(report, done) + run.Results.WorkerCount = i + // FIXME: // 1. Make a zero timeout mean "never" // 2. Make the signals / timeout thing a bit more rational; signal then timeout shouldn't hard kill
@@ -178,8 +196,121 @@ func (run *BenchmarkRun) Run() (err error) { return } +func (run *BenchmarkRun) checkSummary() (done bool, err error) { + if run.Results.WorkerCount == 0 { + err = fmt.Errorf("Internal error: WorkerCount 0!") + return + } + + if len(run.Results.Summary) == run.Results.WorkerCount { + done = true + return + } + + if len(run.Results.Summary) != 0 { + err = fmt.Errorf("Internal error: len(Summary) %d, len(Workers) %d!\n", + len(run.Results.Summary), run.Results.WorkerCount) + return + } + + return +} + +func (run *BenchmarkRun) Process() (err error) { + done, err := run.checkSummary() + if done || err != nil { + return + } + + wcount := run.Results.WorkerCount + + if len(run.Results.Summary) != 0 { + err = fmt.Errorf("Internal error: len(Summary) %d, len(Workers) %d!\n", + len(run.Results.Summary), wcount) + return + } + + run.Results.Summary = make([]WorkerSummary, wcount) + + // FIXME: Filter out results which started before all have started + + data := make([]struct{ + startTime int + lastTime int + lastMops int}, wcount) + + for i := range run.Results.Raw { + e := run.Results.Raw[i] + if e.Id > wcount { + err = fmt.Errorf("Internal error: id %d > wcount %d", e.Id, wcount) + return + } + + d := &data[e.Id] + s := &run.Results.Summary[e.Id] + + if d.startTime == 0 { + d.startTime = e.Now + } else { + tput := Throughput(d.lastTime, d.lastMops, e.Now, e.Mops) + + if tput > s.MaxTput { + s.MaxTput = tput + } + if tput < s.MinTput || s.MinTput == 0 { + s.MinTput = tput + } + } + d.lastTime = e.Now + d.lastMops = e.Mops + } + + for i := range data { + run.Results.Summary[i].AvgTput = Throughput(data[i].startTime, 0, data[i].lastTime, data[i].lastMops) + } + + return +} + +func (run *BenchmarkRun) TextReport() (err error) { + var done bool + done, err = run.checkSummary() + if err != nil { + return + } + if ! done { + err = fmt.Errorf("Run not yet processed") + return + } + + fmt.Printf("== RUN %s ==", run.Label) + + fmt.Printf(" Workers (%d total):\n", run.Results.WorkerCount) + wStart := 0 + for i := range run.Workers { + ws := &run.Workers[i] + n := ws.Count + params := "" + for _, s := range ws.Params.Args { + params = fmt.Sprintf("%s %s", params, s) + } + fmt.Printf("[%d-%d]: %s\n", wStart, wStart+n-1, params) + wStart += n + } + + fmt.Printf("\n%8s %8s %8s %8s\n", "id", "avg", "min", "max") + for i := 0; i < run.Results.WorkerCount; i++ { + s := &run.Results.Summary[i] + fmt.Printf("%8d %8.2f %8.2f %8.2f\n", + i, s.AvgTput, s.MinTput, s.MaxTput) + } + + return +} + type BenchmarkPlan struct { filename string + WorkerType int Runs []BenchmarkRun }
@@ -254,3 +385,25 @@ func (plan *BenchmarkPlan) Save() (err error) { } return } + +func (plan *BenchmarkPlan) TextReport() (err error) { + for i := range plan.Runs { + r := &plan.Runs[i] + if ! r.Completed { + fmt.Printf("Test [%d] %s not run\n", i, r.Label) + } + + err = r.Process() + if err != nil { + fmt.Printf("Error processing [%d] %s: %v\n", i, r.Label, err) + return + } + + err = r.TextReport() + if err != nil { + return + } + } + + return +}
main.go +45 -11
78 lines not on this page · raw message
xenworker.go +2 -2
@@ -105,7 +105,7 @@ func (w *XenWorker) Init(p WorkerParams) (err error) { return } - fmt.Printf(" %s domid %d\n", w.vmname, w.domid) + //fmt.Printf(" %s domid %d\n", w.vmname, w.domid) } // Set xenstore config
@@ -133,7 +133,7 @@ func (w *XenWorker) Init(p WorkerParams) (err error) { //fmt.Printf("json:\n%s\n", string(rcfgBytes)) rcfgPath := fmt.Sprintf("/local/domain/%d/rumprun/cfg", w.domid) - fmt.Printf("Writing to %s, json config %s\n", rcfgPath, rcfgBytes) + //fmt.Printf("Writing to %s, json config %s\n", rcfgPath, rcfgBytes) args := []string{"xenstore-write", rcfgPath, string(rcfgBytes)} if mock {
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 13/59 Add GPL headers / COPYING file (v2 only)
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
--- benchmark.go | 18 ++++++++++++++++++ main.go | 19 +++++++++++++++++++ processworker.go | 18 ++++++++++++++++++ xenworker.go | 18 ++++++++++++++++++ 4 files changed, 73 insertions(+)
benchmark.go +18 -0
@@ -1,3 +1,21 @@ +/* + * Copyright (C) 2016 George W. Dunlap, Citrix Systems UK Ltd + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License only. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ package main import (
main.go +19 -0
@@ -1,3 +1,22 @@ +/* + * Copyright (C) 2016 George W. Dunlap, Citrix Systems UK Ltd + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License only. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + package main import (
processworker.go +18 -0
@@ -1,3 +1,21 @@ +/* + * Copyright (C) 2016 George W. Dunlap, Citrix Systems UK Ltd + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License only. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ package main import (
xenworker.go +18 -0
@@ -1,3 +1,21 @@ +/* + * Copyright (C) 2016 George W. Dunlap, Citrix Systems UK Ltd + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License only. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ package main import (
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH RFC 13/59] Add GPL headers / COPYING file (v2 only)
Quoted 23 lines · Ronald Rojas
From: George Dunlap <[email protected]>
Signed-off-by George Dunlap <[email protected]>--- benchmark.go | 18 ++++++++++++++++++ main.go | 19 +++++++++++++++++++ processworker.go | 18 ++++++++++++++++++ xenworker.go | 18 ++++++++++++++++++ 4 files changed, 73 insertions(+)benchmark.go +8
-0@@ -1,3 +1,21 @@ +/* + * Copyright (C) 2016 George W. Dunlap, Citrix Systems UK Ltd + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License only. + *
benchmark.go line 18
Quoted 10 lines
benchmark.go +10
-0+ * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */
Considering this library is likely to be linked with other code base, maybe LGPL is better?
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
RFC PATCH 14/59 benchmark: Store data in terms of worker sets and worker ids
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
...rather than having a single global index, in preparation for summarizing sets of workers as well as individual workers.
To do this:
- Define a WorkerId type which consists of the worker set + worker id within that set. Pass this to the workers and use this in the report values.
- Use maps based on this WorkerId for currently running processes, accumulated data, and (for now) the results summary.
In a future patch, we'll break down the results summary by worker sets as well.
--- benchmark.go | 120 +++++++++++++++++++++++++++---------------------------- processworker.go | 4 +- xenworker.go | 6 +-- 3 files changed, 63 insertions(+), 67 deletions(-)
benchmark.go +58 -62
@@ -33,8 +33,17 @@ type WorkerSummary struct { MinTput float64 } -type WorkerReport struct { +type WorkerId struct { + Set int Id int +} + +func (wid WorkerId) String() (string) { + return fmt.Sprintf("%d:%d", wid.Set, wid.Id) +} + +type WorkerReport struct { + Id WorkerId Now int Mops int MaxDelta int
@@ -50,7 +59,7 @@ type WorkerSet struct { } type Worker interface { - SetId(int) + SetId(WorkerId) Init(WorkerParams) error Shutdown() Process(chan WorkerReport, chan bool)
@@ -86,13 +95,13 @@ func Report(ws *WorkerState, r WorkerReport) { tput := Throughput(lr.Now, lr.Mops, r.Now, r.Mops) - fmt.Printf("%d Time: %2.3f Mops: %d Tput: %4.2f\n", r.Id, time, mops, tput); + fmt.Printf("%v Time: %2.3f Mops: %d Tput: %4.2f\n", r.Id, time, mops, tput); } ws.LastReport = r } -type WorkerList []WorkerState +type WorkerList map[WorkerId]*WorkerState func (ws *WorkerList) Start(report chan WorkerReport, done chan bool) (i int) { i = 0
@@ -114,41 +123,44 @@ const ( WorkerXen = iota ) -func NewWorkerList(workers []WorkerSet, workerType int) (ws WorkerList, err error) { - count := 0 +func NewWorkerList(workers []WorkerSet, workerType int) (wl WorkerList, err error) { + wl = WorkerList(make(map[WorkerId]*WorkerState)) - // wsi: WorkerSet index for wsi := range workers { - count += workers[wsi].Count - } + for i := 0; i < workers[wsi].Count; i = i+1 { + Id := WorkerId{Set:wsi,Id:i} - fmt.Println("Making ", count, " total workers") - ws = WorkerList(make([]WorkerState, count)) + ws := wl[Id] - // wli: WorkerList index - wli := 0 - for wsi := range workers { - for i := 0; i < workers[wsi].Count; i, wli = i+1, wli+1 { + if ws != nil { + panic("Duplicate worker for id!") + } + + ws = &WorkerState{} + switch workerType { case WorkerProcess: - ws[wli].w = &ProcessWorker{} + ws.w = &ProcessWorker{} case WorkerXen: - ws[wli].w = &XenWorker{} + ws.w = &XenWorker{} default: err = fmt.Errorf("Unknown type: %d", workerType) + return } - ws[wli].w.SetId(wli) + + ws.w.SetId(Id) - ws[wli].w.Init(workers[wsi].Params) + ws.w.Init(workers[wsi].Params) + + wl[Id] = ws } } return } type BenchmarkRunData struct { - WorkerCount int Raw []WorkerReport `json:",omitempty"` - Summary []WorkerSummary `json:",omitempty"` + Summary map[WorkerId]*WorkerSummary `json:",omitempty"` } type BenchmarkRun struct {
@@ -174,8 +186,6 @@ func (run *BenchmarkRun) Run() (err error) { i := Workers.Start(report, done) - run.Results.WorkerCount = i - // FIXME: // 1. Make a zero timeout mean "never" // 2. Make the signals / timeout thing a bit more rational; signal then timeout shouldn't hard kill
@@ -185,7 +195,7 @@ func (run *BenchmarkRun) Run() (err error) { select { case r := <-report: run.Results.Raw = append(run.Results.Raw, r) - Report(&Workers[r.Id], r) + Report(Workers[r.Id], r) case <-done: i--; fmt.Println(i, "workers left");
@@ -215,22 +225,11 @@ func (run *BenchmarkRun) Run() (err error) { } func (run *BenchmarkRun) checkSummary() (done bool, err error) { - if run.Results.WorkerCount == 0 { - err = fmt.Errorf("Internal error: WorkerCount 0!") - return - } - - if len(run.Results.Summary) == run.Results.WorkerCount { + if run.Results.Summary != nil { done = true return } - if len(run.Results.Summary) != 0 { - err = fmt.Errorf("Internal error: len(Summary) %d, len(Workers) %d!\n", - len(run.Results.Summary), run.Results.WorkerCount) - return - } - return }
@@ -239,33 +238,31 @@ func (run *BenchmarkRun) Process() (err error) { if done || err != nil { return } - - wcount := run.Results.WorkerCount - - if len(run.Results.Summary) != 0 { - err = fmt.Errorf("Internal error: len(Summary) %d, len(Workers) %d!\n", - len(run.Results.Summary), wcount) - return - } - run.Results.Summary = make([]WorkerSummary, wcount) + run.Results.Summary = make(map[WorkerId]*WorkerSummary) - // FIXME: Filter out results which started before all have started - - data := make([]struct{ + type Data struct{ startTime int lastTime int - lastMops int}, wcount) + lastMops int + } + + data := make(map[WorkerId]*Data) + // FIXME: Filter out results which started before all have started for i := range run.Results.Raw { e := run.Results.Raw[i] - if e.Id > wcount { - err = fmt.Errorf("Internal error: id %d > wcount %d", e.Id, wcount) - return - } - d := &data[e.Id] - s := &run.Results.Summary[e.Id] + d := data[e.Id] + if d == nil { + d = &Data{} + data[e.Id] = d + } + s := run.Results.Summary[e.Id] + if s == nil { + s = &WorkerSummary{} + run.Results.Summary[e.Id] = s + } if d.startTime == 0 { d.startTime = e.Now
@@ -283,8 +280,9 @@ func (run *BenchmarkRun) Process() (err error) { d.lastMops = e.Mops } - for i := range data { - run.Results.Summary[i].AvgTput = Throughput(data[i].startTime, 0, data[i].lastTime, data[i].lastMops) + for Id := range data { + run.Results.Summary[Id].AvgTput = Throughput(data[Id].startTime, + 0, data[Id].lastTime, data[Id].lastMops) } return
@@ -303,7 +301,6 @@ func (run *BenchmarkRun) TextReport() (err error) { fmt.Printf("== RUN %s ==", run.Label) - fmt.Printf(" Workers (%d total):\n", run.Results.WorkerCount) wStart := 0 for i := range run.Workers { ws := &run.Workers[i]
@@ -317,10 +314,9 @@ func (run *BenchmarkRun) TextReport() (err error) { } fmt.Printf("\n%8s %8s %8s %8s\n", "id", "avg", "min", "max") - for i := 0; i < run.Results.WorkerCount; i++ { - s := &run.Results.Summary[i] - fmt.Printf("%8d %8.2f %8.2f %8.2f\n", - i, s.AvgTput, s.MinTput, s.MaxTput) + for id, s := range run.Results.Summary { + fmt.Printf("%8v %8.2f %8.2f %8.2f\n", + id, s.AvgTput, s.MinTput, s.MaxTput) } return
processworker.go +2 -2
@@ -28,13 +28,13 @@ import ( ) type ProcessWorker struct { - id int + id WorkerId c *exec.Cmd stdout io.ReadCloser jsonStarted bool } -func (w *ProcessWorker) SetId(i int) { +func (w *ProcessWorker) SetId(i WorkerId) { w.id = i }
xenworker.go +3 -3
@@ -28,7 +28,7 @@ import ( ) type XenWorker struct { - id int + id WorkerId vmname string domid int consoleCmd *exec.Cmd
@@ -52,9 +52,9 @@ type RumpRunConfig struct { Hostname string `json:"hostname"` } -func (w *XenWorker) SetId(i int) { +func (w *XenWorker) SetId(i WorkerId) { w.id = i - w.vmname = fmt.Sprintf("worker-%d", i) + w.vmname = fmt.Sprintf("worker-%v", i) w.domid = -1 // INVALID DOMID }
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 15/59 controller: Move "running" code to a separate file
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
--- Makefile | 2 +- benchmark.go | 153 -------------------------------------------------- run.go | 178 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 179 insertions(+), 154 deletions(-) create mode 100644 run.go
Makefile +1 -1
@@ -4,7 +4,7 @@ BINALL = $(BIN) .PHONY: all all: $(BIN) -schedbench: main.go processworker.go xenworker.go benchmark.go +schedbench: main.go processworker.go xenworker.go benchmark.go run.go go build -o $@ $^ .PHONY: clean
benchmark.go +0 -153
183 lines not on this page · raw message
run.go new file +178 -0
178 lines not on this page · raw message
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 16/59 controller: Rename an element in BenchmarkRun to be more accurate
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
--- benchmark.go | 6 +++--- main.go | 6 +++--- run.go | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-)
benchmark.go +3 -3
@@ -84,7 +84,7 @@ type BenchmarkRunData struct { type BenchmarkRun struct { Label string - Workers []WorkerSet + WorkerSets []WorkerSet RuntimeSeconds int Completed bool Results BenchmarkRunData
@@ -168,8 +168,8 @@ func (run *BenchmarkRun) TextReport() (err error) { fmt.Printf("== RUN %s ==", run.Label) wStart := 0 - for i := range run.Workers { - ws := &run.Workers[i] + for i := range run.WorkerSets { + ws := &run.WorkerSets[i] n := ws.Count params := "" for _, s := range ws.Params.Args {
main.go +3 -3
@@ -46,12 +46,12 @@ func main() { filename:filename, Runs:[]BenchmarkRun{ {Label:"baseline-a", - Workers:[]WorkerSet{ + WorkerSets:[]WorkerSet{ {Params:WorkerParams{workerA}, Count:1}}, RuntimeSeconds:10,}, {Label:"baseline-b", - Workers:[]WorkerSet{ + WorkerSets:[]WorkerSet{ {Params:WorkerParams{workerB}, Count:1}}, RuntimeSeconds:10,},
@@ -62,7 +62,7 @@ func main() { label := fmt.Sprintf("%da+%db", i, i) run := BenchmarkRun{ Label:label, - Workers:[]WorkerSet{ + WorkerSets:[]WorkerSet{ {Params:WorkerParams{workerA}, Count:i}, {Params:WorkerParams{workerB},
run.go +1 -1
@@ -105,7 +105,7 @@ func NewWorkerList(WorkerSets []WorkerSet, workerType int) (wl WorkerList, err e } func (run *BenchmarkRun) Run() (err error) { - Workers, err := NewWorkerList(run.Workers, WorkerXen) + Workers, err := NewWorkerList(run.WorkerSets, WorkerXen) if err != nil { fmt.Println("Error creating workers: %v", err) return
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 17/59 controller: Collect and display statistics on WorkerSets
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
Introduce WorkerSetSummary, to contain WorkerSummary's and collect data for the set.
For now "if false"-out reporting of individual worker averages; we can add this back in as an option later.
--- benchmark.go | 156 +++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 121 insertions(+), 35 deletions(-)
benchmark.go +121 -35
@@ -23,14 +23,9 @@ import ( "os" "io/ioutil" "encoding/json" + "math" ) -type WorkerSummary struct { - MaxTput float64 - AvgTput float64 - MinTput float64 -} - type WorkerId struct { Set int Id int
@@ -77,9 +72,26 @@ func Throughput(lt int, lm int, t int, m int) (tput float64) { return } +type WorkerSummary struct { + MaxTput float64 + AvgTput float64 + MinTput float64 +} + +type WorkerSetSummary struct { + Workers []WorkerSummary + TotalTput float64 + MaxTput float64 + AvgAvgTput float64 + AvgStdDevTput float64 + AvgMaxTput float64 + AvgMinTput float64 + MinTput float64 +} + type BenchmarkRunData struct { Raw []WorkerReport `json:",omitempty"` - Summary map[WorkerId]*WorkerSummary `json:",omitempty"` + Summary []WorkerSetSummary `json:",omitempty"` } type BenchmarkRun struct {
@@ -90,6 +102,12 @@ type BenchmarkRun struct { Results BenchmarkRunData } +type BenchmarkPlan struct { + filename string + WorkerType int + Runs []BenchmarkRun +} + func (run *BenchmarkRun) checkSummary() (done bool, err error) { if run.Results.Summary != nil { done = true
@@ -105,7 +123,7 @@ func (run *BenchmarkRun) Process() (err error) { return } - run.Results.Summary = make(map[WorkerId]*WorkerSummary) + run.Results.Summary = make([]WorkerSetSummary, len(run.WorkerSets)) type Data struct{ startTime int
@@ -118,18 +136,32 @@ func (run *BenchmarkRun) Process() (err error) { // FIXME: Filter out results which started before all have started for i := range run.Results.Raw { e := run.Results.Raw[i] + + if e.Id.Set > len(run.Results.Summary) { + return fmt.Errorf("Internal error: e.Id.Set %d > len(Results.Summary) %d\n", + e.Id.Set, len(run.Results.Summary)) + } + if run.Results.Summary[e.Id.Set].Workers == nil { + run.Results.Summary[e.Id.Set].Workers = make([]WorkerSummary, + run.WorkerSets[e.Id.Set].Count) + } + + ws := &run.Results.Summary[e.Id.Set] + + if e.Id.Id > len(ws.Workers) { + return fmt.Errorf("Internal error: e.Id.Id %d > len(Results.Summary[].Workers) %d\n", + e.Id.Id, len(ws.Workers)) + } + + s := &ws.Workers[e.Id.Id] + d := data[e.Id] if d == nil { d = &Data{} data[e.Id] = d } - s := run.Results.Summary[e.Id] - if s == nil { - s = &WorkerSummary{} - run.Results.Summary[e.Id] = s - } - + if d.startTime == 0 { d.startTime = e.Now } else {
@@ -141,16 +173,63 @@ func (run *BenchmarkRun) Process() (err error) { if tput < s.MinTput || s.MinTput == 0 { s.MinTput = tput } + if tput > ws.MaxTput { + ws.MaxTput = tput + } + if tput < ws.MinTput || ws.MinTput == 0 { + ws.MinTput = tput + } } d.lastTime = e.Now d.lastMops = e.Mops } - for Id := range data { - run.Results.Summary[Id].AvgTput = Throughput(data[Id].startTime, - 0, data[Id].lastTime, data[Id].lastMops) + for Id, d := range data { + ws := &run.Results.Summary[Id.Set] + s := &ws.Workers[Id.Id] + + s.AvgTput = Throughput(d.startTime, 0, d.lastTime, d.lastMops) + if s.AvgTput > ws.AvgMaxTput { + ws.AvgMaxTput = s.AvgTput + } + if s.AvgTput < ws.AvgMinTput || ws.AvgMinTput == 0 { + ws.AvgMinTput = s.AvgTput + } + } - + + // Calculate the average-of-averages for each set + for set := range run.Results.Summary { + ws := &run.Results.Summary[set] + + var total float64 + var count int + for id := range ws.Workers { + total += ws.Workers[id].AvgTput + count++ + } + + // FIXME -- Is this legit? + ws.TotalTput = total + ws.AvgAvgTput = total / float64(count) + } + + // Then calculate the standard deviation + for set := range run.Results.Summary { + ws := &run.Results.Summary[set] + + var total float64 + var count int + + for id := range ws.Workers { + d := ws.Workers[id].AvgTput - ws.AvgAvgTput + total += d * d + count++ + } + v := total / float64(count) + ws.AvgStdDevTput = math.Sqrt(v) + } + return }
@@ -165,33 +244,40 @@ func (run *BenchmarkRun) TextReport() (err error) { return } - fmt.Printf("== RUN %s ==", run.Label) + fmt.Printf("== RUN %s ==\n", run.Label) - wStart := 0 - for i := range run.WorkerSets { - ws := &run.WorkerSets[i] - n := ws.Count + for set := range run.WorkerSets { + ws := &run.WorkerSets[set] params := "" for _, s := range ws.Params.Args { params = fmt.Sprintf("%s %s", params, s) } - fmt.Printf("[%d-%d]: %s\n", wStart, wStart+n-1, params) - wStart += n + fmt.Printf("Set %d: %s\n", set, params) } - fmt.Printf("\n%8s %8s %8s %8s\n", "id", "avg", "min", "max") - for id, s := range run.Results.Summary { - fmt.Printf("%8v %8.2f %8.2f %8.2f\n", - id, s.AvgTput, s.MinTput, s.MaxTput) + fmt.Printf("\n%8s %8s %8s %8s %8s %8s %8s %8s\n", "set", "total", "avgavg", "stdev", "avgmax", "avgmin", "totmax", "totmin") + for set := range run.WorkerSets { + ws := &run.Results.Summary[set] + fmt.Printf("%8d %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n", + set, ws.TotalTput, ws.AvgAvgTput, ws.AvgStdDevTput, ws.AvgMaxTput, ws.AvgMinTput, + ws.MaxTput, ws.MinTput) + } - return -} + if false { + fmt.Printf("\n%8s %8s %8s %8s\n", "workerid", "avg", "min", "max") + for set := range run.Results.Summary { + for id := range run.Results.Summary[set].Workers { + s := run.Results.Summary[set].Workers[id] + fmt.Printf("%2d:%2d %8.2f %8.2f %8.2f\n", + set, id, s.AvgTput, s.MinTput, s.MaxTput) + } + } + } -type BenchmarkPlan struct { - filename string - WorkerType int - Runs []BenchmarkRun + fmt.Printf("\n\n") + + return } func LoadBenchmark(filename string) (plan BenchmarkPlan, err error) {
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 18/59 controller: Add cpupool global config
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
Define WorkerConfig for worker configuration, add "Pool" as a pool in which to place the worker (currently implemented in Xen only).
Add WorkerConfig options at the WorkerSet, BenchmarkRun, and BenchmarkPlan levels; allow local levels to "override" global config options.
The cpupool must already be defined.
--- benchmark.go | 19 ++++++++++++++++++- main.go | 1 + processworker.go | 2 +- run.go | 16 +++++++++++----- xenworker.go | 6 +++++- 5 files changed, 36 insertions(+), 8 deletions(-)
benchmark.go +18 -1
@@ -46,14 +46,27 @@ type WorkerParams struct { Args []string } +type WorkerConfig struct { + Pool string +} + +// Propagate unset values from a higher level +func (l *WorkerConfig) PropagateFrom(g WorkerConfig) { + if l.Pool == "" { + l.Pool = g.Pool + } +} + + type WorkerSet struct { Params WorkerParams + Config WorkerConfig Count int } type Worker interface { SetId(WorkerId) - Init(WorkerParams) error + Init(WorkerParams, WorkerConfig) error Shutdown() Process(chan WorkerReport, chan bool) }
@@ -97,6 +110,7 @@ type BenchmarkRunData struct { type BenchmarkRun struct { Label string WorkerSets []WorkerSet + WorkerConfig RuntimeSeconds int Completed bool Results BenchmarkRunData
@@ -105,6 +119,9 @@ type BenchmarkRun struct { type BenchmarkPlan struct { filename string WorkerType int + // Global options for workers that will be over-ridden by Run + // and WorkerSet config options + WorkerConfig Runs []BenchmarkRun }
main.go +1 -0
@@ -43,6 +43,7 @@ func main() { plan := BenchmarkPlan{ WorkerType:WorkerXen, + WorkerConfig:WorkerConfig{Pool:"schedbench"}, filename:filename, Runs:[]BenchmarkRun{ {Label:"baseline-a",
processworker.go +1 -1
@@ -38,7 +38,7 @@ func (w *ProcessWorker) SetId(i WorkerId) { w.id = i } -func (w *ProcessWorker) Init(p WorkerParams) (err error) { +func (w *ProcessWorker) Init(p WorkerParams, g WorkerConfig) (err error) { w.c = exec.Command("./worker-proc", p.Args...) w.stdout, err = w.c.StdoutPipe()
run.go +11 -5
@@ -96,7 +96,7 @@ func NewWorkerList(WorkerSets []WorkerSet, workerType int) (wl WorkerList, err e ws.w.SetId(Id) - ws.w.Init(WorkerSets[wsi].Params) + ws.w.Init(WorkerSets[wsi].Params, WorkerSets[wsi].Config) wl[Id] = ws }
@@ -105,6 +105,10 @@ func NewWorkerList(WorkerSets []WorkerSet, workerType int) (wl WorkerList, err e } func (run *BenchmarkRun) Run() (err error) { + for wsi := range run.WorkerSets { + run.WorkerSets[wsi].Config.PropagateFrom(run.WorkerConfig) + } + Workers, err := NewWorkerList(run.WorkerSets, WorkerXen) if err != nil { fmt.Println("Error creating workers: %v", err)
@@ -159,14 +163,16 @@ func (run *BenchmarkRun) Run() (err error) { func (plan *BenchmarkPlan) Run() (err error) { for i := range plan.Runs { - if ! plan.Runs[i].Completed { - fmt.Printf("Running test [%d] %s\n", i, plan.Runs[i].Label) - err = plan.Runs[i].Run() + r := &plan.Runs[i]; + if ! r.Completed { + r.WorkerConfig.PropagateFrom(plan.WorkerConfig) + fmt.Printf("Running test [%d] %s\n", i, r.Label) + err = r.Run() if err != nil { return } } - fmt.Printf("Test [%d] %s completed\n", i, plan.Runs[i].Label) + fmt.Printf("Test [%d] %s completed\n", i, r.Label) err = plan.Save() if err != nil { fmt.Println("Error saving: ", err)
xenworker.go +5 -1
@@ -58,7 +58,7 @@ func (w *XenWorker) SetId(i WorkerId) { w.domid = -1 // INVALID DOMID } -func (w *XenWorker) Init(p WorkerParams) (err error) { +func (w *XenWorker) Init(p WorkerParams, g WorkerConfig) (err error) { mock := false // Make xl config file
@@ -80,6 +80,10 @@ func (w *XenWorker) Init(p WorkerParams) (err error) { fmt.Fprintf(cfg, "vcpus = 1\n") fmt.Fprintf(cfg, "on_crash = 'destroy'\n") + if g.Pool != "" { + fmt.Fprintf(cfg, "pool = '%s'\n", g.Pool) + } + // xl create -p [filename] {
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 19/59 Add basic libxl framework, get domain cpu_time
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
Introduce libxl "Context" class with open, close, and dominfo.
Create a global variable in xenworker.go to hold the context; open on first worker creation, close on last worker destruction.
Add a new element to WorkerReport, Cputime, and print it out.
For now, include hard-coded link to local Xen libraries. This should be sorted out at some point.
--- Makefile | 13 +++++-- benchmark.go | 2 ++ libxl.go | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ run.go | 2 +- xenworker.go | 26 ++++++++++++++ 5 files changed, 156 insertions(+), 3 deletions(-) create mode 100644 libxl.go
Makefile +11 -2
@@ -4,8 +4,17 @@ BINALL = $(BIN) .PHONY: all all: $(BIN) -schedbench: main.go processworker.go xenworker.go benchmark.go run.go - go build -o $@ $^ + + +CGO_CFLAGS = -I/build/hg/xen.git/dist/install/usr/local/include +CGO_LIBS = -lyajl -lxenlight + +# FIXME +XENLIB_PATH ?= /build/hg/xen.git/dist/install/usr/local/lib/ +CGO_LDFLAGS = -L$(XENLIB_PATH) -Wl,-rpath-link=$(XENLIB_PATH) $(CGO_LIBS) + +schedbench: main.go processworker.go xenworker.go benchmark.go run.go libxl.go + CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CFLAGS="$(CGO_CFLAGS)" go build -o $@ $^ .PHONY: clean clean:
benchmark.go +2 -0
@@ -24,6 +24,7 @@ import ( "io/ioutil" "encoding/json" "math" + "time" ) type WorkerId struct {
@@ -40,6 +41,7 @@ type WorkerReport struct { Now int Mops int MaxDelta int + Cputime time.Duration } type WorkerParams struct {
libxl.go new file +116 -0
116 lines not on this page · raw message
run.go +1 -1
@@ -41,7 +41,7 @@ func Report(ws *WorkerState, r WorkerReport) { tput := Throughput(lr.Now, lr.Mops, r.Now, r.Mops) - fmt.Printf("%v Time: %2.3f Mops: %d Tput: %4.2f\n", r.Id, time, mops, tput); + fmt.Printf("%v Time: %2.3f Mops: %d Tput: %4.2f Cputime: %v\n", r.Id, time, mops, tput, r.Cputime); } ws.LastReport = r
xenworker.go +26 -0
@@ -27,8 +27,16 @@ import ( "io" ) +type xenGlobal struct { + Ctx Context + count int +} + +var xg xenGlobal + type XenWorker struct { id WorkerId + Ctx Context vmname string domid int consoleCmd *exec.Cmd
@@ -59,6 +67,14 @@ 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 + } + } + xg.count++ + mock := false // Make xl config file
@@ -202,6 +218,11 @@ 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)
@@ -237,6 +258,11 @@ func (w *XenWorker) Process(report chan WorkerReport, done chan bool) { var r WorkerReport json.Unmarshal([]byte(s), &r) r.Id = w.id + di, err := xg.Ctx.DomainInfo(Domid(w.domid)) + // Ignore errors for now + if err == nil { + r.Cputime = di.Cpu_time + } report <- r } else { if s == "START JSON" {
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 20/59 xenworker: Use libxl_domain_unpause rather than forking xl
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
Unpause is a time-sensitive operation; use libxl to unpause directly rather than forking and execing xl for each VM.
--- libxl.go | 14 ++++++++++++++ xenworker.go | 12 ++---------- 2 files changed, 16 insertions(+), 10 deletions(-)
libxl.go +14 -0
@@ -114,3 +114,17 @@ func (Ctx *Context) DomainInfo(Id Domid) (di *Dominfo, err error) { di.Domain_type = int32(cdi.domain_type) return } + +func (Ctx *Context) DomainUnpause(Id Domid) (err error) { + if Ctx.ctx == nil { + err = fmt.Errorf("Context not opened") + return + } + + ret := C.libxl_domain_unpause(Ctx.ctx, C.uint32_t(Id)) + + if ret != 0 { + err = fmt.Errorf("libxl_domain_unpause failed: %d", ret) + } + return +}
xenworker.go +2 -10
@@ -232,16 +232,8 @@ func (w *XenWorker) Shutdown() { // FIXME: Return an error func (w *XenWorker) Process(report chan WorkerReport, done chan bool) { - mock := false - - // xl unpause [vmname] - args := []string{"xl", "unpause", w.vmname} - if mock { - args = append([]string{"echo"}, args...) - } - e := exec.Command(args[0], args[1:]...) - - err := e.Run() + // // xl unpause [vmname] + err := xg.Ctx.DomainUnpause(Domid(w.domid)) if err != nil { fmt.Printf("Error unpausing domain: %v\n", err) return
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 21/59 Report utilization statistics
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
Refactor the min/max into a separate type.
--- benchmark.go | 119 +++++++++++++++++++++++++++++++++++++---------------------- run.go | 4 +- 2 files changed, 78 insertions(+), 45 deletions(-)
benchmark.go +75 -44
@@ -87,21 +87,45 @@ func Throughput(lt int, lm int, t int, m int) (tput float64) { return } +func Utilization(lt int, lct time.Duration, t int, ct time.Duration) (util float64) { + util = float64(ct - lct) / float64(t - lt) + return +} + +type MinMax struct { + Min float64 + Max float64 +} + +func (mm *MinMax) Update(x float64) { + if x > mm.Max { + mm.Max = x + } + if x < mm.Min || mm.Min == 0 { + mm.Min = x + } +} + type WorkerSummary struct { - MaxTput float64 + MinMaxTput MinMax + MinMaxUtil MinMax AvgTput float64 - MinTput float64 + AvgUtil float64 } type WorkerSetSummary struct { Workers []WorkerSummary TotalTput float64 - MaxTput float64 AvgAvgTput float64 + MinMaxTput MinMax + MinMaxAvgTput MinMax AvgStdDevTput float64 - AvgMaxTput float64 - AvgMinTput float64 - MinTput float64 + + TotalUtil float64 + MinMaxUtil MinMax + MinMaxAvgUtil MinMax + AvgAvgUtil float64 + AvgStdDevUtil float64 } type BenchmarkRunData struct {
@@ -146,8 +170,10 @@ func (run *BenchmarkRun) Process() (err error) { type Data struct{ startTime int + startCputime time.Duration lastTime int lastMops int + lastCputime time.Duration } data := make(map[WorkerId]*Data)
@@ -183,24 +209,19 @@ func (run *BenchmarkRun) Process() (err error) { if d.startTime == 0 { d.startTime = e.Now + d.startCputime = e.Cputime } else { tput := Throughput(d.lastTime, d.lastMops, e.Now, e.Mops) - - if tput > s.MaxTput { - s.MaxTput = tput - } - if tput < s.MinTput || s.MinTput == 0 { - s.MinTput = tput - } - if tput > ws.MaxTput { - ws.MaxTput = tput - } - if tput < ws.MinTput || ws.MinTput == 0 { - ws.MinTput = tput - } + util := Utilization(d.lastTime, d.lastCputime, e.Now, e.Cputime) + + s.MinMaxTput.Update(tput) + s.MinMaxUtil.Update(util) + ws.MinMaxTput.Update(tput) + ws.MinMaxUtil.Update(util) } d.lastTime = e.Now d.lastMops = e.Mops + d.lastCputime = e.Cputime } for Id, d := range data {
@@ -208,45 +229,51 @@ func (run *BenchmarkRun) Process() (err error) { s := &ws.Workers[Id.Id] s.AvgTput = Throughput(d.startTime, 0, d.lastTime, d.lastMops) - if s.AvgTput > ws.AvgMaxTput { - ws.AvgMaxTput = s.AvgTput - } - if s.AvgTput < ws.AvgMinTput || ws.AvgMinTput == 0 { - ws.AvgMinTput = s.AvgTput - } - + s.AvgUtil = Utilization(d.startTime, d.startCputime, d.lastTime, d.lastCputime) + + ws.MinMaxAvgTput.Update(s.AvgTput) + ws.MinMaxAvgUtil.Update(s.AvgUtil) } // Calculate the average-of-averages for each set for set := range run.Results.Summary { ws := &run.Results.Summary[set] - var total float64 + var totalTput float64 + var totalUtil float64 var count int for id := range ws.Workers { - total += ws.Workers[id].AvgTput + totalTput += ws.Workers[id].AvgTput + totalUtil += ws.Workers[id].AvgUtil count++ } // FIXME -- Is this legit? - ws.TotalTput = total - ws.AvgAvgTput = total / float64(count) + ws.TotalTput = totalTput + ws.TotalUtil = totalUtil + ws.AvgAvgTput = totalTput / float64(count) + ws.AvgAvgUtil = totalUtil / float64(count) } // Then calculate the standard deviation for set := range run.Results.Summary { ws := &run.Results.Summary[set] - var total float64 + var totalAvgTput float64 + var totalAvgUtil float64 var count int for id := range ws.Workers { - d := ws.Workers[id].AvgTput - ws.AvgAvgTput - total += d * d + d1 := ws.Workers[id].AvgTput - ws.AvgAvgTput + d2 := ws.Workers[id].AvgUtil - ws.AvgAvgUtil + totalAvgTput += d1 * d1 + totalAvgUtil += d2 * d2 count++ } - v := total / float64(count) - ws.AvgStdDevTput = math.Sqrt(v) + v1 := totalAvgTput / float64(count) + v2 := totalAvgUtil / float64(count) + ws.AvgStdDevTput = math.Sqrt(v1) + ws.AvgStdDevUtil = math.Sqrt(v2) } return
@@ -274,22 +301,26 @@ func (run *BenchmarkRun) TextReport() (err error) { fmt.Printf("Set %d: %s\n", set, params) } - fmt.Printf("\n%8s %8s %8s %8s %8s %8s %8s %8s\n", "set", "total", "avgavg", "stdev", "avgmax", "avgmin", "totmax", "totmin") + fmt.Printf("\n%8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s\n", "set", "ttotal", "tavgavg", "tstdev", "tavgmax", "tavgmin", "ttotmax", "ttotmin", "utotal", "uavgavg", "ustdev", "uavgmax", "uavgmin", "utotmax", "utotmin") for set := range run.WorkerSets { ws := &run.Results.Summary[set] - fmt.Printf("%8d %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n", - set, ws.TotalTput, ws.AvgAvgTput, ws.AvgStdDevTput, ws.AvgMaxTput, ws.AvgMinTput, - ws.MaxTput, ws.MinTput) - + fmt.Printf("%8d %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n", + set, + ws.TotalTput, ws.AvgAvgTput, ws.AvgStdDevTput, ws.MinMaxAvgTput.Max, + ws.MinMaxAvgTput.Min, ws.MinMaxTput.Max, ws.MinMaxTput.Min, + ws.TotalUtil, ws.AvgAvgUtil, ws.AvgStdDevUtil, ws.MinMaxAvgUtil.Max, + ws.MinMaxAvgUtil.Min, ws.MinMaxUtil.Max, ws.MinMaxUtil.Min) } - if false { - fmt.Printf("\n%8s %8s %8s %8s\n", "workerid", "avg", "min", "max") + if true { + fmt.Printf("\n%8s %8s %8s %8s %8s %8s %8s\n", "workerid", "tavg", "tmin", "tmax", "uavg", "umin", "umax") for set := range run.Results.Summary { for id := range run.Results.Summary[set].Workers { s := run.Results.Summary[set].Workers[id] - fmt.Printf("%2d:%2d %8.2f %8.2f %8.2f\n", - set, id, s.AvgTput, s.MinTput, s.MaxTput) + fmt.Printf("%2d:%2d %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n", + set, id, + s.AvgTput, s.MinMaxTput.Min, s.MinMaxTput.Max, + s.AvgUtil, s.MinMaxUtil.Min, s.MinMaxUtil.Max) } } }
run.go +3 -1
@@ -40,8 +40,10 @@ func Report(ws *WorkerState, r WorkerReport) { mops := r.Mops - lr.Mops tput := Throughput(lr.Now, lr.Mops, r.Now, r.Mops) + + util := Utilization(lr.Now, lr.Cputime, r.Now, r.Cputime) - fmt.Printf("%v Time: %2.3f Mops: %d Tput: %4.2f Cputime: %v\n", r.Id, time, mops, tput, r.Cputime); + fmt.Printf("%v Time: %2.3f Mops: %d Tput: %4.2f Cputime: %v Util: %4.2f\n", r.Id, time, mops, tput, r.Cputime, util); } ws.LastReport = r
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 22/59 Use tsc for time rather than rumpkernel clock_gettime()
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
The rumpkernel clock_gettime() drifts drastically when the system is overloaded. Switch to using a TSC timesource instead:
* Use tsc_mode='native' in guest config
* Read the host tsc from /proc/cpuinfo when starting a run
* Pass it as an argument to the worker
* Implement now() with rdtsc
The results appear to continue to be accurate even with heavy overcommitment.
--- benchmark.go | 8 ++++++++ run.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ xenworker.go | 1 + 3 files changed, 54 insertions(+)
benchmark.go +8 -0
@@ -48,6 +48,14 @@ type WorkerParams struct { Args []string } +func (l *WorkerParams) SetkHZ(kHZ uint64) { + if l.Args[0] == "kHZ" { + l.Args[1] = fmt.Sprintf("%d", kHZ) + } else { + l.Args = append([]string{"kHZ", fmt.Sprintf("%d", kHZ)}, l.Args...) + } +} + type WorkerConfig struct { Pool string }
run.go +45 -0
66 lines not on this page · raw message
xenworker.go +1 -0
@@ -95,6 +95,7 @@ func (w *XenWorker) Init(p WorkerParams, g WorkerConfig) (err error) { fmt.Fprintf(cfg, "memory = 32\n") fmt.Fprintf(cfg, "vcpus = 1\n") fmt.Fprintf(cfg, "on_crash = 'destroy'\n") + fmt.Fprintf(cfg, "tsc_mode = 'native'\n") if g.Pool != "" { fmt.Fprintf(cfg, "pool = '%s'\n", g.Pool)
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 23/59 run: Don't collect results reported after command to stop guests is issued
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
Particularly on heavily-loaded systems, this can lead to skew as some guests have already stopped processing.
--- run.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
run.go +7 -2
@@ -172,9 +172,14 @@ func (run *BenchmarkRun) Run() (err error) { for i > 0 { select { case r := <-report: - run.Results.Raw = append(run.Results.Raw, r) - Report(Workers[r.Id], r) + if ! stopped { + run.Results.Raw = append(run.Results.Raw, r) + Report(Workers[r.Id], r) + } case <-done: + if ! stopped { + fmt.Println("WARNING: Worker left early") + } i--; fmt.Println(i, "workers left"); case <-timeout:
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 24/59 report: Lots of changes
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
Store raw worker reports in the worker summary for easy printing.
Add "level" argument to textreport to easly switch between different levels of granularity.
Report total throughput, time, and cputime for workers.
When running, print plain time and aggregate cputime in addition to deltas.
--- benchmark.go | 34 +++++++++++++++++++++++++++------- main.go | 2 +- run.go | 7 +++++-- 3 files changed, 33 insertions(+), 10 deletions(-)
benchmark.go +27 -7
@@ -115,8 +115,12 @@ func (mm *MinMax) Update(x float64) { } type WorkerSummary struct { + Raw []WorkerReport MinMaxTput MinMax MinMaxUtil MinMax + TotalTput int + TotalTime time.Duration + TotalCputime time.Duration AvgTput float64 AvgUtil float64 }
@@ -201,7 +205,7 @@ func (run *BenchmarkRun) Process() (err error) { } ws := &run.Results.Summary[e.Id.Set] - + if e.Id.Id > len(ws.Workers) { return fmt.Errorf("Internal error: e.Id.Id %d > len(Results.Summary[].Workers) %d\n", e.Id.Id, len(ws.Workers))
@@ -209,6 +213,8 @@ func (run *BenchmarkRun) Process() (err error) { s := &ws.Workers[e.Id.Id] + s.Raw = append(s.Raw, e) + d := data[e.Id] if d == nil { d = &Data{}
@@ -236,6 +242,10 @@ func (run *BenchmarkRun) Process() (err error) { ws := &run.Results.Summary[Id.Set] s := &ws.Workers[Id.Id] + s.TotalTput = d.lastMops + s.TotalTime = time.Duration(d.lastTime - d.startTime) + s.TotalCputime = d.lastCputime - d.startCputime + s.AvgTput = Throughput(d.startTime, 0, d.lastTime, d.lastMops) s.AvgUtil = Utilization(d.startTime, d.startCputime, d.lastTime, d.lastCputime)
@@ -287,7 +297,7 @@ func (run *BenchmarkRun) Process() (err error) { return } -func (run *BenchmarkRun) TextReport() (err error) { +func (run *BenchmarkRun) TextReport(level int) (err error) { var done bool done, err = run.checkSummary() if err != nil {
@@ -320,15 +330,25 @@ func (run *BenchmarkRun) TextReport() (err error) { ws.MinMaxAvgUtil.Min, ws.MinMaxUtil.Max, ws.MinMaxUtil.Min) } - if true { - fmt.Printf("\n%8s %8s %8s %8s %8s %8s %8s\n", "workerid", "tavg", "tmin", "tmax", "uavg", "umin", "umax") + if level >= 1 { + fmt.Printf("\n%8s %8s %8s %8s %8s %8s %8s %8s %8s %8s\n", "workerid", "toput", "time", "cpu", "tavg", "tmin", "tmax", "uavg", "umin", "umax") for set := range run.Results.Summary { for id := range run.Results.Summary[set].Workers { s := run.Results.Summary[set].Workers[id] - fmt.Printf("%2d:%2d %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n", + fmt.Printf("%2d:%2d %10d %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n", set, id, + s.TotalTput, s.TotalTime.Seconds(), s.TotalCputime.Seconds(), s.AvgTput, s.MinMaxTput.Min, s.MinMaxTput.Max, s.AvgUtil, s.MinMaxUtil.Min, s.MinMaxUtil.Max) + + if level >= 2 { + for _, e := range s.Raw { + time := float64(e.Now) / SEC + fmt.Printf (" [%8.3f] %8.3f %8d %12d\n", time, + e.Cputime.Seconds(), e.Mops, e.MaxDelta) + } + } + } } }
@@ -391,7 +411,7 @@ func (plan *BenchmarkPlan) Save() (err error) { return } -func (plan *BenchmarkPlan) TextReport() (err error) { +func (plan *BenchmarkPlan) TextReport(level int) (err error) { for i := range plan.Runs { r := &plan.Runs[i] if ! r.Completed {
@@ -404,7 +424,7 @@ func (plan *BenchmarkPlan) TextReport() (err error) { return } - err = r.TextReport() + err = r.TextReport(level) if err != nil { return }
main.go +1 -1
@@ -98,7 +98,7 @@ func main() { os.Exit(1) } - err = plan.TextReport() + err = plan.TextReport(2) if err != nil { fmt.Println("Running benchmark run:", err) os.Exit(1)
run.go +5 -2
@@ -39,14 +39,17 @@ func Report(ws *WorkerState, r WorkerReport) { lr := ws.LastReport if (lr.Now > 0) { - time := float64(r.Now - lr.Now) / SEC + time := float64(r.Now) / SEC + dtime := float64(r.Now - lr.Now) / SEC mops := r.Mops - lr.Mops tput := Throughput(lr.Now, lr.Mops, r.Now, r.Mops) util := Utilization(lr.Now, lr.Cputime, r.Now, r.Cputime) - fmt.Printf("%v Time: %2.3f Mops: %d Tput: %4.2f Cputime: %v Util: %4.2f\n", r.Id, time, mops, tput, r.Cputime, util); + fmt.Printf("%v %8.3f [%8.3f] cpu %8.3f [%8.3f] Mops: %8d [%8d] Tput: %4.2f Util: %4.2f\n", + r.Id, time, dtime, r.Cputime.Seconds(), r.Cputime.Seconds() - lr.Cputime.Seconds(), + r.Mops, mops, tput, util); } ws.LastReport = r
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 25/59 main: Change default workload to something a bit more extreme
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
--- main.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
main.go +9 -10
@@ -29,15 +29,15 @@ func main() { switch(os.Args[1]) { case "plan": - workerA := []string{"burnwait", "20", "20000000"} + workerA := []string{"burnwait", "1", "20000000"} //workerB := []string{"burnwait", "10", "20000000"} - workerB := []string{"burnwait", "1", "20000000", - "burnwait", "2", "20000000", - "burnwait", "1", "20000000", - "burnwait", "1", "20000000", - "burnwait", "1", "20000000", - "burnwait", "1", "20000000", - "burnwait", "3", "20000000", + workerB := []string{"burnwait", "1", "30000000", + "burnwait", "2", "30000000", + "burnwait", "1", "30000000", + "burnwait", "1", "30000000", + "burnwait", "1", "30000000", + "burnwait", "1", "30000000", + "burnwait", "3", "30000000", }
@@ -58,7 +58,6 @@ func main() { RuntimeSeconds:10,}, }} - for i := 1; i <= 16 ; i *= 2 { label := fmt.Sprintf("%da+%db", i, i) run := BenchmarkRun{
@@ -98,7 +97,7 @@ func main() { os.Exit(1) } - err = plan.TextReport(2) + err = plan.TextReport(0) if err != nil { fmt.Println("Running benchmark run:", err) os.Exit(1)
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 26/59 Use kops rather than mops
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
1 million operations on my test box takes about 3ms -- meaning the minimum granularity for how long to burn cpu is far longer than typical. Make this kops instead, giving us a minimum granularity of 3us.
Update most of the default workers to have similar patterns but on a 1/100 (nb not 1/1000) scale; with the exception of worker A (1/1000 scale) and the first worker in worker B (1/10 scale).
Also, actually fix the name of the scheduler in the README.
--- benchmark.go | 18 +++++++++--------- main.go | 16 ++++++++-------- run.go | 8 ++++---- 3 files changed, 21 insertions(+), 21 deletions(-)
benchmark.go +9 -9
@@ -39,7 +39,7 @@ func (wid WorkerId) String() (string) { type WorkerReport struct { Id WorkerId Now int - Mops int + Kops int MaxDelta int Cputime time.Duration }
@@ -89,9 +89,9 @@ const ( func Throughput(lt int, lm int, t int, m int) (tput float64) { time := float64(t - lt) / SEC - mops := m - lm + kops := m - lm - tput = float64(mops) / time + tput = float64(kops) / time return }
@@ -184,7 +184,7 @@ func (run *BenchmarkRun) Process() (err error) { startTime int startCputime time.Duration lastTime int - lastMops int + lastKops int lastCputime time.Duration }
@@ -225,7 +225,7 @@ func (run *BenchmarkRun) Process() (err error) { d.startTime = e.Now d.startCputime = e.Cputime } else { - tput := Throughput(d.lastTime, d.lastMops, e.Now, e.Mops) + tput := Throughput(d.lastTime, d.lastKops, e.Now, e.Kops) util := Utilization(d.lastTime, d.lastCputime, e.Now, e.Cputime) s.MinMaxTput.Update(tput)
@@ -234,7 +234,7 @@ func (run *BenchmarkRun) Process() (err error) { ws.MinMaxUtil.Update(util) } d.lastTime = e.Now - d.lastMops = e.Mops + d.lastKops = e.Kops d.lastCputime = e.Cputime }
@@ -242,11 +242,11 @@ func (run *BenchmarkRun) Process() (err error) { ws := &run.Results.Summary[Id.Set] s := &ws.Workers[Id.Id] - s.TotalTput = d.lastMops + s.TotalTput = d.lastKops s.TotalTime = time.Duration(d.lastTime - d.startTime) s.TotalCputime = d.lastCputime - d.startCputime - s.AvgTput = Throughput(d.startTime, 0, d.lastTime, d.lastMops) + s.AvgTput = Throughput(d.startTime, 0, d.lastTime, d.lastKops) s.AvgUtil = Utilization(d.startTime, d.startCputime, d.lastTime, d.lastCputime) ws.MinMaxAvgTput.Update(s.AvgTput)
@@ -345,7 +345,7 @@ func (run *BenchmarkRun) TextReport(level int) (err error) { for _, e := range s.Raw { time := float64(e.Now) / SEC fmt.Printf (" [%8.3f] %8.3f %8d %12d\n", time, - e.Cputime.Seconds(), e.Mops, e.MaxDelta) + e.Cputime.Seconds(), e.Kops, e.MaxDelta) } }
main.go +8 -8
@@ -29,15 +29,15 @@ func main() { switch(os.Args[1]) { case "plan": - workerA := []string{"burnwait", "1", "20000000"} + workerA := []string{"burnwait", "7", "20000"} //workerB := []string{"burnwait", "10", "20000000"} - workerB := []string{"burnwait", "1", "30000000", - "burnwait", "2", "30000000", - "burnwait", "1", "30000000", - "burnwait", "1", "30000000", - "burnwait", "1", "30000000", - "burnwait", "1", "30000000", - "burnwait", "3", "30000000", + workerB := []string{"burnwait", "100", "3000000", + "burnwait", "20", "300000", + "burnwait", "10", "300000", + "burnwait", "10", "300000", + "burnwait", "10", "300000", + "burnwait", "10", "300000", + "burnwait", "30", "300000", }
run.go +4 -4
@@ -41,15 +41,15 @@ func Report(ws *WorkerState, r WorkerReport) { if (lr.Now > 0) { time := float64(r.Now) / SEC dtime := float64(r.Now - lr.Now) / SEC - mops := r.Mops - lr.Mops + kops := r.Kops - lr.Kops - tput := Throughput(lr.Now, lr.Mops, r.Now, r.Mops) + tput := Throughput(lr.Now, lr.Kops, r.Now, r.Kops) util := Utilization(lr.Now, lr.Cputime, r.Now, r.Cputime) - fmt.Printf("%v %8.3f [%8.3f] cpu %8.3f [%8.3f] Mops: %8d [%8d] Tput: %4.2f Util: %4.2f\n", + fmt.Printf("%v %8.3f [%8.3f] cpu %8.3f [%8.3f] Kops: %8d [%8d] Tput: %4.2f Util: %4.2f\n", r.Id, time, dtime, r.Cputime.Seconds(), r.Cputime.Seconds() - lr.Cputime.Seconds(), - r.Mops, mops, tput, util); + r.Kops, kops, tput, util); } ws.LastReport = r
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 27/59 report: Allow report verbosity to be specified
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
Take a third argument to control the level of verbosity.
Also add helpful deltas when reporting the raw results.
--- benchmark.go | 17 +++++++++++++++-- main.go | 11 ++++++++--- 2 files changed, 23 insertions(+), 5 deletions(-)
benchmark.go +15 -2
@@ -342,10 +342,23 @@ func (run *BenchmarkRun) TextReport(level int) (err error) { s.AvgUtil, s.MinMaxUtil.Min, s.MinMaxUtil.Max) if level >= 2 { + var le WorkerReport for _, e := range s.Raw { + var dtime float64 + var dCputime time.Duration + var dKops int time := float64(e.Now) / SEC - fmt.Printf (" [%8.3f] %8.3f %8d %12d\n", time, - e.Cputime.Seconds(), e.Kops, e.MaxDelta) + if e.Now > le.Now { + dtime = float64(e.Now - le.Now) / SEC + dCputime = e.Cputime - le.Cputime + dKops = e.Kops - le.Kops + + } + fmt.Printf (" [%8.3f] (%8.3f) %8.3f (%8.3f) %8d (%8d) %12d\n", + time, dtime, + e.Cputime.Seconds(), dCputime.Seconds(), + e.Kops, dKops, e.MaxDelta) + le = e } }
main.go +8 -3
@@ -22,6 +22,7 @@ package main import ( "fmt" "os" + "strconv" ) func main() {
@@ -29,9 +30,9 @@ func main() { switch(os.Args[1]) { case "plan": - workerA := []string{"burnwait", "7", "20000"} + workerA := []string{"burnwait", "70", "200000"} //workerB := []string{"burnwait", "10", "20000000"} - workerB := []string{"burnwait", "100", "3000000", + workerB := []string{"burnwait", "10", "300000", "burnwait", "20", "300000", "burnwait", "10", "300000", "burnwait", "10", "300000",
@@ -91,13 +92,17 @@ func main() { } case "report": + verbosity := 0 + if len(os.Args) > 2 { + verbosity, _ = strconv.Atoi(os.Args[2]) + } plan, err := LoadBenchmark(filename) if err != nil { fmt.Println("Loading benchmark ", filename, " ", err) os.Exit(1) } - err = plan.TextReport(0) + err = plan.TextReport(verbosity) if err != nil { fmt.Println("Running benchmark run:", err) os.Exit(1)
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 28/59 controller: Handle worker early death
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
Log raw worker output. In the event of an unexpected worker death, dump the output and stop further processing.
Also fix an assert that caused workers to die if the timer was too exact.
--- benchmark.go | 7 ------- processworker.go | 18 ++++++++++++++++-- run.go | 24 ++++++++++++++++++------ xenworker.go | 21 +++++++++++++++++++-- 4 files changed, 53 insertions(+), 17 deletions(-)
benchmark.go +0 -7
@@ -74,13 +74,6 @@ type WorkerSet struct { Count int } -type Worker interface { - SetId(WorkerId) - Init(WorkerParams, WorkerConfig) error - Shutdown() - Process(chan WorkerReport, chan bool) -} - const ( USEC = 1000 MSEC = USEC * 1000
processworker.go +16 -2
@@ -32,6 +32,7 @@ type ProcessWorker struct { c *exec.Cmd stdout io.ReadCloser jsonStarted bool + Log []string } func (w *ProcessWorker) SetId(i WorkerId) {
@@ -54,7 +55,19 @@ func (w *ProcessWorker) Shutdown() { w.c.Process.Kill() } -func (w *ProcessWorker) Process(report chan WorkerReport, done chan bool) { +func (w *ProcessWorker) DumpLog(f io.Writer) (err error) { + b := bufio.NewWriter(f) + defer b.Flush() + for _, line := range w.Log { + _, err = fmt.Println(b, line) + if err != nil { + return + } + } + return +} + +func (w *ProcessWorker) Process(report chan WorkerReport, done chan WorkerId) { w.c.Start() scanner := bufio.NewScanner(w.stdout)
@@ -63,6 +76,7 @@ func (w *ProcessWorker) Process(report chan WorkerReport, done chan bool) { s := scanner.Text() //fmt.Println("Got these bytes: ", s); + w.Log = append(w.Log, s) if w.jsonStarted { var r WorkerReport
@@ -77,7 +91,7 @@ func (w *ProcessWorker) Process(report chan WorkerReport, done chan bool) { } } - done <- true + done <- w.id w.c.Wait() }
run.go +18 -6
@@ -26,6 +26,7 @@ import ( "regexp" "strconv" "bufio" + "io" ) type WorkerState struct {
@@ -33,6 +34,14 @@ type WorkerState struct { LastReport WorkerReport } +type Worker interface { + SetId(WorkerId) + Init(WorkerParams, WorkerConfig) error + Shutdown() + Process(chan WorkerReport, chan WorkerId) + DumpLog(io.Writer) error +} + func Report(ws *WorkerState, r WorkerReport) { //fmt.Println(r)
@@ -57,7 +66,7 @@ func Report(ws *WorkerState, r WorkerReport) { type WorkerList map[WorkerId]*WorkerState -func (ws *WorkerList) Start(report chan WorkerReport, done chan bool) (i int) { +func (ws *WorkerList) Start(report chan WorkerReport, done chan WorkerId) (i int) { i = 0 for j := range *ws { go (*ws)[j].w.Process(report, done)
@@ -160,7 +169,7 @@ func (run *BenchmarkRun) Run() (err error) { } report := make(chan WorkerReport) - done := make(chan bool) + done := make(chan WorkerId) signals := make(chan os.Signal, 1) signal.Notify(signals, os.Interrupt)
@@ -179,12 +188,16 @@ func (run *BenchmarkRun) Run() (err error) { run.Results.Raw = append(run.Results.Raw, r) Report(Workers[r.Id], r) } - case <-done: + case did := <-done: if ! stopped { - fmt.Println("WARNING: Worker left early") + fmt.Println("WARNING: Worker", did, "left early, shutting down workers") + Workers.Stop() + stopped = true + err = fmt.Errorf("Worker %v exited early", did) + Workers[did].w.DumpLog(os.Stdout) } i--; - fmt.Println(i, "workers left"); + fmt.Printf("Worker %v exited; %d workers left\n", did, i); case <-timeout: if ! stopped { Workers.Stop()
@@ -201,7 +214,6 @@ func (run *BenchmarkRun) Run() (err error) { } err = fmt.Errorf("Interrupted") } else { - err = fmt.Errorf("Interrupted") fmt.Println("SIGINT received after stop, exiting without cleaning up") return }
xenworker.go +19 -2
@@ -42,6 +42,7 @@ type XenWorker struct { consoleCmd *exec.Cmd console io.ReadCloser jsonStarted bool + Log []string } // We have to capitalize the element names so that the json class can
@@ -231,8 +232,22 @@ func (w *XenWorker) Shutdown() { } } +func (w *XenWorker) DumpLog(f io.Writer) (err error) { + b := bufio.NewWriter(f) + defer b.Flush() + for _, line := range w.Log { + _, err = fmt.Fprintln(b, line) + if err != nil { + return + } + } + return +} + + + // FIXME: Return an error -func (w *XenWorker) Process(report chan WorkerReport, done chan bool) { +func (w *XenWorker) Process(report chan WorkerReport, done chan WorkerId) { // // xl unpause [vmname] err := xg.Ctx.DomainUnpause(Domid(w.domid)) if err != nil {
@@ -244,6 +259,8 @@ func (w *XenWorker) Process(report chan WorkerReport, done chan bool) { for scanner.Scan() { s := scanner.Text() + + w.Log = append(w.Log, s) //fmt.Println("Got these bytes: ", s);
@@ -265,7 +282,7 @@ func (w *XenWorker) Process(report chan WorkerReport, done chan bool) { } } - done <- true + done <- w.id w.consoleCmd.Wait() }
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 29/59 report: Add basic html report
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
Use Google's chartapi to create a (mostly) self-contained html file. Start with just scatterplots of the raw data for proof-of-concept.
--- Makefile | 2 +- benchmark.go | 1 + htmlreport.go | 233 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ main.go | 12 +++ 4 files changed, 247 insertions(+), 1 deletion(-) create mode 100644 htmlreport.go
Makefile +1 -1
@@ -13,7 +13,7 @@ CGO_LIBS = -lyajl -lxenlight XENLIB_PATH ?= /build/hg/xen.git/dist/install/usr/local/lib/ CGO_LDFLAGS = -L$(XENLIB_PATH) -Wl,-rpath-link=$(XENLIB_PATH) $(CGO_LIBS) -schedbench: main.go processworker.go xenworker.go benchmark.go run.go libxl.go +schedbench: main.go processworker.go xenworker.go benchmark.go run.go libxl.go htmlreport.go CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CFLAGS="$(CGO_CFLAGS)" go build -o $@ $^ .PHONY: clean
benchmark.go +1 -0
@@ -438,3 +438,4 @@ func (plan *BenchmarkPlan) TextReport(level int) (err error) { return } +
htmlreport.go new file +233 -0
233 lines not on this page · raw message
main.go +12 -0
@@ -107,6 +107,18 @@ func main() { fmt.Println("Running benchmark run:", err) os.Exit(1) } + case "htmlreport": + plan, err := LoadBenchmark(filename) + if err != nil { + fmt.Println("Loading benchmark ", filename, " ", err) + os.Exit(1) + } + + err = plan.HTMLReport() + if err != nil { + fmt.Println("Running benchmark run:", err) + os.Exit(1) + } default: fmt.Println("Unknown argument: ", os.Args[1]) }
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 30/59 htmlreport: Include utilization scatterplots
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
Reformat RunRaw so that it's a more generic scatterplot, with the caller specifying the javascript tag, title, and axes. Keep them as a straight list to be displayed rather than defining them on a per-run basis.
Collect a slice of utilization points at the same time as collecting the throughput metrics, add them both at the same time.
While we're here, add "omitempty" to some of the options so no json is generated if nothing is specified. Leave "MinValue" so that we are able to specify a zero origin (which will also be the default).
Finally, don't bother finding minimum and maximum points; the chart plotter will do that anyway.
--- htmlreport.go | 89 +++++++++++++++++++++++++++++++---------------------------- 1 file changed, 47 insertions(+), 42 deletions(-)
htmlreport.go +47 -42
@@ -26,16 +26,17 @@ import ( ) type OptionAxis struct { - Title string `json:"title"` + Title string `json:"title,omitempty"` + // Always include this one so that we can start graphs at 0 MinValue float64 `json:"minValue"` - MaxValue float64 `json:"maxValue"` + MaxValue float64 `json:"maxValue,omitempty"` } type Options struct { - Title string `json:"title"` + Title string `json:"title,omitempty"` HAxis OptionAxis `json:"hAxis"` VAxis OptionAxis `json:"vAxis"` - Legend string `json:"legend"` + Legend string `json:"legend,omitempty"` } type Point struct {
@@ -44,18 +45,21 @@ type Point struct { } type RunRaw struct { - Label string + Tag string + Title string + hTitle string + vTitle string Points [][]Point } -func (options *Options) OutputJavascript(w io.Writer, id int) (err error) { +func (options *Options) OutputJavascript(w io.Writer, tag string) (err error) { var optionsJson []byte optionsJson, err = json.Marshal(options) if err != nil { return } - fmt.Fprintf(w, " var sp%dopt = ", id) + fmt.Fprintf(w, " var %sopt = ", tag) fmt.Fprint(w, string(optionsJson)) fmt.Fprintln(w, ";")
@@ -75,41 +79,29 @@ func (p *Point) OutputJson(w io.Writer, id int, max int) (err error) { return } -func (d *RunRaw) OutputHTML(w io.Writer, run int) (err error) { - fmt.Fprintf(w, " <div class='scatterplot' id='scatterplot%d'></div>\n", run) +func (d *RunRaw) OutputHTML(w io.Writer) (err error) { + fmt.Fprintf(w, " <div class='scatterplot' id='scatterplot%s'></div>\n", d.Tag) return } -func (d *RunRaw) OutputJavascript(w io.Writer, run int) (err error) { +func (d *RunRaw) OutputJavascript(w io.Writer) (err error) { var options Options - options.Title = fmt.Sprintf("Run %s (%d) Individual Throughput", d.Label, run) - options.HAxis.Title = "Time" - options.VAxis.Title = "Throughput" + options.Title = d.Title + options.HAxis.Title = d.hTitle + options.VAxis.Title = d.vTitle - var xmm MinMax - var ymm MinMax - for i := range d.Points { - for j := range d.Points[i] { - xmm.Update(d.Points[i][j].x) - ymm.Update(d.Points[i][j].y) - } - } - - options.HAxis.MaxValue = xmm.Max - options.VAxis.MaxValue = ymm.Max - - err = options.OutputJavascript(w, run) + err = options.OutputJavascript(w, d.Tag) if err != nil { return } - fmt.Printf(" var sp%ddata = new google.visualization.DataTable();\n", run) - fmt.Printf(" sp%ddata.addColumn('number', 'Time');\n", run) + fmt.Printf(" var %sdata = new google.visualization.DataTable();\n", d.Tag) + fmt.Printf(" %sdata.addColumn('number', 'Time');\n", d.Tag) for i := range d.Points { - fmt.Printf(" sp%ddata.addColumn('number', 'Worker %d');\n", run, i) + fmt.Printf(" %sdata.addColumn('number', 'Worker %d');\n", d.Tag, i) } - fmt.Printf(" sp%ddata.addRows([\n", run) + fmt.Printf(" %sdata.addRows([\n", d.Tag) // Can't use json here because we need to be able to use 'null' for non-existent values for i := range d.Points {
@@ -122,8 +114,8 @@ func (d *RunRaw) OutputJavascript(w io.Writer, run int) (err error) { } fmt.Print(" ]);\n") - fmt.Printf(" var sp%dchart = new google.visualization.ScatterChart(document.getElementById('scatterplot%d'));\n", run, run); - fmt.Printf(" sp%dchart.draw(sp%ddata, sp%dopt);\n\n", run, run, run) + fmt.Printf(" var %schart = new google.visualization.ScatterChart(document.getElementById('scatterplot%s'));\n", d.Tag, d.Tag); + fmt.Printf(" %schart.draw(%sdata, %sopt);\n\n", d.Tag, d.Tag, d.Tag) return }
@@ -157,7 +149,7 @@ func (rpt *HTMLReport) Output(w io.Writer) (err error) { `); // Print json chart code for i := range rpt.Raw { - err = rpt.Raw[i].OutputJavascript(w, i) + err = rpt.Raw[i].OutputJavascript(w) if err != nil { return }
@@ -171,7 +163,7 @@ func (rpt *HTMLReport) Output(w io.Writer) (err error) { `); // Print html for i := range rpt.Raw { - err = rpt.Raw[i].OutputHTML(w, i) + err = rpt.Raw[i].OutputHTML(w) if err != nil { return }
@@ -185,25 +177,38 @@ func (rpt *HTMLReport) Output(w io.Writer) (err error) { } func (rpt *HTMLReport) AddRun(run *BenchmarkRun) (err error) { - var d RunRaw - - d.Label = run.Label + var tPut RunRaw + var Util RunRaw + + tPut.Title = fmt.Sprintf("Run %s Individual Throughput", run.Label) + tPut.hTitle = "Time (s)" + tPut.vTitle = "Throughput (kOps)" + Util.Title = fmt.Sprintf("Run %s Individual Utilization", run.Label) + Util.hTitle = "Time (s)" + Util.vTitle = "Utilization" for set := range run.Results.Summary { - var idPoints []Point + var idTput []Point + var idUtil []Point for id := range run.Results.Summary[set].Workers { var le WorkerReport for _, e := range run.Results.Summary[set].Workers[id].Raw { - if e.Now > le.Now { + if e.Kops > 0 { time := float64(e.Now) / SEC tput := Throughput(e.Now, e.Kops, le.Now, le.Kops) - idPoints = append(idPoints, Point{x:time, y:tput}) + util := Utilization(e.Now, e.Cputime, le.Now, le.Cputime) + idTput = append(idTput, Point{x:time, y:tput}) + idUtil = append(idUtil, Point{x:time, y:util}) } le = e } } - d.Points = append(d.Points, idPoints) + tPut.Points = append(tPut.Points, idTput) + Util.Points = append(Util.Points, idUtil) } - rpt.Raw = append(rpt.Raw, d) + tPut.Tag = fmt.Sprintf("raw%d", len(rpt.Raw)) + rpt.Raw = append(rpt.Raw, tPut) + Util.Tag = fmt.Sprintf("raw%d", len(rpt.Raw)) + rpt.Raw = append(rpt.Raw, Util) return }
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 31/59 Make a binary that can run reports on a system without libxl
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
To simplify report-generation and iteration, make a binary that doesn't link against libxl. Create a "dummy" Xen library that just returns errors and warnings.
A better way to do this is probably to do some dlopen hackery (so we can use the same binary), but that's for another day.
--- Makefile | 6 +++++- xenworker_dummy.go | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 xenworker_dummy.go
Makefile +5 -1
@@ -1,4 +1,4 @@ -BIN = schedbench +BIN = schedbench schedbench-report BINALL = $(BIN) .PHONY: all
@@ -16,6 +16,10 @@ CGO_LDFLAGS = -L$(XENLIB_PATH) -Wl,-rpath-link=$(XENLIB_PATH) $(CGO_LIBS) schedbench: main.go processworker.go xenworker.go benchmark.go run.go libxl.go htmlreport.go CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CFLAGS="$(CGO_CFLAGS)" go build -o $@ $^ +# FIXME: Do with dlopen instead +schedbench-report: main.go processworker.go xenworker_dummy.go benchmark.go run.go htmlreport.go + go build -o $@ $^ + .PHONY: clean clean: rm -f $(BINALL)
xenworker_dummy.go new file +54 -0
54 lines not on this page · raw message
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 32/59 controller: Allow specification of an input file
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
So that we can analyze data later if we want.
--- main.go | 194 +++++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 106 insertions(+), 88 deletions(-)
main.go +106 -88
@@ -26,101 +26,119 @@ import ( ) func main() { - filename := "test.bench" - - switch(os.Args[1]) { - case "plan": - workerA := []string{"burnwait", "70", "200000"} - //workerB := []string{"burnwait", "10", "20000000"} - workerB := []string{"burnwait", "10", "300000", - "burnwait", "20", "300000", - "burnwait", "10", "300000", - "burnwait", "10", "300000", - "burnwait", "10", "300000", - "burnwait", "10", "300000", - "burnwait", "30", "300000", - } + Args := os.Args + Args = Args[1:] + filename := "test.bench" - plan := BenchmarkPlan{ - WorkerType:WorkerXen, - WorkerConfig:WorkerConfig{Pool:"schedbench"}, - filename:filename, - Runs:[]BenchmarkRun{ - {Label:"baseline-a", + for len(Args) > 0 { + switch(Args[0]) { + case "-f": + if len(Args) < 2 { + fmt.Println("Need arg for -f") + os.Exit(1) + } + filename = Args[1] + Args = Args[2:] + case "plan": + workerA := []string{"burnwait", "70", "200000"} + //workerB := []string{"burnwait", "10", "20000000"} + workerB := []string{"burnwait", "10", "300000", + "burnwait", "20", "300000", + "burnwait", "10", "300000", + "burnwait", "10", "300000", + "burnwait", "10", "300000", + "burnwait", "10", "300000", + "burnwait", "30", "300000", + } + + + plan := BenchmarkPlan{ + WorkerType:WorkerXen, + WorkerConfig:WorkerConfig{Pool:"schedbench"}, + filename:filename, + Runs:[]BenchmarkRun{ + {Label:"baseline-a", + WorkerSets:[]WorkerSet{ + {Params:WorkerParams{workerA}, + Count:1}}, + RuntimeSeconds:10,}, + {Label:"baseline-b", + WorkerSets:[]WorkerSet{ + {Params:WorkerParams{workerB}, + Count:1}}, + RuntimeSeconds:10,}, + }} + + for i := 1; i <= 16 ; i *= 2 { + label := fmt.Sprintf("%da+%db", i, i) + run := BenchmarkRun{ + Label:label, WorkerSets:[]WorkerSet{ {Params:WorkerParams{workerA}, - Count:1}}, - RuntimeSeconds:10,}, - {Label:"baseline-b", - WorkerSets:[]WorkerSet{ + Count:i}, {Params:WorkerParams{workerB}, - Count:1}}, - RuntimeSeconds:10,}, - }} - - for i := 1; i <= 16 ; i *= 2 { - label := fmt.Sprintf("%da+%db", i, i) - run := BenchmarkRun{ - Label:label, - WorkerSets:[]WorkerSet{ - {Params:WorkerParams{workerA}, - Count:i}, - {Params:WorkerParams{workerB}, - Count:i}}, - RuntimeSeconds:10} - plan.Runs = append(plan.Runs, run) - } - - err := plan.Save() - if err != nil { - fmt.Println("Saving plan ", filename, " ", err) - os.Exit(1) - } - fmt.Println("Created plan in ", filename) - case "run": - plan, err := LoadBenchmark(filename) - if err != nil { - fmt.Println("Loading benchmark ", filename, " ", err) - os.Exit(1) - } - - err = plan.Run() - if err != nil { - fmt.Println("Running benchmark run:", err) - os.Exit(1) - } - - case "report": - verbosity := 0 - if len(os.Args) > 2 { - verbosity, _ = strconv.Atoi(os.Args[2]) - } - plan, err := LoadBenchmark(filename) - if err != nil { - fmt.Println("Loading benchmark ", filename, " ", err) - os.Exit(1) - } - - err = plan.TextReport(verbosity) - if err != nil { - fmt.Println("Running benchmark run:", err) - os.Exit(1) - } - case "htmlreport": - plan, err := LoadBenchmark(filename) - if err != nil { - fmt.Println("Loading benchmark ", filename, " ", err) - os.Exit(1) - } - - err = plan.HTMLReport() - if err != nil { - fmt.Println("Running benchmark run:", err) + Count:i}}, + RuntimeSeconds:10} + plan.Runs = append(plan.Runs, run) + } + + err := plan.Save() + if err != nil { + fmt.Println("Saving plan ", filename, " ", err) + os.Exit(1) + } + fmt.Println("Created plan in ", filename) + Args = Args[1:] + case "run": + plan, err := LoadBenchmark(filename) + if err != nil { + fmt.Println("Loading benchmark ", filename, " ", err) + os.Exit(1) + } + + err = plan.Run() + if err != nil { + fmt.Println("Running benchmark run:", err) + os.Exit(1) + } + Args = Args[1:] + + case "report": + verbosity := 0 + Args = Args[1:] + if len(Args) > 0 { + verbosity, _ = strconv.Atoi(os.Args[0]) + Args = Args[1:] + } + plan, err := LoadBenchmark(filename) + if err != nil { + fmt.Println("Loading benchmark ", filename, " ", err) + os.Exit(1) + } + + err = plan.TextReport(verbosity) + if err != nil { + fmt.Println("Running benchmark run:", err) + os.Exit(1) + } + case "htmlreport": + plan, err := LoadBenchmark(filename) + if err != nil { + fmt.Println("Loading benchmark ", filename, " ", err) + os.Exit(1) + } + + err = plan.HTMLReport() + if err != nil { + fmt.Println("Running benchmark run:", err) + os.Exit(1) + } + Args = Args[1:] + default: + fmt.Println("Unknown argument: ", Args[0]) os.Exit(1) } - default: - fmt.Println("Unknown argument: ", os.Args[1]) } }
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 33/59 controller: Add verbosity argument and update README with new instructions
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
--- main.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
main.go +8 -5
@@ -30,6 +30,7 @@ func main() { Args = Args[1:] filename := "test.bench" + verbosity := 0 for len(Args) > 0 { switch(Args[0]) {
@@ -40,6 +41,13 @@ func main() { } filename = Args[1] Args = Args[2:] + case "-v": + if len(Args) < 2 { + fmt.Println("Need arg for -v") + os.Exit(1) + } + verbosity, _ = strconv.Atoi(Args[1]) + Args = Args[2:] case "plan": workerA := []string{"burnwait", "70", "200000"} //workerB := []string{"burnwait", "10", "20000000"}
@@ -105,12 +113,7 @@ func main() { Args = Args[1:] case "report": - verbosity := 0 Args = Args[1:] - if len(Args) > 0 { - verbosity, _ = strconv.Atoi(os.Args[0]) - Args = Args[1:] - } plan, err := LoadBenchmark(filename) if err != nil { fmt.Println("Loading benchmark ", filename, " ", err)
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 34/59 controller: Make a useful config file
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
Allow a simple "skeleton" config file which can be adapted for the particular use case. Have 'plan' expand this with the real benchmark plan.
Include "sample.bench" as a template to modify. Also update the README.md accordingly.
--- Makefile | 4 +-- benchmark.go | 9 ++++--- main.go | 48 ++++++------------------------------ plan.go | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 93 insertions(+), 47 deletions(-) create mode 100644 plan.go
Makefile +2 -2
@@ -13,11 +13,11 @@ CGO_LIBS = -lyajl -lxenlight XENLIB_PATH ?= /build/hg/xen.git/dist/install/usr/local/lib/ CGO_LDFLAGS = -L$(XENLIB_PATH) -Wl,-rpath-link=$(XENLIB_PATH) $(CGO_LIBS) -schedbench: main.go processworker.go xenworker.go benchmark.go run.go libxl.go htmlreport.go +schedbench: main.go processworker.go xenworker.go benchmark.go run.go libxl.go htmlreport.go plan.go CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CFLAGS="$(CGO_CFLAGS)" go build -o $@ $^ # FIXME: Do with dlopen instead -schedbench-report: main.go processworker.go xenworker_dummy.go benchmark.go run.go htmlreport.go +schedbench-report: main.go processworker.go xenworker_dummy.go benchmark.go run.go htmlreport.go plan.go go build -o $@ $^ .PHONY: clean
benchmark.go +5 -4
@@ -148,12 +148,13 @@ type BenchmarkRun struct { } type BenchmarkPlan struct { - filename string - WorkerType int + Input *PlanInput `json:",omitempty"` + filename string `json:",omitempty"` + WorkerType int `json:",omitempty"` // Global options for workers that will be over-ridden by Run // and WorkerSet config options - WorkerConfig - Runs []BenchmarkRun + WorkerConfig `json:",omitempty"` + Runs []BenchmarkRun `json:",omitempty"` } func (run *BenchmarkRun) checkSummary() (done bool, err error) {
main.go +7 -41
56 lines not on this page · raw message
plan.go new file +79 -0
79 lines not on this page · raw message
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 35/59 libxl: Add ListCpupool
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
Add libxl bindings for libxl_list_cpupool().
Define the Scheduler type (based on libxl_schedler) with appropriate constants and string functions.
Punt on the cpumap part of CpupoolInfo for now.
Also create "xltest" command for testing libxl bindings
--- libxl.go | 152 +++++++++++++++++++++++++++++++++++++++++++++++++++++ main.go | 5 ++ xenworker_dummy.go | 4 ++ 3 files changed, 161 insertions(+)
libxl.go +152 -0
@@ -2,6 +2,7 @@ package main /* #include <libxl.h> +#include <stdlib.h> */ import "C"
@@ -128,3 +129,154 @@ func (Ctx *Context) DomainUnpause(Id Domid) (err error) { } return } + + +// typedef struct { +// uint32_t size; /* number of bytes in map */ +// uint8_t *map; +// } libxl_bitmap; +// void libxl_bitmap_init(libxl_bitmap *map); +// void libxl_bitmap_dispose(libxl_bitmap *map); + +// # Consistent with values defined in domctl.h +// # Except unknown which we have made up +// libxl_scheduler = Enumeration("scheduler", [ +// (0, "unknown"), +// (4, "sedf"), +// (5, "credit"), +// (6, "credit2"), +// (7, "arinc653"), +// (8, "rtds"), +// ]) +type Scheduler int +var ( + SchedulerUnknown Scheduler = 0 + SchedulerSedf Scheduler = 4 + SchedulerCredit Scheduler = 5 + SchedulerCredit2 Scheduler = 6 + SchedulerArinc653 Scheduler = 7 + SchedulerRTDS Scheduler = 8 +) + +// const char *libxl_scheduler_to_string(libxl_scheduler p); +// int libxl_scheduler_from_string(const char *s, libxl_scheduler *e); +func (s Scheduler) String() (string) { + cs := C.libxl_scheduler_to_string(C.libxl_scheduler(s)) + // No need to free const return value + + return C.GoString(cs) +} + +func SchedulerFromString(name string) (s Scheduler, err error) { + cname := C.CString(name) + defer C.free(unsafe.Pointer(cname)) + + var cs C.libxl_scheduler + + ret := C.libxl_scheduler_from_string(cname, &cs) + if ret != 0 { + err = fmt.Errorf("libxl_scheduler_from_string failed: %d", ret) + return + } + + s = Scheduler(cs) + + return +} + +// libxl_cpupoolinfo = Struct("cpupoolinfo", [ +// ("poolid", uint32), +// ("pool_name", string), +// ("sched", libxl_scheduler), +// ("n_dom", uint32), +// ("cpumap", libxl_bitmap) +// ], dir=DIR_OUT) + +type CpupoolInfo struct { + PoolId uint32 + PoolName string + Scheduler Scheduler + DomainCount int + // Punt on cpumap for now +} + +// libxl_cpupoolinfo * libxl_list_cpupool(libxl_ctx*, int *nb_pool_out); +// void libxl_cpupoolinfo_list_free(libxl_cpupoolinfo *list, int nb_pool); +func (Ctx *Context) ListCpupool() (list []CpupoolInfo) { + var nbPool C.int + + c_cpupool_list := C.libxl_list_cpupool(Ctx.ctx, &nbPool) + + defer C.libxl_cpupoolinfo_list_free(c_cpupool_list, nbPool) + + if int(nbPool) == 0 { + return + } + + // Magic + cpupoolListSlice := (*[1 << 30]C.libxl_cpupoolinfo)(unsafe.Pointer(c_cpupool_list))[:nbPool:nbPool] + + for i := range cpupoolListSlice { + var info CpupoolInfo + + info.PoolId = uint32(cpupoolListSlice[i].poolid) + info.PoolName = C.GoString(cpupoolListSlice[i].pool_name) + info.Scheduler = Scheduler(cpupoolListSlice[i].sched) + info.DomainCount = int(cpupoolListSlice[i].n_dom) + + list = append(list, info) + } + + return +} + +func (Ctx *Context) CpupoolFindByName(name string) (info CpupoolInfo, found bool) { + plist := Ctx.ListCpupool() + + for i := range plist { + if plist[i].PoolName == name { + found = true + info = plist[i] + return + } + } + return +} + +func XlTest(Args []string) { + var Ctx Context + + err := Ctx.Open() + if err != nil { + fmt.Printf("Opening context: %v\n", err) + return + } + + pool, found := Ctx.CpupoolFindByName("schedbench") + + if found { + fmt.Printf("%v\n", pool) + + a := int(pool.Scheduler) + b := pool.Scheduler.String() + c, err := SchedulerFromString(b) + + if err != nil { + fmt.Printf("Error: %v\n", err) + } + + fmt.Printf("a: %d b: %s c: %d\n", a, b, int(c)) + } else { + fmt.Printf("schedbench not found") + } + + pool, found = Ctx.CpupoolFindByName("schedbnch") + + if found { + fmt.Printf("%v\n", pool) + } else { + fmt.Printf("schedbnch not found") + } + + Ctx.Close() +}
main.go +5 -0
@@ -104,6 +104,11 @@ func main() { os.Exit(1) } Args = Args[1:] + + case "xltest": + XlTest(Args) + Args = nil + default: fmt.Println("Unknown argument: ", Args[0]) os.Exit(1)
xenworker_dummy.go +4 -0
@@ -26,6 +26,10 @@ import ( type XenWorker struct { } +func XlTest(Args []string) { + return +} + func (w *XenWorker) SetId(i WorkerId) { }
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 36/59 controller: Make 'dummy' at the level of 'run' rather than xenworker
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
Get rid of xenworker_dummy.go and use stubs.go instead. This is much cleaner (as evidenced by the size of the file), and allows us to use libxl-based things in run.go without having to make a load of dummy libxl stub functions.
--- Makefile | 2 +- stubs.go | 34 ++++++++++++++++++++++++++++++++ xenworker_dummy.go | 58 ------------------------------------------------------ 3 files changed, 35 insertions(+), 59 deletions(-) create mode 100644 stubs.go delete mode 100644 xenworker_dummy.go
Makefile +1 -1
@@ -17,7 +17,7 @@ schedbench: main.go processworker.go xenworker.go benchmark.go run.go libxl.go h CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CFLAGS="$(CGO_CFLAGS)" go build -o $@ $^ # FIXME: Do with dlopen instead -schedbench-report: main.go processworker.go xenworker_dummy.go benchmark.go run.go htmlreport.go plan.go +schedbench-report: main.go benchmark.go stubs.go htmlreport.go plan.go go build -o $@ $^ .PHONY: clean
stubs.go new file +34 -0
@@ -0,0 +1,34 @@ +/* + * Copyright (C) 2016 George W. Dunlap, Citrix Systems UK Ltd + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; version 2 of the + * License only. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ +package main + +import ( + "fmt" +) + +func (plan *BenchmarkPlan) Run() (err error) { + err = fmt.Errorf("Not implemented") + + return +} + +func XlTest(Args []string) { + return +} +
xenworker_dummy.go deleted +0 -58
58 lines not on this page · raw message
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 37/59 libxl.go: Provide a single global context by default
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
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).
--- libxl.go | 12 +++++------- run.go | 7 +++++++ xenworker.go | 25 +++++-------------------- 3 files changed, 17 insertions(+), 27 deletions(-)
libxl.go +5 -7
@@ -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 {
run.go +7 -0
@@ -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];
xenworker.go +5 -20
@@ -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
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 38/59 controller: Allow multiple schedulers in the same benchmark file
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
First, add a RunConfig element to BenchmarkRun, which contains a (string) name of the scheduler for this run.
Add run.Ready(), which if RunConfig.Scheduler is non-null, will check to see if the cpupool in which the VMs will run (either WorkerConfig.Pool or PoolID 0) has the specified scheduler.
Finally, when expanding the SimpleMatrix plan, if SimpleMatrix.Schedulers is non-emply, add it to the matrix of runs. Put them next to each other so that it's easy to compare similar runs on different schedulers.
Refactor schedbench.sh to account for this, and also update the README.md.
--- benchmark.go | 5 +++++ plan.go | 38 +++++++++++++++++++++++++++----------- run.go | 59 +++++++++++++++++++++++++++++++++++++++++++++++++---------- 3 files changed, 81 insertions(+), 21 deletions(-)
benchmark.go +5 -0
@@ -138,10 +138,15 @@ type BenchmarkRunData struct { Summary []WorkerSetSummary `json:",omitempty"` } +type RunConfig struct { + Scheduler string +} + type BenchmarkRun struct { Label string WorkerSets []WorkerSet WorkerConfig + RunConfig RuntimeSeconds int Completed bool Results BenchmarkRunData
plan.go +27 -11
@@ -35,29 +35,42 @@ func (plan *BenchmarkPlan) ExpandInput() (err error) { WorkerPresets[k] = plan.Input.WorkerPresets[k]; } + // Use named schedulers, or default to "" (which will use the + // current one) + var schedulers []string + if plan.Input.SimpleMatrix.Schedulers != nil { + schedulers = plan.Input.SimpleMatrix.Schedulers + } else { + schedulers = append(schedulers, "") + } + // Always do the baselines for _, wn := range plan.Input.SimpleMatrix.Workers { wp := WorkerPresets[wn] - + if wp.Args == nil { err = fmt.Errorf("Invalid worker preset: %s", wn) return } - + run := BenchmarkRun{ - Label:wn+" baseline", WorkerSets:[]WorkerSet{{Params:wp, Count:1}}, RuntimeSeconds:10, } - - plan.Runs = append(plan.Runs, run) + + for _, s := range schedulers { + fmt.Printf("Making baseline %s run, sched %s\n", wn, s) + run.RunConfig.Scheduler = s + run.Label = wn+" baseline "+s + plan.Runs = append(plan.Runs, run) + } } - + for _, c := range plan.Input.SimpleMatrix.Count { run := BenchmarkRun{ RuntimeSeconds:10, } - + var label string for _, wn := range plan.Input.SimpleMatrix.Workers { wp := WorkerPresets[wn]
@@ -65,14 +78,17 @@ func (plan *BenchmarkPlan) ExpandInput() (err error) { if label != "" { label = label+" + " } - label = fmt.Sprintf("%s%s %d", label, wn, c) + label = fmt.Sprintf("%s%s %d ", label, wn, c) ws := WorkerSet{Params:wp, Count:c} run.WorkerSets = append(run.WorkerSets, ws) } - run.Label = label - - plan.Runs = append(plan.Runs, run) + for _, s := range schedulers { + fmt.Printf("Making count %d run, sched %s\n", c, s) + run.RunConfig.Scheduler = s + run.Label = label+s + plan.Runs = append(plan.Runs, run) + } } return
run.go +49 -10
82 lines not on this page · raw message
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 39/59 libxl.go: Put common link flags in libxl.go
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
...so that the only things added in the makefile are extra flags required when linking against non-installed builds.
Add in the text of the GPL while we're at it.
--- Makefile | 3 +-- libxl.go | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-)
Makefile +1 -2
@@ -7,11 +7,10 @@ all: $(BIN) CGO_CFLAGS = -I/build/hg/xen.git/dist/install/usr/local/include -CGO_LIBS = -lyajl -lxenlight # FIXME XENLIB_PATH ?= /build/hg/xen.git/dist/install/usr/local/lib/ -CGO_LDFLAGS = -L$(XENLIB_PATH) -Wl,-rpath-link=$(XENLIB_PATH) $(CGO_LIBS) +CGO_LDFLAGS = -L$(XENLIB_PATH) -Wl,-rpath-link=$(XENLIB_PATH) schedbench: main.go processworker.go xenworker.go benchmark.go run.go libxl.go htmlreport.go plan.go CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CFLAGS="$(CGO_CFLAGS)" go build -o $@ $^
libxl.go +19 -0
@@ -1,6 +1,25 @@ +/* + * Copyright (C) 2016 George W. Dunlap, Citrix Systems UK Ltd + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; version 2 of the + * License only. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ package main /* +#cgo LDFLAGS: -lyajl -lxenlight #include <libxl.h> #include <stdlib.h> */
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 40/59 controller: Add / update GPL text
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
Add it to files which are missing it; clarify the wording regarding version 2 only in others.
--- benchmark.go | 2 +- main.go | 2 +- processworker.go | 2 +- xenworker.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)
benchmark.go +1 -1
@@ -3,7 +3,7 @@ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the + * published by the Free Software Foundation; version 2 of the * License only. * * This program is distributed in the hope that it will be useful, but
main.go +1 -1
@@ -3,7 +3,7 @@ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the + * published by the Free Software Foundation; version 2 of the * License only. * * This program is distributed in the hope that it will be useful, but
processworker.go +1 -1
@@ -3,7 +3,7 @@ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the + * published by the Free Software Foundation; version 2 of the * License only. * * This program is distributed in the hope that it will be useful, but
xenworker.go +1 -1
@@ -3,7 +3,7 @@ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the + * published by the Free Software Foundation; version 2 of the * License only. * * This program is distributed in the hope that it will be useful, but
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 41/59 libxl.go: Link statically rather than dynamically
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
Link statically rather than dynamically, because Go prefers that.
This also gets rid of the need for schedbench-report, so disable that from the build (although keep the rule and the dummy file around just in case.
Also update README.md.
--- Makefile | 11 +++++++---- libxl.go | 10 +++++++++- 2 files changed, 16 insertions(+), 5 deletions(-)
Makefile +7 -4
@@ -1,4 +1,4 @@ -BIN = schedbench schedbench-report +BIN = schedbench BINALL = $(BIN) .PHONY: all
@@ -10,12 +10,15 @@ CGO_CFLAGS = -I/build/hg/xen.git/dist/install/usr/local/include # FIXME XENLIB_PATH ?= /build/hg/xen.git/dist/install/usr/local/lib/ -CGO_LDFLAGS = -L$(XENLIB_PATH) -Wl,-rpath-link=$(XENLIB_PATH) +CGO_LDFLAGS = -L$(XENLIB_PATH) -Wl,-rpath-link=$(XENLIB_PATH) schedbench: main.go processworker.go xenworker.go benchmark.go run.go libxl.go htmlreport.go plan.go - CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CFLAGS="$(CGO_CFLAGS)" go build -o $@ $^ + CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CFLAGS="$(CGO_CFLAGS)" go build -ldflags '-linkmode external -extldflags "-static"' -o $@ $^ -# FIXME: Do with dlopen instead +# If we use a statically linked binary we don't need this; the same +# binary can be used on any system. Keep this version (without any +# run support) support) around for now in case we want to go back to +# it. schedbench-report: main.go benchmark.go stubs.go htmlreport.go plan.go go build -o $@ $^
libxl.go +9 -1
@@ -19,12 +19,20 @@ package main /* -#cgo LDFLAGS: -lyajl -lxenlight +#cgo LDFLAGS: -lxenlight -lyajl_s -lxengnttab -lxenstore -lxenguest -lxentoollog -lxenevtchn -lxenctrl -lblktapctl -lxenforeignmemory -lxencall -lz -luuid -lutil #include <libxl.h> #include <stdlib.h> */ import "C" +/* + * Other flags that may be needed at some point: + * -lnl-route-3 -lnl-3 + * + * To get back to simple dynamic linking: +#cgo LDFLAGS: -lxenlight -lyajl +*/ + import ( "unsafe" "fmt"
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 42/59 plan: Allow "templating" from other runs
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
Allow 'plan' to use an existing run as a "template": load the template, discard the runs, and save the result in the new file.
Use like this:
./schedbench -t 18.bench -f 20.bench plan
This will make 20 with an empty plan identical to that in 18.
--- main.go | 38 +++++++++++++++++++++++++++++++++----- plan.go | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 63 insertions(+), 7 deletions(-)
main.go +33 -5
@@ -30,6 +30,7 @@ func main() { Args = Args[1:] filename := "test.bench" + template := "" verbosity := 0 for len(Args) > 0 {
@@ -41,6 +42,13 @@ func main() { } filename = Args[1] Args = Args[2:] + case "-t": + if len(Args) < 2 { + fmt.Println("Need arg for -t") + os.Exit(1) + } + template = Args[1] + Args = Args[2:] case "-v": if len(Args) < 2 { fmt.Println("Need arg for -v")
@@ -49,20 +57,40 @@ func main() { verbosity, _ = strconv.Atoi(Args[1]) Args = Args[2:] case "plan": - plan, err := LoadBenchmark(filename) + // Load either the template benchmark or the filename + loadfile := filename + if template != "" { + loadfile = template + } + plan, err := LoadBenchmark(loadfile) if err != nil { - fmt.Println("Loading benchmark ", filename, " ", err) + fmt.Printf("Loading benchmark %s: %v\n", + loadfile, err) os.Exit(1) } + + if template != "" { + plan.filename = filename + err = plan.ClearRuns() + if err != nil { + fmt.Printf("Clearing runs: %v\n", + err) + os.Exit(1) + } + } - plan.ExpandInput() + err = plan.ExpandInput() + if err != nil { + fmt.Printf("Expanding plan: %v\n", err) + os.Exit(1) + } err = plan.Save() if err != nil { - fmt.Println("Saving plan ", filename, " ", err) + fmt.Printf("Saving plan %s: %v\n", filename, err) os.Exit(1) } - fmt.Println("Created plan in ", filename) + fmt.Printf("Created plan in %s\n", filename) Args = Args[1:] case "run": plan, err := LoadBenchmark(filename)
plan.go +30 -2
@@ -1,3 +1,21 @@ +/* + * Copyright (C) 2016 George W. Dunlap, Citrix Systems UK Ltd + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; version 2 of the + * License only. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ package main import (
@@ -19,15 +37,25 @@ var WorkerPresets = map[string]WorkerParams{ "P001":WorkerParams{[]string{"burnwait", "70", "200000"}}, } +func (plan *BenchmarkPlan) ClearRuns() (err error) { + plan.Runs = nil + + return +} func (plan *BenchmarkPlan) ExpandInput() (err error) { if plan.Runs != nil { - fmt.Printf("plan.Expand: Runs non-empty, not doing anything\n"); + err = fmt.Errorf("Runs non-empty, not doing anything\n"); + return + } + + if plan.Input == nil { + err = fmt.Errorf("Input nil, nothing to do") return } if plan.Input.SimpleMatrix == nil { - fmt.Printf("plan.Expand: SimpleMatrix nil, nothing to do\n"); + err = fmt.Errorf("Input.SimpleMatrix nil, nothing to do\n"); return }
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 43/59 libxl: Add bitmap support
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
Make the structure compatible so that we can just copy things out or in.
Use it to complete the Cpupool structure.
--- libxl.go | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 98 insertions(+), 6 deletions(-)
libxl.go +98 -6
@@ -20,8 +20,8 @@ package main /* #cgo LDFLAGS: -lxenlight -lyajl_s -lxengnttab -lxenstore -lxenguest -lxentoollog -lxenevtchn -lxenctrl -lblktapctl -lxenforeignmemory -lxencall -lz -luuid -lutil -#include <libxl.h> #include <stdlib.h> +#include <libxl.h> */ import "C"
@@ -72,6 +72,7 @@ func (Ctx *Context) Close() (err error) { return } +// Builtins type Domid uint32 type MemKB uint64
@@ -160,8 +161,66 @@ func (Ctx *Context) DomainUnpause(Id Domid) (err error) { // uint32_t size; /* number of bytes in map */ // uint8_t *map; // } libxl_bitmap; -// void libxl_bitmap_init(libxl_bitmap *map); -// void libxl_bitmap_dispose(libxl_bitmap *map); + +// Implement the Go bitmap type such that the underlying data can +// easily be copied in and out. NB that we still have to do copies +// both directions, because cgo runtime restrictions forbid passing to +// a C function a pointer to a Go-allocated structure which contains a +// pointer. +type Bitmap struct { + bitmap []C.uint8_t +} + +func (bm *Bitmap) Alloc(max int) { + bm.bitmap = make([]C.uint8_t, (max + 7) / 8) +} + +// Return a Go bitmap which is a copy of the referred C bitmap. +func bitmapCToGo(cbm *C.libxl_bitmap) (bm Bitmap) { + // Alloc a Go slice for the bytes + size := int(cbm.size) + bm.Alloc(size*8) + + // Make a slice pointing to the C array + mapslice := (*[1 << 30]C.uint8_t)(unsafe.Pointer(cbm._map))[:size:size] + + // And copy the C array into the Go array + copy(bm.bitmap, mapslice) + + return +} + +func (bm *Bitmap) Test(bit int) (bool) { + ubit := uint(bit) + if (bit > bm.Max()) { + return false + } + + return (bm.bitmap[bit / 8] & (1 << (ubit & 7))) != 0 +} + +// FIXME: Do we really just want to silently fail here? +func (bm *Bitmap) Set(bit int) { + ubit := uint(bit) + if (bit > bm.Max()) { + return + } + + bm.bitmap[bit / 8] |= 1 << (ubit & 7) +} + +func (bm *Bitmap) Clear(bit int) { + ubit := uint(bit) + if (bit > bm.Max()) { + return + } + + bm.bitmap[bit / 8] &= ^(1 << (ubit & 7)) +} + +func (bm *Bitmap) Max() (int) { + return len(bm.bitmap) * 8 +} // # Consistent with values defined in domctl.h // # Except unknown which we have made up
@@ -222,7 +281,7 @@ type CpupoolInfo struct { PoolName string Scheduler Scheduler DomainCount int - // Punt on cpumap for now + CpuMap Bitmap } // libxl_cpupoolinfo * libxl_list_cpupool(libxl_ctx*, int *nb_pool_out);
@@ -248,6 +307,7 @@ func (Ctx *Context) ListCpupool() (list []CpupoolInfo) { info.PoolName = C.GoString(cpupoolListSlice[i].pool_name) info.Scheduler = Scheduler(cpupoolListSlice[i].sched) info.DomainCount = int(cpupoolListSlice[i].n_dom) + info.CpuMap = bitmapCToGo(&cpupoolListSlice[i].cpumap) list = append(list, info) }
@@ -268,6 +328,24 @@ func (Ctx *Context) CpupoolFindByName(name string) (info CpupoolInfo, found bool return } +// int libxl_cpupool_create(libxl_ctx *ctx, const char *name, +// libxl_scheduler sched, +// libxl_bitmap cpumap, libxl_uuid *uuid, +// uint32_t *poolid); +// int libxl_cpupool_destroy(libxl_ctx *ctx, uint32_t poolid); +// int libxl_cpupool_rename(libxl_ctx *ctx, const char *name, uint32_t poolid); +// int libxl_cpupool_cpuadd(libxl_ctx *ctx, uint32_t poolid, int cpu); +// int libxl_cpupool_cpuadd_node(libxl_ctx *ctx, uint32_t poolid, int node, int *cpus); +// int libxl_cpupool_cpuadd_cpumap(libxl_ctx *ctx, uint32_t poolid, +// const libxl_bitmap *cpumap); +// int libxl_cpupool_cpuremove(libxl_ctx *ctx, uint32_t poolid, int cpu); +// int libxl_cpupool_cpuremove_node(libxl_ctx *ctx, uint32_t poolid, int node, int *cpus); +// int libxl_cpupool_cpuremove_cpumap(libxl_ctx *ctx, uint32_t poolid, +// const libxl_bitmap *cpumap); +// int libxl_cpupool_movedomain(libxl_ctx *ctx, uint32_t poolid, uint32_t domid); +// int libxl_cpupool_info(libxl_ctx *ctx, libxl_cpupoolinfo *info, uint32_t poolid); + + func XlTest(Args []string) { var Ctx Context
@@ -290,7 +368,21 @@ func XlTest(Args []string) { fmt.Printf("Error: %v\n", err) } - fmt.Printf("a: %d b: %s c: %d\n", a, b, int(c)) + fmt.Printf("a: %d b: %s c: %d\n", a, b, int(c)) + + pool.CpuMap.Set(1) + pool.CpuMap.Set(2) + pool.CpuMap.Clear(2) + + fmt.Printf("cpumap: ") + for i := 0; i < pool.CpuMap.Max() ; i++ { + if pool.CpuMap.Test(i) { + fmt.Printf("x") + } else { + fmt.Printf("-") + } + } + fmt.Printf("\n") } else { fmt.Printf("schedbench not found") }
@@ -300,7 +392,7 @@ func XlTest(Args []string) { if found { fmt.Printf("%v\n", pool) } else { - fmt.Printf("schedbnch not found") + fmt.Printf("schedbnch not found\n") } Ctx.Close()
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 44/59 libxl: Implement CpupoolCreate
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
Implement CpupoolCreate.
For now, follow the lead of "xl cpupool-create", by automatically generating a new uuid each time a new cpupool is created, and by not allowing the user to attempt to set the poolid.
This requires us to implement bytmapGotoC, which C-allocates the appropriate array and copies the Go byte map into it. This must be C-allocated because the runtime restricts how Go-allocated structures can be passed into C function calls.
While we're here, reorganize functions slightly, and change the Bitmap implementation to automatically extend the array if the size of the byte array is too small.
--- libxl.go | 119 +++++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 85 insertions(+), 34 deletions(-)
libxl.go +85 -34
@@ -176,20 +176,38 @@ func (bm *Bitmap) Alloc(max int) { } // Return a Go bitmap which is a copy of the referred C bitmap. -func bitmapCToGo(cbm *C.libxl_bitmap) (bm Bitmap) { +func bitmapCToGo(cbm *C.libxl_bitmap) (gbm Bitmap) { // Alloc a Go slice for the bytes size := int(cbm.size) - bm.Alloc(size*8) + gbm.Alloc(size*8) // Make a slice pointing to the C array mapslice := (*[1 << 30]C.uint8_t)(unsafe.Pointer(cbm._map))[:size:size] // And copy the C array into the Go array - copy(bm.bitmap, mapslice) + copy(gbm.bitmap, mapslice) return } +// Must be C.libxl_bitmap_dispose'd of afterwards +func bitmapGotoC(gbm Bitmap, cbm *C.libxl_bitmap) { + C.libxl_bitmap_init(cbm) + + size := len(gbm.bitmap) + cbm._map = (*C.uint8_t)(C.malloc(C.size_t(size))) + cbm.size = C.uint32_t(size) + if cbm._map == nil { + panic("C.calloc failed!") + } + + // Make a slice pointing to the C array + mapslice := (*[1 << 30]C.uint8_t)(unsafe.Pointer(cbm._map))[:size:size] + + // And copy the Go array into the C array + copy(mapslice, gbm.bitmap) +} + func (bm *Bitmap) Test(bit int) (bool) { ubit := uint(bit) if (bit > bm.Max()) {
@@ -199,14 +217,13 @@ func (bm *Bitmap) Test(bit int) (bool) { return (bm.bitmap[bit / 8] & (1 << (ubit & 7))) != 0 } -// FIXME: Do we really just want to silently fail here? func (bm *Bitmap) Set(bit int) { - ubit := uint(bit) - if (bit > bm.Max()) { - return + ibit := bit / 8; + if (ibit + 1 > len(bm.bitmap)) { + bm.bitmap = append(bm.bitmap, make([]C.uint8_t, ibit+1-len(bm.bitmap))...) } - bm.bitmap[bit / 8] |= 1 << (ubit & 7) + bm.bitmap[ibit] |= 1 << (uint(bit) & 7) } func (bm *Bitmap) Clear(bit int) {
@@ -234,12 +251,12 @@ func (bm *Bitmap) Max() (int) { // ]) type Scheduler int var ( - SchedulerUnknown Scheduler = 0 - SchedulerSedf Scheduler = 4 - SchedulerCredit Scheduler = 5 - SchedulerCredit2 Scheduler = 6 - SchedulerArinc653 Scheduler = 7 - SchedulerRTDS Scheduler = 8 + SchedulerUnknown Scheduler = C.LIBXL_SCHEDULER_UNKNOWN + SchedulerSedf Scheduler = C.LIBXL_SCHEDULER_SEDF + SchedulerCredit Scheduler = C.LIBXL_SCHEDULER_CREDIT + SchedulerCredit2 Scheduler = C.LIBXL_SCHEDULER_CREDIT2 + SchedulerArinc653 Scheduler = C.LIBXL_SCHEDULER_ARINC653 + SchedulerRTDS Scheduler = C.LIBXL_SCHEDULER_RTDS ) // const char *libxl_scheduler_to_string(libxl_scheduler p);
@@ -315,23 +332,38 @@ func (Ctx *Context) ListCpupool() (list []CpupoolInfo) { return } -func (Ctx *Context) CpupoolFindByName(name string) (info CpupoolInfo, found bool) { - plist := Ctx.ListCpupool() +// int libxl_cpupool_create(libxl_ctx *ctx, const char *name, +// libxl_scheduler sched, +// libxl_bitmap cpumap, libxl_uuid *uuid, +// uint32_t *poolid); +// FIXME: uuid +// FIXME: Setting poolid +func (Ctx *Context) CpupoolCreate(Name string, Scheduler Scheduler, Cpumap Bitmap) (err error, Poolid uint32) { + poolid := C.uint32_t(0) + name := C.CString(Name) + defer C.free(unsafe.Pointer(name)) + + // For now, just do what xl does, and make a new uuid every time we create the pool + var uuid C.libxl_uuid + C.libxl_uuid_generate(&uuid) - for i := range plist { - if plist[i].PoolName == name { - found = true - info = plist[i] - return - } + var cbm C.libxl_bitmap + bitmapGotoC(Cpumap, &cbm) + defer C.libxl_bitmap_dispose(&cbm) + + ret := C.libxl_cpupool_create(Ctx.ctx, name, C.libxl_scheduler(Scheduler), + cbm, &uuid, &poolid) + // FIXME: Proper error + if ret != 0 { + err = fmt.Errorf("libxl_cpupool_create failed: %d", ret) + return } + + Poolid = uint32(poolid) + return } -// int libxl_cpupool_create(libxl_ctx *ctx, const char *name, -// libxl_scheduler sched, -// libxl_bitmap cpumap, libxl_uuid *uuid, -// uint32_t *poolid); // int libxl_cpupool_destroy(libxl_ctx *ctx, uint32_t poolid); // int libxl_cpupool_rename(libxl_ctx *ctx, const char *name, uint32_t poolid); // int libxl_cpupool_cpuadd(libxl_ctx *ctx, uint32_t poolid, int cpu);
@@ -345,7 +377,22 @@ func (Ctx *Context) CpupoolFindByName(name string) (info CpupoolInfo, found bool // int libxl_cpupool_movedomain(libxl_ctx *ctx, uint32_t poolid, uint32_t domid); // int libxl_cpupool_info(libxl_ctx *ctx, libxl_cpupoolinfo *info, uint32_t poolid); - +// +// Utility functions +// +func (Ctx *Context) CpupoolFindByName(name string) (info CpupoolInfo, found bool) { + plist := Ctx.ListCpupool() + + for i := range plist { + if plist[i].PoolName == name { + found = true + info = plist[i] + return + } + } + return +} + func XlTest(Args []string) { var Ctx Context
@@ -384,15 +431,19 @@ func XlTest(Args []string) { } fmt.Printf("\n") } else { - fmt.Printf("schedbench not found") - } + fmt.Printf("schedbench not found, creating\n") - pool, found = Ctx.CpupoolFindByName("schedbnch") + var Cpumap Bitmap + var Poolid uint32 - if found { - fmt.Printf("%v\n", pool) - } else { - fmt.Printf("schedbnch not found\n") + Cpumap.Set(15) + + err, Poolid = Ctx.CpupoolCreate("schedbench", SchedulerCredit, Cpumap) + if err != nil { + fmt.Printf("Error creating cpupool: %v\n", err) + } else { + fmt.Printf("Pool id: %d\n", Poolid) + } } Ctx.Close()
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 45/59 libxl: Implement Destroy, Add/Remove operations
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
Also:
* Implement useful Bitmap operations: SetRange(), ClearRange(), IsEmpty(), and And().
* Normalize CpupoolInfo element naming.
* Implement CpupoolMakeFree, which will scan through cpupools freeing the cpus in the map.
--- libxl.go | 187 ++++++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 150 insertions(+), 37 deletions(-)
libxl.go +150 -37
@@ -226,6 +226,12 @@ func (bm *Bitmap) Set(bit int) { bm.bitmap[ibit] |= 1 << (uint(bit) & 7) } +func (bm *Bitmap) SetRange(start int, end int) { + for i := start; i <= end; i++ { + bm.Set(i) + } +} + func (bm *Bitmap) Clear(bit int) { ubit := uint(bit) if (bit > bm.Max()) {
@@ -235,10 +241,42 @@ func (bm *Bitmap) Clear(bit int) { bm.bitmap[bit / 8] &= ^(1 << (ubit & 7)) } +func (bm *Bitmap) ClearRange(start int, end int) { + for i := start; i <= end; i++ { + bm.Clear(i) + } +} + func (bm *Bitmap) Max() (int) { return len(bm.bitmap) * 8 } +func (bm *Bitmap) IsEmpty() (bool) { + for i:=0; i<len(bm.bitmap); i++ { + if bm.bitmap[i] != 0 { + return false + } + } + return true +} + +func (a Bitmap) And(b Bitmap) (c Bitmap) { + var max, min int + if len(a.bitmap) > len(b.bitmap) { + max = len(a.bitmap) + min = len(b.bitmap) + } else { + max = len(b.bitmap) + min = len(a.bitmap) + } + c.bitmap = make([]C.uint8_t, max) + + for i := 0; i < min; i++ { + c.bitmap[i] = a.bitmap[i] & b.bitmap[i] + } + return +} + // # Consistent with values defined in domctl.h // # Except unknown which we have made up // libxl_scheduler = Enumeration("scheduler", [
@@ -294,11 +332,11 @@ func SchedulerFromString(name string) (s Scheduler, err error) { // ], dir=DIR_OUT) type CpupoolInfo struct { - PoolId uint32 + Poolid uint32 PoolName string Scheduler Scheduler DomainCount int - CpuMap Bitmap + Cpumap Bitmap } // libxl_cpupoolinfo * libxl_list_cpupool(libxl_ctx*, int *nb_pool_out);
@@ -320,11 +358,11 @@ func (Ctx *Context) ListCpupool() (list []CpupoolInfo) { for i := range cpupoolListSlice { var info CpupoolInfo - info.PoolId = uint32(cpupoolListSlice[i].poolid) + info.Poolid = uint32(cpupoolListSlice[i].poolid) info.PoolName = C.GoString(cpupoolListSlice[i].pool_name) info.Scheduler = Scheduler(cpupoolListSlice[i].sched) info.DomainCount = int(cpupoolListSlice[i].n_dom) - info.CpuMap = bitmapCToGo(&cpupoolListSlice[i].cpumap) + info.Cpumap = bitmapCToGo(&cpupoolListSlice[i].cpumap) list = append(list, info) }
@@ -365,15 +403,78 @@ func (Ctx *Context) CpupoolCreate(Name string, Scheduler Scheduler, Cpumap Bitma } // int libxl_cpupool_destroy(libxl_ctx *ctx, uint32_t poolid); -// int libxl_cpupool_rename(libxl_ctx *ctx, const char *name, uint32_t poolid); +func (Ctx *Context) CpupoolDestroy(Poolid uint32) (err error) { + ret := C.libxl_cpupool_destroy(Ctx.ctx, C.uint32_t(Poolid)) + // FIXME: Proper error + if ret != 0 { + err = fmt.Errorf("libxl_cpupool_destroy failed: %d", ret) + return + } + + return +} + // int libxl_cpupool_cpuadd(libxl_ctx *ctx, uint32_t poolid, int cpu); -// int libxl_cpupool_cpuadd_node(libxl_ctx *ctx, uint32_t poolid, int node, int *cpus); +func (Ctx *Context) CpupoolCpuadd(Poolid uint32, Cpu int) (err error) { + ret := C.libxl_cpupool_cpuadd(Ctx.ctx, C.uint32_t(Poolid), C.int(Cpu)) + // FIXME: Proper error + if ret != 0 { + err = fmt.Errorf("libxl_cpupool_cpuadd failed: %d", ret) + return + } + + return +} + // int libxl_cpupool_cpuadd_cpumap(libxl_ctx *ctx, uint32_t poolid, // const libxl_bitmap *cpumap); +func (Ctx *Context) CpupoolCpuaddCpumap(Poolid uint32, Cpumap Bitmap) (err error) { + var cbm C.libxl_bitmap + bitmapGotoC(Cpumap, &cbm) + defer C.libxl_bitmap_dispose(&cbm) + + ret := C.libxl_cpupool_cpuadd_cpumap(Ctx.ctx, C.uint32_t(Poolid), &cbm) + // FIXME: Proper error + if ret != 0 { + err = fmt.Errorf("libxl_cpupool_cpuadd_cpumap failed: %d", ret) + return + } + + return +} + // int libxl_cpupool_cpuremove(libxl_ctx *ctx, uint32_t poolid, int cpu); -// int libxl_cpupool_cpuremove_node(libxl_ctx *ctx, uint32_t poolid, int node, int *cpus); +func (Ctx *Context) CpupoolCpuremove(Poolid uint32, Cpu int) (err error) { + ret := C.libxl_cpupool_cpuremove(Ctx.ctx, C.uint32_t(Poolid), C.int(Cpu)) + // FIXME: Proper error + if ret != 0 { + err = fmt.Errorf("libxl_cpupool_cpuremove failed: %d", ret) + return + } + + return +} + // int libxl_cpupool_cpuremove_cpumap(libxl_ctx *ctx, uint32_t poolid, // const libxl_bitmap *cpumap); +func (Ctx *Context) CpupoolCpuremoveCpumap(Poolid uint32, Cpumap Bitmap) (err error) { + var cbm C.libxl_bitmap + bitmapGotoC(Cpumap, &cbm) + defer C.libxl_bitmap_dispose(&cbm) + + ret := C.libxl_cpupool_cpuremove_cpumap(Ctx.ctx, C.uint32_t(Poolid), &cbm) + // FIXME: Proper error + if ret != 0 { + err = fmt.Errorf("libxl_cpupool_cpuremove_cpumap failed: %d", ret) + return + } + + return +} + +// int libxl_cpupool_rename(libxl_ctx *ctx, const char *name, uint32_t poolid); +// int libxl_cpupool_cpuadd_node(libxl_ctx *ctx, uint32_t poolid, int node, int *cpus); +// int libxl_cpupool_cpuremove_node(libxl_ctx *ctx, uint32_t poolid, int node, int *cpus); // int libxl_cpupool_movedomain(libxl_ctx *ctx, uint32_t poolid, uint32_t domid); // int libxl_cpupool_info(libxl_ctx *ctx, libxl_cpupoolinfo *info, uint32_t poolid);
@@ -393,6 +494,22 @@ func (Ctx *Context) CpupoolFindByName(name string) (info CpupoolInfo, found bool return } +func (Ctx *Context) CpupoolMakeFree(Cpumap Bitmap) (err error) { + plist := Ctx.ListCpupool() + + for i := range plist { + var Intersection Bitmap + Intersection = Cpumap.And(plist[i].Cpumap) + if ! Intersection.IsEmpty() { + err = Ctx.CpupoolCpuremoveCpumap(plist[i].Poolid, Intersection) + if err != nil { + return + } + } + } + return +} + func XlTest(Args []string) { var Ctx Context
@@ -405,45 +522,41 @@ func XlTest(Args []string) { pool, found := Ctx.CpupoolFindByName("schedbench") if found { - fmt.Printf("%v\n", pool) + fmt.Printf("Found schedbench, destroying\n") - a := int(pool.Scheduler) - b := pool.Scheduler.String() - c, err := SchedulerFromString(b) + err = Ctx.CpupoolDestroy(pool.Poolid) + if err != nil { + fmt.Printf("Couldn't destroy pool: %v\n", err) + return + } + fmt.Printf("Returning cpus to pool 0 for fun\n") + err = Ctx.CpupoolCpuaddCpumap(0, pool.Cpumap) if err != nil { - fmt.Printf("Error: %v\n", err) + fmt.Printf("Couldn't add cpus to domain 0: %v\n", err) + return } + } - fmt.Printf("a: %d b: %s c: %d\n", a, b, int(c)) + var Cpumap Bitmap - pool.CpuMap.Set(1) - pool.CpuMap.Set(2) - pool.CpuMap.Clear(2) - - fmt.Printf("cpumap: ") - for i := 0; i < pool.CpuMap.Max() ; i++ { - if pool.CpuMap.Test(i) { - fmt.Printf("x") - } else { - fmt.Printf("-") - } - } - fmt.Printf("\n") - } else { - fmt.Printf("schedbench not found, creating\n") + Cpumap.SetRange(12, 15) + + fmt.Printf("Freeing cpus\n") + err = Ctx.CpupoolMakeFree(Cpumap) + if err != nil { + fmt.Printf("Couldn't free cpus: %v\n", err) + return + } - var Cpumap Bitmap - var Poolid uint32 - Cpumap.Set(15) + fmt.Printf("Creating new pool\n") - err, Poolid = Ctx.CpupoolCreate("schedbench", SchedulerCredit, Cpumap) - if err != nil { - fmt.Printf("Error creating cpupool: %v\n", err) - } else { - fmt.Printf("Pool id: %d\n", Poolid) - } + err, Poolid := Ctx.CpupoolCreate("schedbench", SchedulerCredit, Cpumap) + if err != nil { + fmt.Printf("Error creating cpupool: %v\n", err) + } else { + fmt.Printf("Pool id: %d\n", Poolid) } Ctx.Close()
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 46/59 libxl: Reorganize bitmapGotoC
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
No need to "allocate" the structure elsewhere; passing as a return value makes usage a lot cleaner.
--- libxl.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
libxl.go +7 -8
@@ -191,8 +191,8 @@ func bitmapCToGo(cbm *C.libxl_bitmap) (gbm Bitmap) { } // Must be C.libxl_bitmap_dispose'd of afterwards -func bitmapGotoC(gbm Bitmap, cbm *C.libxl_bitmap) { - C.libxl_bitmap_init(cbm) +func bitmapGotoC(gbm Bitmap) (cbm C.libxl_bitmap) { + C.libxl_bitmap_init(&cbm) size := len(gbm.bitmap) cbm._map = (*C.uint8_t)(C.malloc(C.size_t(size)))
@@ -206,6 +206,8 @@ func bitmapGotoC(gbm Bitmap, cbm *C.libxl_bitmap) { // And copy the Go array into the C array copy(mapslice, gbm.bitmap) + + return } func (bm *Bitmap) Test(bit int) (bool) {
@@ -385,8 +387,7 @@ func (Ctx *Context) CpupoolCreate(Name string, Scheduler Scheduler, Cpumap Bitma var uuid C.libxl_uuid C.libxl_uuid_generate(&uuid) - var cbm C.libxl_bitmap - bitmapGotoC(Cpumap, &cbm) + cbm := bitmapGotoC(Cpumap) defer C.libxl_bitmap_dispose(&cbm) ret := C.libxl_cpupool_create(Ctx.ctx, name, C.libxl_scheduler(Scheduler),
@@ -429,8 +430,7 @@ func (Ctx *Context) CpupoolCpuadd(Poolid uint32, Cpu int) (err error) { // int libxl_cpupool_cpuadd_cpumap(libxl_ctx *ctx, uint32_t poolid, // const libxl_bitmap *cpumap); func (Ctx *Context) CpupoolCpuaddCpumap(Poolid uint32, Cpumap Bitmap) (err error) { - var cbm C.libxl_bitmap - bitmapGotoC(Cpumap, &cbm) + cbm := bitmapGotoC(Cpumap) defer C.libxl_bitmap_dispose(&cbm) ret := C.libxl_cpupool_cpuadd_cpumap(Ctx.ctx, C.uint32_t(Poolid), &cbm)
@@ -458,8 +458,7 @@ func (Ctx *Context) CpupoolCpuremove(Poolid uint32, Cpu int) (err error) { // int libxl_cpupool_cpuremove_cpumap(libxl_ctx *ctx, uint32_t poolid, // const libxl_bitmap *cpumap); func (Ctx *Context) CpupoolCpuremoveCpumap(Poolid uint32, Cpumap Bitmap) (err error) { - var cbm C.libxl_bitmap - bitmapGotoC(Cpumap, &cbm) + cbm := bitmapGotoC(Cpumap) defer C.libxl_bitmap_dispose(&cbm) ret := C.libxl_cpupool_cpuremove_cpumap(Ctx.ctx, C.uint32_t(Poolid), &cbm)
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 47/59 libxl: Reorganize code
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
Put all type and enumeration definitions at the top of the file, separated into "builtins" and "idl-generated".
Also define Uuid as C.libxl_uud. (Not sure if this gives us the functionality we need without having to manually copy things in.)
Finally, get rid of Bitmap.Alloc(). It's redundant now that Bitmap.Set() automatically extends the array.
--- libxl.go | 189 ++++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 102 insertions(+), 87 deletions(-)
libxl.go +102 -87
@@ -39,10 +39,102 @@ import ( "time" ) +/* + * Types: Builtins + */ + +type Domid uint32 + +type MemKB uint64 + +// typedef struct { +// uint32_t size; /* number of bytes in map */ +// uint8_t *map; +// } libxl_bitmap; + +// Implement the Go bitmap type such that the underlying data can +// easily be copied in and out. NB that we still have to do copies +// both directions, because cgo runtime restrictions forbid passing to +// a C function a pointer to a Go-allocated structure which contains a +// pointer. +type Bitmap struct { + bitmap []C.uint8_t +} + type Context struct { ctx *C.libxl_ctx } +type Uuid C.libxl_uuid + +/* + * Types: IDL + * + * FIXME: Generate these automatically from the IDL + */ +type Dominfo struct { + Uuid Uuid + Domid Domid + Running bool + Blocked bool + Paused bool + Shutdown bool + Dying bool + Never_stop bool + + Shutdown_reason int32 // FIXME shutdown_reason enumeration + Outstanding_memkb MemKB + Current_memkb MemKB + Shared_memkb MemKB + Paged_memkb MemKB + Max_memkb MemKB + Cpu_time time.Duration + Vcpu_max_id uint32 + Vcpu_online uint32 + Cpupool uint32 + Domain_type int32 //FIXME libxl_domain_type enumeration + +} + +// # Consistent with values defined in domctl.h +// # Except unknown which we have made up +// libxl_scheduler = Enumeration("scheduler", [ +// (0, "unknown"), +// (4, "sedf"), +// (5, "credit"), +// (6, "credit2"), +// (7, "arinc653"), +// (8, "rtds"), +// ]) +type Scheduler int +var ( + SchedulerUnknown Scheduler = C.LIBXL_SCHEDULER_UNKNOWN + SchedulerSedf Scheduler = C.LIBXL_SCHEDULER_SEDF + SchedulerCredit Scheduler = C.LIBXL_SCHEDULER_CREDIT + SchedulerCredit2 Scheduler = C.LIBXL_SCHEDULER_CREDIT2 + SchedulerArinc653 Scheduler = C.LIBXL_SCHEDULER_ARINC653 + SchedulerRTDS Scheduler = C.LIBXL_SCHEDULER_RTDS +) + +// libxl_cpupoolinfo = Struct("cpupoolinfo", [ +// ("poolid", uint32), +// ("pool_name", string), +// ("sched", libxl_scheduler), +// ("n_dom", uint32), +// ("cpumap", libxl_bitmap) +// ], dir=DIR_OUT) + +type CpupoolInfo struct { + Poolid uint32 + PoolName string + Scheduler Scheduler + DomainCount int + Cpumap Bitmap +} + +/* + * Context + */ var Ctx Context func (Ctx *Context) IsOpen() bool {
@@ -72,43 +164,12 @@ func (Ctx *Context) Close() (err error) { return } -// Builtins -type Domid uint32 - -type MemKB uint64 - -// FIXME: Use the idl to generate types -type Dominfo struct { - // FIXME: uuid - Domid Domid - Running bool - Blocked bool - Paused bool - Shutdown bool - Dying bool - Never_stop bool - - Shutdown_reason int32 // FIXME shutdown_reason enumeration - Outstanding_memkb MemKB - Current_memkb MemKB - Shared_memkb MemKB - Paged_memkb MemKB - Max_memkb MemKB - Cpu_time time.Duration - Vcpu_max_id uint32 - Vcpu_online uint32 - Cpupool uint32 - Domain_type int32 //FIXME libxl_domain_type enumeration - -} - func (Ctx *Context) DomainInfo(Id Domid) (di *Dominfo, err error) { if Ctx.ctx == nil { err = fmt.Errorf("Context not opened") return } - var cdi C.libxl_dominfo ret := C.libxl_domain_info(Ctx.ctx, unsafe.Pointer(&cdi), C.uint32_t(Id))
@@ -119,8 +180,12 @@ func (Ctx *Context) DomainInfo(Id Domid) (di *Dominfo, err error) { return } - // FIXME -- use introspection to make this more robust + // We could consider having this boilerplate generated by the + // idl, in a function like this: + // + // di = translateCdomaininfoToGoDomaininfo(cdi) di = &Dominfo{} + di.Uuid = Uuid(cdi.uuid) di.Domid = Domid(cdi.domid) di.Running = bool(cdi.running) di.Blocked = bool(cdi.blocked)
@@ -139,6 +204,7 @@ func (Ctx *Context) DomainInfo(Id Domid) (di *Dominfo, err error) { di.Vcpu_online = uint32(cdi.vcpu_online) di.Cpupool = uint32(cdi.cpupool) di.Domain_type = int32(cdi.domain_type) + return }
@@ -156,30 +222,15 @@ func (Ctx *Context) DomainUnpause(Id Domid) (err error) { return } - -// typedef struct { -// uint32_t size; /* number of bytes in map */ -// uint8_t *map; -// } libxl_bitmap; - -// Implement the Go bitmap type such that the underlying data can -// easily be copied in and out. NB that we still have to do copies -// both directions, because cgo runtime restrictions forbid passing to -// a C function a pointer to a Go-allocated structure which contains a -// pointer. -type Bitmap struct { - bitmap []C.uint8_t -} - -func (bm *Bitmap) Alloc(max int) { - bm.bitmap = make([]C.uint8_t, (max + 7) / 8) -} +/* + * Bitmap operations + */ // Return a Go bitmap which is a copy of the referred C bitmap. func bitmapCToGo(cbm *C.libxl_bitmap) (gbm Bitmap) { // Alloc a Go slice for the bytes size := int(cbm.size) - gbm.Alloc(size*8) + gbm.bitmap = make([]C.uint8_t, size) // Make a slice pointing to the C array mapslice := (*[1 << 30]C.uint8_t)(unsafe.Pointer(cbm._map))[:size:size]
@@ -279,26 +330,6 @@ func (a Bitmap) And(b Bitmap) (c Bitmap) { return } -// # Consistent with values defined in domctl.h -// # Except unknown which we have made up -// libxl_scheduler = Enumeration("scheduler", [ -// (0, "unknown"), -// (4, "sedf"), -// (5, "credit"), -// (6, "credit2"), -// (7, "arinc653"), -// (8, "rtds"), -// ]) -type Scheduler int -var ( - SchedulerUnknown Scheduler = C.LIBXL_SCHEDULER_UNKNOWN - SchedulerSedf Scheduler = C.LIBXL_SCHEDULER_SEDF - SchedulerCredit Scheduler = C.LIBXL_SCHEDULER_CREDIT - SchedulerCredit2 Scheduler = C.LIBXL_SCHEDULER_CREDIT2 - SchedulerArinc653 Scheduler = C.LIBXL_SCHEDULER_ARINC653 - SchedulerRTDS Scheduler = C.LIBXL_SCHEDULER_RTDS -) - // const char *libxl_scheduler_to_string(libxl_scheduler p); // int libxl_scheduler_from_string(const char *s, libxl_scheduler *e); func (s Scheduler) String() (string) {
@@ -325,22 +356,6 @@ func SchedulerFromString(name string) (s Scheduler, err error) { return } -// libxl_cpupoolinfo = Struct("cpupoolinfo", [ -// ("poolid", uint32), -// ("pool_name", string), -// ("sched", libxl_scheduler), -// ("n_dom", uint32), -// ("cpumap", libxl_bitmap) -// ], dir=DIR_OUT) - -type CpupoolInfo struct { - Poolid uint32 - PoolName string - Scheduler Scheduler - DomainCount int - Cpumap Bitmap -} - // libxl_cpupoolinfo * libxl_list_cpupool(libxl_ctx*, int *nb_pool_out); // void libxl_cpupoolinfo_list_free(libxl_cpupoolinfo *list, int nb_pool); func (Ctx *Context) ListCpupool() (list []CpupoolInfo) {
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 48/59 libxl: Add Ctx.CheckOpen
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
To standardize the error in the case that Ctx isn't open. Add checks to all functions which call libxl functions directly.
--- libxl.go | 48 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-)
libxl.go +45 -3
@@ -164,9 +164,16 @@ func (Ctx *Context) Close() (err error) { return } -func (Ctx *Context) DomainInfo(Id Domid) (di *Dominfo, err error) { +func (Ctx *Context) CheckOpen() (err error) { if Ctx.ctx == nil { err = fmt.Errorf("Context not opened") + } + return +} + +func (Ctx *Context) DomainInfo(Id Domid) (di *Dominfo, err error) { + err = Ctx.CheckOpen() + if err != nil { return }
@@ -209,8 +216,8 @@ func (Ctx *Context) DomainInfo(Id Domid) (di *Dominfo, err error) { } func (Ctx *Context) DomainUnpause(Id Domid) (err error) { - if Ctx.ctx == nil { - err = fmt.Errorf("Context not opened") + err = Ctx.CheckOpen() + if err != nil { return }
@@ -359,6 +366,11 @@ func SchedulerFromString(name string) (s Scheduler, err error) { // libxl_cpupoolinfo * libxl_list_cpupool(libxl_ctx*, int *nb_pool_out); // void libxl_cpupoolinfo_list_free(libxl_cpupoolinfo *list, int nb_pool); func (Ctx *Context) ListCpupool() (list []CpupoolInfo) { + err := Ctx.CheckOpen() + if err != nil { + return + } + var nbPool C.int c_cpupool_list := C.libxl_list_cpupool(Ctx.ctx, &nbPool)
@@ -394,6 +406,11 @@ func (Ctx *Context) ListCpupool() (list []CpupoolInfo) { // FIXME: uuid // FIXME: Setting poolid func (Ctx *Context) CpupoolCreate(Name string, Scheduler Scheduler, Cpumap Bitmap) (err error, Poolid uint32) { + err = Ctx.CheckOpen() + if err != nil { + return + } + poolid := C.uint32_t(0) name := C.CString(Name) defer C.free(unsafe.Pointer(name))
@@ -420,6 +437,11 @@ func (Ctx *Context) CpupoolCreate(Name string, Scheduler Scheduler, Cpumap Bitma // int libxl_cpupool_destroy(libxl_ctx *ctx, uint32_t poolid); func (Ctx *Context) CpupoolDestroy(Poolid uint32) (err error) { + err = Ctx.CheckOpen() + if err != nil { + return + } + ret := C.libxl_cpupool_destroy(Ctx.ctx, C.uint32_t(Poolid)) // FIXME: Proper error if ret != 0 {
@@ -432,6 +454,11 @@ func (Ctx *Context) CpupoolDestroy(Poolid uint32) (err error) { // int libxl_cpupool_cpuadd(libxl_ctx *ctx, uint32_t poolid, int cpu); func (Ctx *Context) CpupoolCpuadd(Poolid uint32, Cpu int) (err error) { + err = Ctx.CheckOpen() + if err != nil { + return + } + ret := C.libxl_cpupool_cpuadd(Ctx.ctx, C.uint32_t(Poolid), C.int(Cpu)) // FIXME: Proper error if ret != 0 {
@@ -445,6 +472,11 @@ func (Ctx *Context) CpupoolCpuadd(Poolid uint32, Cpu int) (err error) { // int libxl_cpupool_cpuadd_cpumap(libxl_ctx *ctx, uint32_t poolid, // const libxl_bitmap *cpumap); func (Ctx *Context) CpupoolCpuaddCpumap(Poolid uint32, Cpumap Bitmap) (err error) { + err = Ctx.CheckOpen() + if err != nil { + return + } + cbm := bitmapGotoC(Cpumap) defer C.libxl_bitmap_dispose(&cbm)
@@ -460,6 +492,11 @@ func (Ctx *Context) CpupoolCpuaddCpumap(Poolid uint32, Cpumap Bitmap) (err error // int libxl_cpupool_cpuremove(libxl_ctx *ctx, uint32_t poolid, int cpu); func (Ctx *Context) CpupoolCpuremove(Poolid uint32, Cpu int) (err error) { + err = Ctx.CheckOpen() + if err != nil { + return + } + ret := C.libxl_cpupool_cpuremove(Ctx.ctx, C.uint32_t(Poolid), C.int(Cpu)) // FIXME: Proper error if ret != 0 {
@@ -473,6 +510,11 @@ func (Ctx *Context) CpupoolCpuremove(Poolid uint32, Cpu int) (err error) { // int libxl_cpupool_cpuremove_cpumap(libxl_ctx *ctx, uint32_t poolid, // const libxl_bitmap *cpumap); func (Ctx *Context) CpupoolCpuremoveCpumap(Poolid uint32, Cpumap Bitmap) (err error) { + err = Ctx.CheckOpen() + if err != nil { + return + } + cbm := bitmapGotoC(Cpumap) defer C.libxl_bitmap_dispose(&cbm)
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 49/59 libxl: Implement libxl_cpupool_info and Scheduler.FromString()
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
Unify the libxl_cpupoolinfo -> CpupoolInfo translation in a function.
Also make bitmapCToGo pass-by-value rather than pass-by-reference, since it only has two elements and doesn't need to be modified.
--- libxl.go | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 54 insertions(+), 10 deletions(-)
libxl.go +54 -10
@@ -234,7 +234,7 @@ func (Ctx *Context) DomainUnpause(Id Domid) (err error) { */ // Return a Go bitmap which is a copy of the referred C bitmap. -func bitmapCToGo(cbm *C.libxl_bitmap) (gbm Bitmap) { +func bitmapCToGo(cbm C.libxl_bitmap) (gbm Bitmap) { // Alloc a Go slice for the bytes size := int(cbm.size) gbm.bitmap = make([]C.uint8_t, size)
@@ -338,7 +338,6 @@ func (a Bitmap) And(b Bitmap) (c Bitmap) { } // const char *libxl_scheduler_to_string(libxl_scheduler p); -// int libxl_scheduler_from_string(const char *s, libxl_scheduler *e); func (s Scheduler) String() (string) { cs := C.libxl_scheduler_to_string(C.libxl_scheduler(s)) // No need to free const return value
@@ -346,6 +345,32 @@ func (s Scheduler) String() (string) { return C.GoString(cs) } +// int libxl_scheduler_from_string(const char *s, libxl_scheduler *e); +func (s *Scheduler) FromString(gstr string) (err error) { + cstr := C.CString(gstr) + defer C.free(unsafe.Pointer(cstr)) + + var cs C.libxl_scheduler + ret := C.libxl_scheduler_from_string(cstr, &cs) + if ret != 0 { + err = fmt.Errorf("libxl_scheduler_from_string: %d\n", ret) + return + } + + *s = Scheduler(cs) + return +} + +func translateCpupoolInfoCToGo(cci C.libxl_cpupoolinfo) (gci CpupoolInfo) { + gci.Poolid = uint32(cci.poolid) + gci.PoolName = C.GoString(cci.pool_name) + gci.Scheduler = Scheduler(cci.sched) + gci.DomainCount = int(cci.n_dom) + gci.Cpumap = bitmapCToGo(cci.cpumap) + + return +} + func SchedulerFromString(name string) (s Scheduler, err error) { cname := C.CString(name) defer C.free(unsafe.Pointer(cname))
@@ -385,20 +410,37 @@ func (Ctx *Context) ListCpupool() (list []CpupoolInfo) { cpupoolListSlice := (*[1 << 30]C.libxl_cpupoolinfo)(unsafe.Pointer(c_cpupool_list))[:nbPool:nbPool] for i := range cpupoolListSlice { - var info CpupoolInfo + info := translateCpupoolInfoCToGo(cpupoolListSlice[i]) - info.Poolid = uint32(cpupoolListSlice[i].poolid) - info.PoolName = C.GoString(cpupoolListSlice[i].pool_name) - info.Scheduler = Scheduler(cpupoolListSlice[i].sched) - info.DomainCount = int(cpupoolListSlice[i].n_dom) - info.Cpumap = bitmapCToGo(&cpupoolListSlice[i].cpumap) - list = append(list, info) } return } +// int libxl_cpupool_info(libxl_ctx *ctx, libxl_cpupoolinfo *info, uint32_t poolid); +func (Ctx *Context) CpupoolInfo(Poolid uint32) (pool CpupoolInfo) { + err := Ctx.CheckOpen() + if err != nil { + return + } + + var c_cpupool C.libxl_cpupoolinfo + + ret := C.libxl_cpupool_info(Ctx.ctx, &c_cpupool, C.uint32_t(Poolid)) + if ret != 0 { + err = fmt.Errorf("libxl_cpupool_info failed: %d", ret) + return + } + defer C.libxl_cpupoolinfo_dispose(&c_cpupool) + + pool = translateCpupoolInfoCToGo(c_cpupool) + + return +} + + + // int libxl_cpupool_create(libxl_ctx *ctx, const char *name, // libxl_scheduler sched, // libxl_bitmap cpumap, libxl_uuid *uuid,
@@ -532,7 +574,6 @@ func (Ctx *Context) CpupoolCpuremoveCpumap(Poolid uint32, Cpumap Bitmap) (err er // int libxl_cpupool_cpuadd_node(libxl_ctx *ctx, uint32_t poolid, int node, int *cpus); // int libxl_cpupool_cpuremove_node(libxl_ctx *ctx, uint32_t poolid, int node, int *cpus); // int libxl_cpupool_movedomain(libxl_ctx *ctx, uint32_t poolid, uint32_t domid); -// int libxl_cpupool_info(libxl_ctx *ctx, libxl_cpupoolinfo *info, uint32_t poolid); // // Utility functions
@@ -615,5 +656,8 @@ func XlTest(Args []string) { fmt.Printf("Pool id: %d\n", Poolid) } + pool = Ctx.CpupoolInfo(0) + fmt.Printf("Cpupool 0 info: %v\n", pool) + Ctx.Close() }
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 50/59 libxl: Fix Bitmap.Max(), make Test() / Clear() more robust
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
Bitmap.Max() should return the largest currently addressable bit; at the moment it returns the total number of bits (which is one greater than the largest addressable bit).
This also implicitly fixes a bug in Test() and Clear() which would cause an out-of-range error when testing a bit equal to Max().
While we're here, allow Test() and Clear() to handle null bitmaps, the same way Set() can.
--- libxl.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
libxl.go +3 -3
@@ -270,7 +270,7 @@ func bitmapGotoC(gbm Bitmap) (cbm C.libxl_bitmap) { func (bm *Bitmap) Test(bit int) (bool) { ubit := uint(bit) - if (bit > bm.Max()) { + if (bit > bm.Max() || bm.bitmap == nil) { return false }
@@ -294,7 +294,7 @@ func (bm *Bitmap) SetRange(start int, end int) { func (bm *Bitmap) Clear(bit int) { ubit := uint(bit) - if (bit > bm.Max()) { + if (bit > bm.Max() || bm.bitmap == nil) { return }
@@ -308,7 +308,7 @@ func (bm *Bitmap) ClearRange(start int, end int) { } func (bm *Bitmap) Max() (int) { - return len(bm.bitmap) * 8 + return len(bm.bitmap) * 8 - 1 } func (bm *Bitmap) IsEmpty() (bool) {
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 51/59 controller: Make and/or modify cpupools when possible
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
Make it possible for schedbench to modify cpupools in order to satisfy run constraints.
Make a "RunConfig" option which contains the name of the pool, the scheduler, and the number of cpus. As with WorkerConfig, make these automatically inherited from larger levels to smaller levels. This makes it straightforward to allow arbitrary pool configurations in the same plan.
Modify sample.bench to have a RunConfig entry at the top level (instead of the WorkerConfig option). SimplePlan already sets RunConfig.Scheduler, so the effect will be for each run to have all three options set. (Punt on SimplePlan generating more complex options for now.)
Change BenchmarkRun.Ready() to BenchmarkRun.Prep(), which will cause the configuration in RunConfig to become true if possible. Empty 'Pool' element means the default pool (Pool-0). Always create the cpupool if it's non-pool-0, destroying the current one if it exists.
If it is pool 0, just check if it matches, and skip if not.
(We could in theory modify cpupool 0, but push that for future work.)
--- benchmark.go | 17 +++++- run.go | 176 +++++++++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 169 insertions(+), 24 deletions(-)
benchmark.go +16 -1
@@ -67,7 +67,6 @@ func (l *WorkerConfig) PropagateFrom(g WorkerConfig) { } } - type WorkerSet struct { Params WorkerParams Config WorkerConfig
@@ -140,6 +139,21 @@ type BenchmarkRunData struct { type RunConfig struct { Scheduler string + Pool string + Cpus []int +} + +// Propagate unset values from a higher level +func (l *RunConfig) PropagateFrom(g RunConfig) { + if l.Pool == "" { + l.Pool = g.Pool + } + if l.Scheduler == "" { + l.Scheduler = g.Scheduler + } + if l.Cpus == nil { + l.Cpus = g.Cpus + } } type BenchmarkRun struct {
@@ -159,6 +173,7 @@ type BenchmarkPlan struct { // Global options for workers that will be over-ridden by Run // and WorkerSet config options WorkerConfig `json:",omitempty"` + RunConfig RunConfig `json:",omitempty"` Runs []BenchmarkRun `json:",omitempty"` }
run.go +153 -23
207 lines not on this page · raw message
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 52/59 libxl: Implement Bitmap.String()
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
Implement Bitmap.String, which will convert a bitmap into a string parse-able by libxl.
--- libxl.go | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-)
libxl.go +58 -1
@@ -337,6 +337,51 @@ func (a Bitmap) And(b Bitmap) (c Bitmap) { return } +func (bm Bitmap) String() (s string) { + lastOnline := false + crange := false + printed := false + var i int + /// --x-xxxxx-x -> 2,4-8,10 + /// --x-xxxxxxx -> 2,4-10 + for i = 0; i <= bm.Max(); i++ { + if bm.Test(i) { + if !lastOnline { + // Switching offline -> online, print this cpu + if printed { + s += "," + } + s += fmt.Sprintf("%d", i) + printed = true + } else if !crange { + // last was online, but we're not in a range; print - + crange = true + s += "-" + } else { + // last was online, we're in a range, nothing else to do + } + lastOnline = true + } else { + if lastOnline { + // Switching online->offline; do we need to end a range? + if crange { + s += fmt.Sprintf("%d", i-1) + } + } + lastOnline = false + crange = false + } + } + if lastOnline { + // Switching online->offline; do we need to end a range? + if crange { + s += fmt.Sprintf("%d", i-1) + } + } + + return +} + // const char *libxl_scheduler_to_string(libxl_scheduler p); func (s Scheduler) String() (string) { cs := C.libxl_scheduler_to_string(C.libxl_scheduler(s))
@@ -608,6 +653,18 @@ func (Ctx *Context) CpupoolMakeFree(Cpumap Bitmap) (err error) { } func XlTest(Args []string) { + var Cpumap Bitmap + + Cpumap.Set(2) + Cpumap.SetRange(4, 8) + Cpumap.Set(10) + + fmt.Printf("Cpumap: %v\n", Cpumap) + + Cpumap.Set(9) + + fmt.Printf("Cpumap: %v\n", Cpumap) + var Ctx Context err := Ctx.Open()
@@ -635,7 +692,7 @@ func XlTest(Args []string) { } } - var Cpumap Bitmap + Cpumap = Bitmap{} Cpumap.SetRange(12, 15)
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 53/59 controller: Add WorkerConfig.SoftAffinity
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
If the SoftAffinity is present, pass it as "cpus_soft = ..." in the config file.
--- benchmark.go | 1 + xenworker.go | 4 ++++ 2 files changed, 5 insertions(+)
benchmark.go +1 -0
@@ -58,6 +58,7 @@ func (l *WorkerParams) SetkHZ(kHZ uint64) { type WorkerConfig struct { Pool string + SoftAffinity string } // Propagate unset values from a higher level
xenworker.go +4 -0
@@ -91,6 +91,10 @@ func (w *XenWorker) Init(p WorkerParams, g WorkerConfig) (err error) { fmt.Fprintf(cfg, "pool = '%s'\n", g.Pool) } + if g.SoftAffinity != "" { + fmt.Fprintf(cfg, "cpus_soft = '%s'\n", g.SoftAffinity) + } + // xl create -p [filename] {
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 54/59 controller/run: Add RunConfig.NumaDisable
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
If RunConfig.NumaDisable is set, get each worker's WorkerConfig.SoftAffinity to the cpumap of the cpupool the VM is going to be running in.
--- benchmark.go | 4 ++++ run.go | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 3 deletions(-)
benchmark.go +4 -0
@@ -142,6 +142,7 @@ type RunConfig struct { Scheduler string Pool string Cpus []int + NumaDisable *bool `json:",omitempty"` } // Propagate unset values from a higher level
@@ -155,6 +156,9 @@ func (l *RunConfig) PropagateFrom(g RunConfig) { if l.Cpus == nil { l.Cpus = g.Cpus } + if l.NumaDisable == nil { + l.NumaDisable = g.NumaDisable + } } type BenchmarkRun struct {
run.go +32 -3
@@ -312,14 +312,43 @@ func (run *BenchmarkRun) Prep() (ready bool, why string) { return } +func (run *BenchmarkRun) GetCpumap() (Cpumap Bitmap) { + if run.RunConfig.Pool == "" { + fmt.Printf("Run.Prep: No pool set, using 0\n") + pool := Ctx.CpupoolInfo(0) + Cpumap = pool.Cpumap + } else { + pool, poolPresent := Ctx.CpupoolFindByName(run.RunConfig.Pool) + if poolPresent { + Cpumap = pool.Cpumap + } else { + panic("run.GetCpumap(): Pool "+run.RunConfig.Pool+" not found!") + } + } + return +} + func (run *BenchmarkRun) Run() (err error) { for wsi := range run.WorkerSets { - run.WorkerSets[wsi].Config.PropagateFrom(run.WorkerConfig) - if run.WorkerSets[wsi].Config.Pool == "" { - run.WorkerSets[wsi].Config.Pool = run.RunConfig.Pool + conf := &run.WorkerSets[wsi].Config + + conf.PropagateFrom(run.WorkerConfig) + if conf.Pool == "" { + conf.Pool = run.RunConfig.Pool } run.WorkerSets[wsi].Params.SetkHZ(CpukHZ) + if *run.RunConfig.NumaDisable { + if conf.SoftAffinity != "" { + err = fmt.Errorf("Cannot disable Numa if SoftAffinity is set!") + return + } + // Disable libxl NUMA by setting the soft + // affinity to the set of cpus in the cpupool + conf.SoftAffinity = run.GetCpumap().String() + fmt.Printf("Setting SoftAffinity to %s to disable NUMA placement\n", + conf.SoftAffinity) + } } Workers, err := NewWorkerList(run.WorkerSets, WorkerXen)
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 55/59 plan: Make the matrix generation more programmatic
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
Rather than have nested loops, keep a running list of all the configs we've created so far. Then for each existing new element of the matrix, combine it with all the existing columns.
--- plan.go | 50 +++++++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 19 deletions(-)
plan.go +31 -19
@@ -72,7 +72,9 @@ func (plan *BenchmarkPlan) ExpandInput() (err error) { schedulers = append(schedulers, "") } - // Always do the baselines + // Start by making a slice with baselines and each of the counts + var a, b []BenchmarkRun + for _, wn := range plan.Input.SimpleMatrix.Workers { wp := WorkerPresets[wn]
@@ -85,39 +87,49 @@ func (plan *BenchmarkPlan) ExpandInput() (err error) { WorkerSets:[]WorkerSet{{Params:wp, Count:1}}, RuntimeSeconds:10, } - - for _, s := range schedulers { - fmt.Printf("Making baseline %s run, sched %s\n", wn, s) - run.RunConfig.Scheduler = s - run.Label = wn+" baseline "+s - plan.Runs = append(plan.Runs, run) - } + + run.Label = wn+" baseline" + a = append(a, run) } - + + for _, c := range plan.Input.SimpleMatrix.Count { run := BenchmarkRun{ RuntimeSeconds:10, } - var label string for _, wn := range plan.Input.SimpleMatrix.Workers { wp := WorkerPresets[wn] - if label != "" { - label = label+" + " + if run.Label != "" { + run.Label = run.Label+" + " } - label = fmt.Sprintf("%s%s %d ", label, wn, c) - + run.Label = fmt.Sprintf("%s%s %d", run.Label, wn, c) + ws := WorkerSet{Params:wp, Count:c} run.WorkerSets = append(run.WorkerSets, ws) } - for _, s := range schedulers { - fmt.Printf("Making count %d run, sched %s\n", c, s) - run.RunConfig.Scheduler = s - run.Label = label+s - plan.Runs = append(plan.Runs, run) + + a = append(a, run) + } + + // ...then cross it by schedulers + if len(schedulers) > 0 { + for _, base := range a { + for _, s := range schedulers { + run := base + run.RunConfig.Scheduler = s + run.Label = run.Label+" "+s + b = append(b, run) + } } + a = b + b = nil } + for i := range a { + fmt.Printf("%s\n", a[i].Label) + } + plan.Runs = a; return }
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 56/59 controller/plan: Add NumaDisable to SimpleMatrix
In reply to Ronald RojasFrom: George Dunlap <[email protected]>
--- plan.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
plan.go +22 -0
@@ -26,6 +26,7 @@ type PlanSimpleMatrix struct { Schedulers []string Workers []string Count []int + NumaDisable []bool } type PlanInput struct {
@@ -127,6 +128,27 @@ func (plan *BenchmarkPlan) ExpandInput() (err error) { b = nil } + // ...and NumaDisable + if len(plan.Input.SimpleMatrix.NumaDisable) > 0 { + for _, base := range a { + for _, d := range plan.Input.SimpleMatrix.NumaDisable { + run := base + // Need to make a copy of this so that + // we have a pointer to use as a tristate + run.RunConfig.NumaDisable = new(bool) + *run.RunConfig.NumaDisable = d + if d { + run.Label = run.Label+" NumaOff" + } else { + run.Label = run.Label+" NumaOn " + } + b = append(b, run) + } + } + a = b + b = nil + } + for i := range a { fmt.Printf("%s\n", a[i].Label) }
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 57/59 tools/blktap2: remove unused inclusion of sys/sysctl.l
In reply to Ronald RojasFrom: Alistair Francis <[email protected]>
That header file is not used. Removing it would avoid build error with musl libc, which doesn't have that header file.
--- tools/blktap2/drivers/block-remus.c | 1 - 1 file changed, 1 deletion(-)
tools/blktap2/drivers/block-remus.c +0 -1
@@ -54,7 +54,6 @@#include <netinet/in.h> #include <arpa/inet.h> #include <sys/param.h> -#include <sys/sysctl.h> #include <unistd.h> #include <sys/stat.h>
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
RFC PATCH 58/59 remove irrelevant files from old repository
In reply to Ronald Rojas--- Makefile | 31 -- benchmark.go | 467 -------------------------- htmlreport.go | 238 -------------- libxl.go | 720 ----------------------------------------- main.go | 146 --------- plan.go | 157 --------- processworker.go | 98 ------ run.go | 456 -------------------------- stubs.go | 34 -- tools/golang/xenlight/libxl.go | 720 +++++++++++++++++++++++++++++++++++++++++ xenworker.go | 278 ---------------- 11 files changed, 720 insertions(+), 2625 deletions(-) delete mode 100644 Makefile delete mode 100644 benchmark.go delete mode 100644 htmlreport.go delete mode 100644 libxl.go delete mode 100644 main.go delete mode 100644 plan.go delete mode 100644 processworker.go delete mode 100644 run.go delete mode 100644 stubs.go create mode 100644 tools/golang/xenlight/libxl.go delete mode 100644 xenworker.go
Makefile deleted +0 -31
@@ -1,31 +0,0 @@ -BIN = schedbench -BINALL = $(BIN) - -.PHONY: all -all: $(BIN) - - - -CGO_CFLAGS = -I/build/hg/xen.git/dist/install/usr/local/include - -# FIXME -XENLIB_PATH ?= /build/hg/xen.git/dist/install/usr/local/lib/ -CGO_LDFLAGS = -L$(XENLIB_PATH) -Wl,-rpath-link=$(XENLIB_PATH) - -schedbench: main.go processworker.go xenworker.go benchmark.go run.go libxl.go htmlreport.go plan.go - CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CFLAGS="$(CGO_CFLAGS)" go build -ldflags '-linkmode external -extldflags "-static"' -o $@ $^ - -# If we use a statically linked binary we don't need this; the same -# binary can be used on any system. Keep this version (without any -# run support) support) around for now in case we want to go back to -# it. -schedbench-report: main.go benchmark.go stubs.go htmlreport.go plan.go - go build -o $@ $^ - -.PHONY: clean -clean: - rm -f $(BINALL) - -.PHONY: dist -dist: - cp $(BIN) $(DISTDIR)
benchmark.go deleted +0 -467
467 lines not on this page · raw message
htmlreport.go deleted +0 -238
238 lines not on this page · raw message
libxl.go deleted +0 -720
720 lines not on this page · raw message
main.go deleted +0 -146
146 lines not on this page · raw message
plan.go deleted +0 -157
157 lines not on this page · raw message
processworker.go deleted +0 -98
98 lines not on this page · raw message
run.go deleted +0 -456
456 lines not on this page · raw message
stubs.go deleted +0 -34
@@ -1,34 +0,0 @@ -/* - * Copyright (C) 2016 George W. Dunlap, Citrix Systems UK Ltd - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; version 2 of the - * License only. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ -package main - -import ( - "fmt" -) - -func (plan *BenchmarkPlan) Run() (err error) { - err = fmt.Errorf("Not implemented") - - return -} - -func XlTest(Args []string) { - return -} -
tools/golang/xenlight/libxl.go new file +720 -0
653 lines not on this page · raw message
xenworker.go deleted +0 -278
278 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Part of the diff is not shown here. View the raw message.
RFC PATCH 59/59 tools/xenlight: Create interface for xenlight info
In reply to Ronald RojasCreate interface to interact with libxl_verions_info and libxl_physinfo. Also introduce proper error handling.
--- tools/golang/xenlight/libxl.go | 720 -------------------------- tools/golang/xenlight/xenlight.go | 1000 +++++++++++++++++++++++++++++++++++++ 2 files changed, 1000 insertions(+), 720 deletions(-) delete mode 100644 tools/golang/xenlight/libxl.go create mode 100644 tools/golang/xenlight/xenlight.go
tools/golang/xenlight/libxl.go deleted +0 -720
@@ -1,720 +0,0 @@ -/* - * Copyright (C) 2016 George W. Dunlap, Citrix Systems UK Ltd - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; version 2 of the - * License only. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ -package main - -/* -#cgo LDFLAGS: -lxenlight -lyajl_s -lxengnttab -lxenstore -lxenguest -lxentoollog -lxenevtchn -lxenctrl -lblktapctl -lxenforeignmemory -lxencall -lz -luuid -lutil -#include <stdlib.h> -#include <libxl.h> -*/ -import "C" - -/* - * Other flags that may be needed at some point: - * -lnl-route-3 -lnl-3 - * - * To get back to simple dynamic linking: -#cgo LDFLAGS: -lxenlight -lyajl -*/ - -import ( - "unsafe" - "fmt" - "time" -) - -/* - * Types: Builtins - */ - -type Domid uint32 - -type MemKB uint64 - -// typedef struct { -// uint32_t size; /* number of bytes in map */ -// uint8_t *map; -// } libxl_bitmap; - -// Implement the Go bitmap type such that the underlying data can -// easily be copied in and out. NB that we still have to do copies -// both directions, because cgo runtime restrictions forbid passing to -// a C function a pointer to a Go-allocated structure which contains a -// pointer. -type Bitmap struct { - bitmap []C.uint8_t -} - -type Context struct { - ctx *C.libxl_ctx -} - -type Uuid C.libxl_uuid - -/* - * Types: IDL - * - * FIXME: Generate these automatically from the IDL - */ -type Dominfo struct { - Uuid Uuid - Domid Domid - Running bool - Blocked bool - Paused bool - Shutdown bool - Dying bool - Never_stop bool - - Shutdown_reason int32 // FIXME shutdown_reason enumeration - Outstanding_memkb MemKB - Current_memkb MemKB - Shared_memkb MemKB - Paged_memkb MemKB - Max_memkb MemKB - Cpu_time time.Duration - Vcpu_max_id uint32 - Vcpu_online uint32 - Cpupool uint32 - Domain_type int32 //FIXME libxl_domain_type enumeration - -} - -// # Consistent with values defined in domctl.h -// # Except unknown which we have made up -// libxl_scheduler = Enumeration("scheduler", [ -// (0, "unknown"), -// (4, "sedf"), -// (5, "credit"), -// (6, "credit2"), -// (7, "arinc653"), -// (8, "rtds"), -// ]) -type Scheduler int -var ( - SchedulerUnknown Scheduler = C.LIBXL_SCHEDULER_UNKNOWN - SchedulerSedf Scheduler = C.LIBXL_SCHEDULER_SEDF - SchedulerCredit Scheduler = C.LIBXL_SCHEDULER_CREDIT - SchedulerCredit2 Scheduler = C.LIBXL_SCHEDULER_CREDIT2 - SchedulerArinc653 Scheduler = C.LIBXL_SCHEDULER_ARINC653 - SchedulerRTDS Scheduler = C.LIBXL_SCHEDULER_RTDS -) - -// libxl_cpupoolinfo = Struct("cpupoolinfo", [ -// ("poolid", uint32), -// ("pool_name", string), -// ("sched", libxl_scheduler), -// ("n_dom", uint32), -// ("cpumap", libxl_bitmap) -// ], dir=DIR_OUT) - -type CpupoolInfo struct { - Poolid uint32 - PoolName string - Scheduler Scheduler - DomainCount int - Cpumap Bitmap -} - -/* - * Context - */ -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 { - err = fmt.Errorf("Allocating libxl context: %d", ret) - } - return -} - -func (Ctx *Context) Close() (err error) { - ret := C.libxl_ctx_free(unsafe.Pointer(Ctx.ctx)) - Ctx.ctx = nil - - if ret != 0 { - err = fmt.Errorf("Freeing libxl context: %d", ret) - } - return -} - -func (Ctx *Context) CheckOpen() (err error) { - if Ctx.ctx == nil { - err = fmt.Errorf("Context not opened") - } - return -} - -func (Ctx *Context) DomainInfo(Id Domid) (di *Dominfo, err error) { - err = Ctx.CheckOpen() - if err != nil { - return - } - - var cdi C.libxl_dominfo - - ret := C.libxl_domain_info(Ctx.ctx, unsafe.Pointer(&cdi), C.uint32_t(Id)) - - // FIXME: IsDomainNotPresentError - if ret != 0 { - err = fmt.Errorf("libxl_domain_info failed: %d", ret) - return - } - - // We could consider having this boilerplate generated by the - // idl, in a function like this: - // - // di = translateCdomaininfoToGoDomaininfo(cdi) - di = &Dominfo{} - di.Uuid = Uuid(cdi.uuid) - di.Domid = Domid(cdi.domid) - di.Running = bool(cdi.running) - di.Blocked = bool(cdi.blocked) - di.Paused = bool(cdi.paused) - di.Shutdown = bool(cdi.shutdown) - di.Dying = bool(cdi.dying) - di.Never_stop = bool(cdi.never_stop) - di.Shutdown_reason = int32(cdi.shutdown_reason) - di.Outstanding_memkb = MemKB(cdi.outstanding_memkb) - di.Current_memkb = MemKB(cdi.current_memkb) - di.Shared_memkb = MemKB(cdi.shared_memkb) - di.Paged_memkb = MemKB(cdi.paged_memkb) - di.Max_memkb = MemKB(cdi.max_memkb) - di.Cpu_time = time.Duration(cdi.cpu_time) - di.Vcpu_max_id = uint32(cdi.vcpu_max_id) - di.Vcpu_online = uint32(cdi.vcpu_online) - di.Cpupool = uint32(cdi.cpupool) - di.Domain_type = int32(cdi.domain_type) - - return -} - -func (Ctx *Context) DomainUnpause(Id Domid) (err error) { - err = Ctx.CheckOpen() - if err != nil { - return - } - - ret := C.libxl_domain_unpause(Ctx.ctx, C.uint32_t(Id)) - - if ret != 0 { - err = fmt.Errorf("libxl_domain_unpause failed: %d", ret) - } - return -} - -/* - * Bitmap operations - */ - -// Return a Go bitmap which is a copy of the referred C bitmap. -func bitmapCToGo(cbm C.libxl_bitmap) (gbm Bitmap) { - // Alloc a Go slice for the bytes - size := int(cbm.size) - gbm.bitmap = make([]C.uint8_t, size) - - // Make a slice pointing to the C array - mapslice := (*[1 << 30]C.uint8_t)(unsafe.Pointer(cbm._map))[:size:size] - - // And copy the C array into the Go array - copy(gbm.bitmap, mapslice) - - return -} - -// Must be C.libxl_bitmap_dispose'd of afterwards -func bitmapGotoC(gbm Bitmap) (cbm C.libxl_bitmap) { - C.libxl_bitmap_init(&cbm) - - size := len(gbm.bitmap) - cbm._map = (*C.uint8_t)(C.malloc(C.size_t(size))) - cbm.size = C.uint32_t(size) - if cbm._map == nil { - panic("C.calloc failed!") - } - - // Make a slice pointing to the C array - mapslice := (*[1 << 30]C.uint8_t)(unsafe.Pointer(cbm._map))[:size:size] - - // And copy the Go array into the C array - copy(mapslice, gbm.bitmap) - - return -} - -func (bm *Bitmap) Test(bit int) (bool) { - ubit := uint(bit) - if (bit > bm.Max() || bm.bitmap == nil) { - return false - } - - return (bm.bitmap[bit / 8] & (1 << (ubit & 7))) != 0 -} - -func (bm *Bitmap) Set(bit int) { - ibit := bit / 8; - if (ibit + 1 > len(bm.bitmap)) { - bm.bitmap = append(bm.bitmap, make([]C.uint8_t, ibit+1-len(bm.bitmap))...) - } - - bm.bitmap[ibit] |= 1 << (uint(bit) & 7) -} - -func (bm *Bitmap) SetRange(start int, end int) { - for i := start; i <= end; i++ { - bm.Set(i) - } -} - -func (bm *Bitmap) Clear(bit int) { - ubit := uint(bit) - if (bit > bm.Max() || bm.bitmap == nil) { - return - } - - bm.bitmap[bit / 8] &= ^(1 << (ubit & 7)) -} - -func (bm *Bitmap) ClearRange(start int, end int) { - for i := start; i <= end; i++ { - bm.Clear(i) - } -} - -func (bm *Bitmap) Max() (int) { - return len(bm.bitmap) * 8 - 1 -} - -func (bm *Bitmap) IsEmpty() (bool) { - for i:=0; i<len(bm.bitmap); i++ { - if bm.bitmap[i] != 0 { - return false - } - } - return true -} - -func (a Bitmap) And(b Bitmap) (c Bitmap) { - var max, min int - if len(a.bitmap) > len(b.bitmap) { - max = len(a.bitmap) - min = len(b.bitmap) - } else { - max = len(b.bitmap) - min = len(a.bitmap) - } - c.bitmap = make([]C.uint8_t, max) - - for i := 0; i < min; i++ { - c.bitmap[i] = a.bitmap[i] & b.bitmap[i] - } - return -} - -func (bm Bitmap) String() (s string) { - lastOnline := false - crange := false - printed := false - var i int - /// --x-xxxxx-x -> 2,4-8,10 - /// --x-xxxxxxx -> 2,4-10 - for i = 0; i <= bm.Max(); i++ { - if bm.Test(i) { - if !lastOnline { - // Switching offline -> online, print this cpu - if printed { - s += "," - } - s += fmt.Sprintf("%d", i) - printed = true - } else if !crange { - // last was online, but we're not in a range; print - - crange = true - s += "-" - } else { - // last was online, we're in a range, nothing else to do - } - lastOnline = true - } else { - if lastOnline { - // Switching online->offline; do we need to end a range? - if crange { - s += fmt.Sprintf("%d", i-1) - } - } - lastOnline = false - crange = false - } - } - if lastOnline { - // Switching online->offline; do we need to end a range? - if crange { - s += fmt.Sprintf("%d", i-1) - } - } - - return -} - -// const char *libxl_scheduler_to_string(libxl_scheduler p); -func (s Scheduler) String() (string) { - cs := C.libxl_scheduler_to_string(C.libxl_scheduler(s)) - // No need to free const return value - - return C.GoString(cs) -} - -// int libxl_scheduler_from_string(const char *s, libxl_scheduler *e); -func (s *Scheduler) FromString(gstr string) (err error) { - cstr := C.CString(gstr) - defer C.free(unsafe.Pointer(cstr)) - - var cs C.libxl_scheduler - ret := C.libxl_scheduler_from_string(cstr, &cs) - if ret != 0 { - err = fmt.Errorf("libxl_scheduler_from_string: %d\n", ret) - return - } - - *s = Scheduler(cs) - return -} - -func translateCpupoolInfoCToGo(cci C.libxl_cpupoolinfo) (gci CpupoolInfo) { - gci.Poolid = uint32(cci.poolid) - gci.PoolName = C.GoString(cci.pool_name) - gci.Scheduler = Scheduler(cci.sched) - gci.DomainCount = int(cci.n_dom) - gci.Cpumap = bitmapCToGo(cci.cpumap) - - return -} - -func SchedulerFromString(name string) (s Scheduler, err error) { - cname := C.CString(name) - defer C.free(unsafe.Pointer(cname)) - - var cs C.libxl_scheduler - - ret := C.libxl_scheduler_from_string(cname, &cs) - if ret != 0 { - err = fmt.Errorf("libxl_scheduler_from_string failed: %d", ret) - return - } - - s = Scheduler(cs) - - return -} - -// libxl_cpupoolinfo * libxl_list_cpupool(libxl_ctx*, int *nb_pool_out); -// void libxl_cpupoolinfo_list_free(libxl_cpupoolinfo *list, int nb_pool); -func (Ctx *Context) ListCpupool() (list []CpupoolInfo) { - err := Ctx.CheckOpen() - if err != nil { - return - } - - var nbPool C.int - - c_cpupool_list := C.libxl_list_cpupool(Ctx.ctx, &nbPool) - - defer C.libxl_cpupoolinfo_list_free(c_cpupool_list, nbPool) - - if int(nbPool) == 0 { - return - } - - // Magic - cpupoolListSlice := (*[1 << 30]C.libxl_cpupoolinfo)(unsafe.Pointer(c_cpupool_list))[:nbPool:nbPool] - - for i := range cpupoolListSlice { - info := translateCpupoolInfoCToGo(cpupoolListSlice[i]) - - list = append(list, info) - } - - return -} - -// int libxl_cpupool_info(libxl_ctx *ctx, libxl_cpupoolinfo *info, uint32_t poolid); -func (Ctx *Context) CpupoolInfo(Poolid uint32) (pool CpupoolInfo) { - err := Ctx.CheckOpen() - if err != nil { - return - } - - var c_cpupool C.libxl_cpupoolinfo - - ret := C.libxl_cpupool_info(Ctx.ctx, &c_cpupool, C.uint32_t(Poolid)) - if ret != 0 { - err = fmt.Errorf("libxl_cpupool_info failed: %d", ret) - return - } - defer C.libxl_cpupoolinfo_dispose(&c_cpupool) - - pool = translateCpupoolInfoCToGo(c_cpupool) - - return -} - - - -// int libxl_cpupool_create(libxl_ctx *ctx, const char *name, -// libxl_scheduler sched, -// libxl_bitmap cpumap, libxl_uuid *uuid, -// uint32_t *poolid); -// FIXME: uuid -// FIXME: Setting poolid -func (Ctx *Context) CpupoolCreate(Name string, Scheduler Scheduler, Cpumap Bitmap) (err error, Poolid uint32) { - err = Ctx.CheckOpen() - if err != nil { - return - } - - poolid := C.uint32_t(0) - name := C.CString(Name) - defer C.free(unsafe.Pointer(name)) - - // For now, just do what xl does, and make a new uuid every time we create the pool - var uuid C.libxl_uuid - C.libxl_uuid_generate(&uuid) - - cbm := bitmapGotoC(Cpumap) - defer C.libxl_bitmap_dispose(&cbm) - - ret := C.libxl_cpupool_create(Ctx.ctx, name, C.libxl_scheduler(Scheduler), - cbm, &uuid, &poolid) - // FIXME: Proper error - if ret != 0 { - err = fmt.Errorf("libxl_cpupool_create failed: %d", ret) - return - } - - Poolid = uint32(poolid) - - return -} - -// int libxl_cpupool_destroy(libxl_ctx *ctx, uint32_t poolid); -func (Ctx *Context) CpupoolDestroy(Poolid uint32) (err error) { - err = Ctx.CheckOpen() - if err != nil { - return - } - - ret := C.libxl_cpupool_destroy(Ctx.ctx, C.uint32_t(Poolid)) - // FIXME: Proper error - if ret != 0 { - err = fmt.Errorf("libxl_cpupool_destroy failed: %d", ret) - return - } - - return -} - -// int libxl_cpupool_cpuadd(libxl_ctx *ctx, uint32_t poolid, int cpu); -func (Ctx *Context) CpupoolCpuadd(Poolid uint32, Cpu int) (err error) { - err = Ctx.CheckOpen() - if err != nil { - return - } - - ret := C.libxl_cpupool_cpuadd(Ctx.ctx, C.uint32_t(Poolid), C.int(Cpu)) - // FIXME: Proper error - if ret != 0 { - err = fmt.Errorf("libxl_cpupool_cpuadd failed: %d", ret) - return - } - - return -} - -// int libxl_cpupool_cpuadd_cpumap(libxl_ctx *ctx, uint32_t poolid, -// const libxl_bitmap *cpumap); -func (Ctx *Context) CpupoolCpuaddCpumap(Poolid uint32, Cpumap Bitmap) (err error) { - err = Ctx.CheckOpen() - if err != nil { - return - } - - cbm := bitmapGotoC(Cpumap) - defer C.libxl_bitmap_dispose(&cbm) - - ret := C.libxl_cpupool_cpuadd_cpumap(Ctx.ctx, C.uint32_t(Poolid), &cbm) - // FIXME: Proper error - if ret != 0 { - err = fmt.Errorf("libxl_cpupool_cpuadd_cpumap failed: %d", ret) - return - } - - return -} - -// int libxl_cpupool_cpuremove(libxl_ctx *ctx, uint32_t poolid, int cpu); -func (Ctx *Context) CpupoolCpuremove(Poolid uint32, Cpu int) (err error) { - err = Ctx.CheckOpen() - if err != nil { - return - } - - ret := C.libxl_cpupool_cpuremove(Ctx.ctx, C.uint32_t(Poolid), C.int(Cpu)) - // FIXME: Proper error - if ret != 0 { - err = fmt.Errorf("libxl_cpupool_cpuremove failed: %d", ret) - return - } - - return -} - -// int libxl_cpupool_cpuremove_cpumap(libxl_ctx *ctx, uint32_t poolid, -// const libxl_bitmap *cpumap); -func (Ctx *Context) CpupoolCpuremoveCpumap(Poolid uint32, Cpumap Bitmap) (err error) { - err = Ctx.CheckOpen() - if err != nil { - return - } - - cbm := bitmapGotoC(Cpumap) - defer C.libxl_bitmap_dispose(&cbm) - - ret := C.libxl_cpupool_cpuremove_cpumap(Ctx.ctx, C.uint32_t(Poolid), &cbm) - // FIXME: Proper error - if ret != 0 { - err = fmt.Errorf("libxl_cpupool_cpuremove_cpumap failed: %d", ret) - return - } - - return -} - -// int libxl_cpupool_rename(libxl_ctx *ctx, const char *name, uint32_t poolid); -// int libxl_cpupool_cpuadd_node(libxl_ctx *ctx, uint32_t poolid, int node, int *cpus); -// int libxl_cpupool_cpuremove_node(libxl_ctx *ctx, uint32_t poolid, int node, int *cpus); -// int libxl_cpupool_movedomain(libxl_ctx *ctx, uint32_t poolid, uint32_t domid); - -// -// Utility functions -// -func (Ctx *Context) CpupoolFindByName(name string) (info CpupoolInfo, found bool) { - plist := Ctx.ListCpupool() - - for i := range plist { - if plist[i].PoolName == name { - found = true - info = plist[i] - return - } - } - return -} - -func (Ctx *Context) CpupoolMakeFree(Cpumap Bitmap) (err error) { - plist := Ctx.ListCpupool() - - for i := range plist { - var Intersection Bitmap - Intersection = Cpumap.And(plist[i].Cpumap) - if ! Intersection.IsEmpty() { - err = Ctx.CpupoolCpuremoveCpumap(plist[i].Poolid, Intersection) - if err != nil { - return - } - } - } - return -} - -func XlTest(Args []string) { - var Cpumap Bitmap - - Cpumap.Set(2) - Cpumap.SetRange(4, 8) - Cpumap.Set(10) - - fmt.Printf("Cpumap: %v\n", Cpumap) - - Cpumap.Set(9) - - fmt.Printf("Cpumap: %v\n", Cpumap) - - var Ctx Context - - err := Ctx.Open() - if err != nil { - fmt.Printf("Opening context: %v\n", err) - return - } - - pool, found := Ctx.CpupoolFindByName("schedbench") - - if found { - fmt.Printf("Found schedbench, destroying\n") - - err = Ctx.CpupoolDestroy(pool.Poolid) - if err != nil { - fmt.Printf("Couldn't destroy pool: %v\n", err) - return - } - - fmt.Printf("Returning cpus to pool 0 for fun\n") - err = Ctx.CpupoolCpuaddCpumap(0, pool.Cpumap) - if err != nil { - fmt.Printf("Couldn't add cpus to domain 0: %v\n", err) - return - } - } - - Cpumap = Bitmap{} - - Cpumap.SetRange(12, 15) - - fmt.Printf("Freeing cpus\n") - err = Ctx.CpupoolMakeFree(Cpumap) - if err != nil { - fmt.Printf("Couldn't free cpus: %v\n", err) - return - } - - - fmt.Printf("Creating new pool\n") - - err, Poolid := Ctx.CpupoolCreate("schedbench", SchedulerCredit, Cpumap) - if err != nil { - fmt.Printf("Error creating cpupool: %v\n", err) - } else { - fmt.Printf("Pool id: %d\n", Poolid) - } - - pool = Ctx.CpupoolInfo(0) - fmt.Printf("Cpupool 0 info: %v\n", pool) - - Ctx.Close() -}
tools/golang/xenlight/xenlight.go new file +1000 -0
1,000 lines not on this page · raw message
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH RFC 59/59] tools/xenlight: Create interface for xenlight info
Quoted 5 lines · Ronald Rojas
Create interface to interact with
libxl_verions_infoandlibxl_physinfo. Also introduce proper error handling.Signed-off-by Ronald Rojas <[email protected]>
Hey Ronald,
When you send a series to a public open-source project, you want it to be a sort of idealized set of changes that make it easy to "see the forest for the trees", as it were, not the actual local development path. We don't need the full development history of libxl.go -- a simple dump will be fine; and we definitely don't need all the other stuff from schedbench in the xen.git history. :-)
All you needed to do to "import" my existing libxl code from schedbench was:
$ cd xen.git $ cp ../schedbench.git/controller/libxl.go tools/golang/xenlight/xenlight.go $ git add tools/golang/xenlight/xenlight.go
:-)
Also, in this patch it looks from the description like you are incrementally adding a bit of new functionality: but since you also at the same time rename the file from "libxl.go" to "xenlight.go", it's difficult to tell what's going on. In the future, mechanical changes (like renaming a file or code motion) should be kept separate from patches that add or modify functionality, so that it's easy to see what's going on.
Let me take a look at what you've got.
-George
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH RFC 59/59] tools/xenlight: Create interface for xenlight info
Quoted 16 lines · George Dunlap
Quoted 5 lines · Ronald Rojas
Create interface to interact with
libxl_verions_infoandlibxl_physinfo. Also introduce proper error handling.Signed-off-by Ronald Rojas <[email protected]>Hey Ronald,
When you send a series to a public open-source project, you want it to be a sort of idealized set of changes that make it easy to "see the forest for the trees", as it were, not the actual local development path. We don't need the full development history of libxl.go -- a simple dump will be fine; and we definitely don't need all the other stuff from schedbench in the xen.git history. :-)
Quoted 6 lines
All you needed to do to "import" my existing libxl code from schedbench was:
$ cd xen.git $ cp ../schedbench.git/controller/libxl.go tools/golang/xenlight/xenlight.go $ git add tools/golang/xenlight/xenlight.go
+1 for this.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH RFC 59/59] tools/xenlight: Create interface for xenlight info
Quoted 17 lines · Wei Liu
Quoted 16 lines · George Dunlap
Quoted 5 lines · Ronald Rojas
Create interface to interact with
libxl_verions_infoandlibxl_physinfo. Also introduce proper error handling.Signed-off-by Ronald Rojas <[email protected]>Hey Ronald,
When you send a series to a public open-source project, you want it to be a sort of idealized set of changes that make it easy to "see the forest for the trees", as it were, not the actual local development path. We don't need the full development history of libxl.go -- a simple dump will be fine; and we definitely don't need all the other stuff from schedbench in the xen.git history. :-)
Quoted 5 lines
Quoted 5 lines
All you needed to do to "import" my existing libxl code from schedbench was:
$ cd xen.git $ cp ../schedbench.git/controller/libxl.go tools/golang/xenlight/xenlight.go $ git add tools/golang/xenlight/xenlight.go
This is much easier then what I was doing. I did it another way because I thought you would have wanted to keep the git commit history. I can resubmit the patch into 2 commits so it'll be easier to read. 1 for importing the code from schedbench and then the changes that I made afterward. How does that sound?
Quoted 3 lines
Quoted 1 line
+1 for this.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH RFC 59/59] tools/xenlight: Create interface for xenlight info
In reply to Ronald RojasHey Ronald! Looks like you're getting going pretty well here.
At a high level: I think I began by saying that this would probably all be a single patch. But I think it would probably be easier to review the different decisions made at each point by filling out the file bit by bit, and explaining what's going on at each point.
I think also it would be helpful to have somewhere -- either in a comment or in a text file -- a description of the general approach to converting the libxl C style into xenlight golang style. For instance, saying that for functions, we'll take the function name (libxl_cpupool_remove), remove the libxl_ prefix (since the packages are namespaced already) and convert it to CamelCase by capitalizing the first
I'll take a stab at breaking it down in an example order that makes some sense to me, and then you can see what you think.
Futher comments...
Quoted 22 lines · Ronald Rojas
tools/golang/xenlight/xenlight.go new file +16
-0@@ -0,0 +1,1000 @@ +/* + * Copyright (C) 2016 George W. Dunlap, Citrix Systems UK Ltd + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; version 2 of the + * License only. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
tools/golang/xenlight/xenlight.go line 26
Quoted 10 lines
tools/golang/xenlight/xenlight.go new file +10
-0+ * 02110-1301, USA. + */ +package xenlight + +/* +#cgo LDFLAGS: -lxenlight -lyajl +#include <stdlib.h> +#include <libxl.h> +*/ +import "C"
I see you switched back to dynamic linking -- any particular reason?
We probably need to put a "// FIXME" here saying that we need to generate these compile-time dependencies using pkg-config.
tools/golang/xenlight/xenlight.go line 34
Quoted 8 lines
tools/golang/xenlight/xenlight.go new file +8
-0+ +/* + * Other flags that may be needed at some point: + * -lnl-route-3 -lnl-3 +#cgo LDFLAGS: -lxenlight -lyajl_s -lxengnttab -lxenstore -lxenguest -lxentoollog -lxenevtchn -lxenctrl -lblktapctl -lxenforeignmemory -lxencall -lz -luuid -lutil + * + * To get back to simple dynamic linking: +*/
Comment needs updating (to "To use static linking").
Quoted 27 lines
tools/golang/xenlight/xenlight.go new file +27
-0+ +import ( + "fmt" + "time" + "unsafe" +) + +/* + * Errors + */ +const ( + ErrorNonspecific = int(C.ERROR_NONSPECIFIC) + ErrorVersion = int(C.ERROR_VERSION) + ErrorFail = int(C.ERROR_FAIL) + ErrorNi = int(C.ERROR_NI) + ErrorNomem = int(C.ERROR_NOMEM) + ErrorInval = int(C.ERROR_INVAL) + ErrorBadfail = int(C.ERROR_BADFAIL) + ErrorGuestTimedout = int(C.ERROR_GUEST_TIMEDOUT) + ErrorTimedout = int(C.ERROR_TIMEDOUT) + ErrorNoparavirt = int(C.ERROR_NOPARAVIRT) + ErrorNotReady = int(C.ERROR_NOT_READY) + ErrorOseventRegFail = int(C.ERROR_OSEVENT_REG_FAIL) + ErrorBufferfull = int(C.ERROR_BUFFERFULL) + ErrorUnknownChild = int(C.ERROR_UNKNOWN_CHILD) + ErrorLockFail = int(C.ERROR_LOCK_FAIL) + ErrorJsonConfigEmpty = int(C.ERROR_JSON_CONFIG_EMPTY)
tools/golang/xenlight/xenlight.go line 71
Quoted 10 lines
tools/golang/xenlight/xenlight.go new file +10
-0+ ErrorDeviceExists = int(C.ERROR_DEVICE_EXISTS) + ErrorCheckpointDevopsDoesNotMatch = int(C.ERROR_CHECKPOINT_DEVOPS_DOES_NOT_MATCH) + ErrorCheckpointDeviceNotSupported = int(C.ERROR_CHECKPOINT_DEVICE_NOT_SUPPORTED) + ErrorVnumaConfigInvalid = int(C.ERROR_VNUMA_CONFIG_INVALID) + ErrorDomainNotfound = int(C.ERROR_DOMAIN_NOTFOUND) + ErrorAborted = int(C.ERROR_ABORTED) + ErrorNotfound = int(C.ERROR_NOTFOUND) + ErrorDomainDestroyed = int(C.ERROR_DOMAIN_DESTROYED) + ErrorFeatureRemoved = int(C.ERROR_FEATURE_REMOVED) +)
The problem with this at the moment is that we don't actually return any of these errors -- instead we return a newly-generated error which contains text.
This pair of blog posts describes some approaches taken by different kinds of libraries to returning errors, and why:
https://www.goinggo.net/2014/10/error-handling-in-go-part-i.html
https://www.goinggo.net/2014/11/error-handling-in-go-part-ii.html
Another approach is taken by the go syscall package:
https://golang.org/pkg/syscall/#Errno
(See also https://golang.org/src/syscall/syscall_unix.go, lines 93-100, and https://golang.org/src/syscall/zerrors_linux_amd64.go, at lines 1204 and 1381.)
The approach taken by libraries in the second blog allows you to pass back a lot more information about what happened; but I think at the moment, given the limited number of things that libxl returns, that's probably overkill.
Which leaves us either taking the approach of something like bufio, and making things like this:
const (
ErrorNonspecific = errors.New("xenlight: Non-specific error")
...
)
Or taking the approach of the syscall package, and defining a type:
type xlerror int
func (e xlerror) Error() {
}
And making a (private) errors[] array, and re-impleminting Error() from the syscall package.
I think I would probably go with the syscall library's approach, since (like it) we are handed a set of pre-existing error numbers.
What do you think?
OK, there's more to look at but I think that's enough for now.
-George
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH RFC 59/59] tools/xenlight: Create interface for xenlight info
Quoted 4 lines · George Dunlap
At a high level: I think I began by saying that this would probably all be a single patch. But I think it would probably be easier to review the different decisions made at each point by filling out the file bit by bit, and explaining what's going on at each point.
[snip]
Quoted 2 lines
I'll take a stab at breaking it down in an example order that makes some sense to me, and then you can see what you think.
Here's one way you might break down this series that would make it easier to review.
I've re-ordered the file somewhat, and there's a slight bug in the build process so I can't compile it; and many of the descriptions need to be expanded. But it should give you the idea of what I'm talking about.
-George
From c96a7c71c69c440fd87e77b5e11f7ecdf3263e83 Mon Sep 17 00:00:00 2001
From: George Dunlap <[email protected]>
Date: Thu, 29 Dec 2016 19:22:41 +0000
Subject: [PATCH 1/7] tools/xenlight: Create stub package
Create a basic Makefile to build and install libxenlight Golang bindings. Also add a stub package which only opens libxl context.
Include a global xenlight.Ctx variable which can be used as the default context by the entire program if desired.
For now, return simple errors. Proper error handling will be added in the next patch.
--- tools/Makefile | 16 ++++++++ tools/golang/Makefile | 29 ++++++++++++++ tools/golang/xenlight/xenlight.go | 80 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 125 insertions(+) create mode 100644 tools/golang/Makefile create mode 100644 tools/golang/xenlight/xenlight.go
tools/Makefile +16 -0
@@ -12,6 +12,8 @@ SUBDIRS-y += misc SUBDIRS-y += examples SUBDIRS-y += hotplug SUBDIRS-y += xentrace +SUBDIRS-y += golang +#FIXME: Have golang controlled by a configure variable SUBDIRS-$(CONFIG_XCUTILS) += xcutils SUBDIRS-$(CONFIG_X86) += firmware SUBDIRS-y += console
@@ -312,6 +314,20 @@ subdir-install-debugger/gdbsx: .phony subdir-all-debugger/gdbsx: .phony $(MAKE) -C debugger/gdbsx all +subdir-all-golang/xenlight: .phony + $(MAKE) -C golang all + +subdir-clean-golang/xenlight: .phony + $(MAKE) -C golang clean + +subdir-install-golang/xenlight: .phony + $(MAKE) -C golang install + +subdir-build-golang/xenlight: .phony + $(MAKE) -C golang build + +subdir-distclean-golang/xenlight: .phony + $(MAKE) -C golang distclean subdir-clean-debugger/kdd subdir-distclean-debugger/kdd: .phony $(MAKE) -C debugger/kdd clean
tools/golang/Makefile new file +29 -0
@@ -0,0 +1,29 @@ +XEN_ROOT=$(CURDIR)/../.. +GOLANG_SRC=$(GOPATH)/src/xenproject.org/xenlight +include $(XEN_ROOT)/tools/Rules.mk + +BINARY = xenlight.a +GO ?= go + +.PHONY: all +all: build + +.PHONY: build +build: xenlight/xenlight.a + +.PHONY: install +install: build + $(INSTALL_DIR) $(DESTDIR)$(GOLANG_SRC) + $(INSTALL_DATA) xenlight/xenlight.go $(DESTDIR)$(GOLANG_SRC) + +.PHONY: clean +clean: + $(RM) xenlight/$(BINARY) + +.PHONY: distclean +distclean: clean + +xenlight/xenlight.a: xenlight/xenlight.go + $(GO) build -o $@ $< + +-include $(DEPS)
tools/golang/xenlight/xenlight.go new file +80 -0
80 lines not on this page · raw message
Signature · 1 line
2.1.4
From b57339b6f42dd1997d8aef3580dfb7411a56a99f Mon Sep 17 00:00:00 2001
From: George Dunlap <[email protected]>
Date: Thu, 29 Dec 2016 19:36:15 +0000
Subject: [PATCH 2/7] tools/golang: Add error constants and standard handling
You're going to change this so I won't bother writing a description -- write here though a description of what the patch does and a brief account of why.
--- tools/golang/xenlight/xenlight.go | 90 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+)
tools/golang/xenlight/xenlight.go +90 -0
96 lines not on this page · raw message
Signature · 1 line
2.1.4
From 1012318772396a2e4219c9ffa4c57ccd443f42a1 Mon Sep 17 00:00:00 2001
From: George Dunlap <[email protected]>
Date: Thu, 29 Dec 2016 19:49:02 +0000
Subject: [PATCH 3/7] tools/golang/xenlight: Add host-related functionality
Add calls for the following host-related functionality:
- libxl_get_max_cpus
- libxl_get_online_cpus
- libxl_get_max_nodes
- libxl_get_free_memory
- libxl_get_physinfo
- libxl_get_version_info
And include golang versions of the following structs:
- libxl_physinfo
- libxl_version_info
- libxl_hwcap
--- tools/golang/xenlight/xenlight.go | 193 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 193 insertions(+)
tools/golang/xenlight/xenlight.go +193 -0
202 lines not on this page · raw message
Signature · 1 line
2.1.4
From dcadedf83b219755994af123e2ee0ec49db85445 Mon Sep 17 00:00:00 2001
From: George Dunlap <[email protected]>
Date: Thu, 29 Dec 2016 19:54:10 +0000
Subject: [PATCH 4/7] golang/xenlight: Implement libxl_get_gomainfinfo and
libxl_domain_unpause
--- tools/golang/xenlight/xenlight.go | 91 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+)
tools/golang/xenlight/xenlight.go +91 -0
106 lines not on this page · raw message
Signature · 1 line
2.1.4
From 36ea15d6175781c48afee71c0fc4c2ca99f7e084 Mon Sep 17 00:00:00 2001
From: George Dunlap <[email protected]>
Date: Thu, 29 Dec 2016 20:01:27 +0000
Subject: [PATCH 5/7] golang/xenlight: Implement libxl_bitmap and helper
operations
Implement Bitmap type, along with helper operations.
The Bitmap type is implemented internally in a way which makes it easy to copy into and outof the C libxl_bitmap type.
--- tools/golang/xenlight/xenlight.go | 167 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+)
tools/golang/xenlight/xenlight.go +167 -0
179 lines not on this page · raw message
Signature · 1 line
2.1.4
From 272e37b66bfc206c5da5acb6772df8eb4e16e9d2 Mon Sep 17 00:00:00 2001
From: George Dunlap <[email protected]>
Date: Thu, 29 Dec 2016 20:04:20 +0000
Subject: [PATCH 6/7] golang/xenlight: Implement libxl_scheduler enumeration
Include both constants and a Stringification.
--- tools/golang/xenlight/xenlight.go | 63 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+)
tools/golang/xenlight/xenlight.go +63 -0
69 lines not on this page · raw message
Signature · 1 line
2.1.4
From 5325d67694900fe38a35a755bd0048020164cb31 Mon Sep 17 00:00:00 2001
From: George Dunlap <[email protected]>
Date: Thu, 29 Dec 2016 20:08:44 +0000
Subject: [PATCH 7/7] golang/xenlight: Implement cpupool operations
Also include some useful "Utility" functions:
- CpupoolFindByName
- CpupoolMakeFree
Still need to implement the following functions:
libxl_cpupool_rename
libxl_cpupool_cpuadd_node
libxl_cpupool_cpuremove_node
libxl_cpupool_movedomain
--- tools/golang/xenlight/xenlight.go | 244 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 244 insertions(+)
tools/golang/xenlight/xenlight.go +244 -0
259 lines not on this page · raw message
Signature · 1 line
2.1.4
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH RFC 59/59] tools/xenlight: Create interface for xenlight info
In reply to George DunlapQuoted 14 lines · George Dunlap
Hey Ronald! Looks like you're getting going pretty well here.
At a high level: I think I began by saying that this would probably all be a single patch. But I think it would probably be easier to review the different decisions made at each point by filling out the file bit by bit, and explaining what's going on at each point.
I think also it would be helpful to have somewhere -- either in a comment or in a text file -- a description of the general approach to converting the libxl C style into xenlight golang style. For instance, saying that for functions, we'll take the function name (
libxl_cpupool_remove), remove thelibxl_prefix (since the packages are namespaced already) and convert it to CamelCase by capitalizing the first
Quoted 2 lines
I'll take a stab at breaking it down in an example order that makes some sense to me, and then you can see what you think.
I made some guidelines that I think would nicely adjust the naming convention from C to Go. I'll add it as a file below.
Quoted 39 lines
Futher comments...
Quoted 22 lines · Ronald Rojas
tools/golang/xenlight/xenlight.go new file +16
-0@@ -0,0 +1,1000 @@ +/* + * Copyright (C) 2016 George W. Dunlap, Citrix Systems UK Ltd + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; version 2 of the + * License only. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MAtools/golang/xenlight/xenlight.go line 26
Quoted 10 lines
tools/golang/xenlight/xenlight.go new file +10
-0+ * 02110-1301, USA. + */ +package xenlight + +/* +#cgo LDFLAGS: -lxenlight -lyajl +#include <stdlib.h> +#include <libxl.h> +*/ +import "C"I see you switched back to dynamic linking -- any particular reason?
Quoted 2 lines
We probably need to put a "// FIXME" here saying that we need to generate these compile-time dependencies using pkg-config.
We discussed this on IRC but I'll just restate here that I was not able to compile the program through static linking and it would be fine to just use dynamic linking for now.
Since we are doing dynamic linking do we still need to use pkg-config?
Quoted 11 lines
tools/golang/xenlight/xenlight.go line 34
Quoted 9 lines
tools/golang/xenlight/xenlight.go new file +8
-0+ +/* + * Other flags that may be needed at some point: + * -lnl-route-3 -lnl-3 +#cgo LDFLAGS: -lxenlight -lyajl_s -lxengnttab -lxenstore -lxenguest -lxentoollog -lxenevtchn -lxenctrl -lblktapctl -lxenforeignmemory -lxencall -lz -luuid -lutil + * + * To get back to simple dynamic linking: +*/Comment needs updating (to "To use static linking").
Fixed.
Quoted 78 lines
Quoted 28 lines
tools/golang/xenlight/xenlight.go new file +27
-0+ +import ( + "fmt" + "time" + "unsafe" +) + +/* + * Errors + */ +const ( + ErrorNonspecific = int(C.ERROR_NONSPECIFIC) + ErrorVersion = int(C.ERROR_VERSION) + ErrorFail = int(C.ERROR_FAIL) + ErrorNi = int(C.ERROR_NI) + ErrorNomem = int(C.ERROR_NOMEM) + ErrorInval = int(C.ERROR_INVAL) + ErrorBadfail = int(C.ERROR_BADFAIL) + ErrorGuestTimedout = int(C.ERROR_GUEST_TIMEDOUT) + ErrorTimedout = int(C.ERROR_TIMEDOUT) + ErrorNoparavirt = int(C.ERROR_NOPARAVIRT) + ErrorNotReady = int(C.ERROR_NOT_READY) + ErrorOseventRegFail = int(C.ERROR_OSEVENT_REG_FAIL) + ErrorBufferfull = int(C.ERROR_BUFFERFULL) + ErrorUnknownChild = int(C.ERROR_UNKNOWN_CHILD) + ErrorLockFail = int(C.ERROR_LOCK_FAIL) + ErrorJsonConfigEmpty = int(C.ERROR_JSON_CONFIG_EMPTY)tools/golang/xenlight/xenlight.go line 71
Quoted 10 lines
tools/golang/xenlight/xenlight.go new file +10
-0+ ErrorDeviceExists = int(C.ERROR_DEVICE_EXISTS) + ErrorCheckpointDevopsDoesNotMatch = int(C.ERROR_CHECKPOINT_DEVOPS_DOES_NOT_MATCH) + ErrorCheckpointDeviceNotSupported = int(C.ERROR_CHECKPOINT_DEVICE_NOT_SUPPORTED) + ErrorVnumaConfigInvalid = int(C.ERROR_VNUMA_CONFIG_INVALID) + ErrorDomainNotfound = int(C.ERROR_DOMAIN_NOTFOUND) + ErrorAborted = int(C.ERROR_ABORTED) + ErrorNotfound = int(C.ERROR_NOTFOUND) + ErrorDomainDestroyed = int(C.ERROR_DOMAIN_DESTROYED) + ErrorFeatureRemoved = int(C.ERROR_FEATURE_REMOVED) +)The problem with this at the moment is that we don't actually return any of these errors -- instead we return a newly-generated error which contains text.
This pair of blog posts describes some approaches taken by different kinds of libraries to returning errors, and why:
https://www.goinggo.net/2014/10/error-handling-in-go-part-i.html
https://www.goinggo.net/2014/11/error-handling-in-go-part-ii.htmlAnother approach is taken by the go syscall package:
https://golang.org/pkg/syscall/#Errno
(See also https://golang.org/src/syscall/syscall_unix.go, lines 93-100, and https://golang.org/src/syscall/zerrors_linux_amd64.go, at lines 1204 and 1381.)
The approach taken by libraries in the second blog allows you to pass back a lot more information about what happened; but I think at the moment, given the limited number of things that libxl returns, that's probably overkill.
Which leaves us either taking the approach of something like bufio, and making things like this:
const (
ErrorNonspecific =errors.New("xenlight: Non-specific error")
...
)Or taking the approach of the syscall package, and defining a type:
type xlerror int
func (e xlerror)
Error(){}
Quoted 7 lines
And making a (private) errors[] array, and re-impleminting
Error()from the syscall package.I think I would probably go with the syscall library's approach, since (like it) we are handed a set of pre-existing error numbers.
What do you think?
I was actually thinking that taking the approach similiar to bufio would be better. It would not be difficult to create individual errors for each error number and creating variables for each error would allow users to easily compare the error that's returned against specific errors.
I've also been thinking about how to do the testing and I think it would be good to seperate testing into two parts, testing functions that get infomation about the system and functions that change the state of the system.
I haven't been able to figure out how to use osstest to use the Golang libxl but I think it would still be fine to do unit testing by writing C and Go code that get information from a specific fuction(like physinfo) and seeing if they produce the same output.
For functions that change the state of the system (like create/destroy guests) I think your idea of using a chaos monkey would be good. Maybe the general procedure would be something like this:
1. Get the complete system information through the functions tested in the first part.
2. Pick a random operation from a set implemented functions.
3. Make changes to the copy of the systems information that we have
4. Get the system information again through the golang functions and see if this copy of the system information matches the copy we already have.
5. Repeat as necessary
It will probably take some time to finalize the procedure so I will plan to submit it as a seperate patch or with a later patch.
Quoted 5 lines
OK, there's more to look at but I think that's enough for now.
-George
thanks,
Ronald
Rules for changing the naming convention from C to Golang
Builtins:
Remove underscores from C style name and use camelCase. If the type is a primitive data type(such a boolean or int) the equivilant Golang type is used. Otherwise delare the type as the C type.
Example:
type Scheduler int
type Uuid C.lixl_uuid
IDL types:
Remove underscores from C style name, remove libxl prefix,
and use camelCase. Data fields will follow the same format
by removing underscores and using camelCase. Example:
type CpupoolInfo struct {
Poolid uint32
PoolName string
Scheduler Scheduler
DomainCount int
Cpumap Bitmap
}Functions:
Removed the libxl prefix from the function name. Instead of underscores camelCase is used to seperate words. Example:
func (Ctx *Context) CpupoolInfo(Poolid uint32) (pool CpupoolInfo){}_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH RFC 59/59] tools/xenlight: Create interface for xenlight info
Quoted 9 lines · Ronald Rojas
Quoted 9 lines
tools/golang/xenlight/xenlight.go line 26
Quoted 6 lines
tools/golang/xenlight/xenlight.go new file +6
-0+/* +#cgo LDFLAGS: -lxenlight -lyajl +#include <stdlib.h> +#include <libxl.h> +*/ +import "C"I see you switched back to dynamic linking -- any particular reason?
Quoted 7 lines
Quoted 2 lines
We probably need to put a "// FIXME" here saying that we need to generate these compile-time dependencies using pkg-config.
We discussed this on IRC but I'll just restate here that I was not able to compile the program through static linking and it would be fine to just use dynamic linking for now.
Since we are doing dynamic linking do we still need to use pkg-config?
Probably at some point, to make it less likely things will ever break in the future (and as a "consumer" of the file to make sure things don't break for other users).
Quoted 14 lines
Quoted 14 lines
Or taking the approach of the syscall package, and defining a type:
type xlerror int
func (e xlerror)
Error(){}
And making a (private) errors[] array, and re-impleminting
Error()from the syscall package.I think I would probably go with the syscall library's approach, since (like it) we are handed a set of pre-existing error numbers.
Quoted 6 lines
Quoted 1 line
What do you think?
I was actually thinking that taking the approach similiar to bufio would be better. It would not be difficult to create individual errors for each error number and creating variables for each error would allow users to easily compare the error that's returned against specific errors.
You can do this with what the syscall library does as well -- see the references I linked to. Filling out my example a bit:
type Error int
const (
ErrorNonspecific = Error(C.ERROR_NONSPECIFIC)
ErrorVersion = Error(C.ERROR_VERSION)
...
)
var errors = [...]string{
C.ERROR_NONSPECIFIC: "Non-specific error",
C.ERROR_VERSION: "Wrong version",
...
}
func (e Error) Error() {
if 0 <= int(e) && int(e) < len(errors) {
s := errors[e]
if s != "" {
return s
} }
return "errno " + itoa(int(e))
}
Now Xenlight.ErrorNonspecific is a const that you can compare an error to; but if you "string" an error you'll get the error message in the errors[] table -- the same as what you get from the bufio package.
Another advantage of this method is that there's an easy way to convert return values from libxl functions into an error (just cast it directly to Error), and if the caller knows that the error returned is of type Xenlight.Error, they can cast it back to an int and use it themselves if they want.
But I think either method will work just fine. :-)
Quoted 22 lines
I've also been thinking about how to do the testing and I think it would be good to seperate testing into two parts, testing functions that get infomation about the system and functions that change the state of the system.
I haven't been able to figure out how to use osstest to use the Golang libxl but I think it would still be fine to do unit testing by writing C and Go code that get information from a specific fuction(like physinfo) and seeing if they produce the same output.
For functions that change the state of the system (like create/destroy guests) I think your idea of using a chaos monkey would be good. Maybe the general procedure would be something like this:
1. Get the complete system information through the functions tested in the first part.
2. Pick a random operation from a set implemented functions.
3. Make changes to the copy of the systems information that we have
4. Get the system information again through the golang functions and see if this copy of the system information matches the copy we already have.
5. Repeat as necessary
Quoted 2 lines
It will probably take some time to finalize the procedure so I will plan to submit it as a seperate patch or with a later patch.
Sounds like a plan.
-George
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel