[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RFC PATCH v1 4/6] xentop: collect IRQ and HYP time statistics.



Hi Juergen,

On 12/06/2020 05:57, Jürgen Groß wrote:
On 12.06.20 02:22, Volodymyr Babchuk wrote:
As scheduler code now collects time spent in IRQ handlers and in
do_softirq(), we can present those values to userspace tools like
xentop, so system administrator can see how system behaves.

We are updating counters only in sched_get_time_correction() function
to minimize number of taken spinlocks. As atomic_t is 32 bit wide, it
is not enough to store time with nanosecond precision. So we need to
use 64 bit variables and protect them with spinlock.

Signed-off-by: Volodymyr Babchuk <volodymyr_babchuk@xxxxxxxx>
---
  xen/common/sched/core.c     | 17 +++++++++++++++++
  xen/common/sysctl.c         |  1 +
  xen/include/public/sysctl.h |  4 +++-
  xen/include/xen/sched.h     |  2 ++
  4 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/xen/common/sched/core.c b/xen/common/sched/core.c
index a7294ff5c3..ee6b1d9161 100644
--- a/xen/common/sched/core.c
+++ b/xen/common/sched/core.c
@@ -95,6 +95,10 @@ static struct scheduler __read_mostly ops;
  static bool scheduler_active;
+static DEFINE_SPINLOCK(sched_stat_lock);
+s_time_t sched_stat_irq_time;
+s_time_t sched_stat_hyp_time;
+
  static void sched_set_affinity(
      struct sched_unit *unit, const cpumask_t *hard, const cpumask_t *soft); @@ -994,9 +998,22 @@ s_time_t sched_get_time_correction(struct sched_unit *u)
              break;
      }
+    spin_lock_irqsave(&sched_stat_lock, flags);
+    sched_stat_irq_time += irq;
+    sched_stat_hyp_time += hyp;
+    spin_unlock_irqrestore(&sched_stat_lock, flags);

Please don't use a lock. Just use add_sized() instead which will add
atomically.

add_sized() is definitely not atomic. It will only prevent the compiler to read/write multiple time the variable.

If we expect sched_get_time_correction to be called concurrently then we would need to introduce atomic64_t or a spin lock.

Cheers,

--
Julien Grall



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.