mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Rik van Riel <riel@redhat.com>
To: Wanpeng Li <kernellwp@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>,
	Ingo Molnar <mingo@kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Wanpeng Li <wanpeng.li@hotmail.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Radim Krcmar <rkrcmar@redhat.com>, Mike Galbraith <efault@gmx.de>
Subject: Re: [PATCH] time,virt: resync steal time when guest & host lose sync
Date: Fri, 12 Aug 2016 11:58:03 -0400	[thread overview]
Message-ID: <20160812115803.0f26211c@annuminas.surriel.com> (raw)
In-Reply-To: <CANRm+CzUAinBTigNVW37r4odfZmP6gT9vuHY1tnQrXGXp3i6jA@mail.gmail.com>

On Fri, 12 Aug 2016 15:09:00 +0800
Wanpeng Li <kernellwp@gmail.com> wrote:
> 2016-08-12 10:44 GMT+08:00 Rik van Riel <riel@redhat.com>:

> > If you pass ULONG_MAX as the maxtime argument to
> > steal_account_process_time(), does the steal time
> > get accounted properly at 75%?  
> 
> Yes.

I talked with Paolo this morning, and it turns out that if a guest
misses several timer ticks in a row, they will simply get lost.

That means the functions calling steal_account_process_time may not
know how much CPU time has passed since the last time it was called,
but steal_account_process_time will get a good idea on how much time
the host spent running something else.

Removing the limit, and documenting why, seems like the right way to
fix this bug.

Wanpeng, does the patch below work for you?

Everybody else, does this patch look acceptable?

---8<---
Subject: time,virt: do not limit steal_account_process_time

When a guest is interrupted for a longer amount of time, missed clock
ticks are not redelivered later. Because of that, we should not limit
the amount of steal time accounted to the amount of time that the
calling functions think have passed.

Instead, simply let steal_account_process_time account however much
steal time the host told us elapsed. This can make up timer ticks
that were missed when the host scheduled somebody else.

Signed-off-by: Rik van Riel <riel@redhat.com>
Reported-by: Wanpeng Li <kernellwp@gmail.com>
---
 kernel/sched/cputime.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index 1934f658c036..6f15274940fb 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -263,7 +263,12 @@ void account_idle_time(cputime_t cputime)
 		cpustat[CPUTIME_IDLE] += (__force u64) cputime;
 }
 
-static __always_inline cputime_t steal_account_process_time(cputime_t maxtime)
+/*
+ * When a guest is interrupted for a longer amount of time, missed clock
+ * ticks are not redelivered later. Due to that, this function may on
+ * occasion account more time than the calling functions think elapsed.
+ */
+static __always_inline cputime_t steal_account_process_time(void)
 {
 #ifdef CONFIG_PARAVIRT
 	if (static_key_false(&paravirt_steal_enabled)) {
@@ -273,7 +278,7 @@ static __always_inline cputime_t steal_account_process_time(cputime_t maxtime)
 		steal = paravirt_steal_clock(smp_processor_id());
 		steal -= this_rq()->prev_steal_time;
 
-		steal_cputime = min(nsecs_to_cputime(steal), maxtime);
+		steal_cputime = nsecs_to_cputime(steal);
 		account_steal_time(steal_cputime);
 		this_rq()->prev_steal_time += cputime_to_nsecs(steal_cputime);
 
@@ -290,7 +295,7 @@ static inline cputime_t account_other_time(cputime_t max)
 {
 	cputime_t accounted;
 
-	accounted = steal_account_process_time(max);
+	accounted = steal_account_process_time();
 
 	if (accounted < max)
 		accounted += irqtime_account_hi_update(max - accounted);
@@ -486,7 +491,7 @@ void account_process_tick(struct task_struct *p, int user_tick)
 	}
 
 	cputime = cputime_one_jiffy;
-	steal = steal_account_process_time(cputime);
+	steal = steal_account_process_time();
 
 	if (steal >= cputime)
 		return;

  reply	other threads:[~2016-08-12 15:58 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-13 14:50 [GIT PULL] cputime fixes and cleanups Frederic Weisbecker
2016-07-13 14:50 ` [PATCH 1/5] sched,time: Count actually elapsed irq & softirq time Frederic Weisbecker
2016-07-14 10:37   ` [tip:timers/nohz] sched/cputime: " tip-bot for Rik van Riel
2016-08-09  3:59   ` [PATCH 1/5] sched,time: " Wanpeng Li
2016-08-09 14:06     ` Rik van Riel
2016-08-09 23:07       ` Wanpeng Li
2016-08-10  7:51         ` Wanpeng Li
2016-08-09 23:25       ` Wanpeng Li
2016-08-09 23:31         ` Wanpeng Li
2016-08-09 23:35         ` Wanpeng Li
2016-08-09 23:39         ` Wanpeng Li
2016-08-10  5:07           ` Rik van Riel
2016-08-10  6:33             ` Wanpeng Li
2016-08-10 16:52           ` [PATCH] time,virt: resync steal time when guest & host lose sync Rik van Riel
2016-08-11 10:11             ` Wanpeng Li
2016-08-12  2:44               ` Rik van Riel
2016-08-12  7:09                 ` Wanpeng Li
2016-08-12 15:58                   ` Rik van Riel [this message]
2016-08-13 15:36                     ` Frederic Weisbecker
2016-08-15  8:53                     ` Wanpeng Li
2016-08-15 11:38                       ` Wanpeng Li
2016-08-15 15:00                       ` Rik van Riel
2016-08-15 22:19                         ` Wanpeng Li
2016-08-16  1:31                         ` Wanpeng Li
2016-08-16  2:11                           ` Rik van Riel
2016-08-16  6:54                             ` Wanpeng Li
2016-08-16 14:01                               ` Rik van Riel
2016-08-16 23:08                                 ` Wanpeng Li
2016-08-12 16:33             ` Paolo Bonzini
2016-08-12 17:23               ` Rik van Riel
2016-08-13  7:18                 ` Paolo Bonzini
2016-08-13  8:42             ` Ingo Molnar
2016-08-14  1:50               ` Rik van Riel
2016-08-18  8:23               ` Wanpeng Li
2016-07-13 14:50 ` [PATCH 2/5] nohz,cputime: Replace VTIME_GEN irq time code with IRQ_TIME_ACCOUNTING code Frederic Weisbecker
2016-07-14 10:37   ` [tip:timers/nohz] sched/cputime: " tip-bot for Rik van Riel
2016-07-13 14:50 ` [PATCH 3/5] sched: Complete cleanup of old vtime gen irqtime accounting Frederic Weisbecker
2016-07-14 10:38   ` [tip:timers/nohz] sched/cputime: Clean up the old vtime gen irqtime accounting completely tip-bot for Frederic Weisbecker
2016-07-13 14:50 ` [PATCH 4/5] sched: Reorganize vtime native irqtime accounting headers Frederic Weisbecker
2016-07-14 10:38   ` [tip:timers/nohz] sched/cputime: " tip-bot for Frederic Weisbecker
2016-07-13 14:50 ` [PATCH 5/5] time: Drop local_irq_save/restore from irqtime_account_irq Frederic Weisbecker
2016-07-14 10:38   ` [tip:timers/nohz] sched/cputime: Drop local_irq_save/restore from irqtime_account_irq() tip-bot for Rik van Riel

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=20160812115803.0f26211c@annuminas.surriel.com \
    --to=riel@redhat.com \
    --cc=efault@gmx.de \
    --cc=fweisbec@gmail.com \
    --cc=kernellwp@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rkrcmar@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=wanpeng.li@hotmail.com \
    /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

all inboxes | Powered by JetHome®