Josh Stone [Wed, 3 Sep 2014 23:37:06 +0000 (16:37 -0700)]
Remove systemtap_session::built_uprobes
For the purpose of save_uprobes, it doesn't actually matter whether
uprobes.ko was just built or was pulled from the cache. If we have the
uprobes_path at all, go ahead and save it.
Jonathan Lebon [Wed, 3 Sep 2014 21:45:33 +0000 (17:45 -0400)]
initscript: use --save-uprobes instead of -u
Rather than masking the -u option of stap (unoptimized mode), use the
actual option which we use with stap (--save-uprobes). This will allow
us to remain backwards-compatible if we later on automate the uprobes
saving by always turning on --save-uprobes.
So now, users have to do the following if they require userspace
probing:
Stefan Hajnoczi [Wed, 3 Sep 2014 21:38:30 +0000 (17:38 -0400)]
stap: add --save-uprobes
The stap -m <name> option saves the script module. For scripts that
rely on uprobes it may also be necessary to get the uprobes module (if
it was built by stap).
The new stap --save-uprobes option saves uprobes/uprobes.ko into the
current directory.
jistone noted that the smp_call_function_single() function call
introduced in commit 590a9ae1acc47 didn't exist on 2.6.9-era kernels.
We de-optimize to plain smp_call_function() on such dinosaurs.
Josh Stone [Fri, 29 Aug 2014 22:15:47 +0000 (15:15 -0700)]
PR12333: Use 1/0 conditions instead of true/false in C
The kernel happens to declare true/false values for C to use, at least
since commit 6e21828743247 (in 2.6.19), but stapdyn's normal C runtime
doesn't have that. Use boring old 1/0 instead.
Abegail Jakop [Thu, 28 Aug 2014 19:08:59 +0000 (15:08 -0400)]
PR12333: deleting pmap specified by array slice
runtime/map.c: have iterdel() use pre-existing functions
translate.cxx: generate code to delete elements from a pmap, based on
an array slice given. rename next() that called iterdel to del_next()
staptree.cxx: cleanup of an unnecessary condition
Abegail Jakop [Tue, 26 Aug 2014 19:53:22 +0000 (15:53 -0400)]
store given pid for process probe for use by task_finder
session.cxx: replace readlink(), which did the pid validation,
with is_valid_pid()
tapsets.cxx: if given, within dwarf_builder::build store the pid
for use by uprobe_derived_probe so that task_finder associates
the probe with the pid
util.*: new function that checks if the given pid is valid. if
not, it generates an error message that can be used.
Abegail Jakop [Fri, 22 Aug 2014 20:52:33 +0000 (16:52 -0400)]
PR12333: store wildcards in array slices as NULL
parse.cxx: set the index for array slices as NULL if it's a wildcard
elaborate.cxx: account for NULL indexes. added error message in
symresolution_info::visit_arrayindex if it encounters a NULL index,
since all expressions that support wildcards dealt with separately
staptree.cxx: when printing out foreach, delete and array_in, replace
NULL indexes with "*"
translate.cxx: account for NULL indexes. don't generate a tmpvar
for a wildcard array index
Abegail Jakop [Thu, 21 Aug 2014 16:17:40 +0000 (12:17 -0400)]
PR12333" array slicing for membership test
parse.cxx: accept wildcards in the arrayindex for array_in
elaborate.cxx: new function symresolution_info::visit_array_in
that skips processing wildcards that are present in the arrayindex
translate.cxx: generate code to iterate over the array until a
match is found or until the end of the array
Abegail Jakop [Tue, 19 Aug 2014 18:12:52 +0000 (14:12 -0400)]
PR12333: array slicing for delete statements
parse.cxx: accept wildcards (*) within array indexes
elaborate.cxx: skip processing wildcards in array indexes for delete
staptree.cxx: for the varuse_collecting_visitor, don't throw an error
about no referent if the symbol is a wildcard
translate.cxx: generate code for deleting variables if the indexes match
the array slice given. Also generate code to initialize tmpvars used to
store indexes in the array slice.
runtime/map.c: new function _stp_map_iterdel that deletes the node given,
and returns the next node in the map.
Frank Ch. Eigler [Sun, 17 Aug 2014 14:55:35 +0000 (10:55 -0400)]
runtime: improve robustness of shutdown phase via flush_scheduled_work()
It has been observed that schedule_work() artifacts have the potential
to overstay their welcome during shutdown, triggering some time after
their operand data structures have been deallocated. This has shown
up most recently on 3.17-rc0 during the on-the-fly stress-testing, but
also can be observed with plain pseudo-utrace callbacks. We now add a
flush_scheduled_work() into our cargo-cult stp_synchronize_sched(),
which we now call during the on-the-fly shutdown phase too.
Normal optimized mode can make it difficult to see which stap probe
was being invoked for which C probe handler body, as identical probe
handlers are reused. This is inconvenient if one just has a kernel
crash backtrace to start from from.
* translate.cxx (emit_common_header, emit_probe): In -u mode,
eschew duplicate probe handler body elision.
Abegail Jakop [Fri, 15 Aug 2014 20:33:33 +0000 (16:33 -0400)]
PR12333: evaluating the indexes before the loop body
translate.cxx: evaluate the expressions that make up the array slice
index for foreach loops. updated c_tmpcounter::visit_foreach_loop to
account for the additional tmpvars used to store array slice indexes
David Smith [Fri, 15 Aug 2014 20:07:52 +0000 (15:07 -0500)]
Fix PR17275 by fixing testcase problems on s390x.
* testsuite/buildok/memory-all-probes.stp: Tweak test to avoid overly
broad wildcards, which can cause the test to fail on systems without
uprobes (like s390x).
* testsuite/buildok/tcp-all-probes.stp: Ditto.
David Smith [Thu, 14 Aug 2014 18:49:44 +0000 (13:49 -0500)]
Improve on-the-fly initialization code.
* translate.cxx (c_unparser::emit_probe_condition_initialize): Only output
'cond_enabled' field initialization if the probe isn't always enabled.
(translate_pass): Always initialize 'cond_enabled' to 1. This can get
overridden by the output of
c_unparser::emit_probe_condition_initialize().
Josh Stone [Tue, 12 Aug 2014 17:29:30 +0000 (10:29 -0700)]
PR17260: Use get_context to guard stp_print_flush's lock
Holding a context ensures that any probes triggered in the interim will
be considered reentrant and skipped, since such a nested probe might
have recursed on that spinlock. We faced a similar situation before
with _stp_ctl_send and all the locks it touches.
Frank Ch. Eigler [Mon, 11 Aug 2014 19:56:15 +0000 (15:56 -0400)]
statement.nearest probes followup: some docs, samples, tweakage
* NEWS: Mention it.
* man/stapprobes.3stap: Document it.
* testsuite/systemtap.examples/*: Use it.
* testsuite/systemtap.*/: Baby test it.
* dwflpp.cxx: Drop debugging statement and make a speech.
Honggyu Kim [Mon, 4 Aug 2014 13:18:40 +0000 (22:18 +0900)]
dwflpp: register statement.nearest suffix
If a line number is given in 'statement', line records in dwarf may not
be found for a given line number.
In this case, alternative line numbers were suggested and exited.
With statement.nearest suffix, a kprobe is inserted into the nearest
line number that is available in dwarf line record.
* dwflpp.cxx(dwflpp.cxx::insert_alternative_linenos): Add a new method,
Add an arg "has_nearest" in dwflpp::iterate_over_srcfile_lines
* dwflpp.h(dwflpp.cxx::insert_alternative_linenos): Ditto.
* tapsets.cxx: Add a new suffix statement.nearest
Jonathan Lebon [Mon, 11 Aug 2014 19:40:19 +0000 (15:40 -0400)]
Merge branch 'jlebon/onthefly' (PR10995)
This branch adds support for on-the-fly probes as described in PR10995.
It also includes various minor fixes as well as a new file
runtime/linux/kprobes.c which hosts kprobes-related code (rather than
being dynamically emitted from tapsets.cxx).
Jonathan Lebon [Wed, 23 Jul 2014 20:24:45 +0000 (16:24 -0400)]
on-the-fly: don't use background timer if hrtimers missing
On older systems (< 2.6.17), hrtimers are not supported. Guard code
related to the background timer with this check so that we can at least
still compile code on these older platforms.
Jonathan Lebon [Tue, 22 Jul 2014 18:41:42 +0000 (14:41 -0400)]
on-the-fly: only start background timer if needed
Rather than always starting the background timer, only start it when it
is needed. That is, start the background timer when a probe which has an
effect on the conditions of probes which support on-the-fly operations
isn't a safe context for calling schedule_work() (determined by
otf_safe_context()).
Jonathan Lebon [Thu, 24 Jul 2014 18:15:22 +0000 (14:15 -0400)]
make schedule_work() call depend on otf_safe_context()
Now that each probe group directly describes whether their context is
safe for workqueue manipulations, we can directly emit in the probe
epilogue a call to schedule_work() if the probe is safe, rather than
doing it on a case-by-case basis.
Jonathan Lebon [Wed, 23 Jul 2014 18:32:15 +0000 (14:32 -0400)]
on-the-fly: make support a property of group rather than probe
Support for on-the-fly operations is more a property of the
derived_probe_group (which does the actual emitting), rather than
derived_probe.
For example, not because a dwarf_derived_probe supports on-the-fly
operations does it mean that a uprobe_derived_probe (which inherits from
dwarf_derived_probe) does. Similarly, a uprobe_derived_probe's support
for on-the-fly operations depends on the actual code emitted by the
group, which will emit different things depending on whether we're using
utrace or inode-uprobes for example.
To do this, we introduce a 'group' attribute which remembers to which
group a derived_probe has been added. This is then used during
translation time to check if the probe group supports on-the-fly
operations.
This patch also introduces otf_safe_context(), which determines whether
the context of the probe type is safe enough for direct workqueue
manipulations. This then allows us to only use the background timer if
the probe doing the toggling does not support workqueue manipulations.
Jonathan Lebon [Tue, 22 Jul 2014 20:24:00 +0000 (16:24 -0400)]
split linux/timer.c into .c and .h
For the background timer, it is useful to have some of the definitions
currently sitting in linux/timer.c. Split it into a header file and
include the header.
Jonathan Lebon [Tue, 22 Jul 2014 18:16:27 +0000 (14:16 -0400)]
on-the-fly: use a background timer to schedule work
Calling schedule_work() is not always safe from some contexts (e.g. when
tracing/probing the internals of workqueues themselves).
We remove the code which previously called schedule_work() in the common
epilogue of all probe types. We will need to vet on a case-by-case basis
which probe types are safe.
Meanwhile, we implement a background timer which simply checks if
schedule_work() needs to be called.
Jonathan Lebon [Thu, 17 Jul 2014 14:50:21 +0000 (10:50 -0400)]
affection.exp: also check probe globals locking
In light of the locking issue mentioned in the previous commit, this
commit now updates affection.exp so that locking is also checked to
ensure probes lock the right vars for the right access.
Jonathan Lebon [Wed, 16 Jul 2014 16:31:15 +0000 (12:31 -0400)]
on-the-fly: read-lock visited globals
If we have the following situation
probe X if (a || b) {...}
probe Y {a = ...}
probe Z {b = ...}
then we will have Y write-locking a and Z write-locking b, but because
these variables affect X's condition, the cond_enabled of X will be
re-evaluated in the out: path of both Y and Z. This means that it could
happen that Y tries to read b at the same time as Z updates it, and
vice-versa.
This patch ensures that Y and Z also read-lock b and a, respectively. It
does this by making the varuse collector also visit the conditions of
probes who we can affect.
Jonathan Lebon [Wed, 16 Jul 2014 15:59:56 +0000 (11:59 -0400)]
on-the-fly: use atomic_t for need_module_refresh
The need_module_refresh global can get written to in two different
locations at the same time. To avoid getting a messed up value, use
atomic_t operations.
Concurrency-wise, in the worse case, we get work scheduled twice rather
than once only.
Jonathan Lebon [Wed, 16 Jul 2014 14:52:32 +0000 (10:52 -0400)]
kprobes.c: link stap_dwarf_probe to stap_dwarf_kprobe
Prior to PR5673, the stap_dwarf_kprobe struct was embedded in the
stap_dwarf_probe struct. It was then moved out due to issues mentioned
in PR5673.
In this patch we simply add back a pointer member in stap_dwarf_probe to
its own stap_dwarf_kprobe so that they may never be mistakenly shared.
This also greatly simplifies many of the function signatures which
previously took in the stap_dwarf_probe and the stap_dwarf_kprobe as
separate parameters.
Jonathan Lebon [Wed, 16 Jul 2014 15:16:29 +0000 (11:16 -0400)]
kprobes.c: memset also after batch unregistration
We should not only clear the kprobe struct after a single
unregistration, but also when batch unregistration is used. (Even though
batch unregistration is normally only done when exiting, but better safe
than sorry!).
Jonathan Lebon [Wed, 16 Jul 2014 14:27:37 +0000 (10:27 -0400)]
kprobes.c: remove enabled_p from stap_dwarf_probe
Using the kernel function kprobe_disabled(), we can directly query
whether a kprobe is enabled or not. This makes the enabled_p field
redundant. We replace its use with a stapkp_enabled() function which
simply call kprobe_disabled().
Jonathan Lebon [Tue, 15 Jul 2014 20:17:31 +0000 (16:17 -0400)]
runtime: remove STP_ON_THE_FLY
This patch removes the use of the STP_ON_THE_FLY macro so that
on-the-fly related code is always emitted/executed. When no probes use
conditions, the overhead is quite small: the cond_enabled field of each
stap_probe is set to 1 at start-up.
In general, blocks that were previously incompatible with dyninst and
were behind an STP_ON_THE_FLY guard are now emitted only if !usermode.
The tests were adjusted to not test STP_ON_THE_FLY_DISABLED, which no
longer exists.
It is necessary to evaluate a given if(FOO) expression with a !!
prefix in order to turn it into a 0/1 boolean for probe.cond_enabled
matching purposes. With that done, a 1-bit field for cond_enabled is
sufficient.
Jonathan Lebon [Fri, 20 Jun 2014 19:10:53 +0000 (15:10 -0400)]
kprobes.c: register as disabled instead of post disabling
The register_kprobe() function supports settings the kprobe struct
flags member to KPROBE_FLAG_DISABLED to indicate that we want it
registered but disabled (see also Documentation/kprobes.txt).
This patch takes advantage of this by setting the flags member
accordingly during registration, rather than calling disable_kprobe()
after a successful registration.
Jonathan Lebon [Thu, 19 Jun 2014 20:41:17 +0000 (16:41 -0400)]
PR16861: reset kprobe struct and improve refresh
We need to ensure that the stap_dwarf_kprobe struct is completely
zero'ed out after each unregistration so as not to affect future
registrations which will use the same struct.
We also modify the signature of systemtap_module_refresh so that the
name of the module is passed. This allows us to only update the kprobes
related to that module, rather than checking all of them.
Finally, we also set the priority of the module notifier to 0 to
indicate we don't care in which order we are called (i.e. it shouldn't
matter whether we're called before or after the kprobes callback).
Jonathan Lebon [Tue, 17 Jun 2014 21:42:10 +0000 (17:42 -0400)]
kprobes.c: split stapkp_refresh_probe()
We break down stapkp_refresh_probe() into stapkp_enable_probe() and
stapkp_disable_probe(). We also introduce predicate functions
stapkp_should_enable_probe() and stapkp_should_disable_probe() to
improve clarity.