Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1420696 > unrolled thread
| Started by | Wanpeng Li <kernellwp@gmail.com> |
|---|---|
| First post | 2016-06-13 12:40 +0200 |
| Last post | 2016-06-13 13:30 +0200 |
| Articles | 8 — 3 participants |
Back to article view | Back to linux.kernel
[PATCH v6 0/3] Sched, KVM: st: Add steal time support to full dynticks CPU time accounting Wanpeng Li <kernellwp@gmail.com> - 2016-06-13 12:40 +0200
[PATCH v6 2/3] sched/cputime: Fix prev steal time accouting during cpu hotplug Wanpeng Li <kernellwp@gmail.com> - 2016-06-13 12:40 +0200
Re: [PATCH v6 2/3] sched/cputime: Fix prev steal time accouting during cpu hotplug Paolo Bonzini <pbonzini@redhat.com> - 2016-06-13 12:50 +0200
[tip:sched/core] sched/cputime: Fix prev steal time accouting during CPU hotplug tip-bot for Wanpeng Li <tipbot@zytor.com> - 2016-06-14 13:30 +0200
[PATCH v6 3/3] sched/cputime: Add steal time support to full dynticks CPU time accounting Wanpeng Li <kernellwp@gmail.com> - 2016-06-13 12:40 +0200
Re: [PATCH v6 3/3] sched/cputime: Add steal time support to full dynticks CPU time accounting Paolo Bonzini <pbonzini@redhat.com> - 2016-06-13 12:50 +0200
[tip:sched/core] sched/cputime: Add steal time support to full dynticks CPU time accounting tip-bot for Wanpeng Li <tipbot@zytor.com> - 2016-06-14 13:30 +0200
Re: [PATCH v6 0/3] Sched, KVM: st: Add steal time support to full dynticks CPU time accounting Wanpeng Li <kernellwp@gmail.com> - 2016-06-13 13:30 +0200
| From | Wanpeng Li <kernellwp@gmail.com> |
|---|---|
| Date | 2016-06-13 12:40 +0200 |
| Subject | [PATCH v6 0/3] Sched, KVM: st: Add steal time support to full dynticks CPU time accounting |
| Message-ID | <rJxrH-52s-23@gated-at.bofh.it> |
Periodic/NOHZ idle which don't use vtime have logic account steal time,
however, vtime(depends on context tracking) which is just used in full
dynticks doesn't account steal time, this patchset adds the steal time
acccount support in vtime which will be used in full dynticks guest.
Patch 1 and patch 2 fix steal clock warp and prev steal time account
during cpu hotplug bugs.
Patch 3 adds the steal time support to full dynticks CPU time accounting.
N.B. This version of patchset drops previous Acked-by and Reviewed-by since
they are different from earlier version. :)
v5 -> v6:
* improve commit message of patch 2/3, 3/3
* fix account st twice
v4 -> v5:
* improve commit message of patch 1/3
* revert commit e9532e69b8d1
* apply same logic to account_idle_time, so change get_vtime_delta instead
v3 -> v4:
* fix grammar errors, thanks Ingo
* cleanup fragile codes, thanks Ingo
v2 -> v3:
* fix the root cause
* convert steal time jiffies to cputime
v1 -> v2:
* update patch subject, description and comments
* deal with the case where steal time suddenly increases by a ludicrous amount
* fix divide zero bug, thanks Rik
Wanpeng Li (3):
KVM: fix steal clock warp during guest cpu hotplug
sched/cputime: Fix prev steal time accouting during cpu hotplug
sched/cputime: Add steal time support to full dynticks CPU time
accounting
arch/x86/kernel/kvm.c | 2 --
kernel/sched/core.c | 1 -
kernel/sched/cputime.c | 16 +++++++++-------
kernel/sched/sched.h | 13 -------------
4 files changed, 9 insertions(+), 23 deletions(-)
--
1.9.1
[toc] | [next] | [standalone]
| From | Wanpeng Li <kernellwp@gmail.com> |
|---|---|
| Date | 2016-06-13 12:40 +0200 |
| Subject | [PATCH v6 2/3] sched/cputime: Fix prev steal time accouting during cpu hotplug |
| Message-ID | <rJxrI-52s-39@gated-at.bofh.it> |
| In reply to | #1420696 |
From: Wanpeng Li <wanpeng.li@hotmail.com>
Commit e9532e69b8d1 ("sched/cputime: Fix steal time accounting vs. CPU
hotplug") set rq->prev_* to 0 after a cpu hotplug comes back in order to
fix the case where (after CPU hotplug) steal is smaller than
rq->prev_steal_time.
However, this should never happen. steal was only smaller because of the
KVM-specific bug fixed by the previous patch. Worse, the previous patch
triggers a bug on CPU hot-unplug/plug operation: because
rq->prev_steal_time is cleared, all of the CPU's past steal time will be
accounted again on hot-plug.
Since the root cause has been fixed, we can just revert commit e9532e69b8d1.
Fixes: 'commit e9532e69b8d1 ("sched/cputime: Fix steal time accounting vs. CPU hotplug")'
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Rik van Riel <riel@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
---
kernel/sched/core.c | 1 -
kernel/sched/sched.h | 13 -------------
2 files changed, 14 deletions(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 7f2cae4..7d45bb3 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -7213,7 +7213,6 @@ static void sched_rq_cpu_starting(unsigned int cpu)
struct rq *rq = cpu_rq(cpu);
rq->calc_load_update = calc_load_update;
- account_reset_rq(rq);
update_max_interval();
}
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 72f1f30..de607e4 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -1809,16 +1809,3 @@ static inline void cpufreq_trigger_update(u64 time) {}
#else /* arch_scale_freq_capacity */
#define arch_scale_freq_invariant() (false)
#endif
-
-static inline void account_reset_rq(struct rq *rq)
-{
-#ifdef CONFIG_IRQ_TIME_ACCOUNTING
- rq->prev_irq_time = 0;
-#endif
-#ifdef CONFIG_PARAVIRT
- rq->prev_steal_time = 0;
-#endif
-#ifdef CONFIG_PARAVIRT_TIME_ACCOUNTING
- rq->prev_steal_time_rq = 0;
-#endif
-}
--
1.9.1
[toc] | [prev] | [next] | [standalone]
| From | Paolo Bonzini <pbonzini@redhat.com> |
|---|---|
| Date | 2016-06-13 12:50 +0200 |
| Subject | Re: [PATCH v6 2/3] sched/cputime: Fix prev steal time accouting during cpu hotplug |
| Message-ID | <rJxBn-56h-23@gated-at.bofh.it> |
| In reply to | #1420700 |
On 13/06/2016 12:32, Wanpeng Li wrote:
> From: Wanpeng Li <wanpeng.li@hotmail.com>
>
> Commit e9532e69b8d1 ("sched/cputime: Fix steal time accounting vs. CPU
> hotplug") set rq->prev_* to 0 after a cpu hotplug comes back in order to
> fix the case where (after CPU hotplug) steal is smaller than
> rq->prev_steal_time.
>
> However, this should never happen. steal was only smaller because of the
> KVM-specific bug fixed by the previous patch. Worse, the previous patch
> triggers a bug on CPU hot-unplug/plug operation: because
> rq->prev_steal_time is cleared, all of the CPU's past steal time will be
> accounted again on hot-plug.
>
> Since the root cause has been fixed, we can just revert commit e9532e69b8d1.
>
> Fixes: 'commit e9532e69b8d1 ("sched/cputime: Fix steal time accounting vs. CPU hotplug")'
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Peter Zijlstra (Intel) <peterz@infradead.org>
> Cc: Rik van Riel <riel@redhat.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Frederic Weisbecker <fweisbec@gmail.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Radim Krčmář <rkrcmar@redhat.com>
> Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
> ---
> kernel/sched/core.c | 1 -
> kernel/sched/sched.h | 13 -------------
> 2 files changed, 14 deletions(-)
>
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 7f2cae4..7d45bb3 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -7213,7 +7213,6 @@ static void sched_rq_cpu_starting(unsigned int cpu)
> struct rq *rq = cpu_rq(cpu);
>
> rq->calc_load_update = calc_load_update;
> - account_reset_rq(rq);
> update_max_interval();
> }
>
> diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
> index 72f1f30..de607e4 100644
> --- a/kernel/sched/sched.h
> +++ b/kernel/sched/sched.h
> @@ -1809,16 +1809,3 @@ static inline void cpufreq_trigger_update(u64 time) {}
> #else /* arch_scale_freq_capacity */
> #define arch_scale_freq_invariant() (false)
> #endif
> -
> -static inline void account_reset_rq(struct rq *rq)
> -{
> -#ifdef CONFIG_IRQ_TIME_ACCOUNTING
> - rq->prev_irq_time = 0;
> -#endif
> -#ifdef CONFIG_PARAVIRT
> - rq->prev_steal_time = 0;
> -#endif
> -#ifdef CONFIG_PARAVIRT_TIME_ACCOUNTING
> - rq->prev_steal_time_rq = 0;
> -#endif
> -}
>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
[toc] | [prev] | [next] | [standalone]
| From | tip-bot for Wanpeng Li <tipbot@zytor.com> |
|---|---|
| Date | 2016-06-14 13:30 +0200 |
| Subject | [tip:sched/core] sched/cputime: Fix prev steal time accouting during CPU hotplug |
| Message-ID | <rJUHE-49V-39@gated-at.bofh.it> |
| In reply to | #1420700 |
Commit-ID: 3d89e5478bf550a50c99e93adf659369798263b0
Gitweb: http://git.kernel.org/tip/3d89e5478bf550a50c99e93adf659369798263b0
Author: Wanpeng Li <wanpeng.li@hotmail.com>
AuthorDate: Mon, 13 Jun 2016 18:32:45 +0800
Committer: Ingo Molnar <mingo@kernel.org>
CommitDate: Tue, 14 Jun 2016 11:13:15 +0200
sched/cputime: Fix prev steal time accouting during CPU hotplug
Commit:
e9532e69b8d1 ("sched/cputime: Fix steal time accounting vs. CPU hotplug")
... set rq->prev_* to 0 after a CPU hotplug comes back, in order to
fix the case where (after CPU hotplug) steal time is smaller than
rq->prev_steal_time.
However, this should never happen. Steal time was only smaller because of the
KVM-specific bug fixed by the previous patch. Worse, the previous patch
triggers a bug on CPU hot-unplug/plug operation: because
rq->prev_steal_time is cleared, all of the CPU's past steal time will be
accounted again on hot-plug.
Since the root cause has been fixed, we can just revert commit e9532e69b8d1.
Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Cc: Rik van Riel <riel@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Fixes: 'commit e9532e69b8d1 ("sched/cputime: Fix steal time accounting vs. CPU hotplug")'
Link: http://lkml.kernel.org/r/1465813966-3116-3-git-send-email-wanpeng.li@hotmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
kernel/sched/core.c | 1 -
kernel/sched/sched.h | 13 -------------
2 files changed, 14 deletions(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 13d0896..c1b537b 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -7227,7 +7227,6 @@ static void sched_rq_cpu_starting(unsigned int cpu)
struct rq *rq = cpu_rq(cpu);
rq->calc_load_update = calc_load_update;
- account_reset_rq(rq);
update_max_interval();
}
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 72f1f30..de607e4 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -1809,16 +1809,3 @@ static inline void cpufreq_trigger_update(u64 time) {}
#else /* arch_scale_freq_capacity */
#define arch_scale_freq_invariant() (false)
#endif
-
-static inline void account_reset_rq(struct rq *rq)
-{
-#ifdef CONFIG_IRQ_TIME_ACCOUNTING
- rq->prev_irq_time = 0;
-#endif
-#ifdef CONFIG_PARAVIRT
- rq->prev_steal_time = 0;
-#endif
-#ifdef CONFIG_PARAVIRT_TIME_ACCOUNTING
- rq->prev_steal_time_rq = 0;
-#endif
-}
[toc] | [prev] | [next] | [standalone]
| From | Wanpeng Li <kernellwp@gmail.com> |
|---|---|
| Date | 2016-06-13 12:40 +0200 |
| Subject | [PATCH v6 3/3] sched/cputime: Add steal time support to full dynticks CPU time accounting |
| Message-ID | <rJxrI-52s-51@gated-at.bofh.it> |
| In reply to | #1420696 |
From: Wanpeng Li <wanpeng.li@hotmail.com>
This patch adds guest steal-time support to full dynticks CPU
time accounting. After the following commit:
ff9a9b4c4334 ("sched, time: Switch VIRT_CPU_ACCOUNTING_GEN to jiffy granularity")
... time sampling became jiffy based, even if it's still listening to ring
boundaries, so steal_account_process_tick() is reused to account how many
'ticks' are stolen-time, after the last accumulation.
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Rik van Riel <riel@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
---
kernel/sched/cputime.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index 75f98c5..3d60e5d 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -257,7 +257,7 @@ void account_idle_time(cputime_t cputime)
cpustat[CPUTIME_IDLE] += (__force u64) cputime;
}
-static __always_inline bool steal_account_process_tick(void)
+static __always_inline unsigned long steal_account_process_tick(unsigned long max_jiffies)
{
#ifdef CONFIG_PARAVIRT
if (static_key_false(¶virt_steal_enabled)) {
@@ -272,14 +272,14 @@ static __always_inline bool steal_account_process_tick(void)
* time in jiffies. Lets cast the result to jiffies
* granularity and account the rest on the next rounds.
*/
- steal_jiffies = nsecs_to_jiffies(steal);
+ steal_jiffies = min(nsecs_to_jiffies(steal), max_jiffies);
this_rq()->prev_steal_time += jiffies_to_nsecs(steal_jiffies);
account_steal_time(jiffies_to_cputime(steal_jiffies));
return steal_jiffies;
}
#endif
- return false;
+ return 0;
}
/*
@@ -346,7 +346,7 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick,
u64 cputime = (__force u64) cputime_one_jiffy;
u64 *cpustat = kcpustat_this_cpu->cpustat;
- if (steal_account_process_tick())
+ if (steal_account_process_tick(ULONG_MAX))
return;
cputime *= ticks;
@@ -477,7 +477,7 @@ void account_process_tick(struct task_struct *p, int user_tick)
return;
}
- if (steal_account_process_tick())
+ if (steal_account_process_tick(ULONG_MAX))
return;
if (user_tick)
@@ -681,12 +681,14 @@ static cputime_t vtime_delta(struct task_struct *tsk)
static cputime_t get_vtime_delta(struct task_struct *tsk)
{
unsigned long now = READ_ONCE(jiffies);
- unsigned long delta = now - tsk->vtime_snap;
+ unsigned long delta_jiffies, steal_jiffies;
+ delta_jiffies = now - tsk->vtime_snap;
+ steal_jiffies = steal_account_process_tick(delta_jiffies);
WARN_ON_ONCE(tsk->vtime_snap_whence == VTIME_INACTIVE);
tsk->vtime_snap = now;
- return jiffies_to_cputime(delta);
+ return jiffies_to_cputime(delta_jiffies - steal_jiffies);
}
static void __vtime_account_system(struct task_struct *tsk)
--
1.9.1
[toc] | [prev] | [next] | [standalone]
| From | Paolo Bonzini <pbonzini@redhat.com> |
|---|---|
| Date | 2016-06-13 12:50 +0200 |
| Subject | Re: [PATCH v6 3/3] sched/cputime: Add steal time support to full dynticks CPU time accounting |
| Message-ID | <rJxBn-56h-15@gated-at.bofh.it> |
| In reply to | #1420703 |
On 13/06/2016 12:32, Wanpeng Li wrote:
> From: Wanpeng Li <wanpeng.li@hotmail.com>
>
> This patch adds guest steal-time support to full dynticks CPU
> time accounting. After the following commit:
>
> ff9a9b4c4334 ("sched, time: Switch VIRT_CPU_ACCOUNTING_GEN to jiffy granularity")
>
> ... time sampling became jiffy based, even if it's still listening to ring
> boundaries, so steal_account_process_tick() is reused to account how many
> 'ticks' are stolen-time, after the last accumulation.
>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Peter Zijlstra (Intel) <peterz@infradead.org>
> Cc: Rik van Riel <riel@redhat.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Frederic Weisbecker <fweisbec@gmail.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Radim Krčmář <rkrcmar@redhat.com>
> Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
> ---
> kernel/sched/cputime.c | 16 +++++++++-------
> 1 file changed, 9 insertions(+), 7 deletions(-)
>
> diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
> index 75f98c5..3d60e5d 100644
> --- a/kernel/sched/cputime.c
> +++ b/kernel/sched/cputime.c
> @@ -257,7 +257,7 @@ void account_idle_time(cputime_t cputime)
> cpustat[CPUTIME_IDLE] += (__force u64) cputime;
> }
>
> -static __always_inline bool steal_account_process_tick(void)
> +static __always_inline unsigned long steal_account_process_tick(unsigned long max_jiffies)
> {
> #ifdef CONFIG_PARAVIRT
> if (static_key_false(¶virt_steal_enabled)) {
> @@ -272,14 +272,14 @@ static __always_inline bool steal_account_process_tick(void)
> * time in jiffies. Lets cast the result to jiffies
> * granularity and account the rest on the next rounds.
> */
> - steal_jiffies = nsecs_to_jiffies(steal);
> + steal_jiffies = min(nsecs_to_jiffies(steal), max_jiffies);
> this_rq()->prev_steal_time += jiffies_to_nsecs(steal_jiffies);
>
> account_steal_time(jiffies_to_cputime(steal_jiffies));
> return steal_jiffies;
> }
> #endif
> - return false;
> + return 0;
> }
>
> /*
> @@ -346,7 +346,7 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick,
> u64 cputime = (__force u64) cputime_one_jiffy;
> u64 *cpustat = kcpustat_this_cpu->cpustat;
>
> - if (steal_account_process_tick())
> + if (steal_account_process_tick(ULONG_MAX))
> return;
>
> cputime *= ticks;
> @@ -477,7 +477,7 @@ void account_process_tick(struct task_struct *p, int user_tick)
> return;
> }
>
> - if (steal_account_process_tick())
> + if (steal_account_process_tick(ULONG_MAX))
> return;
>
> if (user_tick)
> @@ -681,12 +681,14 @@ static cputime_t vtime_delta(struct task_struct *tsk)
> static cputime_t get_vtime_delta(struct task_struct *tsk)
> {
> unsigned long now = READ_ONCE(jiffies);
> - unsigned long delta = now - tsk->vtime_snap;
> + unsigned long delta_jiffies, steal_jiffies;
>
> + delta_jiffies = now - tsk->vtime_snap;
> + steal_jiffies = steal_account_process_tick(delta_jiffies);
> WARN_ON_ONCE(tsk->vtime_snap_whence == VTIME_INACTIVE);
> tsk->vtime_snap = now;
>
> - return jiffies_to_cputime(delta);
> + return jiffies_to_cputime(delta_jiffies - steal_jiffies);
> }
>
> static void __vtime_account_system(struct task_struct *tsk)
>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
[toc] | [prev] | [next] | [standalone]
| From | tip-bot for Wanpeng Li <tipbot@zytor.com> |
|---|---|
| Date | 2016-06-14 13:30 +0200 |
| Subject | [tip:sched/core] sched/cputime: Add steal time support to full dynticks CPU time accounting |
| Message-ID | <rJUHD-49V-23@gated-at.bofh.it> |
| In reply to | #1420703 |
Commit-ID: 807e5b80687c06715d62df51a5473b231e3e8b15
Gitweb: http://git.kernel.org/tip/807e5b80687c06715d62df51a5473b231e3e8b15
Author: Wanpeng Li <wanpeng.li@hotmail.com>
AuthorDate: Mon, 13 Jun 2016 18:32:46 +0800
Committer: Ingo Molnar <mingo@kernel.org>
CommitDate: Tue, 14 Jun 2016 11:13:16 +0200
sched/cputime: Add steal time support to full dynticks CPU time accounting
This patch adds guest steal-time support to full dynticks CPU
time accounting. After the following commit:
ff9a9b4c4334 ("sched, time: Switch VIRT_CPU_ACCOUNTING_GEN to jiffy granularity")
... time sampling became jiffy based, even if we do the sampling from the
context tracking code, so steal_account_process_tick() can be reused
to account how many 'ticks' are stolen-time, after the last accumulation.
Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Cc: Rik van Riel <riel@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1465813966-3116-4-git-send-email-wanpeng.li@hotmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
kernel/sched/cputime.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index 75f98c5..3d60e5d 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -257,7 +257,7 @@ void account_idle_time(cputime_t cputime)
cpustat[CPUTIME_IDLE] += (__force u64) cputime;
}
-static __always_inline bool steal_account_process_tick(void)
+static __always_inline unsigned long steal_account_process_tick(unsigned long max_jiffies)
{
#ifdef CONFIG_PARAVIRT
if (static_key_false(¶virt_steal_enabled)) {
@@ -272,14 +272,14 @@ static __always_inline bool steal_account_process_tick(void)
* time in jiffies. Lets cast the result to jiffies
* granularity and account the rest on the next rounds.
*/
- steal_jiffies = nsecs_to_jiffies(steal);
+ steal_jiffies = min(nsecs_to_jiffies(steal), max_jiffies);
this_rq()->prev_steal_time += jiffies_to_nsecs(steal_jiffies);
account_steal_time(jiffies_to_cputime(steal_jiffies));
return steal_jiffies;
}
#endif
- return false;
+ return 0;
}
/*
@@ -346,7 +346,7 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick,
u64 cputime = (__force u64) cputime_one_jiffy;
u64 *cpustat = kcpustat_this_cpu->cpustat;
- if (steal_account_process_tick())
+ if (steal_account_process_tick(ULONG_MAX))
return;
cputime *= ticks;
@@ -477,7 +477,7 @@ void account_process_tick(struct task_struct *p, int user_tick)
return;
}
- if (steal_account_process_tick())
+ if (steal_account_process_tick(ULONG_MAX))
return;
if (user_tick)
@@ -681,12 +681,14 @@ static cputime_t vtime_delta(struct task_struct *tsk)
static cputime_t get_vtime_delta(struct task_struct *tsk)
{
unsigned long now = READ_ONCE(jiffies);
- unsigned long delta = now - tsk->vtime_snap;
+ unsigned long delta_jiffies, steal_jiffies;
+ delta_jiffies = now - tsk->vtime_snap;
+ steal_jiffies = steal_account_process_tick(delta_jiffies);
WARN_ON_ONCE(tsk->vtime_snap_whence == VTIME_INACTIVE);
tsk->vtime_snap = now;
- return jiffies_to_cputime(delta);
+ return jiffies_to_cputime(delta_jiffies - steal_jiffies);
}
static void __vtime_account_system(struct task_struct *tsk)
[toc] | [prev] | [next] | [standalone]
| From | Wanpeng Li <kernellwp@gmail.com> |
|---|---|
| Date | 2016-06-13 13:30 +0200 |
| Subject | Re: [PATCH v6 0/3] Sched, KVM: st: Add steal time support to full dynticks CPU time accounting |
| Message-ID | <rJye5-5AU-11@gated-at.bofh.it> |
| In reply to | #1420696 |
Cc maintainers/reviewers, 2016-06-13 18:32 GMT+08:00 Wanpeng Li <kernellwp@gmail.com>: > Periodic/NOHZ idle which don't use vtime have logic account steal time, > however, vtime(depends on context tracking) which is just used in full > dynticks doesn't account steal time, this patchset adds the steal time > acccount support in vtime which will be used in full dynticks guest. > > Patch 1 and patch 2 fix steal clock warp and prev steal time account > during cpu hotplug bugs. > Patch 3 adds the steal time support to full dynticks CPU time accounting. > > N.B. This version of patchset drops previous Acked-by and Reviewed-by since > they are different from earlier version. :) > > v5 -> v6: > * improve commit message of patch 2/3, 3/3 > * fix account st twice > v4 -> v5: > * improve commit message of patch 1/3 > * revert commit e9532e69b8d1 > * apply same logic to account_idle_time, so change get_vtime_delta instead > v3 -> v4: > * fix grammar errors, thanks Ingo > * cleanup fragile codes, thanks Ingo > v2 -> v3: > * fix the root cause > * convert steal time jiffies to cputime > v1 -> v2: > * update patch subject, description and comments > * deal with the case where steal time suddenly increases by a ludicrous amount > * fix divide zero bug, thanks Rik > > Wanpeng Li (3): > KVM: fix steal clock warp during guest cpu hotplug > sched/cputime: Fix prev steal time accouting during cpu hotplug > sched/cputime: Add steal time support to full dynticks CPU time > accounting > > arch/x86/kernel/kvm.c | 2 -- > kernel/sched/core.c | 1 - > kernel/sched/cputime.c | 16 +++++++++------- > kernel/sched/sched.h | 13 ------------- > 4 files changed, 9 insertions(+), 23 deletions(-) > > -- > 1.9.1 >
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web