From a704a23b6653df973d919516d4ebf4886a84824f Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Fri, 10 Jul 2009 17:58:01 +0200 Subject: Fix source_loc ostream operator << representation. * parse.cxx (operator << (ostream&,const source_loc&)): Add loc.file->name. --- parse.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parse.cxx b/parse.cxx index cfa33cb4..f3b9eb09 100644 --- a/parse.cxx +++ b/parse.cxx @@ -91,7 +91,7 @@ tt2str(token_type tt) ostream& operator << (ostream& o, const source_loc& loc) { - o << loc.file << ":" + o << loc.file->name << ":" << loc.line << ":" << loc.column; -- cgit From b2b61f91a752d8221addcbabb3c630766af081e4 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Sat, 11 Jul 2009 11:58:52 +0200 Subject: Don't accidentially use user space ntohs function. The definition of ntohs comes from user space include headers netinet/in.h which could define it as function instead of macro. So use builtin kernel be16_to_cpu instead. * tapset/aux_syscalls.stp (_struct_sockaddr_u): Define and use _stp_ntohs as be16_to_cpu. --- tapset/aux_syscalls.stp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tapset/aux_syscalls.stp b/tapset/aux_syscalls.stp index 9cb7a3df..9347e46f 100644 --- a/tapset/aux_syscalls.stp +++ b/tapset/aux_syscalls.stp @@ -292,6 +292,9 @@ function _struct_sockaddr_u:string(uaddr:long, len:long) #define DADDR (&inet->daddr) #endif +// Use kernel builtin instead of picking up user space ntohs (function). +#define _stp_ntohs be16_to_cpu + //FIXME. Not done yet. char *str = THIS->__retvalue; const int strlen = MAXSTRINGLEN; @@ -301,7 +304,7 @@ function _struct_sockaddr_u:string(uaddr:long, len:long) struct sockaddr_in *sin = (struct sockaddr_in *)buf; const unsigned char *addr = (unsigned char *)&sin->sin_addr; snprintf(str, strlen, "{AF_INET, %d.%d.%d.%d, %d}", - addr[0], addr[1], addr[2], addr[3], ntohs(sin->sin_port)); + addr[0], addr[1], addr[2], addr[3], _stp_ntohs(sin->sin_port)); } else if ((sa->sa_family == AF_UNIX)&&(len == sizeof(struct sockaddr_un))) { @@ -318,7 +321,7 @@ function _struct_sockaddr_u:string(uaddr:long, len:long) // FIXME. Address is probably not correctly displayed struct sockaddr_in6 *sin = (struct sockaddr_in6 *)buf; snprintf(str, strlen, "{AF_INET6, %016llx, %d}", - *(long long *)&sin->sin6_addr, ntohs(sin->sin6_port)); + *(long long *)&sin->sin6_addr, _stp_ntohs(sin->sin6_port)); } else if ((sa->sa_family == AF_PACKET)&&(len == sizeof(struct sockaddr_ll))) { -- cgit From 4eb0c58b7d5c97a822e76c9070bc45e9b09a7c9e Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Sat, 11 Jul 2009 19:28:00 +0200 Subject: PR3523 was fixed, enable -t cache test case. * testsuite/systemtap.base/cache.exp: Enable -t tests. --- testsuite/systemtap.base/cache.exp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/testsuite/systemtap.base/cache.exp b/testsuite/systemtap.base/cache.exp index b10a4f28..5c5c1441 100644 --- a/testsuite/systemtap.base/cache.exp +++ b/testsuite/systemtap.base/cache.exp @@ -99,9 +99,8 @@ stap_compile MERGE1 [F_UNCACHED_COMPILE] $basic_script1 -b -M stap_compile MERGE2 [F_CACHED_COMPILE] $basic_script1 -b -M # Using '-t' (benchmark timing) should change the hash -# These two tests will fail until PR3523 is fixed. -#stap_compile TIMING1 [F_UNCACHED_COMPILE] $basic_script1 -t -#stap_compile TIMING2 [F_CACHED_COMPILE] $basic_script1 -t +stap_compile TIMING1 [F_UNCACHED_COMPILE] $basic_script1 -t +stap_compile TIMING2 [F_CACHED_COMPILE] $basic_script1 -t # Changing the runtime directory should change the hash set new_runtime [exec pwd]/.cache_test_runtime -- cgit From 5a5732e52738b4f00995e705a170230c106885b6 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Sat, 11 Jul 2009 19:59:42 +0200 Subject: Add -O[0123s] gcc optimization flags for gcc pass 4 speedup. * session.h (struct systemtap_session): Add gcc_flags string field. * main.cxx (usage): Document -O[0123s]. (main): Default gcc_flags to -O0. Add O:: to getopt_long. Handle case 'O' to set gcc_flags. * buildrun.cxx (compile_pass): Add gcc_flags to EXTRA_CFLAGS. * stap1.in: Add -O[0123s] documentation. * testsuite/systemtap.base/cache.exp: Add tests for -O[0123s]. --- buildrun.cxx | 2 +- hash.cxx | 1 + main.cxx | 27 ++++++++++++++++++++++++++- session.h | 3 +++ stap.1.in | 7 +++++++ testsuite/systemtap.base/cache.exp | 15 +++++++++++++++ 6 files changed, 53 insertions(+), 2 deletions(-) diff --git a/buildrun.cxx b/buildrun.cxx index ccf1ca15..b54a0534 100644 --- a/buildrun.cxx +++ b/buildrun.cxx @@ -187,7 +187,7 @@ compile_pass (systemtap_session& s) // if (s.keep_tmpdir) // o << "CFLAGS += -fverbose-asm -save-temps" << endl; - o << "EXTRA_CFLAGS += -freorder-blocks" << endl; // improve on -Os + o << "EXTRA_CFLAGS += " << s.gcc_flags << endl; // Add -O[0123s] // o << "CFLAGS += -fno-unit-at-a-time" << endl; diff --git a/hash.cxx b/hash.cxx index 45ae05eb..4e85ed28 100644 --- a/hash.cxx +++ b/hash.cxx @@ -175,6 +175,7 @@ find_script_hash (systemtap_session& s, const string& script, const hash &base) h.add(s.ignore_dwarf); // --ignore-dwarf h.add(s.consult_symtab); // --kelf, --kmap h.add(s.skip_badvars); // --skip-badvars + h.add(s.gcc_flags); // -O[0123s] if (!s.kernel_symtab_path.empty()) // --kmap { h.add(s.kernel_symtab_path); diff --git a/main.cxx b/main.cxx index 9dc658ff..2aeff580 100644 --- a/main.cxx +++ b/main.cxx @@ -111,6 +111,14 @@ usage (systemtap_session& s, int exitcode) << " " << s.module_name << endl << " -o FILE send script output to file, instead of stdout. This supports" << endl << " strftime(3) formats for FILE" << endl + << " -O[0123s] optimization to use for C code. Passed to gcc in pass 4." << endl + << " -O Alias for -O1" << endl + << " -O0 Fast compilation" << endl + << " -O1 Optimize, takes a bit more time" << endl + << " -O2 Optimize more, takes more time" << endl + << " -O3 Optimize even more, takes even more time" << endl + << " -Os Optimize for size, like -O2 but tuned for small code size" << endl + << " Default is -O0." << endl << " -c CMD start the probes, run CMD, and exit when it finishes" << endl << " -x PID sets target() to PID" << endl << " -F run as on-file flight recorder with -o." << endl @@ -403,6 +411,7 @@ main (int argc, char * const argv []) s.ignore_dwarf = false; s.load_only = false; s.skip_badvars = false; + s.gcc_flags = "-O0"; // Location of our signing certificate. // If we're root, use the database in SYSCONFDIR, otherwise @@ -487,7 +496,7 @@ main (int argc, char * const argv []) { "vp", 1, &long_opt, LONG_OPT_VERBOSE_PASS }, { NULL, 0, NULL, 0 } }; - int grc = getopt_long (argc, argv, "hVMvtp:I:e:o:R:r:m:kgPc:x:D:bs:uqwl:d:L:FS:", + int grc = getopt_long (argc, argv, "hVMvtp:I:e:o:O::R:r:m:kgPc:x:D:bs:uqwl:d:L:FS:", long_options, NULL); if (grc < 0) break; @@ -551,6 +560,22 @@ main (int argc, char * const argv []) s.output_file = string (optarg); break; + case 'O': + if (optarg == NULL) + s.gcc_flags = "-O1"; + else + s.gcc_flags = "-O" + string (optarg); + + if (s.gcc_flags != "-O0" && s.gcc_flags != "-O1" + && s.gcc_flags != "-O2" && s.gcc_flags != "-O3" + && s.gcc_flags != "-Os") + { + cerr << "'" << s.gcc_flags << "'" + << " isn't a valid optimization option." << endl; + usage (s, 1); + } + break; + case 'R': s.runtime_path = string (optarg); break; diff --git a/session.h b/session.h index a617e47f..32004410 100644 --- a/session.h +++ b/session.h @@ -135,6 +135,9 @@ struct systemtap_session // Skip bad $ vars bool skip_badvars; + // Optimization flag passed to gcc -O[0123s] + std::string gcc_flags; + // NB: It is very important for all of the above (and below) fields // to be cleared in the systemtap_session ctor (elaborate.cxx) // and/or main.cxx(main). diff --git a/stap.1.in b/stap.1.in index 7736a612..1a287a3e 100644 --- a/stap.1.in +++ b/stap.1.in @@ -183,6 +183,13 @@ Send standard output to named file. In bulk mode, percpu files will start with FILE_ (FILE_cpu with -F) followed by the cpu number. This supports strftime(3) formats for FILE. .TP +.BI \-O[0123s] +Optimization to use for C code. Passed to gcc in pass 4. -O is an +alias for -O1, -O0 enables fast compilation, -O1 optimizes the code and +takes a bit more time, -O2 optimizes more and takes more time, -O3 +optimizes even more and takes even more time, -Os optimizes for size, +like -O2 but tuned for small code size. The default is -O0. +.TP .BI \-c " CMD" Start the probes, run CMD, and exit when CMD finishes. .TP diff --git a/testsuite/systemtap.base/cache.exp b/testsuite/systemtap.base/cache.exp index 5c5c1441..e70f3334 100644 --- a/testsuite/systemtap.base/cache.exp +++ b/testsuite/systemtap.base/cache.exp @@ -102,6 +102,21 @@ stap_compile MERGE2 [F_CACHED_COMPILE] $basic_script1 -b -M stap_compile TIMING1 [F_UNCACHED_COMPILE] $basic_script1 -t stap_compile TIMING2 [F_CACHED_COMPILE] $basic_script1 -t +# Using '-O[0123s]' (C compile optimizations) should change the hash +# unless they are the same +stap_compile OPTO [F_UNCACHED_COMPILE] $basic_script1 -O +# -O0 is the default, so will have been cached by BASIC1 +stap_compile OPTZERO [F_CACHED_COMPILE] $basic_script1 -O0 +# -O is an alias for -O1, so already cached +stap_compile OPTONE [F_CACHED_COMPILE] $basic_script1 -O1 +stap_compile OPTTWO [F_UNCACHED_COMPILE] $basic_script1 -O2 +stap_compile OPTTHREE [F_UNCACHED_COMPILE] $basic_script1 -O3 +stap_compile OPTSMALL [F_UNCACHED_COMPILE] $basic_script1 -Os +# Bad -O argument should be rejected +stap_compile OPTBAD [F_UNCACHED_NO_COMPILE] $basic_script1 -OX + +stap_compile TIMING2 [F_CACHED_COMPILE] $basic_script1 -t + # Changing the runtime directory should change the hash set new_runtime [exec pwd]/.cache_test_runtime exec /bin/rm -f $new_runtime -- cgit From 4a4edc21a14792a4cc240b601912734027945ae8 Mon Sep 17 00:00:00 2001 From: wenji Date: Sat, 27 Jun 2009 09:10:18 -0400 Subject: PR10075: emit address in probe registration logic * tapsets.cxx(dwarf_derived_probe_group::emit_module_init, kprobe_derived_probe_group::emit_module_init): print address. --- tapsets.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tapsets.cxx b/tapsets.cxx index aecdca61..dbf3c55d 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -3237,7 +3237,7 @@ dwarf_derived_probe_group::emit_module_init (systemtap_session& s) s.op->newline() << "if (rc) {"; // PR6749: tolerate a failed register_*probe. s.op->newline(1) << "sdp->registered_p = 0;"; s.op->newline() << "if (!sdp->optional_p)"; - s.op->newline(1) << "_stp_warn (\"probe %s registration error (rc %d)\", probe_point, rc);"; + s.op->newline(1) << "_stp_warn (\"probe %s (address 0x%lx) registration error (rc %d)\", probe_point, relocated_addr, rc);"; s.op->newline(-1) << "rc = 0;"; // continue with other probes // XXX: shall we increment numskipped? s.op->newline(-1) << "}"; @@ -4787,7 +4787,7 @@ kprobe_derived_probe_group::emit_module_init (systemtap_session& s) s.op->newline() << "if (rc) {"; // PR6749: tolerate a failed register_*probe. s.op->newline(1) << "sdp->registered_p = 0;"; s.op->newline() << "if (!sdp->optional_p)"; - s.op->newline(1) << "_stp_warn (\"probe %s registration error (rc %d)\", probe_point, rc);"; + s.op->newline(1) << "_stp_warn (\"probe %s (address 0x%lx) registration error (rc %d)\", probe_point, addr, rc);"; s.op->newline(-1) << "rc = 0;"; // continue with other probes // XXX: shall we increment numskipped? s.op->newline(-1) << "}"; -- cgit