Skip to contentSkip to conversation

Make char muxer more robust wrt small FIFOs

PATCH RESEND In review Alexander Graf 4 participants 21 messages Apr 20, 2010 – May 15, 2010

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 Make char muxer more robust wrt small FIFOs

Virtio-Console can only process one character at a time. Using it on S390 gave me strage "lags" where I got the character I pressed before when pressing one. So I typed in "abc" and only received "a", then pressed "d" but the guest received "b" and so on.

While the stdio driver calls a poll function that just processes on its queue in case virtio-console can't take multiple characters at once, the muxer does not have such callbacks, so it can't empty its queue.

To work around that limitation, I introduced a new timer that only gets active when the guest can not receive any more characters. In that case it polls again after a while to check if the guest is now receiving input.

This patch fixes input when using -nographic on s390 for me.

---

Please consider for stable.

---
 qemu-char.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
qemu-char.c +10 -0
index 05df971..ce9df3a 100644
@@ -235,6 +235,7 @@ typedef struct {
     IOEventHandler *chr_event[MAX_MUX];
     void *ext_opaque[MAX_MUX];
     CharDriverState *drv;
+    QEMUTimer *accept_timer;
     int focus;
     int mux_cnt;
     int term_got_escape;
@@ -396,6 +397,13 @@ static void mux_chr_accept_input(CharDriverState *chr)
         d->chr_read[m](d->ext_opaque[m],
                        &d->buffer[m][d->cons[m]++ & MUX_BUFFER_MASK], 1);
     }
+
+    /* We're still not able to sync producer and consumer, so let's wait a bit
+       and try again by then. */
+    if (d->prod[m] != d->cons[m]) {
+        qemu_mod_timer(d->accept_timer, qemu_get_clock(vm_clock)
+                                        + (int64_t)100000);
+    }
 }
 
 static int mux_chr_can_read(void *opaque)
@@ -478,6 +486,8 @@ static CharDriverState *qemu_chr_open_mux(CharDriverState *drv)
     chr->opaque = d;
     d->drv = drv;
     d->focus = -1;
+    d->accept_timer = qemu_new_timer(vm_clock,
+                                     (QEMUTimerCB*)mux_chr_accept_input, chr);
     chr->chr_write = mux_chr_write;
     chr->chr_update_read_handler = mux_chr_update_read_handler;
     chr->chr_accept_input = mux_chr_accept_input;
Signature · 1 line
1.6.0.2
#1 lore raw
Quoted 9 lines · Alexander Graf

Virtio-Console can only process one character at a time. Using it on S390 gave me strage "lags" where I got the character I pressed before when pressing one. So I typed in "abc" and only received "a", then pressed "d" but the guest received "b" and so on.

While the stdio driver calls a poll function that just processes on its queue in case virtio-console can't take multiple characters at once, the muxer does not have such callbacks, so it can't empty its queue.

Quoted 6 lines

To work around that limitation, I introduced a new timer that only gets active when the guest can not receive any more characters. In that case it polls again after a while to check if the guest is now receiving input.

This patch fixes input when using -nographic on s390 for me.

I think this is really a kvm issue. I assume it's because s390 idles in the kernel so you never drop to userspace to repoll the descriptor.

A timer is a hacky solution. You really need to use an io thread to solve this and then you need to switch away from qemu_set_fd_handler2 to qemu_set_fd_handler() and make sure that the later breaks select whenever it's invoked.

Regards,

Anthony Liguori

Quoted 43 lines

---

Please consider for stable.

---
  qemu-char.c |   10 ++++++++++
  1 files changed, 10 insertions(+), 0 deletions(-)
qemu-char.c +10 -0
index 05df971..ce9df3a 100644
@@ -235,6 +235,7 @@ typedef struct {
      IOEventHandler *chr_event[MAX_MUX];
      void *ext_opaque[MAX_MUX];
      CharDriverState *drv;
+    QEMUTimer *accept_timer;
      int focus;
      int mux_cnt;
      int term_got_escape;
@@ -396,6 +397,13 @@ static void mux_chr_accept_input(CharDriverState *chr)
          d->chr_read[m](d->ext_opaque[m],
                         &d->buffer[m][d->cons[m]++&  MUX_BUFFER_MASK], 1);
      }
+
+    /* We're still not able to sync producer and consumer, so let's wait a bit
+       and try again by then. */
+    if (d->prod[m] != d->cons[m]) {
+        qemu_mod_timer(d->accept_timer, qemu_get_clock(vm_clock)
+                                        + (int64_t)100000);
+    }
  }
 
  static int mux_chr_can_read(void *opaque)
@@ -478,6 +486,8 @@ static CharDriverState *qemu_chr_open_mux(CharDriverState *drv)
      chr->opaque = d;
      d->drv = drv;
      d->focus = -1;
