@@ -33,6 +33,7 @@ import (
3333
3434 vmv1 "github.com/neondatabase/autoscaling/neonvm/apis/neonvm/v1"
3535 "github.com/neondatabase/autoscaling/pkg/util"
36+ "github.com/neondatabase/autoscaling/pkg/util/gzip64"
3637 "github.com/neondatabase/autoscaling/pkg/util/taskgroup"
3738)
3839
@@ -112,6 +113,8 @@ type Config struct {
112113 cpuScalingMode vmv1.CpuScalingMode
113114 // System CPU architecture. Set automatically equal to runtime.GOARCH.
114115 architecture string
116+ // useVirtioConsole is a flag to use virtio console instead of serial console.
117+ useVirtioConsole bool
115118}
116119
117120func newConfig (logger * zap.Logger ) * Config {
@@ -125,11 +128,12 @@ func newConfig(logger *zap.Logger) *Config {
125128 autoMovableRatio : "" ,
126129 cpuScalingMode : "" ,
127130 architecture : runtime .GOARCH ,
131+ useVirtioConsole : false ,
128132 }
129133 flag .StringVar (& cfg .vmSpecDump , "vmspec" , cfg .vmSpecDump ,
130- "Base64 encoded VirtualMachine json specification" )
134+ "Base64 gzip compressed VirtualMachine json specification" )
131135 flag .StringVar (& cfg .vmStatusDump , "vmstatus" , cfg .vmStatusDump ,
132- "Base64 encoded VirtualMachine json status" )
136+ "Base64 gzip compressed VirtualMachine json status" )
133137 flag .StringVar (& cfg .kernelPath , "kernelpath" , cfg .kernelPath ,
134138 "Override path for kernel to use" )
135139 flag .StringVar (& cfg .appendKernelCmdline , "appendKernelCmdline" ,
@@ -142,6 +146,8 @@ func newConfig(logger *zap.Logger) *Config {
142146 flag .StringVar (& cfg .autoMovableRatio , "memhp-auto-movable-ratio" ,
143147 cfg .autoMovableRatio , "Set value of kernel's memory_hotplug.auto_movable_ratio [virtio-mem only]" )
144148 flag .Func ("cpu-scaling-mode" , "Set CPU scaling mode" , cfg .cpuScalingMode .FlagFunc )
149+ flag .BoolVar (& cfg .useVirtioConsole , "use-virtio-console" ,
150+ cfg .useVirtioConsole , "Use virtio console instead of serial console" )
145151 flag .Parse ()
146152
147153 if cfg .autoMovableRatio == "" {
@@ -165,11 +171,11 @@ func main() {
165171func run (logger * zap.Logger ) error {
166172 cfg := newConfig (logger )
167173
168- vmSpecJson , err := base64 . StdEncoding . DecodeString (cfg .vmSpecDump )
174+ vmSpecJson , err := gzip64 . Decode (cfg .vmSpecDump )
169175 if err != nil {
170176 return fmt .Errorf ("failed to decode VirtualMachine Spec dump: %w" , err )
171177 }
172- vmStatusJson , err := base64 . StdEncoding . DecodeString (cfg .vmStatusDump )
178+ vmStatusJson , err := gzip64 . Decode (cfg .vmStatusDump )
173179 if err != nil {
174180 return fmt .Errorf ("failed to decode VirtualMachine Status dump: %w" , err )
175181 }
@@ -331,8 +337,17 @@ func buildQEMUCmd(
331337 "-device" , "virtconsole,chardev=virtio-console" ,
332338 )
333339 case architectureAmd64 :
334- // on amd we have multiple UART ports so we can just use serial stdio
335- qemuCmd = append (qemuCmd , "-serial" , "stdio" )
340+ // UART port is used by default but it has performance issues.
341+ // Virtio console is more performant.
342+ if cfg .useVirtioConsole {
343+ qemuCmd = append (qemuCmd ,
344+ "-chardev" , "stdio,id=virtio-console" ,
345+ "-device" , "virtconsole,chardev=virtio-console" ,
346+ )
347+ } else {
348+ // on amd we have multiple UART ports so we can just use serial stdio
349+ qemuCmd = append (qemuCmd , "-serial" , "stdio" )
350+ }
336351 default :
337352 logger .Fatal ("unsupported architecture" , zap .String ("architecture" , cfg .architecture ))
338353 }
@@ -449,7 +464,12 @@ func makeKernelCmdline(cfg *Config, logger *zap.Logger, vmSpec *vmv1.VirtualMach
449464 // use virtio-serial device kernel console
450465 cmdlineParts = append (cmdlineParts , "console=hvc0" )
451466 case architectureAmd64 :
452- cmdlineParts = append (cmdlineParts , "console=ttyS1" )
467+ // use virtio-serial device if virtio console is enabled
468+ if cfg .useVirtioConsole {
469+ cmdlineParts = append (cmdlineParts , "console=hvc0" )
470+ } else {
471+ cmdlineParts = append (cmdlineParts , "console=ttyS1" )
472+ }
453473 default :
454474 logger .Fatal ("unsupported architecture" , zap .String ("architecture" , cfg .architecture ))
455475 }
0 commit comments