mirror of
https://github.com/genodelabs/genode.git
synced 2025-06-22 16:59:03 +00:00
committed by
Christian Helmuth
parent
9ecbe51e34
commit
7b4556e546
@ -28,8 +28,6 @@ unsigned long long lx_emul_time_counter(void);
|
||||
|
||||
void lx_emul_time_handle(void);
|
||||
|
||||
void lx_emul_force_jiffies_update(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -131,107 +131,3 @@ void lx_emul_register_of_clk_initcall(char const *compat, void *fn)
|
||||
|
||||
count++;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* private kernel/time header needed for internal functions
|
||||
* used in lx_emul_force_jiffies_update
|
||||
*/
|
||||
#include <../kernel/time/tick-internal.h>
|
||||
|
||||
/*
|
||||
* The functions lx_emul_force_jiffies_update, lx_clockevents_program_event
|
||||
* and lx_clockevents_program_event implemented here are stripped down
|
||||
* versions of the Linux internal time handling code, when clock is used in
|
||||
* periodic mode.
|
||||
*
|
||||
* Normally time proceeds due to
|
||||
* -> lx_emul/shadow/kernel/sched/core.c calls lx_emul_time_handle()
|
||||
* -> repos/dde_linux/src/lib/lx_emul/clocksource.c:lx_emul_time_handle() calls
|
||||
* -> dde_clock_event_device->event_handle() == tick_handle_periodic()
|
||||
* -> kernel/time/tick-common.c -> tick_handle_periodic()
|
||||
* -> kernel/time/clockevents.c -> clockevents_program_event()
|
||||
* -> which fast forwards jiffies in a loop until it matches wall clock
|
||||
*
|
||||
* lx_emul_force_jiffies_update can be used to update jiffies to current,
|
||||
* before invoking schedule_timeout(), which expects current jiffies values.
|
||||
* Without current jiffies, the programmed timeouts are too short, which leads
|
||||
* to timeouts firing too early.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* based on kernel/time/clockevents.c clockevents_program_event()
|
||||
*/
|
||||
static int lx_clockevents_program_event(struct clock_event_device *dev,
|
||||
ktime_t expires)
|
||||
{
|
||||
int64_t delta;
|
||||
|
||||
if (WARN_ON_ONCE(expires < 0))
|
||||
return 0;
|
||||
|
||||
dev->next_event = expires;
|
||||
|
||||
if (clockevent_state_shutdown(dev))
|
||||
return 0;
|
||||
|
||||
if (dev->features & CLOCK_EVT_FEAT_KTIME)
|
||||
return 0;
|
||||
|
||||
delta = ktime_to_ns(ktime_sub(expires, ktime_get()));
|
||||
if (delta <= 0) {
|
||||
int res = -ETIME;
|
||||
return res;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* based on kernel/time/tick-common.c tick_handle_periodic()
|
||||
*/
|
||||
void lx_emul_force_jiffies_update(void)
|
||||
{
|
||||
struct clock_event_device *dev = dde_clock_event_device;
|
||||
|
||||
ktime_t next = dev->next_event;
|
||||
|
||||
#if defined(CONFIG_HIGH_RES_TIMERS) || defined(CONFIG_NO_HZ_COMMON)
|
||||
/*
|
||||
* The cpu might have transitioned to HIGHRES or NOHZ mode via
|
||||
* update_process_times() -> run_local_timers() ->
|
||||
* hrtimer_run_queues().
|
||||
*/
|
||||
if (dev->event_handler != tick_handle_periodic)
|
||||
return;
|
||||
#endif
|
||||
|
||||
if (!clockevent_state_oneshot(dev))
|
||||
return;
|
||||
|
||||
for (;;) {
|
||||
/*
|
||||
* Setup the next period for devices, which do not have
|
||||
* periodic mode:
|
||||
*/
|
||||
next = ktime_add_ns(next, TICK_NSEC);
|
||||
|
||||
if (!lx_clockevents_program_event(dev, next))
|
||||
return;
|
||||
|
||||
/*
|
||||
* Have to be careful here. If we're in oneshot mode,
|
||||
* before we call tick_periodic() in a loop, we need
|
||||
* to be sure we're using a real hardware clocksource.
|
||||
* Otherwise we could get trapped in an infinite
|
||||
* loop, as the tick_periodic() increments jiffies,
|
||||
* which then will increment time, possibly causing
|
||||
* the loop to trigger again and again.
|
||||
*/
|
||||
if (timekeeping_valid_for_hres()) {
|
||||
do_timer(1); /* tick_periodic(cpu); */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user