+    d->accept_timer = qemu_new_timer(vm_clock,
+                                     (QEMUTimerCB*)mux_chr_accept_input, chr);
      chr->chr_write = mux_chr_write;
      chr->chr_update_read_handler = mux_chr_update_read_handler;
      chr->chr_accept_input = mux_chr_accept_input;
#2 lore raw

Am 04.05.2010 um 15:44 schrieb Anthony Liguori <[email protected]>:

Quoted 10 lines · Alexander Graf
Quoted 9 lines

Virtio-Console can only process one character at a time. Using it on S390 gave me strage "lags" where I got the character I pressed before when pressing one. So I typed in "abc" and only received "a", then pressed "d" but the guest received "b" and so on.

While the stdio driver calls a poll function that just processes on its queue in case virtio-console can't take multiple characters at once, the muxer does not have such callbacks, so it can't empty its queue.

Quoted 8 lines
Quoted 6 lines

To work around that limitation, I introduced a new timer that only gets active when the guest can not receive any more characters. In that case it polls again after a while to check if the guest is now receiving input.

This patch fixes input when using -nographic on s390 for me.

I think this is really a kvm issue. I assume it's because s390 idles in the kernel so you never drop to userspace to repoll the descriptor.

There is no polling for the muxer. That's why it never knows when virtio-console can receive again.

This patch basically adfs timer based polling for that exact case.

Alex

Quoted 56 lines

A timer is a hacky solution. You really need to use an io thread to solve this and then you need to switch away from qemu_set_fd_handler2 to qemu_set_fd_handler() and make sure that the later breaks select whenever it's invoked.

Regards,

Anthony Liguori

Quoted 48 lines

---

Please consider for stable.

---
 qemu-char.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
qemu-char.c +3 -0
index 05df971..ce9df3a 100644
@@ -235,6 +235,7 @@ typedef struct {
     IOEventHandler *chr_event[MAX_MUX];
     void *ext_opaque[MAX_MUX];
     CharDriverState *drv;
+    QEMUTimer *accept_timer;
     int focus;
     int mux_cnt;
     int term_got_escape;
@@ -396,6 +397,13 @@ static void mux_chr_accept_input 
 (CharDriverState *chr)
         d->chr_read[m](d->ext_opaque[m],
                        &d->buffer[m][d->cons[m]++&   
 MUX_BUFFER_MASK], 1);
     }
+
+    /* We're still not able to sync producer and consumer, so  

let's wait a bit

qemu-char.c +7 -0
+       and try again by then. */
+    if (d->prod[m] != d->cons[m]) {
+        qemu_mod_timer(d->accept_timer, qemu_get_clock(vm_clock)
+                                        + (int64_t)100000);
+    }
 }
 
 static int mux_chr_can_read(void *opaque)
@@ -478,6 +486,8 @@ static CharDriverState *qemu_chr_open_mux 
 (CharDriverState *drv)
     chr->opaque = d;
     d->drv = drv;
     d->focus = -1;
+    d->accept_timer = qemu_new_timer(vm_clock,
+                                     (QEMUTimerCB*) 
 mux_chr_accept_input, chr);
     chr->chr_write = mux_chr_write;
     chr->chr_update_read_handler = mux_chr_update_read_handler;
     chr->chr_accept_input = mux_chr_accept_input;
#3 lore raw
Quoted 18 lines · Alexander Graf

Am 04.05.2010 um 15:44 schrieb Anthony Liguori <[email protected]>:

Quoted 14 lines · Alexander Graf
Quoted 13 lines

Virtio-Console can only process one character at a time. Using it on S390 gave me strage "lags" where I got the character I pressed before when pressing one. So I typed in "abc" and only received "a", then pressed "d" but the guest received "b" and so on.

While the stdio driver calls a poll function that just processes on its queue in case virtio-console can't take multiple characters at once, the muxer does not have such callbacks, so it can't empty its queue.

To work around that limitation, I introduced a new timer that only gets active when the guest can not receive any more characters. In that case it polls again after a while to check if the guest is now receiving input.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

This patch fixes input when using -nographic on s390 for me.

I think this is really a kvm issue. I assume it's because s390 idles in the kernel so you never drop to userspace to repoll the descriptor.

There is no polling for the muxer. That's why it never knows when virtio-console can receive again.

Maybe I'm missing something simple, but it looks to me like the muxer is polling. mux_chr_can_read() is going to eventually poll the muxed devices to figure this out.

If the root of the problem is that mux_chr_can_read() isn't being invoked for a prolonged period of time, the real issue is the problem I described.

Regards,

Anthony Liguori

Quoted 60 lines

This patch basically adfs timer based polling for that exact case.

Alex

Quoted 55 lines

A timer is a hacky solution. You really need to use an io thread to solve this and then you need to switch away from qemu_set_fd_handler2 to qemu_set_fd_handler() and make sure that the later breaks select whenever it's invoked.

Regards,

Anthony Liguori

Quoted 47 lines

---

Please consider for stable.

---
 qemu-char.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
