[RFC,06/11] elf/rtld: introduce runtime option to disable HP_TIMING_INLINE
diff mbox series

Message ID cb3d476eaefbe7c68b8149cc107adfdb102edad9.1568219400.git.isaku.yamahata@gmail.com
State New
Headers show
Series
  • Library OS support
Related show

Commit Message

Isaku Yamahata Sept. 11, 2019, 9:04 p.m. UTC
This patch introduce runtime option, __hp_timing_disabled with
weak symbol to disable rtld profiling with HP_TIMING_INLINE.
Because some LibOS doesn't suport rdtsc/rdtscp (e.g. SGX enclave),
this allows LibOS to disable HP_TIMING profiling on startup.
The impact on traditional runtime is "if (__hp_timing_disabled)".

Signed-off-by: Isaku Yamahata <isaku.yamahata@gmail.com>
---
 elf/Versions |  1 +
 elf/rtld.c   | 20 +++++++++++++++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)

Patch
diff mbox series

diff --git a/elf/Versions b/elf/Versions
index 619676afef..d7d12d7aba 100644
--- a/elf/Versions
+++ b/elf/Versions
@@ -83,5 +83,6 @@  ld {
     __libos_release; __libos_version; __libos_abi;
     # stub symbols for libos support
     __libos_map_library;
+    __hp_timing_disabled;
   }
 }
diff --git a/elf/rtld.c b/elf/rtld.c
index c9490ff694..8d759dfa8c 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -46,6 +46,8 @@ 
 
 #include <assert.h>
 
+#include "libos.h"
+
 /* Only enables rtld profiling for architectures which provides non generic
    hp-timing support.  The generic support requires either syscall
    (clock_gettime), which will incur in extra overhead on loading time.
@@ -58,9 +60,18 @@ 
 # define RTLD_TIMING_SET(var, value) (var) = (value)
 # define RTLD_TIMING_REF(var)        &(var)
 
+bool __hp_timing_disabled __attribute__((weak))= false;
+# define HP_TIMING_DISABLED __hp_timing_disabled
+LIBOS_NOTES("variables", LIBOS_NOTE_VARIABLE,
+            __hp_timing_disabled, 1, "__hp_timing_disabled");
+
 static inline void
 rtld_timer_start (hp_timing_t *var)
 {
+  if (HP_TIMING_DISABLED) {
+    memset(var, 0, sizeof(*var));
+    return;
+  }
   HP_TIMING_NOW (*var);
 }
 
@@ -68,6 +79,8 @@  static inline void
 rtld_timer_stop (hp_timing_t *var, hp_timing_t start)
 {
   hp_timing_t stop;
+  if (HP_TIMING_DISABLED)
+    return;
   HP_TIMING_NOW (stop);
   HP_TIMING_DIFF (*var, start, stop);
 }
@@ -76,6 +89,8 @@  static inline void
 rtld_timer_accum (hp_timing_t *sum, hp_timing_t start)
 {
   hp_timing_t stop;
+  if (HP_TIMING_DISABLED)
+    return;
   rtld_timer_stop (&stop, start);
   HP_TIMING_ACCUM_NT(*sum, stop);
 }
@@ -87,6 +102,7 @@  rtld_timer_accum (hp_timing_t *sum, hp_timing_t start)
 # define rtld_timer_start(var)
 # define rtld_timer_stop(var, start)
 # define rtld_timer_accum(sum, start)
+# define HP_TIMING_DISABLED false
 #endif
 
 /* Avoid PLT use for our local calls at startup.  */
@@ -2748,6 +2764,8 @@  static void
 print_statistics_item (const char *title, hp_timing_t time,
 		       hp_timing_t total)
 {
+  if (HP_TIMING_DISABLED)
+    return;
   char cycles[HP_TIMING_PRINT_SIZE];
   HP_TIMING_PRINT (cycles, sizeof (cycles), time);
 
@@ -2779,7 +2797,7 @@  __attribute ((noinline))
 print_statistics (const hp_timing_t *rtld_total_timep)
 {
 #if HP_TIMING_INLINE
-  {
+  if (!HP_TIMING_DISABLED) {
     char cycles[HP_TIMING_PRINT_SIZE];
     HP_TIMING_PRINT (cycles, sizeof (cycles), *rtld_total_timep);
     _dl_debug_printf ("\nruntime linker statistics:\n"