Port-arm archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[PATCH] Cortex-A9 global timer not registered as timecounter with SMP



Hi,

I'm using a DE1-SoC (Altera Cyclone V SoC, dual Cortex-A9, FDT)
running NetBSD-current (11.99.11).

I ran into a problem with my user program driving LEDs through an
FPGA design, which needs delays of a few hundred microseconds.

usleep() is rounded up to the 10 ms tick (hz = 100), so my program
busy-waits on clock_gettime(CLOCK_MONOTONIC) for small delays.
But with clockinterrupt, that clock also only advances in 10 ms steps,
so a 200us wait still lasts up to 10 ms.

# sysctl kern.timecounter.choice
kern.timecounter.choice = clockinterrupt(q=0, f=100 Hz) dummy(q=-1000000, f=1000000 Hz)
# sysctl kern.timecounter.hardware
kern.timecounter.hardware = clockinterrupt

The global timer is attached (arma9tmr0, 200 MHz) and its counter runs
but it's only registering as a timecounter in a9tmr_cpu_initclocks().
a9tmr_fdt_attach() registers that function only when the global timer
is the hardclock (CPU with no SMP). On SMP systeù, the private timer
is the hardclock and a9ptmr_cpu_initclocks() registers no timecounter
at all.

The patch below registers the global timer as timecounter when it is
not the hardclock.

With it i get:

# sysctl kern.timecounter.choice
kern.timecounter.choice = clockinterrupt(q=0, f=100 Hz) arma9tmr0(q=500, f=200000000 Hz) dummy(q=-1000000, f=1000000 Hz)
# sysctl kern.timecounter.hardware
kern.timecounter.hardware = arma9tmr0

and my short delays behave as expected. I've tested this on my DE1-SoC
only, but it should apply to any FDT-based multi-core Cortex-A9.

What do you think ?

Regards

--- a/sys/arch/arm/cortex/a9tmr.c
+++ b/sys/arch/arm/cortex/a9tmr.c
@@ -260,6 +260,24 @@
 	tc_init(&a9tmr_timecounter);
 }

+/*
+ * Register the global timer as timecounter without using it as hardclock
+ * (SMP: the private timer is the hardclock, see a9tmr_fdt.c).
+ */
+void
+a9tmr_init_timecounter(void)
+{
+	struct a9tmr_softc * const sc = &a9tmr_sc;
+
+	KASSERT(sc->sc_dev != NULL);
+	KASSERT(sc->sc_freq != 0);
+
+	a9tmr_timecounter.tc_name = device_xname(sc->sc_dev);
+	a9tmr_timecounter.tc_frequency = sc->sc_freq;
+
+	tc_init(&a9tmr_timecounter);
+}
+
 static void
 a9tmr_update_freq_cb(void *arg1, void *arg2)
 {
--- a/sys/arch/arm/cortex/a9tmr_var.h
+++ b/sys/arch/arm/cortex/a9tmr_var.h
@@ -53,6 +53,7 @@
 #endif
 int	a9tmr_intr(void *);
 void	a9tmr_update_freq(uint32_t);
+void	a9tmr_init_timecounter(void);
 void	a9tmr_delay(unsigned int n);

 int	a9ptmr_intr(void *);
--- a/sys/arch/arm/fdt/a9tmr_fdt.c
+++ b/sys/arch/arm/fdt/a9tmr_fdt.c
@@ -144,6 +144,9 @@
 	if (is_hardclock) {
 		arm_fdt_cpu_hatch_register(self, a9tmr_fdt_cpu_hatch);
 		arm_fdt_timer_register(a9tmr_cpu_initclocks);
+	} else {
+		/* SMP: not the hardclock, but still the best timecounter */
+		a9tmr_init_timecounter();
 	}

 	pmf_event_register(self, PMFE_SPEED_CHANGED, a9tmr_fdt_speed_changed, true);

Regards,
Denis Bodor


-- 
Denis


Home | Main Index | Thread Index | Old Index