From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38473) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1alcmu-00035F-QY for qemu-devel@nongnu.org; Thu, 31 Mar 2016 09:37:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1alcmp-0000bo-RB for qemu-devel@nongnu.org; Thu, 31 Mar 2016 09:37:28 -0400 Received: from mail-wm0-x231.google.com ([2a00:1450:400c:c09::231]:36889) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1alcmp-0000bc-DP for qemu-devel@nongnu.org; Thu, 31 Mar 2016 09:37:23 -0400 Received: by mail-wm0-x231.google.com with SMTP id p65so115104974wmp.0 for ; Thu, 31 Mar 2016 06:37:23 -0700 (PDT) References: <56FC0818.10002@linaro.org> <56FC174A.6070906@redhat.com> <56FD22A5.10501@gmail.com> From: Alex =?utf-8?Q?Benn=C3=A9e?= In-reply-to: <56FD22A5.10501@gmail.com> Date: Thu, 31 Mar 2016 14:37:24 +0100 Message-ID: <87wpoig44r.fsf@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] tcg: reworking tb_invalidated_flag List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Sergey Fedorov Cc: Paolo Bonzini , Peter Crosthwaite , QEMU Developers , Sergey Fedorov , Richard Henderson Sergey Fedorov writes: > On 30/03/16 21:13, Paolo Bonzini wrote: >> >> On 30/03/2016 19:08, Sergey Fedorov wrote: >>> The second approach is to make 'tb_invalidated_flag' per-CPU. This >>> would be conceptually similar to what we have, but would give us thread >>> safety. With this approach, we need to be careful to correctly clear and >>> set the flag. >> You can just ensure that setting and clearing it is done under tb_lock. > > So it could remain sitting in 'tcg_ctx.tb_ctx'. I'm just wondering what > could be real benefits for making it per-CPU then? > >> Because TranslationBlocks live in tcg_ctx.tb_ctx.tbs you need >> special code to exit all CPUs at tb_flush time, otherwise you risk that >> a tb_alloc reuses a TranslationBlock while it is in use by a VCPU. > > Looks like no matter which approach we use, it's ultimately necessary to > ensure all CPUs have exited from translated code before the translation > buffer may be safely flushed. One approach would be to have multiple translation contexts with their own buffers and then you can safely flush TBs if no vCPUs are currently executing in those regions. But I suspect that is a much more complex future optimisation. Having said that is it safe to flush TBs from a given page if we know no vCPUs are currently executing in that page? As the execution loop has to exit the chained TBs as we cross page boundaries we could just keep account of which vCPUs are currently in which page. -- Alex Bennée