From patchwork Thu Mar 30 13:35:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 745261 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vv5HN3jZnz9s1y for ; Fri, 31 Mar 2017 00:35:44 +1100 (AEDT) Received: from localhost ([::1]:35654 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ctaEn-0003z2-VM for incoming@patchwork.ozlabs.org; Thu, 30 Mar 2017 09:35:41 -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 X-Virus-Scanned: by amavisd-new at test-mx.suse.de 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) 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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, QemuConsole *src, { HIDState *hs = (HIDState *)dev; int scancodes[3], i, count; - int slot; + int slot = -1; InputKeyEvent *key = evt->u.key.data; count = qemu_input_key_value_to_scancode(key->key, @@ -241,6 +241,13 @@ static void hid_keyboard_event(DeviceState *dev, QemuConsole *src, for (i = 0; i < count; i++) { slot = (hs->head + hs->n) & QUEUE_MASK; hs->n++; hs->kbd.keycodes[slot] = scancodes[i]; + hs->kbd.poll_trigger[slot] = NULL; + } + + if (slot != -1) { + hs->kbd.poll_trigger[slot] = g_new(HIDPollTrigger, 1); + hs->kbd.poll_trigger[slot]->key = *key->key; + hs->kbd.poll_trigger[slot]->down = key->down; } hs->event(hs); } @@ -256,6 +263,23 @@ static void hid_keyboard_process_keycode(HIDState *hs) slot = hs->head & QUEUE_MASK; QUEUE_INCR(hs->head); hs->n--; keycode = hs->kbd.keycodes[slot]; + /* Trace polled key events */ + if (hs->kbd.poll_trigger[slot]) { + HIDPollTrigger *t = 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] = NULL; + } + key = keycode & 0x7f; index = key | ((hs->kbd.modifiers & (1 << 8)) >> 1); hid_code = 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" # 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" # 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; +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];