From patchwork Thu Jan 31 01:51:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Kaehlcke X-Patchwork-Id: 10789537 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 69478139A for ; Thu, 31 Jan 2019 01:51:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7031030738 for ; Thu, 31 Jan 2019 01:51:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6EB7F3068C; Thu, 31 Jan 2019 01:51:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0B47B3073A for ; Thu, 31 Jan 2019 01:51:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729304AbfAaBvu (ORCPT ); Wed, 30 Jan 2019 20:51:50 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:41771 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725768AbfAaBvs (ORCPT ); Wed, 30 Jan 2019 20:51:48 -0500 Received: by mail-pl1-f195.google.com with SMTP id u6so709806plm.8 for ; Wed, 30 Jan 2019 17:51:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=lselr77VbRukcmW0lwT2WV7foY0fOvPgFp9daJmbpgQ=; b=GjjNRjXotCc6CcoOE+HHc/2SAtyLhq9ILQQhmQB+Wqd/6EkZjmhAaIIv/5soJVrVkn 1bPWMfERHTxvE+s7tSIa01dj5MKmS4UhJHdH/HfQdVpdLuOgFVpMKilzm7H06rdV/lbz S8Nvcue40g1aRy7kJzSeRtxb0cXe9N+7YIYUewnnnYCtWzFMrYZFa1OlFA/qwSqR6NAF QMfWU2dxjBN5hZkrJmnBHT0qVp5iSagbinJ5zk69NLXmT5aNm3rvpJK8LWqVbU90xJxn OkeaINVJo7Jc1kOv39odcAmxXY6ZLPEuzOzhgeDw2JCijdUB3LdXI6rvWWvj6Nr1yCn2 oUpw== X-Gm-Message-State: AJcUukfYCy+Wo3asGEtRRoq7kB4i9Qi+elmdVUJ9BsCi9ev92p3Ilw/H grvgSiTaFJnmEsLDV2YDNhi9vA== X-Google-Smtp-Source: ALg8bN4SAUBlBM/IU9+S3t9Fl7Ith0t7QZ3Azed+PiKxNAaSM0TljGf48TaudtIff5EymeK2epV15w== X-Received: by 2002:a17:902:8607:: with SMTP id f7mr31983502plo.123.1548899507315; Wed, 30 Jan 2019 17:51:47 -0800 (PST) Received: from mka.mtv.corp.google.com ([2620:15c:202:1:75a:3f6e:21d:9374]) by smtp.gmail.com with ESMTPSA id d3sm2775244pgl.64.2019.01.30.17.51.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 Jan 2019 17:51:46 -0800 (PST) From: Matthias Kaehlcke To: "Rafael J . Wysocki" , Viresh Kumar Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Douglas Anderson , Matthias Kaehlcke Subject: [PATCH] cpufreq: Record stats when fast switching is enabled Date: Wed, 30 Jan 2019 17:51:39 -0800 Message-Id: <20190131015139.126890-1-mka@chromium.org> X-Mailer: git-send-email 2.20.1.495.gaa96b0ce6b-goog MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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); } static void cpufreq_stats_clear_table(struct cpufreq_stats *stats) @@ -58,9 +59,6 @@ static ssize_t show_time_in_state(struct cpufreq_policy *policy, char *buf) ssize_t len = 0; int i; - if (policy->fast_switch_enabled) - return 0; - cpufreq_stats_update(stats); for (i = 0; i < stats->state_num; i++) { len += sprintf(buf + len, "%u %llu\n", stats->freq_table[i], @@ -84,9 +82,6 @@ static ssize_t show_trans_table(struct cpufreq_policy *policy, char *buf) ssize_t len = 0; int i, j; - if (policy->fast_switch_enabled) - return 0; - len += snprintf(buf + len, PAGE_SIZE - len, " From : To\n"); len += snprintf(buf + len, PAGE_SIZE - len, " : "); for (i = 0; i < stats->state_num; i++) {