Skip to contentSkip to conversation

x86: add interrupt latency test

PATCH New [email protected] 1 participant 16 messages Nov 5

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover x86: add interrupt latency test

The series introduces updates to XTF to enable a test for measuring IPI/posted interrupts latencies required by [1].

The test has lots of dependencies, so series grew big.

The series is available via gitlab branch [2].

Complete CI run is available via [3].

Patch 1 aligns Arm XTF with x86 XTF; does not affect x86 XTF runs.

Patch 2 enables per-test Xen configuration.

Patch 3 adds hypervisor cmdline into argo test artifacts.

Patch 4 ports ACCESS_ONCE() from Xen.

Patch 5 adds simple atou() for test command line parsing.

Patch 6 adds missing evtchn management hypercalls.

Patch 7 adds XEN_DOMCTL_debug_op hypercall.

Patch 8 adds minimal measuments sampling framework.

Patch 9 adds cpu_relax() for x86.

Patch 10 adds TSC-based time management.

Patch 11 and 12 are small updates for setting up test environment.

Patch 13 adds primitives for enabling/disabling interrupts.

Patch 14 adds few more APIC registers for tests.

Patch 15 adds the interrupt latency test.

[1] Xen AVIC + CI infra branch: https://gitlab.com/xen-project/people/dmukhin/xen/-/tree/svm-avic-v3?ref_type=heads
[2] XTF branch: https://gitlab.com/xen-project/people/dmukhin/xtf/-/tree/x86_64-ipi-latency?ref_type=heads
[3] CI: https://gitlab.com/xen-project/people/dmukhin/xen/-/pipelines/3028917985

Denis Mukhin (15):
common: account for installing *-sym files
common: add per-test Xen bootargs file
argo: export hypervisor command line for test
common: harden type checks in ACCESS_ONCE()
common: add simple atou()
common: add missing evtchn hypercalls
common: enable XEN_DOMCTL_debug_op domctl
common: add primitives for measurements
x86: introduce cpu_relax()
x86: introduce simple time management
x86: export per-vCPU IDTR initialization
x86: isolate FEP in setup_fep()
x86: add primitives for interrupt enable/disable
x86: apic: add few more registers
x86: add interrupt latency test (hvm64)

 arch/x86/hvm/traps.c                 |   7 +-
 arch/x86/include/arch/apic.h         |  29 ++
 arch/x86/include/arch/idt.h          |   7 +
 arch/x86/include/arch/processor.h    |   3 +
 arch/x86/include/arch/system.h       |   7 +
 arch/x86/include/arch/time.h         |  48 ++
 arch/x86/setup.c                     |  80 +--
 arch/x86/tsc.c                       |  32 ++
 build/files.mk                       |   3 +
 build/gen.mk                         |   4 +-
 build/mkinfo.py                      |   8 +-
 common/libc/string.c                 |  24 +
 common/statistics.c                  | 364 ++++++++++++++
 common/time.c                        |   6 +
 include/xen/arch-x86/cpuid.h         |  26 +
 include/xen/domctl.h                 |  63 +++
 include/xen/event_channel.h          |  13 +
 include/xen/hvm/hvm_op.h             |  17 +
 include/xtf/hypercall.h              |  31 ++
 include/xtf/lib.h                    |   6 +-
 include/xtf/libc.h                   |   2 +
 include/xtf/statistics.h             |  23 +
 include/xtf/time.h                   |   8 +
 tests/argo/bootargs.in               |   1 +
 tests/interrupt-latency/Makefile     |  11 +
 tests/interrupt-latency/ap-asm.S     |  50 ++
 tests/interrupt-latency/ap-main.c    | 164 +++++++
 tests/interrupt-latency/ap.h         |  12 +
 tests/interrupt-latency/bootargs.in  |   1 +
 tests/interrupt-latency/extra.cfg.in |   1 +
 tests/interrupt-latency/main.c       | 706 +++++++++++++++++++++++++++
 31 files changed, 1711 insertions(+), 46 deletions(-)
 create mode 100644 arch/x86/include/arch/system.h
 create mode 100644 arch/x86/include/arch/time.h
 create mode 100644 arch/x86/tsc.c
 create mode 100644 common/statistics.c
 create mode 100644 common/time.c
 create mode 100644 include/xen/domctl.h
 create mode 100644 include/xtf/statistics.h
 create mode 100644 include/xtf/time.h
 create mode 100644 tests/argo/bootargs.in
 create mode 100644 tests/interrupt-latency/Makefile
 create mode 100644 tests/interrupt-latency/ap-asm.S
 create mode 100644 tests/interrupt-latency/ap-main.c
 create mode 100644 tests/interrupt-latency/ap.h
 create mode 100644 tests/interrupt-latency/bootargs.in
 create mode 100644 tests/interrupt-latency/extra.cfg.in
 create mode 100644 tests/interrupt-latency/main.c
Signature · 1 line
2.55.0
#1 lore raw

PATCH 1/15 common: account for installing *-sym files

From: Denis Mukhin <[email protected]>

Install *-sym files to support XTF packaging across all supported architectures.

---
 build/gen.mk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
