Merge branch 'x86/cache' into perf/core, to pick up fixes

Signed-off-by: Ingo Molnar <mingo@kernel.org>
This commit is contained in:
Ingo Molnar
2018-10-23 12:30:19 +02:00
316 changed files with 2969 additions and 1834 deletions

View File

@@ -234,6 +234,7 @@ int main(int argc, char *argv[])
break;
default:
error = HV_E_FAIL;
syslog(LOG_ERR, "Unknown operation: %d",
buffer.hdr.operation);

View File

@@ -1325,7 +1325,7 @@ class Tui(object):
msg = ''
while True:
self.screen.erase()
self.screen.addstr(0, 0, 'Set update interval (defaults to %fs).' %
self.screen.addstr(0, 0, 'Set update interval (defaults to %.1fs).' %
DELAY_DEFAULT, curses.A_BOLD)
self.screen.addstr(4, 0, msg)
self.screen.addstr(2, 0, 'Change delay from %.1fs to ' %

View File

@@ -56,15 +56,13 @@ unsigned int yield_mod_cnt, nr_abort;
printf(fmt, ## __VA_ARGS__); \
} while (0)
#if defined(__x86_64__) || defined(__i386__)
#ifdef __i386__
#define INJECT_ASM_REG "eax"
#define RSEQ_INJECT_CLOBBER \
, INJECT_ASM_REG
#ifdef __i386__
#define RSEQ_INJECT_ASM(n) \
"mov asm_loop_cnt_" #n ", %%" INJECT_ASM_REG "\n\t" \
"test %%" INJECT_ASM_REG ",%%" INJECT_ASM_REG "\n\t" \
@@ -76,9 +74,16 @@ unsigned int yield_mod_cnt, nr_abort;
#elif defined(__x86_64__)
#define INJECT_ASM_REG_P "rax"
#define INJECT_ASM_REG "eax"
#define RSEQ_INJECT_CLOBBER \
, INJECT_ASM_REG_P \
, INJECT_ASM_REG
#define RSEQ_INJECT_ASM(n) \
"lea asm_loop_cnt_" #n "(%%rip), %%" INJECT_ASM_REG "\n\t" \
"mov (%%" INJECT_ASM_REG "), %%" INJECT_ASM_REG "\n\t" \
"lea asm_loop_cnt_" #n "(%%rip), %%" INJECT_ASM_REG_P "\n\t" \
"mov (%%" INJECT_ASM_REG_P "), %%" INJECT_ASM_REG "\n\t" \
"test %%" INJECT_ASM_REG ",%%" INJECT_ASM_REG "\n\t" \
"jz 333f\n\t" \
"222:\n\t" \
@@ -86,10 +91,6 @@ unsigned int yield_mod_cnt, nr_abort;
"jnz 222b\n\t" \
"333:\n\t"
#else
#error "Unsupported architecture"
#endif
#elif defined(__s390__)
#define RSEQ_INJECT_INPUT \

View File

@@ -17,6 +17,7 @@
#include <errno.h>
#include <sched.h>
#include <stdbool.h>
#include <limits.h>
#ifndef SYS_getcpu
# ifdef __x86_64__
@@ -31,6 +32,14 @@
int nerrs = 0;
typedef int (*vgettime_t)(clockid_t, struct timespec *);
vgettime_t vdso_clock_gettime;
typedef long (*vgtod_t)(struct timeval *tv, struct timezone *tz);
vgtod_t vdso_gettimeofday;
typedef long (*getcpu_t)(unsigned *, unsigned *, void *);
getcpu_t vgetcpu;
@@ -95,6 +104,15 @@ static void fill_function_pointers()
printf("Warning: failed to find getcpu in vDSO\n");
vgetcpu = (getcpu_t) vsyscall_getcpu();
vdso_clock_gettime = (vgettime_t)dlsym(vdso, "__vdso_clock_gettime");
if (!vdso_clock_gettime)
printf("Warning: failed to find clock_gettime in vDSO\n");
vdso_gettimeofday = (vgtod_t)dlsym(vdso, "__vdso_gettimeofday");
if (!vdso_gettimeofday)
printf("Warning: failed to find gettimeofday in vDSO\n");
}
static long sys_getcpu(unsigned * cpu, unsigned * node,
@@ -103,6 +121,16 @@ static long sys_getcpu(unsigned * cpu, unsigned * node,
return syscall(__NR_getcpu, cpu, node, cache);
}
static inline int sys_clock_gettime(clockid_t id, struct timespec *ts)
{
return syscall(__NR_clock_gettime, id, ts);
}
static inline int sys_gettimeofday(struct timeval *tv, struct timezone *tz)
{
return syscall(__NR_gettimeofday, tv, tz);
}
static void test_getcpu(void)
{
printf("[RUN]\tTesting getcpu...\n");
@@ -155,10 +183,154 @@ static void test_getcpu(void)
}
}
static bool ts_leq(const struct timespec *a, const struct timespec *b)
{
if (a->tv_sec != b->tv_sec)
return a->tv_sec < b->tv_sec;
else
return a->tv_nsec <= b->tv_nsec;
}
static bool tv_leq(const struct timeval *a, const struct timeval *b)
{
if (a->tv_sec != b->tv_sec)
return a->tv_sec < b->tv_sec;
else
return a->tv_usec <= b->tv_usec;
}
static char const * const clocknames[] = {
[0] = "CLOCK_REALTIME",
[1] = "CLOCK_MONOTONIC",
[2] = "CLOCK_PROCESS_CPUTIME_ID",
[3] = "CLOCK_THREAD_CPUTIME_ID",
[4] = "CLOCK_MONOTONIC_RAW",
[5] = "CLOCK_REALTIME_COARSE",
[6] = "CLOCK_MONOTONIC_COARSE",
[7] = "CLOCK_BOOTTIME",
[8] = "CLOCK_REALTIME_ALARM",
[9] = "CLOCK_BOOTTIME_ALARM",
[10] = "CLOCK_SGI_CYCLE",
[11] = "CLOCK_TAI",
};
static void test_one_clock_gettime(int clock, const char *name)
{
struct timespec start, vdso, end;
int vdso_ret, end_ret;
printf("[RUN]\tTesting clock_gettime for clock %s (%d)...\n", name, clock);
if (sys_clock_gettime(clock, &start) < 0) {
if (errno == EINVAL) {
vdso_ret = vdso_clock_gettime(clock, &vdso);
if (vdso_ret == -EINVAL) {
printf("[OK]\tNo such clock.\n");
} else {
printf("[FAIL]\tNo such clock, but __vdso_clock_gettime returned %d\n", vdso_ret);
nerrs++;
}
} else {
printf("[WARN]\t clock_gettime(%d) syscall returned error %d\n", clock, errno);
}
return;
}
vdso_ret = vdso_clock_gettime(clock, &vdso);
end_ret = sys_clock_gettime(clock, &end);
if (vdso_ret != 0 || end_ret != 0) {
printf("[FAIL]\tvDSO returned %d, syscall errno=%d\n",
vdso_ret, errno);
nerrs++;
return;
}
printf("\t%llu.%09ld %llu.%09ld %llu.%09ld\n",
(unsigned long long)start.tv_sec, start.tv_nsec,
(unsigned long long)vdso.tv_sec, vdso.tv_nsec,
(unsigned long long)end.tv_sec, end.tv_nsec);
if (!ts_leq(&start, &vdso) || !ts_leq(&vdso, &end)) {
printf("[FAIL]\tTimes are out of sequence\n");
nerrs++;
}
}
static void test_clock_gettime(void)
{
for (int clock = 0; clock < sizeof(clocknames) / sizeof(clocknames[0]);
clock++) {
test_one_clock_gettime(clock, clocknames[clock]);
}
/* Also test some invalid clock ids */
test_one_clock_gettime(-1, "invalid");
test_one_clock_gettime(INT_MIN, "invalid");
test_one_clock_gettime(INT_MAX, "invalid");
}
static void test_gettimeofday(void)
{
struct timeval start, vdso, end;
struct timezone sys_tz, vdso_tz;
int vdso_ret, end_ret;
if (!vdso_gettimeofday)
return;
printf("[RUN]\tTesting gettimeofday...\n");
if (sys_gettimeofday(&start, &sys_tz) < 0) {
printf("[FAIL]\tsys_gettimeofday failed (%d)\n", errno);
nerrs++;
return;
}
vdso_ret = vdso_gettimeofday(&vdso, &vdso_tz);
end_ret = sys_gettimeofday(&end, NULL);
if (vdso_ret != 0 || end_ret != 0) {
printf("[FAIL]\tvDSO returned %d, syscall errno=%d\n",
vdso_ret, errno);
nerrs++;
return;
}
printf("\t%llu.%06ld %llu.%06ld %llu.%06ld\n",
(unsigned long long)start.tv_sec, start.tv_usec,
(unsigned long long)vdso.tv_sec, vdso.tv_usec,
(unsigned long long)end.tv_sec, end.tv_usec);
if (!tv_leq(&start, &vdso) || !tv_leq(&vdso, &end)) {
printf("[FAIL]\tTimes are out of sequence\n");
nerrs++;
}
if (sys_tz.tz_minuteswest == vdso_tz.tz_minuteswest &&
sys_tz.tz_dsttime == vdso_tz.tz_dsttime) {
printf("[OK]\ttimezones match: minuteswest=%d, dsttime=%d\n",
sys_tz.tz_minuteswest, sys_tz.tz_dsttime);
} else {
printf("[FAIL]\ttimezones do not match\n");
nerrs++;
}
/* And make sure that passing NULL for tz doesn't crash. */
vdso_gettimeofday(&vdso, NULL);
}
int main(int argc, char **argv)
{
fill_function_pointers();
test_clock_gettime();
test_gettimeofday();
/*
* Test getcpu() last so that, if something goes wrong setting affinity,
* we still run the other tests.
*/
test_getcpu();
return nerrs ? 1 : 0;