[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [RFC 7/9] tacc: Introduce a locked interface for guest time
From: Andrii Anisov <andrii_anisov@xxxxxxxx> The locked interface to acquire guest time by scheduling code is introduced. It can be used by schedulers what do require guest time from a different pcpu to take scheduling decission. Signed-off-by: Andrii Anisov <andrii_anisov@xxxxxxxx> --- xen/common/Kconfig | 3 +++ xen/common/schedule.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ xen/include/xen/sched.h | 11 +++++++++++ 3 files changed, 58 insertions(+) diff --git a/xen/common/Kconfig b/xen/common/Kconfig index 16829f6..c1748dd 100644 --- a/xen/common/Kconfig +++ b/xen/common/Kconfig @@ -221,6 +221,9 @@ config ARGO menu "Schedulers" visible if EXPERT = "y" +config TACC_NEEDS_LOCK + bool + config SCHED_CREDIT bool "Credit scheduler support" default y diff --git a/xen/common/schedule.c b/xen/common/schedule.c index 62df77e..98b739f 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -1562,6 +1562,14 @@ static void schedule(void) context_switch(prev, next); } +#ifdef CONFIG_TACC_NEEDS_LOCK +#define tacc_lock(tacc) spin_lock(&tacc->tacc_lock) +#define tacc_unlock(tacc) spin_unlock(&tacc->tacc_lock) +#else +#define tacc_lock(tacc) +#define tacc_unlock(tacc) +#endif + DEFINE_PER_CPU(struct tacc, tacc); static void tacc_state_change(enum TACC_STATES new_state) @@ -1571,6 +1579,7 @@ static void tacc_state_change(enum TACC_STATES new_state) unsigned long flags; local_irq_save(flags); + tacc_lock(tacc); now = NOW(); delta = now - tacc->state_entry_time; @@ -1584,6 +1593,7 @@ static void tacc_state_change(enum TACC_STATES new_state) tacc->state = new_state; tacc->state_entry_time = now; + tacc_unlock(tacc); local_irq_restore(flags); } @@ -1621,7 +1631,9 @@ void tacc_irq_enter(int place) if ( tacc->irq_cnt == 0 ) { + tacc_lock(tacc); tacc->irq_enter_time = NOW(); + tacc_unlock(tacc); } tacc->irq_cnt++; @@ -1636,8 +1648,10 @@ void tacc_irq_exit(int place) ASSERT(tacc->irq_cnt > 0); if ( tacc->irq_cnt == 1 ) { + tacc_lock(tacc); tacc->irq_time = NOW() - tacc->irq_enter_time; tacc->irq_enter_time = 0; + tacc_unlock(tacc); } tacc->irq_cnt--; @@ -1653,6 +1667,36 @@ s_time_t tacc_get_guest_time(struct tacc *tacc) return guest_time; } +#ifdef CONFIG_TACC_NEEDS_LOCK +s_time_t tacc_get_guest_time_cpu(int cpu) +{ + struct tacc* tacc = &per_cpu(tacc, cpu); + s_time_t guest_time; + s_time_t now; + + tacc_lock(tacc); + + now = NOW(); + guest_time = tacc_get_guest_time(tacc); + if (tacc->state == TACC_GUEST || tacc->state == TACC_GSYNC) + { + guest_time += NOW() - tacc->state_entry_time; + } + + if (tacc->irq_enter_time) + { + guest_time -= NOW() - tacc->irq_enter_time; + } + + guest_time -= tacc->irq_time; + + tacc_unlock(tacc); + + return guest_time; +} +#endif + + void context_saved(struct vcpu *prev) { /* Clear running flag /after/ writing context to memory. */ diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 5b41805..a649d1f 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -1028,6 +1028,9 @@ struct tacc s_time_t irq_enter_time; s_time_t irq_time; int irq_cnt; +#ifdef CONFIG_TACC_NEEDS_LOCK + spinlock_t tacc_lock; +#endif }; DECLARE_PER_CPU(struct tacc, tacc); @@ -1041,6 +1044,14 @@ inline s_time_t tacc_get_guest_time_delta(void) return tacc_get_guest_time(&this_cpu(tacc)) - current->pcpu_guest_time; } +#ifdef CONFIG_TACC_NEEDS_LOCK +s_time_t tacc_get_guest_time_cpu(int cpu); +inline s_time_t tacc_get_guest_time_delta_vcpu(struct vcpu* vcpu) +{ + return tacc_get_guest_time_cpu(vcpu->processor) - vcpu->pcpu_guest_time; +} +#endif + #endif /* __SCHED_H__ */ /* -- 2.7.4 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |