From: Pavel Dovgalyuk <Pavel.Dovgaluk@ispras.ru>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, peter.crosthwaite@xilinx.com,
igor.rubinov@gmail.com, alex.bennee@linaro.org,
mark.burton@greensocs.com, real@ispras.ru, batuzovk@ispras.ru,
maria.klimushenkova@ispras.ru, pavel.dovgaluk@ispras.ru,
pbonzini@redhat.com, hines@cert.org, fred.konrad@greensocs.com
Subject: [Qemu-devel] [PATCH v16 21/21] replay: recording of the user input
Date: Tue, 04 Aug 2015 11:45:48 +0300 [thread overview]
Message-ID: <20150804084548.7280.78947.stgit@PASHA-ISP> (raw)
In-Reply-To: <20150804084345.7280.75100.stgit@PASHA-ISP>
This records user input (keyboard and mouse events) in record mode and replays
these input events in replay mode.
Signed-off-by: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
---
include/ui/input.h | 2 +
replay/Makefile.objs | 1
replay/replay-events.c | 33 +++++++++
replay/replay-input.c | 160 ++++++++++++++++++++++++++++++++++++++++++++++
replay/replay-internal.h | 13 ++++
replay/replay.h | 4 +
stubs/replay.c | 10 +++
ui/input.c | 27 +++++---
8 files changed, 242 insertions(+), 8 deletions(-)
create mode 100755 replay/replay-input.c
diff --git a/include/ui/input.h b/include/ui/input.h
index 5d5ac00..d06a12d 100644
--- a/include/ui/input.h
+++ b/include/ui/input.h
@@ -33,7 +33,9 @@ void qemu_input_handler_bind(QemuInputHandlerState *s,
const char *device_id, int head,
Error **errp);
void qemu_input_event_send(QemuConsole *src, InputEvent *evt);
+void qemu_input_event_send_impl(QemuConsole *src, InputEvent *evt);
void qemu_input_event_sync(void);
+void qemu_input_event_sync_impl(void);
InputEvent *qemu_input_event_new_key(KeyValue *key, bool down);
void qemu_input_event_send_key(QemuConsole *src, KeyValue *key, bool down);
diff --git a/replay/Makefile.objs b/replay/Makefile.objs
index 257c320..3936296 100755
--- a/replay/Makefile.objs
+++ b/replay/Makefile.objs
@@ -2,3 +2,4 @@ obj-y += replay.o
obj-y += replay-internal.o
obj-y += replay-events.o
obj-y += replay-time.o
+obj-y += replay-input.o
diff --git a/replay/replay-events.c b/replay/replay-events.c
index 7910d87..8049450 100755
--- a/replay/replay-events.c
+++ b/replay/replay-events.c
@@ -14,6 +14,7 @@
#include "replay.h"
#include "replay-internal.h"
#include "block/aio.h"
+#include "ui/input.h"
typedef struct Event {
ReplayAsyncEventKind event_kind;
@@ -39,6 +40,13 @@ static void replay_run_event(Event *event)
case REPLAY_ASYNC_EVENT_PTIMER:
aio_bh_call(event->opaque);
break;
+ case REPLAY_ASYNC_EVENT_INPUT:
+ qemu_input_event_send_impl(NULL, (InputEvent *)event->opaque);
+ qapi_free_InputEvent((InputEvent *)event->opaque);
+ break;
+ case REPLAY_ASYNC_EVENT_INPUT_SYNC:
+ qemu_input_event_sync_impl();
+ break;
default:
error_report("Replay: invalid async event ID (%d) in the queue",
event->event_kind);
@@ -132,6 +140,16 @@ void replay_add_ptimer_event(void *bh, uint64_t id)
replay_add_event_internal(REPLAY_ASYNC_EVENT_PTIMER, bh, NULL, id);
}
+void replay_add_input_event(struct InputEvent *event)
+{
+ replay_add_event_internal(REPLAY_ASYNC_EVENT_INPUT, event, NULL, 0);
+}
+
+void replay_add_input_sync_event(void)
+{
+ replay_add_event_internal(REPLAY_ASYNC_EVENT_INPUT_SYNC, NULL, NULL, 0);
+}
+
static void replay_save_event(Event *event, int checkpoint)
{
if (replay_mode != REPLAY_MODE_PLAY) {
@@ -145,6 +163,11 @@ static void replay_save_event(Event *event, int checkpoint)
case REPLAY_ASYNC_EVENT_PTIMER:
replay_put_qword(event->id);
break;
+ case REPLAY_ASYNC_EVENT_INPUT:
+ replay_save_input_event(event->opaque);
+ break;
+ case REPLAY_ASYNC_EVENT_INPUT_SYNC:
+ break;
default:
error_report("Unknown ID %d of replay event", read_event_kind);
exit(1);
@@ -188,6 +211,16 @@ static Event *replay_read_event(int checkpoint)
read_id = replay_get_qword();
}
break;
+ case REPLAY_ASYNC_EVENT_INPUT:
+ event = g_malloc0(sizeof(Event));
+ event->event_kind = read_event_kind;
+ event->opaque = replay_read_input_event();
+ return event;
+ case REPLAY_ASYNC_EVENT_INPUT_SYNC:
+ event = g_malloc0(sizeof(Event));
+ event->event_kind = read_event_kind;
+ event->opaque = 0;
+ return event;
default:
error_report("Unknown ID %d of replay event", read_event_kind);
exit(1);
diff --git a/replay/replay-input.c b/replay/replay-input.c
new file mode 100755
index 0000000..bdb4db1
--- /dev/null
+++ b/replay/replay-input.c
@@ -0,0 +1,160 @@
+/*
+ * replay-input.c
+ *
+ * Copyright (c) 2010-2015 Institute for System Programming
+ * of the Russian Academy of Sciences.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#include "qemu-common.h"
+#include "replay.h"
+#include "replay-internal.h"
+#include "qemu/notify.h"
+#include "ui/input.h"
+#include "qapi/qmp-output-visitor.h"
+#include "qapi/qmp-input-visitor.h"
+#include "qapi-visit.h"
+
+static InputEvent *qapi_clone_InputEvent(InputEvent *src)
+{
+ QmpOutputVisitor *qov;
+ QmpInputVisitor *qiv;
+ Visitor *ov, *iv;
+ QObject *obj;
+ InputEvent *dst = NULL;
+
+ qov = qmp_output_visitor_new();
+ ov = qmp_output_get_visitor(qov);
+ visit_type_InputEvent(ov, &src, NULL, &error_abort);
+ obj = qmp_output_get_qobject(qov);
+ qmp_output_visitor_cleanup(qov);
+ if (!obj) {
+ return NULL;
+ }
+
+ qiv = qmp_input_visitor_new(obj);
+ iv = qmp_input_get_visitor(qiv);
+ visit_type_InputEvent(iv, &dst, NULL, &error_abort);
+ qmp_input_visitor_cleanup(qiv);
+ qobject_decref(obj);
+
+ return dst;
+}
+
+void replay_save_input_event(InputEvent *evt)
+{
+ replay_put_dword(evt->kind);
+
+ switch (evt->kind) {
+ case INPUT_EVENT_KIND_KEY:
+ replay_put_dword(evt->key->key->kind);
+
+ switch (evt->key->key->kind) {
+ case KEY_VALUE_KIND_NUMBER:
+ replay_put_qword(evt->key->key->number);
+ replay_put_byte(evt->key->down);
+ break;
+ case KEY_VALUE_KIND_QCODE:
+ replay_put_dword(evt->key->key->qcode);
+ replay_put_byte(evt->key->down);
+ break;
+ case KEY_VALUE_KIND_MAX:
+ /* keep gcc happy */
+ break;
+ }
+ break;
+ case INPUT_EVENT_KIND_BTN:
+ replay_put_dword(evt->btn->button);
+ replay_put_byte(evt->btn->down);
+ break;
+ case INPUT_EVENT_KIND_REL:
+ replay_put_dword(evt->rel->axis);
+ replay_put_qword(evt->rel->value);
+ break;
+ case INPUT_EVENT_KIND_ABS:
+ replay_put_dword(evt->abs->axis);
+ replay_put_qword(evt->abs->value);
+ break;
+ case INPUT_EVENT_KIND_MAX:
+ /* keep gcc happy */
+ break;
+ }
+}
+
+InputEvent *replay_read_input_event(void)
+{
+ InputEvent evt;
+ KeyValue keyValue;
+ InputKeyEvent key;
+ key.key = &keyValue;
+ InputBtnEvent btn;
+ InputMoveEvent rel;
+ InputMoveEvent abs;
+
+ evt.kind = replay_get_dword();
+ switch (evt.kind) {
+ case INPUT_EVENT_KIND_KEY:
+ evt.key = &key;
+ evt.key->key->kind = replay_get_dword();
+
+ switch (evt.key->key->kind) {
+ case KEY_VALUE_KIND_NUMBER:
+ evt.key->key->number = replay_get_qword();
+ evt.key->down = replay_get_byte();
+ break;
+ case KEY_VALUE_KIND_QCODE:
+ evt.key->key->qcode = (QKeyCode)replay_get_dword();
+ evt.key->down = replay_get_byte();
+ break;
+ case KEY_VALUE_KIND_MAX:
+ /* keep gcc happy */
+ break;
+ }
+ break;
+ case INPUT_EVENT_KIND_BTN:
+ evt.btn = &btn;
+ evt.btn->button = (InputButton)replay_get_dword();
+ evt.btn->down = replay_get_byte();
+ break;
+ case INPUT_EVENT_KIND_REL:
+ evt.rel = &rel;
+ evt.rel->axis = (InputAxis)replay_get_dword();
+ evt.rel->value = replay_get_qword();
+ break;
+ case INPUT_EVENT_KIND_ABS:
+ evt.abs = &abs;
+ evt.abs->axis = (InputAxis)replay_get_dword();
+ evt.abs->value = replay_get_qword();
+ break;
+ case INPUT_EVENT_KIND_MAX:
+ /* keep gcc happy */
+ break;
+ }
+
+ return qapi_clone_InputEvent(&evt);
+}
+
+void replay_input_event(QemuConsole *src, InputEvent *evt)
+{
+ if (replay_mode == REPLAY_MODE_PLAY) {
+ /* Nothing */
+ } else if (replay_mode == REPLAY_MODE_RECORD) {
+ replay_add_input_event(qapi_clone_InputEvent(evt));
+ } else {
+ qemu_input_event_send_impl(src, evt);
+ }
+}
+
+void replay_input_sync_event(void)
+{
+ if (replay_mode == REPLAY_MODE_PLAY) {
+ /* Nothing */
+ } else if (replay_mode == REPLAY_MODE_RECORD) {
+ replay_add_input_sync_event();
+ } else {
+ qemu_input_event_sync_impl();
+ }
+}
diff --git a/replay/replay-internal.h b/replay/replay-internal.h
index 36a6fd8..5e2e056 100755
--- a/replay/replay-internal.h
+++ b/replay/replay-internal.h
@@ -42,6 +42,8 @@ enum ReplayEvents {
enum ReplayAsyncEventKind {
REPLAY_ASYNC_EVENT_PTIMER,
+ REPLAY_ASYNC_EVENT_INPUT,
+ REPLAY_ASYNC_EVENT_INPUT_SYNC,
REPLAY_ASYNC_COUNT
};
@@ -126,4 +128,15 @@ void replay_read_events(int checkpoint);
/*! Adds specified async event to the queue */
void replay_add_event(ReplayAsyncEventKind event_id, void *opaque);
+/* Input events */
+
+/*! Saves input event to the log */
+void replay_save_input_event(InputEvent *evt);
+/*! Reads input event from the log */
+InputEvent *replay_read_input_event(void);
+/*! Adds input event to the queue */
+void replay_add_input_event(struct InputEvent *event);
+/*! Adds input sync event to the queue */
+void replay_add_input_sync_event(void);
+
#endif
diff --git a/replay/replay.h b/replay/replay.h
index 9f6f288..db0bf82 100755
--- a/replay/replay.h
+++ b/replay/replay.h
@@ -111,5 +111,9 @@ void replay_disable_events(void);
bool replay_events_enabled(void);
/*! Adds ptimer event to the queue */
void replay_add_ptimer_event(void *bh, uint64_t id);
+/*! Adds input event to the queue */
+void replay_input_event(QemuConsole *src, InputEvent *evt);
+/*! Adds input sync event to the queue */
+void replay_input_sync_event(void);
#endif
diff --git a/stubs/replay.c b/stubs/replay.c
index 782532e..d6a6e5f 100755
--- a/stubs/replay.c
+++ b/stubs/replay.c
@@ -1,5 +1,7 @@
#include "replay/replay.h"
#include "sysemu/sysemu.h"
+#include "qemu/notify.h"
+#include "ui/input.h"
ReplayMode replay_mode;
@@ -36,3 +38,11 @@ bool replay_events_enabled(void)
{
return false;
}
+
+void qemu_input_event_send_impl(QemuConsole *src, InputEvent *evt)
+{
+}
+
+void qemu_input_event_sync_impl(void)
+{
+}
diff --git a/ui/input.c b/ui/input.c
index 1a552d1..9939722 100644
--- a/ui/input.c
+++ b/ui/input.c
@@ -6,6 +6,7 @@
#include "trace.h"
#include "ui/input.h"
#include "ui/console.h"
+#include "replay/replay.h"
struct QemuInputHandlerState {
DeviceState *dev;
@@ -300,14 +301,10 @@ static void qemu_input_queue_sync(struct QemuInputEventQueueHead *queue)
QTAILQ_INSERT_TAIL(queue, item, node);
}
-void qemu_input_event_send(QemuConsole *src, InputEvent *evt)
+void qemu_input_event_send_impl(QemuConsole *src, InputEvent *evt)
{
QemuInputHandlerState *s;
- if (!runstate_is_running() && !runstate_check(RUN_STATE_SUSPENDED)) {
- return;
- }
-
qemu_input_event_trace(src, evt);
/* pre processing */
@@ -324,14 +321,19 @@ void qemu_input_event_send(QemuConsole *src, InputEvent *evt)
s->events++;
}
-void qemu_input_event_sync(void)
+void qemu_input_event_send(QemuConsole *src, InputEvent *evt)
{
- QemuInputHandlerState *s;
-
if (!runstate_is_running() && !runstate_check(RUN_STATE_SUSPENDED)) {
return;
}
+ replay_input_event(src, evt);
+}
+
+void qemu_input_event_sync_impl(void)
+{
+ QemuInputHandlerState *s;
+
trace_input_event_sync();
QTAILQ_FOREACH(s, &handlers, node) {
@@ -345,6 +347,15 @@ void qemu_input_event_sync(void)
}
}
+void qemu_input_event_sync(void)
+{
+ if (!runstate_is_running() && !runstate_check(RUN_STATE_SUSPENDED)) {
+ return;
+ }
+
+ replay_input_sync_event();
+}
+
InputEvent *qemu_input_event_new_key(KeyValue *key, bool down)
{
InputEvent *evt = g_new0(InputEvent, 1);
next prev parent reply other threads:[~2015-08-04 8:45 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-04 8:43 [Qemu-devel] [PATCH v16 00/21] Deterministic replay core Pavel Dovgalyuk
2015-08-04 8:43 ` [Qemu-devel] [PATCH v16 01/21] i386: partial revert of interrupt poll fix Pavel Dovgalyuk
2015-08-04 8:44 ` [Qemu-devel] [PATCH v16 02/21] replay: global variables and function stubs Pavel Dovgalyuk
2015-08-04 8:44 ` [Qemu-devel] [PATCH v16 03/21] sysemu: system functions for replay Pavel Dovgalyuk
2015-08-04 8:44 ` [Qemu-devel] [PATCH v16 04/21] replay: internal functions for replay log Pavel Dovgalyuk
2015-08-04 8:44 ` [Qemu-devel] [PATCH v16 05/21] replay: introduce mutex to protect the " Pavel Dovgalyuk
2015-08-04 8:44 ` [Qemu-devel] [PATCH v16 06/21] replay: introduce icount event Pavel Dovgalyuk
2015-08-04 8:44 ` [Qemu-devel] [PATCH v16 07/21] cpu-exec: allow temporary disabling icount Pavel Dovgalyuk
2015-08-04 8:44 ` [Qemu-devel] [PATCH v16 08/21] cpu: replay instructions sequence Pavel Dovgalyuk
2015-08-04 8:44 ` [Qemu-devel] [PATCH v16 09/21] i386: interrupt poll processing Pavel Dovgalyuk
2015-08-04 8:44 ` [Qemu-devel] [PATCH v16 10/21] replay: interrupts and exceptions Pavel Dovgalyuk
2015-08-04 8:44 ` [Qemu-devel] [PATCH v16 11/21] replay: asynchronous events infrastructure Pavel Dovgalyuk
2015-08-04 8:44 ` [Qemu-devel] [PATCH v16 12/21] replay: recording and replaying clock ticks Pavel Dovgalyuk
2015-08-04 8:45 ` [Qemu-devel] [PATCH v16 13/21] replay: shutdown event Pavel Dovgalyuk
2015-08-04 8:45 ` [Qemu-devel] [PATCH v16 14/21] replay: checkpoints Pavel Dovgalyuk
2015-08-04 8:45 ` [Qemu-devel] [PATCH v16 15/21] bottom halves: introduce bh call function Pavel Dovgalyuk
2015-08-04 8:45 ` [Qemu-devel] [PATCH v16 16/21] replay: ptimer Pavel Dovgalyuk
2015-08-04 8:45 ` [Qemu-devel] [PATCH v16 17/21] typedef: add typedef for QemuOpts Pavel Dovgalyuk
2015-08-04 8:45 ` [Qemu-devel] [PATCH v16 18/21] replay: initialization and deinitialization Pavel Dovgalyuk
2015-08-04 8:45 ` [Qemu-devel] [PATCH v16 19/21] replay: replay blockers for devices Pavel Dovgalyuk
2015-08-04 8:45 ` [Qemu-devel] [PATCH v16 20/21] replay: command line options Pavel Dovgalyuk
2015-08-04 8:45 ` Pavel Dovgalyuk [this message]
2015-08-15 9:57 ` [Qemu-devel] [PATCH v16 00/21] Deterministic replay core Pavel Dovgalyuk
2015-08-15 10:03 ` Paolo Bonzini
2015-08-17 11:14 ` Paolo Bonzini
2015-08-27 13:04 ` Pavel Dovgaluk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150804084548.7280.78947.stgit@PASHA-ISP \
--to=pavel.dovgaluk@ispras.ru \
--cc=alex.bennee@linaro.org \
--cc=batuzovk@ispras.ru \
--cc=fred.konrad@greensocs.com \
--cc=hines@cert.org \
--cc=igor.rubinov@gmail.com \
--cc=maria.klimushenkova@ispras.ru \
--cc=mark.burton@greensocs.com \
--cc=pbonzini@redhat.com \
--cc=peter.crosthwaite@xilinx.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=real@ispras.ru \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.