Skip to contentSkip to conversation

hw/serial.c: Xmit fifo never used

Qemu-devel Frank Mehnert 4 participants 8 messages May 26, 2010 – May 28, 2010

lore
Share & tools
lore
#0 lore raw

Hi,

the xmit fifo of the serial device is never used. If qemu_chr_write() fails (interface currently not able to send characters) then the transmit_timer should be engaged to try to send the current character from the fifo again after some time. The code is

    } else if (qemu_chr_write(s->chr, &s->tsr, 1) != 1) {
        if ((s->tsr_retry > 0) && (s->tsr_retry <= MAX_XMIT_RETRY)) {
            s->tsr_retry++;
            qemu_mod_timer(s->transmit_timer,
                           new_xmit_ts + s->char_transmit_time);
            return;
        }
        ...
    }

The problem is that this path is never used as tsr_retry is never > 0 initially. So if qemu_chr_write() fails, we never try again but drop the character.

I assume the correct condition would be '>= 0', that is

        ...
        if ((s->tsr_retry >= 0) && (s->tsr_retry <= MAX_XMIT_RETRY)) {
            s->tsr_retry++;
        ...

Kind regards,

Frank

Signature · 6 lines
Dr.-Ing. Frank Mehnert

Sitz der Gesellschaft:
Sun Microsystems GmbH, Sonnenallee 1, 85551 Kirchheim-Heimstetten
Amtsgericht München: HRB 161028
Geschäftsführer: Jürgen Kunz
#1 lore raw
Quoted 21 lines · Frank Mehnert

Hi,

the xmit fifo of the serial device is never used. If qemu_chr_write() fails (interface currently not able to send characters) then the transmit_timer should be engaged to try to send the current character from the fifo again after some time. The code is

    } else if (qemu_chr_write(s->chr, &s->tsr, 1) != 1) {
        if ((s->tsr_retry > 0) && (s->tsr_retry <= MAX_XMIT_RETRY)) {
            s->tsr_retry++;
            qemu_mod_timer(s->transmit_timer,
                           new_xmit_ts + s->char_transmit_time);
            return;
        }
        ...
    }

The problem is that this path is never used as tsr_retry is never > 0 initially. So if qemu_chr_write() fails, we never try again but drop the character.

Quoted 6 lines

