From patchwork Thu Dec 18 12:00:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 42441 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f69.google.com (mail-ee0-f69.google.com [74.125.83.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id AB6A826C8B for ; Thu, 18 Dec 2014 12:02:01 +0000 (UTC) Received: by mail-ee0-f69.google.com with SMTP id d49sf773480eek.0 for ; Thu, 18 Dec 2014 04:02:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:in-reply-to:references :sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=c8hs48oYjxykbeXGYTtF5cEGrvJ2sy0xGktMg6VMD2E=; b=R5EbAv3rI+Bm+o1PisB9VNqQ7TDmjKR20P8PCxuvePb4XG6RlzG9uGimnqDccbxgeK TlKPmijlNhKPpNJ/mqfd/iqA23YXflVxipeCnEggsugOoFPzWHApnA3VHP0C9+06dg2K ugR/XomzeVxog0HwqXX5qmBUQAdT7amhFC/CPvgmDfa5AC87KefpZAdRxYb/LjSUgWRV GT7AUJHpbpgs9HzXcZyvOTCyo3h6EWloJuac+8zKHEPH25utxYlZdGpYEekscTGn449Y 7kJepzc4xzgHFo/wh2+xfGd4csaobYsLH0Vyf0LL5rAF+Va4BlPGaZtbkc27KGK/0yUk xvTw== X-Gm-Message-State: ALoCoQnABpNEFaDFXnZRvbLgEMlwcbyYfj0NwnCHMK/EwHr/krwKGiC74xlLdmWJe6GicIOJCtT+ X-Received: by 10.152.7.99 with SMTP id i3mr227662laa.9.1418904120883; Thu, 18 Dec 2014 04:02:00 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.19.98 with SMTP id d2ls1166304lae.19.gmail; Thu, 18 Dec 2014 04:02:00 -0800 (PST) X-Received: by 10.112.201.72 with SMTP id jy8mr1805798lbc.65.1418904120394; Thu, 18 Dec 2014 04:02:00 -0800 (PST) Received: from mail-lb0-f174.google.com (mail-lb0-f174.google.com. [209.85.217.174]) by mx.google.com with ESMTPS id w1si6716825lag.8.2014.12.18.04.02.00 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 18 Dec 2014 04:02:00 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) client-ip=209.85.217.174; Received: by mail-lb0-f174.google.com with SMTP id 10so840046lbg.33 for ; Thu, 18 Dec 2014 04:02:00 -0800 (PST) X-Received: by 10.112.135.229 with SMTP id pv5mr1889746lbb.52.1418904120308; Thu, 18 Dec 2014 04:02:00 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.142.69 with SMTP id ru5csp1680624lbb; Thu, 18 Dec 2014 04:01:56 -0800 (PST) X-Received: by 10.68.247.98 with SMTP id yd2mr2935461pbc.38.1418904115592; Thu, 18 Dec 2014 04:01:55 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ov3si9608661pbc.228.2014.12.18.04.01.54; Thu, 18 Dec 2014 04:01:55 -0800 (PST) Received-SPF: none (google.com: linux-pm-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752473AbaLRMBy (ORCPT + 12 others); Thu, 18 Dec 2014 07:01:54 -0500 Received: from mail-pd0-f178.google.com ([209.85.192.178]:39184 "EHLO mail-pd0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752459AbaLRMBx (ORCPT ); Thu, 18 Dec 2014 07:01:53 -0500 Received: by mail-pd0-f178.google.com with SMTP id r10so1285047pdi.23 for ; Thu, 18 Dec 2014 04:01:53 -0800 (PST) X-Received: by 10.70.90.140 with SMTP id bw12mr2723950pdb.35.1418904113065; Thu, 18 Dec 2014 04:01:53 -0800 (PST) Received: from localhost ([122.166.148.73]) by mx.google.com with ESMTPSA id nk6sm6577028pdb.89.2014.12.18.04.01.51 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 18 Dec 2014 04:01:52 -0800 (PST) From: Viresh Kumar To: Rafael Wysocki Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, Viresh Kumar Subject: [PATCH 13/13] cpufreq: stats: call cpufreq_stats_update() with locks held Date: Thu, 18 Dec 2014 17:30:30 +0530 Message-Id: <298a359b291b5d867e1c14ba7f9f7caeb64e81c7.1418902789.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.2.0 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: viresh.kumar@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , cpufreq_stats_update() has only two callers, one of them is already taking locks and other one don't. To make locking efficient for cpufreq_stat_notifier_trans(), lets call cpufreq_stats_update() from within locks. Also update show_time_in_state() to call cpufreq_stats_update() after taking locks. Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq_stats.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c index e18735816908..955abb54f9ec 100644 --- a/drivers/cpufreq/cpufreq_stats.c +++ b/drivers/cpufreq/cpufreq_stats.c @@ -39,12 +39,10 @@ static int cpufreq_stats_update(struct cpufreq_stats *stat) { unsigned long long cur_time = get_jiffies_64(); - spin_lock(&cpufreq_stats_lock); if (stat->time_in_state) stat->time_in_state[stat->last_index] += cur_time - stat->last_time; stat->last_time = cur_time; - spin_unlock(&cpufreq_stats_lock); return 0; } @@ -61,7 +59,10 @@ static ssize_t show_time_in_state(struct cpufreq_policy *policy, char *buf) ssize_t len = 0; int i; + spin_lock(&cpufreq_stats_lock); cpufreq_stats_update(stat); + spin_unlock(&cpufreq_stats_lock); + for (i = 0; i < stat->state_num; i++) { len += sprintf(buf + len, "%u %llu\n", stat->freq_table[i], (unsigned long long) @@ -302,9 +303,9 @@ static int cpufreq_stat_notifier_trans(struct notifier_block *nb, if (old_index == new_index) return 0; + spin_lock(&cpufreq_stats_lock); cpufreq_stats_update(stat); - spin_lock(&cpufreq_stats_lock); stat->last_index = new_index; #ifdef CONFIG_CPU_FREQ_STAT_DETAILS stat->trans_table[old_index * stat->max_state + new_index]++;