From: "Alex Bennée" <alex.bennee@linaro.org>
To: mttcg@listserver.greensocs.com, mark.burton@greensocs.com,
fred.konrad@greensocs.com, a.rigo@virtualopensystems.com
Cc: peter.maydell@linaro.org, drjones@redhat.com,
a.spyridakis@virtualopensystems.com, claudio.fontana@huawei.com,
qemu-devel@nongnu.org, will.deacon@arm.com,
crosthwaitepeter@gmail.com, pbonzini@redhat.com,
"Alex Bennée" <alex.bennee@linaro.org>,
aurelien@aurel32.net, rth@twiddle.net
Subject: [Qemu-devel] [RFC 08/11] arm/tlbflush-test: Add TLB torture test
Date: Fri, 26 Feb 2016 13:15:30 +0000 [thread overview]
Message-ID: <1456492533-17171-9-git-send-email-alex.bennee@linaro.org> (raw)
In-Reply-To: <1456492533-17171-1-git-send-email-alex.bennee@linaro.org>
This adds a fairly brain dead torture test for TLB flushes intended for
stressing the MTTCG QEMU build. It takes the usual -smp option for
multiple CPUs.
By default it CPU0 will do a TLBIALL flush after each cycle. You can
pass options via -append to control additional aspects of the test:
- "page" flush each page in turn (one per function)
- "self" do the flush after each computation cycle
- "verbose" report progress on each computation cycle
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
v2
- rename to tlbflush-test
- made makefile changes cleaner
- added self/other flush mode
- create specific prefix
- whitespace fixes
v3
- using new SMP framework for test runing
v4
- merge in the unitests.cfg
---
arm/tlbflush-test.c | 194 +++++++++++++++++++++++++++++++++++++++++++
arm/unittests.cfg | 24 ++++++
config/config-arm-common.mak | 2 +
3 files changed, 220 insertions(+)
create mode 100644 arm/tlbflush-test.c
diff --git a/arm/tlbflush-test.c b/arm/tlbflush-test.c
new file mode 100644
index 0000000..0375ad9
--- /dev/null
+++ b/arm/tlbflush-test.c
@@ -0,0 +1,194 @@
+#include <libcflat.h>
+#include <asm/smp.h>
+#include <asm/cpumask.h>
+#include <asm/barrier.h>
+#include <asm/mmu.h>
+
+#define SEQ_LENGTH 10
+#define SEQ_HASH 0x7cd707fe
+
+static cpumask_t smp_test_complete;
+static int flush_count = 1000000;
+static int flush_self = 0;
+static int flush_page = 0;
+static int flush_verbose = 0;
+
+/* Work functions
+ *
+ * These work functions need to be:
+ *
+ * - page aligned, so we can flush one function at a time
+ * - have branches, so QEMU TCG generates multiple basic blocks
+ * - call across pages, so we exercise the TCG basic block slow path
+ */
+
+/* Adler32 */
+__attribute__((aligned(PAGE_SIZE))) uint32_t hash_array(const void *buf,
+ size_t buflen)
+{
+ const uint8_t *data = (uint8_t *) buf;
+ uint32_t s1 = 1;
+ uint32_t s2 = 0;
+
+ for (size_t n = 0; n < buflen; n++) {
+ s1 = (s1 + data[n]) % 65521;
+ s2 = (s2 + s1) % 65521;
+ }
+ return (s2 << 16) | s1;
+}
+
+__attribute__((aligned(PAGE_SIZE))) void create_fib_sequence(int length,
+ unsigned int *array)
+{
+ int i;
+
+ /* first two values */
+ array[0] = 0;
+ array[1] = 1;
+ for (i=2; i<length; i++) {
+ array[i] = array[i-2] + array[i-1];
+ }
+}
+
+__attribute__((aligned(PAGE_SIZE))) unsigned long long factorial(unsigned int n)
+{
+ unsigned int i;
+ unsigned long long fac = 1;
+ for (i=1; i<=n; i++)
+ {
+ fac = fac * i;
+ }
+ return fac;
+}
+
+__attribute__((aligned(PAGE_SIZE))) void factorial_array
+(unsigned int n, unsigned int *input, unsigned long long *output)
+{
+ unsigned int i;
+ for (i=0; i<n; i++) {
+ output[i] = factorial(input[i]);
+ }
+}
+
+__attribute__((aligned(PAGE_SIZE))) unsigned int do_computation(void)
+{
+ unsigned int fib_array[SEQ_LENGTH];
+ unsigned long long facfib_array[SEQ_LENGTH];
+ uint32_t fib_hash, facfib_hash;
+
+ create_fib_sequence(SEQ_LENGTH, &fib_array[0]);
+ fib_hash = hash_array(&fib_array[0], sizeof(fib_array));
+ factorial_array(SEQ_LENGTH, &fib_array[0], &facfib_array[0]);
+ facfib_hash = hash_array(&facfib_array[0], sizeof(facfib_array));
+
+ return (fib_hash ^ facfib_hash);
+}
+
+/* This provides a table of the work functions so we can flush each
+ * page individually
+ */
+static void * pages[] = {&hash_array, &create_fib_sequence, &factorial,
+ &factorial_array, &do_computation};
+
+static void do_flush(int i)
+{
+ if (flush_page) {
+ flush_tlb_page((unsigned long)pages[i % ARRAY_SIZE(pages)]);
+ } else {
+ flush_tlb_all();
+ }
+}
+
+
+static void just_compute(void)
+{
+ int i, errors = 0;
+ int cpu = smp_processor_id();
+
+ uint32_t result;
+
+ printf("CPU%d online\n", cpu);
+
+ for (i=0; i < flush_count; i++) {
+ result = do_computation();
+
+ if (result != SEQ_HASH) {
+ errors++;
+ printf("CPU%d: seq%d 0x%x!=0x%x\n",
+ cpu, i, result, SEQ_HASH);
+ }
+
+ if (flush_verbose && (i % 1000) == 0) {
+ printf("CPU%d: seq%d\n", cpu, i);
+ }
+
+ if (flush_self) {
+ do_flush(i);
+ }
+ }
+
+ report("CPU%d: Done - Errors: %d\n", errors == 0, cpu, errors);
+
+ cpumask_set_cpu(cpu, &smp_test_complete);
+ if (cpu != 0)
+ halt();
+}
+
+static void just_flush(void)
+{
+ int cpu = smp_processor_id();
+ int i = 0;
+
+ /* set our CPU as done, keep flushing until everyone else
+ finished */
+ cpumask_set_cpu(cpu, &smp_test_complete);
+
+ while (!cpumask_full(&smp_test_complete)) {
+ do_flush(i++);
+ }
+
+ report("CPU%d: Done - Triggered %d flushes\n", true, cpu, i);
+}
+
+int main(int argc, char **argv)
+{
+ int cpu, i;
+ char prefix[100];
+
+ for (i=0; i<argc; i++) {
+ char *arg = argv[i];
+
+ if (strcmp(arg, "page") == 0) {
+ flush_page = 1;
+ }
+
+ if (strcmp(arg, "self") == 0) {
+ flush_self = 1;
+ }
+
+ if (strcmp(arg, "verbose") == 0) {
+ flush_verbose = 1;
+ }
+ }
+
+ snprintf(prefix, sizeof(prefix), "tlbflush_%s_%s",
+ flush_page?"page":"all",
+ flush_self?"self":"other");
+ report_prefix_push(prefix);
+
+ for_each_present_cpu(cpu) {
+ if (cpu == 0)
+ continue;
+ smp_boot_secondary(cpu, just_compute);
+ }
+
+ if (flush_self)
+ just_compute();
+ else
+ just_flush();
+
+ while (!cpumask_full(&smp_test_complete))
+ cpu_relax();
+
+ return report_summary();
+}
diff --git a/arm/unittests.cfg b/arm/unittests.cfg
index 5e26da1..8aebdba 100644
--- a/arm/unittests.cfg
+++ b/arm/unittests.cfg
@@ -38,3 +38,27 @@ file = selftest.flat
smp = $MAX_SMP
extra_params = -append 'smp'
groups = selftest
+
+# TLB Torture Tests
+[tlbflush::all_other]
+file = tlbflush-test.flat
+smp = $MAX_SMP
+groups = tlbflush
+
+[tlbflush::page_other]
+file = tlbflush-test.flat
+smp = $MAX_SMP
+extra_params = -append 'page'
+groups = tlbflush
+
+[tlbflush::all_self]
+file = tlbflush-test.flat
+smp = $MAX_SMP
+extra_params = -append 'self'
+groups = tlbflush
+
+[tlbflush::page_self]
+file = tlbflush-test.flat
+smp = $MAX_SMP
+extra_params = -append 'page self'
+groups = tlbflush
diff --git a/config/config-arm-common.mak b/config/config-arm-common.mak
index 732c805..e6ad11b 100644
--- a/config/config-arm-common.mak
+++ b/config/config-arm-common.mak
@@ -12,6 +12,7 @@ endif
tests-common = $(TEST_DIR)/selftest.flat
tests-common += $(TEST_DIR)/spinlock-test.flat
tests-common += $(TEST_DIR)/ipi-test.flat
+tests-common += $(TEST_DIR)/tlbflush-test.flat
all: test_cases
@@ -72,3 +73,4 @@ test_cases: $(generated_files) $(tests-common) $(tests)
$(TEST_DIR)/selftest.elf: $(cstart.o) $(TEST_DIR)/selftest.o
$(TEST_DIR)/spinlock-test.elf: $(cstart.o) $(TEST_DIR)/spinlock-test.o
$(TEST_DIR)/ipi-test.elf: $(cstart.o) $(TEST_DIR)/ipi-test.o
+$(TEST_DIR)/tlbflush-test.elf: $(cstart.o) $(TEST_DIR)/tlbflush-test.o
--
2.7.1
next prev parent reply other threads:[~2016-02-26 13:15 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-26 13:15 [Qemu-devel] [RFC 00/11] Current MTTCG kvm-unit-test patches Alex Bennée
2016-02-26 13:15 ` [Qemu-devel] [RFC 01/11] config/config-arm-common: build-up tests-common target Alex Bennée
2016-02-26 14:04 ` Andrew Jones
2016-02-26 14:16 ` Alex Bennée
2016-02-26 13:15 ` [Qemu-devel] [RFC 02/11] arm/arm64: irq enable/disable Alex Bennée
2016-02-26 13:15 ` [Qemu-devel] [RFC 03/11] arm/arm64: Add initial gic support Alex Bennée
2016-02-26 13:15 ` [Qemu-devel] [RFC 04/11] arm/arm64: Add IPI test Alex Bennée
2016-02-26 13:15 ` [Qemu-devel] [RFC 05/11] lib: add isaac prng library from CCAN Alex Bennée
2016-02-26 13:15 ` [Qemu-devel] [RFC 06/11] arm/run: set indentation defaults for emacs Alex Bennée
2016-02-26 13:15 ` [Qemu-devel] [RFC 07/11] arm/run: allow aarch64 to start arm binaries Alex Bennée
2016-02-26 14:02 ` Andrew Jones
2016-02-26 14:19 ` Alex Bennée
2016-02-26 13:15 ` Alex Bennée [this message]
2016-02-26 13:15 ` [Qemu-devel] [RFC 09/11] arm/locking-tests: add comprehensive locking test Alex Bennée
2016-02-26 13:15 ` [Qemu-devel] [RFC 10/11] arm/barrier-litmus-tests: add some litmus tests Alex Bennée
2016-02-26 13:15 ` [Qemu-devel] [RFC 11/11] arm/tcg-test: some basic TCG exercising tests Alex Bennée
2016-02-26 14:12 ` [Qemu-devel] [RFC 00/11] Current MTTCG kvm-unit-test patches Andrew Jones
2016-02-26 14:54 ` Alex Bennée
2016-02-26 15:22 ` Andrew Jones
2016-02-26 16:03 ` Alex Bennée
2016-04-27 15:09 ` Alex Bennée
2016-04-27 15:26 ` Andrew Jones
2016-04-28 18:44 ` Andrew Jones
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1456492533-17171-9-git-send-email-alex.bennee@linaro.org \
--to=alex.bennee@linaro.org \
--cc=a.rigo@virtualopensystems.com \
--cc=a.spyridakis@virtualopensystems.com \
--cc=aurelien@aurel32.net \
--cc=claudio.fontana@huawei.com \
--cc=crosthwaitepeter@gmail.com \
--cc=drjones@redhat.com \
--cc=fred.konrad@greensocs.com \
--cc=mark.burton@greensocs.com \
--cc=mttcg@listserver.greensocs.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
--cc=will.deacon@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).