On Tue, May 24, 2022 at 12:49 PM Eric Botcazou via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> Hi,
>
> some time ago we were requested to implement a -finstrument-functions-once
> switch in the compiler, with the semantics that the profiling functions be
> called only once per instrumented function.  The goal was to make it possible
> to use it in (large) production binaries to do function-level coverage, so the
> overhead must be minimum and, in particular, there is no protection against
> data races so the "once" moniker is imprecise.

So that also applies to

"... and the second profiling function is called before the exit
+corresponding to this first entry"

specifically "corresponding to this first entry"?   As if the second
entry exits first will that call the second profiling function or will
it really be the thread that called the first profiling function
(what happens when that thread terminates before calling the second
profiling function? (***)).  Consider re-wording this slightly.

+      /* If -finstrument-functions-once is specified, generate:
+
+          static volatile bool F.0 = true;
+          bool tmp_first;

is there any good reason to make F.0 volatile?  That doesn't prevent
races.  Any reason to make F.0 initialized to true rather than false
(bss init?)

(***) looking at the implementation the second profiling function
can end up being never called when the thread calling the first
profiling function does not exit the function.  So I wonder if
the "optimization"(?) not re-reading F.0 makes sense (it also
requires to keep the value of F.0 live across the whole function)

Otherwise looks OK to me.

Richard.

> Tested on x86-64/Linux, OK for the mainline?
>
>
> 2022-05-24  Eric Botcazou  <ebotca...@adacore.com>
>
>         * common.opt (finstrument-functions): Set explicit value.
>         (-finstrument-functions-once): New option.
>         * doc/invoke.texi (Program Instrumentation Options): Document it.
>         * gimplify.c (build_instrumentation_call): New static function.
>         (gimplify_function_tree): Invoke it to emit the instrumentation calls
>         if -finstrument-functions[-once] is specified.
>
> --
> Eric Botcazou

Reply via email to