Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp2608823ybi; Mon, 1 Jul 2019 15:15:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqxf9JN4yYiuFIqlu9SmyW0CV6lbOSRIHij6oQujT/KJClTw2xMjOrReCFV9XRcqYeWV2e86 X-Received: by 2002:a17:902:9a85:: with SMTP id w5mr29861854plp.221.1562019330230; Mon, 01 Jul 2019 15:15:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562019330; cv=none; d=google.com; s=arc-20160816; b=zHKUoFfqmqa8V6Ji0nLYxZkL5y7sqbRvsFHJrdYzPDzbRAn0Q8n22YeyDWhwJHjeAY EVKaAVd7fY1TwP+yxrZsnudB26vG0lJpoY3/GFpPZcH61I3LkIGsCYbgViUhuZXCXNkn O79ATQZ6MwyCpA6Miz3aIw1M39qskT2U5lAA5BN0j57f6ZNCtpvtkVIjFR2OHQUjvK0E 3RzYlw/2UB6DWmjDS72cLrS19uewN9QY9NC1RsdboGZjM7ehvE9Jlmi7qM/PrC/4BqsY bHNsAhFtC1XCl08u5+2RV1UUBpwyCvLdquMZpf03cVXoV1NXg7TCOnSdwzp7OGOs3oWr PArQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=en4SXX022hwvX0x9G0+SnC+PnaP8ULXzHBhOeJ5wAfo=; b=FMSGxB1KVImlOvp+iI4ZRi/yAgV2e5ZVI0X7PJ/fqLGsZX+lq2385maFZ6XLu+GKba 5pAqoVtzrUUZxNJi8rISi8z0g3GEBjaDzZO7qeKmDbI3T/jGPXEh60zgHzYt+3fJlzNX rPuTCEPWvPcicMPIiOF8S6zjYRTjh4t/bso8ixrGsip8/k4a4yFn8c5CqxFspko8JO79 UAtn2OQEzCMnBpsOF240rly3EWt0EjPPOTobtudjgIQqKvrFWdV1avDJdAvGMTReZs9R 3GWXnxXONzkDKJZfXtpDEAw+9GF84oSx9A6jU+Uepi3XryLws4mTTAk9kyFmoXyPjRrO UwyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b="riEb/0iH"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i5si594806pjk.57.2019.07.01.15.15.14; Mon, 01 Jul 2019 15:15:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b="riEb/0iH"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726678AbfGAWOr (ORCPT + 99 others); Mon, 1 Jul 2019 18:14:47 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:58708 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726320AbfGAWOr (ORCPT ); Mon, 1 Jul 2019 18:14:47 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x61M90wO042017; Mon, 1 Jul 2019 22:14:00 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=en4SXX022hwvX0x9G0+SnC+PnaP8ULXzHBhOeJ5wAfo=; b=riEb/0iHU4DXypD8J+7SMIGCa9AdG//i4jdeiMmo8To4sgCcO28Ik0Lz0JZrZ4KqsGCM QGIy/DNuQqpDiFO0txlZkRqg06IZxFWAd0zbK+Wg30lyVmcU8uPUpcExXuReeoDh5R5g AXVDJPLa9eZ+kDJCFsheVK19WeAAkKQyPRg4m8GX1M8yN1twpXWwW0u4zL9N9XOPEAFW 13CXQrCbkKzGVxzguEpOUNqcOgDvv+5leNHbImAF4ImYvqohkaRFim43Hl0eVytTEzJ6 8x4nk/qgYU7aLhM1NByhw9tgKHCfRBrWq4ep2GBEDkJHRmx2oIxiasPB7aUxsqsvbkIj 3A== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 2te61e050p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 01 Jul 2019 22:14:00 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x61MCxh2098486; Mon, 1 Jul 2019 22:13:59 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3030.oracle.com with ESMTP id 2tebqg5w2n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 01 Jul 2019 22:13:59 +0000 Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x61MDwgS024959; Mon, 1 Jul 2019 22:13:58 GMT Received: from [10.132.91.175] (/10.132.91.175) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 01 Jul 2019 15:13:58 -0700 Subject: Re: [PATCH V3 2/2] sched/fair: Fallback to sched-idle CPU if idle CPU isn't found To: Viresh Kumar Cc: Ingo Molnar , Peter Zijlstra , linux-kernel@vger.kernel.org, Vincent Guittot , tkjos@google.com, Daniel Lezcano , quentin.perret@linaro.org, chris.redpath@arm.com, steven.sistare@oracle.com, songliubraving@fb.com References: <32bd769c-b692-8896-5cc9-d19ab0a23abb@oracle.com> <20190701080349.homlsgia4fuaitek@vireshk-i7> From: Subhra Mazumdar Message-ID: Date: Mon, 1 Jul 2019 15:08:41 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 In-Reply-To: <20190701080349.homlsgia4fuaitek@vireshk-i7> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9305 signatures=668688 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1907010258 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9305 signatures=668688 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1907010257 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/1/19 1:03 AM, Viresh Kumar wrote: > On 28-06-19, 18:16, Subhra Mazumdar wrote: >> On 6/25/19 10:06 PM, Viresh Kumar wrote: >>> We try to find an idle CPU to run the next task, but in case we don't >>> find an idle CPU it is better to pick a CPU which will run the task the >>> soonest, for performance reason. >>> >>> A CPU which isn't idle but has only SCHED_IDLE activity queued on it >>> should be a good target based on this criteria as any normal fair task >>> will most likely preempt the currently running SCHED_IDLE task >>> immediately. In fact, choosing a SCHED_IDLE CPU over a fully idle one >>> shall give better results as it should be able to run the task sooner >>> than an idle CPU (which requires to be woken up from an idle state). >>> >>> This patch updates both fast and slow paths with this optimization. >>> >>> Signed-off-by: Viresh Kumar >>> --- >>> kernel/sched/fair.c | 43 +++++++++++++++++++++++++++++++++---------- >>> 1 file changed, 33 insertions(+), 10 deletions(-) >>> >>> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c >>> index 1277adc3e7ed..2e0527fd468c 100644 >>> --- a/kernel/sched/fair.c >>> +++ b/kernel/sched/fair.c >>> @@ -5376,6 +5376,15 @@ static struct { >>> #endif /* CONFIG_NO_HZ_COMMON */ >>> +/* CPU only has SCHED_IDLE tasks enqueued */ >>> +static int sched_idle_cpu(int cpu) >>> +{ >>> + struct rq *rq = cpu_rq(cpu); >>> + >>> + return unlikely(rq->nr_running == rq->cfs.idle_h_nr_running && >>> + rq->nr_running); >>> +} >>> + >> Shouldn't this check if rq->curr is also sched idle? > Why wouldn't the current set of checks be enough to guarantee that ? I thought nr_running does not include the on-cpu thread. > >> And why not drop the rq->nr_running non zero check? > Because CPU isn't sched-idle if nr_running and idle_h_nr_running are both 0, > i.e. it is an IDLE cpu in that case. And so I thought it is important to have > this check as well. > idle_cpu() not only checks nr_running is 0 but also rq->curr == rq->idle