Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1510007imm; Wed, 6 Jun 2018 17:51:40 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLVbJwUgBW+ald1g3qFvWrzxiocnNAfHYv3FmXvCQuyZBGn7Y/z1PcKdkUfXlcJigBlizmK X-Received: by 2002:a62:d9c5:: with SMTP id b66-v6mr4507108pfl.41.1528332700047; Wed, 06 Jun 2018 17:51:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528332700; cv=none; d=google.com; s=arc-20160816; b=l0BSGljuXIsMzuuhuNeS9UCi1zWauhHMHcNI13VTrE99ji2TrIIt/pmaIja6dkF+A5 imFouT6GZH/i7GCejsX/DMDz0dYw4p9ByeL9hWXDvllun6iOyQtWhbk2iXj1l/k33/8E L+QRy4XYwlt6rt+xAdQZo1WK4dodSBXwYttLJ35UcH8W1eS3lLNp+942iWnIQ5thDp6e gIYz6sUQ/BE2VYHYpSNba0YgJqPZQVPv5laMGyXeHoDmNHlin+Uxm51D4htoCf0NitZb iXINiyybsczT32IInmzyE3k+THopqgoR7OLhzZ9dCsE8UmtQx9ieO9VuCgZruY24DqGO QPfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=b5jR4waz0kJTh2Dr0wl4gGj/NkC95TTbHHWtCGqHHlw=; b=vK9unXVc2SbcqE+iVwnv8B6FTZkkbjMkL7tft9x+t5lCdpkvhQOx59O02wSBZXMEn1 0HT/HE0DUs3NVcJLsak4Ugf8OaR5B/sTjMAT1QYqbjyFSxnC0JK5fZIopyMOZXo4VNcs u5mqSyY9XExMfRhkwxOgDP5jY4WLyD+3fjzGToFBo0j+U84jE15V55kmb9LmZrTyK2d/ RBsgydfTSrrSlCL7X57A6FKVZRsHvS+CRXLHN8E5S7K2Xs8/rmAyvJo9P9cELwPyvDQ2 Zj05VdzkMUo5DRQA60qbFbyU1U524xTyKYQrJM2lzucUxlhUjfIE07M6A/lNB4sgdIp6 MOHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ilpLBmi1; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 60-v6si23454420ple.65.2018.06.06.17.50.55; Wed, 06 Jun 2018 17:51:40 -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=pass header.i=@google.com header.s=20161025 header.b=ilpLBmi1; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752520AbeFGAqa (ORCPT + 99 others); Wed, 6 Jun 2018 20:46:30 -0400 Received: from mail-it0-f68.google.com ([209.85.214.68]:51629 "EHLO mail-it0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752215AbeFGAq2 (ORCPT ); Wed, 6 Jun 2018 20:46:28 -0400 Received: by mail-it0-f68.google.com with SMTP id n7-v6so10658560itn.1 for ; Wed, 06 Jun 2018 17:46:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=b5jR4waz0kJTh2Dr0wl4gGj/NkC95TTbHHWtCGqHHlw=; b=ilpLBmi1KtyhIKLJ5wMzndh+2ZC5FOhjEY5ilXJGq1/wzpWsDtDPP9pSDJcGui2GQa B/CeA5yaOgwySQRQJ3P/jD+vWUSwjFU3P5elPMNan0i/ozUzseFbf7o7JwRknJg+nlVe IN/LweTSXuiS1wG3SON1iJYQgcqIwZerwRAyZOnXtV0miX568SG+nyMMXWUdgRxWlmt2 IcgCACeOcWAbkMG+lhhYGOAfFDaKwujmBlkPBpyBy21gkxx48Kc71gq9/YdErtOczb6g +6ZHV+4YijbTuTjxpBff5TwYK2GqgrMsM5v+/joRx8wmumXU+va/nhRMWtYDTPtsz/K7 oZvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=b5jR4waz0kJTh2Dr0wl4gGj/NkC95TTbHHWtCGqHHlw=; b=t/aT9VkOqTdkRIZeZ7OwjRvMPDQxge45NKYU6cav9xXqjFj0ZN8b35RJCIaN2eObQt mwQRq3UF7X0Cxwia8plHkw/1JmkHMeCVTuq5y7r1qe69Y3xvqlKDUZaVynbqzWH8flWL 4DbQ4zHx/SoYJRHX3SAtnfymUVS5Uqlldo3pie+Qx6YjBYd8UDxEvl0Cy3ioU3KwWFYj isSXvgmwQkVXPElB/ClBhfQyEvlNpdEWlG4s+YkoxeJMtm+qs8AXOqPeypqiPLDRiIk2 EruhnzFMbFwnkXYetQ4pylRoW9T8Sm0Rp2rsotY+6Uf+T/uLx3NCU1FoO1vR395xU3Qt UiHw== X-Gm-Message-State: APt69E20NGENj9GHWGHWQruhuFrS9e8yXhjjxD9c7LgzFgLYsG+fO8Fd 7McUNunPqEiOqSc+I0sZdBVrdyHPzPWIRpDWUvsc5nVa2cU= X-Received: by 2002:a24:ac0f:: with SMTP id s15-v6mr106253ite.142.1528332387326; Wed, 06 Jun 2018 17:46:27 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:ac0:e444:0:0:0:0:0 with HTTP; Wed, 6 Jun 2018 17:46:26 -0700 (PDT) In-Reply-To: <20180507210135.1823-7-hannes@cmpxchg.org> References: <20180507210135.1823-7-hannes@cmpxchg.org> From: Suren Baghdasaryan Date: Wed, 6 Jun 2018 17:46:26 -0700 Message-ID: Subject: Re: [PATCH 6/7] psi: pressure stall information for CPU, memory, and IO To: Johannes Weiner Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-block@vger.kernel.org, cgroups@vger.kernel.org, Ingo Molnar , Peter Zijlstra , 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 Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Johannes, On Mon, May 7, 2018 at 2:01 PM, 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. > + */ Would it be possible to move this aggregation code (excluding calc_avgs()) into a separate function which is called from here as well as from psi_show() before group->some[] and group->full[] are reported? This would not affect the performance if the information is not requested and at the same time would keep at least the "total" field up-to-date when the data is requested. For calc_avgs() I think we would have to calculate the change in nonidle_total, group->some[] and group->full[] fields differently because a call to psi_show() in the middle of two psi_clock() calls would refresh these fields before 2secs expire, however calculating that change is trivial if we store previous group->some[], group->full[] and nonidle_total values inside psi_clock(). This would require new fields in psi_group struct to store these previous values but the upside is that we would eliminate the problem with reporting potentially stale data (up to 2sec update delay) and provide a function one can use to refresh group->some[] and group->full[] and implement custom averaging. > + for_each_online_cpu(cpu) { > + 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); > +} > + Thanks, Suren.