All of lore.kernel.org
 help / color / mirror / Atom feed
From: der.herr@hofr.at (Nicholas Mc Guire)
To: kernelnewbies@lists.kernelnewbies.org
Subject: spinlock variable protection
Date: Sat, 31 Jan 2015 13:04:20 +0100	[thread overview]
Message-ID: <20150131120420.GA21819@opentech.at> (raw)
In-Reply-To: <CAJs94EZK6PAT6RbkuAvJgdNce_6WananEJ06NAC6vJirro1hMw@mail.gmail.com>

On Fri, 30 Jan 2015, Matwey V. Kornilov wrote:

> 2015-01-30 16:52 GMT+03:00 buyitian <buyitian@gmail.com>:
> >>
> > Please check the assembly code to double confirm the GCC behavior.
> > Why will GCC change the order as what you mentioned? Only assembly code can tell you.
> 
> It does not change at the moment. I think it can change it.
> 
> Because from line
>   ret = hdl->count;
> until line
>   return ret;
> there is no access to either ret or hdl->count. So it is reasonable to
> optimizer to think that their values are the same and eliminate
> unneeded variable.
>
If your worry is that it will optimize it out then pack it into
an ACCESS_ONCE and that should prevent GCC from doing so.
for your case I think ret = ACCESS_ONCE(hdl->count);
would be sufficient.

thx!
hofrat 

      parent reply	other threads:[~2015-01-31 12:04 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-30 12:43 spinlock variable protection Matwey V. Kornilov
2015-01-30 13:52 ` buyitian
2015-01-30 14:20   ` Matwey V. Kornilov
2015-01-30 15:23     ` Malte Vesper
2015-01-30 15:29       ` Matwey V. Kornilov
2015-01-31  6:23       ` Arun KS
2015-01-31 12:04     ` Nicholas Mc Guire [this message]

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=20150131120420.GA21819@opentech.at \
    --to=der.herr@hofr.at \
    --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 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.