Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3198066yba; Tue, 16 Apr 2019 06:45:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqy818trJxJ6AyghJsk0+X7OwMF1p85hf7vhsLkRVSvhQ3/7foA0aEM9nCEUYuZMXVQDsbJP X-Received: by 2002:a63:f44:: with SMTP id 4mr72535686pgp.324.1555422304211; Tue, 16 Apr 2019 06:45:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555422304; cv=none; d=google.com; s=arc-20160816; b=ZZZAZ1m2HrG30T3Kp9DdCvRFaixd/Lc7bLJ1xjtIlk3862VadwBlzSl7ZUjb1JVOax kN1LSgKstngMvbIriH1bS69U+IV2JJq6W89dxUvv97D7E36DoEAdURoXGgy/jDOyT/G0 EVgId9U6bVNJ0aeg0mI4v0BTp55HZ06ZHCghwlUpIEEFN6aiScUQCumc7/BD9+Y8kMqq GElLCy/+8UOhBGlbtXIKDdSWsubYj6Oswwb52AY9Xy9RbnlRZJPQYjlHhzzeS/Z6N7ED AplGcDR27tH4iwcCbIM/EO+RMzT+ltAa0PCoMABARd/r5Do+EecDtoxGPDmJ2+Vs8FST yxGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=uYXqUbQ+uTpNPAA9wggCmfZqZlqDQKGhMc+2WcGU0WE=; b=WupZ7b15doP516dSONltQT6jNNDtAqPwAWQRLjF+Zmi5uafBYvC4EKUdNMIDWGs281 7BMqukYuzs+jlC1LWDkES6tk9jSFAJQ77MAFCbHRrl7DkWmdPcFWshqcQUe6m/VthqCC VPJl7eXoYMAxI9jF4K/uqou/n33Iq+HaLYD0X2Sol9z/eF/8zfU7AE+Y49q+3I9GzwDi LxWPF7WD1X7VfZobh5uz9spYxA7qX8wmgDPL83VqpyzzjTQdJN58W47Coy8AKUY9iBtU H2zByXDAEcGyX7dUWmxllwJepY7rjsoWKisgUXy4tr0NaomR68splJvTvmHasDCd61Wb xWEQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 141si47035287pgb.178.2019.04.16.06.44.47; Tue, 16 Apr 2019 06:45:04 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727233AbfDPNoD (ORCPT + 99 others); Tue, 16 Apr 2019 09:44:03 -0400 Received: from out30-45.freemail.mail.aliyun.com ([115.124.30.45]:42808 "EHLO out30-45.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726037AbfDPNoD (ORCPT ); Tue, 16 Apr 2019 09:44:03 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R871e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01f04391;MF=aaron.lu@linux.alibaba.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---0TPTXiJY_1555422231; Received: from aaronlu(mailfrom:aaron.lu@linux.alibaba.com fp:SMTPD_---0TPTXiJY_1555422231) by smtp.aliyun-inc.com(127.0.0.1); Tue, 16 Apr 2019 21:43:58 +0800 Date: Tue, 16 Apr 2019 21:43:51 +0800 From: Aaron Lu To: Peter Zijlstra Cc: mingo@kernel.org, tglx@linutronix.de, pjt@google.com, tim.c.chen@linux.intel.com, torvalds@linux-foundation.org, linux-kernel@vger.kernel.org, subhra.mazumdar@oracle.com, fweisbec@gmail.com, keescook@chromium.org, kerrnel@google.com, Aubrey Li Subject: Re: [RFC][PATCH 13/16] sched: Add core wide task selection and scheduling. Message-ID: <20190416134350.GA66092@aaronlu> References: <20190218165620.383905466@infradead.org> <20190218173514.667598558@infradead.org> <20190402064612.GA46500@aaronlu> <20190402082812.GJ12232@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190402082812.GJ12232@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 02, 2019 at 10:28:12AM +0200, Peter Zijlstra wrote: > On Tue, Apr 02, 2019 at 02:46:13PM +0800, Aaron Lu wrote: ... > > Perhaps we can test if max is on the same cpu as class_pick and then > > use cpu_prio_less() or core_prio_less() accordingly here, or just > > replace core_prio_less(max, p) with cpu_prio_less(max, p) in > > pick_next_task(). The 2nd obviously breaks the comment of > > core_prio_less() though: /* cannot compare vruntime across CPUs */. > > Right, so as the comment states, you cannot directly compare vruntime > across CPUs, doing that is completely buggered. > > That also means that the cpu_prio_less(max, class_pick) in pick_task() > is buggered, because there is no saying @max is on this CPU to begin > with. I find it difficult to decide which task of fair_sched_class having higher priority when the two tasks belong to different CPUs. Please see below. > Another approach would be something like the below: > > > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -87,7 +87,7 @@ static inline int __task_prio(struct tas > */ > > /* real prio, less is less */ > -static inline bool __prio_less(struct task_struct *a, struct task_struct *b, bool runtime) > +static inline bool __prio_less(struct task_struct *a, struct task_struct *b, u64 vruntime) > { > int pa = __task_prio(a), pb = __task_prio(b); > > @@ -104,21 +104,25 @@ static inline bool __prio_less(struct ta > if (pa == -1) /* dl_prio() doesn't work because of stop_class above */ > return !dl_time_before(a->dl.deadline, b->dl.deadline); > > - if (pa == MAX_RT_PRIO + MAX_NICE && runtime) /* fair */ > - return !((s64)(a->se.vruntime - b->se.vruntime) < 0); > + if (pa == MAX_RT_PRIO + MAX_NICE) /* fair */ > + return !((s64)(a->se.vruntime - vruntime) < 0); > > return false; > } > > static inline bool cpu_prio_less(struct task_struct *a, struct task_struct *b) > { > - return __prio_less(a, b, true); > + return __prio_less(a, b, b->se.vruntime); > } > > static inline bool core_prio_less(struct task_struct *a, struct task_struct *b) > { > - /* cannot compare vruntime across CPUs */ > - return __prio_less(a, b, false); > + u64 vruntime = b->se.vruntime; > + > + vruntime -= task_rq(b)->cfs.min_vruntime; > + vruntime += task_rq(a)->cfs.min_vruntime (I used task_cfs_rq() instead of task_rq() above.) Consider the following scenario: (assume cpu0 and cpu1 are siblings of core0) 1 a cpu-intensive task belonging to cgroupA running on cpu0; 2 launch 'ls' from a shell(bash) which belongs to cgroupB; 3 'ls' blocked for a long time(if not forever). Per my limited understanding: the launch of 'ls' cause bash to fork, then the newly forked process' vruntime will be 6ms(probably not precise) ahead of its cfs_rq due to START_DEBIT. Since there is no other running task on that cfs_rq, the cfs_rq's min_vruntime doesn't have a chance to get updated and the newly forked process will always have a distance of 6ms compared to its cfs_rq and it will always 'lose' to the cpu-intensive task belonging to cgroupA by core_prio_less(). No idea how to solve this... > + > + return __prio_less(a, b, vruntime); > } > > static inline bool __sched_core_less(struct task_struct *a, struct task_struct *b)