From: Stefan Hajnoczi <stefanha@gmail.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>, Fam Zheng <fam@euphon.net>,
qemu-block@nongnu.org, qemu-devel <qemu-devel@nongnu.org>,
Max Reitz <mreitz@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [PATCH] util/async: make bh_aio_poll() O(1)
Date: Fri, 21 Feb 2020 13:47:42 +0000 [thread overview]
Message-ID: <20200221134742.GL1484511@stefanha-x1.localdomain> (raw)
In-Reply-To: <CABgObfYY+tr3xuoBFF3Q3zn2khrZCSfGK-P63NYJ_phS1vCp5w@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2992 bytes --]
On Wed, Feb 19, 2020 at 08:05:12PM +0100, Paolo Bonzini wrote:
> Il mer 19 feb 2020, 18:58 Stefan Hajnoczi <stefanha@redhat.com> ha scritto:
>
> > On Wed, Feb 19, 2020 at 12:09:48PM +0100, Paolo Bonzini wrote:
> > > Really a great idea, though I have some remarks on the implementation
> > below.
> > >
> > > On 19/02/20 11:00, Stefan Hajnoczi wrote:
> > > > + * Each aio_bh_poll() call carves off a slice of the BH list. This
> > way newly
> > > > + * scheduled BHs are not processed until the next aio_bh_poll()
> > call. This
> > > > + * concept extends to nested aio_bh_poll() calls because slices are
> > chained
> > > > + * together.
> > >
> > > This is the tricky part so I would expand a bit on why it's needed:
> > >
> > > /*
> > > * Each aio_bh_poll() call carves off a slice of the BH list, so that
> > > * newly scheduled BHs are not processed until the next aio_bh_poll()
> > > * call. All active aio_bh_poll() calls chained their slices together
> > > * in a list, so that nested aio_bh_poll() calls process all scheduled
> > > * bottom halves.
> > > */
> >
> > Thanks, will fix in v2.
> >
> > > > +struct BHListSlice {
> > > > + QEMUBH *first_bh;
> > > > + BHListSlice *next;
> > > > +};
> > > > +
> > >
> > > Using QLIST and QSLIST removes the need to create your own lists, since
> > > you can use QSLIST_MOVE_ATOMIC and QSLIST_INSERT_HEAD_ATOMIC. For
> > example:
> > >
> > > struct BHListSlice {
> > > QSLIST_HEAD(, QEMUBH) first_bh;
> > > QLIST_ENTRY(BHListSlice) next;
> > > };
> > >
> > > ...
> > >
> > > QSLIST_HEAD(, QEMUBH) active_bh;
> > > QLIST_HEAD(, BHListSlice) bh_list;
> >
> > I thought about this but chose the explicit tail pointer approach
> > because it lets aio_compute_timeout() and aio_ctx_check() iterate over
> > both the active BH list and slices in a single for loop :). But
> > thinking about it more, maybe it can still be done by replacing
> > active_bh with a permanently present first BHListSlice element.
> >
>
> Probably not so easy since the idea was to empty the slices list entirely
> via the FIFO order.
>
> But since you are rewriting everything anyway, can you add a flag for
> whether there are any non-idle bottom halves anywhere in the list? It need
> not be computed perfectly, because any non-idle bh will cause the idle
> bottom halves to be triggered as well; you can just set in qemu_bh_schedule
> and clear it at the end of aio_bh_poll.
>
> Then if there is any active bh or slice you consult the flag and use it to
> return the timeout, which will be either 0 or 10ms depending on the flag.
> That's truly O(1). (More precisely, this patch goes from O(#created-bh) to
> O(#scheduled-bh), which of course is optimal for aio_bh_poll but not for
> aio_compute_timeout; making timeout computation O(1) can lower latency a
> bit by decreasing the constant factor).
Yes, good idea. I'll send a follow-up patch.
Stefan
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
prev parent reply other threads:[~2020-02-21 13:48 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-19 10:00 [PATCH] util/async: make bh_aio_poll() O(1) Stefan Hajnoczi
2020-02-19 11:09 ` Paolo Bonzini
2020-02-19 16:54 ` Stefan Hajnoczi
2020-02-19 19:05 ` Paolo Bonzini
2020-02-21 13:47 ` Stefan Hajnoczi [this message]
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=20200221134742.GL1484511@stefanha-x1.localdomain \
--to=stefanha@gmail.com \
--cc=fam@euphon.net \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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).