Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3641144imm; Tue, 17 Jul 2018 08:03:30 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcQi/a7VYopLuBZIZHJYJOx80bwDlDNpH8zRLPlhkti0IM1b5MTUmVNr3Ay0iX9wZPXHkav X-Received: by 2002:a17:902:9b82:: with SMTP id y2-v6mr1983671plp.69.1531839810407; Tue, 17 Jul 2018 08:03:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531839810; cv=none; d=google.com; s=arc-20160816; b=p0C8jNxqiiUdAl0OMx/kD2zXc2k5t4lExbjKQnMz4MeuWXNdbzuAYRWqGJwByd4s7O FP2XUv6M4qJl/tTbHBkl4JtrQMlq5bg4oLzPCrKXAkKvZNS1P85zgvj1+w6Iwvy/1ybe FY00tpAX4Zu6rBjtR6Pjja9HkT3Q58fYXSVilHxd2B7hScVh34dHbA+axS8H5Hd/3HJf acl2gaCAaR8txs+A6VIxVpjD2iqMba+2u5AGaL569qAnLqSEZB5qDFHnKzocdP7POslK ZfmDSjbh88e+sZvKFsmJcHFim7P4kRPVXK8ZFJaOg6L0hUGhktHRuttnEpOKxK8EWHF6 k6QA== 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=xukDW9g+x+JE5sTurwzSx8e/tRij4uBDgfD9bhsMJhg=; b=YeHgoJu+fOlDBRAry/gT+n14TgkY4SK6/ydtMQNNwe5rv4zEEBz6bEHiu/nfo8Q/jY BpHVPYyHyllOe2Rnw0i2wH/EkzadPFwTdvxOqu+IbiPz8TyOoccYF/nzFmPqbfKQavm3 uDDaD4uwWQTq5bgpC1CuV5qsn5rVPOaiyPSzMfhbtkGRVgjbs2AXBDswm7DjOcb9YJ6t KHlGUv7+Wu/665bdaXWlNRTBrkZK4q4mHn+gwowE/Tf8gFJAun6SpVP+dEW7PV2jCRUB am1gcMG4SAvjuAbbwHU1TBiRsGVlN35ls0MzKi/6cKMXAIE5sGNVXAmba0DZKrjp6cjY 1yyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=1u+da1Qu; 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 f90-v6si1071778plf.390.2018.07.17.08.03.13; Tue, 17 Jul 2018 08:03:30 -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=1u+da1Qu; 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 S1731918AbeGQPfF (ORCPT + 99 others); Tue, 17 Jul 2018 11:35:05 -0400 Received: from merlin.infradead.org ([205.233.59.134]:43664 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731704AbeGQPfF (ORCPT ); Tue, 17 Jul 2018 11:35:05 -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=xukDW9g+x+JE5sTurwzSx8e/tRij4uBDgfD9bhsMJhg=; b=1u+da1QuCoNB3qzUoUWAGAH83 uPaKcrbwKZR+mFn39STBN69Czr7riKV/I/YuJ9/3K2jnXPznC/EcKLT3yL8wlHsqIRlQgxceX258l SDrJ3FTR2m9WIvRhY5x+ZGarqhL4kHB0a4Njhkyn0vBWlrC4A7cDBgpqxaC0jarj+TavbVwtOrSsX X913q0dxkbF1iR0EbHd5Lgp1FAYyKdLC2ynyBAGT8N7zFloDq6F4U6lqygFfiA6VhmVl9M4MFulzI mpUP4+l+7YyLPvyE7Unqc+cj+pRsNGzBnt9SrnAs/eCpgDI3GJ7cHX87PIOususYbsU7yxgbv8Gl0 R/b6hhuHQ==; 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 1ffRU1-00019Y-DO; Tue, 17 Jul 2018 15:01:45 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 9AEF620275F36; Tue, 17 Jul 2018 17:01:42 +0200 (CEST) Date: Tue, 17 Jul 2018 17:01:42 +0200 From: Peter Zijlstra To: Johannes Weiner Cc: Ingo Molnar , Andrew Morton , Linus Torvalds , Tejun Heo , Suren Baghdasaryan , Vinayak Menon , Christopher Lameter , Mike Galbraith , Shakeel Butt , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: Re: [PATCH 08/10] psi: pressure stall information for CPU, memory, and IO Message-ID: <20180717150142.GG2494@hirez.programming.kicks-ass.net> References: <20180712172942.10094-1-hannes@cmpxchg.org> <20180712172942.10094-9-hannes@cmpxchg.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180712172942.10094-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 Thu, Jul 12, 2018 at 01:29:40PM -0400, Johannes Weiner wrote: > +static bool psi_update_stats(struct psi_group *group) > +{ > + u64 some[NR_PSI_RESOURCES] = { 0, }; > + u64 full[NR_PSI_RESOURCES] = { 0, }; > + unsigned long nonidle_total = 0; > + unsigned long missed_periods; > + unsigned long expires; > + int cpu; > + int r; > + > + 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 could pin the online CPUs here, but the noise introduced > + * by missing up to one sample period from CPUs that are going > + * away shouldn't matter in practice - just like the noise of > + * previously offlined CPUs returning with a non-zero sample. But why!? cpuu_read_lock() is neither expensive nor complicated. So why try and avoid it? > + */ > + for_each_online_cpu(cpu) { > + struct psi_group_cpu *groupc = per_cpu_ptr(group->cpus, cpu); > + unsigned long nonidle; > + > + if (!groupc->nonidle_time) > + continue; > + > + nonidle = nsecs_to_jiffies(groupc->nonidle_time); > + groupc->nonidle_time = 0; > + nonidle_total += nonidle; > + > + for (r = 0; r < NR_PSI_RESOURCES; r++) { > + struct psi_resource *res = &groupc->res[r]; > + > + some[r] += (res->times[0] + res->times[1]) * nonidle; > + full[r] += res->times[1] * nonidle; > + > + /* It's racy, but we can tolerate some error */ > + res->times[0] = 0; > + res->times[1] = 0; > + } > + } > + > + /* > + * Integrate the sample into the running statistics that are > + * reported to userspace: the cumulative stall times and the > + * decaying averages. > + * > + * Pressure percentages are sampled at PSI_FREQ. We might be > + * called more often when the user polls more frequently than > + * that; we might be called less often when there is no task > + * activity, thus no data, and clock ticks are sporadic. The > + * below handles both. > + */ > + > + /* total= */ > + for (r = 0; r < NR_PSI_RESOURCES; r++) { > + do_div(some[r], max(nonidle_total, 1UL)); > + do_div(full[r], max(nonidle_total, 1UL)); > + > + group->some[r] += some[r]; > + group->full[r] += full[r]; group->some[r] = div64_ul(some[r], max(nonidle_total, 1UL)); group->full[r] = div64_ul(full[r], max(nonidle_total, 1UL)); Is easier to read imo. > + } > + > + /* avgX= */ > + expires = group->period_expires; > + if (time_before(jiffies, expires)) > + goto out; > + > + missed_periods = (jiffies - expires) / PSI_FREQ; > + group->period_expires = expires + ((1 + missed_periods) * PSI_FREQ); > + > + for (r = 0; r < NR_PSI_RESOURCES; r++) { > + u64 some, full; > + > + some = group->some[r] - group->last_some[r]; > + full = group->full[r] - group->last_full[r]; > + > + calc_avgs(group->avg_some[r], some, missed_periods); > + calc_avgs(group->avg_full[r], full, missed_periods); > + > + group->last_some[r] = group->some[r]; > + group->last_full[r] = group->full[r]; > + } > +out: > + mutex_unlock(&group->stat_lock); > + return nonidle_total; > +}