Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

clocksource: dw_apb_timer: Make CPU-affiliation being optional

Currently the DW APB Timer driver binds each clockevent timers to a
particular CPU. This isn't good for multiple reasons. First of all seeing
the device is placed on APB bus (which makes it accessible from any CPU
core), accessible over MMIO and having the DYNIRQ flag set we can be sure
that manually binding the timer to any CPU just isn't correct. By doing
so we just set an extra limitation on device usage. This also doesn't
reflect the device actual capability, since by setting the IRQ affinity
we can make it virtually local to any CPU. Secondly imagine if you had a
real CPU-local timer with the same rating and the same CPU-affinity.
In this case if DW APB timer was registered first, then due to the
clockevent framework tick-timer selection procedure we'll end up with the
real CPU-local timer being left unselected for clock-events tracking. But
on most of the platforms (MIPS/ARM/etc) such timers are normally embedded
into the CPU core and are accessible with much better performance then
devices placed on APB. For instance in MIPS architectures there is
r4k-timer, which is CPU-local, assigned with the same rating, and normally
its clockevent device is registered after the platform-specific one.

So in order to fix all of these issues let's make the DW APB Timer CPU
affinity being optional and deactivated by passing a negative CPU id,
which will effectively set the DW APB clockevent timer cpumask to
'cpu_possible_mask'.

Signed-off-by: Serge Semin <Sergey.Semin@baikalelectronics.ru>
Cc: Alexey Malahov <Alexey.Malahov@baikalelectronics.ru>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: Paul Burton <paulburton@kernel.org>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: linux-mips@vger.kernel.org
Cc: linux-rtc@vger.kernel.org
Cc: devicetree@vger.kernel.org
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20200521204818.25436-5-Sergey.Semin@baikalelectronics.ru

authored by

Serge Semin and committed by
Daniel Lezcano
cee43dbf e69bc899

+3 -2
+3 -2
drivers/clocksource/dw_apb_timer.c
··· 222 222 /** 223 223 * dw_apb_clockevent_init() - use an APB timer as a clock_event_device 224 224 * 225 - * @cpu: The CPU the events will be targeted at. 225 + * @cpu: The CPU the events will be targeted at or -1 if CPU affiliation 226 + * isn't required. 226 227 * @name: The name used for the timer and the IRQ for it. 227 228 * @rating: The rating to give the timer. 228 229 * @base: I/O base for the timer registers. ··· 258 257 dw_ced->ced.max_delta_ticks = 0x7fffffff; 259 258 dw_ced->ced.min_delta_ns = clockevent_delta2ns(5000, &dw_ced->ced); 260 259 dw_ced->ced.min_delta_ticks = 5000; 261 - dw_ced->ced.cpumask = cpumask_of(cpu); 260 + dw_ced->ced.cpumask = cpu < 0 ? cpu_possible_mask : cpumask_of(cpu); 262 261 dw_ced->ced.features = CLOCK_EVT_FEAT_PERIODIC | 263 262 CLOCK_EVT_FEAT_ONESHOT | CLOCK_EVT_FEAT_DYNIRQ; 264 263 dw_ced->ced.set_state_shutdown = apbt_shutdown;