build/gen.mk +1 -1
index df474a121de9..8c400e6595e9 100644
@@ -78,7 +78,7 @@ test-$(1)-$(NAME)~%.cfg: $$(cfg-default-deps) $(ROOT)/config/%.cfg.in
 .PHONY: install-$(1) install-$(1).cfg
 install-$(1): test-$(1)-$(NAME)
 	@$(INSTALL_DIR) $(DESTDIR)$(xtftestdir)/$(NAME)
-	$(INSTALL_PROGRAM) $$< $(DESTDIR)$(xtftestdir)/$(NAME)
+	$(INSTALL_PROGRAM) -t $(DESTDIR)$(xtftestdir)/$(NAME) $$< $$(wildcard $$<-syms)
 
 install-$(1).cfg: $(filter test-$(1)-%,$(TEST-CFGS))
 	@$(INSTALL_DIR) $(DESTDIR)$(xtftestdir)/$(NAME)
Signature · 1 line
2.55.0
#2 lore raw

PATCH 2/15 common: add per-test Xen bootargs file

In reply to [email protected]

From: Denis Mukhin <[email protected]>

Some tests (e.g. Argo) need special Xen configuration to run the test. Add support for test boot arguments to mkinfo.py.

---
 build/gen.mk    | 2 +-
 build/mkinfo.py | 8 +++++---
 2 files changed, 6 insertions(+), 4 deletions(-)
build/gen.mk +1 -1
index 8c400e6595e9..999c2e0dddc6 100644
@@ -36,7 +36,7 @@ build: $(foreach env,$(TEST-ENVS),test-$(env)-$(NAME)) $(TEST-CFGS)
 build: info.json
 
 info.json: $(ROOT)/build/mkinfo.py Makefile
-	$(PYTHON) $< $@ "$(NAME)" "$(CATEGORY)" "$(TEST-ENVS)" "$(VARY-CFG)"
+	$(PYTHON) $< $@ "$(NAME)" "$(CATEGORY)" "$(TEST-ENVS)" "$(VARY-CFG)" "$(firstword $(wildcard $(1).bootargs.in bootargs.in))"
 
 .PHONY: install install-each-env
 install: install-each-env info.json
build/mkinfo.py +5 -3
index 30f99832711f..f1c70f3c444a 100755
@@ -2,15 +2,17 @@
 # -*- coding: utf-8 -*-
 import json
 import sys
+import os
 
 # Usage: mkcfg.py $OUT $NAME $CATEGORY $ENVS $VARIATIONS
-_, out, name, cat, envs, variations = sys.argv
+_, out, name, cat, envs, variations, bootargs = sys.argv
 
 template = {
     "name": name,
     "category": cat,
-    "environments": [],
-    "variations": [],
+    "environments": envs.replace('"', '').split(),
+    "variations": variations.replace('"', '').split(),
+    "xen,xen-bootargs": open(bootargs).read().strip() if os.path.exists(bootargs) else "",
     }
 
 if envs:
Signature · 1 line
2.55.0
#3 lore raw

PATCH 3/15 argo: export hypervisor command line for test

In reply to [email protected]

From: Denis Mukhin <[email protected]>

Add bootargs.in for exporting hypervisor command line via info.json

---
 tests/argo/bootargs.in | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 tests/argo/bootargs.in
tests/argo/bootargs.in new file +1 -0
new file mode 100644
index 000000000000..f586be4de9fe
@@ -0,0 +1 @@
+argo=1,mac-permissive=1
Signature · 1 line
2.55.0
#4 lore raw

PATCH 4/15 common: harden type checks in ACCESS_ONCE()

In reply to [email protected]

From: Denis Mukhin <[email protected]>

---
 include/xtf/lib.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
include/xtf/lib.h +5 -1
index 9ced1e795258..629de4904d60 100644
@@ -7,7 +7,11 @@
 
 #define ARRAY_SIZE(a)    (sizeof(a) / sizeof(*a))
 
-#define ACCESS_ONCE(x)   (*(volatile typeof(x) *)&(x))
+#define __ACCESS_ONCE(x) ({ \
+    (void)(typeof(x))0; \
+    (volatile typeof(x) *)&(x); \
+})
+#define ACCESS_ONCE(x)   (*__ACCESS_ONCE(x))
 
 void __noreturn panic(const char *fmt, ...) __printf(1, 2);
 
Signature · 1 line
2.55.0
#5 lore raw

PATCH 5/15 common: add simple atou()

In reply to [email protected]

From: Denis Mukhin <[email protected]>

---
 common/libc/string.c | 24 ++++++++++++++++++++++++
 include/xtf/libc.h   |  2 ++
 2 files changed, 26 insertions(+)
common/libc/string.c +24 -0
index 8ddceab7419d..e0e40ccfa1df 100644
@@ -97,6 +97,30 @@ int (memcmp)(const void *s1, const void *s2, size_t n)
     return res;
 }
 
