public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jason Low <jason.low2@hp.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@kernel.org>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	Oleg Nesterov <oleg@redhat.com>,
	Mike Galbraith <umgwanakikbuti@gmail.com>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Scott J Norton <scott.norton@hp.com>,
	Chegu Vinod <chegu_vinod@hp.com>,
	Aswin Chandramouleeswaran <aswin@hp.com>,
	linux-kernel@vger.kernel.org, jason.low2@hp.com
Subject: Re: [RFC PATCH] sched, timer: Use atomics for thread_group_cputimer stats
Date: Fri, 23 Jan 2015 11:23:36 -0800	[thread overview]
Message-ID: <1422041016.2436.19.camel@j-VirtualBox> (raw)
In-Reply-To: <20150123092508.GJ2896@worktop.programming.kicks-ass.net>

On Fri, 2015-01-23 at 10:25 +0100, Peter Zijlstra wrote:
> On Thu, Jan 22, 2015 at 07:31:53PM -0800, Jason Low wrote:
> > +static void update_gt_cputime(struct thread_group_cputimer *a, struct task_cputime *b)
> >  {
> > +	if (b->utime > atomic64_read(&a->utime))
> > +		atomic64_set(&a->utime, b->utime);
> >  
> > +	if (b->stime > atomic64_read(&a->stime))
> > +		atomic64_set(&a->stime, b->stime);
> >  
> > +	if (b->sum_exec_runtime > atomic64_read(&a->sum_exec_runtime))
> > +		atomic64_set(&a->sum_exec_runtime, b->sum_exec_runtime);
> >  }
> 
> See something like this is not safe against concurrent adds.

How about something like:

u64 a_utime, a_stime, a_sum_exec_runtime;

retry_utime:
	a_utime = atomic64_read(&a->utime);
	if (b->utime > a_utime) {
		if (atomic64_cmpxchg(&a->utime, a_utime, b->utime) != a_utime)
			goto retry_utime;
	}

retry_stime:
	a_stime = atomic64_read(&a->stime);
	if (b->stime > a_stime) {
		if (atomic64_cmpxchg(&a->stime, a_stime, b->stime) != a_stime)
			goto retry_stime;
	}

retry_sum_exec_runtime:
	a_sum_exec_runtime = atomic64_read(&a->sum_exec_runtime);
	if (b->sum_exec_runtime > a_sum_exec_runtime) {
		if (atomic64_cmpxchg(&a->sum_exec_runtime, a_sum_exec_runtime,
				     b->sum_exec_runtime) != a_sum_exec_runtime)
			goto retry_sum_exec_runtime;
	}


  reply	other threads:[~2015-01-23 19:23 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-23  3:31 [RFC PATCH] sched, timer: Use atomics for thread_group_cputimer stats Jason Low
2015-01-23  8:57 ` Peter Zijlstra
2015-01-23  9:25 ` Peter Zijlstra
2015-01-23 19:23   ` Jason Low [this message]
2015-01-23 20:08     ` Peter Zijlstra
2015-01-23 23:39       ` Jason Low
2015-01-23 23:45       ` Jason Low
2015-01-26 17:12         ` Peter Zijlstra
2015-01-23  9:33 ` Peter Zijlstra
2015-01-23 18:07   ` Jason Low
2015-01-23 20:11     ` Peter Zijlstra

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=1422041016.2436.19.camel@j-VirtualBox \
    --to=jason.low2@hp.com \
    --cc=aswin@hp.com \
    --cc=chegu_vinod@hp.com \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=oleg@redhat.com \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peterz@infradead.org \
    --cc=scott.norton@hp.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