kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: Valdis.Kletnieks@vt.edu (Valdis.Kletnieks at vt.edu)
To: kernelnewbies@lists.kernelnewbies.org
Subject: atomic operations
Date: Sun, 24 Feb 2013 18:24:21 -0500	[thread overview]
Message-ID: <6017.1361748261@turing-police.cc.vt.edu> (raw)
In-Reply-To: Your message of "Sun, 24 Feb 2013 11:50:14 +0100." <CAFLxGvxAAg37U-WXq2LX8J9Qs4XvRoJymeVZytyp8LjgN2Tiug@mail.gmail.com>

On Sun, 24 Feb 2013 11:50:14 +0100, richard -rw- weinberger said:
> On Sun, Feb 24, 2013 at 10:42 AM, Shraddha Kamat <sh2008ka@gmail.com> wrote:
> > what is the relation between atomic operations and memory alignment ?
> >
> > I read from UTLK that "an unaligned memory access is not atomic"
> >
> > please explain me , I am not able to get the relationship between
> > memory alignment and atomicity of the operation.
>
> Not all CPUs support unaligned memory access, such an access may cause a fault
> which needs to be fixed by the kernel...

There's a more subtle issue - an unaligned access can be split across a cache
line boundary, requiring 2 separate memory accesses to do the read or write.
This can result in CPU A fetching the first half of the variable, CPU B
updating both halves, and then A fetching the second half of the now updated
variable.. This can bite you even on CPUs that support unaligned accesses.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 865 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130224/d2bc34b0/attachment.bin 

  reply	other threads:[~2013-02-24 23:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-24  9:42 atomic operations Shraddha Kamat
2013-02-24 10:50 ` richard -rw- weinberger
2013-02-24 23:24   ` Valdis.Kletnieks at vt.edu [this message]
2013-02-24 12:50 ` Peter Teoh
2013-02-24 12:53   ` Peter Teoh
2013-02-25  7:15     ` Kumar amit mehta
2013-03-01  5:44   ` Arun KS

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=6017.1361748261@turing-police.cc.vt.edu \
    --to=valdis.kletnieks@vt.edu \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).