From patchwork Fri Jan 2 05:46:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 42672 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id BC7B826CB5 for ; Fri, 2 Jan 2015 05:48:00 +0000 (UTC) Received: by mail-la0-f70.google.com with SMTP id hs14sf10363437lab.9 for ; Thu, 01 Jan 2015 21:47:59 -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=ZPltlTWAPToSlzkkxRKfNfQbAf9Tr7ysvVVDBE2XnGY=; b=iqs7IR3n6SiOQlPx3Vo2l4d3JKsc2nHJtfqogDLQxs7vY5QXnXB0oXUMZNGvddzgd4 jYvmMvrFkY3tXTkjHj+VPUPa2foSqRK+C2S9fWl95qiWYuwaMcF2cZA0J0chSnxj/C4K QX6iU2lb0+FJZKwoa5nDAJAuVHiwgeUqCgtywCF53iPitr4dAk10P2h+Ld+FsKdLxOOe ozrKbsF3mEnSdH2GFrTPHUTNyw4YvhocSlOrlVJ8Y2utV9TNa7IuSnBdXIh4mpwcGjfh bXzDI8XT8O2jhDNQW8SFm+diB9TO5iVCjzQ2XScLPTkPNvUnHPEyfX1/akbOp0YzVnxc x74g== X-Gm-Message-State: ALoCoQngYO+pI379u6BdRolLa4wt5u2RHU1RFSQN0IGavYslLetSbi+ihVZ13g7iM86Z42IuJmSM X-Received: by 10.194.92.34 with SMTP id cj2mr4329wjb.5.1420177679619; Thu, 01 Jan 2015 21:47:59 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.87.50 with SMTP id u18ls2350344laz.96.gmail; Thu, 01 Jan 2015 21:47:59 -0800 (PST) X-Received: by 10.152.234.35 with SMTP id ub3mr74980014lac.70.1420177679395; Thu, 01 Jan 2015 21:47:59 -0800 (PST) Received: from mail-lb0-f179.google.com (mail-lb0-f179.google.com. [209.85.217.179]) by mx.google.com with ESMTPS id v20si50357028laz.0.2015.01.01.21.47.59 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 Jan 2015 21:47:59 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.179 as permitted sender) client-ip=209.85.217.179; Received: by mail-lb0-f179.google.com with SMTP id z11so14665256lbi.10 for ; Thu, 01 Jan 2015 21:47:59 -0800 (PST) X-Received: by 10.152.87.100 with SMTP id w4mr74843086laz.71.1420177679303; Thu, 01 Jan 2015 21:47:59 -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.9.200 with SMTP id c8csp114539lbb; Thu, 1 Jan 2015 21:47:58 -0800 (PST) X-Received: by 10.66.163.196 with SMTP id yk4mr117258918pab.57.1420177677450; Thu, 01 Jan 2015 21:47:57 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t3si68097479pdc.177.2015.01.01.21.47.56; Thu, 01 Jan 2015 21:47:57 -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 S1750758AbbABFrz (ORCPT + 12 others); Fri, 2 Jan 2015 00:47:55 -0500 Received: from mail-pd0-f175.google.com ([209.85.192.175]:56847 "EHLO mail-pd0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750716AbbABFrz (ORCPT ); Fri, 2 Jan 2015 00:47:55 -0500 Received: by mail-pd0-f175.google.com with SMTP id g10so23096192pdj.6 for ; Thu, 01 Jan 2015 21:47:55 -0800 (PST) X-Received: by 10.68.202.98 with SMTP id kh2mr120969378pbc.6.1420177674923; Thu, 01 Jan 2015 21:47:54 -0800 (PST) Received: from localhost ([122.167.116.151]) by mx.google.com with ESMTPSA id i11sm45373941pbq.23.2015.01.01.21.47.53 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 01 Jan 2015 21:47:54 -0800 (PST) From: Viresh Kumar To: Rafael Wysocki Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, prarit@redhat.com, skannan@codeaurora.org, Viresh Kumar Subject: [PATCH V2 14/14] cpufreq: stats: call cpufreq_stats_update() with locks held Date: Fri, 2 Jan 2015 11:16:51 +0530 Message-Id: <98184387b402a80ba58e9b727c4dacd95abdd8d4.1420177186.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.179 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. Reviewed-by: Prarit Bhargava 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 95867985ea02..f1b234a09f66 100644 --- a/drivers/cpufreq/cpufreq_stats.c +++ b/drivers/cpufreq/cpufreq_stats.c @@ -40,12 +40,10 @@ static int cpufreq_stats_update(struct cpufreq_stats *stat) { unsigned long long cur_time = get_jiffies_64(); - mutex_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; - mutex_unlock(&cpufreq_stats_lock); return 0; } @@ -62,7 +60,10 @@ static ssize_t show_time_in_state(struct cpufreq_policy *policy, char *buf) ssize_t len = 0; int i; + mutex_lock(&cpufreq_stats_lock); cpufreq_stats_update(stat); + mutex_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) @@ -303,9 +304,9 @@ static int cpufreq_stat_notifier_trans(struct notifier_block *nb, if (old_index == new_index) return 0; + mutex_lock(&cpufreq_stats_lock); cpufreq_stats_update(stat); - mutex_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]++;