soc: arm: nordic_nrf: change default SYS_CLOCKS_PER_SEC

The default system clock on all Nordic devices is based on a 32 KiHz
(2^15 Hz) timer.  Scheduling ticks requires that deadlines be specified
with a timer counter that aligns to a system clock.  With the Zephyr
default 100 clocks-per-sec configuration this results in 100 ticks every
32700 ticks of the cycle timer.  This reveals two problems:

* The uptime clock misrepresents elapsed time because it runs 0.208%
  (68/32768) faster than the best available clock;

* Calculation of timer counter compare values often requires an integer
  division and multiply operation to produce a value that's a multiple
  of clock-ticks-per-second.

Integer division on the Cortex-M1 nRF51 is done in software with a
(value-dependent) algorithm with a non-constant runtime that can be
significant.  This can produce missed Bluetooth deadlines as discussed
in upstream #14577 and others.

By changing the default divisor to one that evenly divides the 2^15
clock rate the time interrupts are disabled to manage timers is
significantly reduced, as is the error between uptime and real time.  Do
this at the top level, moving SYS_CLOCK_HW_CYCLES_PER_SEC there as well
since the two parameters are related.

Note that the central_hr configuration described in upstream #13610 does
not distinguish latency due to timer management from other
irq_block/spinlock regions, and the maximum observed latency will still
exceed the nominal 10 us allowed maximum.  However this does occur
much less frequently than changing the timer deadline which can happen
multiple times per tick.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
This commit is contained in:
Peter A. Bigot 2019-04-20 09:25:38 -05:00 committed by Carles Cufí
commit c76dd1edb7
4 changed files with 8 additions and 12 deletions

View file

@ -9,6 +9,14 @@ if SOC_FAMILY_NRF
source "soc/arm/nordic_nrf/*/Kconfig.defconfig.series"
config SYS_CLOCK_HW_CYCLES_PER_SEC
int
default 32768
config SYS_CLOCK_TICKS_PER_SEC
int
default 128
config BUILD_OUTPUT_HEX
default y

View file

@ -13,10 +13,6 @@ source "soc/arm/nordic_nrf/nrf51/Kconfig.defconfig.nrf51*"
config SOC_SERIES
default "nrf51"
config SYS_CLOCK_HW_CYCLES_PER_SEC
int
default 32768
config SYS_POWER_MANAGEMENT
default y

View file

@ -12,10 +12,6 @@ source "soc/arm/nordic_nrf/nrf52/Kconfig.defconfig.nrf52*"
config SOC_SERIES
default "nrf52"
config SYS_CLOCK_HW_CYCLES_PER_SEC
int
default 32768
config SYS_POWER_MANAGEMENT
default y

View file

@ -12,10 +12,6 @@ source "soc/arm/nordic_nrf/nrf91/Kconfig.defconfig.nrf91*"
config SOC_SERIES
default "nrf91"
config SYS_CLOCK_HW_CYCLES_PER_SEC
int
default 32768
config ARCH_HAS_CUSTOM_BUSY_WAIT
default y