Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752071AbbBGHCX (ORCPT ); Sat, 7 Feb 2015 02:02:23 -0500 Received: from szxga03-in.huawei.com ([119.145.14.66]:58831 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751293AbbBGHCW (ORCPT ); Sat, 7 Feb 2015 02:02:22 -0500 Message-ID: <54D5B873.5030208@huawei.com> Date: Sat, 7 Feb 2015 15:02:11 +0800 From: Zefan Li User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 MIME-Version: 1.0 To: Peter Zijlstra CC: Ingo Molnar , Mike Galbraith , LKML , Stefan Bader Subject: Re: [PATCH] sched, autogroup: Fix failure when writing to cpu.rt_runtime_us References: <54D32AD4.1060003@huawei.com> <20150205142527.GI5029@twins.programming.kicks-ass.net> <54D4194B.2040808@huawei.com> <20150206105840.GJ23123@twins.programming.kicks-ass.net> In-Reply-To: <20150206105840.GJ23123@twins.programming.kicks-ass.net> X-Enigmail-Version: 1.6 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.18.230] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020202.54D5B87B.02BE,ss=1,re=0.001,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 7999d41c02a923edf457995afbfb2456 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3717 Lines: 117 >> See this commit: >> >> commit f44937718ce3b8360f72f6c68c9481712517a867 >> Author: Mike Galbraith >> Date: Thu Jan 13 04:54:50 2011 +0100 >> >> sched, autogroup: Fix CONFIG_RT_GROUP_SCHED sched_setscheduler() failure >> ... >> + /* >> + * Autogroup RT tasks are redirected to the root task group >> ... >> + * the policy change to proceed. Thereafter, task_group() >> + * returns &root_task_group, ... >> + */ > > That comment is misleading; if you look at the actual code what we do is > redirect RT programs to _run_ in the root_task_group, but their > task_group() should still be autogroup. > > Otherwise people could escape their cgroup by switching to and from a RT > class. > Before 8323f26ce342 "sched: Fix race in task_group()", task_group() of those RT tasks always return root_task_group, but the escape can't happen. After commit 8323f26ce342, task_group always return root_task_group except for the case I showed: 1. Change scheduling policy before setsid(): # cat /proc/sched_debug | grep test R test 4194 24851.893077 945 120 24851.893077 11196.482331 0.000000 / 2. Change policy after setsid(): R test 4142 4962.517723 420 120 4962.517723 4974.126149 0.000000 /autogroup-44 I think we can fix it with: diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c index 8a2e230..8c3a169 100644 --- a/kernel/sched/auto_group.c +++ b/kernel/sched/auto_group.c @@ -115,9 +115,6 @@ bool task_wants_autogroup(struct task_struct *p, struct task_group *tg) if (tg != &root_task_group) return false; - if (p->sched_class != &fair_sched_class) - return false; - /* * We can only assume the task group can't go away on us if * autogroup_move_group() can see us on ->thread_group list. > So what I think you want is something like the below; preferably with a > comment on ;-) > This is exactly what I did at first, but besides the issue described above, seems it might lead to starving RT tasks. If there's some rt task in autogroups but none in root cgroup, it's allowed to set rt_runtime to 0, so I think we have to disallow this setting, like what we already do with global rt_runtime. diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 89e7283..3f6c3ad 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -7460,6 +7460,9 @@ static inline int tg_has_rt_tasks(struct task_group *tg) { struct task_struct *g, *p; + if (task_group_is_autogroup(tg)) + return 0; + for_each_process_thread(g, p) { if (rt_task(p) && task_group(p) == tg) return 1; @@ -7540,6 +7543,9 @@ static int __rt_schedulable(struct task_group *tg, u64 period, u64 runtime) .rt_runtime = runtime, }; + if (tg == &root_task_group && runtime == 0) + return -EINVAL; + rcu_read_lock(); ret = walk_tg_tree(tg_rt_schedulable, tg_nop, &data); rcu_read_unlock(); > --- > kernel/sched/core.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index 1f37fe7f77a4..f4fd048ce7cf 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -7644,6 +7644,9 @@ static inline int tg_has_rt_tasks(struct task_group *tg) > { > struct task_struct *g, *p; > > + if (task_group_is_autogroup(tg)) > + return 0; > + > for_each_process_thread(g, p) { > if (rt_task(p) && task_group(p) == tg) > return 1; > . > -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/