From patchwork Tue Jan 27 08:36:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 43821 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2FA1C2409D for ; Tue, 27 Jan 2015 08:37:10 +0000 (UTC) Received: by mail-lb0-f199.google.com with SMTP id f15sf6829440lbj.2 for ; Tue, 27 Jan 2015 00:37:09 -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=8P3+mSKqZcpFzXZAYmccJy+Wp73eAJKBl1Am0enM8CA=; b=U/4Pt09sGzn3ck5Cr7c9YKWyStOLPeH4cx3d6AxvRu9fE3hUZaGaHEre/wxfcUPy5b jIrEMLqE8hRsy+9QSahwtNbBiXyzYhpF7itQ1MkJAGZhq28whU/fbudVbe6BxEOuiHQq jZVtgCLxi8fXf9P2CPTNj0lgMpU8yJ64HubsLFDQXN/Bn4j+csTNhftHivioLVgKuZ0E k+0I3Iju/9l83hj/wwgOI0MAfzA0NseG7WnV6WgWHeUM3s2FHnop3EY27vGOUfac2ag2 tGFr+NbmM46WUoqszacHBhpF3xwCIe8bQDkgnVuVU0npoESvKHRJOjBl5DkbLpj8Q3rV yl+Q== X-Gm-Message-State: ALoCoQmMtg3K1ZJ7o6aK6NpfSdNIc4PfBqm04UBTlDF/Il3350aPXnFSbq9QtHOgJ/BFijQaEnNO X-Received: by 10.112.137.70 with SMTP id qg6mr33261lbb.14.1422347829204; Tue, 27 Jan 2015 00:37:09 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.29.202 with SMTP id m10ls2122lah.76.gmail; Tue, 27 Jan 2015 00:37:08 -0800 (PST) X-Received: by 10.152.203.230 with SMTP id kt6mr180843lac.38.1422347828885; Tue, 27 Jan 2015 00:37:08 -0800 (PST) Received: from mail-lb0-f178.google.com (mail-lb0-f178.google.com. [209.85.217.178]) by mx.google.com with ESMTPS id r3si590997lbo.9.2015.01.27.00.37.08 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 27 Jan 2015 00:37:08 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.178 as permitted sender) client-ip=209.85.217.178; Received: by mail-lb0-f178.google.com with SMTP id u10so11839508lbd.9 for ; Tue, 27 Jan 2015 00:37:08 -0800 (PST) X-Received: by 10.152.7.229 with SMTP id m5mr138742laa.80.1422347828796; Tue, 27 Jan 2015 00:37:08 -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 h5csp1025464lbj; Tue, 27 Jan 2015 00:37:07 -0800 (PST) X-Received: by 10.66.234.2 with SMTP id ua2mr327635pac.4.1422347822689; Tue, 27 Jan 2015 00:37:02 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id vr2si685254pbc.134.2015.01.27.00.37.01; Tue, 27 Jan 2015 00:37:02 -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 S1757834AbbA0IhA (ORCPT + 11 others); Tue, 27 Jan 2015 03:37:00 -0500 Received: from mail-pd0-f179.google.com ([209.85.192.179]:54103 "EHLO mail-pd0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753886AbbA0IhA (ORCPT ); Tue, 27 Jan 2015 03:37:00 -0500 Received: by mail-pd0-f179.google.com with SMTP id v10so17550551pde.10 for ; Tue, 27 Jan 2015 00:36:59 -0800 (PST) X-Received: by 10.68.65.16 with SMTP id t16mr40555319pbs.163.1422347819910; Tue, 27 Jan 2015 00:36:59 -0800 (PST) Received: from localhost ([122.178.198.250]) by mx.google.com with ESMTPSA id o5sm849771pdr.9.2015.01.27.00.36.58 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 27 Jan 2015 00:36:59 -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 05/18] cpufreq: Manage governor usage history with 'policy->last_governor' Date: Tue, 27 Jan 2015 14:06:11 +0530 Message-Id: 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.178 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 | 24 ++++++++++++------------ include/linux/cpufreq.h | 1 + 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index f253cf45f910..4ad1e46891b5 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -57,9 +57,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; @@ -941,7 +938,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); @@ -1366,8 +1363,9 @@ static int __cpufreq_remove_dev_prepare(struct device *dev, return ret; } - strncpy(per_cpu(cpufreq_cpu_governor, cpu), - policy->governor->name, CPUFREQ_NAME_LEN); + if (cpus == 1) + strncpy(policy->last_governor, policy->governor->name, + CPUFREQ_NAME_LEN); } if (cpu != policy->cpu) { @@ -2096,7 +2094,8 @@ EXPORT_SYMBOL_GPL(cpufreq_register_governor); void cpufreq_unregister_governor(struct cpufreq_governor *governor) { - int cpu; + struct cpufreq_policy *policy; + unsigned long flags; if (!governor) return; @@ -2104,12 +2103,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 fallback policies */ + read_lock_irqsave(&cpufreq_driver_lock, flags); + for_each_fallback_policy(policy) { + 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 df6af4cfa26a..e326cddef6db 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 */