All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cputime: fix invalid gtime
@ 2015-09-03  0:45 Hiroshi Shimamoto
  2015-09-17 11:11 ` Hiroshi Shimamoto
  2015-09-17 14:21 ` Peter Zijlstra
  0 siblings, 2 replies; 4+ messages in thread
From: Hiroshi Shimamoto @ 2015-09-03  0:45 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra; +Cc: linux-kernel

From: Hiroshi Shimamoto <h-shimamoto@ct.jp.nec.com>

/proc/stats shows invalid gtime when the thread is running in guest.
When vtime accounting is not enabled, we cannot get a valid delta.

Just return gtime when vtime accounting is not enabled in task_gtime().

Before
10987 (qemu-kvm) S 1 10923 10923 0 -1 138428608 7521 0 90 0 3776 460 0 0 20 0 24 0 11960 8090398720 151288 18446744073709551615 1 1 0 0 0 0 2147220671 4096 25155 18446744073709551615 0 0 -1 9 0 0 0 3554 0 0 0 0 0 0 0 0 0
10987 (qemu-kvm) S 1 10923 10923 0 -1 138428608 7521 0 90 0 3776 460 0 0 20 0 17 0 11960 8031649792 150268 18446744073709551615 1 1 0 0 0 0 2147220671 4096 25155 18446744073709551615 0 0 -1 9 0 0 0 3554 0 0 0 0 0 0 0 0 0
10987 (qemu-kvm) R 1 10923 10923 0 -1 138428624 7521 0 90 0 3843 460 0 0 20 0 17 0 11960 8031649792 150268 18446744073709551615 1 1 0 0 0 0 2147220671 4096 25155 18446744073709551615 0 0 -1 9 0 0 0 21415 0 0 0 0 0 0 0 0 0
10987 (qemu-kvm) R 1 10923 10923 0 -1 138428624 7521 0 90 0 3943 460 0 0 20 0 17 0 11960 8031649792 150268 18446744073709551615 1 1 0 0 0 0 2147220671 4096 25155 18446744073709551615 0 0 -1 9 0 0 0 21616 0 0 0 0 0 0 0 0 0
10987 (qemu-kvm) R 1 10923 10923 0 -1 138428624 7521 0 90 0 4044 460 0 0 20 0 17 0 11960 8031649792 150268 18446744073709551615 1 1 0 0 0 0 2147220671 4096 25155 18446744073709551615 0 0 -1 9 0 0 0 21816 0 0 0 0 0 0 0 0 0
10987 (qemu-kvm) R 1 10923 10923 0 -1 138428624 7521 0 90 0 4144 460 0 0 20 0 17 0 11960 8031649792 150268 18446744073709551615 1 1 0 0 0 0 2147220671 4096 25155 18446744073709551615 0 0 -1 9 0 0 0 22017 0 0 0 0 0 0 0 0 0
10987 (qemu-kvm) R 1 10923 10923 0 -1 138428624 7521 0 90 0 4245 460 0 0 20 0 11 0 11960 7981293568 149758 18446744073709551615 1 1 0 0 0 0 2147220671 4096 25155 18446744073709551615 0 0 -1 9 0 0 0 22218 0 0 0 0 0 0 0 0 0
10987 (qemu-kvm) S 1 10923 10923 0 -1 138428608 7521 0 90 0 4308 460 0 0 20 0 11 0 11960 7981293568 149758 18446744073709551615 1 1 0 0 0 0 2147220671 4096 25155 18446744073709551615 0 0 -1 9 0 0 0 4084 0 0 0 0 0 0 0 0 0