I assume the correct condition would be '>= 0', that is

        ...
        if ((s->tsr_retry >= 0) && (s->tsr_retry <= MAX_XMIT_RETRY)) {
            s->tsr_retry++;
        ...

Makes sense, patch welcome.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#2 lore raw
Quoted 9 lines · Jan Kiszka
Quoted 6 lines · Frank Mehnert

I assume the correct condition would be '>= 0', that is

        ...
        if ((s->tsr_retry >= 0) && (s->tsr_retry <= MAX_XMIT_RETRY)) {
            s->tsr_retry++;
        ...

Makes sense, patch welcome.

Attached.

Kind regards,

Frank

Signature · 6 lines
Dr.-Ing. Frank Mehnert

Sitz der Gesellschaft:
Sun Microsystems GmbH, Sonnenallee 1, 85551 Kirchheim-Heimstetten
Amtsgericht München: HRB 161028
Geschäftsführer: Jürgen Kunz
hw/serial.c +1 -1
index 9102edb..0b1550b 100644
@@ -327,7 +327,7 @@ static void serial_xmit(void *opaque)
         /* in loopback mode, say that we just received a char */
         serial_receive1(s, &s->tsr, 1);
     } else if (qemu_chr_write(s->chr, &s->tsr, 1) != 1) {
-        if ((s->tsr_retry > 0) && (s->tsr_retry <= MAX_XMIT_RETRY)) {
+        if ((s->tsr_retry >= 0) && (s->tsr_retry <= MAX_XMIT_RETRY)) {
             s->tsr_retry++;
             qemu_mod_timer(s->transmit_timer,  new_xmit_ts + s->char_transmit_time);
             return;
#3 lore raw
Quoted 11 lines · Frank Mehnert
Quoted 8 lines · Jan Kiszka
Quoted 6 lines · Frank Mehnert

I assume the correct condition would be '>= 0', that is

        ...
        if ((s->tsr_retry >= 0) && (s->tsr_retry <= MAX_XMIT_RETRY)) {
            s->tsr_retry++;
        ...

Makes sense, patch welcome.

Attached.

Signed-off, subject, and description please. And I would keep Stefano as the original author of this feature in CC. A cross-check by him might be good as we enable a code path that was apparently dead so far.

Thanks,
Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#4 lore raw
Quoted 9 lines · Jan Kiszka
Quoted 8 lines · Frank Mehnert
Quoted 7 lines · Jan Kiszka
Quoted 6 lines · Frank Mehnert

I assume the correct condition would be '>= 0', that is

        ...
        if ((s->tsr_retry >= 0) && (s->tsr_retry <= MAX_XMIT_RETRY)) {
            s->tsr_retry++;
        ...
Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Makes sense, patch welcome.

Attached.

Signed-off, subject, and description please. And I would keep Stefano as the original author of this feature in CC. A cross-check by him might be good as we enable a code path that was apparently dead so far.

I think the patch is correct.

#5 lore raw
Quoted 1 line · Stefano Stabellini

I think the patch is correct.

serial: fixed bug which prevented the use of the xmit fifo

---
 hw/serial.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
hw/serial.c +1 -1
index 9102edb..0b1550b 100644
@@ -327,7 +327,7 @@ static void serial_xmit(void *opaque)
         /* in loopback mode, say that we just received a char */
         serial_receive1(s, &s->tsr, 1);
     } else if (qemu_chr_write(s->chr, &s->tsr, 1) != 1) {
-        if ((s->tsr_retry > 0) && (s->tsr_retry <= MAX_XMIT_RETRY)) {
+        if ((s->tsr_retry >= 0) && (s->tsr_retry <= MAX_XMIT_RETRY)) {
             s->tsr_retry++;
             qemu_mod_timer(s->transmit_timer,  new_xmit_ts + 
s->char_transmit_time);
             return;

--
1.5.6.5

Hope this is now the correct format.

Kind regards,

Frank

Signature · 6 lines
Dr.-Ing. Frank Mehnert

Sitz der Gesellschaft:
Sun Microsystems GmbH, Sonnenallee 1, 85551 Kirchheim-Heimstetten
Amtsgericht München: HRB 161028
Geschäftsführer: Jürgen Kunz
#6 lore raw
Quoted 24 lines · Frank Mehnert
Quoted 1 line · Stefano Stabellini

I think the patch is correct.

serial: fixed bug which prevented the use of the xmit fifo

---
 hw/serial.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
hw/serial.c +1 -1
index 9102edb..0b1550b 100644
@@ -327,7 +327,7 @@ static void serial_xmit(void *opaque)
         /* in loopback mode, say that we just received a char */
         serial_receive1(s, &s->tsr, 1);
     } else if (qemu_chr_write(s->chr, &s->tsr, 1) != 1) {
-        if ((s->tsr_retry > 0) && (s->tsr_retry <= MAX_XMIT_RETRY)) {
+        if ((s->tsr_retry >= 0) && (s->tsr_retry <= MAX_XMIT_RETRY)) {
             s->tsr_retry++;
             qemu_mod_timer(s->transmit_timer,  new_xmit_ts + 
 s->char_transmit_time);
             return;
Quoted 6 lines

--
1.5.6.5

Hope this is now the correct format.

Really close: Without "[PATCH]" prefix in the subject line there is the risk that no maintainer will find your patch. Moreover, your mail client wrapped long lines.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#7 lore raw
In reply to Frank Mehnert
Quoted 2 lines

The problem is that this path is never used as tsr_retry is never > 0 initially. So if qemu_chr_write() fails, we never try again but drop

qemu_chr_write is a blocking interface. It should only fail if an unrecoverable error occurs. In that case there's noting useful we can do, and no reason to retry.

Paul