Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3284542imm; Fri, 20 Jul 2018 13:37:24 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdXY/Jvtr96xMvVD0QtVkknSO7BVVN0QPJoiipxaVvg3az/FjiphV08ivMI/BiPe317VdDd X-Received: by 2002:a65:5545:: with SMTP id t5-v6mr3374874pgr.157.1532119044240; Fri, 20 Jul 2018 13:37:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532119044; cv=none; d=google.com; s=arc-20160816; b=nQfdcemtVAvI2NMAzeNdtVv9nrm1sR7mwIRJxmYSA9YPVJgcIx1FCpYw2RFopr1Z+D 0YE+HrrdZTwUomyWe2kMvbid56F634qmd8O3avWKT1YIyeVZ3zflGkQZWz01N4E6sUaB Jab/RhFHYek4Dp+v23h5imY+sIYUPkVIgPDuO8JHntyc/Nj3/j/TqhEEdC8LOJ56T/Et oEs3deWgy9GtEz5LGcdXpvZLNK0ZbphjeyXQpLMn6adqrgTzyqPlN08nYks88RsSwec7 6N4kLDrw+c8kB5cKpLdDDNg2W2cnTEB5g/kXUQ+RHQwPU2hA7VvVFxeRHdbrOHBrLEkG m2Ng== 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=m3AslJrSGa4nehnkgY8erbmLSTX1GfmZUOxFRyZpk00=; b=N0sxhKVv5OlU97h1Xrac1w9mG0R9iOTtLrh6m1NOgjcBYvP6QP/zJFP2YMZnjOs0uT 30u9kqduzzo7STgTgBKXtGnsT2wchTd+sp+DQ0KQBql6KlC0rZvV5zvPXp5RMLJn1R/z oVzPcyafoIDZSFQDzc2gtnH6VYaJrOmNJUUOf8V0AkKm5EIDeaQyNlzmgYOtIBs5RMDX a1AcJGE61VE99l0UxhnyPnmmL+Lpc23ACe+3M+HLjc3g/vR6S59hgyTi01FZ2fkqeeHB ZV6STm2hwCQZg+FkCKYSjApq3LOOkaa+9baUz8Tz3G8ag8kGWzrlNBiLOrjJ6xigpKL6 qOrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=Bw7AT1Qh; 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 q145-v6si2673905pfq.315.2018.07.20.13.37.09; Fri, 20 Jul 2018 13:37:24 -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=Bw7AT1Qh; 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 S1728459AbeGTVZa (ORCPT + 99 others); Fri, 20 Jul 2018 17:25:30 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:56734 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727825AbeGTVZa (ORCPT ); Fri, 20 Jul 2018 17:25:30 -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=m3AslJrSGa4nehnkgY8erbmLSTX1GfmZUOxFRyZpk00=; b=Bw7AT1QhwIyLllWPym/ObCcIa aMQipMCI7ue8NSvd2gNzBmagWYuNwazbNgvTjCmlZktCqhKTrfR4MecTzZMs9r/s7mOmXJXC9B+2y gLJh52QBN7KleX2Jk9WQnBOeNiHUknwaowOaTuhf2+XtJg2qG9dmjQfPJIPPmhJWbx0wSfM3zjoRR AuJ00r6VXE7np61qBxUTLgz5G5FqWQMrQGiBzRL9Q+elD4oIWYsQ3aEPDnsk+xvF4rokNE1AndoAj S8ow6KuKhWgR0jJ8lKqWtyDMikXj0eNbH5UF5xh5Wqljx2G97RHNrlSf9YukM0wtKPsOEj84XVjFU tF4x7gH2w==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=worktop) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fgc7c-0006CJ-Ag; Fri, 20 Jul 2018 20:35:28 +0000 Received: by worktop (Postfix, from userid 1000) id DD9BB6E0A92; Fri, 20 Jul 2018 22:35:24 +0200 (CEST) Date: Fri, 20 Jul 2018 22:35:24 +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: <20180720203524.GD4920@worktop.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.5.22.1 (2013-10-16) 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) > +{ > + 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; > + } > + } An alternative for this, that also allows that ondemand update, but without spamming the rq->lock would be something like: struct psi_group_cpu { u32 tasks[3]; u32 cpu_state : 2; u32 mem_state : 2; u32 io_state : 2; u32 :0; u64 last_update_time; u32 nonidle; u32 full[2]; u32 some[3]; } ____cacheline_aligned_in_smp; /* Allocate _2_ copies */ DEFINE_PER_CPU_ALIGNED_SHARED(struct psi_group_cpu[2], psi_cpus); struct psi_group global_psi = { .cpus = &psi_cpus[0], }; u64 sums[6] = { 0, }; for_each_possible_cpu(cpu) { struct psi_group_cpu *pgc = per_cpu_ptr(group->cpus, cpu); u32 *active, *shadow; active = &pgc[0].nonidle; shadow = &pgc[1].nonidle; /* * Compare the active count to the shadow count * if different, compute the delta and update the shadow * copy. * This only writes to the shadow copy (separate line) * and leaves the active a read-only access. */ for (i = 0; i < 6; i++) { u32 old = READ_ONCE(shadow[i]); u32 new = READ_ONCE(active[i]); delta = (new - old); if (!delta) { if (!i) goto next; continue; } WRITE_ONCE(shadow[i], new); sums[i] += delta; } next: ; }