Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp408982pxa; Tue, 11 Aug 2020 06:14:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5vmNeS5GQX94oYJk5a2UgVM5O4Z2uC1iLoBKtcvJINTxKgDuSTTLFlxAX9ZxQ8HtqfUYC X-Received: by 2002:a05:6402:2379:: with SMTP id a25mr25461734eda.180.1597151662934; Tue, 11 Aug 2020 06:14:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597151662; cv=none; d=google.com; s=arc-20160816; b=yKPrqkfV5QxnIRX6EU5lr51BK0DB74uj2yjYfm1X1ewHf1o2QX2hRSeJN+XZgpY6jN e/VXi0Ze/W4MF98RIopLfyMMUl3fMh27G0/9ptMAXFPF/SuegCcu6SqpHpzzYph+BHMd DgjWUALC/wUQ6pJGusAEWI2a7BeYOzn0gLNsmkUbL+j8E/dJCl1KGHDamMjvkWpsbbCT xEs3JMzxHSh0wq5QNCpGsTXYqQGt2jjG0HPyAjE/xZDaSP27/4ZYuYiwElIrsH/fEJrB X/8t4tQOm/AaoXzMi5dDx5vZyFIgsJD2bDp7ej5Eg6z3cBcUmDLXi5gDFkiHRyxnNFox jo8Q== 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:dkim-signature; bh=qZ9iduntohOD5MRWKGXE3NQwDvKnC/BQdlgFzYDcVCg=; b=ZGvOchPmJL5KerjKilXgSK4O21rqvwDvYtsnEuYZkN9XTiUuXWVm9kSvjhpSazUa3n 9fN2DAScgm0qRUvTnwBvMSwvHzlMnRAw00+F+btpAq2HOTv5Q6HVVM29xqBKYy2WD3hf fsiz0fG8YEFqUOeaPobVWQ4ESEb1l6nIaQNUUcDLbABHHkpNsd7aeUFvdmxPFBY6bKqC Zp7xddKpHXk7L9YrqAkcV9hsma+OA3EE2mtdYBxqe6K1MOhBYia1qQi6X24yxKqIehwZ HXjp7d1p5Q9qiyiGKVR1lNx6WeD+YDy+EZzw5SFD9Qb00T6O9d+B+QWN39pLvPXrKmHI ohRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TE8F4eu3; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ba10si2746279edb.472.2020.08.11.06.13.58; Tue, 11 Aug 2020 06:14:22 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TE8F4eu3; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728637AbgHKNM0 (ORCPT + 99 others); Tue, 11 Aug 2020 09:12:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728566AbgHKNM0 (ORCPT ); Tue, 11 Aug 2020 09:12:26 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2530BC06174A for ; Tue, 11 Aug 2020 06:12:26 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id j21so6690460pgi.9 for ; Tue, 11 Aug 2020 06:12:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=qZ9iduntohOD5MRWKGXE3NQwDvKnC/BQdlgFzYDcVCg=; b=TE8F4eu3B0uTZCmWX+baJY9caqGEcgZS9Ibz77pNiep8D7kqZbmgpJ8fRsP68Mq2A6 P7tgGes4ixKX83YBlw2LTNVBHeu3Wl0wUZXhkUY5a32krwLV9jKWr+XDkjwm5U1Eap/k d3KY7FpiFKXGj3V/xHU8UWZpXutQkg8iw/ZTCqi38StguxoL38Aw1o8WmcGTArrJHL11 9Bfs1J1r8fFgvuPljJTt1sqmAgAYIeWrS/9eqvq06C1rkXEh/eDCmWZBbaKT61/EHVqR CkfvKzcjTxi05D7nEq6teN+SHyvN4mfjgQboJmTkMLlYav8X2wBgFYKsFHimQTdpb5s3 aFxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=qZ9iduntohOD5MRWKGXE3NQwDvKnC/BQdlgFzYDcVCg=; b=FQ4Zv8WKPJzyL/W5pUsGC/U0ouwbhiMV9gD6icjFCXd+w+F+jXymNOBE9CQFOhkluf b9sOWSRhPooRc7shGtYJW0XDm0gfOKq8P6DiNnlKItenGcWAYPSfIaKed8E8iVKooo1i 7pRKyAmy3V53BI9EiYSUrJuTLGFJTJzHMQcWtZbfEPcX94b3xLXS0VNYgmqGm9qSOJ2j XIARfA2zl0mtk1GPr/XkcESaTg1vledYpq4CsE82QmbOCNL+f9dKOP8oooufJcTVUZs/ BLpU+HaJGz8G6dzEz3T3EECLHmJLasuBHIufCcx9786DotSFMYqnqANXsxBnZXsFxZWk e4Lg== X-Gm-Message-State: AOAM5331Zm9B+k4pP1QLp7/5yDYTNfGuEhELADaWnQsoQQwfF10YiN9r s0qGCZneFvdH2GEKtvgQvVjTSY8X X-Received: by 2002:aa7:8608:: with SMTP id p8mr5978330pfn.62.1597151545250; Tue, 11 Aug 2020 06:12:25 -0700 (PDT) Received: from [0.0.0.0] ([108.61.186.250]) by smtp.gmail.com with ESMTPSA id w82sm26414844pff.7.2020.08.11.06.12.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 11 Aug 2020 06:12:24 -0700 (PDT) Subject: Re: [PATCH] sched/fair: Remove the duplicate check from group_has_capacity() To: Valentin Schneider Cc: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, linux-kernel@vger.kernel.org References: <20200810010009.92758-1-arch0.zheng@gmail.com> <9425382c-2a42-57ca-512d-c93c589dc701@gmail.com> <01fe6a9b-fd3a-9b36-b2fa-6cea58415670@gmail.com> From: Qi Zheng Message-ID: <905d8887-e79c-daf6-cbce-80fd0509e37d@gmail.com> Date: Tue, 11 Aug 2020 21:12:17 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020/8/11 下午8:48, Valentin Schneider wrote: > > On 11/08/20 12:44, Qi Zheng wrote: >> On 2020/8/11 下午6:38, Valentin Schneider wrote: >>> >>> On 11/08/20 04:39, Qi Zheng wrote: >>>> On 2020/8/11 上午2:33, Valentin Schneider wrote: >>>>> >>>>> On 10/08/20 02:00, Qi Zheng wrote: >>>>>> 1. The group_has_capacity() function is only called in >>>>>> group_classify(). >>>>>> 2. The following inequality has already been checked in >>>>>> group_is_overloaded() which was also called in >>>>>> group_classify(). >>>>>> >>>>>> (sgs->group_capacity * imbalance_pct) < >>>>>> (sgs->group_runnable * 100) >>>>>> >>>>> >>>>> Consider group_is_overloaded() returns false because of the first >>>>> condition: >>>>> >>>>> if (sgs->sum_nr_running <= sgs->group_weight) >>>>> return false; >>>>> >>>>> then group_has_capacity() would be the first place where the group_runnable >>>>> vs group_capacity comparison would be done. >>>>> >>>>> Now in that specific case we'll actually only check it if >>>>> >>>>> sgs->sum_nr_running == sgs->group_weight >>>>> >>>>> and the only case where the runnable vs capacity check can fail here is if >>>>> there's significant capacity pressure going on. TBH this capacity pressure >>>>> could be happening even when there are fewer tasks than CPUs, so I'm not >>>>> sure how intentional that corner case is. >>>> >>>> Maybe some cpus in sg->cpumask are no longer active at the == case, >>>> which causes the significant capacity pressure? >>>> >>> >>> That can only happen in that short window between deactivating a CPU and >>> not having rebuilt the sched_domains yet, which sounds quite elusive. >>> >> >> In fact, at the beginning, I added unlikely() here to hint the compiler: >> >> - if ((sgs->group_capacity * imbalance_pct) < >> - (sgs->group_runnable * 100)) >> + if (unlikely((sgs->group_capacity * imbalance_pct) < >> + (sgs->group_runnable * 100))) >> >> The corresponding patch is as follows: >> >> [PATCH]sched/core: add unlikely in group_has_capacity() >> >> Do you think it is necessary? > > The "unlikely" approach has the benefit of keeping all corner cases in > place. I was tempted to say it could still make sense to get rid of the > extra check entirely, given that it has an impact only when: > > - sum_nr_running == group_weight > - group capacity has been noticeably reduced > > If sum_nr_running < group_weight, we won't evaluate it. > If sum_nr_running > group_weight, we either won't call into > group_has_capacity() or we'll have checked it already in > group_overloaded(). > > That said, it does make very much sense to check it in that == > case. Vincent might have a different take on this, but right now I'd say > the unlikely approach is the safest one of the two. > So what should I do next? Do I resubmit a patch with unlikely() or add your email to the old patch([PATCH]sched/core: add unlikely in group_has_capacity())? Or continue to wait for suggestions from other maintainers?