qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] Question about aio_poll and glib aio_ctx_dispatch


From: Fam Zheng
Subject: Re: [Qemu-devel] Question about aio_poll and glib aio_ctx_dispatch
Date: Thu, 20 Dec 2018 09:25:53 +0800


> On Dec 20, 2018, at 06:58, Li Qiang <address@hidden> 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?


I think in this case BQL is used to synchronize them so when v9fs_reset runs, 
the main loop doesn't.

Thanks,
Fam

> 
> Thanks,
> Li Qiang
> 
> 
> 发件人: Paolo Bonzini
> 发送时间: 2018年12月20日 4:42
> 收件人: Li Qiang; address@hidden; address@hidden; 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 <address@hidden <mailto:address@hidden>> 于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
> 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]