Skip to contentSkip to conversation

arm64: add vtimer test

PATCH In review Andrew Jones 2 participants 4 messages Jul 4, 2017

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

cover arm64: add vtimer test

Add a test for the vtimer. I've tested on
accel=tcg
accel=kvm,kernel-irqchip=on : on thunderx, seattle, and mustang accel=kvm,kernel-irqchip=off : on thunderx and mustang

It works everywhere without modification except on mustang. My mustang seems to have a hardware problem requiring bit 31 of CNTV_CVAL_EL0 to be clear before attempting to enable (setting CNTV_CTL_EL0.ENABLE), otherwise the VCPU hangs... My mustang's CNTV_CVAL_EL0 also has the strange issue of not being able to set the upper 8 bits. Well, fixing hardware is outside my job description, so "oh, well..." If you hit the same problem, try the hack below, which allows tests to run and pass for me.

arm/timer.c +1 -1
index 89f4c9400ab69..18b8c4773c92f 100644
@@ -73,7 +73,7 @@ static void test_vtimer(void)
 	report_prefix_push("vtimer-busy-loop");
 
 	/* Enable the timer */
-	write_sysreg(~0, cntv_cval_el0);
+	write_sysreg(~0 & ~(1<<31), cntv_cval_el0);
 	isb();
 	write_sysreg(CNTV_CTL_ENABLE, cntv_ctl_el0);
 

Alexander Graf (1):
arm64: add vtimer test

Andrew Jones (1):
arm64: timer: check for vtimer interrupt

 arm/Makefile.arm64 |   2 +-
 arm/timer.c        | 134 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 arm/unittests.cfg  |   6 +++
 lib/arm/asm/gic.h  |   4 ++
 4 files changed, 145 insertions(+), 1 deletion(-)
 create mode 100644 arm/timer.c
Signature · 1 line
2.9.4
#1 lore raw

PATCH 1/2 arm64: add vtimer test

From: Alexander Graf <[email protected]>

All virtualization capable ARM cores support the ARM virtual timer.

Add minimalistic check for firing a virtual timer event, confirming by checking that the timer pin is marked as pending on the GIC.

[ Applied my review comments and a few other tweaks. ]
---
 arm/Makefile.arm64 |   2 +-
 arm/timer.c        | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 arm/unittests.cfg  |   6 +++
 lib/arm/asm/gic.h  |   4 ++
 4 files changed, 125 insertions(+), 1 deletion(-)
 create mode 100644 arm/timer.c
arm/Makefile.arm64 +1 -1
index 24319d6c00ed..f04bbf476763 100644
@@ -14,7 +14,7 @@ cflatobjs += lib/arm64/spinlock.o
 OBJDIRS += lib/arm64
 
 # arm64 specific tests
-tests =
+tests = $(TEST_DIR)/timer.flat
 
 include $(SRCDIR)/$(TEST_DIR)/Makefile.common
 
arm/timer.c new file +114 -0

114 lines not on this page · raw message

arm/unittests.cfg +6 -0
index 73a2419fefe6..bdfedf86b01c 100644
@@ -109,3 +109,9 @@ groups = gic
 file = psci.flat
 smp = $MAX_SMP
 groups = psci
+
+# Timer tests
+[timer]
+file = timer.flat
+groups = timer
+timeout = 2s
lib/arm/asm/gic.h +4 -0
index c688ccc74c79..2eb4af8d6c81 100644
@@ -12,6 +12,8 @@
 #define GICD_TYPER			0x0004
 #define GICD_IGROUPR			0x0080
 #define GICD_ISENABLER			0x0100
+#define GICD_ISPENDR			0x0200
+#define GICD_ICPENDR			0x0280
 #define GICD_ISACTIVER			0x0300
 #define GICD_ICACTIVER			0x0380
 #define GICD_IPRIORITYR			0x0400
@@ -33,6 +35,8 @@
 #include <asm/gic-v2.h>
 #include <asm/gic-v3.h>
 
+#define PPI(irq)			((irq) + 16)
+
 #ifndef __ASSEMBLY__
 #include <asm/cpumask.h>
 
