Michael Jeanson [Fri, 16 Apr 2021 20:06:11 +0000 (16:06 -0400)]
Remove -Wsystem-headers from tests
The objective of add -Wsystem-headers to the tests Makefiles was to
catch warnings in the tracepoint headers when they are installed in the
compiler system header path. However the tests are always built against
the headers inside the tree which are not in the system header path.
A side effect is that it causes problems on some system where the system
headers generate warnings and thus prevent us from building with
warnings treated as errors.
Change-Id: I65529c50cf48e49ba34692e6d501e3218be8d41c Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Michael Jeanson [Tue, 13 Apr 2021 20:39:18 +0000 (16:39 -0400)]
Initialize liblttng-ust-common in dependent libraries
liblttng-ust-common is a new public library introduced in this
developement cycle to contain the shared state between liblttng-ust and
our other libs that can't link directly on liblttng-ust. The constructor
of each of these libraries should now call the liblttng-ust-common
constructor early in their own constructors to ensure proper execution
order.
* Rename library constructors with the _ctor suffix to help
distinguish them from other _init functions.
* Hide the fd-tracker init fonction, the liblttng-ust-common ctor
should be called instead.
* All libraries linked on 'liblttng-ust-common' call its constructor
early in theirs.
Change-Id: I8e083f392b4ef2427addd00120cffc61a6314697 Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Michael Jeanson [Wed, 14 Apr 2021 17:39:03 +0000 (13:39 -0400)]
Internal logging lazy-initialization
Replace the initialization function by a lazy-init scheme, this way we
don't loose logging messages when called from constructors across
libraries or ld preloaded wrappers.
Change-Id: Idb1593c025351af6aed152b31a2aab17b4d884b0 Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
tracepoint: validate provider/event name length with static assert
Validate the provider/event name length with static assert in both
_DEFINE_TRACEPOINT() and within the tracepoint probe.
Validating the length in _DEFINE_TRACEPOINT() ensures that the
tracepoints don't try to register a callsite with a too long name by
mistake. This will enable handling of too long names with rejection of
the tracepoint rather than truncation of the name in a future patch.
The tracepoint probe was already validating the length, but using a
static assert makes the error message clearer.
Introduce LTTNG_UST_TRACEPOINT_NAME_LEN_MAX which is separate from the
communication protocol's LTTNG_UST_ABI_SYM_NAME_LEN to ensure both
communication protocol and instrumentation API can evolve independently.
Rename LTTNG_ALLOCATE_COMPOUND_LITERAL_ON_HEAP to add LTTNG_UST_ prefix
Rename LTTNG_ALLOCATE_COMPOUND_LITERAL_ON_HEAP to
LTTNG_UST_ALLOCATE_COMPOUND_LITERAL_ON_HEAP to use the LTTNG_UST_
prefix. This is public API, but was never documented, recently
introduced, and does not appear to be actively used by any open source
project. Since we are doing an ABI bump, clean this up.
This header has always been unused. The consumer daemon interacts with
the ring buffer in lttng-ust is through liblttng-ust-ctl, and not
through an ioctl-style ABI.
Fix: perform lazy initialization of getenv common lib
The ust-dl wrapper ends up calling into the getenv common lib very early
from library constructors through use of dlopen by the tracepoint
instrumentation code.
This happens before the getenv common lib is explicitly initialized by
liblttng-ust's contructor.
Perform lazy initialization for those early use by constructor
scenarios.
Michael Jeanson [Tue, 13 Apr 2021 19:49:20 +0000 (15:49 -0400)]
fix: remove unused include wait.h
We moved our internal 'wait.h' to 'common/wait.h' but forgot the include
in 'lttng-events.c'. This was a stale include as we don't use anything
from wait.h here. On Linux this went unnoticed as there is a system
'wait.h' which is an alias for 'sys/wait.h'. However, there is no such
system header on FreeBSD and it results in a build failure.
Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I10034b65e4cacae0ef729ce07d505a37f0b2f1cc
Michael Jeanson [Sat, 3 Apr 2021 00:22:42 +0000 (20:22 -0400)]
Split ust-events-internal.h between common and liblttng-ust
Split ust-events-internal.h into a common private header containing the
types and ABI functions and a header internal to liblttng-ust containing
the declaration of the private symbols.
Change-Id: I8ec2a5c8aad9ba85557b5a727ffc3615172e375d Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Michael Jeanson [Tue, 6 Apr 2021 16:29:36 +0000 (12:29 -0400)]
Move getcpu.h to 'lib/lttng-ust/'
Move getcpu.h from 'common/ringbuffer' to 'lib/lttng-ust', the
implementation is there and it provides some liblttng-ust symbols to
other components unrelated to the ringbuffer.
* Namespace internal symbols for clarity
* Add comments to the code.
Change-Id: I93da098dc9f90aa6324ad1ac36eaba1c660f0f64 Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Michael Jeanson [Tue, 6 Apr 2021 20:58:57 +0000 (16:58 -0400)]
Split the common part of clock.h
Split clock.h into an internal liblttng-ust header and a common header
to allow access to 'lttng_ust_clock_init' which is part of the private
ABI of liblttng-ust.
Change-Id: Ic23ed01201edaebecb61ff071dd1d38281ff6de8 Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Michael Jeanson [Mon, 12 Apr 2021 21:12:55 +0000 (17:12 -0400)]
Move fd-tracker to liblttng-ust-common
The fd-tracker provides ABI symbols to liblttng-ust-ctl which shouldn't
link directy on liblttng-ust, move it to liblttng-ust-common to
accomodate this. This is in line with the goal to move the shared state
across our different libraries to ust-common.
Change-Id: I69de6a9e6eaec9599f22e47cb0292ef793f6115d Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Michael Jeanson [Fri, 2 Apr 2021 18:45:42 +0000 (14:45 -0400)]
Move internal headers to 'src/' dir
Move internal headers from the global 'include' directory to their
respective private directories under 'src/'. Remove the 'ust-' prefix
when appropriate as they are now included with the 'common/' path which
makes it easier to distinguish public and internal headers.
This is part of an effort to standardize our autotools setup across
projects to simplify maintenance.
Change-Id: If5510bbe9294ba1f0dcd4b101b363e7ef64e255d Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Michael Jeanson [Fri, 2 Apr 2021 15:47:52 +0000 (11:47 -0400)]
Add 'src' dir to global include path
The objective is to move internal headers from the global 'include'
directory to their respective private directories under 'src'.
Move the private generated 'config.h' to 'src/common/config.h', this way
it can be include with 'common/config.h' and reduce the risk of clashing
with a similarly named file.
This is part of an effort to standardize our autotools setup across
projects to simplify maintenance.
Change-Id: Ie62a81e46458bffb6d31af66411865f23cf1cb4f Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Michael Jeanson [Fri, 2 Apr 2021 15:19:44 +0000 (11:19 -0400)]
Move all sources to 'src/'
This will align the source tree structure with our other projects and
will make it easier to move the private headers currently located in the
global 'include' directory.
Change-Id: Ib016ec0c31de74990b1a8bb0792df2e7470bb994 Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
commit 4e48b5d2debaf ("Refactoring: add back constness of public API structures")
changes the type of the first argument received by context callbacks
from a struct lttng_ust_ctx_field pointer to a void private data pointer.
That commit failed to change some call sites, which were still passing
the struct lttng_ust_ctx_field pointer rather than the private data
pointer. This was not caught by compiler errors because we are loosening
from a structure pointer to a void pointer.
Refactoring: add back constness of public API structures
Probes defining type, enumeration label, enumeration description,
event, and probe structures should be able to define them as "const",
because those are indeed const data which never need to be changed by
the tracer.
In order to allow struct lttng_ust_probe_desc definition to be constant,
move the "head", "lazy_init_head" and "lazy" fields to an internal
structure, "struct lttng_ust_registered_probe". It is opaque from the
point of view of the probe provider, but its pointer is now used as a
cookie between registration and unregistration. Moving the list heads
into an internal structure is an overall cleanup hiding private data
from the public API.
Use a similar scheme for registration of the context provider:
internalize the "hlist" field into an internal registration structure
(opaque from the point of view of the public API), which is now used as
a cookie between registration and unregistration.
This allows to fix an issue which was introduced by a prior refactoring
of the code dealing with contexts: the RCU update of context callbacks
was broken because the context fields were shared between the old and
the new array of contexts, thus leading to non-atomic update of the 3
callback pointers. This is fixed by making struct lttng_ust_ctx private,
and changing the array of pointers to context fields to an array of
context fields.
The functions lttng_ust_context_set_session_provider,
lttng_ust_add_app_context_to_ctx_rcu, and
lttng_ust_context_set_provider_rcu are now private.
For all contexts except the "perf" context fields, define the context
field as a static const variable rather than use memory allocation. This
means freeing the event field and type is not required anymore, and the
perf context field is handled through a destroy callback using the
private data pointer.
Move struct lttng_ust_ctx_field to an internal header. The only reason
why it was public is because the callbacks expected it as an argument.
Change the callbacks to receive a private data pointer instead to
achieve the same goal without exposing our internal structures.
The internal helpers lttng_ust_create_type_integer,
lttng_ust_create_type_array_text and lttng_ust_destroy_type are removed,
and replaced by internal macro helpers lttng_ust_static_type_integer,
lttng_ust_static_type_array_text, lttng_ust_static_event_field, and
lttng_ust_static_ctx_field, to facilitate static definitions in context
code.
Because there is no need to embed list and hlist nodes in the probe
descriptor nor the context provider, there is no need to include those
list headers from public APIs anymore.
Michael Jeanson [Wed, 31 Mar 2021 21:52:30 +0000 (17:52 -0400)]
Add 'ctf_unused' tracepoint field type
Some tracepoint definitions have one or more arguments that don't have a
corresponding field to allow passing a value to a probe without
recording it in the trace buffer nor using it in the filter.
This results in tracepoint macros generating inline functions with unused
arguments which prevents us from turning on -Wunuse-parameter.
Add a new tracepoint field type name 'ctf_unused' to adress this and
properly handle unused values in the tracepoint macros.
[ Mathieu: ctf_unused() takes only the _src parameter, no "type",
because an unused "field" does not have any representation in the ring
buffer nor the filter. If this ends up limiting us in the future, I
accept all the blame. ]
Change-Id: I56d8024926340e9c965ca01fa24a0fff7b7c5baa Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Michael Jeanson [Wed, 31 Mar 2021 16:19:05 +0000 (12:19 -0400)]
cleanup: explicitly mark unused parameters (-Wunused-parameter)
Add the 'unused' attribute to function parameters that are unused to
allow turning on -Wunused-parameter and distinguish unused parameters
that are actual errors.
Change-Id: I5a4b3790ae84da0c5135a214f2a63b513bb199eb Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Michael Jeanson [Fri, 26 Mar 2021 19:34:21 +0000 (15:34 -0400)]
fix: string constants (-Wwrite-strings)
Do not use an anonymous string literal with a non-const char pointer as
this will discard the implicit const, use static non-const string
instead when appropriate. Otherwise, we could end up trying to write to
a string constant.
Change-Id: Ie2bb0e5ab7978930f9edcdb379bd181caaacc15c Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Testing with a fixed number of loops per-thread only works if the
workload is distributed perfectly across CPUs. For instance, if a lock
is held in the workload (e.g. internally by open() and close()), those
may cause starvation of some threads, and therefore cause the benchmark
to be wrong because it will wait for the slowest thread to complete its
loops.
It is also not good for testing overcommit of threads vs cpus.
Change the test to report the number of loops performed in a given wall
time, and use this to report the average and std.dev. of tracing
overhead per event on each active CPU.
Change the benchmark workload to be only CPU-bound and not generate
system calls to minimize the inherent non-scalability of the workload
(e.g. locks held within the kernel).
Kill session daemon after script, conditionally drop caches if root
(else it is forbidden to do so), handle cleanup on trap, use snapshot
(flight recorder) tracing to benchmark ring buffer, output the result in
nanoseconds, removing trailing numbers after dot.
Before this, the test was pretty much always resulting in an output of
"0s" extra overhead due to truncation of significant numbers in the
output.
Fix: liblttng-ust-ctl: missing ring buffer and counter clients init/exit symbols
Move init/exit functions to ust-core.c which is linked against by both
liblttng-ust and liblttng-ust-ctl to make them available to the control
library.
New API: lttng_ust_init_thread() for async-signal tracing
LTTng-UST uses Global Dynamic model TLS variables rather than IE
model because many versions of glibc don't preallocate a pool large
enough for TLS variables IE model defined in other shared libraries,
and causes issues when using LTTng-UST for Java tracing.
Because of this use of Global Dynamic TLS variables, users wishing to
trace from signal handlers need to explicitly trigger the lazy
allocation of those variables for each thread before using them.
This can be triggered by calling lttng_ust_init_thread().
Hide the public symbols for ring buffer and counter clients init/exit.
Expose new symbols for init/exit of all ring buffer and counter clients
instead. Those new symbols are only used by liblttng-ust-ctl, and are
thus in an internal header.
There are additional missing URCU_TLS() accessors in the refactoring of
the ring buffer context. Moreover, when indexing an array, it must be
done outside of the URCU_TLS() accessor.
Refactoring: hide internal fields of ring buffer context
The public ring buffer context is allocated on the probe stack, but
contains many internal fields which are of no use to the probe. They
belong to that structure for the sake of passing information between
reserve, write, commit, strcpy, and other ring buffer callbacks.
Move those fields to a newly introduced private data structure, which is
allocated into a TLS stack belonging to the ring buffer client. It is
indexed with the TLS ring buffer nesting counter to allow recursive use
of the ring buffer (e.g. signal handlers).
While doing this, also move the "offset alignment" operation to the ring
buffer write callback. The alignment is now an additional parameter
expected by the write callback. Note that the strcpy and pstrcpy_pad
callbacks never need to do any alignment, so simply remove those
no-op alignments.
The event reserve callback does not need to have an explicit event id
parameter. It can fetch it from the client private data.