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: 9654235 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6F73860113 for ; Thu, 30 Mar 2017 13:36:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5DA6C28304 for ; Thu, 30 Mar 2017 13:36:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 51735283E1; Thu, 30 Mar 2017 13:36:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BB79D26E39 for ; Thu, 30 Mar 2017 13:35:59 +0000 (UTC) Received: from localhost ([::1]:35654 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ctaF4-0003z2-Ti for patchwork-qemu-devel@patchwork.kernel.org; Thu, 30 Mar 2017 09:35:58 -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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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];