public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
From: Craig Ringer <craig@2ndquadrant.com>
To: systemtap@sourceware.org
Subject: dtrace-generated and direct includes are not very compatible
Date: Thu, 19 Dec 2019 01:56:00 -0000	[thread overview]
Message-ID: <CAMsr+YErkwqLystqBbCa6SVZWuFy0ZHBuJioOFE4QXnMbwfsYg@mail.gmail.com> (raw)

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

             reply	other threads:[~2019-12-19  1:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-19  1:56 Craig Ringer [this message]
2019-12-30 16:04 ` Frank Ch. Eigler

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=CAMsr+YErkwqLystqBbCa6SVZWuFy0ZHBuJioOFE4QXnMbwfsYg@mail.gmail.com \
    --to=craig@2ndquadrant.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).