qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Arwed Meyer <arwed.meyer@gmx.de>
To: "Volker Rümelin" <vr_qemu@t-online.de>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>
Cc: qemu-stable@nongnu.org, qemu-devel@nongnu.org
Subject: Re: [PATCH v2 3/5] msmouse: Use fifo8 instead of array
Date: Sun, 11 Sep 2022 19:53:14 +0200	[thread overview]
Message-ID: <71316e5a-75e4-b38c-64fd-131137feabf2@gmx.de> (raw)
In-Reply-To: <47315b0d-e6b7-60ef-8c0a-f92881ee5177@t-online.de>

Am 11.09.22 um 08:12 schrieb Volker Rümelin:
> Am 08.09.22 um 19:31 schrieb Arwed Meyer:
>
>> @@ -54,21 +60,15 @@ DECLARE_INSTANCE_CHECKER(MouseChardev, MOUSE_CHARDEV,
>>   static void msmouse_chr_accept_input(Chardev *chr)
>>   {
>>       MouseChardev *mouse = MOUSE_CHARDEV(chr);
>> -    int len;
>> +    uint32_t len_out, len;
>>
>> -    len = qemu_chr_be_can_write(chr);
>> -    if (len > mouse->outlen) {
>> -        len = mouse->outlen;
>> -    }
>> -    if (!len) {
>> +    len_out = qemu_chr_be_can_write(chr);
>> +    if (!len_out || fifo8_is_empty(&mouse->outbuf)) {
>>           return;
>>       }
>> -
>> -    qemu_chr_be_write(chr, mouse->outbuf, len);
>> -    mouse->outlen -= len;
>> -    if (mouse->outlen) {
>> -        memmove(mouse->outbuf, mouse->outbuf + len, mouse->outlen);
>> -    }
>> +    len = MIN(fifo8_num_used(&mouse->outbuf), len_out);
>> +    qemu_chr_be_write(chr, fifo8_pop_buf(&mouse->outbuf, len, &len_out),
>> +            len_out);
>
> Hi Arwed,
>
> I think C function arguments are not evaluated in a defined order. It's
> not defined if the third argument of function qemu_chr_be_write() is
> len_out before or after the call to fifo8_pop_buf().
>
> The fifo_pop_buf() function uses a ringbuffer. When the buffer wraps
> around at the end and the ringbuffer contains more than one byte you may
> need two fifo8_pop_buf() and qemu_chr_be_write() calls to write all
> bytes. The code you replace doesn't have that problem.
>
> Some chardev frontends don't return the total number of bytes to write
> in qemu_chr_be_can_write(). They return the number of bytes that can be
> written with one qemu_chr_be_write() call. You need another
> qemu_chr_be_can_write() call after the qemu_chr_be_write() call to see
> if more bytes can be written.
>
> The code in function gd_vc_send_chars() in ui/gtk.c could be used as a
> template to avoid the three issues above.
>
> With best regards,
> Volker
>
>>   }
>>
>>   static void msmouse_queue_event(MouseChardev *mouse)
>

Hi Volker,

have to admit I was not completely sure about the order in which
function arguments get evaluated either. Thanks for the confirmation.
I'll change this to be safe.

I guess you probably won't see much difference between old and new code
in practice since serial I/O is slow anyway, but since I'll change the
patch anyway, I'll take the code from gd_vc_send_chars. Indeed looks better.


  reply	other threads:[~2022-09-11 17:54 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-08 17:31 [PATCH v2 0/5] Make serial msmouse work Arwed Meyer
2022-09-08 17:31 ` [PATCH v2 1/5] msmouse: Handle mouse reset Arwed Meyer
2022-09-08 21:11   ` Peter Maydell
2022-09-11 17:14     ` Arwed Meyer
2022-09-11 18:27       ` Peter Maydell
2022-09-12 17:45         ` Arwed Meyer
2022-09-12 17:54           ` Arwed Meyer
2022-09-13 12:30           ` Peter Maydell
2022-09-08 17:31 ` [PATCH v2 2/5] chardev: src buffer const for write functions Arwed Meyer
2022-09-09 13:13   ` Marc-André Lureau
2022-09-08 17:31 ` [PATCH v2 3/5] msmouse: Use fifo8 instead of array Arwed Meyer
2022-09-09 13:18   ` Marc-André Lureau
2022-09-11 17:27     ` Arwed Meyer
2022-09-11  6:12   ` Volker Rümelin
2022-09-11 17:53     ` Arwed Meyer [this message]
2022-09-08 17:31 ` [PATCH v2 4/5] msmouse: Add pnp data Arwed Meyer
2022-09-09 13:20   ` Marc-André Lureau
2022-09-08 17:31 ` [PATCH v2 5/5] serial: Allow unaligned i/o access Arwed Meyer

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=71316e5a-75e4-b38c-64fd-131137feabf2@gmx.de \
    --to=arwed.meyer@gmx.de \
    --cc=marcandre.lureau@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-stable@nongnu.org \
    --cc=vr_qemu@t-online.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).