All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vincent Guittot <vincent.guittot@linaro.org>
To: Frederic Weisbecker <fweisbec@gmail.com>
Cc: linux-kernel@vger.kernel.org, linaro-dev@lists.linaro.org,
	peterz@infradead.org, mingo@kernel.org,
	Mike Galbraith <efault@gmx.de>,
	Steven Rostedt <rostedt@goodmis.org>
Subject: Re: [PATCH v2 1/2] sched: fix init NOHZ_IDLE flag
Date: Tue, 19 Feb 2013 11:56:54 +0100	[thread overview]
Message-ID: <CAKfTPtAfBq04b6e_y2e2PQGsoDg2e_Em=x9-kF+k1QL9pgjL-g@mail.gmail.com> (raw)
In-Reply-To: <CAKfTPtCCS2ACCco-eQUtKO4ZF4ybBMCEmOzFKMThZTE=Cw19Ng@mail.gmail.com>

On 19 February 2013 11:29, Vincent Guittot <vincent.guittot@linaro.org> wrote:
> On 18 February 2013 16:40, Frederic Weisbecker <fweisbec@gmail.com> wrote:
>> 2013/2/18 Vincent Guittot <vincent.guittot@linaro.org>:
>>> On 18 February 2013 15:38, Frederic Weisbecker <fweisbec@gmail.com> wrote:
>>>> I pasted the original at: http://pastebin.com/DMm5U8J8
>>>
>>> We can clear the idle flag only in the nohz_kick_needed which will not
>>> be called if the sched_domain is NULL so the sequence will be
>>>
>>> = CPU 0 =                                            = CPU 1=
>>>
>>> detach_and_destroy_domain {
>>>             rcu_assign_pointer(cpu1_dom, NULL);
>>> }
>>>
>>> dom = new_domain(...) {
>>>              nr_cpus_busy = 0;
>>>              set_idle(CPU 1);
>>> }
>>>                                                     dom =
>>> rcu_dereference(cpu1_dom)
>>>                                                     //dom == NULL, return
>>>
>>> rcu_assign_pointer(cpu1_dom, dom);
>>>
>>>                                                     dom =
>>> rcu_dereference(cpu1_dom)
>>>                                                     //dom != NULL,
>>>                                                     nohz_kick_needed {
>>>
>>> set_idle(CPU 1)
>>>                                                                    dom
>>> = rcu_dereference(cpu1_dom)
>>>
>>> //dec nr_cpus_busy,
>>>                                                     }
>>>
>>> Vincent
>>
>> Ok but CPU 0 can assign NULL to the domain of cpu1 while CPU 1 is
>> already in the middle of nohz_kick_needed().
>
> Yes nothing prevents the sequence below to occur
>
> = CPU 0 =                                            = CPU 1=
>                                                     dom =
> rcu_dereference(cpu1_dom)
>                                                     //dom != NULL
> detach_and_destroy_domain {
>             rcu_assign_pointer(cpu1_dom, NULL);
> }
>
> dom = new_domain(...) {
>              nr_cpus_busy = 0;
>              //nr_cpus_busy in the new_dom
>              set_idle(CPU 1);
> }
>                                                     nohz_kick_needed {
>                                                              clear_idle(CPU 1)
>                                                              dom =
> rcu_dereference(cpu1_dom)
>
> //cpu1_dom == old_dom
>                                                              inc nr_cpus_busy,
>
> //nr_cpus_busy in the old_dom
>                                                     }
>
> rcu_assign_pointer(cpu1_dom, dom);
> //cpu1_dom == new_dom

The sequence above is not correct in addition to become unreadable
after going through gmail

The correct and readable version
https://pastebin.linaro.org/1750/

Vincent

>
> I'm not sure that this can happen in practice because CPU1 is in
> interrupt handler but we don't have any mechanism to prevent the
> sequence.
>
> The NULL sched_domain can be used to detect this situation and the
> set_cpu_sd_state_busy function can be modified like below
>
> inline void set_cpu_sd_state_busy
>  {
>         struct sched_domain *sd;
>         int cpu = smp_processor_id();
> +       int clear = 0;
>
>         if (!test_bit(NOHZ_IDLE, nohz_flags(cpu)))
>                 return;
> -       clear_bit(NOHZ_IDLE, nohz_flags(cpu));
>
>         rcu_read_lock();
>         for_each_domain(cpu, sd) {
>                 atomic_inc(&sd->groups->sgp->nr_busy_cpus);
> +               clear = 1;
>         }
>         rcu_read_unlock();
> +
> +       if (likely(clear))
> +               clear_bit(NOHZ_IDLE, nohz_flags(cpu));
>  }
>
> The NOHZ_IDLE flag will not be clear if we have a NULL sched_domain
> attached to the CPU.
> With this implementation, we still don't need to get the sched_domain
> for testing the NOHZ_IDLE flag which occurs each time CPU becomes idle
>
> The patch 2 become useless
>
> Vincent

  reply	other threads:[~2013-02-19 10:56 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-29 10:38 [PATCH v2 0/2] sched: fix nr_busy_cpus Vincent Guittot
2013-01-29 10:38 ` [PATCH v2 1/2] sched: fix init NOHZ_IDLE flag Vincent Guittot
2013-02-01 18:03   ` Frederic Weisbecker
2013-02-04  9:09     ` Vincent Guittot
2013-02-08 15:35       ` Frederic Weisbecker
2013-02-08 17:09         ` Vincent Guittot
2013-02-18 14:33           ` Frederic Weisbecker
2013-02-18 14:38             ` Frederic Weisbecker
2013-02-18 15:06               ` Vincent Guittot
2013-02-18 15:40                 ` Frederic Weisbecker
2013-02-19 10:29                   ` Vincent Guittot
2013-02-19 10:56                     ` Vincent Guittot [this message]
2013-01-29 10:39 ` [PATCH v2 2/2] sched: fix update " Vincent Guittot

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='CAKfTPtAfBq04b6e_y2e2PQGsoDg2e_Em=x9-kF+k1QL9pgjL-g@mail.gmail.com' \
    --to=vincent.guittot@linaro.org \
    --cc=efault@gmx.de \
    --cc=fweisbec@gmail.com \
    --cc=linaro-dev@lists.linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.