From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760628AbZD1L0S (ORCPT ); Tue, 28 Apr 2009 07:26:18 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1756747AbZD1L0D (ORCPT ); Tue, 28 Apr 2009 07:26:03 -0400 Received: from mail-qy0-f112.google.com ([209.85.221.112]:60348 "EHLO mail-qy0-f112.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756416AbZD1L0B convert rfc822-to-8bit (ORCPT ); Tue, 28 Apr 2009 07:26:01 -0400 DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=xcSdB9g9jL2whZn+YF8KM+NgYPy7C7OrDwAxDYyT2lxQMqH5JOH/9n2egcYGSFzuyX Y4wLguJeiFrybENZvNjcSUD029u6LQwyXxwyyJU5nz+jBDxC86ADJjJjek8iKNLXtF4U 0UgGOMBeNaNrbMI/61nGS6u8vpPmN8jZ6Sz+g= MIME-Version: 1.0 In-Reply-To: References: Date: Tue, 28 Apr 2009 19:26:00 +0800 Message-ID: Subject: Re: [PATCH] sched: make sure sched_child_runs_first WORK From: marywangran To: linux-kernel@vger.kernel.org Content-Type: text/plain; charset=GB2312 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is new patch,it is simple,and it work all right CFS scheduler become the main scheduler after 2.6.23.everything is fair,no starvation,no complexity.The new task would not simply be queued at the head to quickly preempt current.according to the code of kernel 2.6.28,if you clear the STAR_DEBIT bit by sysctl -w kernel.sched_features=orig_value&~STSRT_DEBIT_bit,child task would not preempt its father always,and this problem is easier to recur if you use a father task with lower nice value. my test file is: /*******child_first.c**********/ #include #include #include int main(int argc,char *argv[]) { cpu_set_t mask; __CPU_ZERO( &mask ); __CPU_SET(0, &mask ); sched_setaffinity( 0, sizeof(mask), &mask ); int v = atoi(argv[1]); nice(v); int i = 90000; while(i-->0) { v++; } if(fork() == 0) { printf("sub\n"); exit(0); } printf("main,%d\n",v); } just compile it to child_first and do following: [root@zhaoya ~]#sysctl -w kernel.sched_features=0 [root@zhaoya ~]#./child_first -20 [root@zhaoya ~]#./child_first -xx ... [root@zhaoya ~]#./child_first 10000... after all this,believe your eyes. because the code judgeing the condition whether the child should preempt the father is very LOOSE£Ħif the nice value of father is very low and the nr_running is very small,the cfs_rq->min_vruntime is always equal with the vruntime of father,so {curr->vruntime <= se->vruntime}.if the nice value if high,the cfs_rq->min_vruntime is always little than father so {cfs_rq->min_vruntime <= curr->vruntime} Signed-off-by: Ya Zhao --- --- linux-2.6.28.1/kernel/sched_fair.c.orig 2009-04-28 22:26:00.000000000 +0800 +++ linux-2.6.28.1/kernel/sched_fair.c 2009-04-28 22:34:49.000000000 +0800 @@ -1628,12 +1628,13 @@ static void task_new_fair(struct rq *rq, /* 'curr' will be NULL if the child belongs to a different group */ if (sysctl_sched_child_runs_first && this_cpu == task_cpu(p) && - curr && curr->vruntime < se->vruntime) { + curr){ /* * Upon rescheduling, sched_class::put_prev_task() will place * 'current' within the tree based on its new key value. */ - swap(curr->vruntime, se->vruntime); + if( curr->vruntime < se->vruntime ) + swap(curr->vruntime, se->vruntime); resched_task(rq->curr); } --