+unsigned int atou(const char *s)
+{
+    unsigned int val = 0;
+
+    while ( *s == ' ' || *s == '\t' || *s == '\n' ||
+            *s == '\r' || *s == '\f' || *s == '\v' )
+        ++s;
+
+    if ( *s == '+' )
+        ++s;
+
+    while ( *s >= '0' && *s <= '9' )
+    {
+        unsigned int digit = *s++ - '0';
+
+        if ( val > (~0u - digit) / 10 )
+            return ~0u;
+
+        val = val * 10 + digit;
+    }
+
+    return val;
+}
+
 /*
  * Local variables:
  * mode: C
include/xtf/libc.h +2 -0
index 86d2abdf2c6a..62fd37c77d65 100644
@@ -40,6 +40,8 @@ int memcmp(const void *s1, const void *s2, size_t n);
 
 size_t strnlen(const char *str, size_t max);
 
+unsigned int atou(const char *s);
+
 /*
  * Internal version of vsnprintf(), taking extra control flags.
  *
Signature · 1 line
2.55.0
#6 lore raw

PATCH 6/15 common: add missing evtchn hypercalls

In reply to [email protected]

From: Denis Mukhin <[email protected]>

---
 include/xen/event_channel.h | 13 +++++++++++++
 include/xen/hvm/hvm_op.h    | 17 +++++++++++++++++
 include/xtf/hypercall.h     | 25 +++++++++++++++++++++++++
 3 files changed, 55 insertions(+)
include/xen/event_channel.h +13 -0
index 2068cc09eeba..734889356252 100644
@@ -7,6 +7,8 @@
 #define EVTCHNOP_send             4
 #define EVTCHNOP_status           5
 #define EVTCHNOP_alloc_unbound    6
+#define EVTCHNOP_bind_ipi         7
+#define EVTCHNOP_unmask           9
 #define EVTCHNOP_init_control    11
 #define EVTCHNOP_expand_array    12
 
@@ -46,6 +48,17 @@ struct evtchn_alloc_unbound {
     evtchn_port_t port;
 };
 
+struct evtchn_bind_ipi {
+    uint32_t vcpu;
+    /* OUT parameters. */
+    evtchn_port_t port;
+};
+
+struct evtchn_unmask {
+    /* IN parameters. */
+    evtchn_port_t port;
+};
+
 struct evtchn_init_control {
     /* IN parameters. */
     uint64_t control_gfn;
include/xen/hvm/hvm_op.h +17 -0
index 8c240d8d90b9..2b1866c7494c 100644
@@ -15,6 +15,23 @@ struct xen_hvm_param {
 };
 typedef struct xen_hvm_param xen_hvm_param_t;
 
+#if defined(__i386__) || defined(__x86_64__)
+
+/*
+ * HVMOP_set_evtchn_upcall_vector: Set a <vector> that should be used for event
+ *                                 channel upcalls on the specified <vcpu>. If set,
+ *                                 this vector will be used in preference to the
+ *                                 domain global callback via (see
+ *                                 HVM_PARAM_CALLBACK_IRQ).
+ */
+#define HVMOP_set_evtchn_upcall_vector 23
+struct xen_hvm_evtchn_upcall_vector {
+    uint32_t vcpu;
+    uint8_t vector;
+};
+
+#endif /* defined(__i386__) || defined(__x86_64__) */
+
 #endif /* XEN_PUBLIC_HVM_HVM_OP_H */
 
 /*
include/xtf/hypercall.h +25 -0
index 68b3da111d85..9d6d901d1668 100644
@@ -241,6 +241,31 @@ static inline int hypercall_evtchn_alloc_unbound(struct evtchn_alloc_unbound *ub
     return hypercall_event_channel_op(EVTCHNOP_alloc_unbound, ub);
 }
 
+static inline int hypercall_evtchn_bind_ipi(struct evtchn_bind_ipi *bind)
+{
+    return hypercall_event_channel_op(EVTCHNOP_bind_ipi, bind);
+}
+
+static inline int hypercall_evtchn_unmask(evtchn_port_t port)
+{
+    struct evtchn_unmask unmask = {
+        .port = port,
+    };
+
+    return hypercall_event_channel_op(EVTCHNOP_unmask, &unmask);
+}
+
+static inline long hypercall_set_evtchn_upcall_vector(
+    unsigned int cpu, unsigned int vector)
+{
+    struct xen_hvm_evtchn_upcall_vector p = {
+        .vcpu = cpu,
+        .vector = vector,
+    };
+
+    return hypercall_hvm_op(HVMOP_set_evtchn_upcall_vector, &p);
+}
+
 static inline int hvm_set_param(unsigned int idx, uint64_t value)
 {
     xen_hvm_param_t p = { .domid = DOMID_SELF, .index = idx, .value = value };
Signature · 1 line
2.55.0
#7 lore raw

PATCH 7/15 common: enable XEN_DOMCTL_debug_op domctl

In reply to [email protected]

From: Denis Mukhin <[email protected]>

---
 include/xen/domctl.h    | 63 +++++++++++++++++++++++++++++++++++++++++
 include/xtf/hypercall.h |  6 ++++
 2 files changed, 69 insertions(+)
 create mode 100644 include/xen/domctl.h
include/xen/domctl.h new file +63 -0
new file mode 100644
index 000000000000..5c3241d503d1
@@ -0,0 +1,63 @@
+/* SPDX-License-Identifier: MIT */
+/******************************************************************************
+ * domctl.h
+ *
+ * Domain management operations. For use by node control stack.
+ *
+ * Copyright (c) 2002-2003, B Dragovic
+ * Copyright (c) 2002-2006, K Fraser
+ */
+
+#ifndef __XEN_PUBLIC_DOMCTL_H__
+#define __XEN_PUBLIC_DOMCTL_H__
+
+#include "xen.h"
+
+/*
+ * The interface version needs to be incremented by 1 in case the interface
+ * is modified in an incompatible way AND if the version hasn't been
+ * incremented in the current development cycle already.
+ * Pure additions (e.g. new sub-commands) or compatible interface changes
+ * (e.g. adding semantics to 0-checked input fields or data to zeroed output
+ * fields) don't require a change of the version.
+ * Stable ops are NOT covered by XEN_DOMCTL_INTERFACE_VERSION!
+ *
+ * Last version bump: Xen 4.23
+ */
+#define XEN_DOMCTL_INTERFACE_VERSION 0x00000019
+
+/* XEN_DOMCTL_debug_op */
+#define XEN_DOMCTL_DEBUG_OP_SINGLE_STEP_OFF      0
+#define XEN_DOMCTL_DEBUG_OP_SINGLE_STEP_ON       1
+#define XEN_DOMCTL_DEBUG_OP_POSTED_INTR          3
+struct xen_domctl_debug_op {
+    uint32_t op;   /* IN */
+    uint32_t vcpu; /* IN */
+    uint32_t arg;  /* IN */
+};
+
+struct xen_domctl {
+/* Stable domctl ops: interface_version is required to be 0.  */
+    uint32_t cmd;
+#define XEN_DOMCTL_debug_op                      54
+    uint32_t interface_version; /* XEN_DOMCTL_INTERFACE_VERSION */
+    domid_t  domain;
+    uint16_t _pad[3];
+    union {
+        struct xen_domctl_debug_op          debug_op;
+        uint8_t                             pad[128];
+    } u;
+};
+typedef struct xen_domctl xen_domctl_t;
+
+#endif /* __XEN_PUBLIC_DOMCTL_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
include/xtf/hypercall.h +6 -0
index 9d6d901d1668..61127eeae174 100644
@@ -42,6 +42,7 @@ extern uint8_t hypercall_page[PAGE_SIZE];
 #include <xen/hvm/hvm_op.h>
 #include <xen/hvm/hvm_vcpu.h>
 #include <xen/hvm/params.h>
+#include <xen/domctl.h>
 #include <xen/memory.h>
 #include <xen/physdev.h>
 #include <xen/sched.h>
@@ -185,6 +186,11 @@ static inline long hypercall_sysctl(xen_sysctl_t *arg)
     return HYPERCALL1(long, __HYPERVISOR_sysctl, arg);
 }
 
