Skip to contentSkip to conversation

small migration thread fix

PATCH Erich Focht 2 participants 4 messages Jan 10, 2003

lore
Share & tools
lore
#0 lore raw

Hi,

the small patch fixes a potential problem in the migration thread for the case that the first CPU in the cpus_allowed mask of a process is offline. Please consider applying it to your trees.

Thanks!
Regards,
Erich

kernel/sched.c +1 -1
diff -urNp linux-2.5.55/kernel/sched.c linux-2.5.55-fix/kernel/sched.c
@@ -2108,7 +2108,7 @@ static int migration_thread(void * data)
 		spin_unlock_irqrestore(&rq->lock, flags);
 
 		p = req->task;
-		cpu_dest = __ffs(p->cpus_allowed);
+		cpu_dest = __ffs(p->cpus_allowed & cpu_online_map);
 		rq_dest = cpu_rq(cpu_dest);
 repeat:
 		cpu_src = task_cpu(p);
#1 lore raw
Quoted 3 lines · Erich Focht

the small patch fixes a potential problem in the migration thread for the case that the first CPU in the cpus_allowed mask of a process is offline. Please consider applying it to your trees.

I'm not mingo, but I can say this looks sane. My only question is whether there are more codepaths that need this kind of check, for instance, what happens if someone does set_cpus_allowed() to a cpumask with !(task->cpumask & cpu_online_map) ?

Thanks,
Bill

#2 lore raw
Quoted 4 lines · William Lee Irwin III

I'm not mingo, but I can say this looks sane. My only question is whether there are more codepaths that need this kind of check, for instance, what happens if someone does set_cpus_allowed() to a cpumask with !(task->cpumask & cpu_online_map) ?

The piece of code below was intended for that. I agree with Rusty's comment, BUG() is too strong for that case.

#if 0 /* FIXME: Grab cpu_lock, return error on this case. --RR */
	new_mask &= cpu_online_map;
	if (!new_mask)
		BUG();

#endif

Anyhow, changing the new_mask in this way is BAD, because the masks are inherited. So when more CPUs come online, they remain excluded from the mask of the process and it's children.

The fix suggested in the comments still has to be done...

Regards,
Erich

#3 lore raw
Quoted 4 lines · William Lee Irwin III
Quoted 4 lines

I'm not mingo, but I can say this looks sane. My only question is whether there are more codepaths that need this kind of check, for instance, what happens if someone does set_cpus_allowed() to a cpumask with !(task->cpumask & cpu_online_map) ?

Quoted 11 lines · Erich Focht

The piece of code below was intended for that. I agree with Rusty's comment, BUG() is too strong for that case.

#if 0 /* FIXME: Grab cpu_lock, return error on this case. --RR */
	new_mask &= cpu_online_map;
	if (!new_mask)
		BUG();

#endif
Anyhow, changing the new_mask in this way is BAD, because the masks are inherited. So when more CPUs come online, they remain excluded from the mask of the process and it's children.
The fix suggested in the comments still has to be done...

I don't have much to add but another ack and a "hmm, maybe something could be done". My prior comments stand. I'd be very much obliged if you provide a fix for the set_cpus_allowed() issue. I very much rely upon you now to provide scheduler fixes and optimizations for large scale and/or NUMA machines these days.

Thanks,
Bill