From: Li Qiang <liq3ea@gmail.com>
To: Fam Zheng <fam@euphon.net>
Cc: Li Qiang <liq3ea@163.com>, Paolo Bonzini <pbonzini@redhat.com>,
"stefanha@redhat.com" <stefanha@redhat.com>,
Qemu Developers <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] Question about aio_poll and glib aio_ctx_dispatch
Date: Thu, 20 Dec 2018 16:34:25 +0800 [thread overview]
Message-ID: <CAKXe6SJo1uRf6YXfTsKuQdnmFM_iAijSGpdAwG0TRTxbceMd5Q@mail.gmail.com> (raw)
In-Reply-To: <B2B5C030-9D7C-47BD-B3BE-F79782C79C01@euphon.net>
Fam Zheng <fam@euphon.net> 于2018年12月20日周四 上午9:26写道:
>
>
> > On Dec 20, 2018, at 06:58, Li Qiang <liq3ea@163.com> wrote:
> >
> > Hello Paolo
> >
> > Thanks for your kind reply.
> >
> > Yes, aio_poll and aio_ctx_dispatch mostly run in different threads,
> though
> > Sometimes they can run in a thread nested from Fam’s slides:
> > →
> http://events17.linuxfoundation.org/sites/events/files/slides/Improving%20the%20QEMU%20Event%20Loop%20-%203.pdf
> >
> > So you mean we can poll the same fd in two threads? If so , the ‘fd’ in
> ‘qemu_aio_context’ will be run twice, I think there’s
> > something I understand wrong.
> >
> > Let’s take an example. In the ‘v9fs_reset’.
> >
> > void v9fs_reset(V9fsState *s)
> > {
> > VirtfsCoResetData data = { .pdu = { .s = s }, .done = false };
> > Coroutine *co;
> >
> > while (!QLIST_EMPTY(&s->active_list)) {
> > aio_poll(qemu_get_aio_context(), true);
> > }
> >
> > co = qemu_coroutine_create(virtfs_co_reset, &data);
> > qemu_coroutine_enter(co);
> >
> > while (!data.done) {
> > aio_poll(qemu_get_aio_context(), true);
> > }
> > }
> >
> > Here we use aio_poll to wait the pending action to complete.
> > Here aio_poll will poll the fds in ‘qemu_aio_context’ in vcpu thread,
> > However, the main loop is also poll the fds in ‘qemu_aio_context’.
> > If some ‘fd’ in ‘qemu_aio_context’ has events, the two thread will be
> wakeup?
> > You say both will call aio_dispatch_handlers and
> timerlistgroup_run_timers.
> > But the are the same fd, how can this happen?
>
>
>
Thanks Fam,
> I think in this case BQL is used to synchronize them so when v9fs_reset
> runs, the main loop doesn't.
>
I think you're right. The main loop will not hold BQL when polling. But it
will acquire the BQL before it can
do the dispatch. So even if an 'fd' events occurs in this case, only the
aio_poll's dispatch can run.
Thanks,
Li Qiang
>
> Thanks,
> Fam
>
> >
> > Thanks,
> > Li Qiang
> >
> >
> > 发件人: Paolo Bonzini
> > 发送时间: 2018年12月20日 4:42
> > 收件人: Li Qiang; stefanha@redhat.com; fam@euphon.net; Qemu Developers; 李强
> > 主题: Re: Question about aio_poll and glib aio_ctx_dispatch
> >
> > On 19/12/18 11:05, Li Qiang wrote:
> >> Sent it to qemu-devel.
> >>
> >> Li Qiang <liq3ea@gmail.com <mailto:liq3ea@gmail.com>> 于2018年12月19日周
> >> 三 下午6:04写道:
> >>
> >> Hello Paolo, Stefan, Fam and all,
> >>
> >> Here I have a question about 'aio_poll'.
> >> IIUC the 'aio_poll' is (mostly) used for synchronous IO
> >> as I see a lot of code like this:
> >> while(condition)
> >> aio_poll();
> >>
> >> However it seems the 'aio_poll' and 'aio_ctx_dispatch' both poll the
> fd.
> >> So what happened when the 'fd' has events, which function will be
> >> wakeup?
> >
> > Roughly speaking, aio_poll is used for synchronous IO and within I/O
> > threads; aio_ctx_dispatch is used within the main thread.
> >
> > Both end up calling aio_dispatch_handlers and timerlistgroup_run_timers.
> >
> > Paolo
> >
>
>
>
prev parent reply other threads:[~2018-12-20 8:35 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CAKXe6SK+Pm8hGh=BXQ8FosVd=s4S+oc4moxJOjOq5HNeoG5Jcw@mail.gmail.com>
2018-12-19 10:05 ` [Qemu-devel] Question about aio_poll and glib aio_ctx_dispatch Li Qiang
2018-12-19 20:41 ` Paolo Bonzini
2018-12-19 22:58 ` [Qemu-devel] 答复: " Li Qiang
2018-12-20 1:25 ` [Qemu-devel] " Fam Zheng
2018-12-20 8:34 ` Li Qiang [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=CAKXe6SJo1uRf6YXfTsKuQdnmFM_iAijSGpdAwG0TRTxbceMd5Q@mail.gmail.com \
--to=liq3ea@gmail.com \
--cc=fam@euphon.net \
--cc=liq3ea@163.com \
--cc=pbonzini@redhat.com \
--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).