public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
* dtrace-generated and direct includes are not very compatible
@ 2019-12-19  1:56 Craig Ringer
  2019-12-30 16:04 ` Frank Ch. Eigler
  0 siblings, 1 reply; 2+ messages in thread
From: Craig Ringer @ 2019-12-19  1:56 UTC (permalink / raw)
  To: systemtap

Hi all

During some recent work I noticed that if you #include a probes.h generated
by stap's dtrace tool from a probes.d, it will enable semaphores for ALL
probes, irrespective of how they are defined.

You cannot define your own separate DTRACE_PROBE()s or STAP_PROBE()s
directly elsewhere in the code if the probes.h is included first, as
systemtap's macros will expect there to be semaphore symbols for them.

There are no macros exposed to generate the semaphore symbols dynamically
in the same manner as the probes.

You can disable semaphore use entirely by including <sys/sdt.h> before your
"probes.h" - at the cost of disabling semaphores for the probes themselves
too.

There's no macro you can define before including <sys/std.h> to explicitly
disable semaphores; only one defined by probes.h that enables them. And
it's only effective at include time, taking effect for all probe macros
used after the header is included.

That's probably not ideal. So I suggest the following changes, which I can
follow with a patch if you agree they make sense:

* Define new variants of STAP_PROBE() etc like STAP_PROBE_WITH_SEMAPHORE()
. Use these in the generated probes.h instead of defining a macro to enable
semaphores globally

* Replace the duplicated block of code for each probe in the generated
probes.h with just a pair of macros defined in <sys/std.h> like

    STAP_PROBE_DECLARE_SEMAPHORE(providername, foo);

    #define PROBE_PROVIDERNAME_FOO()
STAP_PROBE_WITH_SEMAPHORE(providername,foo)

* Also expose a STAP_PROBE_DEFINE_SEMAPHORE(providername, foo) in
<sys/sdt.h> and generate a .c file alongside the .h file. Applications may
choose to compile the generated .c file containing these macros instead of
linking the dtrace-script-generated .o file directly.

* Don't define _SDT_HAS_SEMAPHORES in probes.h anymore. Continue to respect
it with the old behaviour in <sys/sdt.h> if it's defined, by making each
STAP_PROBE() etc map to STAP_PROBE_WITH_SEMAPHORE() when it's defined.

This gives apps the flexibility to define their own probes with semaphores
dynamically from within their own code and macros. It also allows apps that
want to dynamically define probes _without_ such semaphores if they want,
without upsetting dtrace-style probe generation.

-- 
 Craig Ringer                   http://www.2ndQuadrant.com/
 2ndQuadrant - PostgreSQL Solutions for the Enterprise

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: dtrace-generated and direct includes are not very compatible
  2019-12-19  1:56 dtrace-generated and direct includes are not very compatible Craig Ringer
@ 2019-12-30 16:04 ` Frank Ch. Eigler
  0 siblings, 0 replies; 2+ messages in thread
From: Frank Ch. Eigler @ 2019-12-30 16:04 UTC (permalink / raw)
  To: Craig Ringer; +Cc: systemtap


Hi, Craig -

> During some recent work I noticed that if you #include a probes.h generated
> by stap's dtrace tool from a probes.d, it will enable semaphores for ALL
> probes, irrespective of how they are defined.

Yup.

> You cannot define your own separate DTRACE_PROBE()s or STAP_PROBE()s
> directly elsewhere in the code if the probes.h is included first, as
> systemtap's macros will expect there to be semaphore symbols for them.

Yup.

> There are no macros exposed to generate the semaphore symbols dynamically
> in the same manner as the probes.

And Yup.

All this is accidental.


> That's probably not ideal. So I suggest the following changes, which I can
> follow with a patch if you agree they make sense:
>
> * Define new variants of STAP_PROBE() etc like STAP_PROBE_WITH_SEMAPHORE()
> . Use these in the generated probes.h instead of defining a macro to enable
> semaphores globally

OK.

> * Replace the duplicated block of code for each probe in the generated
> probes.h with just a pair of macros defined in <sys/std.h> like
>
>     STAP_PROBE_DECLARE_SEMAPHORE(providername, foo);
>
>     #define PROBE_PROVIDERNAME_FOO()
> STAP_PROBE_WITH_SEMAPHORE(providername,foo)

Whatever makes most sense here.  Varargs and conditional macros make it
tricky.  Well motivated/explained code duplication is fine.


> * Also expose a STAP_PROBE_DEFINE_SEMAPHORE(providername, foo) in
> <sys/sdt.h> and generate a .c file alongside the .h file. Applications may
> choose to compile the generated .c file containing these macros instead of
> linking the dtrace-script-generated .o file directly.

I don't think we really need a .c file; a .h that contains the extern
semaphore shorts would sit just fine in the .h.


> * Don't define _SDT_HAS_SEMAPHORES in probes.h anymore. Continue to respect
> it with the old behaviour in <sys/sdt.h> if it's defined, by making each
> STAP_PROBE() etc map to STAP_PROBE_WITH_SEMAPHORE() when it's defined.

OK.

> This gives apps the flexibility to define their own probes with semaphores
> dynamically from within their own code and macros. It also allows apps that
> want to dynamically define probes _without_ such semaphores if they want,
> without upsetting dtrace-style probe generation.

OK.

- FChE

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-12-30 16:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-19  1:56 dtrace-generated and direct includes are not very compatible Craig Ringer
2019-12-30 16:04 ` Frank Ch. Eigler

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).