Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp666897imp; Thu, 21 Feb 2019 08:47:53 -0800 (PST) X-Google-Smtp-Source: AHgI3IacGxO0/3KT8+xjDPDLYBoI19HshoEyR3BEfcMRopJi7Rt0bNEK0MInn6n0DW2wPidS6W7K X-Received: by 2002:a62:1e82:: with SMTP id e124mr31889362pfe.258.1550767673228; Thu, 21 Feb 2019 08:47:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550767673; cv=none; d=google.com; s=arc-20160816; b=QiG0mEllF0NVQnILR6F5fUnPscJ3vZ9TklzBjKKrgAZDA5fJ6MsR31y+PJ7hs21sLa LrNw3Lvf5asHulMBnvsV3rdKKRFPIrLyq2uHK5gcQgWBFVEqZRlDEdnyLWmXnemNXZVr 2Dp1WW3se3s7rzKXR+X4pgtRETp/+6lpRMXDiM4F9k28BZadxPlQZOjAYAb0rlAgpYpK p9HemCN3u9T323dd5CUt4Vr9vHlgwiPeGXEchZZVXdRHY0dtPgcDIckTiDtvqcMLM2Zm V+RritOkN4ubIt5uvSCcyvfjOZ+owKCc9aXlCXgts50RQbYv7Mfbni+tZ41+CfLyzcWh 1hCA== 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:dkim-signature; bh=pGHJrwXYyWdu/ZzuzXQKBT8exGhGYvkDIyG1GOMNns0=; b=zv2/8vDPQT7Tdto3KhcjqfGG+AdFC6Uy1LVElZFp2rPKmIU1ZPZOIBEIcx3PxYy5hL /bn6KzSnWZPqsw+izPCH2fVywVx+02gOw39ZHoQ0a8ezOShjExi5+MeHkGWiYg2GpnEP iTZ1By97YTaHgBzmVW0vqeVSlBsSJUViSBgPxO2Bm/mHC/Luxphkkm6yqLQjahZZSCAD iNKGd/GvcY+Cz5iAPZgQeCMeGrB74DsY4AzbVsY9SpmILirKVcveLJOU5dykJNFPI1eX Hpyh2a9WjJ8Q1V8iS24knhPhechPmEc2jUd0xpJ4GyzTvgoCJvEZbwARhzeZcLTIAK2t SjIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=AsBsO55C; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y17si22180358plr.275.2019.02.21.08.47.36; Thu, 21 Feb 2019 08:47:53 -0800 (PST) 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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=AsBsO55C; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726434AbfBUQrK (ORCPT + 99 others); Thu, 21 Feb 2019 11:47:10 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:38828 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725943AbfBUQrK (ORCPT ); Thu, 21 Feb 2019 11:47:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.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:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=pGHJrwXYyWdu/ZzuzXQKBT8exGhGYvkDIyG1GOMNns0=; b=AsBsO55C1xcCrdixr2qL829WQ QaW4xlXg+Juc+DnxPlPGZsJ/kqPJkz+tIoE16eOELDAV6RuX22TdBQtLg7NKe8ZZqlce3zVgUvt/n g+8biF3vkalax1n32LdkN0lqREn5bLcpGM615TAKwRtkG3kJauIOVfMeRyhQjmu5ZmZ9hIsCFnh8Z nEpmdOzj24OeyHuhwpice6YxZO9tLy78FGrmwsbM30AnyPDUo7W5UxZjOubj4YpQqFglYwz4Ho9h1 1431Yaabt4c4OvnpWKCKi6X2MOi4X/omxh2cyolZecOnt33jRT/P2P95VxAi72iA5oAfLN4v57/ZQ K1E3o9L7Q==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gwrV2-0003yj-PL; Thu, 21 Feb 2019 16:47:04 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id F3E4D22BBEAF4; Thu, 21 Feb 2019 17:47:02 +0100 (CET) Date: Thu, 21 Feb 2019 17:47:02 +0100 From: Peter Zijlstra To: Valentin Schneider 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 Subject: Re: [RFC][PATCH 15/16] sched: Trivial forced-newidle balancer Message-ID: <20190221164702.GY32534@hirez.programming.kicks-ass.net> References: <20190218165620.383905466@infradead.org> <20190218173514.796920915@infradead.org> <20190221164146.GV32494@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190221164146.GV32494@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 21, 2019 at 05:41:46PM +0100, Peter Zijlstra wrote: > On Thu, Feb 21, 2019 at 04:19:46PM +0000, Valentin Schneider wrote: > > Hi, > > > > On 18/02/2019 16:56, Peter Zijlstra wrote: > > [...] > > > +static bool try_steal_cookie(int this, int that) > > > +{ > > > + struct rq *dst = cpu_rq(this), *src = cpu_rq(that); > > > + struct task_struct *p; > > > + unsigned long cookie; > > > + bool success = false; > > > + > > > + local_irq_disable(); > > > + double_rq_lock(dst, src); > > > + > > > + cookie = dst->core->core_cookie; > > > + if (!cookie) > > > + goto unlock; > > > + > > > + if (dst->curr != dst->idle) > > > + goto unlock; > > > + > > > + p = sched_core_find(src, cookie); > > > + if (p == src->idle) > > > + goto unlock; > > > + > > > + do { > > > + if (p == src->core_pick || p == src->curr) > > > + goto next; > > > + > > > + if (!cpumask_test_cpu(this, &p->cpus_allowed)) > > > + goto next; > > > + > > > + if (p->core_occupation > dst->idle->core_occupation) > > > + goto next; > > > + > > > > IIUC, we're trying to find/steal tasks matching the core_cookie from other > > rqs because dst has been cookie-forced-idle. > > > > If the p we find isn't running, what's the meaning of core_occupation? > > I would have expected it to be 0, but we don't seem to be clearing it when > > resetting the state in pick_next_task(). > > Indeed. We preserve the occupation from the last time around; it's not > perfect but its better than nothing. > > Consider there's two groups; and we just happen to run the other group. > Then our occopation, being what it was last, is still accurate. When > next we run, we'll again get that many siblings together. > > > If it is running, we prevent the stealing if the core it's on is running > > more matching tasks than the core of the pulling rq. It feels to me as if > > that's a balancing tweak to try to cram as many matching tasks as possible > > in a single core, so to me this reads as "don't steal my tasks if I'm > > running more than you are, but I will steal tasks from you if I'm given > > the chance". Is that correct? > > Correct, otherwise an SMT4 with 5 tasks could end up ping-ponging the > one task forever. > > Note that a further condition a little up the callchain from here only > does this stealing if the thread was forced-idle -- ie. it had something > to run anyway. So under the condition where there simple aren't enough > tasks to keep all siblings busy, we'll not compact just cause. Better example; it will avoid stealing a task from a full SMT2 core to fill another.