Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- commit 0fd870816009e85984c923d8b4d3e7bc27cb9462
- Author: Yichun Zhang (agentzh) <yichun@openresty.com>
- Date: Sat Nov 2 22:25:46 2019 -0700
- optimize: turned stap-symbols.h into a separate C compilation unit, stap_symbols.c, to speed up the kernel module building process.
- The speed up is not significant since stap-symbols.h is fast to compile
- anyway. It just saves hundreds of milliseconds at most.
- diff --git a/buildrun.cxx b/buildrun.cxx
- index 1724a9402..1cb653fcf 100644
- --- a/buildrun.cxx
- +++ b/buildrun.cxx
- @@ -323,7 +323,7 @@ compile_pass (systemtap_session& s)
- o << "STAPCONF_HEADER := " << s.tmpdir << "/" << s.stapconf_name << endl;
- - if ((s.use_user_stapconf || s.use_cached_stapconf) && !s.gen_stapconf)
- + if (s.use_user_stapconf || s.use_cached_stapconf)
- goto after_stapconf_rules;
- {
- @@ -516,10 +516,13 @@ compile_pass (systemtap_session& s)
- o << "@";
- o << "cat $^ > $(STAPCONF_HEADER)" << endl;
- - o << "\t";
- - if (s.verbose < 4)
- - o << "@";
- - o << "cp $(STAPCONF_HEADER) \"" << s.user_stapconf << "\"" << endl;
- + if (s.use_user_stapconf)
- + {
- + o << "\t";
- + if (s.verbose < 4)
- + o << "@";
- + o << "cp $(STAPCONF_HEADER) \"" << s.user_stapconf << "\"" << endl;
- + }
- after_stapconf_rules:
- @@ -644,7 +647,9 @@ after_stapconf_rules:
- objname[objname.size()-1] = 'o'; // now objname
- o << " " + objname;
- }
- - o << endl;
- + o << " stap_symbols.o" << endl;
- +
- + o << s.tmpdir << "/stap_symbols.o: $(STAPCONF_HEADER)" << endl;
- // add all stapconf dependencies
- string translated = s.translated_source;
- @@ -660,6 +665,8 @@ after_stapconf_rules:
- o.close ();
- + //system ((string("cp ") + makefile_nm + " ./mk").c_str ());
- +
- // Generate module directory pathname and make sure it exists.
- string module_dir = s.kernel_build_tree;
- string module_dir_makefile = module_dir + "/Makefile";
- diff --git a/runtime/sym.h b/runtime/sym.h
- index a3825539d..6aa4cfcbc 100644
- --- a/runtime/sym.h
- +++ b/runtime/sym.h
- @@ -139,13 +139,13 @@ struct _stp_module {
- };
- /* Defined by translator-generated stap-symbols.h. */
- -static struct _stp_module *_stp_modules [];
- -static const unsigned _stp_num_modules;
- +extern struct _stp_module *_stp_modules [];
- +extern const unsigned _stp_num_modules;
- /* Used in the unwinder to special case unwinding through kretprobes. */
- /* Initialized through translator (stap-symbols.h) relative to kernel */
- /* load address, fixup by transport symbols _stp_do_relocation */
- -static unsigned long _stp_kretprobe_trampoline;
- +extern unsigned long _stp_kretprobe_trampoline;
- static unsigned long _stp_kmodule_relocate (const char *module,
- const char *section,
- @@ -160,10 +160,10 @@ static void _stp_kmodule_update_address(const char* module,
- #if (defined(STP_USE_DWARF_UNWINDER) && defined(STP_NEED_UNWIND_DATA)) \
- || defined(STP_NEED_LINE_DATA)
- -static struct _stp_module _stp_module_self;
- -static struct _stp_section _stp_module_self_sections[];
- -static struct _stp_symbol _stp_module_self_symbols_0[];
- -static struct _stp_symbol _stp_module_self_symbols_1[];
- +extern struct _stp_module _stp_module_self;
- +extern struct _stp_section _stp_module_self_sections[];
- +extern struct _stp_symbol _stp_module_self_symbols_0[];
- +extern struct _stp_symbol _stp_module_self_symbols_1[];
- #endif /* defined(STP_USE_DWARF_UNWINDER) && defined(STP_NEED_UNWIND_DATA)
- || defined(STP_NEED_LINE_DATA) */
- #endif /* _STP_SYM_H_ */
- diff --git a/session.h b/session.h
- index 774158bd9..22a3937d8 100644
- --- a/session.h
- +++ b/session.h
- @@ -419,6 +419,8 @@ public:
- // NB: It is very important for all of the above (and below) fields
- // to be cleared in the systemtap_session ctor (session.cxx).
- + std::ofstream *comm_hdr;
- +
- // unparser data
- translator_output* op;
- std::vector<translator_output*> auxiliary_outputs;
- diff --git a/translate.cxx b/translate.cxx
- index d7c2cc2af..c45908f99 100644
- --- a/translate.cxx
- +++ b/translate.cxx
- @@ -7790,15 +7790,18 @@ prepare_symbol_data (systemtap_session& s)
- void
- emit_symbol_data (systemtap_session& s)
- {
- - string symfile = "stap-symbols.h";
- + string symfile = "stap_symbols.c";
- - s.op->newline() << "#include " << lex_cast_qstring (symfile);
- + ofstream kallsyms ((s.tmpdir + "/" + symfile).c_str());
- - ofstream kallsyms_out ((s.tmpdir + "/" + symfile).c_str());
- + kallsyms << "#include <linux/module.h>\n"
- + "#include <linux/kernel.h>\n"
- + "#include <sym.h>\n"
- + "#include \"stap_common.h\"\n";
- vector<pair<string,unsigned> > seclist;
- map<unsigned, addrmap_t> addrmap;
- - unwindsym_dump_context ctx = { s, kallsyms_out,
- + unwindsym_dump_context ctx = { s, kallsyms,
- 0, /* module index */
- 0, NULL, 0, /* build_id len, bits, vaddr */
- ~0UL, /* stp_kretprobe_trampoline_addr */
- @@ -7892,13 +7895,13 @@ void
- self_unwind_declarations(unwindsym_dump_context *ctx)
- {
- ctx->output << "static uint8_t _stp_module_self_eh_frame [] = {0,};\n";
- - ctx->output << "static struct _stp_symbol _stp_module_self_symbols_0[] = {{0},};\n";
- - ctx->output << "static struct _stp_symbol _stp_module_self_symbols_1[] = {{0},};\n";
- - ctx->output << "static struct _stp_section _stp_module_self_sections[] = {\n";
- + ctx->output << "struct _stp_symbol _stp_module_self_symbols_0[] = {{0},};\n";
- + ctx->output << "struct _stp_symbol _stp_module_self_symbols_1[] = {{0},};\n";
- + ctx->output << "struct _stp_section _stp_module_self_sections[] = {\n";
- ctx->output << "{.name = \".symtab\", .symbols = _stp_module_self_symbols_0, .num_symbols = 0},\n";
- ctx->output << "{.name = \".text\", .symbols = _stp_module_self_symbols_1, .num_symbols = 0},\n";
- ctx->output << "};\n";
- - ctx->output << "static struct _stp_module _stp_module_self = {\n";
- + ctx->output << "struct _stp_module _stp_module_self = {\n";
- ctx->output << ".name = \"stap_self_tmp_value\",\n";
- ctx->output << ".path = \"stap_self_tmp_value\",\n";
- ctx->output << ".num_sections = 2,\n";
- @@ -7936,16 +7939,16 @@ emit_symbol_data_done (unwindsym_dump_context *ctx, systemtap_session& s)
- // Print out a definition of the runtime's _stp_modules[] globals.
- ctx->output << "\n";
- self_unwind_declarations(ctx);
- - ctx->output << "static struct _stp_module *_stp_modules [] = {\n";
- + ctx->output << "struct _stp_module *_stp_modules [] = {\n";
- for (unsigned i=0; i<ctx->stp_module_index; i++)
- {
- ctx->output << "& _stp_module_" << i << ",\n";
- }
- ctx->output << "& _stp_module_self,\n";
- ctx->output << "};\n";
- - ctx->output << "static const unsigned _stp_num_modules = ARRAY_SIZE(_stp_modules);\n";
- + ctx->output << "const unsigned _stp_num_modules = ARRAY_SIZE(_stp_modules);\n";
- - ctx->output << "static unsigned long _stp_kretprobe_trampoline = ";
- + ctx->output << "unsigned long _stp_kretprobe_trampoline = ";
- // Special case for -1, which is invalid in hex if host width > target width.
- if (ctx->stp_kretprobe_trampoline_addr == (unsigned long) -1)
- ctx->output << "-1;\n";
- @@ -8047,6 +8050,8 @@ translate_pass (systemtap_session& s)
- int rc = 0;
- s.op = new translator_output (s.translated_source);
- + s.comm_hdr = new ofstream (s.tmpdir + "/stap_common.h");
- +
- // additional outputs might be found in s.auxiliary_outputs
- c_unparser cup (& s);
- s.up = & cup;
- @@ -8114,31 +8119,43 @@ translate_pass (systemtap_session& s)
- << "__attribute__ ((section (\"" << STAP_PRIVILEGE_SECTION <<"\")))"
- << " = STP_PRIVILEGE;";
- - s.op->newline() << "#ifndef MAXNESTING";
- - s.op->newline() << "#define MAXNESTING " << nesting;
- - s.op->newline() << "#endif";
- + s.op->newline() << "#include \"stap_common.h\"";
- +
- + *s.comm_hdr << "#ifndef MAXNESTING" << endl
- + << "#define MAXNESTING " << nesting << endl
- + << "#endif" << endl;
- // Generated macros specifying how much storage is required for
- // regexp subexpressions. (TODOXXX Skip when there are no DFAs?)
- - s.op->newline() << "#define STAPREGEX_MAX_MAP " << s.dfa_maxmap;
- - s.op->newline() << "#define STAPREGEX_MAX_TAG " << s.dfa_maxtag;
- + *s.comm_hdr << "#define STAPREGEX_MAX_MAP " << s.dfa_maxmap << endl;
- + *s.comm_hdr << "#define STAPREGEX_MAX_TAG " << s.dfa_maxtag << endl;
- - s.op->newline() << "#define STP_SKIP_BADVARS " << (s.skip_badvars ? 1 : 0);
- + *s.comm_hdr << "#define STP_SKIP_BADVARS " << (s.skip_badvars ? 1 : 0) << endl;
- if (s.bulk_mode)
- - s.op->newline() << "#define STP_BULKMODE";
- + *s.comm_hdr << "#define STP_BULKMODE" << endl;
- if (s.timing || s.monitor)
- - s.op->newline() << "#define STP_TIMING";
- + *s.comm_hdr << "#define STP_TIMING" << endl;
- if (s.need_unwind)
- - s.op->newline() << "#define STP_NEED_UNWIND_DATA 1";
- + *s.comm_hdr << "#define STP_NEED_UNWIND_DATA 1" << endl;
- if (s.need_lines)
- - s.op->newline() << "#define STP_NEED_LINE_DATA 1";
- + *s.comm_hdr << "#define STP_NEED_LINE_DATA 1" << endl;
- // Emit the total number of probes (not regarding merged probe handlers)
- - s.op->newline() << "#define STP_PROBE_COUNT " << s.probes.size();
- + *s.comm_hdr << "#define STP_PROBE_COUNT " << s.probes.size() << endl;
- +
- + *s.comm_hdr << "#if (defined(__arm__) || defined(__i386__) || defined(__x86_64__) || defined(__powerpc64__)) || defined (__s390x__) || defined(__aarch64__) || defined(__mips__)\n"
- + "#ifdef STP_NEED_UNWIND_DATA\n"
- + "#ifndef STP_USE_DWARF_UNWINDER\n"
- + "#define STP_USE_DWARF_UNWINDER\n"
- + "#endif\n"
- + "#endif\n"
- + "#endif\n";
- +
- + s.comm_hdr->close ();
- // Emit systemtap_module_refresh() prototype so we can reference it
- s.op->newline() << "static void systemtap_module_refresh (const char* modname);";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement