Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,9 @@ set(OS_LINUX_SRC
"${BOX64_ROOT}/src/os/os_linux.c"
"${BOX64_ROOT}/src/os/perfmap.c"
"${BOX64_ROOT}/src/os/symbolfuncs_linux.c"
"${BOX64_ROOT}/src/os/my_cpuid_linux.c"
"${BOX64_ROOT}/src/os/my_cpuid_common.c"
"${BOX64_ROOT}/src/os/random_linux.c"
"${BOX64_ROOT}/src/os/my_cpuid.c"
"${BOX64_ROOT}/src/os/sysinfo.c"
)

set(ELFLOADER_SRC
Expand Down
22 changes: 10 additions & 12 deletions src/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "cleanup.h"
#include "freq.h"
#include "hostext.h"
#include "sysinfo.h"

box64context_t *my_context = NULL;
extern box64env_t box64env;
Expand Down Expand Up @@ -76,6 +77,7 @@ uint32_t default_gs = 0x53;
uint32_t default_fs = 0;
int box64_isglibc234 = 0;
int box64_unittest_mode = 0;
sysinfo_t box64_sysinfo = { 0 };

#ifdef DYNAREC
cpu_ext_t cpuext = {0};
Expand Down Expand Up @@ -159,9 +161,6 @@ static void openFTrace(void)
}
}

const char* getCpuName();
int getNCpuUnmasked();

void computeRDTSC()
{
int hardware = 0;
Expand Down Expand Up @@ -224,13 +223,12 @@ static void displayMiscInfo()
}
#endif

// grab ncpu and cpu name
int ncpu = getNCpuUnmasked();
const char* cpuname = getCpuName();

printf_log(LOG_INFO, "Running on %s with %d core%s, pagesize: %zd\n", cpuname, ncpu, ncpu > 1 ? "s" : "", box64_pagesize);

// grab and calibrate hardware counter
InitializeSystemInfo();
printf_log(LOG_INFO, "Running on %s with %d core%s, pagesize: %zd", box64_sysinfo.cpuname, box64_sysinfo.ncpu, box64_sysinfo.ncpu > 1 ? "s" : "", box64_pagesize);
if (BOX64ENV(maxcpu))
printf_log_prefix(0, LOG_INFO, ", emulating %d core%s\n", BOX64ENV(maxcpu), BOX64ENV(maxcpu) > 1 ? "s" : "");
else
printf_log_prefix(0, LOG_INFO, "\n");
computeRDTSC();
}

Expand Down Expand Up @@ -716,9 +714,9 @@ extern char** environ;