+static inline long hypercall_domctl(xen_domctl_t *arg)
+{
+    return HYPERCALL1(long, __HYPERVISOR_domctl, arg);
+}
+
 static inline long hypercall_argo_op(unsigned int cmd, void *arg1, void *arg2,
                                      unsigned long arg3, unsigned long arg4)
 {
Signature · 1 line
2.55.0
#8 lore raw

PATCH 8/15 common: add primitives for measurements

In reply to [email protected]

From: Denis Mukhin <[email protected]>

Add new module (hvm64 only) to enable measurements aggregation and printing from the XTF.

---
 build/files.mk           |   1 +
 common/statistics.c      | 364 +++++++++++++++++++++++++++++++++++++++
 include/xtf/statistics.h |  23 +++
 3 files changed, 388 insertions(+)
 create mode 100644 common/statistics.c
 create mode 100644 include/xtf/statistics.h
build/files.mk +1 -0
index 11624a89a21c..8a7d6f8d588f 100644
@@ -55,4 +55,5 @@ $(foreach env,$(32BIT_ENVIRONMENTS),$(eval obj-$(env) += $(obj-32)))
 
 # 64bit specific objects
 obj-64  += $(ROOT)/arch/x86/entry_64.o
+obj-64  += $(ROOT)/common/statistics.o
 $(foreach env,$(64BIT_ENVIRONMENTS),$(eval obj-$(env) += $(obj-64)))
common/statistics.c new file +364 -0

364 lines not on this page · raw message

include/xtf/statistics.h new file +23 -0
new file mode 100644
index 000000000000..e074435ed5ad
@@ -0,0 +1,23 @@
+#ifndef __XTF_STATISTICS_H_
+#define __XTF_STATISTICS_H_
+
+#include <stdint.h>
+
+#define NR_BUCKETS  271u
+
+struct statistics {
+    uint64_t bucket[NR_BUCKETS];
+    uint64_t min;
+    uint64_t max;
+    uint64_t p99;
+    uint64_t sum;
+    uint64_t count;
+    const char *name;
+};
+
+void xtf_add_sample(struct statistics *s, uint64_t sample);
+void xtf_finalize_statistics(struct statistics *s);
+void xtf_print_histogram(const struct statistics *s);
+void xtf_print_metrics(const struct statistics *s, const struct statistics *t);
+
+#endif /* __XTF_STATISTICS_H_ */
Signature · 1 line
2.55.0
#9 lore raw

PATCH 9/15 x86: introduce cpu_relax()

In reply to [email protected]

From: Denis Mukhin <[email protected]>

---
 arch/x86/include/arch/processor.h | 3 +++
 1 file changed, 3 insertions(+)
arch/x86/include/arch/processor.h +3 -0
index 9cf2fe08669f..9db352f18c7c 100644
@@ -190,6 +190,9 @@
 #define X86_SEL_GDT       0
 #define X86_SEL_LDT       X86_SEL_TI
 
+/* Pause for busy-wait loops. */
+#define cpu_relax()       asm volatile ( "pause" ::: "memory" )
+
 #endif /* XTF_X86_PROCESSOR_H */
 
 /*
Signature · 1 line
2.55.0
#10 lore raw

PATCH 10/15 x86: introduce simple time management

In reply to [email protected]

From: Denis Mukhin <[email protected]>

Some tests needs some estimation on certain operations longevity.

On x86 systems Xen conveniently exposes TSC frequency via CPUID[ECX] 0x40000003.

Add TSC-based primitives into XTF to allow time measurements, including TSC to time conversion routines.

Add common xtf_init_time() so that it can be called on demand if the test needs time management.

---
 arch/x86/include/arch/time.h | 48 ++++++++++++++++++++++++++++++++++++
 arch/x86/tsc.c               | 32 ++++++++++++++++++++++++
 build/files.mk               |  2 ++
 common/time.c                |  6 +++++
 include/xen/arch-x86/cpuid.h | 26 +++++++++++++++++++
 include/xtf/time.h           |  8 ++++++
 6 files changed, 122 insertions(+)
 create mode 100644 arch/x86/include/arch/time.h
 create mode 100644 arch/x86/tsc.c
 create mode 100644 common/time.c
 create mode 100644 include/xtf/time.h
arch/x86/include/arch/time.h new file +48 -0
new file mode 100644
index 000000000000..3a244a2a6eda
@@ -0,0 +1,48 @@
+#ifndef __X86_TIME_H_
+#define __X86_TIME_H_
+
+#include <stdint.h>
+
+extern uint32_t tsc_khz;
+
+void arch_init_time(void);
+
+static inline uint64_t rdtsc_ordered(void)
+{
+    uint32_t lo, hi;
+
+    asm volatile (
+        "lfence;"
+        "rdtsc;"
+        : "=a" (lo), "=d" (hi)
+        :
+        : "memory"
+    );
+
+    return ((uint64_t)hi << 32) | lo;
+}
+
+static inline uint64_t cycles_to_time_units(uint64_t cycles, uint64_t mult)
+{
+    if ( !tsc_khz )
+        return 0;
+
+    return cycles * mult / tsc_khz;
+}
+
+static inline uint64_t cycles_to_ns(uint64_t cycles)
+{
+    return cycles_to_time_units(cycles, 1000000ULL);
+}
+
+static inline uint64_t cycles_to_us(uint64_t cycles)
+{
+    return cycles_to_time_units(cycles, 1000ULL);
+}
+
+static inline uint64_t cycles_to_ms(uint64_t cycles)
+{
+    return cycles_to_time_units(cycles, 1ULL);
+}
+
+#endif /* __X86_TIME_H_ */
arch/x86/tsc.c new file +32 -0
new file mode 100644
index 000000000000..93c4de197984
@@ -0,0 +1,32 @@
+#include <arch/cpuid.h>
+#include <arch/time.h>
+
+#include <xtf.h>
+
+uint32_t tsc_khz;
+
+void arch_init_time(void)
+{
+    uint32_t eax, ebx, ecx, edx;
+    bool emulated, reliable;
+
+    cpuid_count(XEN_CPUID_LEAF(3), 0, &eax, &ebx, &ecx, &edx);
+
+    tsc_khz = ecx;
+    emulated = !!(eax & XEN_CPUID_TSC_EMULATED);
+    reliable = !!(eax & XEN_CPUID_HOST_TSC_RELIABLE);
+
+    printk("Xen TSC: emulated=%u reliable=%u mode=%u "
+           "guest=%u kHz incarnation=%u\n",
+           emulated, reliable,
+           ebx, ecx, edx);
+
+    cpuid_count(XEN_CPUID_LEAF(3), 2,
+                &eax, &ebx, &ecx, &edx);
+
+    printk("Xen TSC: host=%u kHz\n", eax);
+
+    if ( emulated || !reliable )
+        xtf_warning("Xen TSC: time measurements are not reliable\n");
+}
+
build/files.mk +2 -0
index 8a7d6f8d588f..ad39c00751b7 100644
@@ -14,6 +14,7 @@ obj-perbits += $(ROOT)/common/libc/string.o
 obj-perbits += $(ROOT)/common/libc/vsnprintf.o
 obj-perbits += $(ROOT)/common/report.o
 obj-perbits += $(ROOT)/common/setup.o
+obj-perbits += $(ROOT)/common/time.o
 obj-perbits += $(ROOT)/common/xenbus.o
 obj-perbits += $(ROOT)/common/weak-defaults.o
 
@@ -25,6 +26,7 @@ obj-perenv += $(ROOT)/arch/x86/hypercall_page.o
 obj-perenv += $(ROOT)/arch/x86/msr.o
 obj-perenv += $(ROOT)/arch/x86/setup.o
 obj-perenv += $(ROOT)/arch/x86/traps.o
+obj-perenv += $(ROOT)/arch/x86/tsc.o
 
 
 # HVM specific objects
common/time.c new file +6 -0
new file mode 100644
index 000000000000..c6e5136a1567
@@ -0,0 +1,6 @@
+#include <xtf/time.h>
+
+void xtf_init_time(void)
+{
+    arch_init_time();
+}
include/xen/arch-x86/cpuid.h +26 -0
index 2fbc8eb656a0..9e1e7e6ac51b 100644
@@ -15,6 +15,7 @@
  */
 
 #define XEN_CPUID_FIRST_LEAF 0x40000000
+#define XEN_CPUID_LEAF(i)    (XEN_CPUID_FIRST_LEAF + (i))
 
 /*
  * Leaf 1 (0x40000x00)
@@ -36,6 +37,31 @@
  * EDX: Features 2. Unused bits are set to zero.
  */
 
+/*
+ * Leaf 4 (0x40000x03)
+ * Sub-leaf 0: EAX: bit 0: emulated tsc
+ *                  bit 1: host tsc is known to be reliable
+ *                  bit 2: RDTSCP instruction available
+ *             EBX: tsc_mode: 0=default (emulate if necessary), 1=emulate,
+ *                            2=no emulation, 3=no emulation + TSC_AUX support
+ *             ECX: guest tsc frequency in kHz
+ *             EDX: guest tsc incarnation (migration count)
+ * Sub-leaf 1: EAX: tsc offset low part
+ *             EBX: tsc offset high part
+ *             ECX: multiplicator for tsc->ns conversion
+ *             EDX: shift amount for tsc->ns conversion
+ * Sub-leaf 2: EAX: host tsc frequency in kHz
+ */
+
+#define XEN_CPUID_TSC_EMULATED               (1u << 0)
+#define XEN_CPUID_HOST_TSC_RELIABLE          (1u << 1)
+#define XEN_CPUID_RDTSCP_INSTR_AVAIL         (1u << 2)
+
+#define XEN_CPUID_TSC_MODE_DEFAULT           (0)
+#define XEN_CPUID_TSC_MODE_ALWAYS_EMULATE    (1u)
+#define XEN_CPUID_TSC_MODE_NEVER_EMULATE     (2u)
+#define XEN_CPUID_TSC_MODE_PVRDTSCP          (3u)
+
 /*
  * Leaf 5 (0x40000x04)
  * HVM-specific features
include/xtf/time.h new file +8 -0
new file mode 100644
index 000000000000..1e5895122a34
@@ -0,0 +1,8 @@
+#ifndef __XTF_TIME_H_
+#define __XTF_TIME_H_
+
+#include <arch/time.h>
+
+void xtf_init_time(void);
+
+#endif /* __XTF_TIME_H_ */
Signature · 1 line
2.55.0
#11 lore raw

PATCH 11/15 x86: export per-vCPU IDTR initialization

In reply to [email protected]

From: Denis Mukhin <[email protected]>

---
 arch/x86/hvm/traps.c        | 7 ++++++-
 arch/x86/include/arch/idt.h | 7 +++++++
 2 files changed, 13 insertions(+), 1 deletion(-)
arch/x86/hvm/traps.c +6 -1
index ad7b8cbc3dda..dc7d617b80c5 100644
@@ -70,6 +70,11 @@ static env_tss tss_DF __aligned(16) =
     .iopb = X86_TSS_INVALID_IO_BITMAP,
 };
 
+void xtf_load_idt(void)
+{
+    lidt(&idt_ptr);
+}
+
 int xtf_set_idte(unsigned int vector, const struct xtf_idte *idte)
 {
     pack_intr_gate(&idt[vector], idte->cs, idte->addr, idte->dpl, 0);
@@ -116,7 +121,7 @@ void arch_init_traps(void)
     pack_intr_gate(&idt[X86_VEC_RET2KERN],
                    __KERN_CS, _u(&entry_ret_to_kernel), 3, 0);
 
-    lidt(&idt_ptr);
+    xtf_load_idt();
 
     pack_tss_desc(&gdt[GDTE_TSS], &tss);
     ltr(GDTE_TSS * 8);
arch/x86/include/arch/idt.h +7 -0
index 02955d54bae4..b54dbec830f0 100644
@@ -29,6 +29,13 @@ struct xtf_idte
     unsigned int cs, dpl;
 };
 
+
+/**
+ * Load per-vCPU IDTR.
+ */
+void xtf_load_idt(void);
+
+
 /**
  * Set up an IDT Entry, in a guest agnostic way.
  *
Signature · 1 line
2.55.0
#12 lore raw

PATCH 12/15 x86: isolate FEP in setup_fep()

In reply to [email protected]

From: Denis Mukhin <[email protected]>

Keep weak symbol test_setup() for per-test definition.

Isolate FEP into a new setup_fep() call which is executed on a common x86 path.

---
 arch/x86/setup.c | 80 +++++++++++++++++++++++++-----------------------
 1 file changed, 41 insertions(+), 39 deletions(-)
arch/x86/setup.c +41 -39
index ba6f9c320843..8fea6495de1c 100644
@@ -253,6 +253,45 @@ static void xen_console_write(const char *buf, size_t len)
     hypercall_console_write(buf, len);
 }
 
+/*
+ * Common test setup:
+ *
+ * xtf_has_* indicates the availabiliy of options which require runtime
+ * detection.
+ */
+bool xtf_has_fep = false;
+
+/*
+ * Default weak settings.
+ *
+ * test_wants_* indicates default settings for the framework, which may be
+ * overridden by individual tests by providing non-weak variables.
+ *
+ * test_needs_* indicates options required by the test, without which the test
+ * isn't worth running.
+ */
+bool __weak test_needs_fep = false;
+
+static void setup_fep(void)
+{
+    /*
+     * Attempt to use the forced emulation prefix to set the value of
+     * xtf_has_fep to the value of 1.  Use the exception table to compensate
+     * for the #UD exception if FEP is not available.
+     */
+    asm volatile ("1:" _ASM_XEN_FEP "mov $1, %[fep];"
+                  "2:"
+                  _ASM_EXTABLE(1b, 2b)
+                  : [fep] "=q" (xtf_has_fep)
+                  : "0" (false));
+
+    if ( test_needs_fep && !xtf_has_fep )
+    {
+        printk("FEP unavailable, but needed by test. (Is Xen support\n");
+        return xtf_skip("compiled in, and booted with 'hvm_fep'?)\n");
+    }
+}
+
 void arch_setup(void)
 {
     if ( IS_DEFINED(CONFIG_HVM) && !pvh_start_info )
@@ -275,6 +314,8 @@ void arch_setup(void)
     }
 
     map_shared_info();
