On Fri, Jun 27, 2008 at 09:38:05PM +0800, xialiang wrote:Quoting Bart Van Assche <bart.vanassche@xxxxxxxxx>:
On Fri, Jun 27, 2008 at 3:17 PM, 夏亮 <xiaiaxaxi@xxxxxxxxxxx> wrote:I am working on Intel Duo Core with Linux OS 2.6.21, and I'd like to
migrate task from one cpu to another cpu.
In SMP systems, load_balance() function uses move_tasks() to move processes
from source runqueue to local runqueue, but it does not move a currently
running task. If I want to migrate a currently running task from source
runqueue to local runqueue, how can I do? Any suggestion is preferred.
Are you familiar with the glibc pthread_setaffinity_np() function
and/or the sched_setaffinity() system call ?
Bart.
Yes. I know sched_setaffinity(), it sets cpu_mask of a task. I want to
use it in a timer interrupt( scheduler_tick() ), can I?
Don't use it from a timer handler. You can use migrate_task() to move the
task, but your email from a couple days ago said you wanted to move the
task at the head of the runqueue due to cpu heat or something like that.
That is a very imprecise way to move the task as any unfortunate task
that happens to be running when the timer tick occurs could get migrated,
not the one generating the work.
I think you really want to look at the other areas of the kernel which do
stuff like throttling the cpu. Just moving a task off the cpu does not
prevent it from being used for another compute intesive load. You could
take the cpu offline. I guess to do that, I would use schedule_work()
or kthread_create() to get out of the timer context and into a regular
thread context then take the cpu offline from there.
Good Luck,
Robin