From: "Michael S. Tsirkin" <mst@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
virtualization@lists.linux-foundation.org
Subject: Re: [PATCH 1/9] virtio: add functions for piecewise addition of buffers
Date: Wed, 13 Feb 2013 12:33:37 +0200 [thread overview]
Message-ID: <20130213103337.GC14452@redhat.com> (raw)
In-Reply-To: <511B4983.7010103@redhat.com>
On Wed, Feb 13, 2013 at 09:06:27AM +0100, Paolo Bonzini wrote:
> Il 12/02/2013 21:49, Michael S. Tsirkin ha scritto:
> > On Tue, Feb 12, 2013 at 09:08:27PM +0100, Paolo Bonzini wrote:
> >> Il 12/02/2013 19:23, Michael S. Tsirkin ha scritto:
> >>> On Tue, Feb 12, 2013 at 07:04:27PM +0100, Paolo Bonzini wrote:
> >>>>>> Perhaps, but 3 or 4 arguments (in/out/nsg or in/out/nsg_in/nsg_out) just
> >>>>>> for this are definitely too many and make the API harder to use.
> >>>>>>
> >>>>>> You have to find a balance. Having actually used the API, the
> >>>>>> possibility of mixing in/out buffers by mistake never even occurred to
> >>>>>> me, much less happened in practice, so I didn't consider it a problem.
> >>>>>> Mixing in/out buffers in a single call wasn't a necessity, either.
> >>>>>
> >>>>> It is useful for virtqueue_add_buf implementation.
> >>>>
> >>>> ret = virtqueue_start_buf(vq, data, out + in, !!out + !!in,
> >>>> gfp);
> >>>> if (ret < 0)
> >>>> return ret;
> >>>>
> >>>> if (out)
> >>>> virtqueue_add_sg(vq, sg, out, DMA_TO_DEVICE);
> >>>> if (in)
> >>>> virtqueue_add_sg(vq, sg + out, in, DMA_FROM_DEVICE);
> >>>>
> >>>> virtqueue_end_buf(vq);
> >>>> return 0;
> >>>>
> >>>> How can it be simpler and easier to understand than that?
> >>>
> >>> Like this:
> >>>
> >>> ret = virtqueue_start_buf(vq, data, in, out, gfp);
> >>> if (ret < 0)
> >>> return ret;
> >>>
> >>> virtqueue_add_sg(vq, sg, in, out);
> >>>
> >>> virtqueue_end_buf(vq);
> >>
> >> It's out/in, not in/out... I know you wrote it in a hurry, but it kind
> >> of shows that the new API is easier to use. Check out patch 8, it's a
> >> real improvement in readability.
> >
> > That's virtqueue_add_buf_single, that's a separate matter.
> > Another option for _single is just two wrappers:
> > virtqueue_add_buf_in
> > virtqueue_add_buf_out
>
> I like it less, but yes this one would be ok (no driver uses a variable
> for the enum parameter).
OK, this has the advantage of being even shorter.
> >> Plus you haven't solved the problem of alternating to/from-device
> >> elements (which is also harder to spot with in/out than with the enum).
> >
> > Yes it does, if add_sg does not have in/out at all there's no way to
> > request the impossible to/from mix.
>
> In your example above it does have it. I assume you meant
>
> ret = virtqueue_start_buf(vq, data, out, in, gfp);
> if (ret < 0)
> return ret;
>
> virtqueue_add_sg(vq, sg, out + in);
> virtqueue_end_buf(vq);
>
> >>>> virtqueue_add_buf and virtqueue_add_sg are very different, despite the
> >>>> similar name.
> >>>
> >>> True. The similarity is between _start and _add_buf.
> >>> And this is confusing too. Maybe this means
> >>> _start and _add_sg should be renamed.
> >>
> >> Maybe. If you have any suggestions it's fine.
> >>
> >> BTW I tried using out/in for start_buf, and the code in virtio-blk gets
> >> messier, it has to do all the math twice.
> >
> > I'm pretty sure we can do this without duplication, if we want to.
>
> Indeed, if you remove the out/in arguments from _sg there is no
> duplication in virtio-blk. That's because it places data-out at the end
> and data-in at the beginning (so data is always after the request header
> and before the response footer).
Yes, it's not a virtio-blk thing, virtio spec and interface require that
we have in after out.
So yes, to me it seems cleaner to drop out/in arguments from _sg.
> >> acknowledge that the API is different and thus the optimal choice of
> >> arguments is different. C doesn't have keyword arguments, there not
> >> much that we can do.
> >
> > Yea, maybe. I'm not the API guru here anyway, it's Rusty's street.
>
> Let's wait for him.
>
> Paolo
next prev parent reply other threads:[~2013-02-13 10:33 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-12 12:23 [PATCH 0/9] virtio: new API for addition of buffers, scatterlist changes Paolo Bonzini
2013-02-12 12:23 ` [PATCH 1/9] virtio: add functions for piecewise addition of buffers Paolo Bonzini
2013-02-12 14:56 ` Michael S. Tsirkin
2013-02-12 15:32 ` Paolo Bonzini
2013-02-12 15:43 ` Michael S. Tsirkin
2013-02-12 15:48 ` Paolo Bonzini
2013-02-12 16:13 ` Michael S. Tsirkin
2013-02-12 16:17 ` Paolo Bonzini
2013-02-12 16:35 ` Michael S. Tsirkin
2013-02-12 16:57 ` Paolo Bonzini
2013-02-12 17:34 ` Michael S. Tsirkin
2013-02-12 18:04 ` Paolo Bonzini
2013-02-12 18:23 ` Michael S. Tsirkin
2013-02-12 20:08 ` Paolo Bonzini
2013-02-12 20:49 ` Michael S. Tsirkin
2013-02-13 8:06 ` Paolo Bonzini
2013-02-13 10:33 ` Michael S. Tsirkin [this message]
2013-02-12 18:03 ` [PATCH v2 " Paolo Bonzini
2013-02-12 12:23 ` [PATCH 2/9] virtio-blk: reorganize virtblk_add_req Paolo Bonzini
2013-02-17 6:38 ` Asias He
2013-02-12 12:23 ` [PATCH 3/9] virtio-blk: use virtqueue_start_buf on bio path Paolo Bonzini
2013-02-17 6:39 ` Asias He
2013-02-12 12:23 ` [PATCH 4/9] virtio-blk: use virtqueue_start_buf on req path Paolo Bonzini
2013-02-17 6:37 ` Asias He
2013-02-18 9:05 ` Paolo Bonzini
2013-02-12 12:23 ` [PATCH 5/9] scatterlist: introduce sg_unmark_end Paolo Bonzini
2013-02-12 12:23 ` [PATCH 6/9] virtio-net: unmark scatterlist ending after virtqueue_add_buf Paolo Bonzini
2013-02-12 12:23 ` [PATCH 7/9] virtio-scsi: use virtqueue_start_buf Paolo Bonzini
2013-02-12 12:23 ` [PATCH 8/9] virtio: introduce and use virtqueue_add_buf_single Paolo Bonzini
2013-02-12 12:23 ` [PATCH 9/9] virtio: reimplement virtqueue_add_buf using new functions Paolo Bonzini
2013-02-14 6:00 ` [PATCH 0/9] virtio: new API for addition of buffers, scatterlist changes Rusty Russell
2013-02-14 9:23 ` Paolo Bonzini
2013-02-15 18:04 ` Paolo Bonzini
2013-02-19 7:49 ` Rusty Russell
2013-02-19 9:11 ` Paolo Bonzini
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=20130213103337.GC14452@redhat.com \
--to=mst@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=virtualization@lists.linux-foundation.org \
/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).