45 lines
1.2 KiB
C
45 lines
1.2 KiB
C
#include "linux/sched.h"
|
|
|
|
#include <linux/version.h>
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,21)
|
|
|
|
#ifdef CONFIG_SMP
|
|
/**
|
|
* set_cpus_allowed() - change a given task's processor affinity
|
|
* @p: task to bind
|
|
* @new_mask: bitmask of allowed processors
|
|
*
|
|
* Upon return, the task is running on a legal processor. Note the caller
|
|
* must have a valid reference to the task: it must not exit() prematurely.
|
|
* This call can sleep; do not hold locks on call.
|
|
*/
|
|
void set_cpus_allowed(struct task_struct *p, unsigned long new_mask)
|
|
{
|
|
new_mask &= cpu_online_map;
|
|
BUG_ON(!new_mask);
|
|
|
|
p->cpus_allowed = new_mask;
|
|
|
|
/*
|
|
* If the task is on a no-longer-allowed processor, we need to move
|
|
* it. If the task is not current, then set need_resched and send
|
|
* its processor an IPI to reschedule.
|
|
*/
|
|
if (!(p->cpus_runnable & p->cpus_allowed)) {
|
|
if (p != current) {
|
|
p->need_resched = 1;
|
|
smp_send_reschedule(p->processor);
|
|
}
|
|
/*
|
|
* Wait until we are on a legal processor. If the task is
|
|
* current, then we should be on a legal processor the next
|
|
* time we reschedule. Otherwise, we need to wait for the IPI.
|
|
*/
|
|
while (!(p->cpus_runnable & p->cpus_allowed))
|
|
schedule();
|
|
}
|
|
}
|
|
#endif
|
|
|
|
#endif /* kernel < 2.4.21 */
|