From owner-freebsd-hackers@FreeBSD.ORG Wed Sep 26 09:55:47 2012 Return-Path: Delivered-To: freebsd-hackers@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3C5AE106564A for ; Wed, 26 Sep 2012 09:55:47 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from citadel.icyb.net.ua (citadel.icyb.net.ua [212.40.38.140]) by mx1.freebsd.org (Postfix) with ESMTP id 4AA1C8FC08 for ; Wed, 26 Sep 2012 09:55:45 +0000 (UTC) Received: from porto.starpoint.kiev.ua (porto-e.starpoint.kiev.ua [212.40.38.100]) by citadel.icyb.net.ua (8.8.8p3/ICyb-2.3exp) with ESMTP id MAA19735; Wed, 26 Sep 2012 12:55:43 +0300 (EEST) (envelope-from avg@FreeBSD.org) Received: from localhost ([127.0.0.1]) by porto.starpoint.kiev.ua with esmtp (Exim 4.34 (FreeBSD)) id 1TGoLH-000CXo-Gc; Wed, 26 Sep 2012 12:55:43 +0300 Message-ID: <5062D11D.7040809@FreeBSD.org> Date: Wed, 26 Sep 2012 12:55:41 +0300 From: Andriy Gapon User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:15.0) Gecko/20120913 Thunderbird/15.0.1 MIME-Version: 1.0 To: Konstantin Belousov References: <5062B971.30203@FreeBSD.org> <20120926091057.GH35915@deviant.kiev.zoral.com.ua> In-Reply-To: <20120926091057.GH35915@deviant.kiev.zoral.com.ua> X-Enigmail-Version: 1.4.3 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: freebsd-hackers Subject: Re: monitor+mwait and volatile-ish X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Sep 2012 09:55:47 -0000 on 26/09/2012 12:10 Konstantin Belousov said the following: > On Wed, Sep 26, 2012 at 11:14:41AM +0300, Andriy Gapon wrote: [snip] >> So what's my point. - using volatile variable with cpu_monitor requires >> DEVOLATILE to silence compiler warning about discarding volatile; this is >> unnecessary code bloat - adding volatile cast in the checks is easy to >> forget and adds code bloat >> >> Possible improvements: - make the argument of cpu_monitor be 'const >> volatile void *', the most permissive type; this would also be a hint >> that variable should be volatile - add some magic dust to cpu_monitor >> that would tell compiler to not cache the variable; right now I can only >> think of the "memory" constraint, but it seems to be too big of a hummer >> >> What do you think about this? > > You might claim that the asm writes to *addr by specifying it in the output > constraint. This should fool the compiler into reload *addr after the > monitor execution. > You mean something like: static __inline void cpu_monitor(const void *addr, u_long extensions, u_int hints) { __asm __volatile("monitor" : "=m" (*(char *)addr) : "a" (addr), "c" (extensions), "d" (hints)); } This seems to do the job with base gcc, 4.6, 4.7 and clang. Thank you! -- Andriy Gapon