qemu-char.c +3 -0
index 05df971..ce9df3a 100644
@@ -235,6 +235,7 @@ typedef struct {
     IOEventHandler *chr_event[MAX_MUX];
     void *ext_opaque[MAX_MUX];
     CharDriverState *drv;
+    QEMUTimer *accept_timer;
     int focus;
     int mux_cnt;
     int term_got_escape;
@@ -396,6 +397,13 @@ static void 
 mux_chr_accept_input(CharDriverState *chr)
         d->chr_read[m](d->ext_opaque[m],
 &d->buffer[m][d->cons[m]++&  MUX_BUFFER_MASK], 1);
     }
+
+    /* We're still not able to sync producer and consumer, so let's 

wait a bit

qemu-char.c +7 -0
+       and try again by then. */
+    if (d->prod[m] != d->cons[m]) {
+        qemu_mod_timer(d->accept_timer, qemu_get_clock(vm_clock)
+                                        + (int64_t)100000);
+    }
 }
 
 static int mux_chr_can_read(void *opaque)
@@ -478,6 +486,8 @@ static CharDriverState 
 *qemu_chr_open_mux(CharDriverState *drv)
     chr->opaque = d;
     d->drv = drv;
     d->focus = -1;
+    d->accept_timer = qemu_new_timer(vm_clock,
+                                     
 (QEMUTimerCB*)mux_chr_accept_input, chr);
     chr->chr_write = mux_chr_write;
     chr->chr_update_read_handler = mux_chr_update_read_handler;
     chr->chr_accept_input = mux_chr_accept_input;
#4 lore raw

Am 04.05.2010 um 16:34 schrieb Anthony Liguori <[email protected]>:

Quoted 22 lines · Alexander Graf
Quoted 21 lines

Am 04.05.2010 um 15:44 schrieb Anthony Liguori <[email protected]>:

Quoted 17 lines · Alexander Graf
Quoted 15 lines

Virtio-Console can only process one character at a time. Using it on S390 gave me strage "lags" where I got the character I pressed before when pressing one. So I typed in "abc" and only received "a", then pressed "d" but the guest received "b" and so on.

While the stdio driver calls a poll function that just processes on its queue in case virtio-console can't take multiple characters at once, the muxer does not have such callbacks, so it can't empty its queue.

To work around that limitation, I introduced a new timer that only gets active when the guest can not receive any more characters. In that case it polls again after a while to check if the guest is now receiving input.

This patch fixes input when using -nographic on s390 for me.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

I think this is really a kvm issue. I assume it's because s390 idles in the kernel so you never drop to userspace to repoll the descriptor.

There is no polling for the muxer. That's why it never knows when virtio-console can receive again.

Maybe I'm missing something simple, but it looks to me like the muxer is polling. mux_chr_can_read() is going to eventually poll the muxed devices to figure this out.

If the root of the problem is that mux_chr_can_read() isn't being invoked for a prolonged period of time, the real issue is the problem I described.

The problem is that the select list of fds includes the stdio fd, so that gets notified and is coupled with virtio-console, but there's nothing passing that on to mux and I don't think it'd be clever to expose internal data to the muxer to tell it about the backend fds.

Alex

Quoted 66 lines

Regards,

Anthony Liguori

Quoted 60 lines

This patch basically adfs timer based polling for that exact case.

Alex

Quoted 55 lines

A timer is a hacky solution. You really need to use an io thread to solve this and then you need to switch away from qemu_set_fd_handler2 to qemu_set_fd_handler() and make sure that the later breaks select whenever it's invoked.

Regards,

Anthony Liguori

Quoted 47 lines

---

Please consider for stable.
---
qemu-char.c | 10 ++++++++++

1 files changed, 10 insertions(+), 0 deletions(-)
qemu-char.c +3 -0
index 05df971..ce9df3a 100644
@@ -235,6 +235,7 @@ typedef struct {
    IOEventHandler *chr_event[MAX_MUX];
    void *ext_opaque[MAX_MUX];
    CharDriverState *drv;
+    QEMUTimer *accept_timer;
    int focus;
    int mux_cnt;
    int term_got_escape;
@@ -396,6 +397,13 @@ static void mux_chr_accept_input 
 (CharDriverState *chr)
        d->chr_read[m](d->ext_opaque[m],
 &d->buffer[m][d->cons[m]++&  MUX_BUFFER_MASK], 1);
    }
+
+    /* We're still not able to sync producer and consumer, so  

let's wait a bit

qemu-char.c +5 -0
+       and try again by then. */
+    if (d->prod[m] != d->cons[m]) {
+        qemu_mod_timer(d->accept_timer, qemu_get_clock(vm_clock)
+                                        + (int64_t)100000);
+    }

}

static int mux_chr_can_read(void *opaque)

qemu-char.c +2 -0
@@ -478,6 +486,8 @@ static CharDriverState *qemu_chr_open_mux 
 (CharDriverState *drv)
    chr->opaque = d;
    d->drv = drv;
    d->focus = -1;
