Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp695534imm; Fri, 3 Aug 2018 09:58:33 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdhUyxlUixUz7ASfg0f3ZvZYZvMubdrYjP/DZsIQEUaI2s4rdB2BcaCMoow+a5IYzeNbbyA X-Received: by 2002:a17:902:bd97:: with SMTP id q23-v6mr4344030pls.311.1533315513126; Fri, 03 Aug 2018 09:58:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533315513; cv=none; d=google.com; s=arc-20160816; b=gGPzdPfIBriL4/7jslO+g/1XXsN3JQ/jWfGaCnqSeCfJKPjAMwj1zOBYG5O9QNUOBG uBQAW/sAsDTH/2+yGOeRJ2kWK1cutb7TopjTre351b2xpzziGcZ116i7qabsxK0LHpQj P0+T5D0ka6vw9pUksZI2SwaiziExMLtw6k/Pefl2+irNmdE6lk8nGv34IlsBXc0Tjf/P L9r+0E4f/n7bJHR+w8N5exZu0TijUxYc5WlD9ps2nvoEX7crk5BvlBBBEt0nfpzw3gOL PQFx0u/jI7i6I0N6He6+MKhEwoCQlPZAt6asJJqOdtLDYyfQmIeq/QTUvq3Eps1norAW oZ2w== 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=us6WDSBVfFK9MXOUFs3re4B3d5LTNqnZtZ8/cNrTON0=; b=ftSKeZwfomHA3oZsBOLMSnjKzE2FNeR47feWl9gzFXngd2CEOh6B089hqXYfTPlZad +Jcrt8BWJ3xJdub0kjMsI/2FhVs6wneyBWLqMFVevtQtAx/pevb5/qW3QsmBdLMYXkVs cctlJf3C90jpH/yos5dcSXim0KVnHDBJSZT+6troZai3vH+QvgwG41Jg2xeHHGJjDzjp a2q7XNqIuG92em4m8RH+yBwaisDER1sbUj0YHf5cqfWH5ezLJylrJQvFs0gW847H2yzz NPPZPOI73HBE69DtmyFD7DoC8cEzZAn8TZkOuXf8tP4B0/XSvieratW1Pdk2DqAQpa00 u2Zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b="o/b8Hnvq"; 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 p17-v6si5967739pfd.76.2018.08.03.09.58.18; Fri, 03 Aug 2018 09:58:33 -0700 (PDT) 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=merlin.20170209 header.b="o/b8Hnvq"; 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 S1728734AbeHCSyQ (ORCPT + 99 others); Fri, 3 Aug 2018 14:54:16 -0400 Received: from merlin.infradead.org ([205.233.59.134]:44138 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727171AbeHCSyP (ORCPT ); Fri, 3 Aug 2018 14:54:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.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=us6WDSBVfFK9MXOUFs3re4B3d5LTNqnZtZ8/cNrTON0=; b=o/b8HnvqHg/3a8NSDjpfeR3LB /uBc0NQBp0ceNu55U83fcxvbvX7cBRgZzMAJF1xLPFzGPB86WdPEyQjU4lc8vOGheZdOeF4YLaIJB JTPgOoS7GxtP76Z4pCjQpaOOrrlYlYQkxWxtMboBpVCflApu2EaRBdy1KB7j6KzbYjEw4+rEf7V8/ gMq528JYuxk9zJdHZEB0BgMjJHOEbjhd1fj0WhqspwqI68AyY8MYLiV/jPm5vkhOqzhEOSYlSxB8P /L3uei7haPxqrWVytdNq3f8IGAABe4YzYSDyDZy6Rq5BX7+UKNijeydqOoAnmddo9riTO9vVCdrve 6Kcajhf8A==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fldNc-0007HU-TO; Fri, 03 Aug 2018 16:56:45 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 89ECC20267E51; Fri, 3 Aug 2018 18:56:41 +0200 (CEST) Date: Fri, 3 Aug 2018 18:56:41 +0200 From: Peter Zijlstra To: Johannes Weiner Cc: Ingo Molnar , Andrew Morton , Linus Torvalds , Tejun Heo , Suren Baghdasaryan , Daniel Drake , Vinayak Menon , Christopher Lameter , Mike Galbraith , Shakeel Butt , Peter Enderborg , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: Re: [PATCH 8/9] psi: pressure stall information for CPU, memory, and IO Message-ID: <20180803165641.GA2476@hirez.programming.kicks-ass.net> References: <20180801151958.32590-1-hannes@cmpxchg.org> <20180801151958.32590-9-hannes@cmpxchg.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180801151958.32590-9-hannes@cmpxchg.org> User-Agent: Mutt/1.10.0 (2018-05-17) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 01, 2018 at 11:19:57AM -0400, Johannes Weiner wrote: > +static bool test_state(unsigned int *tasks, int cpu, enum psi_states state) > +{ > + switch (state) { > + case PSI_IO_SOME: > + return tasks[NR_IOWAIT]; > + case PSI_IO_FULL: > + return tasks[NR_IOWAIT] && !tasks[NR_RUNNING]; > + case PSI_MEM_SOME: > + return tasks[NR_MEMSTALL]; > + case PSI_MEM_FULL: > + /* > + * Since we care about lost potential, things are > + * fully blocked on memory when there are no other > + * working tasks, but also when the CPU is actively > + * being used by a reclaimer and nothing productive > + * could run even if it were runnable. > + */ > + return tasks[NR_MEMSTALL] && > + (!tasks[NR_RUNNING] || > + cpu_curr(cpu)->flags & PF_MEMSTALL); I don't think you can do this, there is nothing that guarantees cpu_curr() still exists. > + case PSI_CPU_SOME: > + return tasks[NR_RUNNING] > 1; > + case PSI_NONIDLE: > + return tasks[NR_IOWAIT] || tasks[NR_MEMSTALL] || > + tasks[NR_RUNNING]; > + default: > + return false; > + } > +} > + > +static bool psi_update_stats(struct psi_group *group) > +{ > + u64 deltas[NR_PSI_STATES - 1] = { 0, }; > + unsigned long missed_periods = 0; > + unsigned long nonidle_total = 0; > + u64 now, expires, period; > + int cpu; > + int s; > + > + mutex_lock(&group->stat_lock); > + > + /* > + * Collect the per-cpu time buckets and average them into a > + * single time sample that is normalized to wallclock time. > + * > + * For averaging, each CPU is weighted by its non-idle time in > + * the sampling period. This eliminates artifacts from uneven > + * loading, or even entirely idle CPUs. > + * > + * We don't need to synchronize against CPU hotplugging. If we > + * see a CPU that's online and has samples, we incorporate it. > + */ > + for_each_online_cpu(cpu) { > + struct psi_group_cpu *groupc = per_cpu_ptr(group->pcpu, cpu); > + u32 uninitialized_var(nonidle); urgh.. I can see why the compiler got confused. Dodgy :-) > + > + BUILD_BUG_ON(PSI_NONIDLE != NR_PSI_STATES - 1); > + > + for (s = PSI_NONIDLE; s >= 0; s--) { > + u32 time, delta; > + > + time = READ_ONCE(groupc->times[s]); > + /* > + * In addition to already concluded states, we > + * also incorporate currently active states on > + * the CPU, since states may last for many > + * sampling periods. > + * > + * This way we keep our delta sampling buckets > + * small (u32) and our reported pressure close > + * to what's actually happening. > + */ > + if (test_state(groupc->tasks, cpu, s)) { > + /* > + * We can race with a state change and > + * need to make sure the state_start > + * update is ordered against the > + * updates to the live state and the > + * time buckets (groupc->times). > + * > + * 1. If we observe task state that > + * needs to be recorded, make sure we > + * see state_start from when that > + * state went into effect or we'll > + * count time from the previous state. > + * > + * 2. If the time delta has already > + * been added to the bucket, make sure > + * we don't see it in state_start or > + * we'll count it twice. > + * > + * If the time delta is out of > + * state_start but not in the time > + * bucket yet, we'll miss it entirely > + * and handle it in the next period. > + */ > + smp_rmb(); > + time += cpu_clock(cpu) - groupc->state_start; > + } The alternative is adding an update to scheduler_tick(), that would ensure you're never more than nr_cpu_ids * TICK_NSEC behind. > + delta = time - groupc->times_prev[s]; > + groupc->times_prev[s] = time; > + > + if (s == PSI_NONIDLE) { > + nonidle = nsecs_to_jiffies(delta); > + nonidle_total += nonidle; > + } else { > + deltas[s] += (u64)delta * nonidle; > + } > + } > + }