xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Anisov <andrii.anisov@gmail.com>
To: xen-devel@lists.xenproject.org
Cc: Stefano Stabellini <sstabellini@kernel.org>,
	Andrii Anisov <andrii_anisov@epam.com>, Wei Liu <wl@xen.org>,
	Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
	George Dunlap <George.Dunlap@eu.citrix.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Ian Jackson <ian.jackson@eu.citrix.com>, Tim Deegan <tim@xen.org>,
	Julien Grall <julien.grall@arm.com>,
	Jan Beulich <jbeulich@suse.com>,
	Dario Faggioli <dfaggioli@suse.com>
Subject: [Xen-devel] [RFC 7/9] tacc: Introduce a locked interface for guest time
Date: Wed, 11 Sep 2019 13:32:20 +0300	[thread overview]
Message-ID: <1568197942-15374-8-git-send-email-andrii.anisov@gmail.com> (raw)
In-Reply-To: <1568197942-15374-1-git-send-email-andrii.anisov@gmail.com>

From: Andrii Anisov <andrii_anisov@epam.com>

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@epam.com>
---
 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@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  parent reply	other threads:[~2019-09-11 10:33 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-11 10:32 [Xen-devel] [RFC 0/9] Changes to time accounting Andrii Anisov
2019-09-11 10:32 ` [Xen-devel] [RFC 1/9] schedule: Introduce per-pcpu " Andrii Anisov
2019-09-11 18:01   ` Volodymyr Babchuk
2019-09-12 10:26     ` Andrii Anisov
2019-10-28 14:28   ` Julien Grall
2019-11-06 11:24     ` Andrii Anisov
2020-05-26  2:27       ` Volodymyr Babchuk
2020-05-29  8:48         ` Dario Faggioli
2020-06-02  1:12           ` Volodymyr Babchuk
2020-06-03 15:22             ` Dario Faggioli
2019-09-11 10:32 ` [Xen-devel] [RFC 2/9] sysctl: extend XEN_SYSCTL_getcpuinfo interface Andrii Anisov
2019-10-28 14:52   ` Julien Grall
2019-11-06 11:25     ` Andrii Anisov
2019-09-11 10:32 ` [Xen-devel] [RFC 3/9] xentop: show CPU load information Andrii Anisov
2019-09-11 10:32 ` [Xen-devel] [RFC 4/9] arm64: utilize time accounting Andrii Anisov
2019-09-11 17:48   ` Volodymyr Babchuk
2019-09-12 12:09     ` Andrii Anisov
2019-09-12 12:17       ` Julien Grall
2019-09-12 12:29         ` Andrii Anisov
2019-10-28 14:47   ` Julien Grall
2019-11-06 11:31     ` Andrii Anisov
2019-09-11 10:32 ` [Xen-devel] [RFC 5/9] tacc: Introduce a lockless interface for guest time Andrii Anisov
2019-09-11 10:32 ` [Xen-devel] [RFC 6/9] sched:rtds: get guest time from time accounting code Andrii Anisov
2019-09-11 10:32 ` Andrii Anisov [this message]
2019-09-11 10:32 ` [Xen-devel] [RFC 8/9] sched:credit: " Andrii Anisov
2019-09-11 10:32 ` [Xen-devel] [RFC 9/9] sched:credit2: " Andrii Anisov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1568197942-15374-8-git-send-email-andrii.anisov@gmail.com \
    --to=andrii.anisov@gmail.com \
    --cc=George.Dunlap@eu.citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=andrii_anisov@epam.com \
    --cc=dfaggioli@suse.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jbeulich@suse.com \
    --cc=julien.grall@arm.com \
    --cc=konrad.wilk@oracle.com \
    --cc=sstabellini@kernel.org \
    --cc=tim@xen.org \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).