From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59422) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bMcAv-0003Kb-54 for qemu-devel@nongnu.org; Mon, 11 Jul 2016 10:27:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bMcAq-0004ry-Sy for qemu-devel@nongnu.org; Mon, 11 Jul 2016 10:27:08 -0400 Received: from mail-lf0-x22e.google.com ([2a00:1450:4010:c07::22e]:34105) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bMcAq-0004ro-GA for qemu-devel@nongnu.org; Mon, 11 Jul 2016 10:27:04 -0400 Received: by mail-lf0-x22e.google.com with SMTP id h129so74997171lfh.1 for ; Mon, 11 Jul 2016 07:27:04 -0700 (PDT) References: <1467735496-16256-7-git-send-email-alex.bennee@linaro.org> <1467909880-18834-1-git-send-email-sergey.fedorov@linaro.org> <1467909880-18834-4-git-send-email-sergey.fedorov@linaro.org> <71295249.5198305.1467967205882.JavaMail.zimbra@redhat.com> <577F7F7D.4010207@gmail.com> <1711483720.5250530.1467975750519.JavaMail.zimbra@redhat.com> <577F9D69.3050600@gmail.com> <5677f192-7367-bf1a-353f-1b0678b1c8fb@redhat.com> <57800533.2070303@gmail.com> <75bb3f61-0b90-1805-1d21-8e83377e133f@redhat.com> <57800C09.30808@gmail.com> <0c04b00b-55d0-46e2-8a21-c364d2939198@redhat.com> <578399C1.6090108@gmail.com> From: Sergey Fedorov Message-ID: <5783ACB5.4050404@gmail.com> Date: Mon, 11 Jul 2016 17:27:01 +0300 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 3/3] tcg: Avoid bouncing tb_lock between tb_gen_code() and tb_add_jump() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: mttcg@greensocs.com, peter maydell , claudio fontana , Sergey Fedorov , patches@linaro.org, jan kiszka , Peter Crosthwaite , mark burton , qemu-devel@nongnu.org, a rigo , cota@braap.org, bobby prani , rth@twiddle.net, =?UTF-8?Q?Alex_Benn=c3=a9e?= , fred konrad On 11/07/16 17:03, Paolo Bonzini wrote: > > On 11/07/2016 15:06, Sergey Fedorov wrote: >> On 08/07/16 23:52, Paolo Bonzini wrote: >>> On 08/07/2016 22:24, Sergey Fedorov wrote: >>>> I remember, I've just found that we discussed it in this thread: >>>> >>>> http://thread.gmane.org/gmane.comp.emulators.qemu/401723/focus=406852 >>>> >>>> I was thinking of just doing 'tb_jmp_cache' lookup out of the lock, not >>>> tb_find_physical(). Now thanks to QHT, we could do tb_find_physical() >>>> out of the lock, too. This changes things. >>> But in my patch ("tcg: move tb_find_fast outside the tb_lock critical >>> section", which originally was written by Fred---most of my contribution >>> was getting the invalidation right, not the lock-free lookup) >>> tb_find_physical was also done out of the lock. It was then retried >>> inside the lock, if it failed. >>> >>> This is why I needed to fail all concurrent lookups as the first step in >>> the invalidation. >>> >>> Emilio's QHT resulted in a rewrite of tb_find_physical, but the basic >>> concepts are the same. >> That could work, I think, if we re-check under tb_lock whether the TB is >> still valid before adding a direct jump to it. > Right, this can still happen: > > tb_find_fast tb_phys_invalidate > tb_lock > jmp_cache miss > -> tb_find_slow > -> tb_find_physical > QHT hit > tb_lock > invalidate tb->pc > remove from lists > tb_unlock > tb_add_jump > tb_unlock > > I seem to recall that Emilio added a seqlock for this purpose, but > adding a tb_check_invalidated(TranslationBlock *tb) inline function will > also do. He used seqlock for 'tb_jmp_cache' only: http://thread.gmane.org/gmane.comp.emulators.qemu/356765/focus=356774 He also added a dedicated field into TranslationBlock struction to mark it invalid: http://thread.gmane.org/gmane.comp.emulators.qemu/356765/focus=356785 Kind regards, Sergey