diff --git a/repos/dde_linux/src/include/lx_emul/shadow/arch/x86/include/asm/vdso/processor.h b/repos/dde_linux/src/include/lx_emul/shadow/arch/x86/include/asm/vdso/processor.h index e264975ddc..16b3d2ccdd 100644 --- a/repos/dde_linux/src/include/lx_emul/shadow/arch/x86/include/asm/vdso/processor.h +++ b/repos/dde_linux/src/include/lx_emul/shadow/arch/x86/include/asm/vdso/processor.h @@ -23,7 +23,7 @@ static __always_inline void cpu_relax(void) * endless busy loops like: * - slchi() in drivers/i2c/algos/i2c-algo-bit.c */ - if (!lx_emul_irq_state()) lx_emul_time_update_jiffies(); + if (!lx_emul_irq_state()) lx_emul_time_update_jiffies_cpu_relax(); } #endif /* _LX_EMUL__SHADOW__ARCH__X86__INCLUDE__ASM__VDSO__PROCESSOR_H_ */ diff --git a/repos/dde_linux/src/include/lx_emul/time.h b/repos/dde_linux/src/include/lx_emul/time.h index 2d4bbae4d2..2b7b1f4f49 100644 --- a/repos/dde_linux/src/include/lx_emul/time.h +++ b/repos/dde_linux/src/include/lx_emul/time.h @@ -32,6 +32,8 @@ void lx_emul_time_update_jiffies(void); void lx_emul_time_initial(unsigned long long); +void lx_emul_time_update_jiffies_cpu_relax(void); + #ifdef __cplusplus } #endif diff --git a/repos/dde_linux/src/lib/lx_emul/clocksource.c b/repos/dde_linux/src/lib/lx_emul/clocksource.c index a42ed4fef8..a64df77cf7 100644 --- a/repos/dde_linux/src/lib/lx_emul/clocksource.c +++ b/repos/dde_linux/src/lib/lx_emul/clocksource.c @@ -134,6 +134,36 @@ void lx_emul_time_update_jiffies(void) } +extern void update_wall_time(void); + + +void lx_emul_time_update_jiffies_cpu_relax() +{ + /* based upon tick_do_update_jiffies64 in kernel/time/tick-sched.c */ + + ktime_t delta, now = ktime_get(); + + /* check if jiffies need an update */ + if (ktime_before(now, tick_next_period)) + return; + + delta = ktime_sub(now, tick_next_period); + + if (unlikely(delta >= TICK_NSEC)) { + /* Slow path for long idle sleep times */ + s64 incr = TICK_NSEC; + + ktime_t ticks = ktime_divns(delta, incr); + + jiffies_64 += ticks; + + tick_next_period = ktime_add_ns(tick_next_period, incr * ticks); + + update_wall_time(); + } +} + + enum { LX_EMUL_MAX_OF_CLOCK_PROVIDERS = 256 };