All of lore.kernel.org
 help / color / mirror / Atom feed
From: Max Krasnyanskiy <maxk@qualcomm.com>
To: David Rientjes <rientjes@google.com>
Cc: Paul Jackson <pj@sgi.com>,
	mingo@elte.hu, peterz@infradead.org, menage@google.com,
	linux-kernel@vger.kernel.org, Oleg Nesterov <oleg@tv-sign.ru>
Subject: Re: [patch] sched: prevent bound kthreads from changing cpus_allowed
Date: Mon, 09 Jun 2008 13:59:25 -0700	[thread overview]
Message-ID: <484D99AD.4000306@qualcomm.com> (raw)
In-Reply-To: <alpine.DEB.1.10.0806051357480.32537@chino.kir.corp.google.com>

David Rientjes wrote:
>>  2) Sometimes calls to kthread_bind are binding to any online cpu, such as in:
>>
>> 	drivers/infiniband/hw/ehca/ehca_irq.c:	kthread_bind(cct->task, any_online_cpu(cpu_online_map));
>>
>>     In such cases, the PF_THREAD_BOUND seems inappropriate.  The caller of
>>     kthread_bind() really doesn't seem to care where that thread is bound;
>>     they just want it on a CPU that is still online.
>>
> 
> This particular case is simply moving the thread to any online cpu so that 
> it survives long enough for the subsequent kthread_stop() in 
> destroy_comp_task().  So I don't see a problem with this instance.
> 
> A caller to kthread_bind() can always remove PF_THREAD_BOUND itself upon 
> return, but I haven't found any cases in the tree where that is currently 
> necessary.  And doing that would defeat the semantics of kthread_bind() 
> where these threads are supposed to be bound to a specific cpu and not 
> allowed to run on others.

Actually I have another use case here. Above example in particular may be ok 
but it does demonstrate the issue nicely. Which is that in some cases kthreads 
are bound to a CPU but do not have a strict "must run here" requirement and 
could be moved if needed.
For example I need an ability to move workqueue threads. Workqueue threads do 
kthread_bind().
So how about we add something like kthread_bind_strict() which  would set 
PF_THREAD_BOUND ?
We could also simply add flags argument to the kthread_bind() which would be 
better imo but requires more changes. ie It'd look like
	kthread_bind(..., cpu, KTHREAD_BIND_STRICT);

Things like migration threads, stop machine, etc would use the strict version 
and everything else would use non-strict bind.

---
On the related note (this seems like the right crowd :). What do people think 
about kthreads and cpusets in general. We currently have a bit of a disconnect 
in the logic.
1. kthreads can be put into a cpuset at which point their cpus_allowed mask is 
updated properly
2. kthread's cpus_allowed mask is updated properly when cpuset setup changes 
(cpus added, removed, etc).
3. kthreads inherit cpuset from a parent (kthreadd for example) _but_  they 
either do kthread_bind() or set_cpus_allowed() and both of those simply ignore 
inherited cpusets.

Notice how scenario #3 does not fit into the overall picture. The behaviour is 
inconsistent.
How about this:
- Split sched_setaffinity into

	sched_setaffinity()
	{
		task *p = get_task_by_pid();
		return task_setaffinity(p);
	}

	task_setaffinity(task, cpumask, flags)
	{
		if (flags & FORCE) {
			// Used for kthreads that require strict binding.
			// Detach the task from the current cpuset
			// and put it into the root cpuset.
   			// Set PF_THREAD_BOUND.
		}

		// Rest of the original sched_setaffinity logic
	}

- Have kthreads call task_setaffinity() instead of set_cpus_allowed() directly.
That way the behaviour will be consistent across the board.

Comments ?

Max


  reply	other threads:[~2008-06-09 20:59 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-05 19:57 [patch] sched: prevent bound kthreads from changing cpus_allowed David Rientjes
2008-06-05 20:29 ` Paul Jackson
2008-06-05 21:12   ` David Rientjes
2008-06-09 20:59     ` Max Krasnyanskiy [this message]
2008-06-09 22:07       ` David Rientjes
2008-06-10  4:23         ` Max Krasnyansky
2008-06-10 17:04           ` David Rientjes
2008-06-10 16:30         ` cpusets and kthreads, inconsistent behaviour Max Krasnyansky
2008-06-10 18:47           ` David Rientjes
2008-06-10 20:44             ` Max Krasnyansky
2008-06-10 20:54               ` David Rientjes
2008-06-10 21:15                 ` Max Krasnyansky
2008-06-10  6:44       ` [patch] sched: prevent bound kthreads from changing cpus_allowed Peter Zijlstra
2008-06-10 15:38         ` Max Krasnyansky
2008-06-10 17:00           ` Oleg Nesterov
2008-06-10 17:19             ` Peter Zijlstra
2008-06-10 20:24               ` workqueue cpu affinity Max Krasnyansky
2008-06-11  6:49                 ` Peter Zijlstra
2008-06-11 19:02                   ` Max Krasnyansky
2008-06-12 18:44                     ` Peter Zijlstra
2008-06-12 19:10                       ` Max Krasnyanskiy
2008-06-11 16:08                 ` Oleg Nesterov
2008-06-11 19:21                   ` Max Krasnyansky
2008-06-11 19:21                   ` Max Krasnyansky
2008-06-12 16:35                     ` Oleg Nesterov
2008-06-11 20:44                   ` Max Krasnyansky
2008-06-10 18:00             ` [patch] sched: prevent bound kthreads from changing cpus_allowed Max Krasnyansky
2008-06-05 20:52 ` Daniel Walker
2008-06-05 21:47 ` Paul Jackson
2008-06-10 10:28 ` Ingo Molnar
2008-06-10 17:47 ` Oleg Nesterov

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=484D99AD.4000306@qualcomm.com \
    --to=maxk@qualcomm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=menage@google.com \
    --cc=mingo@elte.hu \
    --cc=oleg@tv-sign.ru \
    --cc=peterz@infradead.org \
    --cc=pj@sgi.com \
    --cc=rientjes@google.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 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.