+
+    setup_fep();
 }
 
 int arch_get_domid(void)
@@ -293,45 +334,6 @@ int arch_get_domid(void)
     return -1;
 }
 
-/*
- * Common test setup:
- *
- * xtf_has_* indicates the availabiliy of options which require runtime
- * detection.
- */
-bool xtf_has_fep = false;
-
-/*
- * Default weak settings.
- *
- * test_wants_* indicates default settings for the framework, which may be
- * overridden by individual tests by providing non-weak variables.
- *
- * test_needs_* indicates options required by the test, without which the test
- * isn't worth running.
- */
-bool __weak test_needs_fep = false;
-
-void test_setup(void)
-{
-    /*
-     * Attempt to use the forced emulation prefix to set the value of
-     * xtf_has_fep to the value of 1.  Use the exception table to compensate
-     * for the #UD exception if FEP is not available.
-     */
-    asm volatile ("1:" _ASM_XEN_FEP "mov $1, %[fep];"
-                  "2:"
-                  _ASM_EXTABLE(1b, 2b)
-                  : [fep] "=q" (xtf_has_fep)
-                  : "0" (false));
-
-    if ( test_needs_fep && !xtf_has_fep )
-    {
-        printk("FEP unavailable, but needed by test. (Is Xen support\n");
-        return xtf_skip("compiled in, and booted with 'hvm_fep'?)\n");
-    }
-}
-
 /*
  * Local variables:
  * mode: C
Signature · 1 line
2.55.0
#13 lore raw

PATCH 13/15 x86: add primitives for interrupt enable/disable

In reply to [email protected]

From: Denis Mukhin <[email protected]>

---
 arch/x86/include/arch/system.h | 7 +++++++
 1 file changed, 7 insertions(+)
 create mode 100644 arch/x86/include/arch/system.h
arch/x86/include/arch/system.h new file +7 -0
new file mode 100644
index 000000000000..3f1c20263a3c
@@ -0,0 +1,7 @@
+#ifndef __X86_SYSTEM_H_
+#define __X86_SYSTEM_H_
+
+#define xtf_irq_disable()     asm volatile ( "cli" : : : "memory" )
+#define xtf_irq_enable()      asm volatile ( "sti" : : : "memory" )
+
+#endif /* __X86_SYSTEM_H_ */
Signature · 1 line
2.55.0
#14 lore raw

