From nobody Fri May 3 12:39:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1490880972059415.43614975412675; Thu, 30 Mar 2017 06:36:12 -0700 (PDT) Received: from localhost ([::1]:35655 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ctaFF-0004Fd-Sv for importer@patchew.org; Thu, 30 Mar 2017 09:36:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35659) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ctaEX-0003xY-2j for qemu-devel@nongnu.org; Thu, 30 Mar 2017 09:35:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ctaET-00027I-0v for qemu-devel@nongnu.org; Thu, 30 Mar 2017 09:35:25 -0400 Received: from mx2.suse.de ([195.135.220.15]:58476) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ctaES-00025C-RM for qemu-devel@nongnu.org; Thu, 30 Mar 2017 09:35:20 -0400 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 9EBD0ABEB; Thu, 30 Mar 2017 13:35:18 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Alexander Graf To: qemu-devel@nongnu.org Date: Thu, 30 Mar 2017 15:35:38 +0200 Message-Id: <1490880938-90331-1-git-send-email-agraf@suse.de> X-Mailer: git-send-email 1.8.5.6 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 195.135.220.15 Subject: [Qemu-devel] [PATCH] input: Add trace events for polled keyboard input X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" When driving QEMU from the outside, we have basically no chance to determine how quickly the guest OS picks up key events, so we usually have to limit ourselves to very slow keyboard presses to make sure the guest always has enough chance to pick them up. This patch adds trace events for when the guest polls for HID keyboard events. That way we can be reasonably safely assume that the guest handled that one key event and can type the next. Signed-off-by: Alexander Graf --- hw/input/hid.c | 26 +++++++++++++++++++++++++- hw/input/trace-events | 2 ++ include/hw/input/hid.h | 6 ++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/hw/input/hid.c b/hw/input/hid.c index fa9cc4c..b68f597 100644 --- a/hw/input/hid.c +++ b/hw/input/hid.c @@ -228,7 +228,7 @@ static void hid_keyboard_event(DeviceState *dev, QemuCo= nsole *src, { HIDState *hs =3D (HIDState *)dev; int scancodes[3], i, count; - int slot; + int slot =3D -1; InputKeyEvent *key =3D evt->u.key.data; =20 count =3D qemu_input_key_value_to_scancode(key->key, @@ -241,6 +241,13 @@ static void hid_keyboard_event(DeviceState *dev, QemuC= onsole *src, for (i =3D 0; i < count; i++) { slot =3D (hs->head + hs->n) & QUEUE_MASK; hs->n++; hs->kbd.keycodes[slot] =3D scancodes[i]; + hs->kbd.poll_trigger[slot] =3D NULL; + } + + if (slot !=3D -1) { + hs->kbd.poll_trigger[slot] =3D g_new(HIDPollTrigger, 1); + hs->kbd.poll_trigger[slot]->key =3D *key->key; + hs->kbd.poll_trigger[slot]->down =3D key->down; } hs->event(hs); } @@ -256,6 +263,23 @@ static void hid_keyboard_process_keycode(HIDState *hs) slot =3D hs->head & QUEUE_MASK; QUEUE_INCR(hs->head); hs->n--; keycode =3D hs->kbd.keycodes[slot]; =20 + /* Trace polled key events */ + if (hs->kbd.poll_trigger[slot]) { + HIDPollTrigger *t =3D hs->kbd.poll_trigger[slot]; + switch (t->key.type) { + case KEY_VALUE_KIND_NUMBER: + trace_hid_kbd_key_nr_polled(t->key.u.number.data, t->down); + break; + case KEY_VALUE_KIND_QCODE: + trace_hid_kbd_key_qt_polled(t->key.u.qcode.data, t->down); + break; + default: + break; + } + g_free(t); + hs->kbd.poll_trigger[slot] =3D NULL; + } + key =3D keycode & 0x7f; index =3D key | ((hs->kbd.modifiers & (1 << 8)) >> 1); hid_code =3D hid_usage_keys[index]; diff --git a/hw/input/trace-events b/hw/input/trace-events index f3bfbed..7a6b5ff 100644 --- a/hw/input/trace-events +++ b/hw/input/trace-events @@ -24,6 +24,8 @@ milkymist_softusb_pulse_irq(void) "Pulse IRQ" =20 # hw/input/hid.c hid_kbd_queue_full(void) "queue full" +hid_kbd_key_nr_polled(uint64_t value, bool down) "val %#"PRIx64" down %d" +hid_kbd_key_qt_polled(uint64_t value, bool down) "val %#"PRIx64" down %d" =20 # hw/input/virtio virtio_input_queue_full(void) "queue full" diff --git a/include/hw/input/hid.h b/include/hw/input/hid.h index 2127c7c..ff9541e 100644 --- a/include/hw/input/hid.h +++ b/include/hw/input/hid.h @@ -25,8 +25,14 @@ typedef struct HIDMouseState { int mouse_grabbed; } HIDMouseState; =20 +typedef struct HIDPollTrigger { + KeyValue key; + bool down; +} HIDPollTrigger; + typedef struct HIDKeyboardState { uint32_t keycodes[QUEUE_LENGTH]; + HIDPollTrigger *poll_trigger[QUEUE_LENGTH]; uint16_t modifiers; uint8_t leds; uint8_t key[16]; --=20 1.8.5.6