Signature · 1 line
2.9.4
#2 lore raw

PATCH 2/2 arm64: timer: check for vtimer interrupt

In reply to Andrew Jones
---
 arm/timer.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
arm/timer.c +21 -1
index ec110ee08d97..89f4c9400ab6 100644
@@ -17,6 +17,21 @@
 
 static u32 vtimer_irq, vtimer_irq_flags;
 static void *gic_ispendr;
+static bool vtimer_irq_received;
+
+static void irq_handler(struct pt_regs *regs)
+{
+	u32 irqstat = gic_read_iar();
+	u32 irqnr = gic_iar_irqnr(irqstat);
+
+	if (irqnr != GICC_INT_SPURIOUS)
+		gic_write_eoir(irqstat);
+
+	if (irqnr == PPI(vtimer_irq)) {
+		write_sysreg(CNTV_CTL_IMASK, cntv_ctl_el0);
+		++vtimer_irq_received;
+	}
+}
 
 static bool gic_vtimer_pending(void)
 {
@@ -64,7 +79,7 @@ static void test_vtimer(void)
 
 	report("not pending before", !gic_vtimer_pending());
 	report("latency within 10 ms", test_cval_10msec());
-	report("pending after", gic_vtimer_pending());
+	report("interrupt received", vtimer_irq_received);
 
 	/* Disable the timer again */
 	write_sysreg(0, cntv_ctl_el0);
@@ -92,12 +107,17 @@ static void test_init(void)
 
 	switch (gic_version()) {
 	case 2:
+		writel(1 << PPI(vtimer_irq), gicv2_dist_base() + GICD_ISENABLER + 0);
 		gic_ispendr = gicv2_dist_base() + GICD_ISPENDR;
 		break;
 	case 3:
+		writel(1 << PPI(vtimer_irq), gicv3_sgi_base() + GICR_ISENABLER0);
 		gic_ispendr = gicv3_sgi_base() + GICD_ISPENDR;
 		break;
 	}
+
+	install_irq_handler(EL1H_IRQ, irq_handler);
+	local_irq_enable();
 }
 
 int main(void)
Signature · 1 line
2.9.4
maintainer
#3 lore raw
In reply to Andrew Jones
Quoted 5 lines · Andrew Jones

Add a test for the vtimer. I've tested on
accel=tcg
accel=kvm,kernel-irqchip=on : on thunderx, seattle, and mustang accel=kvm,kernel-irqchip=off : on thunderx and mustang

Quoted 8 lines

It works everywhere without modification except on mustang. My mustang seems to have a hardware problem requiring bit 31 of CNTV_CVAL_EL0 to be clear before attempting to enable (setting CNTV_CTL_EL0.ENABLE), otherwise the VCPU hangs... My mustang's CNTV_CVAL_EL0 also has the strange issue of not being able to set the upper 8 bits. Well, fixing hardware is outside my job description, so "oh, well..." If you hit the same problem, try the hack below, which allows tests to run and pass for me.

Applied and pushed, thanks.

Paolo

Quoted 27 lines
arm/timer.c +1 -1
index 89f4c9400ab69..18b8c4773c92f 100644
@@ -73,7 +73,7 @@ static void test_vtimer(void)
 	report_prefix_push("vtimer-busy-loop");
 
 	/* Enable the timer */
-	write_sysreg(~0, cntv_cval_el0);
+	write_sysreg(~0 & ~(1<<31), cntv_cval_el0);
 	isb();
 	write_sysreg(CNTV_CTL_ENABLE, cntv_ctl_el0);
 

Alexander Graf (1):
arm64: add vtimer test

Andrew Jones (1):
arm64: timer: check for vtimer interrupt

 arm/Makefile.arm64 |   2 +-
 arm/timer.c        | 134 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 arm/unittests.cfg  |   6 +++
 lib/arm/asm/gic.h  |   4 ++
 4 files changed, 145 insertions(+), 1 deletion(-)
 create mode 100644 arm/timer.c