From patchwork Thu Feb 19 11:32:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 44834 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1945D21554 for ; Thu, 19 Feb 2015 11:35:04 +0000 (UTC) Received: by mail-wi0-f200.google.com with SMTP id r20sf5195581wiv.3 for ; Thu, 19 Feb 2015 03:35:03 -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=kVrXFoYR41fK7/2TR/e+crrws5fVI8W113ILKeuaMIU=; b=lOx7fba+SZ91GldoglUFJ1+SMLpx3PfSi+twODtaZidEeMS5/bJ8WLIbTiD4KZZ3nA Exu//Rwvv6BQo9rjPGVraASvK4bqLKPwZg8skJJzebvRt3QvSxUSlNPJDC7al7cAik+7 l0X2LzYuBVNqZFtd3zAHB6o8x2jBOl3+jypr3j+ptA0QdtY3lOgz8wcEcEzcYH1jagwf XwtxeGoPQ/xnrwfRFK9T2GVQZDF12Trf+OwoPNrHylQO9LxzZ1871dr9rTxlejuckznq ZTkRol7VtFKlWcH+blyAvmeFmId/B88IZF9dPmw4jW8AV6tqGKf1Sl0O10piJFMAoilR msjQ== X-Gm-Message-State: ALoCoQk9Tb41waeSrEbyrt0R5ptG51bgwyJIxvrw1t5uOGYjhB2QnEfT2Y0MNor1Lir99eOC11Xi X-Received: by 10.180.81.34 with SMTP id w2mr637029wix.2.1424345703377; Thu, 19 Feb 2015 03:35:03 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.170.131 with SMTP id am3ls73366lac.35.gmail; Thu, 19 Feb 2015 03:35:03 -0800 (PST) X-Received: by 10.152.37.138 with SMTP id y10mr3598227laj.88.1424345703214; Thu, 19 Feb 2015 03:35:03 -0800 (PST) Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com. [209.85.217.181]) by mx.google.com with ESMTPS id js5si17017632lab.173.2015.02.19.03.35.03 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Feb 2015 03:35:03 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) client-ip=209.85.217.181; Received: by lbiz11 with SMTP id z11so6824507lbi.5 for ; Thu, 19 Feb 2015 03:35:03 -0800 (PST) X-Received: by 10.112.14.196 with SMTP id r4mr3604817lbc.86.1424345703119; Thu, 19 Feb 2015 03:35:03 -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.35.133 with SMTP id h5csp432157lbj; Thu, 19 Feb 2015 03:35:01 -0800 (PST) X-Received: by 10.66.101.66 with SMTP id fe2mr6994316pab.118.1424345700506; Thu, 19 Feb 2015 03:35:00 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u14si364614pdi.41.2015.02.19.03.34.59; Thu, 19 Feb 2015 03:35:00 -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 S1753426AbbBSLeI (ORCPT + 11 others); Thu, 19 Feb 2015 06:34:08 -0500 Received: from mail-pa0-f42.google.com ([209.85.220.42]:34950 "EHLO mail-pa0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753417AbbBSLeF (ORCPT ); Thu, 19 Feb 2015 06:34:05 -0500 Received: by padfa1 with SMTP id fa1so8897461pad.2 for ; Thu, 19 Feb 2015 03:34:04 -0800 (PST) X-Received: by 10.66.250.225 with SMTP id zf1mr6948460pac.31.1424345644614; Thu, 19 Feb 2015 03:34:04 -0800 (PST) Received: from localhost ([122.172.249.58]) by mx.google.com with ESMTPSA id in1sm23468126pbc.19.2015.02.19.03.34.03 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 19 Feb 2015 03:34:03 -0800 (PST) From: Viresh Kumar To: Rafael Wysocki Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, sboyd@codeaurora.org, prarit@redhat.com, skannan@codeaurora.org, Viresh Kumar Subject: [PATCH V2 11/20] cpufreq: Manage governor usage history with 'policy->last_governor' Date: Thu, 19 Feb 2015 17:02:13 +0530 Message-Id: <073c66088540954706ba5ffc0e4c2efa4759d197.1424345053.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.3.0.rc0.44.ga94655d 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.181 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: , History of which governor was used last is common to all CPUs within a policy and maintaining it per-cpu isn't the best approach for sure. Apart from wasting memory, this also increases the complexity of managing this data structure as it has to be updated for all CPUs. To make that somewhat simpler, lets store this information in a new field 'last_governor' in struct cpufreq_policy and update it on removal of last cpu of a policy. Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq.c | 30 +++++++++++++++--------------- include/linux/cpufreq.h | 1 + 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 20d5f4590c4b..b7cd1bf97044 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -115,9 +115,6 @@ static DEFINE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_data); static DEFINE_RWLOCK(cpufreq_driver_lock); DEFINE_MUTEX(cpufreq_governor_lock); -/* This one keeps track of the previously set governor of a removed CPU */ -static DEFINE_PER_CPU(char[CPUFREQ_NAME_LEN], cpufreq_cpu_governor); - /* Flag to suspend/resume CPUFreq governors */ static bool cpufreq_suspended; @@ -1028,7 +1025,7 @@ static void cpufreq_init_policy(struct cpufreq_policy *policy) memcpy(&new_policy, policy, sizeof(*policy)); /* Update governor of new_policy to the governor used before hotplug */ - gov = find_governor(per_cpu(cpufreq_cpu_governor, policy->cpu)); + gov = find_governor(policy->last_governor); if (gov) pr_debug("Restoring governor %s for cpu %d\n", policy->governor->name, policy->cpu); @@ -1422,14 +1419,15 @@ static int __cpufreq_remove_dev_prepare(struct device *dev, pr_err("%s: Failed to stop governor\n", __func__); return ret; } - - strncpy(per_cpu(cpufreq_cpu_governor, cpu), - policy->governor->name, CPUFREQ_NAME_LEN); } - down_read(&policy->rwsem); + down_write(&policy->rwsem); cpus = cpumask_weight(policy->cpus); - up_read(&policy->rwsem); + + if (has_target() && cpus == 1) + strncpy(policy->last_governor, policy->governor->name, + CPUFREQ_NAME_LEN); + up_write(&policy->rwsem); if (cpu != policy->cpu) { sysfs_remove_link(&dev->kobj, "cpufreq"); @@ -2142,7 +2140,8 @@ EXPORT_SYMBOL_GPL(cpufreq_register_governor); void cpufreq_unregister_governor(struct cpufreq_governor *governor) { - int cpu; + struct cpufreq_policy *policy, *tpolicy; + unsigned long flags; if (!governor) return; @@ -2150,12 +2149,13 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor) if (cpufreq_disabled()) return; - for_each_present_cpu(cpu) { - if (cpu_online(cpu)) - continue; - if (!strcmp(per_cpu(cpufreq_cpu_governor, cpu), governor->name)) - strcpy(per_cpu(cpufreq_cpu_governor, cpu), "\0"); + /* clear last_governor for all inactive policies */ + read_lock_irqsave(&cpufreq_driver_lock, flags); + for_each_inactive_policy(policy, tpolicy) { + if (!strcmp(policy->last_governor, governor->name)) + strcpy(policy->last_governor, "\0"); } + read_unlock_irqrestore(&cpufreq_driver_lock, flags); mutex_lock(&cpufreq_governor_mutex); list_del(&governor->governor_list); diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index 2ee4888c1f47..48e37c07eb84 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -80,6 +80,7 @@ struct cpufreq_policy { struct cpufreq_governor *governor; /* see below */ void *governor_data; bool governor_enabled; /* governor start/stop flag */ + char last_governor[CPUFREQ_NAME_LEN]; /* last governor used */ struct work_struct update; /* if update_policy() needs to be * called, but you're in IRQ context */