diff --git a/Makefile b/Makefile index bcabd03..fb62dc4 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,11 @@ JAVAC ?= javac +MSRS ?= 0 PASS_DOWN_ARGS = ENABLE_JAVA=${ENABLE_JAVA} JAVAC=${JAVAC} \ JAVA_CPPFLAGS=${JAVA_CPPFLAGS} \ JAVA_CFLAGS=${JAVA_CFLAGS} JAVA_LDFLAGS=${JAVA_LDFLAGS} \ CC=${CC} CFLAGS=${CFLAGS} CPPFLAGS=${CPPFLAGS} \ - LDFLAGS=${LDFLAGS} NO_MSRS=${NO_MSRS} + LDFLAGS=${LDFLAGS} MSRS=${MSRS} .PHONY: utils libkrun vm-sanity-checks clean all diff --git a/README.md b/README.md index 2447a88..77464ab 100644 --- a/README.md +++ b/README.md @@ -53,23 +53,18 @@ resulting benchmarking numbers. ### Performance counters -We recommend using our custom Linux kernel found at: - - https://github.com/softdevteam/krun-linux-kernel - -which provides low latency access to the following counters: +If you want low latency access to the following counters: * `IA32_PERF_FIXED_CTR1` (the core cycle counter) * `IA32_APERF` counts * `IA32_MPERF` counts -If you are unable to do this, you can set `NO_MSRS=1` in your Unix environment -when building Krun (see later), but be aware that this degrades the quality of -the resulting benchmarking numbers. +you will need to use the (now rather out of date) custom Linux kernel at: + + https://github.com/softdevteam/krun-linux-kernel -Krun works on any version of the kernel if NO_MSRS=1 is set. If a suitable -version of the Krun custom kernel (>= 4.9.88) is used, the MSRs are also -available. +If you do use this kernel you will need to set `MSRS=1` in your Unix +environment when building Krun (see later). ### Tickless Kernel diff --git a/libkrun/Makefile b/libkrun/Makefile index 00b35fc..2b6d653 100644 --- a/libkrun/Makefile +++ b/libkrun/Makefile @@ -21,11 +21,11 @@ ifeq ($(shell uname -s),Linux) # Under virtualised conditions, we have no performance counters. # MSR-centric code is also guarded on a per-OS basis in libkruntime.c ifeq (${VIRTUALISED},1) - COMMON_CFLAGS += -DNO_MSRS - else ifeq (${NO_MSRS},1) + COMMON_CFLAGS += -DMSRS + else ifeq (${MSRS},1) # You can also force off MSR support. This can be useful for # testing on machines without the Krun Linux kernel installed. - COMMON_CFLAGS += -DNO_MSRS + COMMON_CFLAGS += -DMSRS endif endif diff --git a/libkrun/libkruntime.c b/libkrun/libkruntime.c index d6ba689..fe4d56c 100644 --- a/libkrun/libkruntime.c +++ b/libkrun/libkruntime.c @@ -30,7 +30,7 @@ #define ACTUAL_CLOCK_MONOTONIC CLOCK_MONOTONIC #endif -#if defined(__linux__) && !defined(NO_MSRS) +#if defined(__linux__) && defined(MSRS) // pick up our Krun syscall numbers #include #endif @@ -55,10 +55,10 @@ static int krun_num_cores = 0; // Private prototypes #ifdef __linux__ static void krun_mdata_bounds_check(int mdata_idx); -#ifndef NO_MSRS +#ifndef MSRS static int krun_get_fixed_pctr1_width(void); static void krun_core_bounds_check(int core); -#endif // NO_MSRS +#endif // MSRS #endif // __linux__ void krun_check_mdata(void); @@ -76,7 +76,7 @@ krun_xcalloc(size_t nmemb, size_t size) return p; } -#if defined(__linux__) && !defined(NO_MSRS) +#if defined(__linux__) && defined(MSRS) static void krun_core_bounds_check(int core) { @@ -85,7 +85,7 @@ krun_core_bounds_check(int core) exit(EXIT_FAILURE); } } -#endif // defined(__linux__) && !defined(NO_MSRS) +#endif // defined(__linux__) && defined(MSRS) static void krun_mdata_bounds_check(int mdata_idx) @@ -96,19 +96,19 @@ krun_mdata_bounds_check(int mdata_idx) } } -#if defined(__linux__) && !defined(NO_MSRS) +#if defined(__linux__) && defined(MSRS) /* * Fixed-function counters vary in size across machines. * (configured in initialisation). */ static uint64_t krun_pctr_val_mask = 0; -#elif defined(__linux__) && defined(NO_MSRS) +#elif defined(__linux__) && !defined(MSRS) #elif defined(__OpenBSD__) // We do not yet support performance counters on OpenBSD #else #error "Unsupported platform" -#endif // __linux__ && !NO_MSRS +#endif // __linux__ && defined(MSRS) double krun_clock_gettime_monotonic() @@ -189,7 +189,7 @@ Java_IterationsRunner_JNI_1krun_1get_1num_1cores(JNIEnv *e, jclass c) } #endif -#if defined(__linux__) && !defined(NO_MSRS) +#if defined(__linux__) && defined(MSRS) static int /* * Fetches the width of the fixed-function performance counters so we can @@ -238,17 +238,17 @@ krun_get_fixed_pctr1_width() return fixed_ctr_width; } -#elif defined(__linux__) && defined(NO_MSRS) +#elif defined(__linux__) && !defined(MSRS) #elif defined(__OpenBSD__) // We do not yet support performance counters on OpenBSD #else #error "Unsupported platform" -#endif // linux && !NO_MSRS +#endif // linux && defined(MSRS) void krun_init(void) { -#if defined(__linux__) && !defined(NO_MSRS) +#if defined(__linux__) && defined(MSRS) int i, err; /* See how wide the counter values are and make an appropriate mask */ @@ -272,18 +272,18 @@ krun_init(void) /* Reset all MSRs of interest */ syscall(SYSCALL_KRUN_RESET_MSRS, krun_num_cores); -#elif defined(__linux__) && defined(NO_MSRS) +#elif defined(__linux__) && !defined(MSRS) #elif defined(__OpenBSD__) // We do not yet support performance counters on OpenBSD #else # error "Unsupported platform" -#endif // __linux__ && !NO_MSRS +#endif // __linux__ && defined(MSRS) } void krun_done(void) { -#if defined(__linux__) && !defined(NO_MSRS) +#if defined(__linux__) && defined(MSRS) int i; /* Free per-core arrays */ @@ -292,12 +292,12 @@ krun_done(void) free(krun_mdata[i].aperf); free(krun_mdata[i].mperf); } -#elif defined(__linux__) && defined(NO_MSRS) +#elif defined(__linux__) && !defined(MSRS) #elif defined(__OpenBSD__) // We do not yet support performance counters on OpenBSD #else #error "Unsupported platform" -#endif // __linux__ && !NO_MSRS +#endif // __linux__ && defined(MSRS) } /* @@ -330,7 +330,7 @@ krun_measure(int mdata_idx) struct krun_data *data = &(krun_mdata[mdata_idx]); krun_mdata_bounds_check(mdata_idx); -#if defined(__linux__) && !defined(NO_MSRS) +#if defined(__linux__) && defined(MSRS) int err; /* @@ -360,7 +360,7 @@ krun_measure(int mdata_idx) fprintf(stderr, "krun_read_msrs() syscall failed\n"); exit(EXIT_FAILURE); } -#elif defined(__linux__) && defined(NO_MSRS) +#elif defined(__linux__) && !defined(MSRS) data->wallclock = krun_clock_gettime_monotonic(); #elif defined(__OpenBSD__) data->wallclock = krun_clock_gettime_monotonic(); @@ -423,40 +423,40 @@ krun_get_wallclock(int mdata_idx) uint64_t krun_get_core_cycles(int mdata_idx, int core) { -#if defined(__linux__) && !defined(NO_MSRS) +#if defined(__linux__) && defined(MSRS) krun_mdata_bounds_check(mdata_idx); krun_core_bounds_check(core); return krun_mdata[mdata_idx].core_cycles[core] & krun_pctr_val_mask; #else fprintf(stderr, "%s: libkruntime was built without MSR support\n", __func__); exit(EXIT_FAILURE); -#endif // defined(__linux__) && !defined(NO_MSRS) +#endif // defined(__linux__) && defined(MSRS) } uint64_t krun_get_aperf(int mdata_idx, int core) { -#if defined(__linux__) && !defined(NO_MSRS) +#if defined(__linux__) && defined(MSRS) krun_mdata_bounds_check(mdata_idx); krun_core_bounds_check(core); return krun_mdata[mdata_idx].aperf[core]; #else fprintf(stderr, "%s: libkruntime was built without MSR support\n", __func__); exit(EXIT_FAILURE); -#endif // defined(__linux__) && !defined(NO_MSRS) +#endif // defined(__linux__) && defined(MSRS) } uint64_t krun_get_mperf(int mdata_idx, int core) { -#if defined(__linux__) && !defined(NO_MSRS) +#if defined(__linux__) && defined(MSRS) krun_mdata_bounds_check(mdata_idx); krun_core_bounds_check(core); return krun_mdata[mdata_idx].mperf[core]; #else fprintf(stderr, "%s: libkruntime was built without MSR support\n", __func__); exit(EXIT_FAILURE); -#endif // defined(__linux__) && !defined(NO_MSRS) +#endif // defined(__linux__) && defined(MSRS) } /*