Skip to contentSkip to conversation

hid: handle full ptr queues in post_load

RFC PATCH In review Gerd Hoffmann 2 participants 7 messages Nov 27, 2014

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 hid: handle full ptr queues in post_load

Cc Gonglei <[email protected]>
Cc Dr. David Alan Gilbert <[email protected]>
---
 hw/input/hid.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
hw/input/hid.c +21 -0
index 8f6fbb3..6fb963f 100644
@@ -519,6 +519,27 @@ static int hid_post_load(void *opaque, int version_id)
     HIDState *s = opaque;
 
     hid_set_next_idle(s);
+
+    if (s->n == QUEUE_LENGTH && (s->kind == HID_TABLET ||
+                                 s->kind == HID_MOUSE)) {
+        /*
+         * Handle ptr device migration from old qemu with full queue.
+         *
+         * Throw away everything but the last event, so we propagate
+         * at least the current button state to the guest.  Also keep
+         * current position for the tablet, signal "no motion" for the
+         * mouse.
+         */
+        HIDPointerEvent evt;
+        evt = s->ptr.queue[(s->head+s->n) & QUEUE_MASK];
+        if (s->kind == HID_MOUSE) {
+            evt.xdx = 0;
+            evt.ydy = 0;
+        }
+        s->ptr.queue[0] = evt;
+        s->head = 0;
+        s->n = 1;
+    }
     return 0;
 }
 
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 18 lines · Gerd Hoffmann
Cc Gonglei <[email protected]>
Cc Dr. David Alan Gilbert <[email protected]>
---
 hw/input/hid.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
hw/input/hid.c +3 -0
index 8f6fbb3..6fb963f 100644
@@ -519,6 +519,27 @@ static int hid_post_load(void *opaque, int version_id)
     HIDState *s = opaque;
 
     hid_set_next_idle(s);
+
+    if (s->n == QUEUE_LENGTH && (s->kind == HID_TABLET ||
+                                 s->kind == HID_MOUSE)) {

hw/input/hid.c static int hid_post_load(void *opaque, int version_id) · line 534

Quoted 10 lines
hw/input/hid.c +10 -0
+        /*
+         * Handle ptr device migration from old qemu with full queue.
+         *
+         * Throw away everything but the last event, so we propagate
+         * at least the current button state to the guest.  Also keep
+         * current position for the tablet, signal "no motion" for the
+         * mouse.
+         */
+        HIDPointerEvent evt;
+        evt = s->ptr.queue[(s->head+s->n) & QUEUE_MASK];

s->n is QUEUE_LENGTH, can we directly delete it?
evt = s->ptr.queue[s->head & QUEUE_MASK]

Best regards,
-Gonglei

Quoted 11 lines
hw/input/hid.c +8 -0
+        if (s->kind == HID_MOUSE) {
+            evt.xdx = 0;
+            evt.ydy = 0;
+        }
+        s->ptr.queue[0] = evt;
+        s->head = 0;
+        s->n = 1;
+    }
     return 0;
 }
 
#2 lore raw

Hi,

Quoted 4 lines
Quoted 1 line

+ evt = s->ptr.queue[(s->head+s->n) & QUEUE_MASK];

s->n is QUEUE_LENGTH, can we directly delete it?
evt = s->ptr.queue[s->head & QUEUE_MASK]

I prefer to make clear in the code that we want the last ring element not the first and leave in the "+n", even if we could take it out.

cheers,
Gerd

#3 lore raw
Quoted 10 lines · Gerd Hoffmann

Hi,

Quoted 4 lines
Quoted 1 line

+ evt = s->ptr.queue[(s->head+s->n) & QUEUE_MASK];

s->n is QUEUE_LENGTH, can we directly delete it?
evt = s->ptr.queue[s->head & QUEUE_MASK]

I prefer to make clear in the code that we want the last ring element not the first and leave in the "+n", even if we could take it out.

OK.

Another question, whether or not we handle this scenario before calling hid_set_next_idle(s) ? Maybe it is safer, because hid_idle_timer will call hid_pointer_event(), callback function of hs->event(hs).

Thanks,
-Gonglei

#4 lore raw
Quoted 12 lines · Gonglei
Quoted 10 lines · Gerd Hoffmann

Hi,

Quoted 4 lines
Quoted 1 line

+ evt = s->ptr.queue[(s->head+s->n) & QUEUE_MASK];

s->n is QUEUE_LENGTH, can we directly delete it?
evt = s->ptr.queue[s->head & QUEUE_MASK]

I prefer to make clear in the code that we want the last ring element not the first and leave in the "+n", even if we could take it out.

Quoted 6 lines

OK.

Another question, whether or not we handle this scenario before calling hid_set_next_idle(s) ? Maybe it is safer, because hid_idle_timer will call hid_pointer_event(), callback function of hs->event(hs).

Not needed, the timer will not called before vmload is completely finished.

cheers,
Gerd

#5 lore raw
Quoted 15 lines · Gerd Hoffmann
Quoted 14 lines · Gonglei
Quoted 10 lines · Gerd Hoffmann

Hi,

Quoted 4 lines
Quoted 1 line

+ evt = s->ptr.queue[(s->head+s->n) & QUEUE_MASK];

s->n is QUEUE_LENGTH, can we directly delete it?
evt = s->ptr.queue[s->head & QUEUE_MASK]

I prefer to make clear in the code that we want the last ring element not the first and leave in the "+n", even if we could take it out.

OK.

Quoted 8 lines
Quoted 4 lines

Another question, whether or not we handle this scenario before calling hid_set_next_idle(s) ? Maybe it is safer, because hid_idle_timer will call hid_pointer_event(), callback function of hs->event(hs).

Not needed, the timer will not called before vmload is completely finished.

Yep, as the Qemu big lock.
I will test this patch later, thanks for your work. :)

Regards,
-Gonglei

Tested-by Reviewed-by
#6 lore raw
Quoted 22 lines · Gonglei
Quoted 20 lines · Gerd Hoffmann
Quoted 18 lines · Gonglei
Quoted 10 lines · Gerd Hoffmann

Hi,

Quoted 4 lines
Quoted 1 line

+ evt = s->ptr.queue[(s->head+s->n) & QUEUE_MASK];

s->n is QUEUE_LENGTH, can we directly delete it?
evt = s->ptr.queue[s->head & QUEUE_MASK]

I prefer to make clear in the code that we want the last ring element not the first and leave in the "+n", even if we could take it out.

OK.

Another question, whether or not we handle this scenario before calling hid_set_next_idle(s) ? Maybe it is safer, because hid_idle_timer will call hid_pointer_event(), callback function of hs->event(hs).

Quoted 7 lines
Quoted 3 lines

Not needed, the timer will not called before vmload is completely finished.

Yep, as the Qemu big lock.
I will test this patch later, thanks for your work. :)

Patch works for me. Thanks.

Regards,
-Gonglei