Received: by 10.223.176.5 with SMTP id f5csp3103475wra; Mon, 29 Jan 2018 08:49:18 -0800 (PST) X-Google-Smtp-Source: AH8x224qXenDZKvHmlvJ12Bp+Pt+hBWlAiT8u2QWnpr4wneScqc7/2tsTygMV0tRtBMLWpDaNmE1 X-Received: by 10.98.170.24 with SMTP id e24mr27444297pff.177.1517244558324; Mon, 29 Jan 2018 08:49:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517244558; cv=none; d=google.com; s=arc-20160816; b=IU9KLiFBAYnQx4e1+qnavxfF83kAU54rNCGimutECWISNZ9yMBFMfsXWf3s18x/T97 NoiKf5ne5XbzZkbt90oUmjxVor9gzUTUhkvlQbSmLyDdWplDCyN5Kz9IYPh0NMiqvtT2 PsFzQYKPw4o/otfS3i8FNpNTDDKS3TJChmL4PI5hC+GGIbix/6Uy25IEY0WopmmLXOA9 HFIb73VRfGHgWK2Q5+ZRkQfa2T/rSO1ArfZzFCT647l7nS7P8LXfyGepAIjAQ+e5wgID MzOZ4ig60xx1hzrimOSzio+8ZRAAgJE99J0dadBX8Y9k7Sg0jUPgyL7azAVA0F6kul1k LfJA== 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:dmarc-filter:arc-authentication-results; bh=AXyvhWprHZfeU9gH9Y3ptCnA74IRhyBKjHJvRdnEKhU=; b=lyOjCEZVRpnlrWQ6BCdVtj6FInxPl5tILmdVJRT4YFd75kRPiuMZsj0coR0W1wQfUk wnTQkSG0btfsos4LvGKsYEzFctHZFhJCvm9D5jqOrPfdTn25WsbZ+h+xxid4P1nZSqj6 a7HT3fNCGGOX1HWYlnUgXLqGsvbqN5pBIN3IPa7KKo8YbKRsMsaI2JOsNp0pUvqWlspG ksSyZYMqfB3FZtrYWWZE6kwxdNUI1JXYGSAK7ERmu0RzorVF+f9EXM9WXUAeH11zA9tk ZpZ6qhraSI+x2YbQqQ3H1+io699gkk9fW5K6cpQXEIxFdPj0eCqrVopp0xnkjqKiNj9U 01MQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a70si7744800pge.448.2018.01.29.08.49.03; Mon, 29 Jan 2018 08:49:18 -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; 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 S1751373AbeA2Qsj (ORCPT + 99 others); Mon, 29 Jan 2018 11:48:39 -0500 Received: from mail.kernel.org ([198.145.29.99]:47046 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751249AbeA2Qsh (ORCPT ); Mon, 29 Jan 2018 11:48:37 -0500 Received: from localhost (i16-les03-th2-31-37-47-191.sfr.lns.abo.bbox.fr [31.37.47.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6F90921720; Mon, 29 Jan 2018 16:48:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6F90921720 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=frederic@kernel.org Date: Mon, 29 Jan 2018 17:48:33 +0100 From: Frederic Weisbecker To: Peter Zijlstra Cc: Ingo Molnar , LKML , Chris Metcalf , Thomas Gleixner , Luiz Capitulino , Christoph Lameter , "Paul E . McKenney" , Wanpeng Li , Mike Galbraith , Rik van Riel Subject: Re: [PATCH 4/6] sched/isolation: Residual 1Hz scheduler tick offload Message-ID: <20180129164832.GC2942@lerouge> References: <1516320140-13189-1-git-send-email-frederic@kernel.org> <1516320140-13189-5-git-send-email-frederic@kernel.org> <20180129153839.GT2269@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180129153839.GT2269@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 29, 2018 at 04:38:39PM +0100, Peter Zijlstra wrote: 1;4205;0c> On Fri, Jan 19, 2018 at 01:02:18AM +0100, Frederic Weisbecker wrote: > > When a CPU runs in full dynticks mode, a 1Hz tick remains in order to > > keep the scheduler stats alive. However this residual tick is a burden > > for bare metal tasks that can't stand any interruption at all, or want > > to minimize them. > > > > The usual boot parameters "nohz_full=" or "isolcpus=nohz" will now > > outsource these scheduler ticks to the global workqueue so that a > > housekeeping CPU handles those remotely. > > > > Note that in the case of using isolcpus, it's still up to the user to > > affine the global workqueues to the housekeeping CPUs through > > /sys/devices/virtual/workqueue/cpumask or domains isolation > > "isolcpus=nohz,domain". > > I would very much like a few words on why sched_class::task_tick() is > safe to call remote -- from a quick look I think it actually is, but it > would be good to have some words here. Let's rather say I can't prove that it is safe, given the amount of code that is behind throughout the various flavour of scheduler features. But as far as I checked several times, it seems that nothing is accessed locally on ::scheduler_tick(). Everything looks fetched from the runqueue struct target while it is locked. If we ever find local references such as "current" or "__this_cpu_*" in the path, we'll have to fix them. > > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > > index d72d0e9..c79500c 100644 > > --- a/kernel/sched/core.c > > +++ b/kernel/sched/core.c > > @@ -3062,7 +3062,82 @@ u64 scheduler_tick_max_deferment(void) > > > > return jiffies_to_nsecs(next - now); > > } > > -#endif > > + > > +struct tick_work { > > + int cpu; > > + struct delayed_work work; > > +}; > > + > > +static struct tick_work __percpu *tick_work_cpu; > > + > > +static void sched_tick_remote(struct work_struct *work) > > +{ > > + struct delayed_work *dwork = to_delayed_work(work); > > + struct tick_work *twork = container_of(dwork, struct tick_work, work); > > + int cpu = twork->cpu; > > + struct rq *rq = cpu_rq(cpu); > > + struct rq_flags rf; > > + > > + /* > > + * Handle the tick only if it appears the remote CPU is running > > + * in full dynticks mode. The check is racy by nature, but > > + * missing a tick or having one too much is no big deal. > > + */ > > + if (!idle_cpu(cpu) && tick_nohz_tick_stopped_cpu(cpu)) { > > + rq_lock_irq(rq, &rf); > > + update_rq_clock(rq); > > + rq->curr->sched_class->task_tick(rq, rq->curr, 0); > > + rq_unlock_irq(rq, &rf); > > + } > > + > > + queue_delayed_work(system_unbound_wq, dwork, HZ); > > Do we want something that tracks the actual interrer arrival time of > this work, such that we can detect and warn if the book-keeping thing is > failing to keep up? Yeah perhaps we can have some sort of check to make sure we got a tick after some reasonable delay since the last sched in of the current remote task. > > > +} > > + > > +static void sched_tick_start(int cpu) > > +{ > > + struct tick_work *twork; > > + > > + if (housekeeping_cpu(cpu, HK_FLAG_TICK)) > > + return; > > This all looks very static :-(, you can't reconfigure this nohz_full > crud after boot? Unfortunately yes. In fact making the nohz interface dynamically available through cpuset is the next big step. > > > + WARN_ON_ONCE(!tick_work_cpu); > > + > > + twork = per_cpu_ptr(tick_work_cpu, cpu); > > + twork->cpu = cpu; > > + INIT_DELAYED_WORK(&twork->work, sched_tick_remote); > > + queue_delayed_work(system_unbound_wq, &twork->work, HZ); > > +} > > Similarly, I think we want a few words about how unbound workqueues are > expected to behave vs NUMA. > > AFAICT unbound workqueues by default prefer to run on a cpu in the same > node, but if no cpu is available, it doesn't go looking for the nearest > node that does have a cpu, it just punts to whatever random cpu. Yes, and in fact you just made me look into wq_select_unbound_cpu() and it looks worse than that. If the current CPU is not in the wq_unbound_cpumask, a random one is picked up from that global cpumask without trying a near one in the current node. Looks like room for improvement on the workqueue side. I'll see what I can do. Thanks.