After
10845 (qemu-kvm) S 1 10792 10792 0 -1 138428608 202 0 0 0 2858 30 0 0 20 0 29 0 7676 8511279104 148187 18446744073709551615 1 1 0 0 0 0 2147220671 4096 25155 18446744073709551615 0 0 -1 3 0 0 0 2874 0 0 0 0 0 0 0 0 0
10845 (qemu-kvm) S 1 10792 10792 0 -1 138428608 202 0 0 0 2858 30 0 0 20 0 29 0 7676 8511279104 148187 18446744073709551615 1 1 0 0 0 0 2147220671 4096 25155 18446744073709551615 0 0 -1 3 0 0 0 2874 0 0 0 0 0 0 0 0 0
10845 (qemu-kvm) R 1 10792 10792 0 -1 138428624 203 0 0 0 2936 30 0 0 20 0 29 0 7676 8511279104 148187 18446744073709551615 1 1 0 0 0 0 2147220671 4096 25155 18446744073709551615 0 0 -1 3 0 0 0 2952 0 0 0 0 0 0 0 0 0
10845 (qemu-kvm) R 1 10792 10792 0 -1 138428624 203 0 0 0 3037 30 0 0 20 0 29 0 7676 8511279104 152184 18446744073709551615 1 1 0 0 0 0 2147220671 4096 25155 18446744073709551615 0 0 -1 3 0 0 0 3052 0 0 0 0 0 0 0 0 0
10845 (qemu-kvm) R 1 10792 10792 0 -1 138428624 203 0 0 0 3137 30 0 0 20 0 29 0 7676 8511279104 152184 18446744073709551615 1 1 0 0 0 0 2147220671 4096 25155 18446744073709551615 0 0 -1 3 0 0 0 3152 0 0 0 0 0 0 0 0 0
10845 (qemu-kvm) R 1 10792 10792 0 -1 138428624 203 0 0 0 3237 30 0 0 20 0 27 0 7676 8511279104 152188 18446744073709551615 1 1 0 0 0 0 2147220671 4096 25155 18446744073709551615 0 0 -1 3 0 0 0 3252 0 0 0 0 0 0 0 0 0
10845 (qemu-kvm) S 1 10792 10792 0 -1 138428608 203 0 0 0 3262 31 0 0 20 0 11 0 7676 8393781248 151156 18446744073709551615 1 1 0 0 0 0 2147220671 4096 25155 18446744073709551615 0 0 -1 3 0 0 0 3277 0 0 0 0 0 0 0 0 0
10845 (qemu-kvm) S 1 10792 10792 0 -1 138428608 203 0 0 0 3262 31 0 0 20 0 11 0 7676 8393781248 151156 18446744073709551615 1 1 0 0 0 0 2147220671 4096 25155 18446744073709551615 0 0 -1 3 0 0 0 3277 0 0 0 0 0 0 0 0 0

Signed-off-by: Hiroshi Shimamoto <h-shimamoto@ct.jp.nec.com>
---
 kernel/sched/cputime.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index 8cbc3db..f614ee9 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -786,6 +786,9 @@ cputime_t task_gtime(struct task_struct *t)
 	unsigned int seq;
 	cputime_t gtime;
 