+    d->accept_timer = qemu_new_timer(vm_clock,
+                                     (QEMUTimerCB*) 
 mux_chr_accept_input, chr);
    chr->chr_write = mux_chr_write;
    chr->chr_update_read_handler = mux_chr_update_read_handler;
    chr->chr_accept_input = mux_chr_accept_input;
#5 lore raw
Quoted 27 lines · Alexander Graf

Am 04.05.2010 um 16:34 schrieb Anthony Liguori <[email protected]>:

Quoted 24 lines · Alexander Graf
Quoted 23 lines

Am 04.05.2010 um 15:44 schrieb Anthony Liguori <[email protected]>:

Quoted 18 lines · Alexander Graf
Quoted 9 lines

Virtio-Console can only process one character at a time. Using it on S390 gave me strage "lags" where I got the character I pressed before when pressing one. So I typed in "abc" and only received "a", then pressed "d" but the guest received "b" and so on.

While the stdio driver calls a poll function that just processes on its queue in case virtio-console can't take multiple characters at once, the muxer does not have such callbacks, so it can't empty its queue.

Quoted 6 lines

To work around that limitation, I introduced a new timer that only gets active when the guest can not receive any more characters. In that case it polls again after a while to check if the guest is now receiving input.

This patch fixes input when using -nographic on s390 for me.

I think this is really a kvm issue. I assume it's because s390 idles in the kernel so you never drop to userspace to repoll the descriptor.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

There is no polling for the muxer. That's why it never knows when virtio-console can receive again.

Maybe I'm missing something simple, but it looks to me like the muxer is polling. mux_chr_can_read() is going to eventually poll the muxed devices to figure this out.

If the root of the problem is that mux_chr_can_read() isn't being invoked for a prolonged period of time, the real issue is the problem I described.

The problem is that the select list of fds includes the stdio fd, so that gets notified and is coupled with virtio-console, but there's nothing passing that on to mux and I don't think it'd be clever to expose internal data to the muxer to tell it about the backend fds.

When stdio is readable, it should invoke qemu_chr_read() with the read data which in turn ought to invoke mux_chr_read().

I'm not sure I understand what signalling is missing. Jan, does the problem Alex describes ring a bell? I seem to recall you saying that mux was still fundamentally broken but ought to work most of the time...

Regards,

Anthony Liguori

Quoted 1 line

Alex

#6 lore raw
Quoted 47 lines · Anthony Liguori
Quoted 38 lines · Alexander Graf

Am 04.05.2010 um 16:34 schrieb Anthony Liguori <[email protected]>:

Quoted 36 lines · Alexander Graf
Quoted 24 lines

Am 04.05.2010 um 15:44 schrieb Anthony Liguori <[email protected]>:

Quoted 21 lines · Alexander Graf
Quoted 20 lines

Virtio-Console can only process one character at a time. Using it on S390
gave me strage "lags" where I got the character I pressed before when pressing one. So I typed in "abc" and only received "a", then pressed "d"
but the guest received "b" and so on.

While the stdio driver calls a poll function that just processes on its
queue in case virtio-console can't take multiple characters at once, the
muxer does not have such callbacks, so it can't empty its queue.

To work around that limitation, I introduced a new timer that only gets
active when the guest can not receive any more characters. In that case
it polls again after a while to check if the guest is now receiving input.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

This patch fixes input when using -nographic on s390 for me.

I think this is really a kvm issue. I assume it's because s390 idles in the kernel so you never drop to userspace to repoll the descriptor.

There is no polling for the muxer. That's why it never knows when virtio-console can receive again.

Maybe I'm missing something simple, but it looks to me like the muxer is polling. mux_chr_can_read() is going to eventually poll the muxed devices to figure this out.

Quoted 7 lines
Quoted 3 lines

If the root of the problem is that mux_chr_can_read() isn't being invoked for a prolonged period of time, the real issue is the problem I described.

The problem is that the select list of fds includes the stdio fd, so that gets notified and is coupled with virtio-console, but there's nothing passing that on to mux and I don't think it'd be clever to expose internal data to the muxer to tell it about the backend fds.

Quoted 6 lines

When stdio is readable, it should invoke qemu_chr_read() with the read data which in turn ought to invoke mux_chr_read().

I'm not sure I understand what signalling is missing. Jan, does the problem Alex describes ring a bell? I seem to recall you saying that mux was still fundamentally broken but ought to work most of the time...

That problem was (and still is) that the muxer needs to accept characters even if the active front-end device is not in order to filter out control sequences. Once its queue is full, it will start dropping those the active device would not if directly connected. Could only be solved via some peek service on pending front-end data.

