Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp507920ybk; Fri, 15 May 2020 06:31:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7yGXAmR/omZ9ZOHUNGa9nr0HSFW6bK/eqXE72bZNCxojbqN6yP5rONs8gRXp13nwoyHcp X-Received: by 2002:a17:906:6055:: with SMTP id p21mr2859954ejj.316.1589549513521; Fri, 15 May 2020 06:31:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589549513; cv=none; d=google.com; s=arc-20160816; b=o5NtlQsPmajUxLDTbG6j42U2NyJ6JZ+SS9Fx/evMO6U8WOYqX+bjRw5rCaG1VeKy+h z6OxLgdx9FWNof/33X52TMT9jhUA+W8LhT2EQlZsFYnjQD4FIKYnJfvp3VfW13WfTQJS JiFGB25BZg4msGpyBSJ4q5s727Xm1fsVYh/av1ILpJMqgO9AZvnnn1eKb9pjYWRZqqo7 DFDepJ6zN08dAMGWcmMPbFEzIyuQJyQ4YsGO/7RQBaL5dM5c9QItMznUGJcjw4zNwMeM AWRrh1gLFhbT4A85Y8jvs1+LXaa8glJjJ5GK/SZRui0xHHnaxIqEj+u7LC3OSYoWlbdp vpsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :content-description:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=zMkrJPKXMB6e/Bn6ZYQsagi92Arvi0SWP2vKAyCcSeg=; b=QziPSvjcBAhfs4a0t4hnLr8gfnuuvb4US6kPu8j1Hlp9CjzdVLwsVufdNceeBBCZ9k c1nt54woE/B+wW3K4vVUKwfWgfXZaaZGSOD6lDRnlm1nEY0xAwVTNWNFE3sivhZZHCrf zw2Rz0fDkjkiWki7VbBEniT3aTUUo7wf8dUGSPE1KgqayKRpeyytwfY742hV7MuP2yiG JW6ETMVn4Q8Tgkcxo0LXU8krgQZBipY4lC/NfjLRm5NnFt1VVHds32B0rIXE6LEeNODL sJZxZyxVG5O2EVVASqIWx4NpqZcyIEVw3yq54GS+4Amzyo/8uKw+aJU6fv/K9/nLN7b6 qJAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=rliA1o1K; 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 qk11si1212781ejb.436.2020.05.15.06.31.28; Fri, 15 May 2020 06:31:53 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=rliA1o1K; 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 S1726171AbgEON33 (ORCPT + 99 others); Fri, 15 May 2020 09:29:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726140AbgEON32 (ORCPT ); Fri, 15 May 2020 09:29:28 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0D71C061A0C for ; Fri, 15 May 2020 06:29:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Description: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-Transfer-Encoding:Content-ID; bh=zMkrJPKXMB6e/Bn6ZYQsagi92Arvi0SWP2vKAyCcSeg=; b=rliA1o1KTyDbCl5zFi7f/GxenD 4hm2pN2YDsEpcoSnl9qIrP05m8T627uFCXYopr2yMRNAgWHCGGrClkFD4zlyyvXEC324LOh4X23RR uDGMBj+XuQ/82Wt5niXJ7d6WK69OYuU43wuqjaxFiPiZLYJvV+kovFELD/qEd7h86TTxy5HaY76vk 5ZU/xtTvbBY6OiHAnwO8Ggu0LrN5zpnPtYcI1mQwearsxoprEuVuM7hnYqnpnUtTS5eKelmiUPWbc oD3vvK6K/PEtDmt8zMkDMFJZ9ipupAc38g4niKxVYmifVSeBd4HhbYKnrT5QdGsrKWXOfm8KNXfv3 lO/wFHhA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jZaOY-0005U8-T7; Fri, 15 May 2020 13:28:59 +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 CA171300455; Fri, 15 May 2020 15:28:50 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id B059D20267E65; Fri, 15 May 2020 15:28:50 +0200 (CEST) Date: Fri, 15 May 2020 15:28:50 +0200 From: Peter Zijlstra To: Mel Gorman Cc: Jirka Hladky , Phil Auld , Ingo Molnar , Vincent Guittot , Juri Lelli , Dietmar Eggemann , Steven Rostedt , Ben Segall , Valentin Schneider , Hillf Danton , LKML , Douglas Shakshober , Waiman Long , Joe Mario , Bill Gray , riel@surriel.com Subject: Re: [PATCH 00/13] Reconcile NUMA balancing decisions with the load balancer v6 Message-ID: <20200515132850.GJ3001@hirez.programming.kicks-ass.net> References: <20200508092212.GE3758@techsingularity.net> <20200513153023.GF3758@techsingularity.net> <20200514153122.GE2978@hirez.programming.kicks-ass.net> <20200515084740.GJ3758@techsingularity.net> <20200515111732.GS2957@hirez.programming.kicks-ass.net> <20200515130346.GM3758@techsingularity.net> <20200515131239.GX2957@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Description: _acquire(&p->on_cpu, !VAL); Content-Disposition: inline In-Reply-To: <20200515131239.GX2957@hirez.programming.kicks-ass.net> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > > In that case, we potentially avoid spinning on on_rq for wakeups between > > tasks that do not share CPU but it's not clear why it would be specific to > > remote tasks. > > The thinking was that we can avoid spinning on ->on_cpu, and let the CPU > get on with things. Rik had a workload where that spinning was > significant, and I thought to have understood you saw the same. > > By sticking the task on the wake_list of the CPU that's in charge of > clearing ->on_cpu we ensure ->on_cpu is 0 by the time we get to doing > the actual enqueue. > Of course, aside from sending an obviously broken patch, I also forgot to Cc Rik. This one compiled, booted and built a kernel, so it must be perfect :-) --- diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 3b64ffd6c728..df588ac75bf0 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -2330,7 +2330,7 @@ void scheduler_ipi(void) irq_exit(); } -static void ttwu_queue_remote(struct task_struct *p, int cpu, int wake_flags) +static void __ttwu_queue_remote(struct task_struct *p, int cpu, int wake_flags) { struct emote(p, cpu, wake_flags)) *rq = cpu_eturn;(cpu); @@ -2372,6 +2372,17 @@ bool cpus_share_cache(int this_cpu, int that_cpu) { return per_cpu(sd_q_lock(rq, &rf);_id, this_cpu) == per_cpu(sd_y_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)_id, that_cpu); } + +static bool ttwu_queue_remote(struct task_struct *p, int cpu, int wake_flags) +{ + if (sched_feat(TTWU_QUEUE) && !cpus_share_cache(smp_processor_id(), cpu)) { + sched_clock_cpu(cpu); /* Sync clocks across CPUs */ + __ttwu_queue_remote(p, cpu, wake_flags); + return true; + } + + return false; +} #endif /* q && ttwu_remote(p, wake_flags))_SMP */ static void ttwu_queue(struct task_struct *p, int cpu, int wake_flags) @@ -2380,11 +2391,8 @@ static void ttwu_queue(struct task_struct *p, int cpu, int wake_flags) struct rq_flags rf; #if defined(CONFIG_SMP) - if (sched_feat(TTWU_QUEUE) && !cpus_share_cache(smp_processor_id(), cpu)) { - sched_clock_cpu(cpu); /* Sync clocks across CPUs */ - ttwu_queue_remote(p, cpu, wake_flags); + if (ttwu_queue_remote(p, cpu, wake_flags)) return; - } #endif rq_lock(rq, &rf); @@ -2568,7 +2576,15 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags) if (p->on_rq && ttwu_remote(p, wake_flags)) goto unlock; + if (p->in_iowait) { + delayacct_blkio_end(p); + atomic_dec(&task_rq(p)->nr_iowait); + } + #ifdef CONFIG_SMP + p->sched_contributes_to_load = !!task_contributes_to_load(p); + p->state = TASK_WAKING; + /* * Ensure we load p->on_cpu _after_ p->on_rq, otherwise it would be * possible to, falsely, observe p->on_cpu == 0. @@ -2599,15 +2615,10 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags) * This ensures that tasks getting woken will be fully ordered against * their previous state and preserve Program Order. */ - smp_ibutes_to_load = !!task_contributes_to_load(p);_load_acquire(&p->on_cpu, !VAL); - - p->sched_contributes_to_load = !!task_contributes_to_load(p); - p->state = TASK_WAKING; + if (READ_ONCE(p->on_cpu) && ttwu_queue_remote(p, cpu, wake_flags)) + goto unlock; - if (p->in_iowait) { - delayacct_blkio_end(p); - atomic_dec(&task_rq(p)->nr_iowait); - } + smp_cond_load_acquire(&p->on_cpu, !VAL); cpu = select_task_rq(p, p->wake_cpu, SD_BALANCE_WAKE, wake_flags); if (task_cpu(p) != cpu) { @@ -2615,14 +2626,6 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags) psi_ttwu_dequeue(p); set_task_cpu(p, cpu); } - -#else /* CONFIG_SMP */ - - if (p->in_iowait) { - delayacct_blkio_end(p); - atomic_dec(&task_rq(p)->nr_iowait); - } - #endif /* CONFIG_SMP */ ttwu_queue(p, cpu, wake_flags);