diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2017-10-12 19:08:18 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2017-10-12 19:08:18 +0200 |
| commit | 66aeb467de80c92a099e49eaad6c25974c96f9cf (patch) | |
| tree | cde1ee4dca1033104b2b858007c4cd2d5e0b5d12 /prog | |
| parent | 81e199f71969b97c80cbb4473ddd53adeed3b4d4 (diff) | |
pkg/ipc: don't send program padding to executor
Currently we always send 2MB of data to executor in ipc_simple.go.
Send only what's consumed by the program, and don't send the trailing zeros.
Serialized programs usually take only few KBs.
Diffstat (limited to 'prog')
| -rw-r--r-- | prog/encodingexec.go | 7 | ||||
| -rw-r--r-- | prog/encodingexec_test.go | 4 |
2 files changed, 6 insertions, 5 deletions
diff --git a/prog/encodingexec.go b/prog/encodingexec.go index b2b173bbe..e45ba1192 100644 --- a/prog/encodingexec.go +++ b/prog/encodingexec.go @@ -57,8 +57,9 @@ func (s ByPhysicalAddr) Less(i, j int) bool { } // SerializeForExec serializes program p for execution by process pid into the provided buffer. +// Returns number of bytes written to the buffer. // If the provided buffer is too small for the program an error is returned. -func (p *Prog) SerializeForExec(buffer []byte, pid int) error { +func (p *Prog) SerializeForExec(buffer []byte, pid int) (int, error) { if debug { if err := p.validate(); err != nil { panic(fmt.Errorf("serializing invalid program: %v", err)) @@ -193,9 +194,9 @@ func (p *Prog) SerializeForExec(buffer []byte, pid int) error { } w.write(ExecInstrEOF) if w.eof { - return fmt.Errorf("provided buffer is too small") + return 0, fmt.Errorf("provided buffer is too small") } - return nil + return len(buffer) - len(w.buf), nil } func (target *Target) physicalAddr(arg Arg) uint64 { diff --git a/prog/encodingexec_test.go b/prog/encodingexec_test.go index 3b37783f2..cff800911 100644 --- a/prog/encodingexec_test.go +++ b/prog/encodingexec_test.go @@ -15,7 +15,7 @@ func TestSerializeForExecRandom(t *testing.T) { buf := make([]byte, ExecBufferSize) for i := 0; i < iters; i++ { p := target.Generate(rs, 10, nil) - if err := p.SerializeForExec(buf, i%16); err != nil { + if _, err := p.SerializeForExec(buf, i%16); err != nil { t.Fatalf("failed to serialize: %v", err) } } @@ -269,7 +269,7 @@ func TestSerializeForExec(t *testing.T) { if err != nil { t.Fatalf("failed to deserialize prog %v: %v", i, err) } - if err := p.SerializeForExec(buf, i%16); err != nil { + if _, err := p.SerializeForExec(buf, i%16); err != nil { t.Fatalf("failed to serialize: %v", err) } w := new(bytes.Buffer) |