I think Alex' problem can be addressed by registering qemu_set_fd_handler2(..., backend->read_poll, mux_chr_read, ...). That means the backend has to tell us about its read poll handler (if any).

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#7 lore raw
Quoted 59 lines · Jan Kiszka
Quoted 45 lines · Anthony Liguori
Quoted 37 lines · Alexander Graf

Am 04.05.2010 um 16:34 schrieb Anthony Liguori <[email protected]>:

Quoted 35 lines · Alexander Graf
Quoted 23 lines

Am 04.05.2010 um 15:44 schrieb Anthony Liguori <[email protected]>:

Quoted 21 lines · Alexander Graf
Quoted 20 lines

Virtio-Console can only process one character at a time. Using it on S390
gave me strage "lags" where I got the character I pressed before when pressing one. So I typed in "abc" and only received "a", then pressed "d"
but the guest received "b" and so on.

While the stdio driver calls a poll function that just processes on its
queue in case virtio-console can't take multiple characters at once, the
muxer does not have such callbacks, so it can't empty its queue.

To work around that limitation, I introduced a new timer that only gets
active when the guest can not receive any more characters. In that case
it polls again after a while to check if the guest is now receiving input.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

This patch fixes input when using -nographic on s390 for me.

I think this is really a kvm issue. I assume it's because s390 idles in the kernel so you never drop to userspace to repoll the descriptor.

There is no polling for the muxer. That's why it never knows when virtio-console can receive again.

Maybe I'm missing something simple, but it looks to me like the muxer is polling. mux_chr_can_read() is going to eventually poll the muxed devices to figure this out.

Quoted 7 lines
Quoted 3 lines

If the root of the problem is that mux_chr_can_read() isn't being invoked for a prolonged period of time, the real issue is the problem I described.

The problem is that the select list of fds includes the stdio fd, so that gets notified and is coupled with virtio-console, but there's nothing passing that on to mux and I don't think it'd be clever to expose internal data to the muxer to tell it about the backend fds.

Quoted 6 lines

When stdio is readable, it should invoke qemu_chr_read() with the read data which in turn ought to invoke mux_chr_read().

I'm not sure I understand what signalling is missing. Jan, does the problem Alex describes ring a bell? I seem to recall you saying that mux was still fundamentally broken but ought to work most of the time...

That problem was (and still is) that the muxer needs to accept characters even if the active front-end device is not in order to filter out control sequences. Once its queue is full, it will start dropping those the active device would not if directly connected. Could only be solved via some peek service on pending front-end data.

Quoted 3 lines

I think Alex' problem can be addressed by registering qemu_set_fd_handler2(..., backend->read_poll, mux_chr_read, ...). That means the backend has to tell us about its read poll handler (if any).

Nonsense.

In fact, the problem is the former issue: As the muxer reads the character the front-end is currently unable to receive, polling may stop until as the back-end has some further chars to deliver.

But interestingly, the stdio back-end has a (single-byte) fifo as well. It just drives it a bit differently.

Alex, does this help as well?

qemu-char.c +2 -2
index ac65a1c..2b115a4 100644
@@ -404,6 +404,8 @@ static int mux_chr_can_read(void *opaque)
     MuxDriver *d = chr->opaque;
     int m = d->focus;
 
+    mux_chr_accept_input(opaque);
+
     if ((d->prod[m] - d->cons[m]) < MUX_BUFFER_SIZE)
         return 1;
     if (d->chr_can_read[m])
@@ -418,8 +420,6 @@ static void mux_chr_read(void *opaque, const uint8_t *buf, int size)
     int m = d->focus;
     int i;
 
