From: "H. Peter Anvin" Subject: Re: [PATCH 1/1] x86: fix text_poke Date: Fri, 25 Apr 2008 11:47:42 -0700 Message-ID: <4812274E.9000001@zytor.com> References: <20080425151931.GA25510@elte.hu> <20080425152650.GA894@elte.hu> <20080425154854.GC3265@one.firstfloor.org> <20080425161916.GD3265@one.firstfloor.org> <20080425163035.GE9503@Krystal> <481209F2.4050908@zytor.com> <20080425170929.GA16180@Krystal> <20080425183748.GB16180@Krystal> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: Andi Kleen , Linus Torvalds , Ingo Molnar , Jiri Slaby , David Miller , zdenek.kabelac@gmail.com, rjw@sisk.pl, paulmck@linux.vnet.ibm.com, akpm@linux-foundation.org, linux-ext4@vger.kernel.org, herbert@gondor.apana.org.au, penberg@cs.helsinki.fi, clameter@sgi.com, linux-kernel@vger.kernel.org, pageexec@freemail.hu, Jeremy Fitzhardinge To: Mathieu Desnoyers Return-path: Received: from terminus.zytor.com ([198.137.202.10]:39518 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933593AbYDYTMt (ORCPT ); Fri, 25 Apr 2008 15:12:49 -0400 In-Reply-To: <20080425183748.GB16180@Krystal> Sender: linux-ext4-owner@vger.kernel.org List-ID: Mathieu Desnoyers wrote: > > Thinking about it, there could be a way to insure limited ZF and %al > liveliness: adding an epilogue to the expected instruction sequence > formed by an asm statement which clobbers the flags (flags are clobbered > in any asm statement on x86) and clobbers %al. > > From that point, we just have to find a specific signature that gcc > could not imitate to put in this asm statement, so we can detect if > other instructions have been placed in the middle of our sequence by > gcc. Actually, I think the best thing to do with this asm statement is > to put the instruction pointer in a special section, so we know that > this code location marks the end of ZF and %al liveliness. There would > be therefore no added code, just asm constraints. > > This epilogue should then be used on both branches of the condition, > like this : > > if (unlikely(imv_cond(var))) { > imv_cond_end(); > ... > } else { > imv_cond_end(); > ... > } > [...] > > Does it make sense ? > I don't think so. You're making way too many assumptions about the code generated by gcc. This kind of stuff absolutely can be done, *BUT* it requires the cooperation of the compiler. The right way to do this is to negotiate a set of appropriate builtins with the gcc people, and use them. This means this optimization will only work when compiled with the new gcc, so there is a substantial lag, but it's the only sane way to do this kind of stuff. -hpa