From patchwork Fri Jul 1 08:56:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sergey Fedorov X-Patchwork-Id: 9209505 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D249E607D8 for ; Fri, 1 Jul 2016 08:57:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C261528690 for ; Fri, 1 Jul 2016 08:57:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B6D83286A2; Fri, 1 Jul 2016 08:57:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3A88728690 for ; Fri, 1 Jul 2016 08:57:11 +0000 (UTC) Received: from localhost ([::1]:54523 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bIuG6-0000Ay-H5 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 01 Jul 2016 04:57:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38727) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bIuFq-0000Ae-1E for qemu-devel@nongnu.org; Fri, 01 Jul 2016 04:56:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bIuFj-0002oi-Uy for qemu-devel@nongnu.org; Fri, 01 Jul 2016 04:56:51 -0400 Received: from mail-lf0-x241.google.com ([2a00:1450:4010:c07::241]:33815) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bIuFj-0002nE-I2 for qemu-devel@nongnu.org; Fri, 01 Jul 2016 04:56:47 -0400 Received: by mail-lf0-x241.google.com with SMTP id l184so10726458lfl.1 for ; Fri, 01 Jul 2016 01:56:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=IjVfDhBm8tHQlbzYysPJjKvPGbkVlKwpAmkH6CUSOVw=; b=OnZg11fXCsWHAnYqcwBFhO7TcT4MUpFbNBz3p1eXBAWAUgrITxb1UZHItdKyACoJpr JZZqScWEt8n1lqkL5EMHinMaH15Eh8n/A6nP5M12Y9OmaFCuvBOuGmz117USV4l0bOm0 xeznI+S8oIfpeLgt/+kC65H3YPnyKfLNLe0+10LBWIIo7/k2D5TBsyqLfSDdmep0iESe UzSiKGsouK3RvB1RExuHhVcfF0ykrENf9GotI7NOdJx5QZ7IpWo7b5mPATLh6AqwqlQj 4ILSzMn80AelxcRDFvsJw55v7wjvr1MxljAaBKzA/BfuhyvMfY/spyHZGJryjVYkvpy4 JhCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=IjVfDhBm8tHQlbzYysPJjKvPGbkVlKwpAmkH6CUSOVw=; b=Jf69QJ0URT3qss8YXqWWp93hYggQ6wWTMeVRRGGKkXZI3YzJ4osIVLTcdUos5xM+jg xN7IpKUM8HlMNBdWY1ZyL5djuiqN6VS4ne9qyE6gTOkBoelP74sYc0bmeAdaRdrnHtpF A6U/1Hwv8y32QDKjTZGOQbrDOZJsbe1T/u4pZp7HFBdr4dOPl0xkRMh+WDUu2VbRAAs1 hSCH4rFCeSBdcX2Qzx/m+Guou9bWWBcKdnDG1hU4FHDSQKS/WVFgi3dqbi0icsiBzU+Z mnd7CURsJi7oSBgYGOQSeaKwOBnB/TjwT0/5nmRvlST3CZy6OQSn6bMqgHRLTY0ilb0U Ssfg== X-Gm-Message-State: ALyK8tLP4lGggnTwlwsF/oHs3+wKyoeRObg5sH4YkTKZ4KL6swuwDggPFYkzrQGV7kigDA== X-Received: by 10.25.169.195 with SMTP id s186mr5320340lfe.84.1467363403824; Fri, 01 Jul 2016 01:56:43 -0700 (PDT) Received: from [192.168.0.65] (broadband-46-188-121-154.2com.net. [46.188.121.154]) by smtp.gmail.com with ESMTPSA id 4sm2199840ljf.9.2016.07.01.01.56.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Jul 2016 01:56:42 -0700 (PDT) To: =?UTF-8?Q?Alex_Benn=c3=a9e?= References: <1466375313-7562-1-git-send-email-sergey.fedorov@linaro.org> <1466375313-7562-7-git-send-email-sergey.fedorov@linaro.org> <87lh1o0y1k.fsf@linaro.org> <5774E8C2.1050506@gmail.com> <87furvq85v.fsf@linaro.org> <5774F60C.3010707@gmail.com> From: Sergey Fedorov Message-ID: <57763049.2090800@gmail.com> Date: Fri, 1 Jul 2016 11:56:41 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 MIME-Version: 1.0 In-Reply-To: <5774F60C.3010707@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c07::241 Subject: Re: [Qemu-devel] [RFC 6/8] linux-user: Support CPU work queue X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Crosthwaite , Sergey Fedorov , patches@linaro.org, Riku Voipio , qemu-devel@nongnu.org, Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP On 30/06/16 13:35, Sergey Fedorov wrote: > On 30/06/16 13:32, Alex Bennée wrote: >> Sergey Fedorov writes: >> >>> On 29/06/16 19:17, Alex Bennée wrote: >>>> So I think there is a deadlock we can get with the async work: >>>> >>>> (gdb) thread apply all bt >>>> >>>> Thread 11 (Thread 0x7ffefeca7700 (LWP 2912)): >>>> #0 pthread_cond_wait@@GLIBC_2.3.2 () at ../sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S:185 >>>> #1 0x00005555555cb777 in wait_cpu_work () at /home/alex/lsrc/qemu/qemu.git/linux-user/main.c:155 >>>> #2 0x00005555555a0cee in wait_safe_cpu_work () at /home/alex/lsrc/qemu/qemu.git/cpu-exec-common.c:87 >>>> #3 0x00005555555cb8fe in cpu_exec_end (cpu=0x555555bb67e0) at /home/alex/lsrc/qemu/qemu.git/linux-user/main.c:222 >>>> #4 0x00005555555cc7a7 in cpu_loop (env=0x555555bbea58) at /home/alex/lsrc/qemu/qemu.git/linux-user/main.c:749 >>>> #5 0x00005555555db0b2 in clone_func (arg=0x7fffffffc9c0) at /home/alex/lsrc/qemu/qemu.git/linux-user/syscall.c:5424 >>>> #6 0x00007ffff6bed6fa in start_thread (arg=0x7ffefeca7700) at pthread_create.c:333 >>>> #7 0x00007ffff6923b5d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109 >>>> >>>> >>>> >>>> Thread 3 (Thread 0x7ffff7f38700 (LWP 2904)): >>>> #0 0x00005555555faf5d in safe_syscall_base () >>>> #1 0x00005555555cfeaf in safe_futex (uaddr=0x7ffff528a0a4, op=128, val=1, timeout=0x0, uaddr2=0x0, val3=-162668384) >>>> at /home/alex/lsrc/qemu/qemu.git/linux-user/syscall.c:706 >>>> #2 0x00005555555dd7cc in do_futex (uaddr=4132298916, op=128, val=1, timeout=0, uaddr2=0, val3=-162668384) >>>> at /home/alex/lsrc/qemu/qemu.git/linux-user/syscall.c:6246 >>>> #3 0x00005555555e8cdb in do_syscall (cpu_env=0x555555a81118, num=240, arg1=-162668380, arg2=128, arg3=1, arg4=0, arg5=0, arg6=-162668384, >>>> arg7=0, arg8=0) at /home/alex/lsrc/qemu/qemu.git/linux-user/syscall.c:10642 >>>> #4 0x00005555555cd20e in cpu_loop (env=0x555555a81118) at /home/alex/lsrc/qemu/qemu.git/linux-user/main.c:883 >>>> #5 0x00005555555db0b2 in clone_func (arg=0x7fffffffc9c0) at /home/alex/lsrc/qemu/qemu.git/linux-user/syscall.c:5424 >>>> #6 0x00007ffff6bed6fa in start_thread (arg=0x7ffff7f38700) at pthread_create.c:333 >>>> #7 0x00007ffff6923b5d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109 >>>> >>>> So everything is stalled awaiting this thread waking up and draining >>>> its queue. So for linux-user I think we need some mechanism to kick >>>> these syscalls which I assume means throwing a signal at it. >>> Nice catch! How did you get it? >> Running pigz (armhf, debian) to compress stuff. >> >>> We always go through cpu_exec_end() >>> before serving a guest syscall and always go through cpu_exec_start() >>> before entering the guest code execution loop. If we always schedule >>> safe work on the current thread's queue then I think there's a way to >>> make it safe and avoid kicking syscalls. >> Not let the signals complete until safe work is done? > I'm thinking of waiting for completion of safe works in cpu_exec_start() > as well as in cpu_exec_end(). I found a mistake in my code which causes deadlocks in my run of pigz. Could you also try running it after applying the following patch? Thanks, Sergey diff --git a/linux-user/main.c b/linux-user/main.c index 6da3bb32186b..1dca55145c56 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -214,7 +214,7 @@ static inline void cpu_exec_end(CPUState *cpu) cpu->running = false; tcg_pending_cpus--; if (!tcg_pending_cpus) { - pthread_cond_broadcast(&exclusive_cond); + signal_cpu_work(); } exclusive_idle(); flush_queued_work(cpu);