+	if (!vtime_accounting_enabled())
+		return t->gtime;
+
 	do {
 		seq = read_seqbegin(&t->vtime_seqlock);
 
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* RE: [PATCH] cputime: fix invalid gtime
  2015-09-03  0:45 [PATCH] cputime: fix invalid gtime Hiroshi Shimamoto
@ 2015-09-17 11:11 ` Hiroshi Shimamoto
  2015-09-17 14:21 ` Peter Zijlstra
  1 sibling, 0 replies; 4+ messages in thread
From: Hiroshi Shimamoto @ 2015-09-17 11:11 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra; +Cc: linux-kernel

Hi,

have you had to time to see it?

thanks,
Hiroshi

> Subject: [PATCH] cputime: fix invalid gtime
> 
> From: Hiroshi Shimamoto <h-shimamoto@ct.jp.nec.com>
> 
> /proc/stats shows invalid gtime when the thread is running in guest.
> When vtime accounting is not enabled, we cannot get a valid delta.
> 
> Just return gtime when vtime accounting is not enabled in task_gtime().
> 
> Before
> 10987 (qemu-kvm) S 1 10923 10923 0 -1 138428608 7521 0 90 0 3776 460 0 0 20 0 24 0 11960 8090398720 151288 18446744073709551615
> 1 1 0 0 0 0 2147220671 4096 25155 18446744073709551615 0 0 -1 9 0 0 0 3554 0 0 0 0 0 0 0 0 0
> 10987 (qemu-kvm) S 1 10923 10923 0 -1 138428608 7521 0 90 0 3776 460 0 0 20 0 17 0 11960 8031649792 150268 18446744073709551615
> 1 1 0 0 0 0 2147220671 4096 25155 18446744073709551615 0 0 -1 9 0 0 0 3554 0 0 0 0 0 0 0 0 0
> 10987 (qemu-kvm) R 1 10923 10923 0 -1 138428624 7521 0 90 0 3843 460 0 0 20 0 17 0 11960 8031649792 150268 18446744073709551615
> 1 1 0 0 0 0 2147220671 4096 25155 18446744073709551615 0 0 -1 9 0 0 0 21415 0 0 0 0 0 0 0 0 0
> 10987 (qemu-kvm) R 1 10923 10923 0 -1 138428624 7521 0 90 0 3943 460 0 0 20 0 17 0 11960 8031649792 150268 18446744073709551615
> 1 1 0 0 0 0 2147220671 4096 25155 18446744073709551615 0 0 -1 9 0 0 0 21616 0 0 0 0 0 0 0 0 0
> 10987 (qemu-kvm) R 1 10923 10923 0 -1 138428624 7521 0 90 0 4044 460 0 0 20 0 17 0 11960 8031649792 150268 18446744073709551615
> 1 1 0 0 0 0 2147220671 4096 25155 18446744073709551615 0 0 -1 9 0 0 0 21816 0 0 0 0 0 0 0 0 0
> 10987 (qemu-kvm) R 1 10923 10923 0 -1 138428624 7521 0 90 0 4144 460 0 0 20 0 17 0 11960 8031649792 150268 18446744073709551615
> 1 1 0 0 0 0 2147220671 4096 25155 18446744073709551615 0 0 -1 9 0 0 0 22017 0 0 0 0 0 0 0 0 0
> 10987 (qemu-kvm) R 1 10923 10923 0 -1 138428624 7521 0 90 0 4245 460 0 0 20 0 11 0 11960 7981293568 149758 18446744073709551615
> 1 1 0 0 0 0 2147220671 4096 25155 18446744073709551615 0 0 -1 9 0 0 0 22218 0 0 0 0 0 0 0 0 0
> 10987 (qemu-kvm) S 1 10923 10923 0 -1 138428608 7521 0 90 0 4308 460 0 0 20 0 11 0 11960 7981293568 149758 18446744073709551615
> 1 1 0 0 0 0 2147220671 4096 25155 18446744073709551615 0 0 -1 9 0 0 0 4084 0 0 0 0 0 0 0 0 0
> 
> After
> 10845 (qemu-kvm) S 1 10792 10792 0 -1 138428608 202 0 0 0 2858 30 0 0 20 0 29 0 7676 8511279104 148187 18446744073709551615
> 1 1 0 0 0 0 2147220671 4096 25155 18446744073709551615 0 0 -1 3 0 0 0 2874 0 0 0 0 0 0 0 0 0
> 10845 (qemu-kvm) S 1 10792 10792 0 -1 138428608 202 0 0 0 2858 30 0 0 20 0 29 0 7676 8511279104 148187 18446744073709551615
> 1 1 0 0 0 0 2147220671 4096 25155 18446744073709551615 0 0 -1 3 0 0 0 2874 0 0 0 0 0 0 0 0 0
> 10845 (qemu-kvm) R 1 10792 10792 0 -1 138428624 203 0 0 0 2936 30 0 0 20 0 29 0 7676 8511279104 148187 18446744073709551615
> 1 1 0 0 0 0 2147220671 4096 25155 18446744073709551615 0 0 -1 3 0 0 0 2952 0 0 0 0 0 0 0 0 0
> 10845 (qemu-kvm) R 1 10792 10792 0 -1 138428624 203 0 0 0 3037 30 0 0 20 0 29 0 7676 8511279104 152184 18446744073709551615
> 1 1 0 0 0 0 2147220671 4096 25155 18446744073709551615 0 0 -1 3 0 0 0 3052 0 0 0 0 0 0 0 0 0
> 10845 (qemu-kvm) R 1 10792 10792 0 -1 138428624 203 0 0 0 3137 30 0 0 20 0 29 0 7676 8511279104 152184 18446744073709551615
> 1 1 0 0 0 0 2147220671 4096 25155 18446744073709551615 0 0 -1 3 0 0 0 3152 0 0 0 0 0 0 0 0 0
> 10845 (qemu-kvm) R 1 10792 10792 0 -1 138428624 203 0 0 0 3237 30 0 0 20 0 27 0 7676 8511279104 152188 18446744073709551615
> 1 1 0 0 0 0 2147220671 4096 25155 18446744073709551615 0 0 -1 3 0 0 0 3252 0 0 0 0 0 0 0 0 0
> 10845 (qemu-kvm) S 1 10792 10792 0 -1 138428608 203 0 0 0 3262 31 0 0 20 0 11 0 7676 8393781248 151156 18446744073709551615
> 1 1 0 0 0 0 2147220671 4096 25155 18446744073709551615 0 0 -1 3 0 0 0 3277 0 0 0 0 0 0 0 0 0
> 10845 (qemu-kvm) S 1 10792 10792 0 -1 138428608 203 0 0 0 3262 31 0 0 20 0 11 0 7676 8393781248 151156 18446744073709551615
> 1 1 0 0 0 0 2147220671 4096 25155 18446744073709551615 0 0 -1 3 0 0 0 3277 0 0 0 0 0 0 0 0 0
> 
> Signed-off-by: Hiroshi Shimamoto <h-shimamoto@ct.jp.nec.com>
> ---
>  kernel/sched/cputime.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
> index 8cbc3db..f614ee9 100644
> --- a/kernel/sched/cputime.c
> +++ b/kernel/sched/cputime.c
> @@ -786,6 +786,9 @@ cputime_t task_gtime(struct task_struct *t)
>  	unsigned int seq;
>  	cputime_t gtime;
> 
> +	if (!vtime_accounting_enabled())
> +		return t->gtime;
> +
>  	do {
>  		seq = read_seqbegin(&t->vtime_seqlock);
> 
> --
> 1.8.3.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] cputime: fix invalid gtime
  2015-09-03  0:45 [PATCH] cputime: fix invalid gtime Hiroshi Shimamoto
  2015-09-17 11:11 ` Hiroshi Shimamoto
@ 2015-09-17 14:21 ` Peter Zijlstra
  2015-09-17 23:47   ` Hiroshi Shimamoto
  1 sibling, 1 reply; 4+ messages in thread
From: Peter Zijlstra @ 2015-09-17 14:21 UTC (permalink / raw)
  To: Hiroshi Shimamoto; +Cc: Ingo Molnar, linux-kernel, Frederic Weisbecker

On Thu, Sep 03, 2015 at 12:45:50AM +0000, Hiroshi Shimamoto wrote:
> From: Hiroshi Shimamoto <h-shimamoto@ct.jp.nec.com>
> 
> /proc/stats shows invalid gtime when the thread is running in guest.

Why is this a problem?

> When vtime accounting is not enabled, we cannot get a valid delta.
> Just return gtime when vtime accounting is not enabled in task_gtime().

But isn't other stuff then also broken, like fetch_task_cputime(). Tell
me more about why you think your patch is the right one.

> Before
> 10987 (qemu-kvm) S 1 10923 10923 0 -1 138428608 7521 0 90 0 3776 460 0 0 20 0 24 0 11960 8090398720 151288 18446744073709551615 1 1 0 0 0 0 2147220671 4096 25155 18446744073709551615 0 0 -1 9 0 0 0 3554 0 0 0 0 0 0 0 0 0

It would have been helpful if you'd used a small script to take out the
right column. As is I've no clue which field to look at.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH] cputime: fix invalid gtime
  2015-09-17 14:21 ` Peter Zijlstra
@ 2015-09-17 23:47   ` Hiroshi Shimamoto
  0 siblings, 0 replies; 4+ messages in thread
From: Hiroshi Shimamoto @ 2015-09-17 23:47 UTC (permalink / raw)
  To: Peter Zijlstra; +Cc: Ingo Molnar, linux-kernel, Frederic Weisbecker

> Subject: Re: [PATCH] cputime: fix invalid gtime
> 
> On Thu, Sep 03, 2015 at 12:45:50AM +0000, Hiroshi Shimamoto wrote:
> > From: Hiroshi Shimamoto <h-shimamoto@ct.jp.nec.com>
> >
> > /proc/stats shows invalid gtime when the thread is running in guest.
> 
> Why is this a problem?

In host, when I monitored cpu usage in guest I noticed that the cpu time
is not stable.

> 
> > When vtime accounting is not enabled, we cannot get a valid delta.
> > Just return gtime when vtime accounting is not enabled in task_gtime().
> 
> But isn't other stuff then also broken, like fetch_task_cputime(). Tell
> me more about why you think your patch is the right one.

No, because I think vtime_snap_whence keeps VTIME_SLEEPING until
vtime_accounting_enabled() returns true. Then no delta is added.

> 
> > Before
> > 10987 (qemu-kvm) S 1 10923 10923 0 -1 138428608 7521 0 90 0 3776 460 0 0 20 0 24 0 11960 8090398720 151288 18446744073709551615
> 1 1 0 0 0 0 2147220671 4096 25155 18446744073709551615 0 0 -1 9 0 0 0 3554 0 0 0 0 0 0 0 0 0
> 
> It would have been helpful if you'd used a small script to take out the
> right column. As is I've no clue which field to look at.

Sorry for inconvenience with little explanation.
I watched /proc/<pid>/stats.
When guest running busy, gtime looks big number.

10987 (qemu-kvm) S ... 3554 ...
10987 (qemu-kvm) R ... 21415 ...

and keep it busy. after 1 second.

10987 (qemu-kvm) R ... 21616 ...

few second later, I stopped busy program on guest.
The gtime back to sane value.

10987 (qemu-kvm) S ... 4084 ...


thanks,
Hiroshi


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-09-17 23:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-03  0:45 [PATCH] cputime: fix invalid gtime Hiroshi Shimamoto
2015-09-17 11:11 ` Hiroshi Shimamoto
2015-09-17 14:21 ` Peter Zijlstra
2015-09-17 23:47   ` Hiroshi Shimamoto

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.