qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Hailiang Zhang <zhang.zhanghailiang@huawei.com>
To: Jason Wang <jasowang@redhat.com>, zhangchen.fnst@cn.fujitsu.com
Cc: xuquan8@huawei.com, qemu-devel@nongnu.org, weidong.huang@huawei.com
Subject: Re: [Qemu-devel] [PATCH 1/3] colo-compare: serialize compare thread's initialization with main thread
Date: Mon, 24 Apr 2017 14:03:50 +0800	[thread overview]
Message-ID: <58FD9546.5000104@huawei.com> (raw)
In-Reply-To: <df05a73b-fba8-a6d3-bf6a-648304458257@redhat.com>

On 2017/4/24 12:10, Jason Wang wrote:
>
> On 2017年04月20日 15:46, zhanghailiang wrote:
>> We call qemu_chr_fe_set_handlers() in colo-compare thread, it is used
>> to detach watched fd from default main context, so it has chance to
>> handle the same watched fd with main thread concurrently, which will
>> trigger an error report:
>> "qemu-char.c:918: io_watch_poll_finalize: Assertion `iwp->src == ((void *)0)' failed."
> Anyway to prevent fd from being handled by main thread before creating
> colo thread? Using semaphore seems not elegant.

So how about calling qemu_mutex_lock_iothread() before qemu_chr_fe_set_handlers() ?

> Thanks
>
>> Fix it by serializing compare thread's initialization with main thread.
>>
>> Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
>> ---
>>    net/colo-compare.c | 6 ++++++
>>    1 file changed, 6 insertions(+)
>>
>> diff --git a/net/colo-compare.c b/net/colo-compare.c
>> index 54e6d40..a6bf419 100644
>> --- a/net/colo-compare.c
>> +++ b/net/colo-compare.c
>> @@ -83,6 +83,7 @@ typedef struct CompareState {
>>        GHashTable *connection_track_table;
>>        /* compare thread, a thread for each NIC */
>>        QemuThread thread;
>> +    QemuSemaphore thread_ready;
>>    
>>        GMainContext *worker_context;
>>        GMainLoop *compare_loop;
>> @@ -557,6 +558,8 @@ static void *colo_compare_thread(void *opaque)
>>                              (GSourceFunc)check_old_packet_regular, s, NULL);
>>        g_source_attach(timeout_source, s->worker_context);
>>    
>> +    qemu_sem_post(&s->thread_ready);
>> +
>>        g_main_loop_run(s->compare_loop);
>>    
>>        g_source_unref(timeout_source);
>> @@ -707,12 +710,15 @@ static void colo_compare_complete(UserCreatable *uc, Error **errp)
>>                                                          connection_key_equal,
>>                                                          g_free,
>>                                                          connection_destroy);
>> +    qemu_sem_init(&s->thread_ready, 0);
>>    
>>        sprintf(thread_name, "colo-compare %d", compare_id);
>>        qemu_thread_create(&s->thread, thread_name,
>>                           colo_compare_thread, s,
>>                           QEMU_THREAD_JOINABLE);
>>        compare_id++;
>> +    qemu_sem_wait(&s->thread_ready);
>> +    qemu_sem_destroy(&s->thread_ready);
>>    
>>        return;
>>    }
>
> .
>

  reply	other threads:[~2017-04-24  6:04 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-20  7:46 [Qemu-devel] [PATCH 0/3] colo-compare: fix three bugs zhanghailiang
2017-04-20  7:46 ` [Qemu-devel] [PATCH 1/3] colo-compare: serialize compare thread's initialization with main thread zhanghailiang
2017-04-24  4:10   ` Jason Wang
2017-04-24  6:03     ` Hailiang Zhang [this message]
2017-04-25  8:41       ` Jason Wang
2017-04-25  9:59         ` Hailiang Zhang
2017-04-25 11:33           ` Jason Wang
2017-04-26  7:51             ` Hailiang Zhang
2017-05-04  2:51             ` Hailiang Zhang
2017-05-05  3:03               ` Jason Wang
2017-04-20  7:46 ` [Qemu-devel] [PATCH 2/3] colo-compare: Check main_loop value before call g_main_loop_quit zhanghailiang
2017-04-24  4:13   ` Jason Wang
2017-04-24  6:06     ` Hailiang Zhang
2017-04-20  7:46 ` [Qemu-devel] [PATCH 3/3] colo-compare: fix a memory leak zhanghailiang

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=58FD9546.5000104@huawei.com \
    --to=zhang.zhanghailiang@huawei.com \
    --cc=jasowang@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=weidong.huang@huawei.com \
    --cc=xuquan8@huawei.com \
    --cc=zhangchen.fnst@cn.fujitsu.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).