* set_cpus_allowed() optimization
@ 2002-05-10 20:09 Mike Kravetz
2002-05-13 23:05 ` Robert Love
0 siblings, 1 reply; 2+ messages in thread
From: Mike Kravetz @ 2002-05-10 20:09 UTC (permalink / raw)
To: Ingo Molnar; +Cc: Robert Love, linux-kernel
Please consider the following optimization to set_cpus_allowed().
In the case where the task does not reside on a runqueue, is it
not safe/sufficient to simply set the task's cpu field? This
would avoid scheduling the migration thread to perform the task.
Previously, set_cpus_allowed() was always called for a task that
resides on a runqueue. With the introduction of the 'cpu affinity'
system calls, this is no longer the case.
Does this seem reasonable?
A patch for 2.5.15 is included below.
--
Mike
diff -Naur linux-2.5.15/kernel/sched.c linux-2.5.15-sca/kernel/sched.c
--- linux-2.5.15/kernel/sched.c Thu May 9 22:22:53 2002
+++ linux-2.5.15-sca/kernel/sched.c Fri May 10 19:51:58 2002
@@ -1670,13 +1670,22 @@
rq = task_rq_lock(p, &flags);
p->cpus_allowed = new_mask;
/*
- * Can the task run on the task's current CPU? If not then
- * migrate the process off to a proper CPU.
+ * Can the task run on the task's current CPU?
+ * If yes, we are done.
*/
if (new_mask & (1UL << p->thread_info->cpu)) {
task_rq_unlock(rq, &flags);
goto out;
}
+ /*
+ * If the task is not on a runqueue, then it is safe to
+ * simply update the task's cpu field.
+ */
+ if (!p->array) {
+ p->thread_info->cpu = __ffs(p->cpus_allowed);
+ task_rq_unlock(rq, &flags);
+ goto out;
+ }
init_MUTEX_LOCKED(&req.sem);
req.task = p;
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: set_cpus_allowed() optimization
2002-05-10 20:09 set_cpus_allowed() optimization Mike Kravetz
@ 2002-05-13 23:05 ` Robert Love
0 siblings, 0 replies; 2+ messages in thread
From: Robert Love @ 2002-05-13 23:05 UTC (permalink / raw)
To: Mike Kravetz; +Cc: Ingo Molnar, linux-kernel
n Fri, 2002-05-10 at 13:09, Mike Kravetz wrote:
> Please consider the following optimization to set_cpus_allowed().
> In the case where the task does not reside on a runqueue, is it
> not safe/sufficient to simply set the task's cpu field? This
> would avoid scheduling the migration thread to perform the task.
>
> Previously, set_cpus_allowed() was always called for a task that
> resides on a runqueue. With the introduction of the 'cpu affinity'
> system calls, this is no longer the case.
I like! I agree, if the task is not runnable then it should be
sufficient to just set task->cpu as when it is activated it will be put
into the runqueue based on ->cpu.
There was a chance even without the CPU affinity runqueues a process
would dequeue before set_cpus_allowed returned. Look at the case in
migration_thread where exactly what your patch does is done. If !array,
then the code just sets task->cpu and returns.
Ingo? Good?
Robert Love
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-05-13 23:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-05-10 20:09 set_cpus_allowed() optimization Mike Kravetz
2002-05-13 23:05 ` Robert Love
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox