All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Hopwood <david.nospam.hopwood@blueyonder.co.uk>
To: xen-devel@lists.sourceforge.net
Subject: Re: x86-64 tools fix question
Date: Wed, 02 Mar 2005 06:40:59 +0000	[thread overview]
Message-ID: <42255FFB.2030900@blueyonder.co.uk> (raw)
In-Reply-To: <1109707006.13010.15.camel@thinkpad>

Jerone Young wrote:
> In the tools there is a declaration:
> 
> #if defined(__i386__)
> #define rmb() __asm__ __volatile__ ( "lock; addl $0,0(%%esp)" : : :
> "memory" )
> #define wmb() __asm__ __volatile__ ( "" : : : "memory" )
> #else
> #error "Define barriers"
> #endif
> 
> located in:
> 	xcs/xcs.h
> 	tools/python/xen/lowlevel/xu/xu.c
> 	
> 	I'm assuming this has a convenient side-effect that it prevents read
> reordering. Otherwise I can't figure out why this is being done at all.
> Now I'm guessing that that using rsp instead of esp since we are in
> 64bit mode will give the same effect needed.
> 
> #elif defined(__x86_64__)
> #define rmb() __asm__ __volatile__ ( "lock; addl $0,0(%%rsp)" : : :
> "memory" )
> #define wmb() __asm__ __volatile__ ( "" : : : "memory" )
> 
> 	I would like to discuss is this correct, dead wrong, or even needed at
> all?

See volume 1, section 3.9.2 of the AMD64 architecture manual
(http://www.amd.com/us-en/Processors/DevelopWithAMD/0,,30_2252_875_7044,00.html),
quoted below for convenience.

This should be guaranteed to work:

#define rmb() __asm__ __volatile__ ( "mfence" : : : "memory" )
#define wmb() __asm__ __volatile__ ( "mfence" : : : "memory" )

but may be overkill. Are these macros used in any performance-critical
situations? If not then the overkill wouldn't matter.

# 3.9.2 Forcing Memory Order
#
# Special instructions are provided for application software to force
# memory ordering in situations where such ordering is important. These
# instructions are:
#  * Load Fence -- The LFENCE instruction forces ordering of
#    memory loads (reads). All memory loads preceding the
#    LFENCE (in program order) are completed prior to
#    completing memory loads following the LFENCE. Memory
#    loads cannot be reordered around an LFENCE instruction,
#    but other non-serializing instructions (such as memory
#    writes) can be reordered around the LFENCE.
#  * Store Fence -- The SFENCE instruction forces ordering of
#    memory stores (writes). All memory stores preceding the
#    SFENCE (in program order) are completed prior to
#    completing memory stores following the SFENCE. Memory
#    stores cannot be reordered around an SFENCE instruction,
#    but other non-serializing instructions (such as memory
#    loads) can be reordered around the SFENCE.
#  * Memory Fence -- The MFENCE instruction forces ordering of
#    all memory accesses (reads and writes). All memory accesses
#    preceding the MFENCE (in program order) are completed
#    prior to completing any memory access following the
#    MFENCE. Memory accesses cannot be reordered around an
#    MFENCE instruction, but other non-serializing instructions
#    that do not access memory can be reordered around the
#    MFENCE.

-- 
David Hopwood <david.nospam.hopwood@blueyonder.co.uk>



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click

  parent reply	other threads:[~2005-03-02  6:40 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-01 19:56 x86-64 tools fix question Jerone Young
2005-03-01 20:37 ` Keir Fraser
2005-03-01 21:23   ` Anthony Liguori
2005-03-01 22:24     ` [PATCH] cpu barriers moved and x86-64 barriers add Jerone Young
2005-03-02 17:27       ` Jerone Young
2005-03-02  6:40 ` David Hopwood [this message]
2005-03-02  6:52   ` x86-64 tools fix question Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=42255FFB.2030900@blueyonder.co.uk \
    --to=david.nospam.hopwood@blueyonder.co.uk \
    --cc=xen-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.