Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp192395pxx; Wed, 28 Oct 2020 02:17:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwfgM8em8CVhDHITfPrTb61lQOu90K0WPeCwEVWwWoWM184zoEhCG/kG/vnya5f8CloBaW7 X-Received: by 2002:a17:906:a195:: with SMTP id s21mr6376316ejy.146.1603876636803; Wed, 28 Oct 2020 02:17:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603876636; cv=none; d=google.com; s=arc-20160816; b=YVP/H4NZnfU2azP3plH6MnPezQWJv3i0Vpi5m06gysY3/SvKMO5qHQO0Fiiznt827X fte5L288wcdZ83Ch26znH/83fgpSSYF2t+UnddiXkCmr5laQyISRaBCiAUxpn+blpLcO +edIqhzWFzuqLTshXKWo4N31V/A3RINqz9b+ln3rCDRe+K7sVtf994Wh0xsmMy6QHTP/ uQ1i+Uw3ToqSU9EAm2KrsLktCWLoKuLBnS2sqlnMBCNL4/kUMKiExRrj7WSWpgQCx+cL hXOJcMhXDGje8xz2JadML45G8aanELpqjwjOqKKnSXJlt8N//IWBGlq8gwm1UKzvn3We WbdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=ykXi2g6uJbJA/qiSGsDHFlM7mN9y+u5WVs1nXQ3xu8g=; b=ax8GuHEv8YLkLBEM9w+wwsGYOb6AGQdtx5RKxuf3rqKFoCBOAtNDTSjttSKehZKJaY /uv30eEijQXL+iE+xJhqIGK3tmTZR96nBoD5jlG2fg/mZ4+U39tJDwYQh7bCZS6k6+mE OgmP3xhX0ZDT7IzUrYYJcGnsu+QL4weQ52vNOuEZT0P/LFYx5YRzAHf2CBeDFyV3S2kJ LGYxtQHgthC6T9H9FP+HW6vJaMOwauFDmwE70X6QMzF9wKQZWIM7qQAZxyGCFEpgREi1 /RBLyfGuqJqc6N07ex83PAihOlYgUrN0L4+yNoAROzqlE8nOGL9K+sS1LfXaKJVDRv74 opwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=bE21aN+e; 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 g1si3663191edn.100.2020.10.28.02.16.54; Wed, 28 Oct 2020 02:17:16 -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=@joelfernandes.org header.s=google header.b=bE21aN+e; 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 S2901088AbgJ0OS1 (ORCPT + 99 others); Tue, 27 Oct 2020 10:18:27 -0400 Received: from mail-qk1-f196.google.com ([209.85.222.196]:44610 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755699AbgJ0OPC (ORCPT ); Tue, 27 Oct 2020 10:15:02 -0400 Received: by mail-qk1-f196.google.com with SMTP id s14so1233398qkg.11 for ; Tue, 27 Oct 2020 07:15:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=ykXi2g6uJbJA/qiSGsDHFlM7mN9y+u5WVs1nXQ3xu8g=; b=bE21aN+eAnzXRmHKMmMxsFJ3xfnOvdPPKVaV5LTOHd0Oz+1QNGWKha0fH1XCPD1gxU YWMGhphDrxMSFFjVg+G0R7ROFT14G5sB2uEvmrqV5mMC/B85QkpfUII5ToKZwt+Ro0a6 FMpd2dADntULV7B3NQ4ISJFuxOYJTy6xV8VRM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=ykXi2g6uJbJA/qiSGsDHFlM7mN9y+u5WVs1nXQ3xu8g=; b=MrHBJ1oZ4T5HnZT5Np6TNphqCJObMBi9BpNrsy7ygS9RVmu6I3LrRH+lQbWQCAC2Mk Pvdw0R6O5QpkFT6qW4Dy7ZgK29Gc510HmtCXQzizPNzUgMon3xg5GJjhUyDPG3QELgc+ thJZdcOXVIg70UIjg8sdUc+9EO50Gi+/25t2KR/xok0ybATypeoM1Wu9XHZkbymLMnxO Fhdw71PTf9dad/isMj++GqeG8UBLg5BmJWElodJdYhoPMeN5ssyVsOub+KbVnIK1eHmM Cyg+7FDR+qenPLT+Qc63coqVuC3mde9XZm9KW4LHghgjEU7oPZ8FCSlabIKTYAzhQq9V WiJg== X-Gm-Message-State: AOAM533T9+mnaiD3tb1XyZg3kja12ZsMEFW8OrmAKqxGOu83kFQ5eh4J /gcZD6+9yXauAa6yBWP8ogd8wQ== X-Received: by 2002:a37:9d4c:: with SMTP id g73mr2289576qke.391.1603808100838; Tue, 27 Oct 2020 07:15:00 -0700 (PDT) Received: from localhost ([2620:15c:6:411:cad3:ffff:feb3:bd59]) by smtp.gmail.com with ESMTPSA id b12sm849357qtj.12.2020.10.27.07.15.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2020 07:15:00 -0700 (PDT) Date: Tue, 27 Oct 2020 10:14:59 -0400 From: Joel Fernandes To: Vineeth Pillai Cc: "Li, Aubrey" , Nishanth Aravamudan , Julien Desfossez , Peter Zijlstra , Tim Chen , Aaron Lu , Aubrey Li , Thomas Glexiner , LKML , Ingo Molnar , Linus Torvalds , Frederic Weisbecker , Kees Cook , Greg Kerr , Phil Auld , Valentin Schneider , Mel Gorman , Pawan Gupta , Paolo Bonzini , vineeth@bitbyteword.org, Chen Yu , Christian Brauner , Agata Gruza , Antonio Gomez Iglesias , graf@amazon.com, konrad.wilk@oracle.com, Dario Faggioli , Paul Turner , Steven Rostedt , Patrick Bellasi , =?utf-8?B?YmVuYmppYW5nKOiSi+W9qik=?= , Alexandre Chartre , James.Bottomley@hansenpartnership.com, OWeisse@umich.edu, Dhaval Giani , Junaid Shahid , Jesse Barnes , "Hyser,Chris" , "Paul E. McKenney" , Tim Chen , "Ning, Hongyu" Subject: Re: [PATCH v8 -tip 02/26] sched: Introduce sched_class::pick_task() Message-ID: <20201027141459.GB771372@google.com> References: <20201020014336.2076526-1-joel@joelfernandes.org> <20201020014336.2076526-3-joel@joelfernandes.org> <8ea1aa61-4a1c-2687-9f15-1062d37606c7@linux.intel.com> <20201023214702.GA3603399@google.com> <4241e5ac-ecdf-8634-fa0d-dd6759e477e1@linux.microsoft.com> <8230ada7-839f-2335-9a55-b09f6a813e91@linux.microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <8230ada7-839f-2335-9a55-b09f6a813e91@linux.microsoft.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Oct 24, 2020 at 08:27:16AM -0400, Vineeth Pillai wrote: > > > On 10/24/20 7:10 AM, Vineeth Pillai wrote: > > > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > > index 93a3b874077d..4cae5ac48b60 100644 > > --- a/kernel/sched/fair.c > > +++ b/kernel/sched/fair.c > > @@ -4428,12 +4428,14 @@ pick_next_entity(struct cfs_rq *cfs_rq, struct > > sched_entity *curr) > > ??????????????????????? se = second; > > ??????? } > > > > -?????? if (cfs_rq->next && wakeup_preempt_entity(cfs_rq->next, left) < > > 1) { > > +?????? if (left && cfs_rq->next && > > +?????????????????????? wakeup_preempt_entity(cfs_rq->next, left) < 1) { > > ??????????????? /* > > ???????????????? * Someone really wants this to run. If it's not unfair, > > run it. > > ???????????????? */ > > ??????????????? se = cfs_rq->next; > > -?????? } else if (cfs_rq->last && wakeup_preempt_entity(cfs_rq->last, > > left) < 1) { > > +?????? } else if (left && cfs_rq->last && > > +?????????????????????? wakeup_preempt_entity(cfs_rq->last, left) < 1) { > > ??????????????? /* > > ???????????????? * Prefer last buddy, try to return the CPU to a > > preempted task. > > > > > > There reason for left being NULL needs to be investigated. This was > > there from v1 and we did not yet get to it. I shall try to debug later > > this week. > > Thinking more about it and looking at the crash, I think that > 'left == NULL' can happen in pick_next_entity for core scheduling. > If a cfs_rq has only one task that is running, then it will be > dequeued and 'left = __pick_first_entity()' will be NULL as the > cfs_rq will be empty. This would not happen outside of coresched > because we never call pick_tack() before put_prev_task() which > will enqueue the task back. > > With core scheduling, a cpu can call pick_task() for its sibling while > the sibling is still running the active task and put_prev_task has yet > not been called. This can result in 'left == NULL'. So I think the > above fix is appropriate when core scheduling is active. It could be > cleaned up a bit though. Thanks a lot Vineeth! Just add, the pick_next_entity() returning NULL still causes pick_task_fair() to behave correctly. Because pick_task_fair() will return 'curr' to the core-wide picking code, not NULL. The problem is CFS pick_next_entity() is not able to handle it though and crash, as Vineeth found the below hunk got lost in the rebase: @@ -4464,13 +4464,13 @@ pick_next_entity(struct cfs_rq *cfs_rq, struct sched_entity *curr) /* * Prefer last buddy, try to return the CPU to a preempted task. */ - if (cfs_rq->last && wakeup_preempt_entity(cfs_rq->last, left) < 1) + if (left && cfs_rq->last && wakeup_preempt_entity(cfs_rq->last, left) < 1) se = cfs_rq->last; /* * Someone really wants this to run. If it's not unfair, run it. */ - if (cfs_rq->next && wakeup_preempt_entity(cfs_rq->next, left) < 1) + if (left && cfs_rq->next && wakeup_preempt_entity(cfs_rq->next, left) < 1) se = cfs_rq->next; clear_buddies(cfs_rq, se); Peter's fix in the other email looks good and I will include that for testing before the next posting. thanks, - Joel