Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1688708ybk; Mon, 11 May 2020 01:44:50 -0700 (PDT) X-Google-Smtp-Source: APiQypJEQHmbapuwo+dIRKKvjVf2fCozJEzj83QPHvqh7Ab9Wtio6fWAhhAETDiCjJfaGFyqWb0/ X-Received: by 2002:a17:906:6411:: with SMTP id d17mr12511924ejm.109.1589186690261; Mon, 11 May 2020 01:44:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589186690; cv=none; d=google.com; s=arc-20160816; b=vtWzEuz+W3JtsW3UqPzgm6hSXXfx61A9ZGaQ4h/Zx2Ua1qpuT+aRxIdC2otugRBGsj JpJ/l1jAOHRS6wwqdSHPF4SKe689crD1izAcE+UuAy3KAQhMO2iUpWnuadVfLhkpIvZz 0CvX3NDfk2f7C6gr7Rmu6D2xcCaH80za19iWqtScRuDQ/axT5JFhK+H6zvVWW+Xas3YI ievCrxkoGg/dclalV30MJJ3C/e+gnH3PSTX6JOXh6pBETGJmECA0vOShshHgBjJqUlLp 1YhqKI0ekSb/1toRkkvO18Z57Qi0jvV3Oys1VQwq+N42CI/eiryqc8WJxsYO2hwLXT7m 1WUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=MQyx2D6lD3Lwdqkcbne1lU/0KB3WL2/p6LLo8XsZ/AE=; b=FuOtR2YPavnfadbuYtcnRIsIi9BDOoNudj/dukPFUyPzGbFRnlOsk73EMPEuAZ/WwM aJ8itb1blAMFHVubzsORhKbBDfj0rQYtuid1Djbl5u9SXSgfaunz2CMU7e/wLeIR5XpN 8LnyvFuGiagNPXe48iga8t7UeHMSMU9tDBbPAXatlVN20lvGtpjtyJADy7TBWpA8Ha+p 0UJK52LgMUq9O6+dMhQW1bxaWAan27OCoLR00tZI9sVfSkvVqaHcdfosxA7bMsvC+juG o/ZM0rtf8ND9W02uudGqFznPDoTtpI+XT23Y2QhRadMpDorhfKMP/9xBdZ7xydRx80hB yx/w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s8si5171639eji.349.2020.05.11.01.44.26; Mon, 11 May 2020 01:44:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729033AbgEKIkr (ORCPT + 99 others); Mon, 11 May 2020 04:40:47 -0400 Received: from foss.arm.com ([217.140.110.172]:53816 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728562AbgEKIkr (ORCPT ); Mon, 11 May 2020 04:40:47 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 889E0D6E; Mon, 11 May 2020 01:40:46 -0700 (PDT) Received: from [192.168.0.7] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 37E343F305; Mon, 11 May 2020 01:40:45 -0700 (PDT) Subject: Re: [PATCH v2] sched/fair: Fix enqueue_task_fair warning some more To: Tao Zhou , Vincent Guittot Cc: Phil Auld , Peter Zijlstra , linux-kernel , Ingo Molnar , Juri Lelli , Tao Zhou References: <20200506141821.GA9773@lorien.usersys.redhat.com> <20200507203612.GF19331@lorien.usersys.redhat.com> <20200508151515.GA25974@geo.homenetwork> <20200508170213.GA27353@geo.homenetwork> From: Dietmar Eggemann Message-ID: <801229de-200d-c9d5-7fd3-8556c5abc064@arm.com> Date: Mon, 11 May 2020 10:40:39 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <20200508170213.GA27353@geo.homenetwork> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 08/05/2020 19:02, Tao Zhou wrote: > On Fri, May 08, 2020 at 05:27:44PM +0200, Vincent Guittot wrote: >> On Fri, 8 May 2020 at 17:12, Tao Zhou wrote: >>> >>> Hi Phil, >>> >>> On Thu, May 07, 2020 at 04:36:12PM -0400, Phil Auld wrote: >>>> sched/fair: Fix enqueue_task_fair warning some more [...] >>>> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c >>>> index 02f323b85b6d..c6d57c334d51 100644 >>>> --- a/kernel/sched/fair.c >>>> +++ b/kernel/sched/fair.c >>>> @@ -5479,6 +5479,13 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags) >>>> /* end evaluation on encountering a throttled cfs_rq */ >>>> if (cfs_rq_throttled(cfs_rq)) >>>> goto enqueue_throttle; >>>> + >>>> + /* >>>> + * One parent has been throttled and cfs_rq removed from the >>>> + * list. Add it back to not break the leaf list. >>>> + */ >>>> + if (throttled_hierarchy(cfs_rq)) >>>> + list_add_leaf_cfs_rq(cfs_rq); >>>> } >>> >>> I was confused by why the throttled cfs rq can be on list. >>> It is possible when enqueue a task and thanks to the 'threads'. >>> But I think the above comment does not truely put the right >>> intention, right ? >>> If throttled parent is onlist, the child cfs_rq is ignored >>> to be added to the leaf cfs_rq list me think. >>> >>> unthrottle_cfs_rq() follows the same logic if i am not wrong. >>> Is it necessary to add the above to it ? >> >> When a cfs_rq is throttled, its sched group is dequeued and all child >> cfs_rq are removed from leaf_cfs_rq list. But the sched group of the >> child cfs_rq stay enqueued in the throttled cfs_rq so child sched >> group->on_rq might be still set. > > If there is a throttle of throttle, and unthrottle the child throttled > cfs_rq(ugly): > ... > | > cfs_rq throttled (parent A) > | > | > cfs_rq in hierarchy (B) > | > | > cfs_rq throttled (C) > | > ... > > Then unthrottle the child throttled cfs_rq C, now the A is on the > leaf_cfs_rq list. sched_group entity of C is enqueued to B, and > sched_group entity of B is on_rq and is ignored by enqueue but in > the throttled hierarchy and not add to leaf_cfs_rq list. > The above may be absolutely wrong that I miss something. > > Another thing : > In enqueue_task_fair(): > > for_each_sched_entity(se) { > cfs_rq = cfs_rq_of(se); > > if (list_add_leaf_cfs_rq(cfs_rq)) > break; > } > > In unthrottle_cfs_rq(): > > for_each_sched_entity(se) { > cfs_rq = cfs_rq_of(se); > > list_add_leaf_cfs_rq(cfs_rq); > } > > The difference between them is that if condition, add if > condition to unthrottle_cfs_rq() may be an optimization and > keep the same. > I'm not 100% sure if this is exactly what Tao pointed out here but I also had difficulties understanding understanding how this patch works: p.se | __________________| | V cfs_c -> tg_c -> se_c (se->on_rq = 1) | __________________| | v cfs_b -> tg_b -> se_b | __________________| | V cfs_a -> tg_a -> se_a | __________________| | V cfs_r -> tg_r | V rq (1) The incomplete update happens with cfs_c at the end of enqueue_entity() in the first loop because of 'if ( .... || cfs_bandwidth_used())' (cfs_b->on_list=0 since cfs_a is throttled) (2) se_c breaks out of the first loop (se_c->on_rq = 1) (3) With the patch cfs_b is added back to the list. But only because cfs_a->on_list=1. But since cfs_a is throttled it should be cfs_a->on_list=0 as well. throttle_cfs_rq()->walk_tg_tree_from(..., tg_throttle_down, ...) should include cfs_a when calling list_del_leaf_cfs_rq(). IMHO, throttle_cfs_rq() calls tg_throttle_down() for the throttled cfs_rq too. Another thing: Why don't we use throttled_hierarchy(cfs_rq) instead of cfs_bandwidth_used() in enqueue_entity() as well?