linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Renninger <trenn@suse.de>
To: Peter Zijlstra <peterz@infradead.org>
Cc: mike@android.com, linux-kernel@vger.kernel.org,
	lizf@cn.fujitsu.com, menage@google.com,
	containers@lists.linux-foundation.org, mingo@elte.hu
Subject: Re: [PATCH 2/2] scheduler: cgroups cpuaccouting: Make cpuusage atomic
Date: Thu, 20 May 2010 12:53:08 +0200	[thread overview]
Message-ID: <201005201253.08904.trenn@suse.de> (raw)
In-Reply-To: <1274295743.1674.1545.camel@laptop>

On Wednesday 19 May 2010 21:02:23 Peter Zijlstra wrote:
> On Wed, 2010-05-19 at 20:58 +0200, Thomas Renninger wrote:
> > and avoid locking on 32 bit.
> > This resolves an ugly dependency in cgroups_cpuaccount.c
> > to per_cpu runqueues lock variable.
> 
> While I totally agree with the sentiments here, atomic64_t isn't
> available on all 32bit archs and is _terribly_ expensive on ARCH=i386.

Please ignore the 2nd patch.
If nobody objects about the creation of kernel/sched.h which should get
used for further cleanups IMO, the first patch should get in.
I thought a bit about it, but taking the per_cpu rq lock is the most sane
thing I could think of.

Here is a fix (bug always was there), for "on top" patching of the first.
It should also be possible to fix this by exchanging:
CONFIG_64BIT to CONFIG_X86_64, but removing the #ifdefs should
be preferred over a lock that is only grabbed via sysfs access...

Thanks,

    Thomas

scheduler: cgroup_cpuaccount - Fix race on cpuusage

A u64 access is not atomic on all 64 bit archs.
Especially this:
*cpuusage += cputime;
should not necessarily be atomic on non X86_64 archs.
As cpuacct_cpuusage_{read,write} is only used during
sysfs access, the lock should be acquired rather rarely
and the code is nicer as well.

Signed-off-by: Thomas Renninger <trenn@suse.de>
CC: linux-kernel@vger.kernel.org
CC: mike@android.com
CC: menage@google.com
CC: lizf@cn.fujitsu.com
CC: containers@lists.linux-foundation.org
CC: mingo@elte.hu
CC: peterz@infradead.org

diff --git a/kernel/cgroup_cpuaccount.c b/kernel/cgroup_cpuaccount.c
index 0ad356a..a9e0345 100644
--- a/kernel/cgroup_cpuaccount.c
+++ b/kernel/cgroup_cpuaccount.c
@@ -95,16 +95,12 @@ static u64 cpuacct_cpuusage_read(struct cpuacct *ca, int cpu)
 	u64 *cpuusage = per_cpu_ptr(ca->cpuusage, cpu);
 	u64 data;
 
-#ifndef CONFIG_64BIT
 	/*
-	 * Take rq->lock to make 64-bit read safe on 32-bit platforms.
+	 * Take rq->lock to make 64-bit read safe
 	 */
 	lock_runqueue(cpu);
 	data = *cpuusage;
 	unlock_runqueue(cpu);
-#else
-	data = *cpuusage;
-#endif
 
 	return data;
 }
@@ -113,16 +109,12 @@ static void cpuacct_cpuusage_write(struct cpuacct *ca, int cpu, u64 val)
 {
 	u64 *cpuusage = per_cpu_ptr(ca->cpuusage, cpu);
 
-#ifndef CONFIG_64BIT
 	/*
-	 * Take rq->lock to make 64-bit write safe on 32-bit platforms.
+	 * Take rq->lock to make 64-bit write safe
 	 */
 	lock_runqueue(cpu);
 	*cpuusage = val;
 	unlock_runqueue(cpu);
-#else
-	*cpuusage = val;
-#endif
 }
 
 /* return total cpu usage (in nanoseconds) of a group */

  parent reply	other threads:[~2010-05-20 10:52 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-19  1:30 [PATCH 0/4] Enable cpu frequency and power tracking for cpuacct cgroup Mike Chan
2010-05-19  1:30 ` [PATCH 1/4] scheduler: cpuacct: Enable platform hooks to track cpuusage for CPU frequencies Mike Chan
2010-05-19  1:30 ` [PATCH 2/4] omap: cpu: Implement callbacks for cpu frequency tracking in cpuacct Mike Chan
2010-05-19  1:30 ` [PATCH 3/4] scheduler: cpuacct: Enable platform callbacks for cpuacct power tracking Mike Chan
2010-05-19  9:30   ` [PATCH] scheduler: Extract cgroups_cpuaccount code from sched.c into own file Thomas Renninger
2010-05-19  9:37     ` Peter Zijlstra
2010-05-19 10:27       ` Peter Zijlstra
2010-05-19 18:58         ` scheduler: cleanup sched.c and extract cgroup_cpuaccount stuff into separate file Thomas Renninger
2010-05-19 18:58         ` [PATCH 1/2] scheduler: Extract cgroups_cpuaccount code from sched.c into own file V2 Thomas Renninger
2010-05-19 18:58         ` [PATCH 2/2] scheduler: cgroups cpuaccouting: Make cpuusage atomic Thomas Renninger
2010-05-19 19:02           ` Peter Zijlstra
2010-05-19 19:13             ` Thomas Renninger
2010-05-19 19:31               ` Mike Chan
2010-05-20 10:53             ` Thomas Renninger [this message]
2010-05-20  0:43           ` KAMEZAWA Hiroyuki
2010-05-19 19:06     ` [PATCH] scheduler: Extract cgroups_cpuaccount code from sched.c into own file Mike Chan
2010-05-19  1:30 ` [PATCH 4/4] omap: cpu: Power tracking support for cgroup cpuacct Mike Chan
2010-05-19 13:11   ` Nishanth Menon
2010-05-19 15:34     ` Thomas Renninger
2010-05-19 18:56       ` Mike Chan
2010-05-19 19:00         ` Nishanth Menon

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=201005201253.08904.trenn@suse.de \
    --to=trenn@suse.de \
    --cc=containers@lists.linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizf@cn.fujitsu.com \
    --cc=menage@google.com \
    --cc=mike@android.com \
    --cc=mingo@elte.hu \
    --cc=peterz@infradead.org \
    /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;
as well as URLs for NNTP newsgroup(s).