* How can I migrate a currently running task?
@ 2008-06-27 13:17 夏亮
2008-06-27 13:25 ` Bart Van Assche
2008-06-27 14:27 ` Dmitry Adamushko
0 siblings, 2 replies; 7+ messages in thread
From: 夏亮 @ 2008-06-27 13:17 UTC (permalink / raw)
To: linux-kernel
Hi,
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. Thanks!
Liang
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How can I migrate a currently running task?
2008-06-27 13:17 How can I migrate a currently running task? 夏亮
@ 2008-06-27 13:25 ` Bart Van Assche
2008-06-27 13:38 ` xialiang
2008-06-27 14:27 ` Dmitry Adamushko
1 sibling, 1 reply; 7+ messages in thread
From: Bart Van Assche @ 2008-06-27 13:25 UTC (permalink / raw)
To: 夏亮; +Cc: linux-kernel
On Fri, Jun 27, 2008 at 3:17 PM, 夏亮 <xiaiaxaxi@sjtu.edu.cn> 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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How can I migrate a currently running task?
2008-06-27 13:25 ` Bart Van Assche
@ 2008-06-27 13:38 ` xialiang
2008-06-27 18:48 ` Robin Holt
0 siblings, 1 reply; 7+ messages in thread
From: xialiang @ 2008-06-27 13:38 UTC (permalink / raw)
To: Bart Van Assche; +Cc: linux-kernel
Quoting Bart Van Assche <bart.vanassche@gmail.com>:
> On Fri, Jun 27, 2008 at 3:17 PM, 夏亮 <xiaiaxaxi@sjtu.edu.cn> 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?
I use sched_getaffinity() in a timer interrupt, but it doesn't work.As
following,
scheduler_tick()
{
every 100ms, balance();
}
static int balance(void)
{
Get temperature of two cpus.
int ret;
cpumask_t mask;
If(one cpu is much hotter than another one){
ret = sched_getaffinity(rq->curr->pid, &mask);
}
}
If I comment sched_getaffinity, it works well.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How can I migrate a currently running task?
2008-06-27 13:17 How can I migrate a currently running task? 夏亮
2008-06-27 13:25 ` Bart Van Assche
@ 2008-06-27 14:27 ` Dmitry Adamushko
1 sibling, 0 replies; 7+ messages in thread
From: Dmitry Adamushko @ 2008-06-27 14:27 UTC (permalink / raw)
To: 夏亮; +Cc: linux-kernel
2008/6/27 夏亮 <xiaiaxaxi@sjtu.edu.cn>:
> Hi,
>
> 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.
> Thanks!
Some high-prio task takes away CPU from a 'target' task and then
pushes it onto another CPU. That's what 'migration_thread' does.
Take a look at use-cases of migrate_task() in sched.c.
>
> Liang
>
--
Best regards,
Dmitry Adamushko
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How can I migrate a currently running task?
2008-06-27 13:38 ` xialiang
@ 2008-06-27 18:48 ` Robin Holt
2008-06-28 4:05 ` xialiang
0 siblings, 1 reply; 7+ messages in thread
From: Robin Holt @ 2008-06-27 18:48 UTC (permalink / raw)
To: xialiang; +Cc: Bart Van Assche, linux-kernel
On Fri, Jun 27, 2008 at 09:38:05PM +0800, xialiang wrote:
> Quoting Bart Van Assche <bart.vanassche@gmail.com>:
>
>> On Fri, Jun 27, 2008 at 3:17 PM, 夏亮 <xiaiaxaxi@sjtu.edu.cn> 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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How can I migrate a currently running task?
2008-06-27 18:48 ` Robin Holt
@ 2008-06-28 4:05 ` xialiang
2008-06-28 7:55 ` Peter Zijlstra
0 siblings, 1 reply; 7+ messages in thread
From: xialiang @ 2008-06-28 4:05 UTC (permalink / raw)
To: Robin Holt; +Cc: Bart Van Assche, linux-kernel
Quoting Robin Holt <holt@sgi.com>:
> On Fri, Jun 27, 2008 at 09:38:05PM +0800, xialiang wrote:
>> Quoting Bart Van Assche <bart.vanassche@gmail.com>:
>>
>>> On Fri, Jun 27, 2008 at 3:17 PM, 夏亮 <xiaiaxaxi@sjtu.edu.cn> 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
>
I would move a task at the head of the runqueue, but I already
know which task creates the heat. I get the profile of tasks
beforehand. So if I find the temperature of a cpu is much higher than
that of the other, and coincidentally the currently running task of
the cpu is what I want to migrate. Can I migrate it in the
scheduler_tick()? Or where should I put the migration code? Thanks!
Best regards,
Liang
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How can I migrate a currently running task?
2008-06-28 4:05 ` xialiang
@ 2008-06-28 7:55 ` Peter Zijlstra
0 siblings, 0 replies; 7+ messages in thread
From: Peter Zijlstra @ 2008-06-28 7:55 UTC (permalink / raw)
To: xialiang; +Cc: Robin Holt, Bart Van Assche, linux-kernel
On Sat, 2008-06-28 at 12:05 +0800, xialiang wrote:
> Quoting Robin Holt <holt@sgi.com>:
>
> > On Fri, Jun 27, 2008 at 09:38:05PM +0800, xialiang wrote:
> >> Quoting Bart Van Assche <bart.vanassche@gmail.com>:
> >>
> >>> On Fri, Jun 27, 2008 at 3:17 PM, 夏亮 <xiaiaxaxi@sjtu.edu.cn> 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
> >
>
> I would move a task at the head of the runqueue, but I already
> know which task creates the heat. I get the profile of tasks
> beforehand. So if I find the temperature of a cpu is much higher than
> that of the other, and coincidentally the currently running task of
> the cpu is what I want to migrate. Can I migrate it in the
> scheduler_tick()?
No, you cannot migrate current from hardirq context.
> Or where should I put the migration code? Thanks!
If you want to balance temperature, the best place would be the load
balancer.
Just don't wreck all the other balance conditions.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2008-06-28 7:55 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-06-27 13:17 How can I migrate a currently running task? 夏亮
2008-06-27 13:25 ` Bart Van Assche
2008-06-27 13:38 ` xialiang
2008-06-27 18:48 ` Robin Holt
2008-06-28 4:05 ` xialiang
2008-06-28 7:55 ` Peter Zijlstra
2008-06-27 14:27 ` Dmitry Adamushko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®