From 8d33daa13a646b4c3ce485286ecb2ad360e6565f Mon Sep 17 00:00:00 2001 From: AngelaBriel Date: Thu, 3 Jan 2019 15:02:23 +0100 Subject: [PATCH] remove new line from println arg list remove unused 'daemon' part to prevent errors on ppc hw --- daemon/client.go | 42 ----------------------- daemon/func.go | 84 --------------------------------------------- daemon/func_test.go | 37 -------------------- daemon/server.go | 56 ------------------------------ main.go | 3 +- 5 files changed, 1 insertion(+), 221 deletions(-) delete mode 100644 daemon/client.go delete mode 100644 daemon/func.go delete mode 100644 daemon/func_test.go delete mode 100644 daemon/server.go diff --git a/daemon/client.go b/daemon/client.go deleted file mode 100644 index 7f0a9f5d..00000000 --- a/daemon/client.go +++ /dev/null @@ -1,42 +0,0 @@ -package daemon - -import ( - "fmt" - "net" - "net/rpc" -) - -// Client connects to RPC server via domain socket in order to call RPC functions. -type Client struct { -} - -// doRPC establishes a new connection via domain socket and executes exactly one RPC call. -func (client *Client) doRPC(fun func(*rpc.Client) error) error { - conn, err := net.Dial("unix", DomainSocketFile) - if err != nil { - return err - } - defer conn.Close() - rpcClient := rpc.NewClient(conn) - defer rpcClient.Close() - if err := fun(rpcClient); err != nil { - return err - } - return nil -} - -// SetForceLatency instructs RPC server to maintain a new value for cpu_dma_latency. -func (client *Client) SetForceLatency(newValue int) error { - return client.doRPC(func(rpcClient *rpc.Client) error { - var dummy DummyAttr - return rpcClient.Call(fmt.Sprintf(RPCObjNameFmt, "SetForceLatency"), newValue, &dummy) - }) -} - -// StopForceLatency instructs RPC server to stop background loop that maintains cpu_dma_latency value. -func (client *Client) StopForceLatency() error { - return client.doRPC(func(rpcClient *rpc.Client) error { - var dummy DummyAttr - return rpcClient.Call(fmt.Sprintf(RPCObjNameFmt, "StopForceLatency"), dummy, &dummy) - }) -} diff --git a/daemon/func.go b/daemon/func.go deleted file mode 100644 index 618e0eda..00000000 --- a/daemon/func.go +++ /dev/null @@ -1,84 +0,0 @@ -package daemon - -import ( - "log" - "os" - "reflect" - "sync" -) - -// FunctionHost hosts saptune daemon's RPC functions that are invoked by RPC client. -type FunctionHost struct { - forceLatency chan int // forceLatency channel stores the latest setting daemon should apply in cpu_dma_latency. - forceLatencyIsSet bool // forceLatencyLoop is true only if the continuous loop that maintains force-latency value is running. - mutex *sync.Mutex // mutex protects internal states from being modified concurrently. -} - -// NewFunctionHost returns an initialised function host. -func NewFunctionHost() *FunctionHost { - return &FunctionHost{ - forceLatency: make(chan int), - mutex: new(sync.Mutex), - } -} - -// RPCObjNameFmt is a format string that helps client to construct RPC call function name. -var RPCObjNameFmt = reflect.TypeOf(FunctionHost{}).Name() + ".%s" - -type DummyAttr bool // DummyAttr is a placeholder receiver's type in an RPC function - -/* -maintainDMALatency opens a file handle to /dev/cpu_dma_latency and feeds it the latest desired value. -Blocks caller until channel is closed. -*/ -func (host *FunctionHost) maintainDMALatency() { - // The file handle must be maintained open in order to set the value - dmaLatency, err := os.OpenFile("/dev/cpu_dma_latency", os.O_RDWR, 0600) - if err != nil { - log.Printf("FunctionHost.maintainDMALatency: failed to open cpu_dma_latency - %v", err) - } - // Close the file handle after the latency value is no longer maintained - defer dmaLatency.Close() - - for { - newValue, keepGoing := <-host.forceLatency - if keepGoing { - log.Printf("FunctionHost.maintainDMALatency: setting cpu_dma_latency to new value %d", newValue) - // TODO: write new value into file - } else { - // Caller is responsible for maintaining forceLatencyIsSet flag - log.Print("FunctionHost.maintainDMALatency: stop maintaining cpu_dma_latency") - return - } - } -} - -/* -SetForceLatency starts a loop that manipulates cpu_dma_latency to match input value. If the loop is already -started, the loop will be informed about the new value via a channel. -*/ -func (host *FunctionHost) SetForceLatency(newValue int, _ *DummyAttr) error { - host.mutex.Lock() - defer host.mutex.Unlock() - if !host.forceLatencyIsSet { - host.forceLatencyIsSet = true - go host.maintainDMALatency() - } - host.forceLatency <- newValue - /* - The RPC function does not wait till value is set before responding to client. - Should an error occur, the goroutine in background will log the error and quit. - */ - return nil -} - -// StopForceLatency stops the background loop that maintains cpu_dma_latency by closing its channel. -func (host *FunctionHost) StopForceLatency(_ DummyAttr, _ *DummyAttr) error { - host.mutex.Lock() - defer host.mutex.Unlock() - if host.forceLatencyIsSet { - close(host.forceLatency) - host.forceLatencyIsSet = false - } - return nil -} diff --git a/daemon/func_test.go b/daemon/func_test.go deleted file mode 100644 index 575b332a..00000000 --- a/daemon/func_test.go +++ /dev/null @@ -1,37 +0,0 @@ -package daemon - -import ( - "github.com/SUSE/saptune/system" - "testing" - "time" -) - -func TestFunc(t *testing.T) { - if !system.IsUserRoot() { - t.Skip("the test requires root access") - } - // Start RPC server - server := new(Server) - if err := server.Listen(); err != nil { - t.Fatal(err) - } - go server.MainLoop() - // Expect RPC server to be ready in a second - time.Sleep(1 * time.Second) - client := new(Client) - // Test all RPC functions - if err := client.SetForceLatency(1); err != nil { - t.Fatal(err) - } - if err := client.StopForceLatency(); err != nil { - t.Fatal(err) - } - // Repeatedly shutdown server should not carry negative consequence - server.Shutdown() - server.Shutdown() - // Server should shut down in a second - time.Sleep(1 * time.Second) - if err := client.StopForceLatency(); err == nil { - t.Fatal("did not shutdown") - } -} diff --git a/daemon/server.go b/daemon/server.go deleted file mode 100644 index 28249711..00000000 --- a/daemon/server.go +++ /dev/null @@ -1,56 +0,0 @@ -package daemon - -import ( - "log" - "net" - "net/rpc" - "os" -) - -const ( - // DomainSocketFile is the file name of unix domain socket server that saptune daemon listens on. - DomainSocketFile = "/var/run/saptune" -) - -// Server is run by saptune system service to handle certain tuning parameters that require long-term maintenance. -type Server struct { - listener net.Listener // listener is the unix domain socket listener. - rpcServer *rpc.Server // rpcServer is the RPC server serving connections on domain socket. - host *FunctionHost // host is an object of all RPC functions served to RPC client. -} - -// Listen establishes unix domain socket listener and starts RPC server. -func (srv *Server) Listen() (err error) { - if err := os.RemoveAll(DomainSocketFile); err != nil { - return err - } - srv.listener, err = net.Listen("unix", DomainSocketFile) - if err != nil { - return - } - srv.host = NewFunctionHost() - srv.rpcServer = rpc.NewServer() - srv.rpcServer.Register(srv.host) - log.Printf("Server.Listen: listening on %s", DomainSocketFile) - return -} - -// Shutdown closes server listener so that main loop (if running) will terminate. -func (srv *Server) Shutdown() { - if listener := srv.listener; listener != nil { - listener.Close() - srv.listener = nil - } -} - -// MainLoop accepts and handles incoming connections in a continuous loop. Blocks caller until listener closes. -func (srv *Server) MainLoop() { - for { - client, err := srv.listener.Accept() - if err != nil { - log.Printf("Server.MainLoop: quit now - %v", err) - return - } - go srv.rpcServer.ServeConn(client) - } -} diff --git a/main.go b/main.go index a3958bcc..6e0e0269 100644 --- a/main.go +++ b/main.go @@ -34,8 +34,7 @@ Tune system according to SAP and SUSE notes: saptune note [ apply | simulate | verify | customise | revert ] NoteID Tune system for all notes applicable to your SAP solution: saptune solution [ list | verify ] - saptune solution [ apply | simulate | verify | revert ] SolutionName -`) + saptune solution [ apply | simulate | verify | revert ] SolutionName`) os.Exit(exitStatus) }