Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp694255pxx; Wed, 28 Oct 2020 14:43:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyTmnd0UhEXQgPbnvj2Gzg49hf9XkZpwFtuqfeBzrocRjjrv9AwrwF/Q6MCbqoT+7xE+EJm X-Received: by 2002:a05:6402:22d9:: with SMTP id dm25mr968721edb.182.1603921430525; Wed, 28 Oct 2020 14:43:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603921430; cv=none; d=google.com; s=arc-20160816; b=Xi3FbmStOQwSrR/t0eix0XdFONn84hBL0RhddI43KAiKQ6A5oLI1pTX1ahY1UdpdvN X6qR9WPE8LTMh2qoeuK9NVCLekZI23MW/DccJD0LLvdqNcUkWScD1PhdtlYmWascmG9z EACrMq6F+w5zvjNjjNv4EB7bkGzuMNie9qd54dkXjix5ecNGDgXO2SiXG2VKxMRdaVWq Oixla6w0KD1xxtyMLKKeoLlcVsdKNCmhiJqh5SdTUNR0yoNXujuhEPi2rIKhgZRYBfYn SfCZzZG/JRJEBQy/b8mInkAFCC1+fUX3+lly/4qX0xEBZBh++Hg4at0DfB8riYtLbFOb eyaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=be4icrz0RAthBmHkcsABA0cMrKaZCZOUSHSUverl/k4=; b=fzhrZN5GZtZ6bNk0jxe0S3N9HgtBkzYmA/NJWfjnLwqOv0ur7+SVHWA0Jqhq/+WSsI kjzM9LNioU8EjrEFa/EuOKXL65axXRsoTRYKF0c308vVUHc4b8fYRTWosYmS1ECN9jBY MSpd73X5eRFq7wvb1MOeZ9pIkoJ1qGXTMSpiakhy0gsm2R9kMKxfAl/mrl6ql4rcOXBD Y4JPGWmm40Cstk0SUflmvueDJny0/Olg3vk3BE72vRmOafpPVk8G6sryPPbKb4BO7V7b BVI8wKF662PfElpmDPyrqrR/7gWjNhzEhC6w5dF3xrnpJUcLY9ivA9/6qcYPq1LaA9ja 9OtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=eKymfijE; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id rh9si446968ejb.71.2020.10.28.14.43.28; Wed, 28 Oct 2020 14:43:50 -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=pass header.i=@google.com header.s=20161025 header.b=eKymfijE; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726408AbgJ1BkH (ORCPT + 99 others); Tue, 27 Oct 2020 21:40:07 -0400 Received: from mail-qv1-f68.google.com ([209.85.219.68]:40977 "EHLO mail-qv1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1833065AbgJ0X6W (ORCPT ); Tue, 27 Oct 2020 19:58:22 -0400 Received: by mail-qv1-f68.google.com with SMTP id t20so1585162qvv.8 for ; Tue, 27 Oct 2020 16:58:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=be4icrz0RAthBmHkcsABA0cMrKaZCZOUSHSUverl/k4=; b=eKymfijEAdnFIVb0Cvy9/o6PON2ivrDulc3gRFHoiPKBnxlM9a1I2JQ/GttbZLDQZ3 x86v5uOzbm66/vtT8mwN/bie4dkbiGunMkScqZlKJp/MvYBoc6oJE63kavE/92REjhBP ftxqBeeDI/IplysVilpwVsfcU54kTCMb2rr+7oEYEXahA8xupZcfBAkotzhk6PHKCIjk XxpT8cWfxQDo0H3Kyr44xfQDsFkb/DKDneBkUAriyGhjREmbaZs0qZiKW2/+ZnjRUiCZ NZwtu1IwBrt2YX3HKL6xuhCGZHp8O86xKjhHPdgTPGflG/316P5T2LD3z0R/t+78FOGK 044A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=be4icrz0RAthBmHkcsABA0cMrKaZCZOUSHSUverl/k4=; b=N9cTHvb0HFpdVOnrd/Q2VTuHASSYsM8+7OXdQ2ENWavMHnx84X5QqQelHkC0ckzQ/B j36YEBw9HVv6s5ky1E9gIudxT1uU5z8DjVTtf/XLHSS1aj8rmPee5OaUxe+HT5PDXGp7 4USBV6zVeL6g4IcYQXh36glsoTpUJf8n9Dr1OaNdydcKf1vmwaDH+BNTjURFzCsNiubA wd939YZutEO2iCow6ZLtQYbSMRd/NIdoTK1hbwS4tSXVVrWKI6+FNG0Ut8DmpOIaNSH8 3t5pzJOxWBe2YQGbYB7Q6JCFmHVuGnf2U94ESITi5Zpcqbctu50lAPYZK0XU5jlAJQJJ cXhg== X-Gm-Message-State: AOAM533Q9k5Mlv0jVfgEoG7zL3zq25w9ZcjzE2o4QNK8VNomC/VoH9hW 4lqsZjm2x2fzWgypWPcXQcg0HDhSWZ09mwLpaADMwA== X-Received: by 2002:a0c:ecce:: with SMTP id o14mr5519869qvq.2.1603843100009; Tue, 27 Oct 2020 16:58:20 -0700 (PDT) MIME-Version: 1.0 References: <20201023032944.399861-1-joshdon@google.com> <20201023071905.GL2611@hirez.programming.kicks-ass.net> In-Reply-To: <20201023071905.GL2611@hirez.programming.kicks-ass.net> From: Josh Don Date: Tue, 27 Oct 2020 16:58:08 -0700 Message-ID: Subject: Re: [PATCH 1/3] sched: better handling for busy polling loops To: Peter Zijlstra Cc: g@hirez.programming.kicks-ass.net, Ingo Molnar , Juri Lelli , Vincent Guittot , "David S. Miller" , Jakub Kicinski , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Paolo Bonzini , Eric Dumazet , linux-kernel , netdev@vger.kernel.org, kvm@vger.kernel.org, Xi Wang Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 23, 2020 at 12:19 AM Peter Zijlstra wrote: > > On Thu, Oct 22, 2020 at 08:29:42PM -0700, Josh Don wrote: > > Busy polling loops in the kernel such as network socket poll and kvm > > halt polling have performance problems related to process scheduler load > > accounting. > > AFAICT you're not actually fixing the load accounting issue at all. Halt polling is an ephemeral state, and the goal is not to adjust the accounting, but rather to allow wake up balance to identify polling cpus. > > This change also disables preemption for the duration of the busy > > polling loop. This is important, as it ensures that if a polling thread > > decides to end its poll to relinquish cpu to another thread, the polling > > thread will actually exit the busy loop and potentially block. When it > > later becomes runnable, it will have the opportunity to find an idle cpu > > via wakeup cpu selection. > > At the cost of inducing a sleep+wake cycle; which is mucho expensive. So > this could go either way. No data presented. I can take a look at getting some data on that. What I do have is data that reflects an overall improvement in machine efficiency. On heavily loaded hosts, we were able to recoup ~2% of cycles. > > +void prepare_to_busy_poll(void) > > +{ > > + struct rq __maybe_unused *rq = this_rq(); > > + unsigned long __maybe_unused flags; > > + > > + /* Preemption will be reenabled by end_busy_poll() */ > > + preempt_disable(); > > + > > +#ifdef CONFIG_SMP > > + raw_spin_lock_irqsave(&rq->lock, flags); > > + /* preemption disabled; only one thread can poll at a time */ > > + WARN_ON_ONCE(rq->busy_polling); > > + rq->busy_polling++; > > + raw_spin_unlock_irqrestore(&rq->lock, flags); > > +#endif > > Explain to me the purpose of that rq->lock usage. This was required in a previous iteration, but failed to drop after a refactor. > > +int continue_busy_poll(void) > > +{ > > + if (!single_task_running()) > > + return 0; > > Why? If there's more, we'll end up in the below condition anyway. > Migrating a task over won't necessarily set need_resched. Though it does make sense to allow check_preempt_curr to set it directly in this case. > > diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h > > index 28709f6b0975..45de468d0ffb 100644 > > --- a/kernel/sched/sched.h > > +++ b/kernel/sched/sched.h > > @@ -1003,6 +1003,8 @@ struct rq { > > > > /* This is used to determine avg_idle's max value */ > > u64 max_idle_balance_cost; > > + > > + unsigned int busy_polling; > > This is a good location, cache-wise, because? > > > #endif /* CONFIG_SMP */ > > > > #ifdef CONFIG_IRQ_TIME_ACCOUNTING Good call out, I didn't consider that.