public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
From: Josh Stone <jistone@redhat.com>
To: Martin Martin <martin@infinio.com>
Cc: systemtap@sourceware.org
Subject: Re: DTRACE_PROBE and optimization
Date: Thu, 12 Sep 2013 18:09:00 -0000	[thread overview]
Message-ID: <5232035A.3080201@redhat.com> (raw)
In-Reply-To: <CAAQ0mPhMP8dA_b5++ZOFLKcdOYaVZY5G-zJRzNqTCSTk=YXOpw@mail.gmail.com>

On 09/12/2013 08:25 AM, Martin Martin wrote:
> Hi all,
> 
> In a user space program, I'm hoping to use DTRACE_PROBE for fault
> injection like this:
> 
> bool doFault = false;
> DTRACE_PROBE1(provider, mark_name, &doFault);
> if (doFault) {
>    ... inject my fault ...
> }
> 
> If DTRACE_PROBE1() compiles to a NOOP, can I be sure the compiler
> won't think doFault is always false and optimize out the if statement?

It's a tricky question, but the direct answer is that the compiler
likely will do just as you say, assume false and optimize that out.  It
certainly does when I put your code in a simple test case.

Stripping a lot of detail, that probe essentially becomes:
  __asm__ __volatile__ ("nop" :: "nor" (&doFault));

This is a NOP with no output constraints, and the input constraint "nor"
means it can be a number, offsettable memory, or a register.  Because
there's no output, the compiler can't see any way that the value might
change, so it freely propagates the "false" constant.

There are ways we could make this work in general, especially a "memory"
clobber list, but that would have a much higher impact on code
generation for all SDT consumers.  Maybe we could make this opt-in, like
a "#define SDT_CLOBBERS_MEMORY 1" for consumers like you.

Or for your specific example, you could declare doFault volatile, which
will also solve your optimization problem.


We do have a similar bug filed already:
  https://sourceware.org/bugzilla/show_bug.cgi?id=12239
... but unfortunately there's no discussion captured.  I do remember
talking about this with Roland though, so it might be in the mailing
list archives.  IIRC he said pretty much what I mentioned above, that
only a "memory" clobber would help, but that's too costly for general
SDT applications.

      reply	other threads:[~2013-09-12 18:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-12 15:25 Martin Martin
2013-09-12 18:09 ` Josh Stone [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=5232035A.3080201@redhat.com \
    --to=jistone@redhat.com \
    --cc=martin@infinio.com \
    --cc=systemtap@sourceware.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 read-only IMAP folder(s) and NNTP newsgroup(s).