Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp447167pxu; Thu, 26 Nov 2020 02:54:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJxtCdMBlkuSHhjdIgAXEVBlkb6zY0gUCwp5O5HWBfCQSe6LcXB1G9YUaJ54uPVpPgEo45AD X-Received: by 2002:a17:906:5f92:: with SMTP id a18mr2080095eju.397.1606388085020; Thu, 26 Nov 2020 02:54:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606388085; cv=none; d=google.com; s=arc-20160816; b=PuFRV1gWu0YWNX6TRGiKbqSEXP1xyFFRw27BdKCAyFwuLkJ//TdREfH2v9yykAsgKY MdoWWP0UPnBR71YrkgCrJaT1GiA/tnCgvt05wyMJf7RJZ0Mgm1KADbsv87n59y5GVx0T KuB+0bBsfIfPCRB/r4kixEkCHevk/7evIgxQBqpjFhv4k4PvP4HIjEpCtPvgoRANCQ+Z eZGFCu2iMGvl8ucZ7wrkhDSO2oWwGZu7AsDcezx4v8GCPcSq9K4K5z4vB3df+Gi+xXc5 Z/4k/xlz2m8Df7A9lkyPgDkDOqmQAMiec9WfcqmaPYx2IkBsMEAVNN+sYxLz2RBBUDot gg1g== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=fDlu5J9M+Xdp0HOAKxmY6WP3yf0ej07B8LChxfpJT5A=; b=n17XPwcZs8Co80A2vRjSG3NP7GrrjeecEvIxmfPibCgR0wEedLrcICLE1vNhY52MMh gPX9biSHNpqqsx6fT6RUgpvrtU9W4vHSPB6hJw9ZiZ55gtuvaTlEW9sUuFcTR0CWSIPB 1J7kFDXhCszUJTr+tIpaCUNlRd8E3c0Al1R6wfEmtlNxk1GmqtcSMkQ32yde9RLy0or5 hhNW6QOlqeb9Rd+HrGuDRbd5jsbWlfDChu8W9tIJT/RUXtMV2Ok+mqW6H8KJuwtetqWi VhnlsuW4ZvAzTydBYE/ZS2F7OSt5QWfu80Kn6mmHjVEg4WJ4GU82028/+jtnPgxb9A80 Qj1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=merlin.20170209 header.b=3HfQBIMK; 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 q17si2047737ejn.294.2020.11.26.02.54.22; Thu, 26 Nov 2020 02:54:45 -0800 (PST) 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=@infradead.org header.s=merlin.20170209 header.b=3HfQBIMK; 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 S2388890AbgKZIaQ (ORCPT + 99 others); Thu, 26 Nov 2020 03:30:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727039AbgKZIaQ (ORCPT ); Thu, 26 Nov 2020 03:30:16 -0500 Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A653C0613D4 for ; Thu, 26 Nov 2020 00:30:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=fDlu5J9M+Xdp0HOAKxmY6WP3yf0ej07B8LChxfpJT5A=; b=3HfQBIMKZLxJjn4pRg2PO2R1jU wEkDFC4MFR3nFwXrubpqJaNBB4Pt25gsq4UgMzK6QW7bAvMFmZKLeoAe0veVbFdm2LhnQP1fIdmD9 tDPndmQYPrItovxELLijTVIa/fOr2O3WHIeYwJamDnxTSiSRkGYwvqZQzfnw0e4excqpMot5Hh5Lg bNP/iZBQjALRyIYbbFcEirMlVKh5/5GDb7gziIJxPiElP4GQlUq3WddRCVQ4ZRUQDqkn9Z6rjuu6s 3sDS8knnyBctBzYvX/0cdNJjLvyvt4Y/1zkPffcmyQCR81iUECM/MT0/jixzysBtDTUMOn3UMGcRJ TNozZo2A==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kiCeS-0000dY-8Y; Thu, 26 Nov 2020 08:29:16 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 4CC6B3012DF; Thu, 26 Nov 2020 09:29:14 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 30F3920D6FE65; Thu, 26 Nov 2020 09:29:14 +0100 (CET) Date: Thu, 26 Nov 2020 09:29:14 +0100 From: Peter Zijlstra To: Balbir Singh Cc: Joel Fernandes , Nishanth Aravamudan , Julien Desfossez , Tim Chen , Vineeth Pillai , Aaron Lu , Aubrey Li , tglx@linutronix.de, linux-kernel@vger.kernel.org, mingo@kernel.org, torvalds@linux-foundation.org, fweisbec@gmail.com, keescook@chromium.org, kerrnel@google.com, 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, dfaggioli@suse.com, pjt@google.com, rostedt@goodmis.org, derkling@google.com, benbjiang@tencent.com, Alexandre Chartre , James.Bottomley@hansenpartnership.com, OWeisse@umich.edu, Dhaval Giani , Junaid Shahid , jsbarnes@google.com, chris.hyser@oracle.com, Ben Segall , Josh Don , Hao Luo , Tom Lendacky , Aubrey Li , "Paul E. McKenney" , Tim Chen Subject: Re: [PATCH -tip 10/32] sched: Fix priority inversion of cookied task with sibling Message-ID: <20201126082914.GE2414@hirez.programming.kicks-ass.net> References: <20201117232003.3580179-1-joel@joelfernandes.org> <20201117232003.3580179-11-joel@joelfernandes.org> <20201122224123.GE110669@balbir-desktop> <20201124183038.GG1021337@google.com> <20201125230519.GC163610@balbir-desktop> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201125230519.GC163610@balbir-desktop> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 26, 2020 at 10:05:19AM +1100, Balbir Singh wrote: > > @@ -5259,7 +5254,20 @@ pick_next_task(struct rq *rq, struct task_struct *prev, struct rq_flags *rf) > > * Optimize the 'normal' case where there aren't any > > * cookies and we don't need to sync up. > > */ > > - if (i == cpu && !need_sync && !p->core_cookie) { > > + if (i == cpu && !need_sync) { > > + if (p->core_cookie) { > > + /* > > + * This optimization is only valid as > > + * long as there are no cookies > > This is not entirely true, need_sync is a function of core cookies, so I > think this needs more clarification, it sounds like we enter this when > the core has no cookies, but the task has a core_cookie? The term cookie > is quite overloaded when used in the context of core vs task. Nah, its the same. So each task gets a cookie to identify the 'group' of tasks (possibly just itself) it is allowed to share a core with. When we to core task selection, the core gets assigned the cookie of the group it will run, same thing. > Effectively from what I understand this means that p wants to be > coscheduled, but the core itself is not coscheduling anything at the > moment, so we need to see if we should do a sync and that sync might > cause p to get kicked out and a higher priority class to come in? This whole patch is about eliding code-wide task selection when it is not required. IOW an optimization. When there wasn't a core cookie (IOW, the previous task selection wasn't core wide and limited) and the task we just selected for our own CPU also didn't have a cookie (IOW it doesn't have to be core-wide) we can skip the core wide task selection and schedule just this CPU and call it a day. The logic was subtly wrong, this patch fixes it. A next patch completely rewrites it again to make it far simpler again. Don't spend time trying to understand this patch (unless you're _that_ kind of person ;-) but instead apply the whole thing and look at the resulting pick_next_task() function.