<html><body><div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: #000000"><div><span id="zwchr" data-marker="__DIVIDER__">---- On Nov 17, 2016, at 10:34 AM, Evgeny Roubinchtein <zhenya1007@gmail.com> wrote:<br></span></div><div data-marker="__QUOTED_TEXT__"><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><div dir="ltr">Dear LTTNG users and developers,<br><div>I would like to know how the tracepoint macro interacts with the compiler's code optimizer (I am specifically interested in GCC 4.9 if that makes a difference).  </div><br><div>Suppose I add a tracepoint to the section of code that the optimizer would have eliminated, and then compile with optimization.  What happens?  Does the optimizer eliminate the statement(s) that the tracepoint macro expands to?  Or does the tracepoint macro do something to force the optimizer to keep the statement(s) in? (e.g., declare some variable volatile, or some moral equivalent).</div></div></blockquote><div>If you put a tracepoint in dead code, it will prevent dead code elimination, because</div><div> the code is not dead anymore: it now has a side-effect, which is to call the tracepoint</div><div>callbacks if there are any ever connected. Also, reading the "state" variable is done<br></div><div>with a volatile load, which is considered as another side-effect.<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><div dir="ltr"><div>Now essentially the same question about local variables.  To make things simple, let's imagine that my tracepoint definition has a single variable declared inside TP_ARGS, i.e., something like:</div><div>TRACEPOINT_EVENT (<br></div><div>      my_provider,  my_trace_point</div><div>      TP_ARGS (int, foo_arg),</div><div>       TP_FIELDS( ctf_integer(int, foo, foo_arg)))</div><div>Let's also imagine that, in my code, I have an automatic local variable, (let's call it `bar`) that would normally be "optimized out", and I add a tracepoint statement that references "bar", and compile with optimization.  What happens?  Specifically, can it happen that the optimizer is now prevented from "optimizing out" `bar`, and is, e.g., forced to stack-allocated it (rather than keeping it in a register, or whatever other techniques it employs to "optimize it out").</div></div></blockquote><div>Adding a tracepoint adds liveness contraints (this is on purpose).<br></div><div>So it may increase register pressure, or in some situations require</div><div>to save/reload the variable from the stack, but note that such reload</div><div>would be done within the "unlikely" if() branch, so loading such variable</div><div>from the stack would only affect "tracing active" case.<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>As a rule of thumb, you may want to keep your static tracepoints<br data-mce-bogus="1"></div><div>close to where variables are actually used by the application.<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>Another aspect to consider with respect to optimisations: if you</div><div>put a tracepoint in a "leaf" function, the function call of the tracepoint</div><div>turns it into a non-leaf function.<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>Those are very relevant questions :) Let me know if you need<br data-mce-bogus="1"></div><div>further clarification.<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>Thanks,<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>Mathieu<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><div dir="ltr"><br><div>Please Cc me on replies as I am not subscribed to the list.</div><br><div>Thank you in advance!</div><br><div>-- </div><div>Best,</div><div>Zhenya</div></div><br>_______________________________________________<br>lttng-dev mailing list<br>lttng-dev@lists.lttng.org<br>https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev<br></blockquote></div><div><br></div><div data-marker="__SIG_POST__">-- <br></div><div>Mathieu Desnoyers<br>EfficiOS Inc.<br>http://www.efficios.com</div></div></body></html>