LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.ibm.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: linux-kernel@vger.kernel.org, andrea.parri@amarulasolutions.com
Subject: Re: Question about sched_setaffinity()
Date: Tue, 30 Apr 2019 03:51:30 -0700	[thread overview]
Message-ID: <20190430105129.GA3923@linux.ibm.com> (raw)
In-Reply-To: <20190430100318.GP2623@hirez.programming.kicks-ass.net>

On Tue, Apr 30, 2019 at 12:03:18PM +0200, Peter Zijlstra wrote:
> On Sat, Apr 27, 2019 at 11:02:46AM -0700, Paul E. McKenney wrote:
> 
> > This actually passes rcutorture.  But, as Andrea noted, not klitmus.
> > After some investigation, it turned out that klitmus was creating kthreads
> > with PF_NO_SETAFFINITY, hence the failures.  But that prompted me to
> > put checks into my code: After all, rcutorture can be fooled.
> > 
> > 	void synchronize_rcu(void)
> > 	{
> > 		int cpu;
> > 
> > 		for_each_online_cpu(cpu) {
> > 			sched_setaffinity(current->pid, cpumask_of(cpu));
> > 			WARN_ON_ONCE(raw_smp_processor_id() != cpu);
> > 		}
> > 	}
> > 
> > This triggers fairly quickly, usually in less than a minute of rcutorture
> > testing.
> >
> > And further investigation shows that sched_setaffinity()
> > always returned 0. 
> 
> > Is this expected behavior?  Is there some configuration or setup that I
> > might be missing?
> 
> ISTR there is hotplug involved in RCU torture? In that case, it can be
> sched_setaffinity() succeeds to place us on a CPU, which CPU hotplug
> then takes away. So when we run the WARN thingy, we'll be running on a
> different CPU than expected.

There can be CPU hotplug involved in rcutorture, but it was disabled
during this run.

> If OTOH, your loop is written like (as it really should be):
> 
> 	void synchronize_rcu(void)
> 	{
> 		int cpu;
> 
> 		cpus_read_lock();
> 		for_each_online_cpu(cpu) {
> 			sched_setaffinity(current->pid, cpumask_of(cpu));
> 			WARN_ON_ONCE(raw_smp_processor_id() != cpu);
> 		}
> 		cpus_read_unlock();
> 	}
> 
> Then I'm not entirely sure how we can return 0 and not run on the
> expected CPU. If we look at __set_cpus_allowed_ptr(), the only paths out
> to 0 are:
> 
>  - if the mask didn't change
>  - if we already run inside the new mask
>  - if we migrated ourself with the stop-task
>  - if we're not in fact running
> 
> That last case should never trigger in your circumstances, since @p ==
> current and current is obviously running. But for completeness, the
> wakeup of @p would do the task placement in that case.

Are there some diagnostics I could add that would help track this down,
be it my bug or yours?

							Thanx, Paul

  reply	other threads:[~2019-04-30 10:51 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-27 18:02 Paul E. McKenney
2019-04-30 10:03 ` Peter Zijlstra
2019-04-30 10:51   ` Paul E. McKenney [this message]
2019-04-30 11:55     ` Peter Zijlstra
2019-05-01 19:12       ` Paul E. McKenney
2019-05-01 19:16         ` Steven Rostedt
2019-05-01 20:27           ` Paul E. McKenney
2019-05-07 22:16             ` Paul E. McKenney
2019-05-09 17:36               ` Paul E. McKenney
2019-05-09 19:36                 ` Paul E. McKenney
2019-05-10 12:08                   ` Peter Zijlstra
2019-05-10 23:07                     ` Paul E. McKenney
2019-05-11 21:45                       ` Andrea Parri
2019-05-12  0:39                         ` Paul E. McKenney
2019-05-12  1:05                           ` Andrea Parri
2019-05-13 12:20                             ` Paul E. McKenney
2019-05-13 15:37                               ` Joel Fernandes
2019-05-13 15:53                                 ` Paul E. McKenney
2019-05-13  8:10                       ` Peter Zijlstra
2019-05-13 12:19                         ` Paul E. McKenney
2019-05-09 21:40                 ` Andrea Parri
2019-05-09 21:56                   ` Andrea Parri
2019-05-09 22:17                     ` Paul E. McKenney
2019-05-10  6:32                       ` Andrea Parri

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=20190430105129.GA3923@linux.ibm.com \
    --to=paulmck@linux.ibm.com \
    --cc=andrea.parri@amarulasolutions.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --subject='Re: Question about sched_setaffinity()' \
    /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

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