Received: by 10.192.165.148 with SMTP id m20csp5317899imm; Wed, 9 May 2018 03:06:16 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrNOMZhTr3iZxee5040APujJL0oQz60qhu72HvYf5rT2++EKM1G1Ie0otkoxW1gDNzY0THV X-Received: by 10.98.70.155 with SMTP id o27mr43081318pfi.124.1525860376474; Wed, 09 May 2018 03:06:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525860376; cv=none; d=google.com; s=arc-20160816; b=j4/sjCyZdEPW8Nrpul1aWiQwABQHpziv9qJHSUd9bwlhkGvlimpoiNaYrekCf/uLlg x5acS83Nd3oSCdK/tZvw8dHfW0D1/1j92KBqxxeAGElnTd0/XU1nuxzszvQkayyYsKSg aOdySAUJCLIAQDFP1J/3o042PO/VcKNToeuVCN1yQ2ZNkJ1YqTxzFpiOUFcZEazE43OO d8gXVtf58HswpsrZA6O1V9swkqjDb6SL161AqKOi4gYE5m1b5WSmsx+fkkzjY90S4hsA xjB64dBOVK0KvrelHhfzgWMUIA/b8BE+vaaGU/t+Dy8DxZ/NFc2Z620kaYtlOU/tYyZo ZcdA== 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=vxvWi1nbXzArEdY2FWpKQjZfC+4fz9cL5BzcBusl2zU=; b=UV6ktaw5OTSflHRYPLMFvRhPIckscZ9GWrRG3+Hl7LqjES8ChGvnkWlJvl7uy+BVV1 uH6pullQW0DjoJr50AbgD0ylNeDyYORKWQdOSwgq4lHM5PN+/JIGZrdzU/5A2MATQfoa dMAV8nnqG0hrB218L8dZ8s6VHT7D/vW02GqvAU09gkbxSXU0er3yYCnwVuR3eUUxU5gP NJkzPe4jleX1ZiC/RAkp9gGUhZE1tlbheKNTgXa835F31XregFx2g044pLkuQ4DdhQF/ Lj5bxjYsQV7eOO5CucuU0NCzdkTQh7SEMOpSVHy+nY/pcW4mcAV2RGQmUzDzyw0P1Uqz MQlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=CyWqbwWa; 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 d1-v6si27519671plr.410.2018.05.09.03.06.01; Wed, 09 May 2018 03:06:16 -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=bombadil.20170209 header.b=CyWqbwWa; 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 S934366AbeEIKFH (ORCPT + 99 others); Wed, 9 May 2018 06:05:07 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:58232 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933685AbeEIKFF (ORCPT ); Wed, 9 May 2018 06:05:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.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=vxvWi1nbXzArEdY2FWpKQjZfC+4fz9cL5BzcBusl2zU=; b=CyWqbwWafKV6Zf2sXkV9lV9tl 7qkCuOoRQq3zHHt9eQeJ+DPUwsCusEf2rX6rMuGTZaCrGMNMpTvzMjOTgZlA0YvZcl7gh5A6hoemi bQfwvFmgAEwpT7NiYyW52ItS+UD+2f8okx1wWKP8M9MPBATD/rIyisQ2/+NWr0T/ukmCXKH4hEoWA 3mNnfbvL3RtiojXFk8nebvGu5eZ3U8km4ApjaRsyKgNX3OG46haKmPBEzmBMxl4zStOG/CRJ0YExb cZPphEktkaHm8WIeFTlzfSQc8umgEyAGxlTQEZYfzmWLTpgynJTRq2E36VHqHS7UVKAzwcXTa6ltZ 3W5i8QY4w==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fGLxy-0001Rb-0S; Wed, 09 May 2018 10:04:58 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id F1F922029FA13; Wed, 9 May 2018 12:04:55 +0200 (CEST) Date: Wed, 9 May 2018 12:04:55 +0200 From: Peter Zijlstra To: Johannes Weiner Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-block@vger.kernel.org, cgroups@vger.kernel.org, Ingo Molnar , Andrew Morton , Tejun Heo , Balbir Singh , Mike Galbraith , Oliver Yang , Shakeel Butt , xxx xxx , Taras Kondratiuk , Daniel Walker , Vinayak Menon , Ruslan Ruslichenko , kernel-team@fb.com Subject: Re: [PATCH 6/7] psi: pressure stall information for CPU, memory, and IO Message-ID: <20180509100455.GK12217@hirez.programming.kicks-ass.net> References: <20180507210135.1823-1-hannes@cmpxchg.org> <20180507210135.1823-7-hannes@cmpxchg.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180507210135.1823-7-hannes@cmpxchg.org> User-Agent: Mutt/1.9.5 (2018-04-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 07, 2018 at 05:01:34PM -0400, Johannes Weiner wrote: > +static void psi_clock(struct work_struct *work) > +{ > + u64 some[NR_PSI_RESOURCES] = { 0, }; > + u64 full[NR_PSI_RESOURCES] = { 0, }; > + unsigned long nonidle_total = 0; > + unsigned long missed_periods; > + struct delayed_work *dwork; > + struct psi_group *group; > + unsigned long expires; > + int cpu; > + int r; > + > + dwork = to_delayed_work(work); > + group = container_of(dwork, struct psi_group, clock_work); > + > + /* > + * Calculate the sampling period. The clock might have been > + * stopped for a while. > + */ > + expires = group->period_expires; > + missed_periods = (jiffies - expires) / MY_LOAD_FREQ; > + group->period_expires = expires + ((1 + missed_periods) * MY_LOAD_FREQ); > + > + /* > + * Aggregate the per-cpu state into a global state. Each CPU > + * is weighted by its non-idle time in the sampling period. > + */ > + for_each_online_cpu(cpu) { Typically when using online CPU state, you also need hotplug notifiers to deal with changes in the online set. You also typically need something like cpus_read_lock() around an iteration of online CPUs, to avoid the set changing while you're poking at them. The lack for neither is evident or explained. > + struct psi_group_cpu *groupc = per_cpu_ptr(group->cpus, cpu); > + unsigned long nonidle; > + > + 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; > + } > + } > + > + for (r = 0; r < NR_PSI_RESOURCES; r++) { > + /* Finish the weighted aggregation */ > + some[r] /= max(nonidle_total, 1UL); > + full[r] /= max(nonidle_total, 1UL); > + > + /* Accumulate stall time */ > + group->some[r] += some[r]; > + group->full[r] += full[r]; > + > + /* Calculate recent pressure averages */ > + calc_avgs(group->avg_some[r], some[r], missed_periods); > + calc_avgs(group->avg_full[r], full[r], missed_periods); > + } > + > + /* Keep the clock ticking only when there is action */ > + if (nonidle_total) > + schedule_delayed_work(dwork, MY_LOAD_FREQ); > +}