linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Question about sched_setaffinity()
@ 2019-04-27 18:02 Paul E. McKenney
  2019-04-30 10:03 ` Peter Zijlstra
  0 siblings, 1 reply; 24+ messages in thread
From: Paul E. McKenney @ 2019-04-27 18:02 UTC (permalink / raw)
  To: peterz; +Cc: linux-kernel, andrea.parri

Hello, Peter!

TL;DR: If a normal !PF_NO_SETAFFINITY kthread invokes sched_setaffinity(),
and sched_setaffinity() returns 0, is it expected behavior for that
kthread to be running on some CPU other than one of the ones specified by
the in_mask argument?  All CPUs are online, and there is no CPU-hotplug
activity taking place.

							Thanx, Paul

Details:

I have long showed the following "toy" synchronize_rcu() implementation:

	void synchronize_rcu(void)
	{
		int cpu;

		for_each_online_cpu(cpu)
			run_on(cpu);
	}

I decided that if I was going to show it, I should test it.  And it
occurred to me that run_on() can be a call to sched_setaffinity():

	void synchronize_rcu(void)
	{
		int cpu;

		for_each_online_cpu(cpu)
			sched_setaffinity(current->pid, cpumask_of(cpu));
	}

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.  So I tried this hack:

	void synchronize_rcu(void)
	{
		int cpu;

		for_each_online_cpu(cpu) {
			while (raw_smp_processor_id() != cpu)
				sched_setaffinity(current->pid, cpumask_of(cpu));
			WARN_ON_ONCE(raw_smp_processor_id() != cpu);
		}
	}

This never triggers, and rcutorture's grace-period rate is not significantly
affected.

Is this expected behavior?  Is there some configuration or setup that I
might be missing?


^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2019-05-13 15:53 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-27 18:02 Question about sched_setaffinity() Paul E. McKenney
2019-04-30 10:03 ` Peter Zijlstra
2019-04-30 10:51   ` Paul E. McKenney
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

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