Quellcode durchsuchen

HPCC-10640 Testsocket segfault on startup on ARM

Segfaults when trying to log the fact that the RDTSC instruction is not
available, before any logging has been set up.

This commit fixes both the crash when logging from within the jdebug setup
code (by ensuring that logging is set up earlier), and the fact that the
system logs the failure to use rdtsc on non-intel systems.

Signed-off-by: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman vor 11 Jahren
Ursprung
Commit
1a3315d94a
2 geänderte Dateien mit 11 neuen und 3 gelöschten Zeilen
  1. 1 1
      system/include/modinit.h
  2. 10 2
      system/jlib/jdebug.cpp

+ 1 - 1
system/include/modinit.h

@@ -30,6 +30,7 @@
 #define INIT_PRIORITY_SYSTEM         0xF000 // system, calls to system or non-dependent calls (can be called asap)
 
 
+#define INIT_PRIORITY_JLOG       INIT_PRIORITY_SYSTEM+0x950
 #define INIT_PRIORITY_JDEBUG1    INIT_PRIORITY_SYSTEM+0x900
 #define INIT_PRIORITY_JHEAP      INIT_PRIORITY_SYSTEM+0x800
 #define INIT_PRIORITY_JIFACE     INIT_PRIORITY_SYSTEM+0x800
@@ -38,7 +39,6 @@
 #define INIT_PRIORITY_JHASH      INIT_PRIORITY_SYSTEM+0x800
 #define INIT_PRIORITY_JPTREE     INIT_PRIORITY_SYSTEM+0x700
 
-#define INIT_PRIORITY_JLOG       INIT_PRIORITY_SYSTEM+0x600
 #define INIT_PRIORITY_JMISC1     INIT_PRIORITY_SYSTEM+0x500
 #define INIT_PRIORITY_JDEBUG2    INIT_PRIORITY_SYSTEM+0x500
 #define INIT_PRIORITY_JMISC2     INIT_PRIORITY_SYSTEM+0x400

+ 10 - 2
system/jlib/jdebug.cpp

@@ -285,7 +285,9 @@ double getCycleToNanoScale()
 #else
 
 static bool use_gettimeofday=false;
+#if defined(_ARCH_X86_) || defined(_ARCH_X86_64_)
 static bool useRDTSC = _USE_RDTSC;
+#endif
 static double cycleToNanoScale; 
 
 void calibrate_timing()
@@ -296,7 +298,7 @@ void calibrate_timing()
         unsigned long ebx; 
         unsigned long ecx;
         unsigned long edx;
-#ifdef __64BIT__
+#if defined(_ARCH_X86_64_)
         __asm__ ("cpuid\n\t" : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)   : "0" (1));
 
 #else
@@ -312,7 +314,6 @@ void calibrate_timing()
         if ((edx&0x10)==0)
             useRDTSC = false;
     }
-#endif
     if (useRDTSC) {
         unsigned startu = usTick();
         cycle_t start = getTSC();
@@ -333,14 +334,17 @@ void calibrate_timing()
         ERRLOG("calibrate_timing failed using RDTSC");
         useRDTSC = false;
     }
+#endif
     cycleToNanoScale = 1.0;
 }
 
 
 cycle_t jlib_decl get_cycles_now()
 {
+#if defined(_ARCH_X86_) || defined(_ARCH_X86_64_)
     if (useRDTSC)
         return getTSC();
+#endif
 #ifndef __APPLE__
     if (!use_gettimeofday) {
         timespec tm;
@@ -357,15 +361,19 @@ cycle_t jlib_decl get_cycles_now()
 
 __int64 jlib_decl cycle_to_nanosec(cycle_t cycles)
 {
+#if defined(_ARCH_X86_) || defined(_ARCH_X86_64_)
     if (useRDTSC)
         return (__int64)((double)cycles * cycleToNanoScale);
+#endif
     return cycles;
 }
 
 cycle_t nanosec_to_cycle(__int64 ns)
 {
+#if defined(_ARCH_X86_) || defined(_ARCH_X86_64_)
     if (useRDTSC)
         return (__int64)((double)ns / cycleToNanoScale);
+#endif
     return ns;
 }