From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39133) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZTgVV-0002Zc-7D for qemu-devel@nongnu.org; Sun, 23 Aug 2015 21:25:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZTgVR-0000b5-R2 for qemu-devel@nongnu.org; Sun, 23 Aug 2015 21:25:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36581) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZTgVR-0000aM-Md for qemu-devel@nongnu.org; Sun, 23 Aug 2015 21:25:01 -0400 References: <1440375847-17603-1-git-send-email-cota@braap.org> <1440375847-17603-34-git-send-email-cota@braap.org> From: Paolo Bonzini Message-ID: <55DA7267.1000100@redhat.com> Date: Sun, 23 Aug 2015 18:24:55 -0700 MIME-Version: 1.0 In-Reply-To: <1440375847-17603-34-git-send-email-cota@braap.org> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [RFC 33/38] cpu: introduce cpu_tcg_sched_work to run work while other CPUs sleep List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Emilio G. Cota" , qemu-devel@nongnu.org, mttcg@greensocs.com Cc: guillaume.delbergue@greensocs.com, alex.bennee@linaro.org, mark.burton@greensocs.com, a.rigo@virtualopensystems.com, Frederic Konrad On 23/08/2015 17:24, Emilio G. Cota wrote: > This is similar in intent to the async_safe_work mechanism. The main > differences are: >=20 > - Work is run on a single CPU thread *after* all others are put to slee= p >=20 > - Sleeping threads are woken up by the worker thread upon completing it= s job >=20 > - A flag as been added to tcg_ctx so that only one thread can schedule > work at a time. The flag is checked every time tb_lock is acquired. >=20 > - Handles the possibility of CPU threads being created after the existi= ng > CPUs are put to sleep. This is easily triggered with many threads on > a many-core host in usermode. >=20 > - Works for both softmmu and usermode >=20 > Signed-off-by: Emilio G. Cota I think this is a duplicate of the existing run_on_cpu code. If needed in user-mode emulation, it should be extracted out of cpus.c. Also I think it is dangerous (prone to deadlocks) to wait for other CPUs with synchronize_cpu and condvar. I would much rather prefer to _halt_ the CPUs if there is pending work, and keep it halted like this: static inline bool cpu_has_work(CPUState *cpu) { CPUClass *cc =3D CPU_GET_CLASS(cpu); + if (tcg_ctx.tb_ctx.tcg_has_work) { + return false; + } g_assert(cc->has_work); return cc->has_work(cpu); } You can then run flush_queued_work from linux-user/main.c (and bsd-user/main.c) when cpu_exec returns EXCP_HALTED. Paolo