Skip to content

Commit 41ae555

Browse files
committed
disable video display by default
As of QEMU v5.2, enabling video display has negative impact due to macOS App Nap: https://gitlab.com/qemu-project/qemu/-/issues/334 Close #29 Signed-off-by: Akihiro Suda <[email protected]>
1 parent 9a2939f commit 41ae555

File tree

7 files changed

+40
-2
lines changed

7 files changed

+40
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ Host * !127.0.0.1
261261
### "Hints for debugging other problems?"
262262
- Inspect logs:
263263
- `limactl --debug start`
264+
- `$HOME/.lima/<INSTANCE>/serial.log`
264265
- `/var/log/cloud-init-output.log` (inside the guest)
265266
- `/var/log/cloud-init.log` (inside the guest)
266267
- Make sure that you aren't mixing up tabs and spaces in the YAML.

docs/internal.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ An instance directory contains the following files:
1111
- `qemu-pid`: PID of the QEMU
1212
- `ssh.sock`: SSH control master socket
1313
- `ga.sock`: Forwarded to `/run/user/$UID/lima-guestagent.sock`
14+
- `serial.log`: QEMU serial log, for debugging
15+
- `serial.sock`: QEMU serial socket, for debugging (Usage: `socat -,echo=0,icanon=0 unix-connect:serial.sock`)

pkg/limayaml/default.TEMPLATE.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ firmware:
5151
# Default: false
5252
legacyBIOS: false
5353

54+
video:
55+
# QEMU display, e.g., "none", "cocoa", "sdl".
56+
# As of QEMU v5.2, enabling this is known to have negative impact
57+
# on performance on macOS hosts: https://gitlab.com/qemu-project/qemu/-/issues/334
58+
# Default: "none"
59+
display: "none"
60+
5461
#UNIMPLEMENTED| provision:
5562
#UNIMPLEMENTED| # `system` is executed with the root privilege
5663
#UNIMPLEMENTED| system: |

pkg/limayaml/defaults.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ func FillDefault(y *LimaYAML) {
1919
if y.Disk == "" {
2020
y.Disk = "100GiB"
2121
}
22+
23+
if y.Video.Display == "" {
24+
y.Video.Display = "none"
25+
}
2226
}
2327

2428
func resolveArch(s string) Arch {

pkg/limayaml/limayaml.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ type LimaYAML struct {
99
Mounts []Mount `yaml:"mounts,omitempty"`
1010
SSH SSH `yaml:"ssh,omitempty"` // REQUIRED (FIXME)
1111
Firmware Firmware `yaml:"firmware,omitempty"`
12+
Video Video `yaml:"video,omitempty"`
1213
}
1314

1415
type Arch = string
@@ -37,3 +38,8 @@ type Firmware struct {
3738
// LegacyBIOS is ignored for aarch64.
3839
LegacyBIOS bool `yaml:"legacyBIOS,omitempty"`
3940
}
41+
42+
type Video struct {
43+
// Display is a QEMU display string
44+
Display string `yaml:"display,omitempty"`
45+
}

pkg/qemu/qemu.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,10 @@ func Cmdline(cfg Config) (string, []string, error) {
144144
// virtio-rng-pci acceralates starting up the OS, according to https://wiki.gentoo.org/wiki/QEMU/Options
145145
args = append(args, "-device", "virtio-rng-pci")
146146

147-
// Misc devices
147+
// Graphics
148+
if y.Video.Display != "" {
149+
args = append(args, "-display", y.Video.Display)
150+
}
148151
switch y.Arch {
149152
case limayaml.X8664:
150153
args = append(args, "-device", "virtio-vga")
@@ -157,8 +160,23 @@ func Cmdline(cfg Config) (string, []string, error) {
157160
args = append(args, "-device", "usb-kbd")
158161
args = append(args, "-device", "usb-mouse")
159162
}
163+
164+
// Parallel
160165
args = append(args, "-parallel", "none")
161166

167+
// Serial
168+
serialSock := filepath.Join(cfg.InstanceDir, "serial.sock")
169+
if err := os.RemoveAll(serialSock); err != nil {
170+
return "", nil, err
171+
}
172+
serialLog := filepath.Join(cfg.InstanceDir, "serial.log")
173+
if err := os.RemoveAll(serialLog); err != nil {
174+
return "", nil, err
175+
}
176+
const serialChardev = "char-serial"
177+
args = append(args, "-chardev", fmt.Sprintf("socket,id=%s,path=%s,server,nowait,logfile=%s", serialChardev, serialSock, serialLog))
178+
args = append(args, "-serial", "chardev:"+serialChardev)
179+
162180
// We also want to enable vsock and virtfs here, but QEMU does not support vsock and virtfs for macOS hosts
163181

164182
// QEMU process

pkg/start/start.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func Start(ctx context.Context, instName, instDir string, y *limayaml.LimaYAML)
3535
qCmd := exec.CommandContext(ctx, qExe, qArgs...)
3636
qCmd.Stdout = os.Stdout
3737
qCmd.Stderr = os.Stderr
38-
logrus.Info("Starting QEMU")
38+
logrus.Infof("Starting QEMU (hint: to watch the boot progress, see %q)", filepath.Join(instDir, "serial.log"))
3939
logrus.Debugf("qCmd.Args: %v", qCmd.Args)
4040
if err := qCmd.Start(); err != nil {
4141
return err

0 commit comments

Comments
 (0)