PATCH 14/15 x86: apic: add few more registers

In reply to [email protected]

From: Denis Mukhin <[email protected]>

Add few more registers definitions for testing: TPR, EOI, ISR, IRR.

Add routines to extract APIC ID from register 0x20.

---
 arch/x86/include/arch/apic.h | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
arch/x86/include/arch/apic.h +29 -0
index 71c09a836998..8cf28ba5a39b 100644
@@ -17,10 +17,24 @@
 
 /* Local APIC register definitions. */
 #define APIC_ID         0x020
+#define   GET_xAPIC_ID(x)         (((x) >> 24) & 0xffu)
+#define   SET_xAPIC_ID(x)         (((x) << 24))
+
 #define APIC_LVR        0x030
+
+#define APIC_TPR        0x080
+#define   APIC_TPR_MASK           0x000FF
+
+#define APIC_EOI        0x0b0
+#define   APIC_EOI_ACK            0x00000
+
 #define APIC_SPIV       0x0f0
 #define   APIC_SPIV_APIC_ENABLED  0x00100
 
+#define APIC_ISR        0x100
+
+#define APIC_IRR        0x200
+
 #define APIC_ESR        0x280
 #define   APIC_SIV                0x00020 /* Send Illegal Vector */
 #define   APIC_RIV                0x00040 /* Recieve Illegal Vector */
@@ -126,6 +140,21 @@ static inline void apic_icr_write(uint64_t val)
         return apic_msr_icr_write(val);
 }
 
