Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp205448pxp; Fri, 18 Mar 2022 23:33:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyTQbdm1VlAdJBgbRowgxBTp0NZKETYcNcnS49KzT5hnaurpQMphVFIdfOUlNAst+5ylcjj X-Received: by 2002:a17:906:358e:b0:6cf:61dd:5a1f with SMTP id o14-20020a170906358e00b006cf61dd5a1fmr12184538ejb.416.1647671633124; Fri, 18 Mar 2022 23:33:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647671633; cv=none; d=google.com; s=arc-20160816; b=a87aVw8gfHygVaSXxVTx9beQEPC5yl923S9N+1hYA6ZMCc4mtA7Je7LopsC/rwRsbm NOAeTWlkfE9C6+uX3nEgr6DRzUokN2p/CwoH39vhO/4ofNloPQ6SL3+ESriKOf1QIsWj 5q1Xw+XrEkcJPxQzkz14Q/uDiAnCNKN8rwq2X4K6vkr6Q/DNqBh4sV4OPFtDwnuZXRXz 6OqD1Eu6RkcUDNLUH2OidYEhA4420PSw70GENgwH3MtQlj/qAm5VRUL1/I3nC7YxxXJ5 9NVot4xqYQR5ALhFCSc9mmy8nlY/dg2Ek8U82bKzsnheozWCGFj8irKsYKBvgcsSLDpp orbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=iguF8ZKfuQY2GREbfrikvERYGr6QK9/sWPcTjhS6nXs=; b=Txzn17SWeaGvoNeo9dudPleB0vKlNI5lxCjJa/iUlljs+WVSzCYw9YY73IeVjrGy5H t67obgM3yh+25ldGZVYc9bYWFWswHCUCii2p2TgUJUhC4DnwLT3lwJ17j2ibvRtZVMAH xViuxH5NjQGdy2tEZtRu0WzK0nclhNC+1dYWsZHjDy1MlvHAMvvNavCX11b9+p2lZecR Dx2TY+EfXxigQuxw4lEPXXPB7UiSbx+n3FiFJv2O/0YBdX2gbGAtGp7dRqh2A3ZXkvux Xy+PgF9LDnw16Qk5eiRlZG/lepKQl79PtB7u4O8PK8TUC+tFGLTIi5lnJ6NtTDho7Q4z Z/vA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i14-20020a50c3ce000000b00418f25f49a1si5340754edf.566.2022.03.18.23.33.27; Fri, 18 Mar 2022 23:33:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239266AbiCRQa4 (ORCPT + 99 others); Fri, 18 Mar 2022 12:30:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239155AbiCRQap (ORCPT ); Fri, 18 Mar 2022 12:30:45 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D3442195D8D for ; Fri, 18 Mar 2022 09:28:47 -0700 (PDT) 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 8F2C71515; Fri, 18 Mar 2022 09:28:46 -0700 (PDT) Received: from [192.168.178.6] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DA7D03F7B4; Fri, 18 Mar 2022 09:28:44 -0700 (PDT) Message-ID: <7c75e5d4-75a2-8ea5-64ad-13794a6036b6@arm.com> Date: Fri, 18 Mar 2022 17:28:43 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH] sched/fair: Refactor cpu_util_without() Content-Language: en-US To: Vincent Guittot Cc: Ingo Molnar , Peter Zijlstra , Juri Lelli , Steven Rostedt , Mel Gorman , Ben Segall , Patrick Bellasi , Vincent Donnefort , linux-kernel@vger.kernel.org References: <20220301171727.812157-1-dietmar.eggemann@arm.com> From: Dietmar Eggemann In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org - Valentin Schneider On 02/03/2022 10:09, Vincent Guittot wrote: > On Tue, 1 Mar 2022 at 18:17, Dietmar Eggemann wrote: [...] > I have only minor comment Thanks for the review! [...] >> +static unsigned long cpu_util_next(int cpu, struct task_struct *p, int dst_cpu) >> +{ [...] >> + if (sched_feat(UTIL_EST)) { >> + util_est = READ_ONCE(cfs_rq->avg.util_est.enqueued); >> + >> + /* >> + * During wake-up, the task isn't enqueued yet and doesn't >> + * appear in the cfs_rq->avg.util_est.enqueued of any rq, >> + * so just add it (if needed) to "simulate" what will be >> + * cpu_util after the task has been enqueued. >> + */ >> + if (dst_cpu == cpu) >> + util_est += _task_util_est(p); >> + > > Could you add a comment that explains why the addition above will not > be removed below by the lsub_positive below so it isn't worth trying > to optimize such a case? Yes. I rewored the comments in cpu_util_next() so they also apply when called by cpu_util_without(). And I use a `if{}/else if{}` here too in v2. >> + /* >> + * Despite the following checks we still have a small window >> + * for a possible race, when an execl's select_task_rq_fair() >> + * races with LB's detach_task(): >> + * >> + * detach_task() >> + * p->on_rq = TASK_ON_RQ_MIGRATING; >> + * ---------------------------------- A >> + * deactivate_task() \ >> + * dequeue_task() + RaceTime >> + * util_est_dequeue() / >> + * ---------------------------------- B >> + * >> + * The additional check on "current == p" it's required to >> + * properly fix the execl regression and it helps in further >> + * reducing the chances for the above race. >> + */ >> + if (unlikely(task_on_rq_queued(p) || current == p)) >> + lsub_positive(&util_est, _task_util_est(p)); I did a lot of testing on mainline & v4.20 and there wasn't one occurrence of `p->on_rq == TASK_ON_RQ_MIGRATING` here. Not for WF_EXEC tasks (p->on_rq = TASK_ON_RQ_QUEUED) and in case of v4.20 not for WF_EXEC and WF_TTWU tasks (p->on_rq = 0). So I assume it's not needed. I left it in v2 though and mentioned it in the additional comment section of the patch. [...] >> static unsigned long cpu_util_without(int cpu, struct task_struct *p) >> { [...] >> /* >> * Covered cases: >> * >> @@ -6560,82 +6609,8 @@ static unsigned long cpu_util_without(int cpu, struct task_struct *p) >> * estimation of the spare capacity on that CPU, by just >> * considering the expected utilization of tasks already >> * runnable on that CPU. > > The comment about the covered cases above should be moved in > cpu_util_next() which is where the cases are covered now Yes. I Incorporated it into the comments in cpu_util_next() in v2. [...]