diff mbox series

[XTF,benchmark,v1,4/4] perf: measure MMUEXT_MARK_SUPER test

Message ID 20200323133701.21728-5-nmanthey@amazon.de (mailing list archive)
State New, archived
Headers show
Series XTF: add micro benchmarks | expand

Commit Message

Norbert Manthey March 23, 2020, 1:37 p.m. UTC
A first simple test is to call a hypercall in a tight loop. To measure
implementation aspects of the hypervisor, we picked a hypercall that
is not implemented and hence results in a no-op, namely the hypercall
mmuext_op with the command MMUEXT_MARK_SUPER.

The test calibrates the execution time for 1000 calls to the hypercall,
and next calculates the number of calls to take about 5 minutes.

Signed-off-by: Norbert Manthey <nmanthey@amazon.de>
Reviewed-by: Bjoern Doebel <doebel@amazon.de>

---
 tests/perf-PV-MMUEXT_MARK_SUPER-noop/Makefile |  9 +++
 tests/perf-PV-MMUEXT_MARK_SUPER-noop/main.c   | 80 +++++++++++++++++++
 2 files changed, 89 insertions(+)
 create mode 100644 tests/perf-PV-MMUEXT_MARK_SUPER-noop/Makefile
 create mode 100644 tests/perf-PV-MMUEXT_MARK_SUPER-noop/main.c
diff mbox series

Patch

diff --git a/tests/perf-PV-MMUEXT_MARK_SUPER-noop/Makefile b/tests/perf-PV-MMUEXT_MARK_SUPER-noop/Makefile
new file mode 100644
--- /dev/null
+++ b/tests/perf-PV-MMUEXT_MARK_SUPER-noop/Makefile
@@ -0,0 +1,9 @@ 
+include $(ROOT)/build/common.mk
+
+NAME      := perf-PV-MMUEXT_MARK_SUPER-noop
+CATEGORY  := benchmark
+TEST-ENVS := pv64
+
+obj-perenv += main.o
+
+include $(ROOT)/build/gen.mk
diff --git a/tests/perf-PV-MMUEXT_MARK_SUPER-noop/main.c b/tests/perf-PV-MMUEXT_MARK_SUPER-noop/main.c
new file mode 100644
--- /dev/null
+++ b/tests/perf-PV-MMUEXT_MARK_SUPER-noop/main.c
@@ -0,0 +1,80 @@ 
+/**
+ * Copyright (C) Amazon.com, Inc. or its affiliates.
+ * Author: Norbert Manthey <nmanthey@amazon.de>
+ *
+ * @file tests/perf-PV-MMUEXT_MARK_SUPER-noop/main.c
+ * @ref test-perf-PV-MMUEXT_MARK_SUPER-noop
+ *
+ * @page perf-PV-MMUEXT_MARK_SUPER-noop
+ *
+ * This test runs the hypercall mmuext_op with the command MMUEXT_MARK_SUPER in
+ * a tight loop, and measures how much time it takes for all loops. Finally, the
+ * test prints this time.
+ *
+ * Since this is a performance test, the actual value is furthermore printed
+ * using the predefined pattern on a separate line. The reported value
+ * represents the time it takes to run the mmuext_op hypercall in nano seconds.
+ * The average is calculated by running the call for about 5 minutes.
+ *
+ * perf <testname> <value>
+ *
+ * @see tests/perf-PV-MMUEXT_MARK_SUPER-noop/main.c
+ */
+
+/* To improve precision of the measurement, try to run the hypercall for this
+   amount of seconds. As the time per call can be different for test machines,
+   we measure the time for the below number of calls, and estimate the number of
+   calls to perform accordingly. */
+#define MEASUREMENT_SECONDS 300
+
+/* This number of calls to the function under test will be used to estimate how
+   many times we need to call the function to measure for about 5 minutes. */
+#define CALIBRATION_CALLS 1000
+
+#include <xtf/time.h>
+#include <xtf.h>
+
+const char test_title[] = "Test perf-MMUEXT_MARK_SUPER";
+
+/* Use a global struct to avoid local variables in call_MMUEXT_MARK_SUPER */
+mmuext_op_t op =
+{
+    .cmd = MMUEXT_MARK_SUPER,
+    .arg1.mfn = 1,
+};
+
+/* Schedule a no-op hypercall */
+int call_MMUEXT_MARK_SUPER(void)
+{
+    return hypercall_mmuext_op(&op, 1, NULL, DOMID_SELF);
+}
+
+void test_main(void)
+{
+    int rc = 0;
+
+    /* Test whether the hypercall is implemented as expected */
+    rc = call_MMUEXT_MARK_SUPER();
+    if(rc != -EOPNOTSUPP && rc != -EINVAL && rc != -ENOSYS)
+        return xtf_error("Unexpected MMUEXT_MARK_SUPER, rc %d\n", rc);
+
+    /* Measuring average execution time for given function, and print stats */
+    measure_performance(test_title,
+                        "mmuext_op(MMUEXT_MARK_SUPER, ...)",
+                        call_MMUEXT_MARK_SUPER,
+                        MEASUREMENT_SECONDS,
+                        CALIBRATION_CALLS,
+                        1);
+
+    return xtf_success("Success: performed MMUEXT_MARK_SUPER hypercall with expected result\n");
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */