lx_emul: update jiffies during schedule

Whenever a new schedule decision is made in the Linux emulation layer,
we try to update the jiffies counter.

Ref genodelabs/genode#4778
This commit is contained in:
Stefan Kalkowski 2023-03-02 13:08:27 +01:00 committed by Christian Helmuth
parent c90b61f571
commit 7e2c546d8e
3 changed files with 27 additions and 5 deletions

View File

@ -28,6 +28,8 @@ unsigned long long lx_emul_time_counter(void);
void lx_emul_time_handle(void);
void lx_emul_time_update_jiffies(void);
#ifdef __cplusplus
}
#endif

View File

@ -17,6 +17,8 @@
#include <linux/sched_clock.h>
#include <linux/smp.h>
#include <linux/of_clk.h>
#include <linux/tick.h>
#include <linux/interrupt.h>
#include <lx_emul/debug.h>
#include <lx_emul/time.h>
#include <lx_emul/init.h>
@ -109,6 +111,24 @@ void lx_emul_time_handle(void)
}
extern ktime_t tick_next_period;
void lx_emul_time_update_jiffies(void)
{
/* check if jiffies need an update */
if (ktime_before(ktime_get(), tick_next_period))
return;
/* tick_nohz_idle_stop_tick breaks with error if softirq is pending */
if (local_softirq_pending() & SOFTIRQ_STOP_IDLE_MASK)
return;
tick_nohz_idle_enter();
tick_nohz_idle_stop_tick();
tick_nohz_idle_restart_tick();
tick_nohz_idle_exit();
}
enum { LX_EMUL_MAX_OF_CLOCK_PROVIDERS = 256 };

View File

@ -103,14 +103,12 @@ static void __schedule(void)
asmlinkage __visible void __sched schedule(void)
{
lx_emul_time_update_jiffies();
if (current->__state) {
unsigned int task_flags = current->flags;
if (task_flags & PF_WQ_WORKER) {
tick_nohz_idle_enter();
lx_emul_time_handle();
tick_nohz_idle_exit();
if (task_flags & PF_WQ_WORKER)
wq_worker_sleeping(current);
}
}
__schedule();
@ -141,6 +139,7 @@ asmlinkage __visible void __sched notrace preempt_schedule(void)
if (likely(!preemptible()))
return;
lx_emul_time_update_jiffies();
__schedule();
}
@ -150,6 +149,7 @@ asmlinkage __visible void __sched notrace preempt_schedule_notrace(void)
if (likely(!preemptible()))
return;
lx_emul_time_update_jiffies();
__schedule();
}