forked from TencentOS/TencentOS-kernel
sched/rt: optimize checking group rt scheduler constraints
from upstream commit b4fb015eeff7f3e5518a7dbe806 Signed-off-by: Chen Xiaoguang <xiaoggchen@tencent.com>
This commit is contained in:
parent
d244f95696
commit
38eea51b40
|
|
@ -2389,7 +2389,9 @@ static DEFINE_MUTEX(rt_constraints_mutex);
|
|||
/* Must be called with tasklist_lock held */
|
||||
static inline int tg_has_rt_tasks(struct task_group *tg)
|
||||
{
|
||||
struct task_struct *g, *p;
|
||||
struct task_struct *task;
|
||||
struct css_task_iter it;
|
||||
int ret = 0;
|
||||
|
||||
/*
|
||||
* Autogroups do not have RT tasks; see autogroup_create().
|
||||
|
|
@ -2397,12 +2399,12 @@ static inline int tg_has_rt_tasks(struct task_group *tg)
|
|||
if (task_group_is_autogroup(tg))
|
||||
return 0;
|
||||
|
||||
for_each_process_thread(g, p) {
|
||||
if (rt_task(p) && task_group(p) == tg)
|
||||
return 1;
|
||||
}
|
||||
css_task_iter_start(&tg->css, 0, &it);
|
||||
while (!ret && (task = css_task_iter_next(&it)))
|
||||
ret |= rt_task(task);
|
||||
css_task_iter_end(&it);
|
||||
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct rt_schedulable_data {
|
||||
|
|
@ -2435,7 +2437,8 @@ static int tg_rt_schedulable(struct task_group *tg, void *data)
|
|||
/*
|
||||
* Ensure we don't starve existing RT tasks.
|
||||
*/
|
||||
if (rt_bandwidth_enabled() && !runtime && tg_has_rt_tasks(tg))
|
||||
if (rt_bandwidth_enabled() && !runtime &&
|
||||
tg->rt_bandwidth.rt_runtime && tg_has_rt_tasks(tg))
|
||||
return -EBUSY;
|
||||
|
||||
total = to_ratio(period, runtime);
|
||||
|
|
@ -2501,7 +2504,6 @@ static int tg_set_rt_bandwidth(struct task_group *tg,
|
|||
return -EINVAL;
|
||||
|
||||
mutex_lock(&rt_constraints_mutex);
|
||||
read_lock(&tasklist_lock);
|
||||
err = __rt_schedulable(tg, rt_period, rt_runtime);
|
||||
if (err)
|
||||
goto unlock;
|
||||
|
|
@ -2519,7 +2521,6 @@ static int tg_set_rt_bandwidth(struct task_group *tg,
|
|||
}
|
||||
raw_spin_unlock_irq(&tg->rt_bandwidth.rt_runtime_lock);
|
||||
unlock:
|
||||
read_unlock(&tasklist_lock);
|
||||
mutex_unlock(&rt_constraints_mutex);
|
||||
|
||||
return err;
|
||||
|
|
@ -2573,9 +2574,7 @@ static int sched_rt_global_constraints(void)
|
|||
int ret = 0;
|
||||
|
||||
mutex_lock(&rt_constraints_mutex);
|
||||
read_lock(&tasklist_lock);
|
||||
ret = __rt_schedulable(NULL, 0, 0);
|
||||
read_unlock(&tasklist_lock);
|
||||
mutex_unlock(&rt_constraints_mutex);
|
||||
|
||||
return ret;
|
||||
|
|
|
|||
Loading…
Reference in New Issue