Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6943784imu; Thu, 31 Jan 2019 02:14:57 -0800 (PST) X-Google-Smtp-Source: ALg8bN69b3brFsgMUKRSEn/ZXQw/Mli4fqnRMIu/EPY6e9FtE1ddnyn7nIMqSveQ4mZTzSeweQj4 X-Received: by 2002:a63:42c1:: with SMTP id p184mr27383973pga.202.1548929697324; Thu, 31 Jan 2019 02:14:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548929697; cv=none; d=google.com; s=arc-20160816; b=wiqfymr7J+vWxiI6YBWXrBCzIhXWiZ3Q2pVnKMGViXKa8OXM3Ia5rikJIAw7JxKtOC IZ1GL8u2YueRxM7JFQlKs+LTdonw6ARugT2Ii0wwuRAJ54LtckhlrGqcYeFogKfBYGEa We3fZZp5PmjDtTa0+3Asbysnjd1HVg7dZHeqTnszUenFWpNSC9+/bIWASz+Nk/R3b6n5 m/WIjRuFjPUvIPzjfQVMX+XQbOfBofk+1LZTsjfwco8ixpZhT57FJ+UZ5noW78HmXK+Q W5IXCFHZrUia78rFGc2OeCAymDsjoKhbM6txkYNAbrOE81V8CyO1loGYiQ6pKpRUYHdT vudA== 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 :in-reply-to:references:mime-version; bh=P/Jws6e3aN00SQWrPyj3MGR+rd8FXHf3OC9KUt0eqsg=; b=k+L6u3MWmlpJqZBRTg3mGgnA63ln0VScV+wV/+IMGmrIak2vHuAir9RV+reWq8knq8 YHhRCNOGVbFL2kVOujU7Tpdnzx8DIrpuUwH/g1q9M3nx9tZkM4/z0wW/gr+EArPb04hP ddmEc4FQpeVaqPSiLRKRtA/4uCO5CMKmVlk8aGOYN9k/Y6cpQUyHshYmYPzR6n9UfSZv xk9KhKS9g/DEF2XCgrJCGrQV5zd9jWFD+EflPnYtNtx4TgS1bizqYKxpiptR+5wxVVsk aUkPiA/wpFIyEmryub0qGFifotKaN0lMIRv6/BXecFyuYLncRZ/zVISGrXgAuPpXiL/g rUdg== ARC-Authentication-Results: i=1; mx.google.com; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b24si3608186pgg.288.2019.01.31.02.14.41; Thu, 31 Jan 2019 02:14:57 -0800 (PST) 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; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732029AbfAaKOP (ORCPT + 99 others); Thu, 31 Jan 2019 05:14:15 -0500 Received: from mail-oi1-f193.google.com ([209.85.167.193]:45288 "EHLO mail-oi1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729635AbfAaKOO (ORCPT ); Thu, 31 Jan 2019 05:14:14 -0500 Received: by mail-oi1-f193.google.com with SMTP id y1so2217220oie.12; Thu, 31 Jan 2019 02:14:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=P/Jws6e3aN00SQWrPyj3MGR+rd8FXHf3OC9KUt0eqsg=; b=Nozow7BYqGqXiwdEkwddmK4enNwZOPLE1YLH2ZoeW1rIC3XpueeNJ0KELR3+e4+u94 HlxHCMhl4m9cSIs1fcqGwe3CyguEN+KUxhuGYjTsHNZJftjsDlG/uN2BM7Pdt8D1s16S iP8KXR08/NKI1ESTzhJUixpYQSFxDJTTel/0ZhOMvMZA3p66+e4exQgtuQgDK6n/a262 ens7gYRwmpb3wLK3LPst3H7YMx/uDRUlrpTn/PRTXvPSm3FmQ+UsIsZxHKTP8v54rCas bEGjPsfDGYE3koCW2P7T5lmuvyEb+u9VdHpKeL2GngLQBPGR8Z1ynjgMkK7AFoFrIePW YwOA== X-Gm-Message-State: AJcUukfOydoO8I3cmtE7xwHY5vBU91wUanXUN+70Qu0fSChfAbh4tb3K +H3TEtHfs+KGl/bsT+InONyGTQkukAcEOAU/AvtSZA== X-Received: by 2002:aca:e715:: with SMTP id e21mr15153294oih.76.1548929653827; Thu, 31 Jan 2019 02:14:13 -0800 (PST) MIME-Version: 1.0 References: <20190131015139.126890-1-mka@chromium.org> <20190131083004.rkxehycu4pbbx52s@vireshk-i7> <20190131100753.fjh6o3smmcjedxmz@vireshk-i7> In-Reply-To: <20190131100753.fjh6o3smmcjedxmz@vireshk-i7> From: "Rafael J. Wysocki" Date: Thu, 31 Jan 2019 11:14:03 +0100 Message-ID: Subject: Re: [PATCH] cpufreq: Record stats when fast switching is enabled To: Viresh Kumar Cc: "Rafael J. Wysocki" , Matthias Kaehlcke , "Rafael J . Wysocki" , Linux PM , Linux Kernel Mailing List , Douglas Anderson 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 On Thu, Jan 31, 2019 at 11:07 AM Viresh Kumar wrote: > > On 31-01-19, 11:03, Rafael J. Wysocki wrote: > > On Thu, Jan 31, 2019 at 9:30 AM Viresh Kumar wrote: > > > > > > On 30-01-19, 17:51, Matthias Kaehlcke wrote: > > > > When fast switching is enabled currently no cpufreq stats are > > > > recorded and the corresponding sysfs attributes appear empty (see > > > > also commit 1aefc75b2449 ("cpufreq: stats: Make the stats code > > > > non-modular")). > > > > > > > > Record the stats after a successful fast switch and re-enable access > > > > through sysfs when fast switching is enabled. Since > > > > cpufreq_stats_update() can now be called in interrupt context (during > > > > a fast switch) disable local IRQs while holding the stats spinlock. > > > > > > > > Signed-off-by: Matthias Kaehlcke > > > > --- > > > > The change is so simple that I wonder if I'm missing some important > > > > reason why the stats can't/shouldn't be updated during/after a fast > > > > switch ... > > > > > > > > I would expect that holding the stats spinlock briefly in > > > > cpufreq_stats_update() shouldn't be a problem. In theory it would > > > > also be an option to have a per stats lock, though it seems overkill > > > > from my (possibly ignorant) point of view. > > > > --- > > > > drivers/cpufreq/cpufreq.c | 8 +++++++- > > > > drivers/cpufreq/cpufreq_stats.c | 11 +++-------- > > > > 2 files changed, 10 insertions(+), 9 deletions(-) > > > > > > > > diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c > > > > index e35a886e00bcf..63aadb0bbddfe 100644 > > > > --- a/drivers/cpufreq/cpufreq.c > > > > +++ b/drivers/cpufreq/cpufreq.c > > > > @@ -1857,9 +1857,15 @@ EXPORT_SYMBOL(cpufreq_unregister_notifier); > > > > unsigned int cpufreq_driver_fast_switch(struct cpufreq_policy *policy, > > > > unsigned int target_freq) > > > > { > > > > + unsigned int freq; > > > > + > > > > target_freq = clamp_val(target_freq, policy->min, policy->max); > > > > > > > > - return cpufreq_driver->fast_switch(policy, target_freq); > > > > + freq = cpufreq_driver->fast_switch(policy, target_freq); > > > > + if (freq) > > > > + cpufreq_stats_record_transition(policy, freq); > > > > + > > > > + return freq; > > > > } > > > > EXPORT_SYMBOL_GPL(cpufreq_driver_fast_switch); > > > > > > > > diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c > > > > index 1572129844a5b..21b919bfaeccf 100644 > > > > --- a/drivers/cpufreq/cpufreq_stats.c > > > > +++ b/drivers/cpufreq/cpufreq_stats.c > > > > @@ -30,11 +30,12 @@ struct cpufreq_stats { > > > > static void cpufreq_stats_update(struct cpufreq_stats *stats) > > > > { > > > > unsigned long long cur_time = get_jiffies_64(); > > > > + unsigned long flags; > > > > > > > > - spin_lock(&cpufreq_stats_lock); > > > > + spin_lock_irqsave(&cpufreq_stats_lock, flags); > > > > stats->time_in_state[stats->last_index] += cur_time - stats->last_time; > > > > stats->last_time = cur_time; > > > > - spin_unlock(&cpufreq_stats_lock); > > > > + spin_unlock_irqrestore(&cpufreq_stats_lock, flags); > > > > } > > > > > > The only problem that I can think of (or recall) is that this routine > > > also gets called when time_in_state sysfs file is read and that can > > > end up taking lock which the scheduler's hotpath will wait for. > > > > What about the extra locking overhead in the scheduler context? > > What about using READ_ONCE/WRITE_ONCE here ? Not sure if we really > need locking in this particular case. If that works, then fine, but ISTR some synchronization issues related to that.