From: "Srivatsa S. Bhat" <srivatsa.bhat@linux.vnet.ibm.com>
To: Tejun Heo <tj@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
peterz@infradead.org, tglx@linutronix.de, mingo@kernel.org,
rusty@rustcorp.com.au, fweisbec@gmail.com, hch@infradead.org,
mgorman@suse.de, riel@redhat.com, bp@suse.de,
rostedt@goodmis.org, mgalbraith@suse.de, ego@linux.vnet.ibm.com,
paulmck@linux.vnet.ibm.com, oleg@redhat.com, rjw@rjwysocki.net,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/2] CPU hotplug, stop-machine: Plug race-window that leads to "IPI-to-offline-CPU"
Date: Mon, 12 May 2014 01:37:58 +0530 [thread overview]
Message-ID: <536FD89E.8030904@linux.vnet.ibm.com> (raw)
In-Reply-To: <20140510030635.GC22539@mtj.dyndns.org>
On 05/10/2014 08:36 AM, Tejun Heo wrote:
> On Wed, May 07, 2014 at 03:31:51AM +0530, Srivatsa S. Bhat wrote:
>> diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c
>> index 01fbae5..7abb361 100644
>> --- a/kernel/stop_machine.c
>> +++ b/kernel/stop_machine.c
>> @@ -165,12 +165,13 @@ static void ack_state(struct multi_stop_data *msdata)
>> set_state(msdata, msdata->state + 1);
>> }
>>
>> +
>
> Why add a new line here?
Argh, a stray newline.. will remove it.
>
>> /* This is the cpu_stop function which stops the CPU. */
>> static int multi_cpu_stop(void *data)
>> {
>> struct multi_stop_data *msdata = data;
>> enum multi_stop_state curstate = MULTI_STOP_NONE;
>> - int cpu = smp_processor_id(), err = 0;
>> + int cpu = smp_processor_id(), num_active_cpus, err = 0;
>
> TYPE var0 = INIT0, var1, var2 = INIT2;
>
> looks kinda weird. Maybe collect initialized ones to one side or
> separate out uninitialized one to a separate declaration?
>
Yeah, now that you point out, it does look very odd. I don't
remember why I wrote it that way in the first place! :-(
I'll fix this in the next version. Thanks!
> Also, isn't nr_active_cpus more common way of naming it?
>
Sure, will use this convention.
>> unsigned long flags;
>> bool is_active;
>>
>> @@ -180,15 +181,38 @@ static int multi_cpu_stop(void *data)
>> */
>> local_save_flags(flags);
>>
>> - if (!msdata->active_cpus)
>> + if (!msdata->active_cpus) {
>> is_active = cpu == cpumask_first(cpu_online_mask);
>> - else
>> + num_active_cpus = 1;
>> + } else {
>> is_active = cpumask_test_cpu(cpu, msdata->active_cpus);
>> + num_active_cpus = cpumask_weight(msdata->active_cpus);
>> + }
>>
>> /* Simple state machine */
>> do {
>> /* Chill out and ensure we re-read multi_stop_state. */
>> cpu_relax();
>> +
>> + /*
>> + * In the case of CPU offline, we don't want the other CPUs to
>> + * send IPIs to the active_cpu (the one going offline) after it
>> + * has entered the _DISABLE_IRQ state (because, then it will
>> + * notice the IPIs only after it goes offline). So ensure that
>> + * the active_cpu always follows the others while entering
>> + * each subsequent state in this state-machine.
>> + *
>> + * msdata->thread_ack tracks the number of CPUs that are yet to
>> + * move to the next state, during each transition. So make the
>> + * active_cpu(s) wait until ->thread_ack indicates that the
>> + * active_cpus are the only ones left to complete the transition.
>> + */
>> + if (is_active) {
>> + /* Wait until all the non-active threads ack the state */
>> + while (atomic_read(&msdata->thread_ack) > num_active_cpus)
>> + cpu_relax();
>> + }
>
> Wouldn't it be cleaner to separate this out to a separate stage so
> that there are two separate DISABLE_IRQ stages - sth like
> MULTI_STOP_DISABLE_IRQ_INACTIVE and MULTI_STOP_DISABLE_IRQ_ACTIVE?
> The above adds an ad-hoc mechanism on top of the existing mechanism
> which is built to sequence similar things anyway.
>
Indeed, that looks like a much more elegant method! Thanks a lot for the
suggestion Tejun, I'll use that in the next version of the patchset.
Thank you!
Regards,
Srivatsa S. Bhat
prev parent reply other threads:[~2014-05-11 20:09 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-06 18:02 [PATCH 0/2] CPU hotplug: Fix the long-standing "IPI to offline CPU" issue Srivatsa S. Bhat
2014-05-06 18:02 ` [PATCH 1/2] smp: Print more useful debug info upon receiving IPI on an offline CPU Srivatsa S. Bhat
2014-05-06 20:34 ` Andrew Morton
2014-05-06 21:23 ` Srivatsa S. Bhat
2014-05-06 22:01 ` [PATCH v2 " Srivatsa S. Bhat
2014-05-06 18:03 ` [PATCH 2/2] CPU hotplug, stop-machine: Plug race-window that leads to "IPI-to-offline-CPU" Srivatsa S. Bhat
2014-05-06 20:40 ` Andrew Morton
2014-05-06 20:42 ` Tejun Heo
2014-05-06 21:27 ` Srivatsa S. Bhat
2014-05-06 22:01 ` [PATCH v2 " Srivatsa S. Bhat
2014-05-10 3:06 ` Tejun Heo
2014-05-11 20:07 ` Srivatsa S. Bhat [this message]
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=536FD89E.8030904@linux.vnet.ibm.com \
--to=srivatsa.bhat@linux.vnet.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=bp@suse.de \
--cc=ego@linux.vnet.ibm.com \
--cc=fweisbec@gmail.com \
--cc=hch@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mgalbraith@suse.de \
--cc=mgorman@suse.de \
--cc=mingo@kernel.org \
--cc=oleg@redhat.com \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peterz@infradead.org \
--cc=riel@redhat.com \
--cc=rjw@rjwysocki.net \
--cc=rostedt@goodmis.org \
--cc=rusty@rustcorp.com.au \
--cc=tglx@linutronix.de \
--cc=tj@kernel.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).