int initialize(int argc, const char **argv, char** env, x64emu_t** emulator, elfheader_t** elfheader, int exec)
{
#ifndef STATICBUILD
#ifndef STATICBUILD
init_malloc_hook();
#endif
#endif
init_auxval(argc, argv, environ?environ:env);
// analogue to QEMU_VERSION in qemu-user-mode emulation
if(getenv("BOX64_VERSION")) {
Expand Down
1 change: 1 addition & 0 deletions src/dynarec/arm64/dynarec_arm64_consts.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "emu/x64compstrings.h"
#include "x64test.h"
#include "dynarec/dynarec_next.h"
#include "random.h"

static const int8_t mask_shift8[] = { -7, -6, -5, -4, -3, -2, -1, 0 };
static const int8_t mask_string8[] = { 7, 6, 5, 4, 3, 2, 1, 0 };
Expand Down
1 change: 1 addition & 0 deletions src/dynarec/la64/dynarec_la64_consts.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "x64test.h"
#include "dynarec/dynarec_next.h"
#include "bitutils.h"
#include "random.h"

#ifndef HAVE_TRACE
void PrintTrace() {}
Expand Down
1 change: 1 addition & 0 deletions src/dynarec/rv64/dynarec_rv64_consts.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "x64test.h"
#include "dynarec/dynarec_next.h"
#include "bitutils.h"
#include "random.h"

#ifndef HAVE_TRACE
void PrintTrace() {}
Expand Down
1 change: 1 addition & 0 deletions src/emu/x64run0f.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "emit_signals.h"
#include "x64shaext.h"
#include "freq.h"
#include "random.h"
#ifdef DYNAREC
#include "custommem.h"
#include "../dynarec/native_lock.h"
Expand Down
4 changes: 3 additions & 1 deletion src/include/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "os.h"
#include "hostext.h"
#include "sysinfo.h"

typedef struct box64context_s box64context_t;
extern box64env_t box64env;
Expand Down Expand Up @@ -33,6 +34,7 @@ extern int box64_unittest_mode;
extern uintptr_t fmod_smc_start, fmod_smc_end; // to handle libfmod (from Unreal) SMC (self modifying code)
extern uint32_t default_gs, default_fs;
extern int box64_tcmalloc_minimal; // when using tcmalloc_minimal
extern sysinfo_t box64_sysinfo;
#define LOG_NONE 0
#define LOG_INFO 1
#define LOG_DEBUG 2
Expand Down Expand Up @@ -96,7 +98,7 @@ void init_malloc_hook(void);
#define box_strdup strdup
#define box_realpath realpath
#else
extern size_t(*box_malloc_usable_size)(void*);
extern size_t (*box_malloc_usable_size)(void*);
extern void* __libc_malloc(size_t);
extern void* __libc_realloc(void*, size_t);
extern void* __libc_calloc(size_t, size_t);
Expand Down
8 changes: 0 additions & 8 deletions src/include/my_cpuid.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,4 @@
typedef struct x64emu_s x64emu_t;

void my_cpuid(x64emu_t* emu, uint32_t tmp32u);
uint32_t helper_getcpu(x64emu_t* emu); // get the numa/cpu id actually running
uint32_t get_random32();
uint64_t get_random64();
int get_cpuMhz();
int getNCpu();
int getNCpuUnmasked();
int canNCpuBeChanged();
const char* getBoxCpuName();
#endif //__MY_CPUID_H__
5 changes: 5 additions & 0 deletions src/include/random.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#ifndef __RANDOM_H_
#define __RANDOM_H_
uint32_t get_random32(void);
uint64_t get_random64(void);
#endif //__RANDOM_H_
25 changes: 25 additions & 0 deletions src/include/sysinfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef __SYSINFO_H_
#define __SYSINFO_H_
#include <stdio.h>
#include <stdint.h>

typedef struct x64emu_s x64emu_t;
typedef struct sysinfo_s {
uint64_t frequency;
uint64_t ncpu;
uint64_t bogomips;
char* cpuname;

uint64_t box64_ncpu;
char* box64_cpuname;

uint32_t emulated_frequency : 1;
uint32_t read_frequency : 1;
uint32_t read_ncpu : 1;
uint32_t read_bogomips : 1;
uint32_t read_cpuname : 1;
} sysinfo_t;

void InitializeSystemInfo(void);
uint32_t helper_getcpu(x64emu_t* emu);
#endif //__SYSINFO_H_
9 changes: 1 addition & 8 deletions src/os/freq_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,8 @@ static inline uint64_t readFreq()
{
static size_t val = -1;

FILE* f = popen("cat /proc/cpuinfo | grep -i \"CPU MHz\" | head -n 1 | sed -r 's/CPU MHz.+:\\s{1,}//g'", "r");
if(f) {
char tmp[200] = "";
ssize_t s = fread(tmp, 1, 200, f);
pclose(f);
if (s > 0) return (uint64_t)atof(tmp) * 1e6;
}
if (box64_sysinfo.read_frequency) return box64_sysinfo.frequency;

// fallback to rdtime + sleep
struct timespec ts;
ts.tv_sec = 0;
ts.tv_nsec = 50000000; // 50 milliseconds
Expand Down
10 changes: 5 additions & 5 deletions src/os/my_cpuid_common.c → src/os/my_cpuid.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
void my_cpuid(x64emu_t* emu, uint32_t tmp32u)
{
emu->regs[_AX].dword[1] = emu->regs[_DX].dword[1] = emu->regs[_CX].dword[1] = emu->regs[_BX].dword[1] = 0;
int ncpu = getNCpu();
if(!ncpu) ncpu = 1;
int ncpu = box64_sysinfo.box64_ncpu;
if (!ncpu) ncpu = 1;
int ncluster = 1;
static int warned = 10;
if(BOX64ENV(cputype)) {
Expand All @@ -33,7 +33,7 @@ void my_cpuid(x64emu_t* emu, uint32_t tmp32u)
}
static char branding[3*4*4+1] = "";
if(!branding[0]) {
strcpy(branding, getBoxCpuName());
strncpy(branding, box64_sysinfo.box64_cpuname, 3*4*4);
while(strlen(branding)<3*4*4) {
memmove(branding+1, branding, strlen(branding)+1);
branding[0] = ' ';
Expand Down Expand Up @@ -356,8 +356,8 @@ void my_cpuid(x64emu_t* emu, uint32_t tmp32u)
if(BOX64ENV(cputype)) {
R_RAX = R_RBX = R_RCX = R_RDX = 0;
} else {
R_RAX = get_cpuMhz();
R_RBX = get_cpuMhz();
R_RAX = box64_sysinfo.frequency / 1000000;
R_RBX = box64_sysinfo.frequency / 1000000;
R_RCX = 100;
R_RDX = 0;

Expand Down
Loading
Loading