Skip to content

Commit

Permalink
Merge pull request #405 from ltratt/deprecate_custom_kernel
Browse files Browse the repository at this point in the history
Deprecate custom kernel
  • Loading branch information
vext01 authored Jul 28, 2021
2 parents e9aa015 + 5922e6f commit a0c8e5b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 40 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
17 changes: 6 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions libkrun/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
50 changes: 25 additions & 25 deletions libkrun/libkruntime.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <sys/krun-syscall.h>
#endif
Expand All @@ -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);

Expand All @@ -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)
{
Expand All @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 */
Expand All @@ -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 */
Expand All @@ -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)
}

/*
Expand Down Expand Up @@ -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;

/*
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)
}

/*
Expand Down

0 comments on commit a0c8e5b

Please sign in to comment.