--- zzzz-none-000/linux-3.10.107/arch/arm/lib/delay.c 2017-06-27 09:49:32.000000000 +0000 +++ vr9-7490-729/linux-3.10.107/arch/arm/lib/delay.c 2021-11-10 11:53:52.000000000 +0000 @@ -37,6 +37,19 @@ static const struct delay_timer *delay_timer; static bool delay_calibrated; +/* + * Oh, if only we had a cycle counter... + */ +void delay_loop(unsigned long loops) +{ + asm volatile( + "1: subs %0, %0, #1 \n" + " bhi 1b \n" + : /* No output */ + : "r" (loops) + ); +} + int read_current_timer(unsigned long *timer_val) { if (!delay_timer) @@ -49,10 +62,19 @@ static void __timer_delay(unsigned long cycles) { - cycles_t start = get_cycles(); +#if defined(CONFIG_AVM_ENHANCED) + unsigned long start; + start = delay_timer->read_current_timer(); - while ((get_cycles() - start) < cycles) + while ((delay_timer->read_current_timer() - start) < cycles) cpu_relax(); + +#else/*--- #if defined(CONFIG_AVM_ENHANCED) ---*/ + /*--- avm: get_cycles() do not use read_current_timer() ---*/ + cycles_t start = get_cycles(); + while ((get_cycles() - start) < cycles) + cpu_relax(); +#endif/*--- #else ---*//*--- #if defined(CONFIG_AVM_ENHANCED) ---*/ } static void __timer_const_udelay(unsigned long xloops) @@ -70,7 +92,7 @@ void __init register_current_timer_delay(const struct delay_timer *timer) { if (!delay_calibrated) { - pr_info("Switching to timer-based delay loop\n"); + pr_info("Switching to timer-based delay loop\n"); delay_timer = timer; lpj_fine = timer->freq / HZ; @@ -82,7 +104,7 @@ delay_calibrated = true; } else { - pr_info("Ignoring duplicate/late registration of read_current_timer delay\n"); + pr_info("Ignoring duplicate/late registration of read_current_timer delay\n"); } } @@ -91,3 +113,25 @@ delay_calibrated = true; return lpj_fine; } + +#ifdef ARCH_HAS_READ_CURRENT_TIMER +/* + * Assuming read_current_timer() is monotonically increasing + * across calls. + */ +void read_current_timer_delay_loop(unsigned long loops) +{ + unsigned long bclock = bclock, + now = now; + + read_current_timer(&bclock); + do { + read_current_timer(&now); + } while ((now - bclock) < loops); +} +#endif + +void set_delay_fn(void (*fn)(unsigned long)) +{ + arm_delay_ops.delay = fn; +}