LKML Archive on
help / color / mirror / Atom feed
From: Will Deacon <>
Cc: Will Deacon <>,
	Santosh Shilimkar <>,
	Robert Richter <>
Subject: [PATCH] oprofile: add SMP barriers for hrtimer hotplug code
Date: Mon, 31 Jan 2011 15:08:21 +0000	[thread overview]
Message-ID: <> (raw)

OProfile uses a CPU notifier to start and stop any hrtimers when CPUs change
between ONLINE and DEAD. A static int ctr_running is used to keep track of
the counter state.

This can lead to problems where writes to the state variable are re-ordered
with repect to reads of the variable occurring on other CPUs, meaning that
__oprofile_hrtimer_start may read ctr_running as 0 and not initialise the
hrtimer. Potential deadlock can occur in __oprofile_hrtimer_stop because
lock_hrtimer_base will poll until timer->base != NULL, which will never

This patch adds smp_mb()s to ensure that ctr_running mirrors the correct
counter state.

Cc: Santosh Shilimkar <>
Cc: Robert Richter <>
Signed-off-by: Will Deacon <>
 drivers/oprofile/timer_int.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
index 0107251..38c1e1b 100644
--- a/drivers/oprofile/timer_int.c
+++ b/drivers/oprofile/timer_int.c
@@ -48,6 +48,7 @@ static int oprofile_hrtimer_start(void)
 	ctr_running = 1;
+	smp_mb();
 	on_each_cpu(__oprofile_hrtimer_start, NULL, 1);
 	return 0;
@@ -70,6 +71,7 @@ static void oprofile_hrtimer_stop(void)
+	smp_mb();
 	ctr_running = 0;

             reply	other threads:[~2011-01-31 15:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-31 15:08 Will Deacon [this message]
2011-01-31 15:41 ` Santosh Shilimkar
2011-01-31 17:24   ` Will Deacon

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:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \
    --subject='Re: [PATCH] oprofile: add SMP barriers for hrtimer hotplug code' \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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).