Received: by 10.192.165.148 with SMTP id m20csp1200174imm; Thu, 10 May 2018 07:09:41 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrznXXXrCdGPXg/ZLm66WBnjSYAPr5Ub9BaweMt+xJDzW3chvmmRNX1BDPfABFqa9XstHhN X-Received: by 2002:a17:902:7446:: with SMTP id e6-v6mr1512726plt.369.1525961381077; Thu, 10 May 2018 07:09:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525961381; cv=none; d=google.com; s=arc-20160816; b=t1RmNFWAdORqD7MzmzI/sxhVwMxMovdwvo3e7w9xS2qqEPH11OeSLx9wYzPid3qbon ikKr/JeuvrSZ1U4BEpYt0ED53mmh8bwtgXhGfpuK4DTVNKilwB/ZdAnHxDBTKJyiO+7S pJZgrDn0bL3QB4X5lZ2YI1qgipNF6WRAtfeuGGKFpkoXImbaJ4iqC9hqGtJOznt/z9CU +NvEcETSoxiCgIA01W8ekohbr+8tj0fbrN3MN6Malyxqe26WaYi4Z+RuGLYRQR47yD3I bsskVtc8E6xKnyVgyCiWuu5pSz9ZAMnOnDhnt7UV9YRREzBoAktLdJc5BOn2BHmkBuCD 0YeA== 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=RRFZzZ7oJZ5YNByGaYSmyxoIywpOqYJqdPDKehPwdAY=; b=KFw1F7WqP1KAA7sEllCWyWMQQAHdXmLziJ9Na69inQA7sXybakCn0AyO8FyD+EsVkv oT/8vMcgkYe2hcXRia1JzsQHQ51uR78RR4ck4eo1IlUH96Yvqjaj9k+rUUlr0kyx3PH5 OAvJqsx3sP2ivsmI6QjdwxVS1js+uSUOheZ+M9745Dbn3qE8skGdlZw/ihEyLMjMqkLO Pnl46BHDZj9eMommFXQfX0afVVsu61WHWDpyFEio18Jae4ffToGu5np9qqULBEEP2NTX Mui86XUiss72alT0fWZhXPjttwiAtiEYuI5mYtilg1A1T8Kxp1Bovo3AHzkKAebht0qS ySow== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@cmpxchg.org header.s=x header.b=3f7DNs8Q; 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=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f7-v6si830046pfa.78.2018.05.10.07.09.25; Thu, 10 May 2018 07:09:41 -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=@cmpxchg.org header.s=x header.b=3f7DNs8Q; 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=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965135AbeEJOIx (ORCPT + 99 others); Thu, 10 May 2018 10:08:53 -0400 Received: from gum.cmpxchg.org ([85.214.110.215]:50164 "EHLO gum.cmpxchg.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934609AbeEJOIv (ORCPT ); Thu, 10 May 2018 10:08:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=cmpxchg.org ; s=x; 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=RRFZzZ7oJZ5YNByGaYSmyxoIywpOqYJqdPDKehPwdAY=; b=3f7DNs8QIA52KDk0PnNOErlrpC VDf2wO+9uuERN1LkvClWDBp0HVltIRvkr5Mreg7wsogxSC5doH3z6WiOqurd7v1zVTo3/ck63oNlN qQRGQTKlHly5w1BV+/CZDn9eUWKc09B/WMI/xJoEirj+moYx4GypZFehQKobTEU3tJEs=; Date: Thu, 10 May 2018 10:10:42 -0400 From: Johannes Weiner To: Peter Zijlstra 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: <20180510141042.GD19348@cmpxchg.org> References: <20180507210135.1823-1-hannes@cmpxchg.org> <20180507210135.1823-7-hannes@cmpxchg.org> <20180509100455.GK12217@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180509100455.GK12217@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 09, 2018 at 12:04:55PM +0200, Peter Zijlstra wrote: > 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. The per-cpu state we access is allocated for each possible CPU, so that is safe (and state being all 0 is semantically sound, too). In a race with onlining, we might miss some per-cpu samples, but would catch them the next time. In a race with offlining, we may never consider the final up to 2s state history of the disappearing CPU; we could have an offlining callback to flush the state, but I'm not sure this would be an actual problem in the real world since the error is small (smallest averaging window is 5 sampling periods) and then would age out quickly. I can certainly add a comment explaining this at least. > > + 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; > > + } > > + }