-    mux_chr_accept_input (opaque);
-
     for(i = 0; i < size; i++)
         if (mux_proc_byte(chr, d, buf[i])) {
             if (d->prod[m] == d->cons[m] &&

I'm trying to reproduce in parallel.

Jan

#8 lore raw
Quoted 26 lines · Jan Kiszka

Alex, does this help as well?

qemu-char.c +2 -2
index ac65a1c..2b115a4 100644
@@ -404,6 +404,8 @@ static int mux_chr_can_read(void *opaque)
     MuxDriver *d = chr->opaque;
     int m = d->focus;
 
+    mux_chr_accept_input(opaque);
+
     if ((d->prod[m] - d->cons[m]) < MUX_BUFFER_SIZE)
         return 1;
     if (d->chr_can_read[m])
@@ -418,8 +420,6 @@ static void mux_chr_read(void *opaque, const uint8_t *buf, int size)
     int m = d->focus;
     int i;
 
-    mux_chr_accept_input (opaque);
-
     for(i = 0; i < size; i++)
         if (mux_proc_byte(chr, d, buf[i])) {
             if (d->prod[m] == d->cons[m] &&
Quoted 1 line

I'm trying to reproduce in parallel.

Works for me. Will post as proper patch later.

Jan

#9 lore raw

Am 05.05.2010 um 10:08 schrieb Jan Kiszka <[email protected]>:

Quoted 28 lines
Quoted 27 lines · Jan Kiszka

Alex, does this help as well?

qemu-char.c +2 -2
index ac65a1c..2b115a4 100644
@@ -404,6 +404,8 @@ static int mux_chr_can_read(void *opaque)
    MuxDriver *d = chr->opaque;
    int m = d->focus;
 
+    mux_chr_accept_input(opaque);
+
    if ((d->prod[m] - d->cons[m]) < MUX_BUFFER_SIZE)
        return 1;
    if (d->chr_can_read[m])
@@ -418,8 +420,6 @@ static void mux_chr_read(void *opaque, const  
 uint8_t *buf, int size)
    int m = d->focus;
    int i;
 
-    mux_chr_accept_input (opaque);
-
    for(i = 0; i < size; i++)
        if (mux_proc_byte(chr, d, buf[i])) {
            if (d->prod[m] == d->cons[m] &&
Quoted 3 lines
Quoted 1 line

I'm trying to reproduce in parallel.

Works for me. Will post as proper patch later.

I'll try it out next week, after my vacation is over :)

Alex

Quoted 1 line
#10 lore raw

PATCH 1/1 char: Flush read buffer in mux_chr_can_read

In reply to Jan Kiszka

Move the buffer flush from mux_chr_read to mux_chr_can_read. While the latter is called periodically, the former will only be invoked when new characters arrive at the back-end. This caused problems to front-end drivers whenever they were unable to read data immediately, e.g. virtio-console attached to stdio.

---
 qemu-char.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
qemu-char.c +2 -2
index ac65a1c..2b115a4 100644
@@ -404,6 +404,8 @@ static int mux_chr_can_read(void *opaque)
     MuxDriver *d = chr->opaque;
     int m = d->focus;
 
+    mux_chr_accept_input(opaque);
+
     if ((d->prod[m] - d->cons[m]) < MUX_BUFFER_SIZE)
         return 1;
     if (d->chr_can_read[m])
@@ -418,8 +420,6 @@ static void mux_chr_read(void *opaque, const uint8_t *buf, int size)
     int m = d->focus;
     int i;
 
-    mux_chr_accept_input (opaque);
-
     for(i = 0; i < size; i++)
         if (mux_proc_byte(chr, d, buf[i])) {
             if (d->prod[m] == d->cons[m] &&
#11 lore raw

[Qemu-devel] Re: [PATCH] char: Flush read buffer in mux_chr_can_read

Quoted 6 lines · Jan Kiszka

Move the buffer flush from mux_chr_read to mux_chr_can_read. While the latter is called periodically, the former will only be invoked when new characters arrive at the back-end. This caused problems to front-end drivers whenever they were unable to read data immediately, e.g. virtio-console attached to stdio.

I don't see this patch applied, but also don't see any issues with virtio-console anymore on today's git. Odd.

Alex

#12 lore raw

[Qemu-devel] Re: [PATCH] char: Flush read buffer in mux_chr_can_read

Quoted 11 lines · Alexander Graf
Quoted 6 lines · Jan Kiszka

Move the buffer flush from mux_chr_read to mux_chr_can_read. While the latter is called periodically, the former will only be invoked when new characters arrive at the back-end. This caused problems to front-end drivers whenever they were unable to read data immediately, e.g. virtio-console attached to stdio.

I don't see this patch applied, but also don't see any issues with virtio-console anymore on today's git. Odd.

Hmm, I had a clear before-after experience using virtio console with an x86 Linux guest. I still think my patch is correct and required. Maybe you can bisect this positive "regression"? Something might paper over the core issue now.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#13 lore raw

[Qemu-devel] Re: [PATCH] char: Flush read buffer in mux_chr_can_read

Quoted 16 lines · Jan Kiszka
Quoted 9 lines · Alexander Graf
Quoted 7 lines · Jan Kiszka

Move the buffer flush from mux_chr_read to mux_chr_can_read. While the latter is called periodically, the former will only be invoked when new characters arrive at the back-end. This caused problems to front-end drivers whenever they were unable to read data immediately, e.g. virtio-console attached to stdio.

Quoted 4 lines

I don't see this patch applied, but also don't see any issues with virtio-console anymore on today's git. Odd.

Quoted 5 lines

Hmm, I had a clear before-after experience using virtio console with an x86 Linux guest. I still think my patch is correct and required. Maybe you can bisect this positive "regression"? Something might paper over the core issue now.

I just did a git reset --hard on baf0b55a9e57b909b1f8b0f732c0b10242867418 and it worked! What the ...

Alex

#14 lore raw

[Qemu-devel] Re: [PATCH] char: Flush read buffer in mux_chr_can_read

Quoted 16 lines · Alexander Graf
Quoted 15 lines · Jan Kiszka
Quoted 13 lines · Alexander Graf
Quoted 7 lines · Jan Kiszka

Move the buffer flush from mux_chr_read to mux_chr_can_read. While the latter is called periodically, the former will only be invoked when new characters arrive at the back-end. This caused problems to front-end drivers whenever they were unable to read data immediately, e.g. virtio-console attached to stdio.

I don't see this patch applied, but also don't see any issues with virtio-console anymore on today's git. Odd.

Quoted 8 lines
Quoted 5 lines

Hmm, I had a clear before-after experience using virtio console with an x86 Linux guest. I still think my patch is correct and required. Maybe you can bisect this positive "regression"? Something might paper over the core issue now.

I just did a git reset --hard on baf0b55a9e57b909b1f8b0f732c0b10242867418 and it worked! What the ...

Whatever "worked" now means (I'm slightly confused), I just rechecked the situation over current git head ("qemu linux-guest.img -chardev stdio,id=cons,mux=on -device virtio-serial -device virtconsole,chardev=cons -mon chardev=cons", "cat /dev/hvc0" in the guest, typing some chars on the host console): The problem still persists, my patch still solves it. Can you confirm this, ideally also for s390?

Jan

#15 lore raw

[Qemu-devel] Re: [PATCH] char: Flush read buffer in mux_chr_can_read

Quoted 26 lines · Jan Kiszka
Quoted 16 lines · Alexander Graf
Quoted 15 lines · Jan Kiszka
Quoted 13 lines · Alexander Graf
Quoted 7 lines · Jan Kiszka

Move the buffer flush from mux_chr_read to mux_chr_can_read. While the latter is called periodically, the former will only be invoked when new characters arrive at the back-end. This caused problems to front-end drivers whenever they were unable to read data immediately, e.g. virtio-console attached to stdio.

I don't see this patch applied, but also don't see any issues with virtio-console anymore on today's git. Odd.

Quoted 8 lines
Quoted 5 lines

Hmm, I had a clear before-after experience using virtio console with an x86 Linux guest. I still think my patch is correct and required. Maybe you can bisect this positive "regression"? Something might paper over the core issue now.

I just did a git reset --hard on baf0b55a9e57b909b1f8b0f732c0b10242867418 and it worked! What the ...

Quoted 7 lines

Whatever "worked" now means (I'm slightly confused), I just rechecked the situation over current git head ("qemu linux-guest.img -chardev stdio,id=cons,mux=on -device virtio-serial -device virtconsole,chardev=cons -mon chardev=cons", "cat /dev/hvc0" in the guest, typing some chars on the host console): The problem still persists, my patch still solves it. Can you confirm this, ideally also for s390?

Now that I can finally reproduce the bug with --enable-io-thread, I can verify that it does *not* fix the issue.

Alex

#16 lore raw

[Qemu-devel] Re: [PATCH] char: Flush read buffer in mux_chr_can_read

Quoted 34 lines · Alexander Graf
Quoted 24 lines · Jan Kiszka
Quoted 16 lines · Alexander Graf
Quoted 15 lines · Jan Kiszka
Quoted 13 lines · Alexander Graf
Quoted 7 lines · Jan Kiszka

Move the buffer flush from mux_chr_read to mux_chr_can_read. While the latter is called periodically, the former will only be invoked when new characters arrive at the back-end. This caused problems to front-end drivers whenever they were unable to read data immediately, e.g. virtio-console attached to stdio.

I don't see this patch applied, but also don't see any issues with virtio-console anymore on today's git. Odd.

Quoted 7 lines
Quoted 5 lines

Hmm, I had a clear before-after experience using virtio console with an x86 Linux guest. I still think my patch is correct and required. Maybe you can bisect this positive "regression"? Something might paper over the core issue now.

I just did a git reset --hard on baf0b55a9e57b909b1f8b0f732c0b10242867418 and it worked! What the ...

Quoted 7 lines

Whatever "worked" now means (I'm slightly confused), I just rechecked the situation over current git head ("qemu linux-guest.img -chardev stdio,id=cons,mux=on -device virtio-serial -device virtconsole,chardev=cons -mon chardev=cons", "cat /dev/hvc0" in the guest, typing some chars on the host console): The problem still persists, my patch still solves it. Can you confirm this, ideally also for s390?

Quoted 1 line

Now that I can finally reproduce the bug with --enable-io-thread, I can verify that it does *not* fix the issue.

I do not trust your tests. :p

I just tried to reproduce with --enable-io-thread and the setup I described above - all still fine here. Can you reproduce with an x86 guest?

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#17 lore raw

[Qemu-devel] Re: [PATCH] char: Flush read buffer in mux_chr_can_read

Quoted 35 lines · Jan Kiszka
Quoted 34 lines · Alexander Graf
Quoted 31 lines · Jan Kiszka
Quoted 16 lines · Alexander Graf
Quoted 15 lines · Jan Kiszka
Quoted 13 lines · Alexander Graf
Quoted 7 lines · Jan Kiszka

Move the buffer flush from mux_chr_read to mux_chr_can_read. While the latter is called periodically, the former will only be invoked when new characters arrive at the back-end. This caused problems to front-end drivers whenever they were unable to read data immediately, e.g. virtio-console attached to stdio.

I don't see this patch applied, but also don't see any issues with virtio-console anymore on today's git. Odd.

Quoted 7 lines
Quoted 5 lines

Hmm, I had a clear before-after experience using virtio console with an x86 Linux guest. I still think my patch is correct and required. Maybe you can bisect this positive "regression"? Something might paper over the core issue now.

I just did a git reset --hard on baf0b55a9e57b909b1f8b0f732c0b10242867418 and it worked! What the ...

Whatever "worked" now means (I'm slightly confused), I just rechecked the situation over current git head ("qemu linux-guest.img -chardev stdio,id=cons,mux=on -device virtio-serial -device virtconsole,chardev=cons -mon chardev=cons", "cat /dev/hvc0" in the guest, typing some chars on the host console): The problem still persists, my patch still solves it. Can you confirm this, ideally also for s390?

Quoted 6 lines
Quoted 1 line

Now that I can finally reproduce the bug with --enable-io-thread, I can verify that it does *not* fix the issue.

I do not trust your tests. :p

I just tried to reproduce with --enable-io-thread and the setup I described above - all still fine here. Can you reproduce with an x86 guest?

Nope, it works fine with an x86 guest. I put the following in /etc/inittab of my guest:

11:2345:respawn:/sbin/mingetty --noclear /dev/hvc0 linux

One major thing to keep in mind when talking about s390 guests is that we almost never trap into userspace.

Alex

#18 lore raw

[Qemu-devel] Re: [PATCH] char: Flush read buffer in mux_chr_can_read

Quoted 5 lines · Alexander Graf
Quoted 4 lines · Jan Kiszka
Quoted 1 line · Alexander Graf

Now that I can finally reproduce the bug with --enable-io-thread, I can verify that it does *not* fix the issue.

I do not trust your tests. :p

Quoted 8 lines
Quoted 2 lines

I just tried to reproduce with --enable-io-thread and the setup I described above - all still fine here. Can you reproduce with an x86 guest?

Nope, it works fine with an x86 guest. I put the following in /etc/inittab of my guest:

11:2345:respawn:/sbin/mingetty --noclear /dev/hvc0 linux

One major thing to keep in mind when talking about s390 guests is that we almost never trap into userspace.

Do you have the same problem when using an unbuffered backend, e.g. pty? Maybe that single-byte "fifo" of stdio makes the difference, though I wonder why only on s390 (guest exists should not block the polling done by the io-thread, just accelerate it).

Jan

#19 lore raw

[Qemu-devel] Re: [PATCH] char: Flush read buffer in mux_chr_can_read

Quoted 11 lines · Jan Kiszka
Quoted 10 lines · Alexander Graf
Quoted 6 lines · Jan Kiszka
Quoted 1 line · Alexander Graf

Now that I can finally reproduce the bug with --enable-io-thread, I can verify that it does *not* fix the issue.

I do not trust your tests. :p

I just tried to reproduce with --enable-io-thread and the setup I described above - all still fine here. Can you reproduce with an x86 guest?

Nope, it works fine with an x86 guest. I put the following in /etc/inittab of my guest:

Quoted 8 lines
Quoted 3 lines

11:2345:respawn:/sbin/mingetty --noclear /dev/hvc0 linux

One major thing to keep in mind when talking about s390 guests is that we almost never trap into userspace.

Do you have the same problem when using an unbuffered backend, e.g. pty? Maybe that single-byte "fifo" of stdio makes the difference, though I wonder why only on s390 (guest exists should not block the polling done by the io-thread, just accelerate it).

Mind to give me a small example on how to use that? :)

Alex

#20 lore raw

[Qemu-devel] Re: [PATCH] char: Flush read buffer in mux_chr_can_read

Quoted 14 lines · Alexander Graf
Quoted 12 lines · Jan Kiszka
Quoted 11 lines · Alexander Graf
Quoted 6 lines · Jan Kiszka
Quoted 1 line · Alexander Graf

Now that I can finally reproduce the bug with --enable-io-thread, I can verify that it does *not* fix the issue.

I do not trust your tests. :p

I just tried to reproduce with --enable-io-thread and the setup I described above - all still fine here. Can you reproduce with an x86 guest?

Nope, it works fine with an x86 guest. I put the following in /etc/inittab of my guest:

11:2345:respawn:/sbin/mingetty --noclear /dev/hvc0 linux

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

One major thing to keep in mind when talking about s390 guests is that we almost never trap into userspace.

Do you have the same problem when using an unbuffered backend, e.g. pty? Maybe that single-byte "fifo" of stdio makes the difference, though I wonder why only on s390 (guest exists should not block the polling done by the io-thread, just accelerate it).

Mind to give me a small example on how to use that? :)

-chardev pty,...

echo whatever > /dev/pts/<n>

Or you set up a telnet server.

Jan