lkml.org 
[lkml]   [2009]   [Oct]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Date
SubjectBug when changing cpus_allowed of RT tasks?
I think there's a problem when balancing RT tasks: both find_lowest_rq_rt and
select_task_rq_rt check for p->rt.nr_cpus_allowed being greater than 1 to wake
a task in another cpu:

static int select_task_rq_rt(struct task_struct *p, int sd_flag, int flags)
{
[...]
if (unlikely(rt_task(rq->curr)) &&
(p->rt.nr_cpus_allowed > 1)) {
int cpu = find_lowest_rq(p);

return (cpu == -1) ? task_cpu(p) : cpu;
}
[...]
}

static int find_lowest_rq(struct task_struct *task)
{
struct sched_domain *sd;
struct cpumask *lowest_mask = __get_cpu_var(local_cpu_mask);
int this_cpu = smp_processor_id();
int cpu = task_cpu(task);
cpumask_var_t domain_mask;

if (task->rt.nr_cpus_allowed == 1)
return -1; /* No other targets possible */
[...]
}


What happens if rt.nr_cpus_allowed continues to be 1, but the allowed cpu is
not the one in which task is being woken up? Since set_cpus_allowed_rt just
changed the mask and updated the value of nr_cpus_allowed_rt, as far as I can
see, it remains on same CPU even if the new mask does not allow.

A possible fix below, and in case it is right:
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>



Lucas De Marchi


--

diff --git a/kernel/sched_rt.c b/kernel/sched_rt.c
index a4d790c..531c946 100644
--- a/kernel/sched_rt.c
+++ b/kernel/sched_rt.c
@@ -962,8 +962,7 @@ static int select_task_rq_rt(struct task_struct
*p, int sd_flag, int flags)
* that is just being woken and probably will have
* cold cache anyway.
*/
- if (unlikely(rt_task(rq->curr)) &&
- (p->rt.nr_cpus_allowed > 1)) {
+ if (unlikely(rt_task(rq->curr))) {
int cpu = find_lowest_rq(p);

return (cpu == -1) ? task_cpu(p) : cpu;
@@ -1177,7 +1176,8 @@ static int find_lowest_rq(struct task_struct *task)
int cpu = task_cpu(task);
cpumask_var_t domain_mask;

- if (task->rt.nr_cpus_allowed == 1)
+ if ((task->rt.nr_cpus_allowed == 1) &&
+ likely(cpumask_test_cpu(cpu, &task->cpus_allowed)))
return -1; /* No other targets possible */

if (!cpupri_find(&task_rq(task)->rd->cpupri, task, lowest_mask))

\
 
 \ /
  Last update: 2009-10-26 17:13    [W:0.020 / U:0.408 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site