Received: by 10.223.176.5 with SMTP id f5csp2447117wra; Mon, 5 Feb 2018 04:20:52 -0800 (PST) X-Google-Smtp-Source: AH8x227jEcvpYPt9d9MpTS1DAzpDwo8R/EGTXkGuR7IbHO4brfYH9hy3ohsbaRPG2+OBxAHWxmDh X-Received: by 2002:a17:902:bf41:: with SMTP id u1-v6mr33585131pls.416.1517833252807; Mon, 05 Feb 2018 04:20:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517833252; cv=none; d=google.com; s=arc-20160816; b=BBSDMI08mE8suRepSTCdkrLE7bC+NHgx4NRZcMIwyd+0p91BTADc2N/qSFlJmGu5Yj GqvaOO0OnOJPoxEdxqK4WS71QP5mFtSBkTyg+jf5H5hkF5cHIJmlUxwMYPdWSa90D00l p/+7PZ9GPMwI92Fk+a4E24mS8Ghs9djPe5bLXI9FdjUVKVlQdeUhTQ6FN07zN6oZo7Dx YjzRR1eQiOzNCCduoKx/u3Q7hCfpaa9EiVXVesEXmEya9tk+UnOruTvbA6QZx2p0H7+F HbJXE6KyB0tB9T9h3lN8B0pqMa2c4Aq2QFupaDEpSP/+R8e/3agfAk9vRYayraZfQFoo kvuQ== 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:arc-authentication-results; bh=YYhVBZqURNDpgDv7PoJiJW+aWJ9xgzjfIU2waGqbJgI=; b=0v5+EI+p2d+W4IYvckqZJmcoe2uIIBzeyJJwNAmSgQLGBvSIMddogRP/NdIvXAsKDI lvOjXKbkyINnBkCrjqaj/vn1MgE94G0K9ovIJCvP99VRcLGx2xD49YVjeILLGh2aDLem 2yJu0lnRNYEI794gv+N7Ns68kj86bXogU1C9u0JHecCIkojYsEtfDHofKFNjNSigYq5t w51zM1Xux19od0RJJ5BKwpniWc0ql540o1Wcr34Z1mn7G6jpIFDPVRyeOfowHi/LSeE5 fg88bUZn06T6F76qbWZ7Yor2doQxE5u+AeIszQhnAy6vk3p4DpPf5J0IWYKp9R1jACEy GAZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=D5sJ4skt; 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 n65si586958pfg.219.2018.02.05.04.20.38; Mon, 05 Feb 2018 04:20:52 -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=D5sJ4skt; 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 S1752844AbeBEMT5 (ORCPT + 99 others); Mon, 5 Feb 2018 07:19:57 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:35937 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752291AbeBEMTw (ORCPT ); Mon, 5 Feb 2018 07:19:52 -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=YYhVBZqURNDpgDv7PoJiJW+aWJ9xgzjfIU2waGqbJgI=; b=D5sJ4sktUo1JClZg2Gxw1QESZ YTQz5YX7rDbit2pSHzHXLKEsnz3DXsanXnbdj6tJwYg3Y4UOFYK4xwsf8qHs/W9zaJ+aGk/K/jsRR NTm6b9YP80ySTzqvfyGRZ6jKmFut/1VwKF2HevqtH8fN3LTTdy4sfm5x4xxRcPT4K/kVzOOiG6bCJ 8IxdNlpryDTTpMuuLDeSbnuQG9sMe/wvZZVaBeD4+YwLmDdVa/YIYaSmqrlENSp4Hy3n0XDfTm2FG yi3SqvKyv0BmDTjuWzJ3B2v1EDA0UL3xDjOre2Ra301KOD8AYpA0b9msL5FhfMwUDuKkLNWjS8KqS PUQTeAAcA==; 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.89 #1 (Red Hat Linux)) id 1eifkU-0001is-Ox; Mon, 05 Feb 2018 12:19:50 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id B97F22029F9F9; Mon, 5 Feb 2018 13:19:47 +0100 (CET) Date: Mon, 5 Feb 2018 13:19:47 +0100 From: Peter Zijlstra To: Subhra Mazumdar Cc: Steven Sistare , linux-kernel@vger.kernel.org, mingo@redhat.com, dhaval.giani@oracle.com Subject: Re: [RESEND RFC PATCH V3] sched: Improve scalability of select_idle_sibling using SMT balance Message-ID: <20180205121947.GW2269@hirez.programming.kicks-ass.net> References: <20180129233102.19018-1-subhra.mazumdar@oracle.com> <20180201123335.GV2249@hirez.programming.kicks-ass.net> <911d42cf-54c7-4776-c13e-7c11f8ebfd31@oracle.com> <20180202171708.GN2269@hirez.programming.kicks-ass.net> <93db4b69-5ec6-732f-558e-5e64d9ba0cf9@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <93db4b69-5ec6-732f-558e-5e64d9ba0cf9@oracle.com> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 02, 2018 at 09:37:02AM -0800, Subhra Mazumdar wrote: > In the scheme of SMT balance, if the idle cpu search is done _not_ in the > last run core, then we need a random cpu to start from. If the idle cpu > search is done in the last run core we can start the search from last run > cpu. Since we need the random index for the first case I just did it for > both. That shouldn't be too hard to fix. I think we can simply transpose the CPU number. That is, something like: cpu' = core'_id + (cpu - core_id) should work for most sane cases. We don't give any guarantees this will in fact work, but (almost) all actual CPU enumeration schemes I've seen this should work for. And if it doesn't work, we're not worse of than we are now. I just couldn't readily find a place where we need to do this for cores with the current code. But I think we have one place between LLCs where it can be done: --- diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 7b6535987500..eb8b8d0a026c 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -6109,7 +6109,7 @@ static int select_idle_smt(struct task_struct *p, struct sched_domain *sd, int t if (!static_branch_likely(&sched_smt_present)) return -1; - for_each_cpu(cpu, cpu_smt_mask(target)) { + for_each_cpu_wrap(cpu, cpu_smt_mask(target), target) { if (!cpumask_test_cpu(cpu, &p->cpus_allowed)) continue; if (idle_cpu(cpu)) @@ -6357,8 +6357,17 @@ select_task_rq_fair(struct task_struct *p, int prev_cpu, int sd_flag, int wake_f if (cpu == prev_cpu) goto pick_cpu; - if (wake_affine(affine_sd, p, prev_cpu, sync)) - new_cpu = cpu; + if (wake_affine(affine_sd, p, prev_cpu, sync)) { + /* + * Transpose prev_cpu's offset into this cpu's + * LLC domain to retain the 'random' search offset + * for for_each_cpu_wrap(). + */ + new_cpu = per_cpu(sd_llc_id, cpu) + + (prev_cpu - per_cpu(sd_llc_id, prev_cpu)); + if (unlikely(!cpus_share_cache(new_cpu, cpu))) + new_cpu = cpu; + } } if (sd && !(sd_flag & SD_BALANCE_FORK)) {