Received: by 10.223.176.5 with SMTP id f5csp3018355wra; Thu, 1 Feb 2018 09:28:40 -0800 (PST) X-Google-Smtp-Source: AH8x227VgLw2kRt68puLFKsu6tBUKing4+UJnqzf2cV1KeZDKLahWmvczndr7ZoBTjtesf/eN+Ri X-Received: by 2002:a17:902:7290:: with SMTP id d16-v6mr2252773pll.303.1517506120552; Thu, 01 Feb 2018 09:28:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517506120; cv=none; d=google.com; s=arc-20160816; b=fna96wloarTooQb+/ROuxrfPiAoF/bvRRPYmEp6kvjALARt1enc3kpJEat8YDlF+UL EMcd37Zpfx9bJS7cbihWUI3Oo3IWOr9cD19Oa2dgyqSh+3AIVuB+jIl7mWoGDw4+0tZr jz9TyEP5GrNu+uOfCetsRxSJaYzUnllBRy/h35ALVMky1Y1ADruQ/K5PDzcX/XUj+vHF NC+Ozq9PP4TJ67zLopB2/mj3PiSud1aiMDDRg7lENoBjc5RL/sKArLnMMJ+Q4RtUyU9/ WN3wHrYpMd9e2Fcbc6lzEfGCBcTqlsgeiLpykCpqKLoWVZ2NsdaKw/T8fGGUbfDvTMUq 5mqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=g+gRWDEJBpYRXjshie5LY7bzpZgaOf63IcoyQau84vg=; b=FNd1GG3eotZp67rB0VLxd5TXNj2P8yZ25vTr+e6G9y2bwpTgSU9rramB1SM0V7NEwa MCgg2cmMtm38rz8zGL1GtiiP9ZaC2ALP/UZrsevSJzGxbFo/E1o4KJtxiutD9iW6Xx5Z 1ei2od8JUZHD1rz3SfAvyoX86XzicCtSduxTBI7XC0fIRvDwq5Lzp4TirBzXiT3qoLlK BPpI8+1G4Zn/oPWk8hFDnzklKAW6HTI2eCYe9/b+AHKOKUUgf6EhC6eYcxdHNCXOZnLN QE8HoAxFmfcj7MtmyF9MaIOuKRXRw3b/P6h8OZtC71vZeh5fGIbBAl6tNmKjWPVIykK9 aEuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bhLIpzYG; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z18si26376pgc.251.2018.02.01.09.28.25; Thu, 01 Feb 2018 09:28:40 -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=pass header.i=@linaro.org header.s=google header.b=bhLIpzYG; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752841AbeBAR0T (ORCPT + 99 others); Thu, 1 Feb 2018 12:26:19 -0500 Received: from mail-io0-f194.google.com ([209.85.223.194]:38071 "EHLO mail-io0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752021AbeBAR0R (ORCPT ); Thu, 1 Feb 2018 12:26:17 -0500 Received: by mail-io0-f194.google.com with SMTP id d13so19988916iog.5 for ; Thu, 01 Feb 2018 09:26:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=g+gRWDEJBpYRXjshie5LY7bzpZgaOf63IcoyQau84vg=; b=bhLIpzYGCz8rrCLuYMW3WCSiPQo/1FchiA7D2YhLqcNwYSODzo7QRYbb0/vZQfWbte 3U1MaNSkhEyboR+8R5YHsUYWxFhlAryfgGqF0oCHPBRANIlnTysjtwV89FJ0cKdwD/ku CrN3fGY1K3Rs00xmuAu/e/x55F889WqHp6l14= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=g+gRWDEJBpYRXjshie5LY7bzpZgaOf63IcoyQau84vg=; b=oaAzVTnUG18Fl7k/TDc7nYvMVzBC3+oBBCU6s0aqGrPtG9oBVShT4zAmWuf5hYpb3o o4o5t+SkfRtBr4ZxjQ6EeC6sY0uY//JWYacEtm0niByJ/K4jXIJbhQVwCxjlYb53YawW sfnjyZyuwzE3ui0NQsoagYcbZehKDtXQ26Vx04QpflsRSipvB34aYGe//jHCrf4Rtg6L YRX1V4wgkuj8JJyLcWFAw4zK416AQSAplpWprIEi3Zk+70gdTtgm0tKA7KIX6/f9Ar1U 5gzxVIq979VGGlGE+iP0EQYyP8QYPFjKVY7ZejmMs4sD48cxpew2kjM7bZse0gxxNwux +qpA== X-Gm-Message-State: AKwxytcvvrhwCKCIk59gVbrKAAfYcVf1JojVOObyW2w3tvdLNKnv+Fxq L3OcDGnUkjl7b97byJpIJucsHu2x4ORu5mvbOv2QqQ== X-Received: by 10.107.53.22 with SMTP id c22mr25652155ioa.189.1517505976661; Thu, 01 Feb 2018 09:26:16 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.50.198 with HTTP; Thu, 1 Feb 2018 09:25:56 -0800 (PST) In-Reply-To: <20180201165249.GC2269@hirez.programming.kicks-ass.net> References: <20171222075934.f6yenvcb2zkf2ysd@hirez.programming.kicks-ass.net> <20171222082915.4lcb7xyyooqyjpia@hirez.programming.kicks-ass.net> <20171222091221.ow5vn3ydx3hj4nht@hirez.programming.kicks-ass.net> <20171222185629.lysjebfifgdwvvhu@hirez.programming.kicks-ass.net> <20171222204247.kyc6ugyyu3ei7zhs@hirez.programming.kicks-ass.net> <20180115082609.GA6320@linaro.org> <20180201165249.GC2269@hirez.programming.kicks-ass.net> From: Vincent Guittot Date: Thu, 1 Feb 2018 18:25:56 +0100 Message-ID: Subject: Re: [RFC PATCH 2/5] sched: Add NOHZ_STATS_KICK To: Peter Zijlstra Cc: Ingo Molnar , linux-kernel , Brendan Jackman , Dietmar Eggemann , Morten Rasmussen Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1 February 2018 at 17:52, Peter Zijlstra wrote: > On Mon, Jan 15, 2018 at 09:26:09AM +0100, Vincent Guittot wrote: > > Would've probably been easier to read if you'd not included the revert > of that timer patch... > >> @@ -9258,21 +9255,11 @@ void nohz_balance_enter_idle(int cpu) >> set_cpu_sd_state_idle(cpu); >> >> /* >> - * implies a barrier such that if the stats_state update is observed >> - * the above updates are also visible. Pairs with stuff in >> - * update_sd_lb_stats() and nohz_idle_balance(). >> + * Each time a cpu enter idle, we assume that it has blocked load and >> + * enable the periodic update of the load of idle cpus >> */ >> - val = atomic_read(&nohz.stats_state); >> - do { >> - new = val + 2; >> - new |= 1; >> - } while (!atomic_try_cmpxchg(&nohz.stats_state, &val, new)); >> + atomic_set(&nohz.stats_state, 1); >> > >> @@ -9422,7 +9408,6 @@ static bool nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) >> return false; >> } >> >> - stats_seq = atomic_read(&nohz.stats_state); >> /* >> * barrier, pairs with nohz_balance_enter_idle(), ensures ... >> */ >> @@ -9432,6 +9417,16 @@ static bool nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) >> >> SCHED_WARN_ON((flags & NOHZ_KICK_MASK) == NOHZ_BALANCE_KICK); >> >> + /* >> + * We assume there will be no idle load after this update and clear >> + * the stats state. If a cpu enters idle in the mean time, it will >> + * set the stats state and trig another update of idle load. >> + * Because a cpu that becomes idle, is added to idle_cpus_mask before >> + * setting the stats state, we are sure to not clear the state and not >> + * check the load of an idle cpu. >> + */ >> + atomic_set(&nohz.stats_state, 0); >> + >> for_each_cpu(balance_cpu, nohz.idle_cpus_mask) { >> if (balance_cpu == this_cpu || !idle_cpu(balance_cpu)) >> continue; >> @@ -9441,8 +9436,10 @@ static bool nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) >> * work being done for other cpus. Next load >> * balancing owner will pick it up. >> */ >> - if (need_resched()) >> + if (need_resched()) { >> + has_blocked_load = true; >> break; >> + } >> >> rq = cpu_rq(balance_cpu); >> >> @@ -9477,12 +9474,12 @@ static bool nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) >> if (flags & NOHZ_BALANCE_KICK) >> rebalance_domains(this_rq, CPU_IDLE); >> >> - if (has_blocked_load || >> - !atomic_try_cmpxchg(&nohz.stats_state, &stats_seq, 0)) { >> - WRITE_ONCE(nohz.next_stats, >> - now + msecs_to_jiffies(LOAD_AVG_PERIOD)); >> - mod_timer(&nohz.timer, nohz.next_stats); >> - } >> + WRITE_ONCE(nohz.next_stats, >> + now + msecs_to_jiffies(LOAD_AVG_PERIOD)); >> + >> + /* There is still blocked load, enable periodic update */ >> + if (has_blocked_load) >> + atomic_set(&nohz.stats_state, 1); >> >> /* >> * next_balance will be updated only when there is a need. > > After this there is no point for stats_state to be atomic anymore. Also > a better name. Ok > > Maybe if I drop the last two patches (and you re-introduce the bits > from: Subject: sched: Optimize nohz stats, that you do need) this all > becomes more readable? Yes. we can do like that