This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
Support ENABLED sdt probe macro
- From: Stan Cox <scox at redhat dot com>
- To: SystemTap List <systemtap at sources dot redhat dot com>
- Date: Mon, 10 Aug 2009 17:03:15 -0400
- Subject: Support ENABLED sdt probe macro
SW10013
This is for utrace only; uprobes is related.
For test.d 'dtrace -h -s test.d' emits in test.h
__extension__ extern long test_semaphore __attribute__ ((unused))
__attribute__ ((section (".probes")));
and for 'dtrace -G test.d' adds the definition
The changes for sdt.h are simple for a change, it checks that value
before each probe setup.
session.h defines a map from filename to variable location
tapset-utrace.cxx will produce the following additional generated code:
add 'struct task_struct *tsk;' to stap_utrace_probe
since there is not a means to determine the task from
systemtap_module_exit
in _stp_utrace_probe_cb add for each probe if the filename matches.
(There is not a means to determine what probe brought us here so
incrementing only the concerned probe is a challenge)
size_t sdt_semaphore = 1;
__access_process_vm (tsk, 0x601230, &sdt_semaphore,
sizeof (sdt_semaphore), 0);
sdt_semaphore += 1;
in systemtap_module_exit add for each probe if the filename matches
size_t sdt_semaphore;
__access_process_vm (tsk, 0x601230, &sdt_semaphore,
sizeof (sdt_semaphore, 0);
sdt_semaphore -= 1;
__access_process_vm (tsk, 0x601230, &sdt_semaphore,
sizeof (sdt_semaphore), 1);
In tapsets.cxx record the mapping from filename to variable location
In translate.cxx include a new "access_process_vm.h" (see itrace.c)
diff --git a/dtrace.in b/dtrace.in
index 168bfb1..38fb03b 100755
--- a/dtrace.in
+++ b/dtrace.in
@@ -19,2 +19,3 @@ from tempfile import mkstemp
class provider:
+ semaphores_def = "\n"
def typedef_append(self, typedefs,this_probe,arg,c):
@@ -30,2 +31,6 @@ class provider:
return typedefs
+ def semaphore_def_append(self, this_probe):
+ self.semaphores_def += "__extension__ long %s_semaphore __attribute__ ((unused)) __attribute__ ((section (\".probes\")));\n" % (this_probe)
+ def semaphore_def_write(self, file):
+ file.write(self.semaphores_def)
def generate(self, provider, header, add_typedefs):
@@ -35,2 +40,4 @@ class provider:
self.h.write("/* Generated by the Systemtap dtrace wrapper */\n")
+ if (build_source):
+ self.h.write("\n#define STAP_HAS_SEMAPHORES 1\n\n")
self.h.write("\n#include <sys/sdt.h>\n\n")
@@ -66,2 +73,3 @@ class provider:
c = 0
+ self.semaphore_def_append (this_probe)
while (i < len(args)):
@@ -93,3 +101,4 @@ class provider:
self.h.write ('/* %s (%s) */\n' % (this_probe_canon,args_string))
- self.h.write ('#define %s_ENABLED() 1\n' % this_probe_canon)
+ self.h.write ('#define %s_ENABLED() %s_semaphore\n' % (this_probe_canon,this_probe))
+ self.h.write ("__extension__ extern long %s_semaphore __attribute__ ((unused)) __attribute__ ((section (\".probes\")));\n" % (this_probe))
self.h.write (define_str + ") \\\n")
@@ -176,2 +185,3 @@ if (build_header):
elif (build_source):
+ providers = provider()
(basename,ext) = os.path.splitext(s_filename)
@@ -181,2 +191,3 @@ elif (build_source):
f.write("static __dtrace () {}\n")
+ providers.semaphore_def_write(f)
f.close()
diff --git a/includes/sys/sdt.h b/includes/sys/sdt.h
index f179c2a..6f3aaab 100644
--- a/includes/sys/sdt.h
+++ b/includes/sys/sdt.h
@@ -254,2 +254,9 @@ extern long int syscall (long int __sysno, ...) __THROW;
+#ifdef STAP_HAS_SEMAPHORES
+#define STAP_SEMAPHORE(probe) \
+ if ( probe ## _semaphore )
+#else
+#define STAP_SEMAPHORE(probe) ;
+#endif
+
#include <sys/syscall.h>
@@ -257,4 +264,5 @@ extern long int syscall (long int __sysno, ...) __THROW;
#define STAP_PROBE_(probe) \
+STAP_SEMAPHORE(probe) \
do { \
- STAP_PROBE_DATA(probe,STAP_SYSCALL,0); \
+ STAP_PROBE_DATA(probe,STAP_GUARD,0); \
syscall (STAP_SYSCALL, #probe, STAP_GUARD); \
@@ -263,2 +271,3 @@ do { \
#define STAP_PROBE1_(probe,label,parm1) \
+STAP_SEMAPHORE(probe) \
do { \
@@ -269,2 +278,3 @@ do { \
#define STAP_PROBE2_(probe,label,parm1,parm2) \
+STAP_SEMAPHORE(probe) \
do { \
@@ -278,2 +288,3 @@ do { \
....
diff --git a/session.h b/session.h
index ea91442..f642b74 100644
--- a/session.h
+++ b/session.h
@@ -223,2 +223,6 @@ struct systemtap_session
+
+ // Location of semaphores to activate sdt probes
+ std::multimap<std::string, Dwarf_Addr> sdt_semaphore_addr;
+
// NB: It is very important for all of the above (and below) fields
diff --git a/tapset-utrace.cxx b/tapset-utrace.cxx
index a07e08b..844326d 100644
--- a/tapset-utrace.cxx
+++ b/tapset-utrace.cxx
@@ -718,2 +718,3 @@ utrace_derived_probe_group::emit_probe_decl (systemtap_session& s,
s.op->line() << " .engine_attached=0,";
+ s.op->line() << " .tsk=0,";
s.op->line() << " },";
@@ -752,2 +753,3 @@ utrace_derived_probe_group::emit_module_decls (systemtap_session& s)
s.op->newline() << "int engine_attached;";
+ s.op->newline() << "struct task_struct *tsk;";
s.op->newline(-1) << "};";
@@ -863,2 +865,3 @@ utrace_derived_probe_group::emit_module_decls (systemtap_session& s)
s.op->newline() << "p->engine_attached = 1;";
+ s.op->newline() << "p->tsk = tsk;";
s.op->newline(-1) << "}";
@@ -874,2 +877,24 @@ utrace_derived_probe_group::emit_module_decls (systemtap_session& s)
s.op->newline(-1) << "}";
+
+ vector<Dwarf_Addr>::iterator it;
+ if (! s.sdt_semaphore_addr.empty())
+ for (p_b_path_iterator it = probes_by_path.begin();
+ it != probes_by_path.end(); it++)
+ {
+ s.op->newline() << "{";
+ s.op->indent(1);
+ s.op->newline() << "size_t sdt_semaphore = 1;";
+ multimap<std::string,Dwarf_Addr>::iterator its;
+ for (its = s.sdt_semaphore_addr.begin();
+ its != s.sdt_semaphore_addr.end();
+ its++)
+ if (it->first == its->first)
+ {
+ // Ideally we would increment this but we don't know what probe
+ // this corresponds to.
+ s.op->newline() << "__access_process_vm (tsk, " << hex << "0x" << its->second << ", &sdt_semaphore, sizeof (sdt_semaphore), 1);" << dec;
+ }
+ s.op->newline(-1) << "}";
+ }
+
s.op->newline(-1) << "}";
@@ -1047,2 +1072,27 @@ utrace_derived_probe_group::emit_module_exit (systemtap_session& s)
s.op->newline(-1) << "}";
+
+ int sem_idx = 0;
+ if (! s.sdt_semaphore_addr.empty())
+ for (p_b_path_iterator it = probes_by_path.begin();
+ it != probes_by_path.end(); it++)
+ {
+ s.op->newline() << "{";
+ s.op->indent(1);
+ s.op->newline() << "size_t sdt_semaphore;";
+ multimap<std::string,Dwarf_Addr>::iterator its;
+ for (its = s.sdt_semaphore_addr.begin();
+ its != s.sdt_semaphore_addr.end();
+ its++)
+ {
+ if (it->first == its->first)
+ {
+ s.op->newline() << "__access_process_vm (stap_utrace_probes[" << sem_idx << "].tsk, " << hex << "0x" << its->second << ", &sdt_semaphore, sizeof (sdt_semaphore), 0);" << dec;
+ s.op->newline() << "sdt_semaphore -= 1;";
+ s.op->newline() << "__access_process_vm (stap_utrace_probes[" << sem_idx << "].tsk, " << hex << "0x" << its->second << ", &sdt_semaphore, sizeof (sdt_semaphore), 1);" << dec;
+ }
+ }
+
+ s.op->newline(-1) << "}";
+ sem_idx += it->second.size() - 1;
+ }
}
diff --git a/tapsets.cxx b/tapsets.cxx
index f91d15d..6bbf761 100644
--- a/tapsets.cxx
+++ b/tapsets.cxx
@@ -3352,2 +3352,3 @@ private:
probe_point * base_loc;
+ literal_map_t const & params;
vector<derived_probe *> & results;
@@ -3367,2 +3368,3 @@ private:
void convert_probe(probe *base);
+ void record_semaphore();
void convert_location(probe *base, probe_point *location);
@@ -3375,3 +3377,3 @@ sdt_query::sdt_query(probe * base_probe, probe_point * base_loc,
base_query(dw, params), base_probe(base_probe),
- base_loc(base_loc), results(results)
+ base_loc(base_loc), params(params), results(results)
{
@@ -3396,2 +3398,4 @@ sdt_query::handle_query_module()
+ record_semaphore();
+
probe *new_base = new probe(*base_probe);
@@ -3561,2 +3565,23 @@ sdt_query::get_next_probe()
void
+sdt_query::record_semaphore ()
+{
+ int sym_count = dwfl_module_getsymtab(dw.module);
+ assert (sym_count >= 0);
+ for (int i = 0; i < sym_count; i++)
+ {
+ GElf_Sym sym;
+ GElf_Word shndxp;
+ char *sym_str = (char*)dwfl_module_getsym (dw.module, i, &sym, &shndxp);
+ if (strcmp(sym_str, string(probe_name + "_semaphore").c_str()) == 0)
+ {
+ string process_name;
+ derived_probe_builder::get_param(params, TOK_PROCESS, process_name);
+ sess.sdt_semaphore_addr.insert(make_pair(find_executable(process_name), sym.st_value));
+ break;
+ }
+ }
+}
+
+
+void
sdt_query::convert_probe (probe *base)
@@ -3711,3 +3736,2 @@ sdt_query::convert_location (probe *base, probe_point *location)
-
void
diff --git a/translate.cxx b/translate.cxx
index 4a6a10b..f99cf0c 100644
--- a/translate.cxx
+++ b/translate.cxx
@@ -5179,2 +5181,4 @@ translate_pass (systemtap_session& s)
s.op->newline() << "#include \"loc2c-runtime.h\" ";
+ if (! s.sdt_semaphore_addr.empty())
+ s.op->newline() << "#include \"access_process_vm.h\" ";