Advertisement
Guest User

Untitled

a guest
Dec 18th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 9.82 KB | None | 0 0
  1. commit 0fd870816009e85984c923d8b4d3e7bc27cb9462
  2. Author: Yichun Zhang (agentzh) <yichun@openresty.com>
  3. Date:   Sat Nov 2 22:25:46 2019 -0700
  4.  
  5.     optimize: turned stap-symbols.h into a separate C compilation unit, stap_symbols.c, to speed up the kernel module building process.
  6.    
  7.     The speed up is not significant since stap-symbols.h is fast to compile
  8.     anyway. It just saves hundreds of milliseconds at most.
  9.  
  10. diff --git a/buildrun.cxx b/buildrun.cxx
  11. index 1724a9402..1cb653fcf 100644
  12. --- a/buildrun.cxx
  13. +++ b/buildrun.cxx
  14. @@ -323,7 +323,7 @@ compile_pass (systemtap_session& s)
  15.  
  16.    o << "STAPCONF_HEADER := " << s.tmpdir << "/" << s.stapconf_name << endl;
  17.  
  18. -  if ((s.use_user_stapconf || s.use_cached_stapconf) && !s.gen_stapconf)
  19. +  if (s.use_user_stapconf || s.use_cached_stapconf)
  20.      goto after_stapconf_rules;
  21.  
  22.    {
  23. @@ -516,10 +516,13 @@ compile_pass (systemtap_session& s)
  24.      o << "@";
  25.    o << "cat $^ > $(STAPCONF_HEADER)" << endl;
  26.  
  27. -  o << "\t";
  28. -  if (s.verbose < 4)
  29. -    o << "@";
  30. -  o << "cp $(STAPCONF_HEADER) \"" << s.user_stapconf << "\"" << endl;
  31. +  if (s.use_user_stapconf)
  32. +    {
  33. +      o << "\t";
  34. +      if (s.verbose < 4)
  35. +        o << "@";
  36. +      o << "cp $(STAPCONF_HEADER) \"" << s.user_stapconf << "\"" << endl;
  37. +    }
  38.  
  39.  after_stapconf_rules:
  40.  
  41. @@ -644,7 +647,9 @@ after_stapconf_rules:
  42.        objname[objname.size()-1] = 'o'; // now objname
  43.        o << " " + objname;
  44.      }
  45. -  o << endl;
  46. +  o << " stap_symbols.o" << endl;
  47. +
  48. +  o << s.tmpdir << "/stap_symbols.o: $(STAPCONF_HEADER)" << endl;
  49.  
  50.    // add all stapconf dependencies
  51.    string translated = s.translated_source;
  52. @@ -660,6 +665,8 @@ after_stapconf_rules:
  53.  
  54.    o.close ();
  55.  
  56. +  //system ((string("cp ") + makefile_nm + " ./mk").c_str ());
  57. +
  58.    // Generate module directory pathname and make sure it exists.
  59.    string module_dir = s.kernel_build_tree;
  60.    string module_dir_makefile = module_dir + "/Makefile";
  61. diff --git a/runtime/sym.h b/runtime/sym.h
  62. index a3825539d..6aa4cfcbc 100644
  63. --- a/runtime/sym.h
  64. +++ b/runtime/sym.h
  65. @@ -139,13 +139,13 @@ struct _stp_module {
  66.  };
  67.  
  68.  /* Defined by translator-generated stap-symbols.h. */
  69. -static struct _stp_module *_stp_modules [];
  70. -static const unsigned _stp_num_modules;
  71. +extern struct _stp_module *_stp_modules [];
  72. +extern const unsigned _stp_num_modules;
  73.  
  74.  /* Used in the unwinder to special case unwinding through kretprobes. */
  75.  /* Initialized through translator (stap-symbols.h) relative to kernel */
  76.  /* load address, fixup by transport symbols _stp_do_relocation */
  77. -static unsigned long _stp_kretprobe_trampoline;
  78. +extern unsigned long _stp_kretprobe_trampoline;
  79.  
  80.  static unsigned long _stp_kmodule_relocate (const char *module,
  81.                         const char *section,
  82. @@ -160,10 +160,10 @@ static void _stp_kmodule_update_address(const char* module,
  83.  
  84.  #if (defined(STP_USE_DWARF_UNWINDER) && defined(STP_NEED_UNWIND_DATA)) \
  85.      || defined(STP_NEED_LINE_DATA)
  86. -static struct _stp_module _stp_module_self;
  87. -static struct _stp_section _stp_module_self_sections[];
  88. -static struct _stp_symbol _stp_module_self_symbols_0[];
  89. -static struct _stp_symbol _stp_module_self_symbols_1[];
  90. +extern struct _stp_module _stp_module_self;
  91. +extern struct _stp_section _stp_module_self_sections[];
  92. +extern struct _stp_symbol _stp_module_self_symbols_0[];
  93. +extern struct _stp_symbol _stp_module_self_symbols_1[];
  94.  #endif /* defined(STP_USE_DWARF_UNWINDER) && defined(STP_NEED_UNWIND_DATA)
  95.            || defined(STP_NEED_LINE_DATA) */
  96.  #endif /* _STP_SYM_H_ */
  97. diff --git a/session.h b/session.h
  98. index 774158bd9..22a3937d8 100644
  99. --- a/session.h
  100. +++ b/session.h
  101. @@ -419,6 +419,8 @@ public:
  102.    // NB: It is very important for all of the above (and below) fields
  103.    // to be cleared in the systemtap_session ctor (session.cxx).
  104.  
  105. +  std::ofstream *comm_hdr;
  106. +
  107.    // unparser data
  108.    translator_output* op;
  109.    std::vector<translator_output*> auxiliary_outputs;
  110. diff --git a/translate.cxx b/translate.cxx
  111. index d7c2cc2af..c45908f99 100644
  112. --- a/translate.cxx
  113. +++ b/translate.cxx
  114. @@ -7790,15 +7790,18 @@ prepare_symbol_data (systemtap_session& s)
  115.  void
  116.  emit_symbol_data (systemtap_session& s)
  117.  {
  118. -  string symfile = "stap-symbols.h";
  119. +  string symfile = "stap_symbols.c";
  120.  
  121. -  s.op->newline() << "#include " << lex_cast_qstring (symfile);
  122. +  ofstream kallsyms ((s.tmpdir + "/" + symfile).c_str());
  123.  
  124. -  ofstream kallsyms_out ((s.tmpdir + "/" + symfile).c_str());
  125. +  kallsyms << "#include <linux/module.h>\n"
  126. +    "#include <linux/kernel.h>\n"
  127. +    "#include <sym.h>\n"
  128. +    "#include \"stap_common.h\"\n";
  129.  
  130.    vector<pair<string,unsigned> > seclist;
  131.    map<unsigned, addrmap_t> addrmap;
  132. -  unwindsym_dump_context ctx = { s, kallsyms_out,
  133. +  unwindsym_dump_context ctx = { s, kallsyms,
  134.                  0, /* module index */
  135.                  0, NULL, 0, /* build_id len, bits, vaddr */
  136.                  ~0UL, /* stp_kretprobe_trampoline_addr */
  137. @@ -7892,13 +7895,13 @@ void
  138.  self_unwind_declarations(unwindsym_dump_context *ctx)
  139.  {
  140.    ctx->output << "static uint8_t _stp_module_self_eh_frame [] = {0,};\n";
  141. -  ctx->output << "static struct _stp_symbol _stp_module_self_symbols_0[] = {{0},};\n";
  142. -  ctx->output << "static struct _stp_symbol _stp_module_self_symbols_1[] = {{0},};\n";
  143. -  ctx->output << "static struct _stp_section _stp_module_self_sections[] = {\n";
  144. +  ctx->output << "struct _stp_symbol _stp_module_self_symbols_0[] = {{0},};\n";
  145. +  ctx->output << "struct _stp_symbol _stp_module_self_symbols_1[] = {{0},};\n";
  146. +  ctx->output << "struct _stp_section _stp_module_self_sections[] = {\n";
  147.    ctx->output << "{.name = \".symtab\", .symbols = _stp_module_self_symbols_0, .num_symbols = 0},\n";
  148.    ctx->output << "{.name = \".text\", .symbols = _stp_module_self_symbols_1, .num_symbols = 0},\n";
  149.    ctx->output << "};\n";
  150. -  ctx->output << "static struct _stp_module _stp_module_self = {\n";
  151. +  ctx->output << "struct _stp_module _stp_module_self = {\n";
  152.    ctx->output << ".name = \"stap_self_tmp_value\",\n";
  153.    ctx->output << ".path = \"stap_self_tmp_value\",\n";
  154.    ctx->output << ".num_sections = 2,\n";
  155. @@ -7936,16 +7939,16 @@ emit_symbol_data_done (unwindsym_dump_context *ctx, systemtap_session& s)
  156.    // Print out a definition of the runtime's _stp_modules[] globals.
  157.    ctx->output << "\n";
  158.    self_unwind_declarations(ctx);
  159. -   ctx->output << "static struct _stp_module *_stp_modules [] = {\n";
  160. +   ctx->output << "struct _stp_module *_stp_modules [] = {\n";
  161.    for (unsigned i=0; i<ctx->stp_module_index; i++)
  162.      {
  163.        ctx->output << "& _stp_module_" << i << ",\n";
  164.      }
  165.    ctx->output << "& _stp_module_self,\n";
  166.    ctx->output << "};\n";
  167. -  ctx->output << "static const unsigned _stp_num_modules = ARRAY_SIZE(_stp_modules);\n";
  168. +  ctx->output << "const unsigned _stp_num_modules = ARRAY_SIZE(_stp_modules);\n";
  169.  
  170. -  ctx->output << "static unsigned long _stp_kretprobe_trampoline = ";
  171. +  ctx->output << "unsigned long _stp_kretprobe_trampoline = ";
  172.    // Special case for -1, which is invalid in hex if host width > target width.
  173.    if (ctx->stp_kretprobe_trampoline_addr == (unsigned long) -1)
  174.      ctx->output << "-1;\n";
  175. @@ -8047,6 +8050,8 @@ translate_pass (systemtap_session& s)
  176.    int rc = 0;
  177.  
  178.    s.op = new translator_output (s.translated_source);
  179. +  s.comm_hdr = new ofstream (s.tmpdir + "/stap_common.h");
  180. +
  181.    // additional outputs might be found in s.auxiliary_outputs
  182.    c_unparser cup (& s);
  183.    s.up = & cup;
  184. @@ -8114,31 +8119,43 @@ translate_pass (systemtap_session& s)
  185.               << "__attribute__ ((section (\"" << STAP_PRIVILEGE_SECTION <<"\")))"
  186.               << " = STP_PRIVILEGE;";
  187.  
  188. -      s.op->newline() << "#ifndef MAXNESTING";
  189. -      s.op->newline() << "#define MAXNESTING " << nesting;
  190. -      s.op->newline() << "#endif";
  191. +      s.op->newline() << "#include \"stap_common.h\"";
  192. +
  193. +      *s.comm_hdr << "#ifndef MAXNESTING" << endl
  194. +        << "#define MAXNESTING " << nesting << endl
  195. +        << "#endif" << endl;
  196.  
  197.        // Generated macros specifying how much storage is required for
  198.        // regexp subexpressions. (TODOXXX Skip when there are no DFAs?)
  199. -      s.op->newline() << "#define STAPREGEX_MAX_MAP " << s.dfa_maxmap;
  200. -      s.op->newline() << "#define STAPREGEX_MAX_TAG " << s.dfa_maxtag;
  201. +      *s.comm_hdr << "#define STAPREGEX_MAX_MAP " << s.dfa_maxmap << endl;
  202. +      *s.comm_hdr << "#define STAPREGEX_MAX_TAG " << s.dfa_maxtag << endl;
  203.  
  204. -      s.op->newline() << "#define STP_SKIP_BADVARS " << (s.skip_badvars ? 1 : 0);
  205. +      *s.comm_hdr << "#define STP_SKIP_BADVARS " << (s.skip_badvars ? 1 : 0) << endl;
  206.  
  207.        if (s.bulk_mode)
  208. -     s.op->newline() << "#define STP_BULKMODE";
  209. +     *s.comm_hdr << "#define STP_BULKMODE" << endl;
  210.  
  211.        if (s.timing || s.monitor)
  212. -   s.op->newline() << "#define STP_TIMING";
  213. +   *s.comm_hdr << "#define STP_TIMING" << endl;
  214.  
  215.        if (s.need_unwind)
  216. -   s.op->newline() << "#define STP_NEED_UNWIND_DATA 1";
  217. +   *s.comm_hdr << "#define STP_NEED_UNWIND_DATA 1" << endl;
  218.  
  219.        if (s.need_lines)
  220. -        s.op->newline() << "#define STP_NEED_LINE_DATA 1";
  221. +        *s.comm_hdr << "#define STP_NEED_LINE_DATA 1" << endl;
  222.  
  223.        // Emit the total number of probes (not regarding merged probe handlers)
  224. -      s.op->newline() << "#define STP_PROBE_COUNT " << s.probes.size();
  225. +      *s.comm_hdr << "#define STP_PROBE_COUNT " << s.probes.size() << endl;
  226. +
  227. +      *s.comm_hdr << "#if (defined(__arm__) || defined(__i386__) || defined(__x86_64__) || defined(__powerpc64__)) || defined (__s390x__) || defined(__aarch64__) || defined(__mips__)\n"
  228. +        "#ifdef STP_NEED_UNWIND_DATA\n"
  229. +        "#ifndef STP_USE_DWARF_UNWINDER\n"
  230. +        "#define STP_USE_DWARF_UNWINDER\n"
  231. +        "#endif\n"
  232. +        "#endif\n"
  233. +        "#endif\n";
  234. +
  235. +      s.comm_hdr->close ();
  236.  
  237.        // Emit systemtap_module_refresh() prototype so we can reference it
  238.        s.op->newline() << "static void systemtap_module_refresh (const char* modname);";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement