public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Rik van Riel <riel@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Mike Galbraith <umgwanakikbuti@gmail.com>,
	linux-kernel@vger.kernel.org,
	Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>,
	Frank Mayhar <fmayhar@google.com>,
	Frederic Weisbecker <fweisbec@redhat.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Sanjay Rao <srao@redhat.com>, Larry Woodman <lwoodman@redhat.com>
Subject: Re: [PATCH RFC] time,signal: protect resource use statistics with seqlock
Date: Fri, 15 Aug 2014 20:36:30 +0200	[thread overview]
Message-ID: <20140815183630.GA22832@redhat.com> (raw)
In-Reply-To: <53EE4278.8030909@redhat.com>

On 08/15, Rik van Riel wrote:
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 08/15/2014 12:49 PM, Oleg Nesterov wrote:
>
> > Just in case... Yes, sure, "seqlock_t stats_lock" is more scalable.
> > Just I do not know it's worth the trouble.
>
> If we don't know whether it is worth the trouble, it is probably best
> to stick to a well-known generic locking algorithm, instead of brewing
> our own and trying to maintain it.

Perhaps. I am obviously biased and can't judge ;) Plus, again, I do
understand that your approach has some advantages too.

> Now to see if this change to cputime_adjust does the trick :)
>
> +++ b/kernel/sched/cputime.c
> @@ -605,9 +605,12 @@ static void cputime_adjust(struct task_cputime *curr,
>  	 * If the tick based count grows faster than the scheduler one,
>  	 * the result of the scaling may go backward.
>  	 * Let's enforce monotonicity.
> +	 * Atomic exchange protects against concurrent cputime_adjust.
>  	 */
> - -	prev->stime = max(prev->stime, stime);
> - -	prev->utime = max(prev->utime, utime);
> +	while (stime > (rtime = ACCESS_ONCE(prev->stime)))
> +		cmpxchg(&prev->stime, rtime, stime);
> +	while (utime > (rtime = ACCESS_ONCE(prev->utime)))
> +		cmpxchg(&prev->utime, rtime, utime);

Yes, perhaps we need something like this in any case. To remind, at least
do_task_stat() calls task_cputime_adjusted() lockless, although we could
fix this separately.

But I do not think the change above is enough. With this change cputime_adjust()
can race with itself. Yes, this guarantees monotonicity even if it is called
lockless, but this can lead to "obviously inconsistent" numbers.

And I don't think we can ignore this. If we could, then we can remove the
scale_stime recalculation and change cputime_adjust() to simply do:

	static void cputime_adjust(struct task_cputime *curr,
				   struct cputime *prev,
				   cputime_t *ut, cputime_t *st)
	{
		/* enforce monotonicity */
		*ut = prev->stime = max(prev->stime, curr->stime);
		*st = prev->utime = max(prev->utime, curr->utime);
	}

Yes, we have this problem either way. And personally I think that this
"enforce monotonicity" logic is pointless, userspace could take care,
but it is too late to complain.

Oleg.


  reply	other threads:[~2014-08-15 18:39 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-12 18:25 [PATCH RFC] time: drop do_sys_times spinlock Rik van Riel
2014-08-12 19:12 ` Oleg Nesterov
2014-08-12 19:22   ` Rik van Riel
2014-08-12 22:27   ` Rik van Riel
2014-08-13 17:22     ` Oleg Nesterov
2014-08-13 17:35       ` Rik van Riel
2014-08-13 18:08         ` Oleg Nesterov
2014-08-13 18:25           ` Rik van Riel
2014-08-13 18:45             ` Oleg Nesterov
2014-08-13 18:57               ` Rik van Riel
2014-08-13 21:03               ` [PATCH RFC] time,signal: protect resource use statistics with seqlock Rik van Riel
2014-08-14  0:43                 ` Frederic Weisbecker
2014-08-14  1:57                   ` Rik van Riel
2014-08-14 13:34                     ` Frederic Weisbecker
2014-08-14 14:39                       ` Oleg Nesterov
2014-08-15  2:52                         ` Frederic Weisbecker
2014-08-15 14:26                           ` Oleg Nesterov
2014-08-15 22:33                             ` Frederic Weisbecker
2014-08-14 13:22                 ` Oleg Nesterov
2014-08-14 13:38                   ` Frederic Weisbecker
2014-08-14 13:53                     ` Oleg Nesterov
2014-08-14 17:48                   ` Oleg Nesterov
2014-08-14 18:34                     ` Oleg Nesterov
2014-08-15  5:19                     ` Mike Galbraith
2014-08-15  6:28                       ` Peter Zijlstra
2014-08-15  9:37                         ` Mike Galbraith
2014-08-15  9:44                           ` Peter Zijlstra
2014-08-15 16:36                         ` Oleg Nesterov
2014-08-15 16:49                           ` Oleg Nesterov
2014-08-15 17:25                             ` Rik van Riel
2014-08-15 18:36                               ` Oleg Nesterov [this message]
2014-08-14 14:24                 ` Oleg Nesterov
2014-08-14 15:37                   ` Rik van Riel
2014-08-14 16:12                     ` Oleg Nesterov
2014-08-14 17:36                       ` Rik van Riel
2014-08-14 18:15                         ` Oleg Nesterov
2014-08-14 19:03                           ` Rik van Riel
2014-08-14 19:37                             ` Oleg Nesterov
2014-08-15  2:14                       ` Rik van Riel
2014-08-15 14:58                         ` Oleg Nesterov
2014-08-13 21:03               ` Rik van Riel
2014-08-13 17:40       ` [PATCH RFC] time: drop do_sys_times spinlock Peter Zijlstra
2014-08-13 17:50         ` Rik van Riel
2014-08-13 17:53           ` Peter Zijlstra
2014-08-13  6:59   ` Mike Galbraith
2014-08-13 11:11     ` Peter Zijlstra
2014-08-13 13:24       ` Rik van Riel
2014-08-13 13:39         ` Peter Zijlstra
2014-08-13 14:09           ` Mike Galbraith

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=20140815183630.GA22832@redhat.com \
    --to=oleg@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=fmayhar@google.com \
    --cc=fweisbec@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lwoodman@redhat.com \
    --cc=peterz@infradead.org \
    --cc=riel@redhat.com \
    --cc=seto.hidetoshi@jp.fujitsu.com \
    --cc=srao@redhat.com \
    --cc=umgwanakikbuti@gmail.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