All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Jaromir Capik <jcapik@redhat.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Michal Hocko <mhocko@suse.cz>,
	Martin Schwidefsky <schwidefsky@de.ibm.com>,
	Ingo Molnar <mingo@kernel.org>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Thomas Gleixner <tglx@linutronix.de>
Cc: Ania Honess <ahoness@redhat.com>,
	atomlin@redhat.com, asolanas@redhat.com,
	linux-kernel@vger.kernel.org
Subject: proc/stat: idle goes backward
Date: Fri, 16 Aug 2013 16:47:04 +0200	[thread overview]
Message-ID: <20130816144704.GA25904@redhat.com> (raw)
In-Reply-To: <1277145964.2082352.1376490809716.JavaMail.root@redhat.com>

Hello.

Out customer reports that "idle" field is not monotonic. So far this
is all I know. I do not know how to reproduce, etc.

But when I look at this code, this looks really possible even
ignoring drivers/cpuidle/ which plays with update_ts_time_stats().

So, get_cpu_idle_time_us(last_update_time => NULL) does:

	if (ts->idle_active && !nr_iowait_cpu(cpu)) {
		ktime_t delta = ktime_sub(now, ts->idle_entrytime);

		idle = ktime_add(ts->idle_sleeptime, delta);
	} else {
		idle = ts->idle_sleeptime;
	}


Suppose that ts->idle_active == T. By the time we calculate

	idle = ktime_add(ts->idle_sleeptime, delta);

this cpu can be already non-idle and ->idle_sleeptime can be already
updated by tick_nohz_stop_idle(), we return the wrong value.

If user-space reads /proc/stat again after that, "idle" can obviously
go back.

get_cpu_iowait_time_us() has the same problem.

Plus nr_iowait_cpu() can change in between even if cpu stays idle,
io_schedule() can return on another CPU.

Questions:

	- Any other reason why it can be non-monotonic?

	- Should we fix this or should we document that userspace
	  should handle this itself?

	  IOW, is this is bug or not?

Oleg.


       reply	other threads:[~2013-08-16 14:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <v5wUE000000000000000000000000000000000000000000000MRITO500uRRuI-89T-iqXCkOVGWF4w@sfdc.net>
     [not found] ` <1904614521.2884383.1376487067689.JavaMail.root@redhat.com>
     [not found]   ` <1277145964.2082352.1376490809716.JavaMail.root@redhat.com>
2013-08-16 14:47     ` Oleg Nesterov [this message]
2013-08-16 15:01       ` proc/stat: idle goes backward Frederic Weisbecker
2013-08-16 15:13         ` Oleg Nesterov
2013-08-16 15:30           ` Frederic Weisbecker

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=20130816144704.GA25904@redhat.com \
    --to=oleg@redhat.com \
    --cc=ahoness@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=asolanas@redhat.com \
    --cc=atomlin@redhat.com \
    --cc=fweisbec@gmail.com \
    --cc=jcapik@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhocko@suse.cz \
    --cc=mingo@kernel.org \
    --cc=schwidefsky@de.ibm.com \
    --cc=tglx@linutronix.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 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.