[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH RFC 15/59] controller: Move "running" code to a separate file
From: George Dunlap <george.dunlap@xxxxxxxxxx> Signed-off-by: George Dunlap <george.dunlap@xxxxxxxxxx> --- Makefile | 2 +- benchmark.go | 153 -------------------------------------------------- run.go | 178 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 179 insertions(+), 154 deletions(-) create mode 100644 run.go diff --git a/Makefile b/Makefile index 7a33cfb..2e06f87 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/benchmark.go b/benchmark.go index 4354a47..2e03fe5 100644 --- a/benchmark.go +++ b/benchmark.go @@ -21,8 +21,6 @@ package main import ( "fmt" "os" - "os/signal" - "time" "io/ioutil" "encoding/json" ) @@ -71,11 +69,6 @@ const ( SEC = MSEC * 1000 ) -type WorkerState struct { - w Worker - LastReport WorkerReport -} - func Throughput(lt int, lm int, t int, m int) (tput float64) { time := float64(t - lt) / SEC mops := m - lm @@ -84,80 +77,6 @@ func Throughput(lt int, lm int, t int, m int) (tput float64) { return } -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 := 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); - } - - ws.LastReport = r -} - -type WorkerList map[WorkerId]*WorkerState - -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 { - (*ws)[i].w.Shutdown() - } -} - -const ( - WorkerProcess = iota - WorkerXen = iota -) - -func NewWorkerList(workers []WorkerSet, workerType int) (wl WorkerList, err error) { - wl = WorkerList(make(map[WorkerId]*WorkerState)) - - for wsi := range workers { - for i := 0; i < workers[wsi].Count; i = i+1 { - Id := WorkerId{Set:wsi,Id:i} - - ws := wl[Id] - - if ws != nil { - panic("Duplicate worker for id!") - } - - ws = &WorkerState{} - - switch workerType { - case WorkerProcess: - ws.w = &ProcessWorker{} - case WorkerXen: - ws.w = &XenWorker{} - default: - err = fmt.Errorf("Unknown type: %d", workerType) - return - } - - ws.w.SetId(Id) - - ws.w.Init(workers[wsi].Params) - - wl[Id] = ws - } - } - return -} - type BenchmarkRunData struct { Raw []WorkerReport `json:",omitempty"` Summary map[WorkerId]*WorkerSummary `json:",omitempty"` @@ -171,59 +90,6 @@ type BenchmarkRun struct { Results BenchmarkRunData } -func (run *BenchmarkRun) Run() (err error) { - Workers, err := NewWorkerList(run.Workers, WorkerXen) - if err != nil { - fmt.Println("Error creating workers: %v", err) - return - } - - report := make(chan WorkerReport) - done := make(chan bool) - signals := make(chan os.Signal, 1) - - signal.Notify(signals, os.Interrupt) - - i := Workers.Start(report, done) - - // 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 - timeout := time.After(time.Duration(run.RuntimeSeconds) * time.Second); - stopped := false - for i > 0 { - select { - case r := <-report: - run.Results.Raw = append(run.Results.Raw, r) - Report(Workers[r.Id], r) - case <-done: - i--; - fmt.Println(i, "workers left"); - case <-timeout: - if ! stopped { - Workers.Stop() - stopped = true - run.Completed = true - } - case <-signals: - if ! stopped { - fmt.Println("SIGINT receieved, shutting down workers") - Workers.Stop() - stopped = true - if run.RuntimeSeconds == 0 { - run.Completed = true - } - err = fmt.Errorf("Interrupted") - } else { - err = fmt.Errorf("Interrupted") - fmt.Println("SIGINT received after stop, exiting without cleaning up") - return - } - } - } - return -} - func (run *BenchmarkRun) checkSummary() (done bool, err error) { if run.Results.Summary != nil { done = true @@ -328,25 +194,6 @@ type BenchmarkPlan struct { Runs []BenchmarkRun } -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() - if err != nil { - return - } - } - fmt.Printf("Test [%d] %s completed\n", i, plan.Runs[i].Label) - err = plan.Save() - if err != nil { - fmt.Println("Error saving: ", err) - return - } - } - return -} - func LoadBenchmark(filename string) (plan BenchmarkPlan, err error) { plan.filename = filename diff --git a/run.go b/run.go new file mode 100644 index 0000000..7b5ef0a --- /dev/null +++ b/run.go @@ -0,0 +1,178 @@ +/* + * 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 ( + "fmt" + "os" + "os/signal" + "time" +) + +type WorkerState struct { + w 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 := 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); + } + + ws.LastReport = r +} + +type WorkerList map[WorkerId]*WorkerState + +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 { + (*ws)[i].w.Shutdown() + } +} + +const ( + WorkerProcess = iota + WorkerXen = iota +) + +func NewWorkerList(WorkerSets []WorkerSet, workerType int) (wl WorkerList, err error) { + wl = WorkerList(make(map[WorkerId]*WorkerState)) + + for wsi := range WorkerSets { + for i := 0; i < WorkerSets[wsi].Count; i = i+1 { + Id := WorkerId{Set:wsi,Id:i} + + ws := wl[Id] + + if ws != nil { + panic("Duplicate worker for id!") + } + + ws = &WorkerState{} + + switch workerType { + case WorkerProcess: + ws.w = &ProcessWorker{} + case WorkerXen: + ws.w = &XenWorker{} + default: + err = fmt.Errorf("Unknown type: %d", workerType) + return + } + + ws.w.SetId(Id) + + ws.w.Init(WorkerSets[wsi].Params) + + wl[Id] = ws + } + } + return +} + +func (run *BenchmarkRun) Run() (err error) { + Workers, err := NewWorkerList(run.Workers, WorkerXen) + if err != nil { + fmt.Println("Error creating workers: %v", err) + return + } + + report := make(chan WorkerReport) + done := make(chan bool) + signals := make(chan os.Signal, 1) + + signal.Notify(signals, os.Interrupt) + + i := Workers.Start(report, done) + + // 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 + timeout := time.After(time.Duration(run.RuntimeSeconds) * time.Second); + stopped := false + for i > 0 { + select { + case r := <-report: + run.Results.Raw = append(run.Results.Raw, r) + Report(Workers[r.Id], r) + case <-done: + i--; + fmt.Println(i, "workers left"); + case <-timeout: + if ! stopped { + Workers.Stop() + stopped = true + run.Completed = true + } + case <-signals: + if ! stopped { + fmt.Println("SIGINT receieved, shutting down workers") + Workers.Stop() + stopped = true + if run.RuntimeSeconds == 0 { + run.Completed = true + } + err = fmt.Errorf("Interrupted") + } else { + err = fmt.Errorf("Interrupted") + fmt.Println("SIGINT received after stop, exiting without cleaning up") + return + } + } + } + return +} + +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() + if err != nil { + return + } + } + fmt.Printf("Test [%d] %s completed\n", i, plan.Runs[i].Label) + err = plan.Save() + if err != nil { + fmt.Println("Error saving: ", err) + return + } + } + return +} + -- 2.7.4 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx https://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |