Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6568534imu; Wed, 30 Jan 2019 17:52:18 -0800 (PST) X-Google-Smtp-Source: ALg8bN6MQS4RlfqTp7xCIHsB3qhYVldzKv7y3sKXPjPBieX40cE421ZAgJuLgOj+Paco4X5ZRe4i X-Received: by 2002:a17:902:b112:: with SMTP id q18mr32909498plr.255.1548899537950; Wed, 30 Jan 2019 17:52:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548899537; cv=none; d=google.com; s=arc-20160816; b=iWsY18F/VlxiJF/zL/NjUE7L2ix684TI6NsGjH7/YZQTIcRFKA/jNrR++NP5wX/9gT CAQYUf+qONqyGZ0HGpONr3F9FFgL6qbLtS+4lTSYSwW70ypWwS6BE2pCfZMTUCcT1ZG5 lLtB649UVG4z4i3bJ25uEZWk4O4TaNNixHBUdVqxDayefnWUn8CmeKmaIHH0ahVRTLtN 9qj1u6IyctRdavyR0L72Xysc+osilfulR9HWkpi9s/E6CNKE897sdyW7Ea5dOsqdW04d hAx7rBo74+zVLbWvkH2OI3NLMERnnTa32sf+u3DBdEmR1IxEFShdDN8Vz+F/ZhbhU+3K RsyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=lselr77VbRukcmW0lwT2WV7foY0fOvPgFp9daJmbpgQ=; b=IQ34loqU9/QRlG8ZrNsFKtHY7yanZwa8L4j8ZbW4Ead3CsS9gwefcMbdHpJnpszf10 3TdiEtpZ2A6v6C6rrk0jc/gJFClCGI0P+DoSwrBuCZuyZsTtULkzh4D/jiIUxbvpqeBR 57UQ82R0Mv4TwZSmC7gTGEAKSVyUMgetupWknY71bptgpKWlUxdfK3abMvW/bXJmX3VC K+Z8Izzd7/cThvXpQqUWG3dV88J00dh2g/DSmEQ6viR80A00M1sG1VhK/pW5bUuovW9o iwTH6QV+rwrixf8NpNquWmNlR0iFdp20OCI7iePfcSlvtIYNcR0Ub+tb2epKwVeZIzpq XfZw== 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i1si2877867pgi.480.2019.01.30.17.52.02; Wed, 30 Jan 2019 17:52:17 -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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729509AbfAaBvv (ORCPT + 99 others); Wed, 30 Jan 2019 20:51:51 -0500 Received: from mail-pl1-f194.google.com ([209.85.214.194]:43855 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729038AbfAaBvs (ORCPT ); Wed, 30 Jan 2019 20:51:48 -0500 Received: by mail-pl1-f194.google.com with SMTP id gn14so704613plb.10 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=ZAjSBQIlTpPfykTlVbP4NqKUUhgkcKAeYEA2BfPM4B9Gs4ryMmozyBLmcoXJIV2VJn 73duYfUa14IPkYIlcI85caNoGj/zxvgDMBW11g9F7Qe+jeuwotjX12cNdf4e9L7oL995 MqYEAInsP/7SPC9uIhTezMpVg6sdACGngu0+v8IfzvCaBsh2Lm1bYhNl3Q3EcedvJH04 OZ5Sedq/QFhdMcBCK6Wfzd265nidSmLuSfBOTNeazBM+1T49q+PNhaw5B40j+YsNYh61 /qV9VfYiqUnW9WV6O1Hv7DLnsVY8EXwKFIS+XUEG0axre+v30j7xXr3Uafj5W8uKpqXv qKgg== X-Gm-Message-State: AJcUukfZH0NHespQ+8k+nyose3VwO9Tc95fL24ImPiSdDyrrPhxHNZgh 5Qk5joelRD/AmNbljJangzy4Sw== 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 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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++) { -- 2.20.1.495.gaa96b0ce6b-goog