From: "Zhang, Yanmin" <yanmin.zhang@intel.com>
To: "Pavel Machek" <pavel@ucw.cz>
Cc: <linux-kernel@vger.kernel.org>,
"Pallipadi, Venkatesh" <venkatesh.pallipadi@intel.com>,
"Shah, Rajesh" <rajesh.shah@intel.com>
Subject: RE: [BUG] Variable stopmachine_state should be volatile
Date: Fri, 2 Dec 2005 10:48:57 +0800 [thread overview]
Message-ID: <8126E4F969BA254AB43EA03C59F44E840410AF14@pdsmsx404> (raw)
[-- Attachment #1: Type: text/plain, Size: 731 bytes --]
>>-----Original Message-----
>>From: Pavel Machek [mailto:pavel@ucw.cz]
>>Sent: 2005年12月1日 18:26
>>To: Zhang, Yanmin
>>Cc: linux-kernel@vger.kernel.org; Pallipadi, Venkatesh; Shah, Rajesh
>>Subject: Re: [BUG] Variable stopmachine_state should be volatile
>>
>>Hi!
>>
>>> >>Those barriers should already prevent compiler optimalization, no? If
>>> >>they do not, just use some barriers that do.
>>>
>>>
>>> I hit the problem when compiling 2.6 kernel by intel compiler.
>>> How about to change the type of stopmachine_state to atomic_t?
>>
>>That is certainly safest / very conservative solution.
>> Pavel
Thanks. The functions are not performance sensitive, so atomic_t is ok. Here is the new patch.
[-- Attachment #2: stopmachine_state_volatile_2.6.15_rc3_v2.patch --]
[-- Type: application/octet-stream, Size: 2708 bytes --]
--- linux-2.6.15-rc3/kernel/stop_machine.c 2005-11-29 00:02:44.000000000 +0800
+++ linux-2.6.15-rc3_fix/kernel/stop_machine.c 2005-11-30 18:41:55.000000000 +0800
@@ -13,14 +13,12 @@
* kthread. */
/* Thread to stop each CPU in user context. */
-enum stopmachine_state {
- STOPMACHINE_WAIT,
- STOPMACHINE_PREPARE,
- STOPMACHINE_DISABLE_IRQ,
- STOPMACHINE_EXIT,
-};
+#define STOPMACHINE_WAIT 0
+#define STOPMACHINE_PREPARE 1
+#define STOPMACHINE_DISABLE_IRQ 2
+#define STOPMACHINE_EXIT 3
-static enum stopmachine_state stopmachine_state;
+static atomic_t stopmachine_state;
static unsigned int stopmachine_num_threads;
static atomic_t stopmachine_thread_ack;
static DECLARE_MUTEX(stopmachine_mutex);
@@ -33,24 +31,21 @@ static int stopmachine(void *cpu)
set_cpus_allowed(current, cpumask_of_cpu((int)(long)cpu));
/* Ack: we are alive */
- smp_mb(); /* Theoretically the ack = 0 might not be on this CPU yet. */
atomic_inc(&stopmachine_thread_ack);
/* Simple state machine */
- while (stopmachine_state != STOPMACHINE_EXIT) {
- if (stopmachine_state == STOPMACHINE_DISABLE_IRQ
+ while (atomic_read(&stopmachine_state) != STOPMACHINE_EXIT) {
+ if (atomic_read(&stopmachine_state) == STOPMACHINE_DISABLE_IRQ
&& !irqs_disabled) {
local_irq_disable();
irqs_disabled = 1;
/* Ack: irqs disabled. */
- smp_mb(); /* Must read state first. */
atomic_inc(&stopmachine_thread_ack);
- } else if (stopmachine_state == STOPMACHINE_PREPARE
- && !prepared) {
+ } else if (atomic_read(&stopmachine_state)
+ == STOPMACHINE_PREPARE && !prepared) {
/* Everyone is in place, hold CPU. */
preempt_disable();
prepared = 1;
- smp_mb(); /* Must read state first. */
atomic_inc(&stopmachine_thread_ack);
}
/* Yield in first stage: migration threads need to
@@ -62,7 +57,6 @@ static int stopmachine(void *cpu)
}
/* Ack: we are exiting. */
- smp_mb(); /* Must read state first. */
atomic_inc(&stopmachine_thread_ack);
if (irqs_disabled)
@@ -74,11 +68,10 @@ static int stopmachine(void *cpu)
}
/* Change the thread state */
-static void stopmachine_set_state(enum stopmachine_state state)
+static void stopmachine_set_state(int state)
{
atomic_set(&stopmachine_thread_ack, 0);
- smp_wmb();
- stopmachine_state = state;
+ atomic_set(&stopmachine_state, state);
while (atomic_read(&stopmachine_thread_ack) != stopmachine_num_threads)
cpu_relax();
}
@@ -97,7 +90,7 @@ static int stop_machine(void)
atomic_set(&stopmachine_thread_ack, 0);
stopmachine_num_threads = 0;
- stopmachine_state = STOPMACHINE_WAIT;
+ atomic_set(&stopmachine_state, STOPMACHINE_WAIT);
for_each_online_cpu(i) {
if (i == raw_smp_processor_id())
next reply other threads:[~2005-12-02 2:49 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-12-02 2:48 Zhang, Yanmin [this message]
-- strict thread matches above, loose matches on Subject: below --
2005-12-12 7:06 Zhang, Yanmin
2005-12-08 18:53 Luck, Tony
2005-12-08 1:37 Zhang, Yanmin
2005-12-12 13:39 ` Christoph Hellwig
[not found] <88056F38E9E48644A0F562A38C64FB60067BE61C@scsmsx403.amr.corp.intel.com>
2005-12-02 3:53 ` Pavel Machek
2005-12-01 5:27 Zhang, Yanmin
2005-12-01 10:26 ` Pavel Machek
2005-12-01 2:58 Zhang, Yanmin
2005-12-01 3:25 ` Pavel Machek
2005-11-30 2:04 Zhang, Yanmin
2005-11-30 22:19 ` Pavel Machek
2005-12-02 8:04 ` Arjan van de Ven
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=8126E4F969BA254AB43EA03C59F44E840410AF14@pdsmsx404 \
--to=yanmin.zhang@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=pavel@ucw.cz \
--cc=rajesh.shah@intel.com \
--cc=venkatesh.pallipadi@intel.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
all inboxes | Powered by JetHome®