From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O6rZF-0002OB-1e for qemu-devel@nongnu.org; Tue, 27 Apr 2010 16:39:41 -0400 Received: from [140.186.70.92] (port=33404 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O6rZD-0002Mg-1y for qemu-devel@nongnu.org; Tue, 27 Apr 2010 16:39:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O6rZB-0005Af-Bi for qemu-devel@nongnu.org; Tue, 27 Apr 2010 16:39:38 -0400 Received: from ey-out-1920.google.com ([74.125.78.150]:1861) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O6rZ8-0005AN-W5 for qemu-devel@nongnu.org; Tue, 27 Apr 2010 16:39:36 -0400 Received: by ey-out-1920.google.com with SMTP id 5so447208eyb.14 for ; Tue, 27 Apr 2010 13:39:34 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: Date: Tue, 27 Apr 2010 16:39:33 -0400 Message-ID: Subject: Re: [Qemu-devel] thread synchronization in qcow2.c and qcow2-cluster.c From: "Chunqiang (CQ) Tang" Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi , qemu-devel@nongnu.org > kvm-all.c:kvm_cpu_exec: > =A0 =A0 =A0 =A0qemu_mutex_unlock_iothread(); > =A0 =A0 =A0 =A0ret =3D kvm_vcpu_ioctl(env, KVM_RUN, 0); > =A0 =A0 =A0 =A0qemu_mutex_lock_iothread(); Thank you for the information. I also suspected that qemu_mutex_lock_iothread() does the synchronization. However, my profiling showed that qemu-kvm.c:kvm_cpu_exec() in is actually executed, instead of kvm-all.c:kvm_cpu_exec(). Also I previously profiled all executions of qemu_mutex_lock_iothread(), and found that it only protects the vl.c:main_loop_wai() thread but does NOT protect the qemu-kvm.c:kvm_cpu_exec() thread. Did I miss something or is this a defect? I did extensive profiling but still don't know the source code well enough to confidently draw a conclusion. For example, see the profiled execution sequence below. The kvm_cpu_exec() thread did not perform qemu_mutex_lock_iothread(). The locking was only performed by the vl.c:main_loop_wai() thread. home/ctang/kvm/qemu-kvm-0.12.3/qemu-kvm.c : 2530 thread: b7e056d0 /home/ctang/kvm/bin/qemu-system-x86_64(qemu_mutex_unlock_iothread+0= x1a) [0x8092242] /home/ctang/kvm/bin/qemu-system-x86_64(main_loop_wait+0x221) [0x806= edef] /home/ctang/kvm/bin/qemu-system-x86_64(kvm_main_loop+0x1ff) [0x8091= 6a1] /home/ctang/kvm/bin/qemu-system-x86_64 [0x806f5c2] /home/ctang/kvm/bin/qemu-system-x86_64(main+0x2e2c) [0x80736d1] /lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe5) [0xb7e33775] /home/ctang/kvm/bin/qemu-system-x86_64 [0x8068bb1] block/qcow2-cluster.c : 721 thread: b7dc2b90 /home/ctang/kvm/bin/qemu-system-x86_64(qcow2_alloc_cluster_offset+0= x3c) [0x81175fa] /home/ctang/kvm/bin/qemu-system-x86_64(qcow_aio_write_cb+0x158) [0x8111d73] /home/ctang/kvm/bin/qemu-system-x86_64(qcow_aio_writev+0x94) [0x811= 2054] /home/ctang/kvm/bin/qemu-system-x86_64(bdrv_aio_writev+0xe1) [0x80f= a8e9] /home/ctang/kvm/bin/qemu-system-x86_64 [0x81f4a96] /home/ctang/kvm/bin/qemu-system-x86_64 [0x81f4c04] /home/ctang/kvm/bin/qemu-system-x86_64(dma_bdrv_write+0x48) [0x81f4= cbf] /home/ctang/kvm/bin/qemu-system-x86_64 [0x80a437c] /home/ctang/kvm/bin/qemu-system-x86_64(bmdma_cmd_writeb+0x73) [0x80a9503] /home/ctang/kvm/bin/qemu-system-x86_64 [0x812b1eb] /home/ctang/kvm/bin/qemu-system-x86_64(cpu_outb+0x27) [0x812b4e6] /home/ctang/kvm/bin/qemu-system-x86_64 [0x808d267] /home/ctang/kvm/bin/qemu-system-x86_64(kvm_run+0x2f4) [0x808f4b8] /home/ctang/kvm/bin/qemu-system-x86_64(kvm_cpu_exec+0x56) [0x80907b= 2] /home/ctang/kvm/bin/qemu-system-x86_64 [0x8090f4d] /home/ctang/kvm/bin/qemu-system-x86_64 [0x8091098] /lib/tls/i686/cmov/libpthread.so.0 [0xb7fd24ff] /lib/tls/i686/cmov/libc.so.6(clone+0x5e) [0xb7f0149e] /home/ctang/kvm/qemu-kvm-0.12.3/qemu-kvm.c : 2537 thread: b7e056d0 /home/ctang/kvm/bin/qemu-system-x86_64(qemu_mutex_lock_iothread+0x1= a) [0x809229d] /home/ctang/kvm/bin/qemu-system-x86_64(main_loop_wait+0x25c) [0x806= ee2a] /home/ctang/kvm/bin/qemu-system-x86_64(kvm_main_loop+0x1ff) [0x8091= 6a1] /home/ctang/kvm/bin/qemu-system-x86_64 [0x806f5c2] /home/ctang/kvm/bin/qemu-system-x86_64(main+0x2e2c) [0x80736d1] /lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe5) [0xb7e33775] /home/ctang/kvm/bin/qemu-system-x86_64 [0x8068bb1]