diff --git a/docs/setup.md b/docs/setup.md index 07a522b..cdf6826 100644 --- a/docs/setup.md +++ b/docs/setup.md @@ -272,3 +272,5 @@ git diff --stat ORIG_HEAD -- src/versions.env src/patches # anything here: reb ./macbox backup before-xcode-27 # a copy of the disk (instant on XFS/Btrfs reflinks), the VM stopped ./macbox build && ./macbox down && ./macbox up # a newer build ``` + +The VM configuration enables QEMU's `usb-kbd.x-ignore-idle` property to avoid unchanged keyboard reports at idle. Before rolling back to a QEMU build without patch 0015, remove `-global usb-kbd.x-ignore-idle=on` from the VM configuration (`vm.toml`) and from the scripts that regenerate it; older builds cannot start with that flag. diff --git a/macbox b/macbox index 5cb6dd3..9d0e2bf 100755 --- a/macbox +++ b/macbox @@ -189,6 +189,8 @@ qemu_extra() { # the network (passt, SSH forwarded by Docker) and the disk's op -set "drive.disk.cache=$MACBOX_DISK_CACHE" -set drive.disk.discard=unmap; do out+=("$(printf '%q' "$a")") done + # QEMU 0015: do not send unchanged keyboard reports at idle. + out+=(-global usb-kbd.x-ignore-idle=on) # Reims's VideoToolbox and M2 scaler devices, in the slots reims-ctl gives them (after the mapper) [ "$MACBOX_VIDEO" = on ] && out+=(-device apple-videotoolbox-pci,id=video,bus=pcie.0,addr=0x8 \ -device apple-m2scaler-pci,id=scaler,bus=pcie.0,addr=0x9) diff --git a/src/patches/README.md b/src/patches/README.md index f38809b..30dfb77 100644 --- a/src/patches/README.md +++ b/src/patches/README.md @@ -64,7 +64,7 @@ is in [docs/performance.md](../../docs/performance.md#gpu-tuning-switches). | 0034, 0035 the detach check | Every submission is checked, on metal2vulkan's scheduler thread, against the objects detached now. That list is now made once per change (a detach, an attach or a release), sorted, and asked by binary search (metal2vulkan 0100). Before, it was made again for every check and scanned: 18–24% of that thread's time. On by default. Live `detached_sorted=0` brings back the check as before, for an A/B in one boot. Measured: 1 simulator +3.5%, 3 simulators +5.3% ([performance.md](../../docs/performance.md#several-simulators-at-once-and-the-desktop-under-load)). | | 0036 `REIMS_VGPU_WINDOW_COMPOSITOR_FILE` | the windows move to another Wayland compositor while the VM runs: the file names the socket. Reims connects to it itself and hands SDL the connection; when the file changes, each window lets its input go, its render thread lets the swapchain and surface go, SDL's video restarts on the new socket, and the windows open there. On failure they go back. `.on` says where they are. Off unless set; `MACBOX_VIEW_SWITCH=on` sets it. | -## QEMU (`vendor/qemu` at bd95509, github.com/steelbrain/qemu-reims-vgpu), 14 patches +## QEMU (`vendor/qemu` at bd95509, github.com/steelbrain/qemu-reims-vgpu), 15 patches | Patches | What they do | |---|---| @@ -72,6 +72,7 @@ is in [docs/performance.md](../../docs/performance.md#gpu-tuning-switches). | 0004, 0005 coherent pages | with `REIMS_VGPU_COHERENT=1` the same markers serve metal2vulkan's trap-coherent surfaces. A run that doesn't end well leaves `coherent.running` in the census directory, and every later start boots without coherent pages until it's removed (`macbox coherent reset`), so a fault there costs one crash, not a crash loop. | | 0010–0013 KVM shortcuts for the GPU device | `x-irqfd` (interrupts through a KVM irqfd), `x-halt-poll-ns`, `x-ioeventfd` (doorbells through KVM ioeventfds): device properties, all off unless set | | 0014 the video devices | upstream's own 4895365e5b (on `steelbrain/reims-vgpu`, after bd95509), unchanged: `apple-videotoolbox-pci` (106b:1a03) and `apple-m2scaler-pci` (106b:1a0b), the transports of Reims's VideoToolbox and scaler devices. Without it the build can't attach them. Drop it when `QEMU_REF` moves past 4895365e5b. The devices stay detached unless `MACBOX_VIDEO=on` | +| 0015 `x-ignore-idle` | usb-kbd can ignore the guest's idle timer and send reports only on key changes. The property defaults to off; macbox enables it with `-global usb-kbd.x-ignore-idle=on`. | ## Licenses diff --git a/src/patches/qemu/0015-usb-kbd-x-ignore-idle-an-idle-keyboard-reports-only-on.patch b/src/patches/qemu/0015-usb-kbd-x-ignore-idle-an-idle-keyboard-reports-only-on.patch new file mode 100644 index 0000000..02abe89 --- /dev/null +++ b/src/patches/qemu/0015-usb-kbd-x-ignore-idle-an-idle-keyboard-reports-only-on.patch @@ -0,0 +1,114 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: macbox +Date: Sun, 15 Nov 2026 01:20:04 +0200 +Subject: [PATCH 15/15] usb-kbd: x-ignore-idle, an idle keyboard reports only on key + changes + +Allow usb-kbd to ignore the HID idle timer while preserving the idle value +reported to the guest. The property defaults to off and can be changed live. +The guest idle value is reset on device reset and is not migrated. + +--- + hw/usb/dev-hid.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++- + 1 file changed, 54 insertions(+), 1 deletion(-) + +diff --git a/hw/usb/dev-hid.c b/hw/usb/dev-hid.c +index ae19d60203..1d0e36d405 100644 +--- a/hw/usb/dev-hid.c ++++ b/hw/usb/dev-hid.c +@@ -43,6 +43,19 @@ struct USBHIDState { + uint32_t usb_version; + char *display; + uint32_t head; ++ /* ++ * x-ignore-idle (usb-kbd only, off by default). macOS sets ++ * the keyboard's idle rate to 24 ms, so an idle keyboard sends a report ++ * every 24 ms (41.6/s: 2026-11-15, QEMU's usb_xhci_xfer_success trace) ++ * and the guest's HID driver wakes for each. With it on, SET_IDLE is ++ * accepted and GET_IDLE answers it, but the keyboard reports only when ++ * a key changes, as it does at idle rate 0. macOS repeats held keys ++ * itself. Live: qom-set turns it on or off in a running VM (an A/B in ++ * one boot); -global usb-kbd.x-ignore-idle=on sets it at start. Not ++ * migrated. ++ */ ++ bool ignore_idle; ++ uint8_t guest_idle; + }; + + #define TYPE_USB_HID "usb-hid" +@@ -570,6 +583,7 @@ static void usb_hid_handle_reset(USBDevice *dev) + USBHIDState *us = USB_HID(dev); + + hid_reset(&us->hid); ++ us->guest_idle = 0; + } + + static void usb_hid_handle_control(USBDevice *dev, USBPacket *p, +@@ -635,10 +649,14 @@ static void usb_hid_handle_control(USBDevice *dev, USBPacket *p, + hs->protocol = value; + break; + case HID_GET_IDLE: +- data[0] = hs->idle; ++ data[0] = us->ignore_idle ? us->guest_idle : hs->idle; + p->actual_length = 1; + break; + case HID_SET_IDLE: ++ if (us->ignore_idle) { ++ us->guest_idle = (uint8_t) (value >> 8); ++ break; ++ } + hs->idle = (uint8_t) (value >> 8); + hid_set_next_idle(hs); + if (hs->kind == HID_MOUSE || hs->kind == HID_TABLET) { +@@ -844,6 +862,35 @@ static const Property usb_keyboard_properties[] = { + DEFINE_PROP_STRING("display", USBHIDState, display), + }; + ++static bool usb_kbd_get_ignore_idle(Object *obj, Error **errp) ++{ ++ return USB_HID(obj)->ignore_idle; ++} ++ ++/* ++ * On: the idle rate the guest set is kept aside and the keyboard's is 0, so ++ * its timer goes. Off: the guest's rate is the keyboard's again. ++ */ ++static void usb_kbd_set_ignore_idle(Object *obj, bool value, Error **errp) ++{ ++ USBHIDState *us = USB_HID(obj); ++ HIDState *hs = &us->hid; ++ ++ if (value == us->ignore_idle) { ++ return; ++ } ++ if (value) { ++ us->guest_idle = hs->idle; ++ hs->idle = 0; ++ } else { ++ hs->idle = us->guest_idle; ++ } ++ us->ignore_idle = value; ++ if (hs->event) { ++ hid_set_next_idle(hs); ++ } ++} ++ + static void usb_keyboard_class_initfn(ObjectClass *klass, const void *data) + { + DeviceClass *dc = DEVICE_CLASS(klass); +@@ -853,6 +900,12 @@ static void usb_keyboard_class_initfn(ObjectClass *klass, const void *data) + uc->product_desc = "QEMU USB Keyboard"; + dc->vmsd = &vmstate_usb_kbd; + device_class_set_props(dc, usb_keyboard_properties); ++ object_class_property_add_bool(klass, "x-ignore-idle", ++ usb_kbd_get_ignore_idle, ++ usb_kbd_set_ignore_idle); ++ object_class_property_set_description(klass, "x-ignore-idle", ++ "Report only on key changes, whatever idle rate the " ++ "guest sets (live)"); + set_bit(DEVICE_CATEGORY_INPUT, dc->categories); + } + +-- +2.53.0 +