+static inline bool apic_isr_read(unsigned int vector)
+{
+    return apic_read(APIC_ISR + (vector / 32 * 0x10)) & (1U << (vector % 32));
+}
+
+static inline bool apic_irr_read(unsigned int vector)
+{
+    return apic_read(APIC_IRR + (vector / 32 * 0x10)) & (1U << (vector % 32));
+}
+
+static inline unsigned int get_apic_id(void)
+{
+    return GET_xAPIC_ID(apic_read(APIC_ID));
+}
+
 #endif /* XTF_X86_APIC_H */
 
 /*
Signature · 1 line
2.55.0
#15 lore raw

PATCH 15/15 x86: add interrupt latency test (hvm64)

In reply to [email protected]

From: Denis Mukhin <[email protected]>

Introduce new test to measure IPI/posted interrupts latencies.

The test uses 2 vCPUs.

vCPU#0 (BSP) issues IPI vector 0x21 to vCPU#1 (AP) in a loop, then performs data accounting. vCPU#1 runs some noisy code which keeps trashing the CPU cache.

vCPU#1 (AP) is brought up via minimal framework which is frankenstained from xsa-472-3. It just starts AP in hvm64 flat mode. Xen conveniently provides a way to skip INIT/SIPI steps by using VCPUOP_{initialise,up} hypercalls, which simplified solution.

Had to plumb minimal GDT setup and re-initialize APIC into xAPIC mode.

Also, I was lucky with Xen exposing TSC frequency via CPUID.

Exported and used domctl hypercalls, specifically so it is possible to use XEN_DOMCTL_DEBUG_OP_POSTED_INTR.

Added missing evtchn hypercall to EVTCHNOP_bind_ipi/EVTCHNOP_unmask test vector.

There are several measurements done.

vCPU0 vCPU1
executes some workload

 +-> t0
 |   |
 |   write ICR2 [*]
 r   write ICR
 e   |---------------- interrupt -----------> t0' = recv_tsc
 p   return from APIC emulation [*']          ISR
 e   |                                        t1' = handler_tsc
 a   t1
 t   |
 |   sync against ISR
 |   |
 +---+
    vCPU0                                     vCPU1

IRQ delivery latency : t0' - t0
IRQ issue latency : t1 - t0
IRQ handler latency : t1' - t0'

[*] For event channel that is EVTCHNOP_send hypercall.
[*'] For event channel that is return from the EVTCHNOP_send hypercall.

---
 tests/interrupt-latency/Makefile     |  11 +
 tests/interrupt-latency/ap-asm.S     |  50 ++
 tests/interrupt-latency/ap-main.c    | 164 +++++++
 tests/interrupt-latency/ap.h         |  12 +
 tests/interrupt-latency/bootargs.in  |   1 +
 tests/interrupt-latency/extra.cfg.in |   1 +
 tests/interrupt-latency/main.c       | 706 +++++++++++++++++++++++++++
 7 files changed, 945 insertions(+)
 create mode 100644 tests/interrupt-latency/Makefile
 create mode 100644 tests/interrupt-latency/ap-asm.S
 create mode 100644 tests/interrupt-latency/ap-main.c
 create mode 100644 tests/interrupt-latency/ap.h
 create mode 100644 tests/interrupt-latency/bootargs.in
 create mode 100644 tests/interrupt-latency/extra.cfg.in
 create mode 100644 tests/interrupt-latency/main.c
tests/interrupt-latency/Makefile new file +11 -0
new file mode 100644
index 000000000000..43f2a3c69a62
@@ -0,0 +1,11 @@
+include $(ROOT)/build/common.mk
+
+NAME      := interrupt-latency
+CATEGORY  := functional
+TEST-ENVS := hvm64
+
+TEST-EXTRA-CFG := extra.cfg.in
+
+obj-perenv += main.o ap-main.o ap-asm.o
+
+include $(ROOT)/build/gen.mk
tests/interrupt-latency/ap-asm.S new file +50 -0

50 lines not on this page · raw message

tests/interrupt-latency/ap-main.c new file +164 -0

164 lines not on this page · raw message

tests/interrupt-latency/ap.h new file +12 -0
new file mode 100644
index 000000000000..02a214af8fea
@@ -0,0 +1,12 @@
+#ifndef __AP_H_
+#define __AP_H_
+
+#define NR_APS  1
+
+int ap_start(unsigned int cpu, void (* thread)(void));
+
+int ap_set_irq(unsigned int apic_id, unsigned int vector);
+
+unsigned int ap_apic_id(unsigned int cpu);
+
+#endif /* __AP_H_ */
tests/interrupt-latency/bootargs.in new file +1 -0
new file mode 100644
index 000000000000..c56ba76658e1
@@ -0,0 +1 @@
+sched=null dom0_max_vcpus=2 dom0_vcpus_pin smt=0 cpuidle=0 cpufreq=xen:performance watchdog=0 bootscrub=0 svm_avic=1 -- samples=20000000
tests/interrupt-latency/extra.cfg.in new file +1 -0
new file mode 100644
index 000000000000..95c6aa2abaa9
@@ -0,0 +1 @@
+vcpus = 2
tests/interrupt-latency/main.c new file +706 -0

706 lines not on this page · raw message

Signature · 1 line
2.55.0