about summary refs log tree commit diff stats
path: root/src/main.c
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2024-02-23 16:41:44 +0100
committerptitSeb <sebastien.chev@gmail.com>2024-02-23 16:41:44 +0100
commitffda782c3d88d977acc12a3c2c2738719f9304ed (patch)
treea0e1893fb28090c4f0f2a26c7a67bb40ae71f6b5 /src/main.c
parent3a6df996dc85257a5496ecb28a72579df225a176 (diff)
downloadbox64-ffda782c3d88d977acc12a3c2c2738719f9304ed.tar.gz
box64-ffda782c3d88d977acc12a3c2c2738719f9304ed.zip
Better handling of Hardware counter for rdtsc emulation (ARM64 only for now), more cpuid leafs, and introduce BOX64_RDTSC env.var. with a profile that use it
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
index 000b1c9f..491bde58 100644
--- a/src/main.c
+++ b/src/main.c
@@ -57,6 +57,7 @@ int box64_mmap32 = 1;
 int box64_mmap32 = 0;
 #endif
 int box64_ignoreint3 = 0;
+int box64_rdtsc = 0;
 #ifdef DYNAREC
 int box64_dynarec = 1;
 int box64_dynarec_dump = 0;
@@ -999,6 +1000,30 @@ void LoadLogEnv()
         if(box64_ignoreint3)
             printf_log(LOG_INFO, "Will silently ignore INT3 in the code\n");
     }
+    p = getenv("BOX64_RDTSC");
+        if(p) {
+        if(strlen(p)==1) {
+            if(p[0]>='0' && p[0]<='0'+2)
+                box64_rdtsc = p[0]-'0';
+        }
+        if(box64_rdtsc==2) {
+            #if defined(ARM64)
+            box64_rdtsc = 0;    // allow hardxare counter
+            uint64_t freq = ReadTSCFrequency(NULL);
+            printf_log(LOG_INFO, "Hardware counter measured at %d Mhz, ", freq/1000);
+            if(freq>1000000000) {
+                printf_log(LOG_INFO, "keeping it\n");
+            } else {
+                box64_rdtsc = 1;
+                printf_log(LOG_INFO, "not using it\n");
+            }
+            #else
+            box64_rdtsc = 1;
+            printf_log(LOG_INFO, "Will use time-based emulation for rdtsc, even if hardware counter are available\n");
+            #endif
+        } else if(box64_rdtsc)
+            printf_log(LOG_INFO, "Will use time-based emulation for rdtsc, even if hardware counter are available\n");
+    }
     box64_pagesize = sysconf(_SC_PAGESIZE);
     if(!box64_pagesize)
         box64_pagesize = 4096;
@@ -1140,6 +1165,7 @@ void PrintFlags() {
     printf(" BOX64_ENV1='XXX=yyyy' will add XXX=yyyy env. var. and continue with BOX86_ENV2 ... until var doesn't exist\n");
     printf(" BOX64_JITGDB with 1 to launch \"gdb\" when a segfault is trapped, attached to the offending process\n");
     printf(" BOX64_MMAP32=1 to use 32bits address space mmap in priority for external mmap as soon a 32bits process are detected (default for Snapdragon build)\n");
+    printf(" BOX64_RDTSC to use a monotonic timer for rdtsc even if hardware counter are available (or check if precision is >=1Ghz for 2)\n");
 }
 
 void PrintHelp() {