From: Michal Hocko <mhocko@suse.cz>
To: "Artem S. Tashkinov" <t.artem@lycos.com>
Cc: pomac@vapor.com, linux-kernel@vger.kernel.org, rjw@sisk.pl,
tino.keitel@tikei.de
Subject: [PATCH] proc: Do not overflow get_{idle,iowait}_time for nohz (was: Re: Re: [REGRESSION] [Linux 3.2] top/htop and all other CPU usage)
Date: Fri, 2 Dec 2011 17:49:17 +0100 [thread overview]
Message-ID: <20111202164917.GA6139@tiehlicka.suse.cz> (raw)
In-Reply-To: <20111202133515.GB21070@tiehlicka.suse.cz>
On Fri 02-12-11 14:35:15, Michal Hocko wrote:
> On Tue 29-11-11 11:38:47, Artem S. Tashkinov wrote:
> > On Nov 29, 2011, Michal Hocko <mhocko@suse.cz> wrote:
> >
> > > As I have written in other email could you post your config and collect
> > > the following data?
> > > for i in `seq 30`;
> > > do
> > > cat /proc/stat > `date +'%s'`
> > > sleep 1
> > > done
> > > export old_user=0 old_nice=0 old_sys=0 old_idle=0 old_iowait=0;
> > >
> > > # for all your available CPUs
> > > grep cpu0 * | while read cpu user nice sys idle iowait rest;
> > > do
> > > echo $cpu $(($user-$old_user)) $(($nice-$old_nice)) $(($sys-$old_sys)) $(($idle-$old_idle)) $(($iowait-$old_iowait))
> > > old_user=$user old_nice=$nice old_sys=$sys old_idle=$idle old_iowait=$iowait
> > > done
> >
> > 1322566208:cpu0 5199 0 2931 357890604 2541
> > 1322566209:cpu0 0 0 1 0 0
> > 1322566210:cpu0 0 0 0 0 0
> > 1322566211:cpu0 0 0 0 0 0
[...]
>
> Could you post raw data as well? Ideally starting right after boot and
> collected for more than 30s (longer better...)
Ahh, missed that you attached data. And also noticed that you are using
CONFIG_HZ_300 which explains the problem and why I do cannot reproduce
it.
get_{idle,iowait}_time translates us to cputime64_t and it uses
usecs_to_cputime which is just an alias for usecs_to_jiffies and it does
if (u > jiffies_to_usecs(MAX_JIFFY_OFFSET))
return MAX_JIFFY_OFFSET;
which in your case (HZ=300) means that we overflow much more often than
for HZ==100. The patch below should fix this:
---
>From 23882e2aabe27934df4d23b0ed52749fd4f61ab4 Mon Sep 17 00:00:00 2001
From: Michal Hocko <mhocko@suse.cz>
Date: Fri, 2 Dec 2011 16:17:03 +0100
Subject: [PATCH] proc: Do not overflow get_{idle,iowait}_time for nohz
get_{idle,iowait}_time use usecs_to_cputime to translate micro seconds
time to cputime64_t. This is just an alias to usecs_to_jiffies which
reduces the data type from u64 to unsigned int and also checks whether
the given paramerer overflows jiffies_to_usecs(MAX_JIFFY_OFFSET) and
returns MAX_JIFFY_OFFSET in that case. How much we overflow depends on
CONFIG_HZ and especially for CONFIG_HZ_300 it is quite low (1431649781).
This results in a bug when people saw [h]top going mad reporting 100%
CPU usage even though there was basically no CPU load at all. The reason
was simply that /proc/stat stopped reporting idle/io_wait changes (and
reported MAX_JIFFY_OFFSET) and so the only change happenning was for
user system time.
Let's use nsecs_to_jiffies64 instead as it doesn't overflow.
Signed-off-by: Michal Hocko <mhocko@suse.cz>
---
fs/proc/stat.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/fs/proc/stat.c b/fs/proc/stat.c
index 42b274d..2a30d67 100644
--- a/fs/proc/stat.c
+++ b/fs/proc/stat.c
@@ -32,7 +32,7 @@ static cputime64_t get_idle_time(int cpu)
idle = kstat_cpu(cpu).cpustat.idle;
idle = cputime64_add(idle, arch_idle_time(cpu));
} else
- idle = usecs_to_cputime(idle_time);
+ idle = nsecs_to_jiffies64(1000 * idle_time);
return idle;
}
@@ -46,7 +46,7 @@ static cputime64_t get_iowait_time(int cpu)
/* !NO_HZ so we can rely on cpustat.iowait */
iowait = kstat_cpu(cpu).cpustat.iowait;
else
- iowait = usecs_to_cputime(iowait_time);
+ iowait = nsecs_to_jiffies64(1000 * iowait_time);
return iowait;
}
--
1.7.7.3
--
Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9
Czech Republic
next prev parent reply other threads:[~2011-12-02 16:49 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-28 22:28 [REGRESSION] [Linux 3.2] top/htop and all other CPU usage pomac
2011-11-29 7:52 ` Michal Hocko
2011-11-29 11:38 ` Artem S. Tashkinov
2011-11-29 12:31 ` Michal Hocko
2011-11-29 12:44 ` Michal Hocko
2011-11-29 12:54 ` Artem S. Tashkinov
2011-11-29 13:10 ` Michal Hocko
2011-11-29 13:51 ` Artem S. Tashkinov
2011-11-29 22:51 ` Rafael J. Wysocki
2011-11-30 10:12 ` Michal Hocko
2011-11-30 19:56 ` Rafael J. Wysocki
2011-12-01 14:07 ` Michal Hocko
2011-12-02 10:39 ` Michal Hocko
2011-12-02 13:35 ` Michal Hocko
2011-12-02 16:49 ` Michal Hocko [this message]
2011-12-02 17:59 ` [PATCH] proc: Do not overflow get_{idle,iowait}_time for nohz (was: Re: Re: [REGRESSION] [Linux 3.2] top/htop and all other CPU usage) Michal Hocko
2011-12-02 20:12 ` Artem S. Tashkinov
2011-12-05 8:56 ` Michal Hocko
2011-12-02 17:43 ` Re: Re: [REGRESSION] [Linux 3.2] top/htop and all other CPU usage Artem S. Tashkinov
2011-11-29 17:23 ` Ian Kumlien
2011-11-29 17:31 ` Ian Kumlien
2011-11-29 17:56 ` Michal Hocko
2011-11-29 18:37 ` Ian Kumlien
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=20111202164917.GA6139@tiehlicka.suse.cz \
--to=mhocko@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=pomac@vapor.com \
--cc=rjw@sisk.pl \
--cc=t.artem@lycos.com \
--cc=tino.keitel@tikei.de \
/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®